1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2008 Lloyd Bryant <[email protected]> |
4 |
|
|
* Copyright (C) 2011-2019 The ManaPlus Developers |
5 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
6 |
|
|
* |
7 |
|
|
* This file is part of The ManaPlus Client. |
8 |
|
|
* |
9 |
|
|
* This program is free software; you can redistribute it and/or modify |
10 |
|
|
* it under the terms of the GNU General Public License as published by |
11 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
12 |
|
|
* any later version. |
13 |
|
|
* |
14 |
|
|
* This program is distributed in the hope that it will be useful, |
15 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
|
|
* GNU General Public License for more details. |
18 |
|
|
* |
19 |
|
|
* You should have received a copy of the GNU General Public License |
20 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 |
|
|
*/ |
22 |
|
|
|
23 |
|
|
#include "net/eathena/partyhandler.h" |
24 |
|
|
|
25 |
|
|
#include "actormanager.h" |
26 |
|
|
#include "notifymanager.h" |
27 |
|
|
#include "party.h" |
28 |
|
|
|
29 |
|
|
#include "being/localplayer.h" |
30 |
|
|
|
31 |
|
|
#include "enums/resources/notifytypes.h" |
32 |
|
|
|
33 |
|
|
#include "net/ea/partyrecv.h" |
34 |
|
|
|
35 |
|
|
#include "net/eathena/messageout.h" |
36 |
|
|
#include "net/eathena/partyrecv.h" |
37 |
|
|
#include "net/eathena/protocolout.h" |
38 |
|
|
|
39 |
|
|
#include "debug.h" |
40 |
|
|
|
41 |
|
|
extern int packetVersion; |
42 |
|
|
|
43 |
|
|
namespace EAthena |
44 |
|
|
{ |
45 |
|
|
|
46 |
|
|
PartyHandler::PartyHandler() : |
47 |
|
|
Ea::PartyHandler() |
48 |
|
|
{ |
49 |
|
|
partyHandler = this; |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
PartyHandler::~PartyHandler() |
53 |
|
|
{ |
54 |
|
|
partyHandler = nullptr; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
void PartyHandler::create(const std::string &name) const |
58 |
|
|
{ |
59 |
|
|
createOutPacket(CMSG_PARTY_CREATE); |
60 |
|
|
outMsg.writeString(name.substr(0, 23), 24, "party name"); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
void PartyHandler::invite(const std::string &name) const |
64 |
|
|
{ |
65 |
|
|
if (actorManager == nullptr) |
66 |
|
|
return; |
67 |
|
|
const Being *const being = actorManager->findBeingByName( |
68 |
|
|
name, ActorType::Player); |
69 |
|
|
if (being != nullptr) |
70 |
|
|
{ |
71 |
|
|
createOutPacket(CMSG_PARTY_INVITE); |
72 |
|
|
outMsg.writeBeingId(being->getId(), "account id"); |
73 |
|
|
} |
74 |
|
|
else |
75 |
|
|
{ |
76 |
|
|
if (packetVersion < 20070227) |
77 |
|
|
return; |
78 |
|
|
createOutPacket(CMSG_PARTY_INVITE2); |
79 |
|
|
outMsg.writeString(name, 24, "nick"); |
80 |
|
|
} |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
void PartyHandler::inviteResponse(const int partyId, |
84 |
|
|
const bool accept) const |
85 |
|
|
{ |
86 |
|
|
if (localPlayer != nullptr) |
87 |
|
|
{ |
88 |
|
|
createOutPacket(CMSG_PARTY_INVITED2); |
89 |
|
|
outMsg.writeInt32(partyId, "party id"); |
90 |
|
|
outMsg.writeInt8(CAST_S8(accept ? 1 : 0), "accept"); |
91 |
|
|
} |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
void PartyHandler::leave() const |
95 |
|
|
{ |
96 |
|
|
createOutPacket(CMSG_PARTY_LEAVE); |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
void PartyHandler::kick(const Being *const being) const |
100 |
|
|
{ |
101 |
|
|
if (being != nullptr) |
102 |
|
|
{ |
103 |
|
|
createOutPacket(CMSG_PARTY_KICK); |
104 |
|
|
outMsg.writeBeingId(being->getId(), "account id"); |
105 |
|
|
outMsg.writeString(being->getName(), 24, "player name"); |
106 |
|
|
} |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
void PartyHandler::kick(const std::string &name) const |
110 |
|
|
{ |
111 |
|
|
if (Ea::taParty == nullptr) |
112 |
|
|
return; |
113 |
|
|
|
114 |
|
|
const PartyMember *const m = Ea::taParty->getMember(name); |
115 |
|
|
if (m == nullptr) |
116 |
|
|
{ |
117 |
|
|
NotifyManager::notify(NotifyTypes::PARTY_USER_NOT_IN_PARTY, name); |
118 |
|
|
return; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
createOutPacket(CMSG_PARTY_KICK); |
122 |
|
|
outMsg.writeBeingId(m->getID(), "account id"); |
123 |
|
|
outMsg.writeString(name, 24, "player name"); |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
void PartyHandler::chat(const std::string &text) const |
127 |
|
|
{ |
128 |
|
|
createOutPacket(CMSG_PARTY_MESSAGE); |
129 |
|
|
const std::string mes = std::string(localPlayer->getName()).append( |
130 |
|
|
" : ").append(text); |
131 |
|
|
if (packetVersion >= 20151001) |
132 |
|
|
{ |
133 |
|
|
outMsg.writeInt16(CAST_S16(mes.length() + 4), "len"); |
134 |
|
|
outMsg.writeString(mes, CAST_S32(mes.length()), "nick : message"); |
135 |
|
|
} |
136 |
|
|
else |
137 |
|
|
{ |
138 |
|
|
outMsg.writeInt16(CAST_S16(mes.length() + 4 + 1), "len"); |
139 |
|
|
outMsg.writeString(mes, CAST_S32(mes.length()), "nick : message"); |
140 |
|
|
outMsg.writeInt8(0, "null char"); |
141 |
|
|
} |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
// +++ must be 3 types item, exp, pickup |
145 |
|
|
void PartyHandler::setShareExperience(const PartyShareT share) const |
146 |
|
|
{ |
147 |
|
|
if (share == PartyShare::NOT_POSSIBLE) |
148 |
|
|
return; |
149 |
|
|
|
150 |
|
|
createOutPacket(CMSG_PARTY_SETTINGS); |
151 |
|
|
if (packetVersion >= 20090603) |
152 |
|
|
{ |
153 |
|
|
outMsg.writeInt32(CAST_S32(share), "share exp"); |
154 |
|
|
outMsg.writeInt16(CAST_S16(Ea::PartyRecv::mShareItems), |
155 |
|
|
"share items"); |
156 |
|
|
} |
157 |
|
|
else |
158 |
|
|
{ |
159 |
|
|
outMsg.writeInt32(CAST_S32(share), "share exp"); |
160 |
|
|
} |
161 |
|
|
} |
162 |
|
|
|
163 |
|
|
// +++ must be 3 types item, exp, pickup |
164 |
|
|
void PartyHandler::setShareItems(const PartyShareT share) const |
165 |
|
|
{ |
166 |
|
|
if (share == PartyShare::NOT_POSSIBLE) |
167 |
|
|
return; |
168 |
|
|
|
169 |
|
|
createOutPacket(CMSG_PARTY_SETTINGS); |
170 |
|
|
if (packetVersion >= 20090603) |
171 |
|
|
{ |
172 |
|
|
outMsg.writeInt32(CAST_S32(Ea::PartyRecv::mShareExp), |
173 |
|
|
"share exp"); |
174 |
|
|
outMsg.writeInt16(CAST_S16(share), "share items"); |
175 |
|
|
} |
176 |
|
|
} |
177 |
|
|
|
178 |
|
|
void PartyHandler::changeLeader(const std::string &name) const |
179 |
|
|
{ |
180 |
|
|
if (actorManager == nullptr) |
181 |
|
|
return; |
182 |
|
|
const Being *const being = actorManager->findBeingByName( |
183 |
|
|
name, ActorType::Player); |
184 |
|
|
if (being == nullptr) |
185 |
|
|
return; |
186 |
|
|
createOutPacket(CMSG_PARTY_CHANGE_LEADER); |
187 |
|
|
outMsg.writeBeingId(being->getId(), "account id"); |
188 |
|
|
} |
189 |
|
|
|
190 |
|
|
void PartyHandler::allowInvite(const bool allow) const |
191 |
|
|
{ |
192 |
|
|
createOutPacket(CMSG_PARTY_ALLOW_INVITES); |
193 |
|
|
outMsg.writeInt8(CAST_S8(allow ? 1 : 0), "allow"); |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
PartyShareT PartyHandler::getShareAutoItems() const |
197 |
|
|
{ |
198 |
|
|
return PartyRecv::mShareAutoItems; |
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
void PartyHandler::setShareAutoItems(const PartyShareT share) const |
202 |
|
|
{ |
203 |
|
|
PartyRecv::mShareAutoItems = share; |
204 |
|
|
} |
205 |
|
|
|
206 |
|
2 |
} // namespace EAthena |