ManaPlus
Functions
TmwAthena::CharServerRecv Namespace Reference

Functions

void readPlayerData (Net::MessageIn &msg, Net::Character *const character)
 
void processCharCreate (Net::MessageIn &msg)
 
void processCharDeleteFailed (Net::MessageIn &msg)
 
void processCharLogin (Net::MessageIn &msg)
 
void processCharMapInfo (Net::MessageIn &msg)
 
void processChangeMapServer (Net::MessageIn &msg)
 

Function Documentation

◆ processChangeMapServer()

void TmwAthena::CharServerRecv::processChangeMapServer ( Net::MessageIn msg)

Definition at line 237 of file charserverrecv.cpp.

238 {
239  Network *const network = Network::mInstance;
240  ServerInfo &server = mapServer;
241  BLOCK_START("CharServerRecv::processChangeMapServer")
242  if (network == nullptr)
243  {
244  BLOCK_END("CharServerRecv::processChangeMapServer")
245  return;
246  }
247  GameHandler::setMap(msg.readString(16, "map name"));
248  const int x = msg.readInt16("x");
249  const int y = msg.readInt16("y");
250  if (config.getBoolValue("usePersistentIP") || settings.persistentIp)
251  {
252  msg.readInt32("ip address");
253  server.hostname = settings.serverName;
254  }
255  else
256  {
257  server.hostname = ipToString(msg.readInt32("ip address"));
258  }
259  server.port = msg.readInt16("port");
260 
261  network->disconnect();
263  if (localPlayer != nullptr)
264  {
266  localPlayer->setMap(nullptr);
267  }
268  BLOCK_END("CharServerRecv::processChangeMapServer")
269 }
void setState(const StateT state)
Definition: client.h:66
void setTileCoords(const int x, const int y)
void setMap(Map *const map)
std::string hostname
Definition: serverinfo.h:45
uint16_t port
Definition: serverinfo.h:58
std::string serverName
Definition: settings.h:114
Configuration config
Client * client
Definition: client.cpp:118
if(!vert) return
LocalPlayer * localPlayer
bool msg(InputEvent &event)
Definition: chat.cpp:39
ServerInfo mapServer
@ CHANGE_MAP
Definition: state.h:50
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
Settings settings
Definition: settings.cpp:32
const char * ipToString(const uint32_t address)
Definition: stringutils.cpp:86

References BLOCK_END, BLOCK_START, State::CHANGE_MAP, client, config, Ea::Network::disconnect(), Configuration::getBoolValue(), ServerInfo::hostname, ipToString(), localPlayer, TmwAthena::mapServer, TmwAthena::Network::mInstance, Actions::msg(), Settings::persistentIp, ServerInfo::port, Settings::serverName, Ea::GameHandler::setMap(), LocalPlayer::setMap(), Client::setState(), LocalPlayer::setTileCoords(), settings, x, and y.

◆ processCharCreate()

void TmwAthena::CharServerRecv::processCharCreate ( Net::MessageIn msg)

Definition at line 271 of file charserverrecv.cpp.

272 {
273  BLOCK_START("CharServerRecv::processCharCreate")
274  Net::Character *const character = new Net::Character;
275  readPlayerData(msg, character);
276  Net::CharServerHandler::mCharacters.push_back(character);
277 
278  Net::CharServerHandler::updateCharSelectDialog();
279 
280  // Close the character create dialog
281  Net::CharServerHandler::mCharCreateDialog->scheduleDelete();
282  Net::CharServerHandler::mCharCreateDialog = nullptr;
283  BLOCK_END("CharServerRecv::processCharCreate")
284 }
#define new
Definition: debug_new.h:147
void processCharCreate(Net::MessageIn &msg)
void readPlayerData(Net::MessageIn &msg, Net::Character *const character)
void scheduleDelete(SDL_Surface *const surface)

References BLOCK_END, BLOCK_START, Net::CharServerHandler::mCharacters, Net::CharServerHandler::mCharCreateDialog, Actions::msg(), EAthena::CharServerRecv::readPlayerData(), Window::scheduleDelete(), and Net::CharServerHandler::updateCharSelectDialog().

◆ processCharDeleteFailed()

void TmwAthena::CharServerRecv::processCharDeleteFailed ( Net::MessageIn msg)

Definition at line 286 of file charserverrecv.cpp.

287 {
288  BLOCK_START("CharServerRecv::processCharDeleteFailed")
289  Net::CharServerHandler::unlockCharSelectDialog();
290  msg.readUInt8("error");
292  // TRANSLATORS: error header
293  _("Error"),
294  // TRANSLATORS: error message
295  _("Failed to delete character."),
296  // TRANSLATORS: ok dialog button
297  _("OK"),
298  DialogType::ERROR,
299  Modal_true,
301  nullptr,
302  260);
303  BLOCK_END("CharServerRecv::processCharDeleteFailed")
304 }
#define CREATEWIDGET(type,...)
Definition: createwidget.h:29
#define _(s)
Definition: gettext.h:35
const bool Modal_true
Definition: modal.h:30
bool error(InputEvent &event) __attribute__((noreturn))
Definition: actions.cpp:82
void processCharDeleteFailed(Net::MessageIn &msg)
const bool ShowCenter_true
Definition: showcenter.h:30

References _, BLOCK_END, BLOCK_START, CREATEWIDGET, DialogType::ERROR, Modal_true, Actions::msg(), ShowCenter_true, and Net::CharServerHandler::unlockCharSelectDialog().

◆ processCharLogin()

void TmwAthena::CharServerRecv::processCharLogin ( Net::MessageIn msg)

Definition at line 170 of file charserverrecv.cpp.

171 {
172  BLOCK_START("CharServerRecv::processCharLogin")
173 
174  msg.readInt16("len");
175  const int slots = msg.readInt16("slots");
176  if (slots > 0 && slots < 30)
177  loginData.characterSlots = CAST_U16(slots);
178 
179  msg.skip(18, "unused");
180 
181  delete_all(Net::CharServerHandler::mCharacters);
182  Net::CharServerHandler::mCharacters.clear();
183 
184  // Derive number of characters from message length
185  const int count = (msg.getLength() - 24) / 106;
186 
187  for (int i = 0; i < count; ++i)
188  {
189  Net::Character *const character = new Net::Character;
190  readPlayerData(msg, character);
191  Net::CharServerHandler::mCharacters.push_back(character);
192  if (character->dummy != nullptr)
193  {
194  logger->log("CharServer: Player: %s (%d)",
195  character->dummy->getName().c_str(), character->slot);
196  }
197  }
198 
200  BLOCK_END("CharServerRecv::processCharLogin")
201 }
#define CAST_U16
Definition: cast.h:29
const std::string & getName() const
Definition: being.h:232
void log(const char *const log_text,...)
Definition: logger.cpp:269
static Net::Characters mCharacters
void delete_all(Container &c)
Definition: dtor.h:56
Logger * logger
Definition: logger.cpp:89
LoginData loginData
Definition: client.cpp:185
void clear()
Definition: playerinfo.cpp:452
@ CHAR_SELECT
Definition: state.h:47
LocalPlayer * dummy
Definition: character.h:56
uint16_t slot
Definition: character.h:58

References BLOCK_END, BLOCK_START, CAST_U16, State::CHAR_SELECT, LoginData::characterSlots, client, delete_all(), Net::Character::dummy, Being::getName(), Logger::log(), logger, loginData, Net::CharServerHandler::mCharacters, Actions::msg(), EAthena::CharServerRecv::readPlayerData(), Client::setState(), and Net::Character::slot.

◆ processCharMapInfo()

void TmwAthena::CharServerRecv::processCharMapInfo ( Net::MessageIn msg)

Definition at line 203 of file charserverrecv.cpp.

204 {
205  Network *const network = Network::mInstance;
206  ServerInfo &server = mapServer;
207  BLOCK_START("CharServerRecv::processCharMapInfo")
208  PlayerInfo::setCharId(msg.readInt32("char id?"));
209  GameHandler::setMap(msg.readString(16, "map name"));
210  if (config.getBoolValue("usePersistentIP") || settings.persistentIp)
211  {
212  msg.readInt32("ip address");
213  server.hostname = settings.serverName;
214  }
215  else
216  {
217  server.hostname = ipToString(msg.readInt32("ip address"));
218  }
219  server.port = msg.readInt16("port");
221 
222  // Prevent the selected local player from being deleted
225 
227 
230 
231  if (network != nullptr)
232  network->disconnect();
234  BLOCK_END("CharServerRecv::processCharMapInfo")
235 }
Net::CharServerHandler * charServerHandler
Definition: net.cpp:85
static void updateCharSelectDialog()
virtual void clear() const =0
static Net::Character * mSelectedCharacter
std::string althostname
Definition: serverinfo.h:46
uint32_t data
ServerInfo charServer
void setBackend(const PlayerInfoBackend &backend)
Definition: playerinfo.cpp:376
void setCharId(const int charId)
Definition: playerinfo.cpp:381
@ CONNECT_GAME
Definition: state.h:48

References ServerInfo::althostname, BLOCK_END, BLOCK_START, TmwAthena::charServer, charServerHandler, Net::CharServerHandler::clear(), client, config, State::CONNECT_GAME, data, Ea::Network::disconnect(), Net::Character::dummy, Configuration::getBoolValue(), ServerInfo::hostname, ipToString(), localPlayer, TmwAthena::mapServer, TmwAthena::Network::mInstance, Net::CharServerHandler::mSelectedCharacter, Actions::msg(), Settings::persistentIp, ServerInfo::port, Settings::serverName, PlayerInfo::setBackend(), PlayerInfo::setCharId(), Ea::GameHandler::setMap(), Client::setState(), settings, and Net::CharServerHandler::updateCharSelectDialog().

◆ readPlayerData()

void TmwAthena::CharServerRecv::readPlayerData ( Net::MessageIn msg,
Net::Character *const  character 
)

Definition at line 63 of file charserverrecv.cpp.

65 {
66  if (character == nullptr)
67  return;
68 
69  const Token &token =
70  static_cast<LoginHandler*>(loginHandler)->getToken();
71 
72  LocalPlayer *const tempPlayer = new LocalPlayer(
73  msg.readBeingId("account id"), BeingTypeId_zero);
74 
75  PlayerInfoBackend &data = character->data;
76  data.mAttributes[Attributes::PLAYER_EXP] = msg.readInt32("base exp");
77  data.mAttributes[Attributes::MONEY] = msg.readInt32("money");
78  data.mAttributes[Attributes::PLAYER_JOB_EXP] = msg.readInt32("job exp");
79  data.mAttributes[Attributes::PLAYER_JOB_LEVEL] =
80  msg.readInt32("job level");
81 
82  const int shoes = msg.readInt16("shoes");
83  const int gloves = msg.readInt16("gloves");
84  const int cape = msg.readInt16("cape");
85  const int misc1 = msg.readInt16("misc1");
86 
87  msg.readInt32("option");
88  tempPlayer->setKarma(msg.readInt32("karma"));
89  tempPlayer->setManner(msg.readInt32("manner"));
90  msg.readInt16("character points left");
91 
92  data.mAttributes[Attributes::PLAYER_HP] = msg.readInt16("hp");
93  data.mAttributes[Attributes::PLAYER_MAX_HP] = msg.readInt16("max hp");
94  data.mAttributes[Attributes::PLAYER_MP] = msg.readInt16("mp");
95  data.mAttributes[Attributes::PLAYER_MAX_MP] = msg.readInt16("max mp");
96 
97  msg.readInt16("speed");
98  const uint16_t race = msg.readInt16("class");
99  const uint8_t hairStyle = msg.readUInt8("hair style");
100  const uint16_t look = msg.readUInt8("look");
101  tempPlayer->setSubtype(fromInt(race, BeingTypeId), look);
102  const uint16_t weapon = msg.readInt16("weapon");
103  tempPlayer->setSpriteId(SPRITE_BODY,
104  weapon);
105  tempPlayer->setWeaponId(weapon);
106 
107  data.mAttributes[Attributes::PLAYER_BASE_LEVEL] = msg.readInt16("level");
108 
109  msg.readInt16("skill point");
110  const int bottomClothes = msg.readInt16("bottom clothes");
111  const int shield = msg.readInt16("shield");
112 
113  const int hat = msg.readInt16("hat");
114  const int topClothes = msg.readInt16("top clothes");
115 
116  const ItemColor hairColor = fromInt(
117  msg.readUInt8("hair color"), ItemColor);
118  msg.readUInt8("unused");
119  if (hairStyle == 0)
120  {
121  tempPlayer->unSetSprite(SPRITE_HAIR_COLOR);
122  }
123  else
124  {
125  tempPlayer->setSpriteColor(SPRITE_HAIR_COLOR,
126  hairStyle * -1,
127  ItemDB::get(-hairStyle).getDyeColorsString(hairColor));
128  }
129  tempPlayer->setHairColor(hairColor);
130 
131  const int misc2 = msg.readInt16("misc2");
132  tempPlayer->setName(msg.readString(24, "name"));
133 
134  character->dummy = tempPlayer;
135 
136  character->data.mStats[Attributes::PLAYER_STR].base = msg.readUInt8("str");
137  character->data.mStats[Attributes::PLAYER_AGI].base = msg.readUInt8("agi");
138  character->data.mStats[Attributes::PLAYER_VIT].base = msg.readUInt8("vit");
139  character->data.mStats[Attributes::PLAYER_INT].base = msg.readUInt8("int");
140  character->data.mStats[Attributes::PLAYER_DEX].base = msg.readUInt8("dex");
141  character->data.mStats[Attributes::PLAYER_LUK].base = msg.readUInt8("luk");
142 
143  tempPlayer->setSpriteId(SPRITE_HAIR,
144  shoes);
145  tempPlayer->setSpriteId(SPRITE_SHOES,
146  gloves);
147  tempPlayer->setSpriteId(SPRITE_SHIELD,
148  cape);
149  tempPlayer->setSpriteId(SPRITE_HEAD_TOP,
150  misc1);
151  tempPlayer->setSpriteId(SPRITE_WEAPON,
152  bottomClothes);
153  tempPlayer->setSpriteId(SPRITE_FLOOR,
154  shield);
155  tempPlayer->setSpriteId(SPRITE_CLOTHES_COLOR,
156  hat);
157  tempPlayer->setSpriteId(SPRITE_HEAD_BOTTOM,
158  topClothes);
159  tempPlayer->setSpriteId(SPRITE_HEAD_MID,
160  misc2);
161 
162  character->slot = msg.readUInt8("slot");
163  const uint8_t sex = CAST_U8(msg.readUInt8("gender"));
165  tempPlayer->setGender(Being::intToGender(sex));
166  else
167  tempPlayer->setGender(token.sex);
168 }
int BeingTypeId
Definition: beingtypeid.h:30
const BeingTypeId BeingTypeId_zero
Definition: beingtypeid.h:30
#define CAST_U8
Definition: cast.h:27
void setKarma(const int karma)
Definition: being.h:1031
void setWeaponId(const int id)
Definition: being.cpp:3135
static GenderT intToGender(const uint8_t sex) A_CONST
Definition: being.h:941
void setName(const std::string &name)
Definition: being.cpp:1136
void setSubtype(const BeingTypeId subtype, const uint16_t look)
Definition: being.cpp:371
void setHairColor(const unsigned int slot, const ItemColor color)
Definition: being.cpp:3389
void setSpriteId(const unsigned int slot, const int id)
Definition: being.cpp:2789
virtual void setGender(const GenderT gender)
Definition: being.cpp:3581
void unSetSprite(const unsigned int slot)
Definition: being.cpp:2861
void setManner(const int manner)
Definition: being.h:1037
void setSpriteColor(const unsigned int slot, const int id, const std::string &color)
Definition: being.cpp:2890
virtual bool haveCreateCharGender() const =0
#define fromInt(val, name)
Definition: intdefines.h:46
uint16_t ItemColor
Definition: itemcolor.h:30
Net::LoginHandler * loginHandler
Definition: net.cpp:90
bool hat(InputEvent &event)
Definition: chat.cpp:62
@ PLAYER_MAX_MP
Definition: attributes.h:35
@ PLAYER_BASE_LEVEL
Definition: attributes.h:31
@ PLAYER_JOB_EXP
Definition: attributes.h:66
@ PLAYER_JOB_LEVEL
Definition: attributes.h:41
@ PLAYER_MAX_HP
Definition: attributes.h:33
const ItemInfo & get(const int id)
Definition: itemdb.cpp:792
@ SPRITE_HAIR_COLOR
Definition: sprite.h:35
@ SPRITE_WEAPON
Definition: sprite.h:31
@ SPRITE_FLOOR
Definition: sprite.h:40
@ SPRITE_HEAD_TOP
Definition: sprite.h:33
@ SPRITE_SHOES
Definition: sprite.h:38
@ SPRITE_SHIELD
Definition: sprite.h:37
@ SPRITE_HEAD_MID
Definition: sprite.h:34
@ SPRITE_BODY
Definition: sprite.h:39
@ SPRITE_CLOTHES_COLOR
Definition: sprite.h:36
@ SPRITE_HEAD_BOTTOM
Definition: sprite.h:32
Net::ServerFeatures * serverFeatures
Definition: net.cpp:101
PlayerInfoBackend data
Definition: character.h:57
Definition: token.h:31
GenderT sex
Definition: token.h:44

References BeingTypeId_zero, CAST_U8, Net::Character::data, data, Net::Character::dummy, fromInt, ItemDB::get(), Actions::hat(), Net::ServerFeatures::haveCreateCharGender(), Being::intToGender(), loginHandler, Attributes::MONEY, Actions::msg(), PlayerInfoBackend::mStats, Attributes::PLAYER_AGI, Attributes::PLAYER_BASE_LEVEL, Attributes::PLAYER_DEX, Attributes::PLAYER_EXP, Attributes::PLAYER_HP, Attributes::PLAYER_INT, Attributes::PLAYER_JOB_EXP, Attributes::PLAYER_JOB_LEVEL, Attributes::PLAYER_LUK, Attributes::PLAYER_MAX_HP, Attributes::PLAYER_MAX_MP, Attributes::PLAYER_MP, Attributes::PLAYER_STR, Attributes::PLAYER_VIT, serverFeatures, Being::setGender(), Being::setHairColor(), Being::setKarma(), Being::setManner(), Being::setName(), Being::setSpriteColor(), Being::setSpriteId(), Being::setSubtype(), Being::setWeaponId(), Token::sex, Net::Character::slot, SPRITE_BODY, SPRITE_CLOTHES_COLOR, SPRITE_FLOOR, ItemDbType::SPRITE_HAIR, SPRITE_HAIR_COLOR, SPRITE_HEAD_BOTTOM, SPRITE_HEAD_MID, SPRITE_HEAD_TOP, SPRITE_SHIELD, SPRITE_SHOES, SPRITE_WEAPON, and Being::unSetSprite().