diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-12-15 14:35:22 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-12-16 18:25:58 +0100 |
commit | 01489b9930025bed3c5bfc34b6c86045cbaccb46 (patch) | |
tree | 2820d4a62f0562168cee7b989fd611adfff0da70 | |
parent | cee7b8909d3591ad851ac7b31753b83fbfdabfa5 (diff) | |
download | manaserv-01489b9930025bed3c5bfc34b6c86045cbaccb46.tar.gz manaserv-01489b9930025bed3c5bfc34b6c86045cbaccb46.tar.bz2 manaserv-01489b9930025bed3c5bfc34b6c86045cbaccb46.tar.xz manaserv-01489b9930025bed3c5bfc34b6c86045cbaccb46.zip |
Deharcoded the host and port options for each servers.
Changes:
============================================================
For the account server:
------------------------------------------------------------
Old -> New
------------------------------------------------------------
net_accountServerAddress,
net_listenHost -> net_accountHost
net_accountServerPort -> net_accountListenToClientPort
net_accountServerPort +1 -> net_accountListenToGamePort
For the game server:
------------------------------------------------------------
Old -> New
------------------------------------------------------------
net_gameServerAddress -> net_gameHost
net_gameServerPort -> net_gameListenToClientPort
For the chat server:
------------------------------------------------------------
Old -> New
------------------------------------------------------------
-> net_chatHost
net_accountServerPort + 2 -> net_chatListenToClientPort
Special fallback feature, as requested by Freeyorp:
When the net_accountListenToClientPort (default to 9601)
is set, the 3 others ports will automatically offset from it,
if they're not set, following this rule:
net_accountListenToGamePort = net_accountListenToClientPort + 1
net_chatListenToClientPort = net_accountListenToClientPort + 2
net_gameListenToClientPort = net_accountListenToClientPort + 3
Resolves: Mana-Mantis #216.
Reviewed-by: Jaxad0127.
-rw-r--r-- | src/account-server/accounthandler.cpp | 16 | ||||
-rw-r--r-- | src/account-server/main-account.cpp | 25 | ||||
-rw-r--r-- | src/game-server/accountconnection.cpp | 14 | ||||
-rw-r--r-- | src/game-server/main-game.cpp | 14 |
4 files changed, 56 insertions, 13 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index 5b1ccd05..1463b37e 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -868,11 +868,19 @@ void AccountHandler::handleCharacterSelectMessage(AccountClient &client, reply.writeString(address); reply.writeInt16(port); - // TODO: get correct address and port for the chat server - reply.writeString(Configuration::getValue("net_accountServerAddress", + // Give address and port for the chat server + reply.writeString(Configuration::getValue("net_chatHost", "localhost")); - reply.writeInt16(Configuration::getValue("net_accountServerPort", - DEFAULT_SERVER_PORT) + 2); + + // 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. + int alternativePort = + Configuration::getValue("net_accountListenToClientPort", 0) + 2; + if (alternativePort == 2) + alternativePort = DEFAULT_SERVER_PORT + 2; + reply.writeInt16(Configuration::getValue("net_chatListenToClientPort", + alternativePort)); GameServerHandler::registerClient(magic_token, selectedChar); registerChatClient(magic_token, selectedChar->getName(), acc->getLevel()); diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp index 9516b4d1..a0e935dd 100644 --- a/src/account-server/main-account.cpp +++ b/src/account-server/main-account.cpp @@ -368,15 +368,30 @@ int main(int argc, char *argv[]) options.verbosity) ); Logger::setVerbosity(options.verbosity); + std::string accountHost = Configuration::getValue("net_accountHost", + "localhost"); + + // We separate the chat host as the chat server will be separated out + // from the account server. + std::string chatHost = Configuration::getValue("net_chatHost", + "localhost"); + + // Setting the listen ports + // Note: The accountToGame and chatToClient listen ports auto offset + // to accountToClient listen port when they're not set, + // or to DEFAULT_SERVER_PORT otherwise. if (!options.portChanged) - options.port = Configuration::getValue("net_accountServerPort", + options.port = Configuration::getValue("net_accountListenToClientPort", options.port); + int accountGamePort = Configuration::getValue("net_accountListenToGamePort", + options.port + 1); + int chatClientPort = Configuration::getValue("net_chatListenToClientPort", + options.port + 2); - std::string host = Configuration::getValue("net_listenHost", std::string()); if (!AccountClientHandler::initialize(DEFAULT_ATTRIBUTEDB_FILE, - options.port, host) || - !GameServerHandler::initialize(options.port + 1, host) || - !chatHandler->startListen(options.port + 2, host)) + options.port, accountHost) || + !GameServerHandler::initialize(accountGamePort, accountHost) || + !chatHandler->startListen(chatClientPort, chatHost)) { LOG_FATAL("Unable to create an ENet server host."); return EXIT_NET_EXCEPTION; diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index 72546fbf..c3bc83bf 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -49,9 +49,17 @@ AccountConnection::~AccountConnection() bool AccountConnection::start(int gameServerPort) { const std::string accountServerAddress = - Configuration::getValue("net_accountServerAddress", "localhost"); + Configuration::getValue("net_accountHost", "localhost"); + + // When the accountListenToGamePort is set, we use it. + // Otherwise, we use the accountListenToClientPort + 1 if the option is set. + // If neither, the DEFAULT_SERVER_PORT + 1 is used. + int alternativePort = + Configuration::getValue("net_accountListenToClientPort", 0) + 1; + if (alternativePort == 1) + alternativePort = DEFAULT_SERVER_PORT + 1; const int accountServerPort = - Configuration::getValue("net_accountServerPort", DEFAULT_SERVER_PORT) + 1; + Configuration::getValue("net_accountListenToGamePort", alternativePort); if (!Connection::start(accountServerAddress, accountServerPort)) { @@ -62,7 +70,7 @@ bool AccountConnection::start(int gameServerPort) LOG_INFO("Connection established to the account server."); const std::string gameServerAddress = - Configuration::getValue("net_gameServerAddress", "localhost"); + Configuration::getValue("net_gameHost", "localhost"); const std::string password = Configuration::getValue("net_password", "changeMe"); diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp index 084415b0..d62c92aa 100644 --- a/src/game-server/main-game.cpp +++ b/src/game-server/main-game.cpp @@ -374,9 +374,21 @@ int main(int argc, char *argv[]) options.verbosity) ); Logger::setVerbosity(options.verbosity); + // When the gameListenToClientPort is set, we use it. + // Otherwise, we use the accountListenToClientPort + 3 if the option is set. + // If neither, the DEFAULT_SERVER_PORT + 3 is used. if (!options.portChanged) - options.port = Configuration::getValue("net_gameServerPort", + { + // Prepare the fallback value + options.port = Configuration::getValue("net_accountListenToClientPort", + 0) + 3; + if (options.port == 3) + options.port = DEFAULT_SERVER_PORT + 3; + + // Set the actual value of options.port + options.port = Configuration::getValue("net_gameListenToClientPort", options.port); + } // Make an initial attempt to connect to the account server // Try again after longer and longer intervals when connection fails. |