diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-11 21:39:51 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-02 17:05:37 +0100 |
commit | 78d6d9352f66f41963207b04a999d94c17d67cf2 (patch) | |
tree | c286d4a6ebd46bc89808d3e18b2d7d920ea10351 /src/client.cpp | |
parent | 8546361abaa6123acd9dc1429575d1fd1cf6a4ec (diff) | |
download | mana-78d6d9352f66f41963207b04a999d94c17d67cf2.tar.gz mana-78d6d9352f66f41963207b04a999d94c17d67cf2.tar.bz2 mana-78d6d9352f66f41963207b04a999d94c17d67cf2.tar.xz mana-78d6d9352f66f41963207b04a999d94c17d67cf2.zip |
Added support for -y / --server-type parameter
Usually this would be guessed correctly by the port, but now it is also
possible to just specify the server type and the port will be derived
from there, unless a default port is given in the branding file.
Closes #56
Diffstat (limited to 'src/client.cpp')
-rw-r--r-- | src/client.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/client.cpp b/src/client.cpp index c337420d..f90ca05a 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -378,20 +378,34 @@ Client::Client(const Options &options): // Initialize default server mCurrentServer.hostname = options.serverName; mCurrentServer.port = options.serverPort; + mCurrentServer.type = ServerInfo::parseType(options.serverType); loginData.username = options.username; loginData.password = options.password; loginData.remember = config.getBoolValue("remember"); loginData.registerLogin = false; - if (mCurrentServer.hostname.empty()) - mCurrentServer.hostname = branding.getValue("defaultServer", std::string()); + if (mCurrentServer.type == ServerInfo::UNKNOWN && mCurrentServer.port != 0) + { + mCurrentServer.type = ServerInfo::defaultServerTypeForPort(mCurrentServer.port); + } - if (mCurrentServer.port == 0) + if (mCurrentServer.type == ServerInfo::UNKNOWN) { - mCurrentServer.port = (unsigned short) branding.getValue("defaultPort", - DEFAULT_PORT); mCurrentServer.type = ServerInfo::parseType( - branding.getValue("defaultServerType", "tmwathena")); + branding.getValue("defaultServerType", "tmwathena")); + } + + if (mCurrentServer.port == 0) + { + const uint16_t defaultPort = ServerInfo::defaultPortForServerType(mCurrentServer.type); + mCurrentServer.port = static_cast<uint16_t>( + branding.getValue("defaultPort", defaultPort)); + } + + const bool noServerList = branding.getValue("onlineServerList", std::string()).empty(); + if (mCurrentServer.hostname.empty() && noServerList) + { + mCurrentServer.hostname = branding.getValue("defaultServer", std::string()); } if (chatLogger) @@ -607,10 +621,7 @@ int Client::exec() // If a server was passed on the command line, or branding // provides a server and a blank server list, we skip the // server selection dialog. - if ((!mOptions.serverName.empty() && mOptions.serverPort) - || (!branding.getValue("defaultServer","").empty() && - branding.getValue("defaultPort",0) && - branding.getValue("onlineServerList", "").empty())) + if (!mCurrentServer.hostname.empty() && mCurrentServer.port) { mState = STATE_CONNECT_SERVER; @@ -933,6 +944,7 @@ int Client::exec() Net::getLoginHandler()->disconnect(); Net::getGameHandler()->disconnect(); + mCurrentServer.hostname.clear(); mState = STATE_CHOOSE_SERVER; break; |