ManaPlus
serverinfo.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef NET_SERVERINFO_H
25 #define NET_SERVERINFO_H
26 
28 #include "enums/net/servertype.h"
29 
30 #include "net/hostsgroup.h"
31 #include "net/serverurlinfo.h"
32 
33 #include "utils/stringutils.h"
34 
35 #include "localconsts.h"
36 
38 {
39  public:
40  typedef std::pair<int, std::string> VersionString;
41 
44  std::string name;
45  std::string hostname;
46  std::string althostname;
47  std::string description;
48  std::string registerUrl;
49  std::string onlineListUrl;
50  std::string supportUrl;
51  std::string serverUrl;
52  std::string defaultHostName;
53  STD_VECTOR<std::string> updateMirrors;
54  STD_VECTOR<HostsGroup> updateHosts;
55  STD_VECTOR<ServerUrlInfo> freeSources;
56  STD_VECTOR<ServerUrlInfo> nonFreeSources;
57  STD_VECTOR<ServerUrlInfo> docs;
58  uint16_t port;
61  bool save;
63 
67  name(),
68  hostname(),
69  althostname(),
70  description(),
71  registerUrl(),
72  onlineListUrl(),
73  supportUrl(),
74  serverUrl(),
76  updateMirrors(),
77  updateHosts(),
78  freeSources(),
80  docs(),
81 #ifdef TMWA_SUPPORT
82  port(6901),
83 #else // TMWA_SUPPORT
84  port(6900),
85 #endif // TMWA_SUPPORT
86  version(),
87  packetVersion(),
88  save(false),
89  persistentIp(true)
90  {
91  version.first = 0;
92  }
93 
95  type(info.type),
97  name(info.name),
110  docs(info.docs),
111  port(info.port),
112  version(),
114  save(info.save),
116  {
117  version.first = info.version.first;
118  version.second = info.version.second;
119  }
120 
122 
123  ServerInfo &operator=(const ServerInfo &info)
124  {
125  type = info.type;
126  freeType = info.freeType;
127  name = info.name;
128  hostname = info.hostname;
129  althostname = info.althostname;
130  description = info.description;
131  registerUrl = info.registerUrl;
132  onlineListUrl = info.onlineListUrl;
133  supportUrl = info.supportUrl;
134  serverUrl = info.serverUrl;
135  defaultHostName = info.defaultHostName;
136  updateMirrors = info.updateMirrors;
137  updateHosts = info.updateHosts;
138  freeSources = info.freeSources;
139  nonFreeSources = info.nonFreeSources;
140  docs = info.docs;
141  port = info.port;
142  save = info.save;
143  persistentIp = info.persistentIp;
144  version.first = info.version.first;
145  version.second = info.version.second;
146  packetVersion = info.packetVersion;
147  return *this;
148  }
149 
151  {
152  return !(hostname.empty()
153  || port == 0
154  || type == ServerType::UNKNOWN);
155  }
156 
157  void clear()
158  {
160  name.clear();
161  hostname.clear();
162  althostname.clear();
163  port = 0;
164  description.clear();
165  registerUrl.clear();
166  onlineListUrl.clear();
167  supportUrl.clear();
168  serverUrl.clear();
169  defaultHostName.clear();
170  updateMirrors.clear();
171  updateHosts.clear();
172  freeSources.clear();
173  nonFreeSources.clear();
174  docs.clear();
175  version.first = 0;
176  version.second.clear();
177  packetVersion = 0;
178  save = false;
179  persistentIp = true;
181  }
182 
183  bool operator==(const ServerInfo &other) const
184  {
185  return name == other.name &&
186  hostname == other.hostname &&
187  port == other.port;
188  }
189 
190  bool operator!=(const ServerInfo &other) const
191  {
192  return name != other.name ||
193  hostname != other.hostname ||
194  port != other.port;
195  }
196 
197  static ServerTypeT parseType(const std::string &serverType)
199  {
200 #ifdef TMWA_SUPPORT
201  if (compareStrI(serverType, "tmwathena") == 0)
202  return ServerType::TMWATHENA;
203  else
204 #endif // TMWA_SUPPORT
205  if (compareStrI(serverType, "eathena") == 0)
206  return ServerType::EATHENA;
207  else if (compareStrI(serverType, "hercules") == 0)
208  return ServerType::EATHENA;
209  else if (compareStrI(serverType, "evol2") == 0)
210  return ServerType::EVOL2;
211  return ServerType::UNKNOWN;
212  }
213 
214  static ServerFreeTypeT parseFreeType(const std::string &serverFreeType)
216  {
217  if (compareStrI(serverFreeType, "free") == 0)
218  return ServerFreeType::Free;
219  else if (compareStrI(serverFreeType, "nonfree") == 0)
221  else if (compareStrI(serverFreeType, "unknown") == 0)
223  return ServerFreeType::NotSet;
224  }
225 };
226 
227 typedef STD_VECTOR<ServerInfo> ServerInfos;
228 
229 #endif // NET_SERVERINFO_H
ServerInfo(const ServerInfo &info)
Definition: serverinfo.h:94
void clear()
Definition: serverinfo.h:157
std::string hostname
Definition: serverinfo.h:45
std::vector< std::string > updateMirrors
Definition: serverinfo.h:53
std::string serverUrl
Definition: serverinfo.h:51
std::vector< ServerUrlInfo > nonFreeSources
Definition: serverinfo.h:56
bool operator!=(const ServerInfo &other) const
Definition: serverinfo.h:190
std::string supportUrl
Definition: serverinfo.h:50
std::string althostname
Definition: serverinfo.h:46
uint16_t port
Definition: serverinfo.h:58
std::vector< HostsGroup > updateHosts
Definition: serverinfo.h:54
bool operator==(const ServerInfo &other) const
Definition: serverinfo.h:183
static ServerFreeTypeT parseFreeType(const std::string &serverFreeType)
Definition: serverinfo.h:214
std::vector< ServerUrlInfo > docs
Definition: serverinfo.h:57
std::string onlineListUrl
Definition: serverinfo.h:49
bool isValid() const
Definition: serverinfo.h:150
int packetVersion
Definition: serverinfo.h:60
VersionString version
Definition: serverinfo.h:59
ServerTypeT type
Definition: serverinfo.h:42
bool persistentIp
Definition: serverinfo.h:62
static ServerTypeT parseType(const std::string &serverType)
Definition: serverinfo.h:197
std::string name
Definition: serverinfo.h:44
std::string registerUrl
Definition: serverinfo.h:48
std::string defaultHostName
Definition: serverinfo.h:52
std::string description
Definition: serverinfo.h:47
ServerFreeTypeT freeType
Definition: serverinfo.h:43
bool save
Definition: serverinfo.h:61
std::pair< int, std::string > VersionString
Definition: serverinfo.h:40
std::vector< ServerUrlInfo > freeSources
Definition: serverinfo.h:55
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DEFAULT_COPY(func)
Definition: localconsts.h:41
bool info(InputEvent &event)
Definition: commands.cpp:57
ServerFreeType ::T ServerFreeTypeT
std::vector< ServerInfo > ServerInfos
Definition: serverinfo.h:227
ServerType ::T ServerTypeT
Definition: servertype.h:36
int compareStrI(const std::string &a, const std::string &b)