summaryrefslogtreecommitdiff
path: root/src/account-server/accounthandler.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2023-05-15 14:45:05 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2023-05-15 14:45:05 +0200
commitf395960adeea1f51f01ec8045d1e175926a6ea4a (patch)
treebf9d107fb5891c3e6bd0abeb4d49573c73230707 /src/account-server/accounthandler.cpp
parentf3071beef3ddd93bbe3ab6e30c14fc95a5112b9c (diff)
downloadmanaserv-f395960adeea1f51f01ec8045d1e175926a6ea4a.tar.gz
manaserv-f395960adeea1f51f01ec8045d1e175926a6ea4a.tar.bz2
manaserv-f395960adeea1f51f01ec8045d1e175926a6ea4a.tar.xz
manaserv-f395960adeea1f51f01ec8045d1e175926a6ea4a.zip
General code cleanups
* Overall includes cleanup * Use std::make_pair * Make some functions const
Diffstat (limited to 'src/account-server/accounthandler.cpp')
-rw-r--r--src/account-server/accounthandler.cpp33
1 files changed, 17 insertions, 16 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);
}