From 1263c729d85df649c7ab59726bddad7c8cd7ae81 Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Tue, 1 Oct 2013 19:22:57 +0200 Subject: Send the character data in a single message --- src/account-server/accounthandler.cpp | 52 ++++++++++++++++------------------- src/common/manaserv_protocol.h | 14 +++++----- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index 32b33501..4fc0664f 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -73,12 +73,6 @@ public: */ TokenCollector mTokenCollector; - /** - * Send the character data to the client. - */ - static void sendCharacterData(AccountClient &client, - const CharacterData &ch); - protected: /** * Processes account related messages. @@ -271,19 +265,17 @@ void AccountHandler::computerDisconnected(NetComputer *comp) delete client; // ~AccountClient unsets the account } -void AccountHandler::sendCharacterData(AccountClient &client, - const CharacterData &ch) +static void sendCharacterData(MessageOut &charInfo, const CharacterData *ch) { - MessageOut charInfo(APMSG_CHAR_INFO); - charInfo.writeInt8(ch.getCharacterSlot()); - charInfo.writeString(ch.getName()); - charInfo.writeInt8(ch.getGender()); - charInfo.writeInt8(ch.getHairStyle()); - charInfo.writeInt8(ch.getHairColor()); - charInfo.writeInt16(ch.getAttributePoints()); - charInfo.writeInt16(ch.getCorrectionPoints()); - - auto &possessions = ch.getPossessions(); + charInfo.writeInt8(ch->getCharacterSlot()); + charInfo.writeString(ch->getName()); + charInfo.writeInt8(ch->getGender()); + charInfo.writeInt8(ch->getHairStyle()); + charInfo.writeInt8(ch->getHairColor()); + charInfo.writeInt16(ch->getAttributePoints()); + charInfo.writeInt16(ch->getCorrectionPoints()); + + auto &possessions = ch->getPossessions(); auto &equipData = possessions.getEquipment(); auto &inventoryData = possessions.getInventory(); charInfo.writeInt8(equipData.size()); @@ -295,15 +287,22 @@ void AccountHandler::sendCharacterData(AccountClient &client, charInfo.writeInt16(it->second.itemId); } - for (auto &it : ch.getAttributes()) + charInfo.writeInt8(ch->getAttributes().size()); + for (auto &it : ch->getAttributes()) { // {id, base value in 256ths, modified value in 256ths }* charInfo.writeInt32(it.first); charInfo.writeInt32((int) (it.second.base * 256)); charInfo.writeInt32((int) (it.second.modified * 256)); } +} - client.send(charInfo); +static void sendFullCharacterData(AccountClient *client, Characters &chars) +{ + MessageOut msg(APMSG_CHAR_INFO); + for (auto &charIt : chars) + sendCharacterData(msg, charIt.second); + client->send(msg); } std::string getRandomString(int length) @@ -431,9 +430,7 @@ void AccountHandler::handleLoginMessage(AccountClient &client, MessageIn &msg) Characters &chars = acc->getCharacters(); // Send characters list - for (Characters::const_iterator i = chars.begin(), i_end = chars.end(); - i != i_end; ++i) - sendCharacterData(client, *(*i).second); + sendFullCharacterData(&client, chars); } void AccountHandler::handleLogoutMessage(AccountClient &client) @@ -831,10 +828,9 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, storage->addTransaction(trans); reply.writeInt8(ERRMSG_OK); - client.send(reply); - // Send new characters infos back to client - sendCharacterData(client, *chars[slot]); + sendCharacterData(reply, newCharacter); + client.send(reply); return; } } @@ -990,9 +986,7 @@ void AccountHandler::tokenMatched(AccountClient *client, int accountID) Characters &chars = acc->getCharacters(); // Send characters list - for (Characters::const_iterator i = chars.begin(), i_end = chars.end(); - i != i_end; ++i) - sendCharacterData(*client, *(*i).second); + sendFullCharacterData(client, chars); } void AccountHandler::deletePendingClient(AccountClient *client) diff --git a/src/common/manaserv_protocol.h b/src/common/manaserv_protocol.h index 26db32c6..9d562037 100644 --- a/src/common/manaserv_protocol.h +++ b/src/common/manaserv_protocol.h @@ -29,7 +29,7 @@ namespace ManaServ { enum { - PROTOCOL_VERSION = 8, + PROTOCOL_VERSION = 9, SUPPORTED_DB_VERSION = 26 }; @@ -79,14 +79,14 @@ enum { PAMSG_LOGIN_RNDTRGR = 0x0015, // S username APMSG_LOGIN_RNDTRGR_RESPONSE = 0x0016, // S random seed PAMSG_CHAR_CREATE = 0x0020, // S name, B hair style, B hair color, B gender, B slot, {W stats}* - APMSG_CHAR_CREATE_RESPONSE = 0x0021, // B error + APMSG_CHAR_CREATE_RESPONSE = 0x0021, // B error, on success: B slot, S name, B gender, B hair style, B hair color, + // W character points, W correction points, B amount of items equipped, + // { W slot, W itemId }* + // B attributeCount, + // {D attr id, D base value (in 1/256ths) D mod value (in 256ths) }* PAMSG_CHAR_DELETE = 0x0022, // B slot APMSG_CHAR_DELETE_RESPONSE = 0x0023, // B error - // B slot, S name, B gender, B hair style, B hair color, - // W character points, W correction points, B amount of items equipped, - // { W slot, W itemId }* - // {D attr id, D base value (in 1/256ths) D mod value (in 256ths) }* - APMSG_CHAR_INFO = 0x0024, // ^ + APMSG_CHAR_INFO = 0x0024, // {content of APMSG_CHAR_CREATE_RESPONSE (without error code)}* PAMSG_CHAR_SELECT = 0x0026, // B slot APMSG_CHAR_SELECT_RESPONSE = 0x0027, // B error, B*32 token, S game address, W game port, S chat address, W chat port PAMSG_EMAIL_CHANGE = 0x0030, // S email -- cgit v1.2.3-60-g2f50