diff options
Diffstat (limited to 'src/account-server')
-rw-r--r-- | src/account-server/accounthandler.cpp | 33 | ||||
-rw-r--r-- | src/account-server/character.cpp | 4 | ||||
-rw-r--r-- | src/account-server/character.h | 3 | ||||
-rw-r--r-- | src/account-server/serverhandler.cpp | 47 | ||||
-rw-r--r-- | src/account-server/serverhandler.h | 4 | ||||
-rw-r--r-- | src/account-server/storage.cpp | 11 |
6 files changed, 43 insertions, 59 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index 2e4e5c04..9cb32af1 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -27,6 +27,7 @@ #include "account-server/serverhandler.h" #include "chat-server/chathandler.h" #include "common/configuration.h" +#include "common/defines.h" #include "common/manaserv_protocol.h" #include "common/transaction.h" #include "net/connectionhandler.h" @@ -903,7 +904,7 @@ void AccountHandler::handleCharacterSelectMessage(AccountClient &client, { MessageOut reply(APMSG_CHAR_SELECT_RESPONSE); - Account *acc = client.getAccount(); + const Account *acc = client.getAccount(); if (!acc) { reply.writeInt8(ERRMSG_NO_LOGIN); @@ -912,9 +913,10 @@ void AccountHandler::handleCharacterSelectMessage(AccountClient &client, } int slot = msg.readInt8(); - Characters &chars = acc->getCharacters(); + const Characters &chars = acc->getCharacters(); + const auto charIt = chars.find(slot); - if (chars.find(slot) == chars.end()) + if (charIt == chars.end()) { // Invalid char selection reply.writeInt8(ERRMSG_INVALID_ARGUMENT); @@ -922,14 +924,14 @@ void AccountHandler::handleCharacterSelectMessage(AccountClient &client, return; } - CharacterData *selectedChar = chars[slot]; + const CharacterData &selectedChar = *charIt->second; - std::string address; - int port; + std::string gameServerAddress; + int gameServerPort; if (!GameServerHandler::getGameServerFromMap - (selectedChar->getMapId(), address, port)) + (selectedChar.getMapId(), gameServerAddress, gameServerPort)) { - LOG_ERROR("Character Selection: No game server for map #"<<selectedChar->getMapId()); + LOG_ERROR("Character Selection: No game server for map #" << selectedChar.getMapId()); reply.writeInt8(ERRMSG_FAILURE); client.send(reply); return; @@ -937,12 +939,12 @@ void AccountHandler::handleCharacterSelectMessage(AccountClient &client, reply.writeInt8(ERRMSG_OK); - LOG_DEBUG(selectedChar->getName() << " is trying to enter the servers."); + LOG_DEBUG(selectedChar.getName() << " is trying to enter the servers."); std::string magic_token(utils::getMagicToken()); reply.writeString(magic_token, MAGIC_TOKEN_LENGTH); - reply.writeString(address); - reply.writeInt16(port); + reply.writeString(gameServerAddress); + reply.writeInt16(gameServerPort); // Give address and port for the chat server reply.writeString(Configuration::getValue("net_publicChatHost", @@ -950,21 +952,20 @@ void AccountHandler::handleCharacterSelectMessage(AccountClient &client, // When the chatListenToClientPort is set, we use it. // Otherwise, we use the accountListenToClientPort + 2 if the option is set. - // If neither, the DEFAULT_SERVER_PORT + 2 is used. - const int alternativePort = + const int defaultChatPort = Configuration::getValue("net_accountListenToClientPort", DEFAULT_SERVER_PORT) + 2; reply.writeInt16(Configuration::getValue("net_chatListenToClientPort", - alternativePort)); + defaultChatPort)); GameServerHandler::registerClient(magic_token, selectedChar); - registerChatClient(magic_token, selectedChar->getName(), acc->getLevel()); + registerChatClient(magic_token, selectedChar.getName(), acc->getLevel()); client.send(reply); // log transaction Transaction trans; - trans.mCharacterId = selectedChar->getDatabaseID(); + trans.mCharacterId = selectedChar.getDatabaseID(); trans.mAction = TRANS_CHAR_SELECTED; storage->addTransaction(trans); } diff --git a/src/account-server/character.cpp b/src/account-server/character.cpp index c61be1f6..a43c91e7 100644 --- a/src/account-server/character.cpp +++ b/src/account-server/character.cpp @@ -41,7 +41,7 @@ CharacterData::CharacterData(const std::string &name, int id): { } -void CharacterData::serialize(MessageOut &msg) +void CharacterData::serialize(MessageOut &msg) const { // general character properties msg.writeInt8(getAccountLevel()); @@ -94,7 +94,7 @@ void CharacterData::serialize(MessageOut &msg) // questlog msg.writeInt16(mQuests.size()); - for (QuestInfo &quest : mQuests) { + for (const QuestInfo &quest : mQuests) { msg.writeInt16(quest.id); msg.writeInt8(quest.state); msg.writeString(quest.title); diff --git a/src/account-server/character.h b/src/account-server/character.h index d7e905cc..e3c1b49c 100644 --- a/src/account-server/character.h +++ b/src/account-server/character.h @@ -25,7 +25,6 @@ #include <vector> #include <set> -#include "common/defines.h" #include "common/inventorydata.h" #include "utils/point.h" @@ -82,7 +81,7 @@ class CharacterData public: CharacterData(const std::string &name, int id = -1); - void serialize(MessageOut &msg); + void serialize(MessageOut &msg) const; void deserialize(MessageIn &msg); /** diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index 54754546..aa9f78cd 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -18,13 +18,12 @@ * along with The Mana Server. If not, see <http://www.gnu.org/licenses/>. */ +#include "account-server/serverhandler.h" + #include <cassert> #include <sstream> #include <list> -#include "account-server/serverhandler.h" - -#include "account-server/accountclient.h" #include "account-server/accounthandler.h" #include "account-server/character.h" #include "account-server/flooritem.h" @@ -154,20 +153,20 @@ bool GameServerHandler::getGameServerFromMap(int mapId, } static void registerGameClient(GameServer *s, const std::string &token, - CharacterData *ptr) + const CharacterData &ptr) { MessageOut msg(AGMSG_PLAYER_ENTER); msg.writeString(token, MAGIC_TOKEN_LENGTH); - msg.writeInt32(ptr->getDatabaseID()); - msg.writeString(ptr->getName()); - ptr->serialize(msg); + msg.writeInt32(ptr.getDatabaseID()); + msg.writeString(ptr.getName()); + ptr.serialize(msg); s->send(msg); } void GameServerHandler::registerClient(const std::string &token, - CharacterData *ptr) + const CharacterData &ptr) { - GameServer *s = ::getGameServerFromMap(ptr->getMapId()); + GameServer *s = ::getGameServerFromMap(ptr.getMapId()); assert(s); registerGameClient(s, token, ptr); } @@ -318,7 +317,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) int mapId = ptr->getMapId(); if (GameServer *s = getGameServerFromMap(mapId)) { - registerGameClient(s, magic_token, ptr); + registerGameClient(s, magic_token, *ptr); MessageOut result(AGMSG_REDIRECT_RESPONSE); result.writeInt32(id); result.writeString(magic_token, MAGIC_TOKEN_LENGTH); @@ -470,11 +469,8 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) break; } - // get the post for that character - Post *post = postalManager->getPost(ptr); - - // send the post if valid - if (post) + // get the post for that character and send the post if valid + if (Post *post = postalManager->getPost(ptr)) { for (unsigned i = 0; i < post->getNumberOfLetters(); ++i) { @@ -483,8 +479,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) Letter *letter = post->getLetter(i); result.writeString(letter->getSender()->getName()); result.writeString(letter->getContents()); - std::vector<InventoryItem> items = letter->getAttachments(); - for (auto &item : items) + for (auto &item : letter->getAttachments()) { result.writeInt16(item.itemId); result.writeInt16(item.amount); @@ -522,26 +517,18 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) break; } - // get the letter contents - std::string contents = msg.readString(); - - std::vector< std::pair<int, int> > items; - while (msg.getUnreadLength()) - { - items.push_back(std::pair<int, int>(msg.readInt16(), msg.readInt16())); - } - // save the letter LOG_DEBUG("Creating letter"); auto letter = new Letter(0, sender, receiver); - letter->addText(contents); - for (auto &i : items) + letter->addText(msg.readString()); + while (msg.getUnreadLength() >= 4) { InventoryItem item; - item.itemId = i.first; - item.amount = i.second; + item.itemId = msg.readInt16(); + item.amount = msg.readInt16(); letter->addAttachment(item); } + postalManager->addLetter(letter); result.writeInt8(ERRMSG_OK); diff --git a/src/account-server/serverhandler.h b/src/account-server/serverhandler.h index 916a0224..57732d1d 100644 --- a/src/account-server/serverhandler.h +++ b/src/account-server/serverhandler.h @@ -48,9 +48,9 @@ namespace GameServerHandler bool getGameServerFromMap(int, std::string &address, int &port); /** - * Warns a game server about a soon-to-connect client. + * Notifies a game server about a soon-to-connect client. */ - void registerClient(const std::string &token, CharacterData *); + void registerClient(const std::string &token, const CharacterData &); /** * Dumps per-server statistics into given stream diff --git a/src/account-server/storage.cpp b/src/account-server/storage.cpp index 34a49cfc..96590524 100644 --- a/src/account-server/storage.cpp +++ b/src/account-server/storage.cpp @@ -26,10 +26,10 @@ #include "account-server/account.h" #include "account-server/character.h" #include "account-server/flooritem.h" -#include "chat-server/chatchannel.h" #include "chat-server/guild.h" #include "chat-server/post.h" #include "common/configuration.h" +#include "common/defines.h" #include "common/manaserv_protocol.h" #include "dal/dalexcept.h" #include "dal/dataproviderfactory.h" @@ -1438,14 +1438,13 @@ std::map<int, Guild*> Storage::getGuildList() std::list<std::pair<int, int> > members; for (unsigned j = 0; j < memberInfo.rows(); ++j) { - members.push_back(std::pair<int, int>(toUint(memberInfo(j, 0)), - toUint(memberInfo(j, 1)))); + members.push_back(std::make_pair(toUint(memberInfo(j, 0)), + toUint(memberInfo(j, 1)))); } for (auto i : members) { - CharacterData *character = getCharacter(i.first, nullptr); - if (character) + if (CharacterData *character = getCharacter(i.first, nullptr)) { character->addGuild(guild.second->getName()); guild.second->addMember(character->getDatabaseID(), i.second); @@ -1945,7 +1944,6 @@ void Storage::syncDatabase() } dal::PerformTransaction transaction(mDb); - int itemCount = 0; for_each_xml_child_node(node, rootNode) { // Try to load the version of the item database. @@ -2029,7 +2027,6 @@ void Storage::syncDatabase() utils::throwError("(Storage::SyncDatabase) " "SQL query preparation failure #1."); } - itemCount++; } catch (const dal::DbSqlQueryExecFailure &e) { |