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  int offset = 0;
193  if (msg.getVersion() >= 20170502)
194  {
195  partySize = 50;
196  offset = 28 + 6;
197  }
198  else
199  {
200  partySize = 46;
201  offset = 28;
202  }
203 
204  const int count = (length - offset) / partySize;
205  if (localPlayer != nullptr &&
206  Ea::taParty != nullptr)
207  {
210  }
211 
212  for (int i = 0; i < count; i++)
213  {
214  const BeingId id = msg.readBeingId("account id");
215  if (msg.getVersion() >= 20171207)
216  msg.readBeingId("char id");
217  std::string nick = msg.readString(24, "nick");
218  std::string map = msg.readString(16, "map name");
219  const bool leader = msg.readUInt8("leader") == 0U;
220  const bool online = msg.readUInt8("online") == 0U;
221  int level = 0;
222  if (msg.getVersion() >= 20170502)
223  {
224  msg.readInt16("class");
225  level = msg.readInt16("level");
226  }
227 
228  if (Ea::taParty != nullptr)
229  {
230  bool joined(false);
231 
232  if (isOldParty)
233  {
234  if (names.find(nick) == names.end())
235  {
237  nick);
238  joined = true;
239  }
240  }
241  PartyMember *const member = Ea::taParty->addMember(id, nick);
242  if (member != nullptr)
243  {
244  if (!joined && (partyTab != nullptr))
245  {
246  if (!names.empty() && ((onlineNames.find(nick)
247  == onlineNames.end() && online)
248  || (onlineNames.find(nick) != onlineNames.end()
249  && !online)))
250  {
251  partyTab->showOnline(nick, fromBool(online, Online));
252  }
253  }
254  member->setLeader(leader);
255  member->setOnline(online);
256  member->setMap(map);
257  if (level != 0)
258  member->setLevel(level);
259  }
260  }
261  }
262 
263  if (msg.getVersion() >= 20170502 && msg.getUnreadLength() >= 6)
264  {
265  msg.readInt8("pickup item share (&1)");
266  msg.readInt8("get item share (&2)");
267  msg.readInt32("unknown");
268  }
269 
270  if (Ea::taParty != nullptr)
271  Ea::taParty->sort();
272 
273  if ((localPlayer != nullptr) && (Ea::taParty != nullptr))
274  {
277  if (socialWindow != nullptr)
279  }
280 }
281 
283 {
284  const int msgLength = msg.readInt16("len") - 8;
285  if (msgLength <= 0)
286  return;
287 
288  const BeingId id = msg.readBeingId("id");
289  std::string chatMsg = msg.readString(msgLength, "message");
290 
291  const size_t pos = chatMsg.find(" : ", 0);
292  if (pos != std::string::npos)
293  chatMsg.erase(0, pos + 3);
294 
295  if ((Ea::taParty != nullptr) && (partyTab != nullptr))
296  {
297  const PartyMember *const member = Ea::taParty->getMember(id);
298  if (member != nullptr)
299  {
300  partyTab->chatLog(member->getName(), chatMsg);
301  }
302  else
303  {
305  chatMsg);
306  }
307  }
308 }
309 
311 {
312  if (partyTab == nullptr)
313  return;
314 
315  const std::string nick = msg.readString(24, "nick");
316 
317  switch (msg.readInt32("result"))
318  {
319  case 0:
321  nick);
322  break;
323  case 1:
325  break;
326  case 2:
328  break;
329  case 3:
331  nick);
332  break;
333  case 4:
335  nick);
336  break;
337  case 5:
340  nick);
341  break;
342  case 7:
344  nick);
345  break;
346  default:
348  break;
349  }
350 }
351 
353 {
355  // +++ probably need add option to show pickup notifications
356  // in party tab
357  msg.readBeingId("account id");
358  msg.readInt16("item id");
359  msg.readUInt8("identify");
360  msg.readUInt8("attribute");
361  msg.readUInt8("refine");
362  for (int f = 0; f < maxCards; f++)
363  msg.readUInt16("card");
364  msg.readInt16("equip location");
365  msg.readUInt8("item type");
366  // for color can be used ItemColorManager
367 }
368 
370 {
371  PartyMember *const oldMember = Ea::taParty->getMember(
372  msg.readBeingId("old leder id"));
373  PartyMember *const newMember = Ea::taParty->getMember(
374  msg.readBeingId("new leder id"));
375  if (oldMember != nullptr)
376  oldMember->setLeader(false);
377  if (newMember != nullptr)
378  newMember->setLeader(true);
379 }
380 
382 {
383  if (socialWindow == nullptr)
384  {
385  msg.readInt32("party id");
386  msg.readString(24, "party name");
387  return;
388  }
389  const int id = msg.readInt32("party id");
390  const std::string partyName = msg.readString(24, "party name");
391 
392  if (socialWindow != nullptr)
393  socialWindow->showPartyInvite(partyName, std::string(), id);
394 }
395 
397  const PartyShareT item)
398 {
399  switch (item)
400  {
401  case PartyShare::YES:
403  break;
406  break;
407  case PartyShare::NO:
409  break;
412  break;
415  break;
418  break;
419  default:
420  case PartyShare::UNKNOWN:
422  break;
423  }
424 }
425 
426 } // 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:98
void processPartyInfo(Net::MessageIn &msg)
Definition: partyrecv.cpp:144
#define FOR_EACHP(type, iter, array)
Definition: foreach.h:30
uint16_t readUInt16(const char *const str)
Definition: messagein.cpp:147
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:211
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:111
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:125
void createTab()
Definition: partyrecv.cpp:225
void processPartyLeader(Net::MessageIn &msg)
Definition: partyrecv.cpp:369
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
LocalPlayer * localPlayer
void processPartyItemPickup(Net::MessageIn &msg)
Definition: partyrecv.cpp:352
PartyMember * getMember(const BeingId id) const
Definition: party.cpp:98
void processPartyMessage(Net::MessageIn &msg)
Definition: partyrecv.cpp:282
unsigned int getVersion() const
Definition: messagein.h:131
SocialWindow * socialWindow
const std::string & getName() const
Definition: being.h:231
void processPartyInvited(Net::MessageIn &msg)
Definition: partyrecv.cpp:381
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:310
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:355
#define UNIMPLEMENTEDPACKET
Definition: logger.h:55
void processPartyAutoItemSettingsContinue(Net::MessageIn &msg, const PartyShareT item)
Definition: partyrecv.cpp:396
void processPartyInvitationStats(Net::MessageIn &msg)
Definition: partyrecv.cpp:53
int32_t readInt32(const char *const str)
Definition: messagein.cpp:169
#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()