ManaPlus
partyrecv.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2008 Lloyd Bryant <[email protected]>
4  * Copyright (C) 2011-2018 The ManaPlus Developers
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "net/eathena/partyrecv.h"
23 
24 #include "notifymanager.h"
25 #include "party.h"
26 
27 #include "being/localplayer.h"
28 
30 
31 #include "gui/windows/chatwindow.h"
33 
35 
36 #include "net/messagein.h"
37 
38 #include "net/ea/partyrecv.h"
39 
40 #include "utils/checkutils.h"
41 #include "utils/foreach.h"
42 
43 #include "debug.h"
44 
45 namespace EAthena
46 {
47 
48 namespace PartyRecv
49 {
51 } // namespace PartyRecv
52 
54 {
55  // +++ for now server allow only switch this option but not using it.
56  msg.readUInt8("allow party");
57 }
58 
60 {
61  const BeingId id = msg.readBeingId("account id");
62  if (msg.getVersion() >= 20171207)
63  msg.readBeingId("char id");
64  const bool leader = msg.readInt32("leader") == 0U;
65  int level = 0;
66  if (msg.getVersion() >= 20170502)
67  {
68  msg.readInt16("class");
69  level = msg.readInt16("level");
70  }
71  const int x = msg.readInt16("x");
72  const int y = msg.readInt16("y");
73  const bool online = msg.readInt8("online") == 0U;
74  msg.readString(24, "party name");
75  const std::string nick = msg.readString(24, "player name");
76  const std::string map = msg.readString(16, "map name");
77  msg.readInt8("pickup item share (&1)");
78  msg.readInt8("get item share (&2)");
79 
80  if (Ea::taParty == nullptr)
81  return;
82 
83  PartyMember *const member = Ea::taParty->addMember(id, nick);
84  if (member != nullptr)
85  {
86  if ((partyTab != nullptr) && member->getOnline() != online)
87  partyTab->showOnline(nick, fromBool(online, Online));
88  member->setLeader(leader);
89  member->setOnline(online);
90  member->setMap(map);
91  member->setX(x);
92  member->setY(y);
93  if (level != 0)
94  member->setLevel(level);
95  }
96 }
97 
99 {
100  const BeingId id = msg.readBeingId("account id");
101  msg.readInt16("class");
102  const int level = msg.readInt16("level");
103 
104  if (Ea::taParty == nullptr)
105  return;
106 
107  PartyMember *const member = Ea::taParty->getMember(id);
108  if (member != nullptr)
109  {
110  member->setOnline(true);
111  if (level != 0)
112  member->setLevel(level);
113  }
114  else
115  {
116  reportAlways("processPartyMemberJobLevel: party member not exists.");
117  }
118 }
119 
121 {
122  if (partyTab == nullptr)
123  {
124  if (chatWindow == nullptr)
125  return;
126 
128  }
129 
130  const PartyShareT exp = static_cast<PartyShareT>(
131  msg.readInt32("party exp"));
133  if (msg.getVersion() >= 20090603)
134  {
135  const PartyShareT item = static_cast<PartyShareT>(
136  msg.readInt8("pickup item share (&1)"));
138  const PartyShareT autoItem = static_cast<PartyShareT>(
139  msg.readInt8("get auto item share (&2)"));
141  }
142 }
143 
145 {
146  bool isOldParty = false;
147  std::set<std::string> names;
148  std::set<std::string> onlineNames;
149  if (Ea::taParty == nullptr)
150  {
151  logger->log1("error: party empty in SMSG_PARTY_INFO");
153  }
154  if (partyTab == nullptr)
156 
157  if (Ea::taParty != nullptr)
158  {
159  if (Ea::taParty->getNumberOfElements() > 1)
160  {
161  isOldParty = true;
162  Ea::taParty->getNamesSet(names);
163  const Party::MemberList *const members = Ea::taParty->getMembers();
164  FOR_EACHP (Party::MemberList::const_iterator, it, members)
165  {
166  if ((*it)->getOnline())
167  onlineNames.insert((*it)->getName());
168  }
169  if (localPlayer != nullptr)
170  onlineNames.insert(localPlayer->getName());
171  }
172  }
173 
174  if (localPlayer == nullptr)
175  logger->log1("error: localPlayer==0 in SMSG_PARTY_INFO");
176 
177  if (Ea::taParty != nullptr)
179 
180  const int length = msg.readInt16("len");
181  if (Ea::taParty != nullptr)
182  {
183  const std::string name = msg.readString(24, "party name");
184  Ea::taParty->setName(name);
185  }
186  else
187  {
188  msg.readString(24, "party name");
189  }
190 
191  int partySize = 0;
192  const int offset = 28;
193  if (msg.getVersion() >= 20171207)
194  {
195  partySize = 4 + 4 + 24 + 16 + 1 + 1 + 2 + 2;
196  }
197  else if (msg.getVersion() >= 20170502)
198  {
199  partySize = 4 + 24 + 16 + 1 + 1 + 2 + 2;
200  }
201  else
202  {
203  partySize = 4 + 24 + 16 + 1 + 1;
204  }
205 
206  const int count = (length - offset) / partySize;
207  if (localPlayer != nullptr &&
208  Ea::taParty != nullptr)
209  {
212  }
213 
214  for (int i = 0; i < count; i++)
215  {
216  const BeingId id = msg.readBeingId("account id");
217  if (msg.getVersion() >= 20171207)
218  msg.readBeingId("char id");
219  std::string nick = msg.readString(24, "nick");
220  std::string map = msg.readString(16, "map name");
221  const bool leader = msg.readUInt8("leader") == 0U;
222  const bool online = msg.readUInt8("online") == 0U;
223  int level = 0;
224  if (msg.getVersion() >= 20170502)
225  {
226  msg.readInt16("class");
227  level = msg.readInt16("level");
228  }
229 
230  if (Ea::taParty != nullptr)
231  {
232  bool joined(false);
233 
234  if (isOldParty)
235  {
236  if (names.find(nick) == names.end())
237  {
239  nick);
240  joined = true;
241  }
242  }
243  PartyMember *const member = Ea::taParty->addMember(id, nick);
244  if (member != nullptr)
245  {
246  if (!joined && (partyTab != nullptr))
247  {
248  if (!names.empty() && ((onlineNames.find(nick)
249  == onlineNames.end() && online)
250  || (onlineNames.find(nick) != onlineNames.end()
251  && !online)))
252  {
253  partyTab->showOnline(nick, fromBool(online, Online));
254  }
255  }
256  member->setLeader(leader);
257  member->setOnline(online);
258  member->setMap(map);
259  if (level != 0)
260  member->setLevel(level);
261  }
262  }
263  }
264 
265  if (msg.getVersion() >= 20170502 && msg.getUnreadLength() >= 6)
266  {
267  msg.readInt8("pickup item share (&1)");
268  msg.readInt8("get item share (&2)");
269  msg.readInt32("unknown");
270  }
271 
272  if (Ea::taParty != nullptr)
273  Ea::taParty->sort();
274 
275  if ((localPlayer != nullptr) && (Ea::taParty != nullptr))
276  {
279  if (socialWindow != nullptr)
281  }
282 }
283 
285 {
286  const int msgLength = msg.readInt16("len") - 8;
287  if (msgLength <= 0)
288  return;
289 
290  const BeingId id = msg.readBeingId("id");
291  std::string chatMsg = msg.readString(msgLength, "message");
292 
293  const size_t pos = chatMsg.find(" : ", 0);
294  if (pos != std::string::npos)
295  chatMsg.erase(0, pos + 3);
296 
297  if ((Ea::taParty != nullptr) && (partyTab != nullptr))
298  {
299  const PartyMember *const member = Ea::taParty->getMember(id);
300  if (member != nullptr)
301  {
302  partyTab->chatLog(member->getName(), chatMsg);
303  }
304  else
305  {
307  chatMsg);
308  }
309  }
310 }
311 
313 {
314  if (partyTab == nullptr)
315  return;
316 
317  const std::string nick = msg.readString(24, "nick");
318 
319  switch (msg.readInt32("result"))
320  {
321  case 0:
323  nick);
324  break;
325  case 1:
327  break;
328  case 2:
330  break;
331  case 3:
333  nick);
334  break;
335  case 4:
337  nick);
338  break;
339  case 5:
342  nick);
343  break;
344  case 7:
346  nick);
347  break;
348  default:
350  break;
351  }
352 }
353 
355 {
357  // +++ probably need add option to show pickup notifications
358  // in party tab
359  msg.readBeingId("account id");
360  msg.readItemId("item id");
361  msg.readUInt8("identify");
362  msg.readUInt8("attribute");
363  msg.readUInt8("refine");
364  for (int f = 0; f < maxCards; f++)
365  msg.readItemId("card");
366  msg.readInt16("equip location");
367  msg.readUInt8("item type");
368  // for color can be used ItemColorManager
369 }
370 
372 {
373  PartyMember *const oldMember = Ea::taParty->getMember(
374  msg.readBeingId("old leder id"));
375  PartyMember *const newMember = Ea::taParty->getMember(
376  msg.readBeingId("new leder id"));
377  if (oldMember != nullptr)
378  oldMember->setLeader(false);
379  if (newMember != nullptr)
380  newMember->setLeader(true);
381 }
382 
384 {
385  if (socialWindow == nullptr)
386  {
387  msg.readInt32("party id");
388  msg.readString(24, "party name");
389  return;
390  }
391  const int id = msg.readInt32("party id");
392  const std::string partyName = msg.readString(24, "party name");
393 
394  if (socialWindow != nullptr)
395  socialWindow->showPartyInvite(partyName, std::string(), id);
396 }
397 
399  const PartyShareT item)
400 {
401  switch (item)
402  {
403  case PartyShare::YES:
405  break;
408  break;
409  case PartyShare::NO:
411  break;
414  break;
417  break;
420  break;
421  default:
422  case PartyShare::UNKNOWN:
424  break;
425  }
426 }
427 
428 } // namespace EAthena
ChatWindow * chatWindow
Definition: chatwindow.cpp:89
std::string getName() const
Definition: avatar.h:52
unsigned char readUInt8(const char *const str)
Definition: messagein.cpp:103
void processPartyInfo(Net::MessageIn &msg)
Definition: partyrecv.cpp:144
#define FOR_EACHP(type, iter, array)
Definition: foreach.h:30
void log1(const char *const log_text)
Definition: logger.cpp:233
bool getOnline() const
Definition: avatar.h:80
BeingId readBeingId(const char *const str)
Definition: messagein.cpp:223
void processPartyItemSettingsContinue(Net::MessageIn &msg, const PartyShareT item)
Definition: partyrecv.cpp:93
void setLevel(const int level)
Definition: avatar.h:116
void setMap(const std::string &map)
Definition: avatar.h:122
Party * taParty
Definition: partyrecv.cpp:47
PartyTab * partyTab
Definition: partytab.cpp:44
void setLeader(const bool leader)
Definition: party.h:47
PartyShare ::T PartyShareT
Definition: partyshare.h:35
int BeingId
Definition: beingid.h:29
void setOnline(const bool online)
Definition: avatar.h:86
PartyShareT mShareAutoItems
Definition: partyrecv.cpp:50
unsigned int getUnreadLength() const
Definition: messagein.h:64
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:110
bool msg(InputEvent &event)
Definition: chat.cpp:38
void clearMembers()
Definition: party.h:121
void notify(const unsigned int message)
void setY(const int y)
Definition: avatar.h:134
std::vector< PartyMember * > MemberList
Definition: party.h:156
signed char readInt8(const char *const str)
Definition: messagein.cpp:116
void getNamesSet(std::set< std::string > &names) const
Definition: party.cpp:298
void setPartyName(const std::string &name)
Definition: being.cpp:5246
Logger * logger
Definition: logger.cpp:88
int16_t readInt16(const char *const str)
Definition: messagein.cpp:130
void createTab()
Definition: partyrecv.cpp:225
void processPartyLeader(Net::MessageIn &msg)
Definition: partyrecv.cpp:371
const std::string & getName(const int id)
Definition: groupdb.cpp:343
#define CAST_S32
Definition: cast.h:29
void showPartyInvite(const std::string &partyName, const std::string &inviter, const int partyId)
#define fromBool(val, name)
Definition: booldefines.h:48
static Party * getParty(const int16_t id)
Definition: party.cpp:312
void processPartyMemberJobLevel(Net::MessageIn &msg)
Definition: partyrecv.cpp:98
int getVersion() const
Definition: messagein.h:133
LocalPlayer * localPlayer
void processPartyItemPickup(Net::MessageIn &msg)
Definition: partyrecv.cpp:354
PartyMember * getMember(const BeingId id) const
Definition: party.cpp:98
void processPartyMessage(Net::MessageIn &msg)
Definition: partyrecv.cpp:284
SocialWindow * socialWindow
const std::string & getName() const
Definition: being.h:231
void processPartyInvited(Net::MessageIn &msg)
Definition: partyrecv.cpp:383
int readItemId(const char *const str)
Definition: messagein.cpp:216
void processPartyExpSettingsContinue(Net::MessageIn &msg, const PartyShareT exp)
Definition: partyrecv.cpp:63
const MemberList * getMembers() const
Definition: party.h:158
void setName(const std::string &name)
Definition: party.h:69
PartyMember * addMember(const BeingId id, const std::string &name)
Definition: party.cpp:84
void processPartyInviteResponse(Net::MessageIn &msg)
Definition: partyrecv.cpp:312
void processPartyMemberInfo(Net::MessageIn &msg)
Definition: partyrecv.cpp:59
void showOnline(const std::string &nick, const Online online)
Definition: chattab.cpp:546
void processPartySettings(Net::MessageIn &msg)
Definition: partyrecv.cpp:120
void setParty(Party *const party)
Definition: being.cpp:1306
std::string readString(int length, const char *const dstr)
Definition: messagein.cpp:367
#define UNIMPLEMENTEDPACKET
Definition: logger.h:55
void processPartyAutoItemSettingsContinue(Net::MessageIn &msg, const PartyShareT item)
Definition: partyrecv.cpp:398
void processPartyInvitationStats(Net::MessageIn &msg)
Definition: partyrecv.cpp:53
int32_t readInt32(const char *const str)
Definition: messagein.cpp:174
#define reportAlways(...)
Definition: checkutils.h:252
#define maxCards
Definition: cards.h:24
void setX(const int x)
Definition: avatar.h:128
#define UNIMPLEMENTEDPACKETFIELD(field)
Definition: logger.h:58
void sort()
Definition: party.cpp:322
void updateParty()