summaryrefslogtreecommitdiff
path: root/src/net/serverinfo.h
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-02-11 21:39:51 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-02 17:05:37 +0100
commit78d6d9352f66f41963207b04a999d94c17d67cf2 (patch)
treec286d4a6ebd46bc89808d3e18b2d7d920ea10351 /src/net/serverinfo.h
parent8546361abaa6123acd9dc1429575d1fd1cf6a4ec (diff)
downloadmana-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/serverinfo.h')
-rw-r--r--src/net/serverinfo.h24
1 files changed, 18 insertions, 6 deletions
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>;