From 78d6d9352f66f41963207b04a999d94c17d67cf2 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sun, 11 Feb 2024 21:39:51 +0100 Subject: 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 --- src/client.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'src/client.cpp') 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( + 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; -- cgit v1.2.3-70-g09d2