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-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/tmwa/partyrecv.h"
24 
25 #include "actormanager.h"
26 #include "notifymanager.h"
27 #include "party.h"
28 
29 #include "being/localplayer.h"
30 
32 
33 #include "gui/windows/chatwindow.h"
35 
37 
38 #include "net/messagein.h"
39 
40 #include "net/ea/partyrecv.h"
41 
42 #include "utils/foreach.h"
43 
44 #include "debug.h"
45 
46 namespace TmwAthena
47 {
48 
50 {
51  if (partyTab == nullptr)
52  {
53  if (chatWindow == nullptr)
54  return;
55 
57  }
58 
59  // These seem to indicate the sharing mode for exp and items
60  const PartyShareT exp = static_cast<PartyShareT>(
61  msg.readInt16("share exp"));
62  const PartyShareT item = static_cast<PartyShareT>(
63  msg.readInt16("share items"));
66 }
67 
69 {
70  bool isOldParty = false;
71  std::set<std::string> names;
72  std::set<std::string> onlineNames;
73  if (Ea::taParty == nullptr)
74  {
75  logger->log1("error: party empty in SMSG_PARTY_INFO");
77  }
78  if (Ea::taParty != nullptr)
79  {
80  if (Ea::taParty->getNumberOfElements() > 1)
81  {
82  isOldParty = true;
83  Ea::taParty->getNamesSet(names);
84  const Party::MemberList *const members = Ea::taParty->getMembers();
85  FOR_EACHP (Party::MemberList::const_iterator, it, members)
86  {
87  if ((*it)->getOnline())
88  onlineNames.insert((*it)->getName());
89  }
90  if (localPlayer != nullptr)
91  onlineNames.insert(localPlayer->getName());
92  }
93  }
94 
95  if (localPlayer == nullptr)
96  logger->log1("error: localPlayer==0 in SMSG_PARTY_INFO");
97 
98  if (Ea::taParty != nullptr)
100 
101  const int length = msg.readInt16("len");
102  if (Ea::taParty != nullptr)
103  Ea::taParty->setName(msg.readString(24, "party name"));
104 
105  const int count = (length - 28) / 46;
106  if ((localPlayer != nullptr) && (Ea::taParty != nullptr))
107  {
110  }
111 
112  for (int i = 0; i < count; i++)
113  {
114  const BeingId id = msg.readBeingId("id");
115  std::string nick = msg.readString(24, "nick");
116  std::string map = msg.readString(16, "map");
117  const bool leader = msg.readUInt8("leader") == 0U;
118  const bool online = msg.readUInt8("online") == 0U;
119 
120  if (Ea::taParty != nullptr)
121  {
122  bool joined(false);
123 
124  if (isOldParty)
125  {
126  if (names.find(nick) == names.end())
127  {
129  nick);
130  joined = true;
131  }
132  }
133  PartyMember *const member = Ea::taParty->addMember(id, nick);
134  if (member != nullptr)
135  {
136  if (!joined && (partyTab != nullptr))
137  {
138  if (!names.empty() && ((onlineNames.find(nick)
139  == onlineNames.end() && online)
140  || (onlineNames.find(nick) != onlineNames.end()
141  && !online)))
142  {
143  partyTab->showOnline(nick, fromBool(online, Online));
144  }
145 
146  member->setLeader(leader);
147  member->setOnline(online);
148  member->setMap(map);
149  }
150  else
151  {
152  member->setLeader(leader);
153  member->setOnline(online);
154  member->setMap(map);
155  }
156  }
157  }
158  }
159 
160  if (Ea::taParty != nullptr)
161  Ea::taParty->sort();
162 
163  if ((localPlayer != nullptr) && (Ea::taParty != nullptr))
164  {
167  if (socialWindow != nullptr)
169  }
170 }
171 
173 {
174  const int msgLength = msg.readInt16("len") - 8;
175  if (msgLength <= 0)
176  return;
177 
178  const BeingId id = msg.readBeingId("id");
179  const std::string chatMsg = msg.readString(msgLength, "message");
180 
181  if ((Ea::taParty != nullptr) && (partyTab != nullptr))
182  {
183  const PartyMember *const member = Ea::taParty->getMember(id);
184  if (member != nullptr)
185  {
186  partyTab->chatLog(member->getName(), chatMsg);
187  }
188  else
189  {
191  chatMsg);
192  }
193  }
194 }
195 
197 {
198  if (partyTab == nullptr)
199  return;
200 
201  const std::string nick = msg.readString(24, "nick");
202 
203  switch (msg.readUInt8("status"))
204  {
205  case 0:
207  nick);
208  break;
209  case 1:
211  break;
212  case 2:
214  break;
215  case 3:
217  nick);
218  break;
219  default:
221  break;
222  }
223 }
224 
226 {
227  const BeingId id = msg.readBeingId("account id");
228  std::string nick;
229 
230  if (actorManager != nullptr)
231  {
232  const Being *const being = actorManager->findBeing(id);
233  if (being != nullptr)
234  {
235  if (being->getType() == ActorType::Player)
236  nick = being->getName();
237  }
238  }
239 
240  if (socialWindow != nullptr)
241  {
242  const std::string partyName = msg.readString(24, "party name");
243  socialWindow->showPartyInvite(partyName, nick, 0);
244  }
245  else
246  {
247  msg.readString(24, "party name");
248  }
249 }
250 
252 {
253  const BeingId id = msg.readBeingId("id");
254  PartyMember *m = nullptr;
255  if (Ea::taParty != nullptr)
256  m = Ea::taParty->getMember(id);
257  if (m != nullptr)
258  {
259  msg.readInt32("unused");
260  m->setX(msg.readInt16("x"));
261  m->setY(msg.readInt16("y"));
262  const bool online = msg.readUInt8("online") != 0;
263  if (m->getOnline() != online)
264  partyTab->showOnline(m->getName(), fromBool(online, Online));
265  m->setOnline(online);
266  msg.readString(24, "party");
267  msg.readString(24, "nick");
268  m->setMap(msg.readString(16, "map"));
269  }
270  else
271  {
272  msg.readInt32("unused");
273  msg.readInt16("x");
274  msg.readInt16("y");
275  msg.readUInt8("online");
276  msg.readString(24, "party");
277  msg.readString(24, "nick");
278  msg.readString(16, "map");
279  }
280 }
281 
283 {
284  const BeingId id = msg.readBeingId("id");
285  const int hp = msg.readInt16("hp");
286  const int maxhp = msg.readInt16("max hp");
287  PartyMember *m = nullptr;
288  if (Ea::taParty != nullptr)
289  m = Ea::taParty->getMember(id);
290  if (m != nullptr)
291  {
292  m->setHp(hp);
293  m->setMaxHp(maxhp);
294  }
295 
296  // The server only sends this when the member is in range, so
297  // lets make sure they get the party hilight.
298  if ((actorManager != nullptr) && (Ea::taParty != nullptr))
299  {
300  if (Being *const b = actorManager->findBeing(id))
301  b->setParty(Ea::taParty);
302  }
303 }
304 
305 } // namespace TmwAthena
ActorManager * actorManager
int BeingId
Definition: beingid.h:30
#define fromBool(val, name)
Definition: booldefines.h:49
ChatWindow * chatWindow
Definition: chatwindow.cpp:94
Being * findBeing(const BeingId id) const
void setY(const int y)
Definition: avatar.h:135
void setX(const int x)
Definition: avatar.h:129
void setOnline(const bool online)
Definition: avatar.h:87
void setMaxHp(const int maxHp)
Definition: avatar.h:99
void setHp(const int hp)
Definition: avatar.h:93
bool getOnline() const
Definition: avatar.h:81
void setMap(const std::string &map)
Definition: avatar.h:123
std::string getName() const
Definition: avatar.h:53
Definition: being.h:96
void setParty(Party *const party)
Definition: being.cpp:1307
const std::string & getName() const
Definition: being.h:232
void setPartyName(const std::string &name)
Definition: being.cpp:5246
ActorTypeT getType() const
Definition: being.h:116
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:111
void showOnline(const std::string &nick, const Online online)
Definition: chattab.cpp:547
void log1(const char *const log_text)
Definition: logger.cpp:238
void setLeader(const bool leader)
Definition: party.h:48
std::vector< PartyMember * > MemberList
Definition: party.h:157
const MemberList * getMembers() const
Definition: party.h:159
void setName(const std::string &name)
Definition: party.h:70
PartyMember * addMember(const BeingId id, const std::string &name)
Definition: party.cpp:85
PartyMember * getMember(const BeingId id) const
Definition: party.cpp:99
void getNamesSet(std::set< std::string > &names) const
Definition: party.cpp:299
static Party * getParty(const int16_t id)
Definition: party.cpp:313
void clearMembers()
Definition: party.h:122
void sort()
Definition: party.cpp:323
void showPartyInvite(const std::string &partyName, const std::string &inviter, const int partyId)
void updateParty()
#define FOR_EACHP(type, iter, array)
Definition: foreach.h:31
LocalPlayer * localPlayer
Logger * logger
Definition: logger.cpp:89
bool msg(InputEvent &event)
Definition: chat.cpp:39
void createTab()
Definition: partyrecv.cpp:226
void processPartyItemSettingsContinue(Net::MessageIn &msg, const PartyShareT item)
Definition: partyrecv.cpp:94
void processPartyExpSettingsContinue(Net::MessageIn &msg, const PartyShareT exp)
Definition: partyrecv.cpp:64
Party * taParty
Definition: partyrecv.cpp:48
const std::string & getName(const int id)
Definition: groupdb.cpp:344
void notify(const unsigned int message)
@ PARTY_USER_JOINED
Definition: notifytypes.h:66
@ PARTY_INVITE_ALREADY_MEMBER
Definition: notifytypes.h:67
@ PARTY_UNKNOWN_USER_MSG
Definition: notifytypes.h:82
@ PARTY_INVITE_ERROR
Definition: notifytypes.h:71
@ PARTY_INVITE_PARTY_FULL
Definition: notifytypes.h:70
@ PARTY_INVITE_REFUSED
Definition: notifytypes.h:68
@ PARTY_INVITE_DONE
Definition: notifytypes.h:69
void processPartySettings(Net::MessageIn &msg)
Definition: partyrecv.cpp:49
void processPartyUpdateHp(Net::MessageIn &msg)
Definition: partyrecv.cpp:282
void processPartyInviteResponse(Net::MessageIn &msg)
Definition: partyrecv.cpp:196
void processPartyMove(Net::MessageIn &msg)
Definition: partyrecv.cpp:251
void processPartyMessage(Net::MessageIn &msg)
Definition: partyrecv.cpp:172
void processPartyInvited(Net::MessageIn &msg)
Definition: partyrecv.cpp:225
void processPartyInfo(Net::MessageIn &msg)
Definition: partyrecv.cpp:68
bool Online
Definition: online.h:30
PartyShare ::T PartyShareT
Definition: partyshare.h:36
PartyTab * partyTab
Definition: partytab.cpp:45
SocialWindow * socialWindow