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/net | |
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/net')
-rw-r--r-- | src/net/logindata.h | 2 | ||||
-rw-r--r-- | src/net/manaserv/connection.cpp | 2 | ||||
-rw-r--r-- | src/net/manaserv/connection.h | 4 | ||||
-rw-r--r-- | src/net/serverinfo.h | 24 |
4 files changed, 21 insertions, 11 deletions
diff --git a/src/net/logindata.h b/src/net/logindata.h index 380f9061..1e19b541 100644 --- a/src/net/logindata.h +++ b/src/net/logindata.h @@ -40,7 +40,7 @@ public: std::string email; std::string captchaResponse; - Gender gender; + Gender gender = GENDER_UNSPECIFIED; bool remember; /**< Whether to store the username. */ bool registerLogin; /**< Whether an account is being registered. */ diff --git a/src/net/manaserv/connection.cpp b/src/net/manaserv/connection.cpp index d439f964..896d86ad 100644 --- a/src/net/manaserv/connection.cpp +++ b/src/net/manaserv/connection.cpp @@ -42,7 +42,7 @@ Connection::~Connection() connections--; } -bool Connection::connect(const std::string &address, short port) +bool Connection::connect(const std::string &address, enet_uint16 port) { logger->log("Net::Connection::connect(%s, %i)", address.c_str(), port); diff --git a/src/net/manaserv/connection.h b/src/net/manaserv/connection.h index e6646e0e..dfd45e31 100644 --- a/src/net/manaserv/connection.h +++ b/src/net/manaserv/connection.h @@ -25,8 +25,6 @@ #include <enet/enet.h> #include "net/manaserv/network.h" -#include <iosfwd> - namespace ManaServ { class MessageOut; @@ -49,7 +47,7 @@ namespace ManaServ * This method is non-blocking, use isConnected to check whether the * server is connected. */ - bool connect(const std::string &address, short port); + bool connect(const std::string &address, enet_uint16 port); /** * Disconnects from the given server. diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h index f9119d19..481ef7cd 100644 --- a/src/net/serverinfo.h +++ b/src/net/serverinfo.h @@ -24,8 +24,9 @@ #include "utils/stringutils.h" -#include <string> +#include <cstdint> #include <deque> +#include <string> class ServerInfo { @@ -41,7 +42,7 @@ public: Type type = UNKNOWN; std::string name; std::string hostname; - unsigned short port = 0; + uint16_t port = 0; std::string description; VersionString version = std::make_pair(0, std::string()); @@ -51,7 +52,7 @@ public: bool isValid() const { - return !(hostname.empty() || port == 0 || type == UNKNOWN); + return !hostname.empty() && port != 0 && type != UNKNOWN; } void clear() @@ -76,24 +77,35 @@ public: if (compareStrI(type, "tmwathena") == 0) return TMWATHENA; // Used for backward compatibility - else if (compareStrI(type, "eathena") == 0) + if (compareStrI(type, "eathena") == 0) return TMWATHENA; - else if (compareStrI(type, "manaserv") == 0) + if (compareStrI(type, "manaserv") == 0) return MANASERV; return UNKNOWN; } - static unsigned short defaultPortForServerType(Type type) + static uint16_t defaultPortForServerType(Type type) { switch (type) { default: + case ServerInfo::UNKNOWN: + return 0; case ServerInfo::TMWATHENA: return 6901; case ServerInfo::MANASERV: return 9601; } } + + static Type defaultServerTypeForPort(uint16_t port) + { + if (port == 6901) + return TMWATHENA; + if (port == 9601) + return MANASERV; + return UNKNOWN; + } }; using ServerInfos = std::deque<ServerInfo>; |