ManaPlus
playerrecv.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "net/tmwa/playerrecv.h"
25 
26 #include "actormanager.h"
27 #include "configuration.h"
28 
29 #include "being/localplayer.h"
30 #include "being/playerinfo.h"
31 
32 #include "gui/onlineplayer.h"
33 
36 
37 #include "net/messagein.h"
38 
39 #include "debug.h"
40 
41 extern unsigned int tmwServerVersion;
42 
43 namespace TmwAthena
44 {
45 
47 {
48  BLOCK_START("PlayerRecv::processPlayerStatUpdate5")
50  msg.readInt16("char points"),
51  Notify_true);
52 
53  unsigned int val = msg.readUInt8("str");
55  if (statusWindow != nullptr)
56  {
58  msg.readUInt8("str cost"));
59  }
60  else
61  {
62  msg.readUInt8("str cost");
63  }
64 
65  val = msg.readUInt8("agi");
67  if (statusWindow != nullptr)
68  {
70  msg.readUInt8("agi cost"));
71  }
72  else
73  {
74  msg.readUInt8("agi cost");
75  }
76 
77  val = msg.readUInt8("vit");
79  if (statusWindow != nullptr)
80  {
82  msg.readUInt8("vit cost"));
83  }
84  else
85  {
86  msg.readUInt8("vit cost");
87  }
88 
89  val = msg.readUInt8("int");
91  if (statusWindow != nullptr)
92  {
94  msg.readUInt8("int cost"));
95  }
96  else
97  {
98  msg.readUInt8("int cost");
99  }
100 
101  val = msg.readUInt8("dex");
103  if (statusWindow != nullptr)
104  {
106  msg.readUInt8("dex cost"));
107  }
108  else
109  {
110  msg.readUInt8("dex cost");
111  }
112 
113  val = msg.readUInt8("luk");
115  if (statusWindow != nullptr)
116  {
118  msg.readUInt8("luk cost"));
119  }
120  else
121  {
122  msg.readUInt8("luk cost");
123  }
124 
126  msg.readInt16("atk"),
127  Notify_false);
129  msg.readInt16("atk+"),
130  Notify_true);
132 
133  val = msg.readInt16("matk");
135 
136  val = msg.readInt16("matk+");
138  val,
139  Notify_true);
140 
142  msg.readInt16("def"),
143  Notify_false);
145  msg.readInt16("def+"),
146  Notify_true);
147 
149  msg.readInt16("mdef"),
150  Notify_false);
152  msg.readInt16("mdef+"),
153  Notify_true);
154 
156  msg.readInt16("hit"),
157  Notify_true);
158 
160  msg.readInt16("flee"),
161  Notify_false);
163  msg.readInt16("flee+"),
164  Notify_true);
165 
167  msg.readInt16("crit"),
168  Notify_true);
169 
171  msg.readInt16("manner"),
172  Notify_true);
173  msg.readInt16("unused?");
174  BLOCK_END("PlayerRecv::processPlayerStatUpdate5")
175 }
176 
178 {
179  BLOCK_START("PlayerRecv::processWalkResponse")
180  /*
181  * This client assumes that all walk messages succeed,
182  * and that the server will send a correction notice
183  * otherwise.
184  */
185  uint16_t srcX;
186  uint16_t srcY;
187  uint16_t dstX;
188  uint16_t dstY;
189  msg.readInt32("tick");
190  msg.readCoordinatePair(srcX, srcY, dstX, dstY, "move path");
191  msg.readUInt8("unused");
192  if (localPlayer != nullptr)
193  localPlayer->setRealPos(dstX, dstY);
194  BLOCK_END("PlayerRecv::processWalkResponse")
195 }
196 
198 {
199  if (whoIsOnline == nullptr)
200  return;
201 
202  BLOCK_START("PlayerRecv::processOnlineList")
203  const int count = (msg.readInt16("len") - 4) / 31;
204  STD_VECTOR<OnlinePlayer*> arr;
205 
206  if (count == 0)
207  {
208  if (whoIsOnline != nullptr)
209  whoIsOnline->loadList(arr);
210  BLOCK_END("PlayerRecv::processOnlineList")
211  return;
212  }
213 
214  for (int f = 0; f < count; f ++)
215  {
216  const BeingId beingId = msg.readBeingId("account id");
217  const std::string name = msg.readString(24, "name");
218  const unsigned char level = msg.readUInt8("level");
219  const unsigned char group = msg.readUInt8("group");
220  GenderT gender = Being::intToGender(msg.readUInt8("gender"));
221 
222  if (!config.getBoolValue("showgender"))
223  gender = Gender::UNSPECIFIED;
224  arr.push_back(new OnlinePlayer(name,
225  CAST_U8(255), level, gender, 0, group));
226  if (actorManager)
227  actorManager->updateNameId(name, beingId);
228  }
229 
230  if (whoIsOnline != nullptr)
231  whoIsOnline->loadList(arr);
232  BLOCK_END("PlayerRecv::processOnlineList")
233 }
234 
235 } // namespace TmwAthena
ActorManager * actorManager
int BeingId
Definition: beingid.h:30
#define CAST_U8
Definition: cast.h:27
void updateNameId(const std::string &name, const BeingId beingId)
static GenderT intToGender(const uint8_t sex) A_CONST
Definition: being.h:941
bool getBoolValue(const std::string &key) const
void setRealPos(const int x, const int y)
void setPointsNeeded(const AttributesT id, const int needed)
void loadList(const std::vector< OnlinePlayer * > &list)
Configuration config
Gender ::T GenderT
Definition: gender.h:35
LocalPlayer * localPlayer
bool msg(InputEvent &event)
Definition: chat.cpp:39
@ PLAYER_CHAR_POINTS
Definition: attributes.h:49
@ PLAYER_MANNER
Definition: attributes.h:56
@ UNSPECIFIED
Definition: gender.h:33
void setStatMod(const AttributesT id, const int value, const Notify notify)
Definition: playerinfo.cpp:159
void setAttribute(const AttributesT id, const int64_t value, const Notify notify)
Definition: playerinfo.cpp:110
void updateAttrs()
Definition: playerinfo.cpp:420
void setStatBase(const AttributesT id, const int value, const Notify notify)
Definition: playerinfo.cpp:143
void processOnlineList(Net::MessageIn &msg)
Definition: playerrecv.cpp:197
void processPlayerStatUpdate5(Net::MessageIn &msg)
Definition: playerrecv.cpp:46
void processWalkResponse(Net::MessageIn &msg)
Definition: playerrecv.cpp:177
const bool Notify_false
Definition: notify.h:30
const bool Notify_true
Definition: notify.h:30
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
StatusWindow * statusWindow
unsigned int tmwServerVersion
Definition: client.cpp:134
WhoIsOnline * whoIsOnline
Definition: whoisonline.cpp:82