ManaPlus
Functions
Ea::PlayerRecv Namespace Reference

Functions

void processPlayerWarp (Net::MessageIn &msg)
 
void processPlayerStatUpdate1 (Net::MessageIn &msg)
 
void processPlayerStatUpdate2 (Net::MessageIn &msg)
 
void processPlayerStatUpdate3 (Net::MessageIn &msg)
 
void processPlayerStatUpdate4 (Net::MessageIn &msg)
 
void processPlayerStatUpdate6 (Net::MessageIn &msg)
 
void processPlayerArrowMessage (Net::MessageIn &msg)
 
void processPlayerClientCommand (Net::MessageIn &msg)
 
void processMapMusic (Net::MessageIn &msg)
 
void processMapMask (Net::MessageIn &msg)
 

Function Documentation

◆ processMapMask()

void Ea::PlayerRecv::processMapMask ( Net::MessageIn msg)

Definition at line 238 of file playerrecv.cpp.

239 {
240  const int mask = msg.readInt32("mask");
241  msg.readInt32("unused");
242  Map *const map = Game::instance()->getCurrentMap();
243  if (map != nullptr)
244  map->setMask(mask);
245 }
Map * getCurrentMap() const
Definition: game.h:107
static Game * instance()
Definition: game.h:82
Definition: map.h:75
void setMask(const int mask)
Definition: map.cpp:1676
bool msg(InputEvent &event)
Definition: chat.cpp:39

References Game::getCurrentMap(), Game::instance(), Actions::msg(), and Map::setMask().

◆ processMapMusic()

void Ea::PlayerRecv::processMapMusic ( Net::MessageIn msg)

Definition at line 226 of file playerrecv.cpp.

227 {
228  const int size = msg.readInt16("len") - 4;
229  const std::string music = msg.readString(size, "name");
230  soundManager.playMusic(music,
232 
233  Map *const map = viewport->getMap();
234  if (map != nullptr)
235  map->setMusicFile(music);
236 }
void setMusicFile(const std::string &file)
Definition: map.cpp:1686
void playMusic(const std::string &fileName, const SkipError skipError)
Map * getMap() const
Definition: viewport.h:135
Viewport * viewport
Definition: viewport.cpp:36
int size()
Definition: emotedb.cpp:306
const bool SkipError_false
Definition: skiperror.h:30
SoundManager soundManager

References Viewport::getMap(), Actions::msg(), SoundManager::playMusic(), Map::setMusicFile(), EmoteDB::size(), SkipError_false, soundManager, and viewport.

◆ processPlayerArrowMessage()

void Ea::PlayerRecv::processPlayerArrowMessage ( Net::MessageIn msg)

Definition at line 207 of file playerrecv.cpp.

208 {
209  BLOCK_START("PlayerRecv::processPlayerArrowMessage")
210  const int type = msg.readInt16("type");
211  switch (type)
212  {
213  case 0:
215  break;
216  case 3:
217  // arrows equiped
218  break;
219  default:
221  break;
222  }
223  BLOCK_END("PlayerRecv::processPlayerArrowMessage")
224 }
#define UNIMPLEMENTEDPACKETFIELD(field)
Definition: logger.h:59
void notify(const unsigned int message)
@ ARROWS_EQUIP_NEEDED
Definition: notifytypes.h:87
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79

References NotifyTypes::ARROWS_EQUIP_NEEDED, BLOCK_END, BLOCK_START, Actions::msg(), NotifyManager::notify(), and UNIMPLEMENTEDPACKETFIELD.

◆ processPlayerClientCommand()

void Ea::PlayerRecv::processPlayerClientCommand ( Net::MessageIn msg)

Definition at line 247 of file playerrecv.cpp.

248 {
249  const int sz = msg.readInt16("len") - 4;
250  std::string command = msg.readString(sz, "command");
251  std::string cmd;
252  std::string args;
253 
254  if (settings.awayMode ||
257  {
258  return;
259  }
260 
261  if (!parse2Str(command, cmd, args))
262  {
263  cmd = STD_MOVE(command);
264  args.clear();
265  }
266  inputManager.executeRemoteChatCommand(cmd, args, nullptr);
267 }
bool executeRemoteChatCommand(const std::string &cmd, const std::string &args, ChatTab *const tab)
bool awayMode
Definition: settings.h:158
bool enableRemoteCommands
Definition: settings.h:162
bool pseudoAwayMode
Definition: settings.h:159
InputManager inputManager
Settings settings
Definition: settings.cpp:32
#define STD_MOVE(var)
Definition: stdmove.h:28
bool parse2Str(const std::string &args, std::string &str1, std::string &str2)

References Settings::awayMode, Settings::enableRemoteCommands, InputManager::executeRemoteChatCommand(), inputManager, Actions::msg(), parse2Str(), Settings::pseudoAwayMode, settings, and STD_MOVE.

◆ processPlayerStatUpdate1()

void Ea::PlayerRecv::processPlayerStatUpdate1 ( Net::MessageIn msg)

Definition at line 139 of file playerrecv.cpp.

140 {
141  BLOCK_START("PlayerRecv::processPlayerStatUpdate1")
142  const int type = msg.readInt16("type");
143  const int value = msg.readInt32("value");
144  if (localPlayer == nullptr)
145  {
146  BLOCK_END("PlayerRecv::processPlayerStatUpdate1")
147  return;
148  }
149 
150  playerHandler->setStat(msg, type, value, NoStat, Notify_true);
151  BLOCK_END("PlayerRecv::processPlayerStatUpdate1")
152 }
if(!vert) return
LocalPlayer * localPlayer
void processPlayerStatUpdate1(Net::MessageIn &msg)
Definition: playerrecv.cpp:139
Net::PlayerHandler * playerHandler
Definition: net.cpp:96
static const int NoStat
Definition: nostat.h:27
const bool Notify_true
Definition: notify.h:30

References BLOCK_END, BLOCK_START, localPlayer, Actions::msg(), NoStat, Notify_true, playerHandler, and Net::PlayerHandler::setStat().

◆ processPlayerStatUpdate2()

void Ea::PlayerRecv::processPlayerStatUpdate2 ( Net::MessageIn msg)

Definition at line 154 of file playerrecv.cpp.

155 {
156  BLOCK_START("PlayerRecv::processPlayerStatUpdate2")
157  const int type = msg.readInt16("type");
158  const int value = msg.readInt32("value");
159  playerHandler->setStat(msg, type, value, NoStat, Notify_true);
160  BLOCK_END("PlayerRecv::processPlayerStatUpdate2")
161 }
void processPlayerStatUpdate2(Net::MessageIn &msg)
Definition: playerrecv.cpp:154

References BLOCK_END, BLOCK_START, Actions::msg(), NoStat, Notify_true, playerHandler, and Net::PlayerHandler::setStat().

◆ processPlayerStatUpdate3()

void Ea::PlayerRecv::processPlayerStatUpdate3 ( Net::MessageIn msg)

Definition at line 163 of file playerrecv.cpp.

164 {
165  BLOCK_START("PlayerRecv::processPlayerStatUpdate3")
166  const int type = msg.readInt32("type");
167  const int base = msg.readInt32("base");
168  const int bonus = msg.readInt32("bonus");
169 
170  playerHandler->setStat(msg, type, base, bonus, Notify_false);
171  BLOCK_END("PlayerRecv::processPlayerStatUpdate3")
172 }
void processPlayerStatUpdate3(Net::MessageIn &msg)
Definition: playerrecv.cpp:163
const bool Notify_false
Definition: notify.h:30

References anonymous_namespace{stringutils.cpp}::base, BLOCK_END, BLOCK_START, Actions::msg(), Notify_false, playerHandler, and Net::PlayerHandler::setStat().

◆ processPlayerStatUpdate4()

void Ea::PlayerRecv::processPlayerStatUpdate4 ( Net::MessageIn msg)

Definition at line 174 of file playerrecv.cpp.

175 {
176  BLOCK_START("PlayerRecv::processPlayerStatUpdate4")
177  const uint16_t type = msg.readInt16("type");
178  const uint8_t ok = msg.readUInt8("flag");
179  const int value = msg.readUInt8("value");
180 
181  if (ok != 1)
182  {
183  const int oldValue = PlayerInfo::getStatBase(
184  static_cast<AttributesT>(type));
185  const int points = PlayerInfo::getAttribute(
186  Attributes::PLAYER_CHAR_POINTS) + oldValue - value;
188  points,
189  Notify_true);
191  }
192 
193  playerHandler->setStat(msg, type, value, NoStat, Notify_true);
194  BLOCK_END("PlayerRecv::processPlayerStatUpdate4")
195 }
Attributes ::T AttributesT
Definition: attributes.h:118
virtual void setStat(Net::MessageIn &msg, const int type, const int64_t base, const int mod, const Notify notify) const =0
bool ok(InputEvent &event)
Definition: actions.cpp:34
@ PLAYER_CHAR_POINTS
Definition: attributes.h:49
@ SKILL_RAISE_ERROR
Definition: notifytypes.h:86
int getStatBase(const AttributesT id)
Definition: playerinfo.cpp:135
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:102
void setAttribute(const AttributesT id, const int64_t value, const Notify notify)
Definition: playerinfo.cpp:110

References BLOCK_END, BLOCK_START, PlayerInfo::getAttribute(), PlayerInfo::getStatBase(), Actions::msg(), NoStat, NotifyManager::notify(), Notify_true, Actions::ok(), Attributes::PLAYER_CHAR_POINTS, playerHandler, PlayerInfo::setAttribute(), Net::PlayerHandler::setStat(), and NotifyTypes::SKILL_RAISE_ERROR.

◆ processPlayerStatUpdate6()

void Ea::PlayerRecv::processPlayerStatUpdate6 ( Net::MessageIn msg)

Definition at line 197 of file playerrecv.cpp.

198 {
199  BLOCK_START("PlayerRecv::processPlayerStatUpdate6")
200  const int type = msg.readInt16("type");
201  const int value = msg.readUInt8("value");
202  if (statusWindow != nullptr)
203  playerHandler->setStat(msg, type, value, NoStat, Notify_true);
204  BLOCK_END("PlayerRecv::processPlayerStatUpdate6")
205 }
void processPlayerStatUpdate6(Net::MessageIn &msg)
Definition: playerrecv.cpp:197
StatusWindow * statusWindow

References BLOCK_END, BLOCK_START, Actions::msg(), NoStat, Notify_true, playerHandler, Net::PlayerHandler::setStat(), and statusWindow.

◆ processPlayerWarp()

void Ea::PlayerRecv::processPlayerWarp ( Net::MessageIn msg)

Definition at line 60 of file playerrecv.cpp.

61 {
62  BLOCK_START("PlayerRecv::processPlayerWarp")
63  std::string mapPath = msg.readString(16, "map name");
64  int x = msg.readInt16("x");
65  int y = msg.readInt16("y");
66 
67  logger->log("Warping to %s (%d, %d)", mapPath.c_str(), x, y);
68 
69  if (localPlayer == nullptr)
70  logger->log1("SMSG_PLAYER_WARP localPlayer null");
71 
72  /*
73  * We must clear the local player's target *before* the call
74  * to changeMap, as it deletes all beings.
75  */
76  if (localPlayer != nullptr)
77  localPlayer->stopAttack(false);
78 
79  Game *const game = Game::instance();
80  if (game == nullptr)
81  {
82  BLOCK_END("PlayerRecv::processPlayerWarp")
83  return;
84  }
85 
86  const std::string &currentMapName = game->getCurrentMapName();
87  const bool sameMap = (currentMapName == mapPath);
88 
89  // Switch the actual map, deleting the previous one if necessary
90  mapPath = mapPath.substr(0, mapPath.rfind('.'));
91  game->changeMap(mapPath);
92 
93  int scrollOffsetX = 0;
94  int scrollOffsetY = 0;
95 
96  if (localPlayer != nullptr)
97  {
98  const Map *const map = game->getCurrentMap();
99  if (map != nullptr)
100  {
101  if (x >= map->getWidth())
102  x = map->getWidth() - 1;
103  if (y >= map->getHeight())
104  y = map->getHeight() - 1;
105  if (x < 0)
106  x = 0;
107  if (y < 0)
108  y = 0;
109  /* Scroll if neccessary */
110  if (!sameMap
111  || (abs(x - localPlayer->getTileX())
113  || (abs(y - localPlayer->getTileY())
115  {
116  scrollOffsetX = (x - localPlayer->getTileX())
117  * map->getTileWidth();
118  scrollOffsetY = (y - localPlayer->getTileY())
119  * map->getTileHeight();
120  }
121  }
122 
126  localPlayer->reset();
127  }
128 
129  logger->log("Adjust scrolling by %d:%d", scrollOffsetX, scrollOffsetY);
130 
131  if (viewport != nullptr)
132  {
134  viewport->scrollBy(scrollOffsetX, scrollOffsetY);
135  }
136  BLOCK_END("PlayerRecv::processPlayerWarp")
137 }
int getTileX() const
Definition: being.h:168
int getTileY() const
Definition: being.h:174
Definition: game.h:64
void setTileCoords(const int x, const int y)
void setAction(const BeingActionT &action, const int attackId)
void navigateClean()
void log(const char *const log_text,...)
Definition: logger.cpp:269
int getHeight() const
Definition: map.h:172
int getTileHeight() const
Definition: map.h:184
int getWidth() const
Definition: map.h:166
int getTileWidth() const
Definition: map.h:178
void scrollBy(const int x, const int y)
Definition: viewport.h:127
void returnCamera()
Definition: viewport.cpp:1111
static const int MAP_TELEPORT_SCROLL_DISTANCE
Definition: playerrecv.cpp:55
Logger * logger
Definition: logger.cpp:89
bool stopAttack(InputEvent &event)
Definition: actions.cpp:56

References BLOCK_END, BLOCK_START, Game::changeMap(), Game::getCurrentMap(), Game::getCurrentMapName(), Map::getHeight(), Map::getTileHeight(), Map::getTileWidth(), Being::getTileX(), Being::getTileY(), Map::getWidth(), Game::instance(), localPlayer, Logger::log(), Logger::log1(), logger, MAP_TELEPORT_SCROLL_DISTANCE, Actions::msg(), LocalPlayer::navigateClean(), CompoundSprite::reset(), Viewport::returnCamera(), Viewport::scrollBy(), LocalPlayer::setAction(), LocalPlayer::setTileCoords(), BeingAction::STAND, LocalPlayer::stopAttack(), viewport, x, and y.