SuperTuxKart
Loading...
Searching...
No Matches
server.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2013-2015 Glenn De Jonghe
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef HEADER_SERVER_HPP
20#define HEADER_SERVER_HPP
21
27#include "race/race_manager.hpp"
28#include "utils/types.hpp"
29
30#include <irrString.h>
31
32#include <map>
33#include <string>
34#include <tuple>
35
36class Track;
37class XMLNode;
38class SocketAddress;
39
43class Server
44{
45public:
46
47protected:
49 irr::core::stringw m_name;
50
52 std::string m_lower_case_name;
53
54 std::string m_server_owner_lower_case_name;
55
56 std::string m_lower_case_player_names;
57
62 std::unique_ptr<SocketAddress> m_ipv6_address;
63
64 uint32_t m_server_id;
65 uint32_t m_server_owner;
66
69
72
73 int m_current_ai;
74
76 std::unique_ptr<SocketAddress> m_address;
77
82
83 unsigned m_server_mode;
84
85 RaceManager::Difficulty m_difficulty;
86
87 bool m_password_protected;
88
89 /* WAN server only, show the owner name of server, can only be seen
90 * for localhost or if you are friend with the server owner. */
91 core::stringw m_server_owner_name;
92
93 /* WAN server only, distance based on IP latitude and longitude. */
94 float m_distance;
95
96 /* WAN server only, true if hosted officially by stk team. */
97 bool m_official;
98
99 bool m_supports_encrytion;
100
101 bool m_game_started;
102
103 bool m_ipv6_connection;
104
105 bool m_reconnect_when_quit_lobby;
106
107 std::vector<std::tuple<
108 /*rank*/int, core::stringw, /*scores*/double, /*playing time*/float
109 > > m_players;
110
111 std::string m_current_track;
112
113 std::string m_country_code;
114public:
115
117 Server(const XMLNode& server_info);
118 Server(unsigned server_id, const irr::core::stringw &name,
119 int max_players, int current_players, unsigned difficulty,
120 unsigned server_mode, const SocketAddress &address,
121 bool password_protected, bool game_started,
122 const std::string& current_track = "");
123 // ------------------------------------------------------------------------
124 virtual ~Server();
125 // ------------------------------------------------------------------------
127 const SocketAddress& getAddress() const { return *m_address.get(); }
128 // ------------------------------------------------------------------------
129 void setAddress(const SocketAddress& addr);
130 // ------------------------------------------------------------------------
132 const std::string& getLowerCaseName() const { return m_lower_case_name; }
133 // ------------------------------------------------------------------------
135 const irr::core::stringw& getName() const { return m_name; }
136 // ------------------------------------------------------------------------
138 const uint32_t getServerId() const { return m_server_id; }
139 // ------------------------------------------------------------------------
141 const uint32_t getServerOwner() const { return m_server_owner; }
142 // ------------------------------------------------------------------------
143 uint16_t getPrivatePort() const { return m_private_port; }
144 // ------------------------------------------------------------------------
146 const int getMaxPlayers() const { return m_max_players; }
147 // ------------------------------------------------------------------------
149 const int getCurrentPlayers() const { return m_current_players; }
150 // ------------------------------------------------------------------------
151 unsigned getServerMode() const { return m_server_mode; }
152 // ------------------------------------------------------------------------
153 RaceManager::Difficulty getDifficulty() const { return m_difficulty; }
154 // ------------------------------------------------------------------------
155 bool isPasswordProtected() const { return m_password_protected; }
156 // ------------------------------------------------------------------------
157 const core::stringw& getServerOwnerName() const
158 { return m_server_owner_name; }
159 // ------------------------------------------------------------------------
160 const std::string& getServerOwnerLowerCaseName() const
161 { return m_server_owner_lower_case_name; }
162 // ------------------------------------------------------------------------
163 float getDistance() const { return m_distance; }
164 // ------------------------------------------------------------------------
165 bool supportsEncryption() const { return m_supports_encrytion; }
166 // ------------------------------------------------------------------------
167 bool isOfficial() const { return m_official; }
168 // ------------------------------------------------------------------------
169 bool isGameStarted() const { return m_game_started; }
170 // ------------------------------------------------------------------------
171 const std::vector<std::tuple<int, core::stringw, double, float> >&
172 getPlayers() const { return m_players; }
173 // ------------------------------------------------------------------------
174 void setServerId(unsigned id) { m_server_id = id; }
175 // ------------------------------------------------------------------------
176 void setPrivatePort(uint16_t port) { m_private_port = port; }
177 // ------------------------------------------------------------------------
178 void setSupportsEncryption(bool val) { m_supports_encrytion = val; }
179 // ------------------------------------------------------------------------
180 bool searchByName(const std::string& lower_case_word);
181 // ------------------------------------------------------------------------
182 Track* getCurrentTrack() const;
183 // ------------------------------------------------------------------------
184 const std::string& getCountryCode() const { return m_country_code; }
185 // ------------------------------------------------------------------------
186 void setIPV6Connection(bool val)
187 {
188 if (!m_ipv6_address)
189 m_ipv6_connection = false;
190 else
191 m_ipv6_connection = val;
192 }
193 // ------------------------------------------------------------------------
194 bool useIPV6Connection() const { return m_ipv6_connection; }
195 // ------------------------------------------------------------------------
196 void setIPV6Address(const SocketAddress& addr);
197 // ------------------------------------------------------------------------
198 SocketAddress* getIPV6Address() const
199 {
200 if (!m_ipv6_address)
201 return NULL;
202 return m_ipv6_address.get();
203 }
204 // ------------------------------------------------------------------------
205 virtual void saveServer() const {}
206 // ------------------------------------------------------------------------
207 void setIsPasswordProtected(bool password_protected) { m_password_protected = password_protected; }
208 // ------------------------------------------------------------------------
209 bool reconnectWhenQuitLobby() const { return m_reconnect_when_quit_lobby; }
210 // ------------------------------------------------------------------------
211 void setReconnectWhenQuitLobby(bool val)
212 { m_reconnect_when_quit_lobby = val; }
213 // ------------------------------------------------------------------------
214 std::string getBookmarkKey() const;
215 // ------------------------------------------------------------------------
216 const int getCurrentAI() const { return m_current_ai; }
217}; // Server
218
220{
221public:
222 UserDefinedServer(const core::stringw& name, const SocketAddress& ipv4,
223 bool password_protected = false)
224 : Server(0, name, 0, 0, 0, 0, ipv4, password_protected, false) {}
225 // ------------------------------------------------------------------------
226 virtual void saveServer() const;
227}; // UserDefinedServer
228
229#endif // HEADER_SERVER_HPP
Difficulty
Game difficulty.
Definition: race_manager.hpp:230
Definition: server.hpp:44
const int getCurrentPlayers() const
Returns the number of currently connected players.
Definition: server.hpp:149
int m_current_players
The number of players currently on the server.
Definition: server.hpp:71
int m_max_players
The maximum number of players that the server supports.
Definition: server.hpp:68
const irr::core::stringw & getName() const
Returns the name of the server.
Definition: server.hpp:135
const uint32_t getServerOwner() const
Returns the user id in STK addon server of the server owner (WAN).
Definition: server.hpp:141
const uint32_t getServerId() const
Returns the ID of this server.
Definition: server.hpp:138
const std::string & getLowerCaseName() const
Returns the lower case name of the server.
Definition: server.hpp:132
const int getMaxPlayers() const
Returns the maximum number of players allowed on this server.
Definition: server.hpp:146
irr::core::stringw m_name
The server name to be displayed.
Definition: server.hpp:49
std::unique_ptr< SocketAddress > m_address
The public ip address and port of this server.
Definition: server.hpp:76
const SocketAddress & getAddress() const
Returns IPv4 address and port of this server.
Definition: server.hpp:127
std::string m_lower_case_name
Name in lower case for comparisons.
Definition: server.hpp:52
uint16_t m_private_port
This is the private port of the server.
Definition: server.hpp:81
std::unique_ptr< SocketAddress > m_ipv6_address
We need to use full socket address structure instead of string to hold it, because for local link add...
Definition: server.hpp:62
Describes a IPv4 or IPv6 address in sockaddr_in(6) format, suitable in using with sendto.
Definition: socket_address.hpp:47
Definition: track.hpp:114
Definition: server.hpp:220
utility class used to parse XML files
Definition: xml_node.hpp:48
Declares the general types that are used by the network.