Mana
Loading...
Searching...
No Matches
serverinfo.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <cstdint>
25#include <deque>
26#include <string>
27
28enum class ServerType
29{
30 Unknown,
33};
34
36{
37public:
38 using VersionString = std::pair<int, std::string>;
39
41 std::string name;
42 std::string hostname;
43 uint16_t port = 0;
44
45 std::string description;
46 VersionString version = std::make_pair(0, std::string());
47
48 bool save = false;
49 bool persistentIp = true;
50
51 bool isValid() const
52 {
53 return !hostname.empty() && port != 0 && type != ServerType::Unknown;
54 }
55
56 void clear()
57 {
58 *this = ServerInfo();
59 }
60
61 bool operator==(const ServerInfo &other) const
62 {
63 return (type == other.type && hostname == other.hostname &&
64 port == other.port);
65 }
66
67 bool operator!=(const ServerInfo &other) const
68 {
69 return (type != other.type || hostname != other.hostname ||
70 port != other.port);
71 }
72
73 static ServerType parseType(const std::string &type)
74 {
75 if (type == "tmwathena")
77 // Used for backward compatibility
78 if (type == "eathena")
80 if (type == "manaserv")
83 }
84
86 {
87 switch (type)
88 {
89 default:
91 return 0;
93 return 6901;
95 return 9601;
96 }
97 }
98
100 {
101 if (port == 6901)
103 if (port == 9601)
105 return ServerType::Unknown;
106 }
107};
108
109using ServerInfos = std::deque<ServerInfo>;
void clear()
Definition serverinfo.h:56
std::string hostname
Definition serverinfo.h:42
static ServerType parseType(const std::string &type)
Definition serverinfo.h:73
bool operator!=(const ServerInfo &other) const
Definition serverinfo.h:67
uint16_t port
Definition serverinfo.h:43
std::pair< int, std::string > VersionString
Definition serverinfo.h:38
bool operator==(const ServerInfo &other) const
Definition serverinfo.h:61
bool isValid() const
Definition serverinfo.h:51
VersionString version
Definition serverinfo.h:46
ServerType type
Definition serverinfo.h:40
static ServerType defaultServerTypeForPort(uint16_t port)
Definition serverinfo.h:99
bool persistentIp
Definition serverinfo.h:49
std::string name
Definition serverinfo.h:41
static uint16_t defaultPortForServerType(ServerType type)
Definition serverinfo.h:85
std::string description
Definition serverinfo.h:45
Warning: buffers and other variables are shared, so there can be only one connection active at a time...
ServerType
Definition serverinfo.h:29
std::deque< ServerInfo > ServerInfos
Definition serverinfo.h:109