diff options
author | Chuck Miller <shadowmil@gmail.com> | 2009-10-07 13:39:24 -0400 |
---|---|---|
committer | Chuck Miller <shadowmil@gmail.com> | 2009-10-07 13:39:24 -0400 |
commit | c19244ddca910dbfc566a61772296cb59fa28d80 (patch) | |
tree | 5771c2d385487e311959f48e3f0de47e264712ff | |
parent | 9a35609facf9fbb511467d607f83ecd1f4d1ee1b (diff) | |
download | manaserv-c19244ddca910dbfc566a61772296cb59fa28d80.tar.gz manaserv-c19244ddca910dbfc566a61772296cb59fa28d80.tar.bz2 manaserv-c19244ddca910dbfc566a61772296cb59fa28d80.tar.xz manaserv-c19244ddca910dbfc566a61772296cb59fa28d80.zip |
Adds server auth, also adds the "net_password" configure option
-rw-r--r-- | src/account-server/serverhandler.cpp | 15 | ||||
-rw-r--r-- | src/defines.h | 10 | ||||
-rw-r--r-- | src/game-server/accountconnection.cpp | 9 |
3 files changed, 31 insertions, 3 deletions
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index 5bfa6a57..ff523b49 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -31,6 +31,7 @@ #include "account-server/dalstorage.hpp" #include "chat-server/post.hpp" #include "common/transaction.hpp" +#include "common/configuration.hpp" #include "net/connectionhandler.hpp" #include "net/messageout.hpp" #include "net/netcomputer.hpp" @@ -176,6 +177,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) // TODO: check the credentials of the game server server->address = msg.readString(); server->port = msg.readShort(); + const std::string password = msg.readString(); // checks the version of the remote item database with our local copy unsigned int dbversion = msg.readLong(); @@ -194,7 +196,18 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) LOG_DEBUG("Item database of game server has a wrong version"); outMsg.writeShort(DATA_VERSION_OUTDATED); } - comp->send(outMsg); + if (password == Configuration::getValue("net_password", "P@s$w0rd")) + { + outMsg.writeShort(PASSWORD_OK); + comp->send(outMsg); + } + else + { + LOG_INFO("The password given by " << server->address << ':' << server->port << " was bad."); + outMsg.writeShort(PASSWORD_BAD); + comp->disconnect(outMsg); + break; + } LOG_INFO("Game server " << server->address << ':' << server->port << " wants to register " << (msg.getUnreadLength() / 2) diff --git a/src/defines.h b/src/defines.h index ac820b2d..f2bee1dd 100644 --- a/src/defines.h +++ b/src/defines.h @@ -255,8 +255,8 @@ enum { PCMSG_KICK_USER = 0x0466, // W channel id, S name // Inter-server - GAMSG_REGISTER = 0x0500, // S address, W port, L items db revision, { W map id }* - AGMSG_REGISTER_RESPONSE = 0x0501, // C item version + GAMSG_REGISTER = 0x0500, // S address, W port, S password, L items db revision, { W map id }* + AGMSG_REGISTER_RESPONSE = 0x0501, // C item version, C password response AGMSG_ACTIVE_MAP = 0x0502, // W map id AGMSG_PLAYER_ENTER = 0x0510, // B*32 token, L id, S name, serialised character data GAMSG_PLAYER_DATA = 0x0520, // L id, serialised character data @@ -304,6 +304,12 @@ enum { DATA_VERSION_OUTDATED = 0x01 }; +// used in AGMSG_REGISTER_RESPNSE to show if password was accepted +enum { + PASSWORD_OK = 0x00, + PASSWORD_BAD = 0x01 +}; + // used to identify part of sync message enum { SYNC_CHARACTER_POINTS = 0x01, // L charId, L charPoints, L corrPoints, B attribute id, L attribute value diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index 41f71627..13c924a4 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -67,11 +67,14 @@ bool AccountConnection::start() Configuration::getValue("net_gameServerAddress", "localhost"); const int gameServerPort = Configuration::getValue("net_gameServerPort", DEFAULT_SERVER_PORT + 3); + const std::string password = + Configuration::getValue("net_password", "P@s$w0rd"); // Register with the account server and send the list of maps we handle MessageOut msg(GAMSG_REGISTER); msg.writeString(gameServerAddress); msg.writeShort(gameServerPort); + msg.writeString(password); msg.writeLong(ItemManager::GetDatabaseVersion()); const MapManager::Maps &m = MapManager::getMaps(); for (MapManager::Maps::const_iterator i = m.begin(), i_end = m.end(); @@ -113,6 +116,12 @@ void AccountConnection::processMessage(MessageIn &msg) { LOG_DEBUG("Local item database is in sync with account server."); } + if (msg.readShort() != PASSWORD_OK) + { + LOG_ERROR("This game server sent a invaild password"); + stop(); + exit(1); + } } break; case AGMSG_PLAYER_ENTER: |