diff options
Diffstat (limited to 'src/account-server')
-rw-r--r-- | src/account-server/accounthandler.cpp | 13 | ||||
-rw-r--r-- | src/account-server/main-account.cpp | 3 | ||||
-rw-r--r-- | src/account-server/serverhandler.cpp | 13 |
3 files changed, 12 insertions, 17 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index d5d5d35f..2b1f2ff0 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -38,8 +38,7 @@ #include "net/netcomputer.hpp" #include "utils/logger.h" #include "utils/stringfilter.h" - -// TODO: Implement a class to handle these tokens more generally +#include "utils/tokendispenser.hpp" typedef std::map< std::string, AccountClient* > AccountPendingClients; typedef std::map< std::string, int > AccountPendingReconnects; @@ -226,12 +225,8 @@ AccountHandler::processMessage(NetComputer *comp, MessageIn &message) LOG_DEBUG(selectedChar->getName() << " is trying to enter the servers."); - std::string magic_token(32, ' '); - for (int i = 0; i < 32; ++i) { - magic_token[i] = - 1 + (int) (127 * (rand() / (RAND_MAX + 1.0))); - } - result.writeString(magic_token, 32); + std::string magic_token(utils::getMagicToken()); + result.writeString(magic_token, MAGIC_TOKEN_LENGTH); result.writeString(address); result.writeShort(port); // TODO: get correct address and port for the chat server @@ -390,7 +385,7 @@ AccountHandler::handleReconnectMessage(AccountClient &computer, MessageIn &msg) { if (computer.getAccount().get() == NULL) { - std::string magic_token = msg.readString(32); + std::string magic_token = msg.readString(MAGIC_TOKEN_LENGTH); AccountPendingReconnects::iterator i = pendingReconnects.find(magic_token); if (i == pendingReconnects.end()) diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp index 6e2ef77a..209e4a24 100644 --- a/src/account-server/main-account.cpp +++ b/src/account-server/main-account.cpp @@ -175,6 +175,9 @@ void initialize() config.setValue("dbuser", ""); config.setValue("dbpass", ""); config.setValue("dbhost", ""); + + //Seed the random number generator + std::srand( time(NULL) ); } diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index 9a6dd667..d2159d44 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -31,6 +31,7 @@ #include "net/messageout.hpp" #include "net/netcomputer.hpp" #include "utils/logger.h" +#include "utils/tokendispenser.hpp" extern void registerAccountReconnect(int accountID, const std::string &magic_token); @@ -79,7 +80,7 @@ void ServerHandler::registerGameClient(std::string const &token, CharacterPtr pt unsigned mapId = ptr->getMapId(); MessageOut msg(AGMSG_PLAYER_ENTER); - msg.writeString(token, 32); + msg.writeString(token, MAGIC_TOKEN_LENGTH); ptr->serialize(msg); //Characterdata Servers::const_iterator i = servers.find(mapId); @@ -138,11 +139,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) { LOG_DEBUG("GAMSG_REDIRECT"); int id = msg.readLong(); - std::string magic_token(32, ' '); - for (int i = 0; i < 32; ++i) - { - magic_token[i] = 1 + (int)(127 * (rand() / (RAND_MAX + 1.0))); - } + std::string magic_token(utils::getMagicToken()); Storage &store = Storage::instance("tmw"); CharacterPtr ptr = store.getCharacter(id); std::string address; @@ -153,7 +150,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) registerGameClient(magic_token, ptr); result.writeShort(AGMSG_REDIRECT_RESPONSE); result.writeLong(ptr->getDatabaseID()); - result.writeString(magic_token, 32); + result.writeString(magic_token, MAGIC_TOKEN_LENGTH); result.writeString(address); result.writeShort(port); } @@ -168,7 +165,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) { LOG_DEBUG("GAMSG_PLAYER_RECONNECT"); int characterID = msg.readLong(); - std::string magic_token = msg.readString(32); + std::string magic_token = msg.readString(MAGIC_TOKEN_LENGTH); Storage &store = Storage::instance("tmw"); CharacterPtr ptr = store.getCharacter(characterID); |