GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
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 |
|||
27 |
#include "enums/net/serverfreetype.h" |
||
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 |
|||
37 |
3146 |
class ServerInfo final |
|
38 |
{ |
||
39 |
public: |
||
40 |
typedef std::pair<int, std::string> VersionString; |
||
41 |
|||
42 |
ServerTypeT type; |
||
43 |
ServerFreeTypeT freeType; |
||
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; |
||
59 |
VersionString version; |
||
60 |
int packetVersion; |
||
61 |
bool save; |
||
62 |
bool persistentIp; |
||
63 |
|||
64 |
256 |
ServerInfo() : |
|
65 |
type(ServerType::TMWATHENA), |
||
66 |
freeType(ServerFreeType::NotSet), |
||
67 |
name(), |
||
68 |
hostname(), |
||
69 |
althostname(), |
||
70 |
description(), |
||
71 |
registerUrl(), |
||
72 |
onlineListUrl(), |
||
73 |
supportUrl(), |
||
74 |
serverUrl(), |
||
75 |
defaultHostName(), |
||
76 |
updateMirrors(), |
||
77 |
updateHosts(), |
||
78 |
freeSources(), |
||
79 |
nonFreeSources(), |
||
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 |
4096 |
persistentIp(true) |
|
90 |
{ |
||
91 |
version.first = 0; |
||
92 |
256 |
} |
|
93 |
|||
94 |
30 |
ServerInfo(const ServerInfo &info) : |
|
95 |
30 |
type(info.type), |
|
96 |
30 |
freeType(info.freeType), |
|
97 |
name(info.name), |
||
98 |
hostname(info.hostname), |
||
99 |
althostname(info.althostname), |
||
100 |
description(info.description), |
||
101 |
registerUrl(info.registerUrl), |
||
102 |
onlineListUrl(info.onlineListUrl), |
||
103 |
supportUrl(info.supportUrl), |
||
104 |
serverUrl(info.serverUrl), |
||
105 |
defaultHostName(info.defaultHostName), |
||
106 |
updateMirrors(info.updateMirrors), |
||
107 |
updateHosts(info.updateHosts), |
||
108 |
freeSources(info.freeSources), |
||
109 |
nonFreeSources(info.nonFreeSources), |
||
110 |
docs(info.docs), |
||
111 |
30 |
port(info.port), |
|
112 |
version(), |
||
113 |
30 |
packetVersion(info.packetVersion), |
|
114 |
30 |
save(info.save), |
|
115 |
✓✗✓✗ ✓✗✓✗ ✓✗ |
450 |
persistentIp(info.persistentIp) |
116 |
{ |
||
117 |
30 |
version.first = info.version.first; |
|
118 |
60 |
version.second = info.version.second; |
|
119 |
30 |
} |
|
120 |
|||
121 |
A_DEFAULT_COPY(ServerInfo) |
||
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 |
|||
150 |
bool isValid() const noexcept2 A_WARN_UNUSED |
||
151 |
{ |
||
152 |
✗✗✗✗ ✗✗✗✗ ✗✓✗✗ |
60 |
return !(hostname.empty() |
153 |
|| port == 0 |
||
154 |
|| type == ServerType::UNKNOWN); |
||
155 |
} |
||
156 |
|||
157 |
void clear() |
||
158 |
{ |
||
159 |
type = ServerType::UNKNOWN; |
||
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; |
||
180 |
freeType = ServerFreeType::Unknown; |
||
181 |
} |
||
182 |
|||
183 |
42 |
bool operator==(const ServerInfo &other) const |
|
184 |
{ |
||
185 |
✗✗ | 42 |
return name == other.name && |
186 |
✗✓✗✗ |
42 |
hostname == other.hostname && |
187 |
42 |
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 |
44 |
static ServerTypeT parseType(const std::string &serverType) |
|
198 |
A_WARN_UNUSED |
||
199 |
{ |
||
200 |
#ifdef TMWA_SUPPORT |
||
201 |
✓✗✓✓ |
176 |
if (compareStrI(serverType, "tmwathena") == 0) |
202 |
return ServerType::TMWATHENA; |
||
203 |
else |
||
204 |
#endif // TMWA_SUPPORT |
||
205 |
✓✗✓✓ |
136 |
if (compareStrI(serverType, "eathena") == 0) |
206 |
return ServerType::EATHENA; |
||
207 |
✓✗✓✗ |
128 |
else if (compareStrI(serverType, "hercules") == 0) |
208 |
return ServerType::EATHENA; |
||
209 |
✓✗✓✓ |
128 |
else if (compareStrI(serverType, "evol2") == 0) |
210 |
return ServerType::EVOL2; |
||
211 |
30 |
return ServerType::UNKNOWN; |
|
212 |
} |
||
213 |
|||
214 |
14 |
static ServerFreeTypeT parseFreeType(const std::string &serverFreeType) |
|
215 |
A_WARN_UNUSED |
||
216 |
{ |
||
217 |
✓✗✓✗ |
56 |
if (compareStrI(serverFreeType, "free") == 0) |
218 |
return ServerFreeType::Free; |
||
219 |
✓✗✓✗ |
56 |
else if (compareStrI(serverFreeType, "nonfree") == 0) |
220 |
return ServerFreeType::NonFree; |
||
221 |
✓✗✓✗ |
56 |
else if (compareStrI(serverFreeType, "unknown") == 0) |
222 |
return ServerFreeType::Unknown; |
||
223 |
14 |
return ServerFreeType::NotSet; |
|
224 |
} |
||
225 |
}; |
||
226 |
|||
227 |
typedef STD_VECTOR<ServerInfo> ServerInfos; |
||
228 |
|||
229 |
#endif // NET_SERVERINFO_H |
Generated by: GCOVR (Version 3.3) |