SuperTuxKart
server_config.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2018 SuperTuxKart-Team
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_CONFIG
20 #define HEADER_SERVER_CONFIG
21 
22 #include "config/user_config.hpp"
23 #include "race/race_manager.hpp"
24 
25 #ifndef SERVER_CFG_PREFIX
26 #define SERVER_CFG_PREFIX extern
27 #endif
28 
29 #ifndef SERVER_CFG_DEFAULT
30 #define SERVER_CFG_DEFAULT(X)
31 #endif
32 
33 #include <string>
34 #include <vector>
35 
36 class XMLNode;
37 
38 namespace ServerConfig
39 {
40  // ========================================================================
42  {
43  public:
44  FloatServerConfigParam(float default_value, const char* param_name,
45  const char* comment);
46  using FloatUserConfigParam::operator=;
47  };
48  // ========================================================================
50  {
51  public:
52  IntServerConfigParam(int default_value, const char* param_name,
53  const char* comment);
54  using IntUserConfigParam::operator=;
55  };
56  // ========================================================================
58  {
59  public:
60  BoolServerConfigParam(bool default_value, const char* param_name,
61  const char* comment);
62  using BoolUserConfigParam::operator=;
63  };
64  // ========================================================================
66  {
67  public:
68  StringServerConfigParam(std::string default_value,
69  const char* param_name, const char* comment);
70  using StringUserConfigParam::operator=;
71  };
72  // ========================================================================
73  template<typename T, typename U>
75  {
76  private:
79  public:
80  MapServerConfigParam(const char* param_name, const char* comment,
81  std::array<std::string, 3> key_names,
82  std::map<T, U> default_value);
84  };
85  // ========================================================================
89  // ========================================================================
90  SERVER_CFG_PREFIX StringServerConfigParam m_server_name
91  SERVER_CFG_DEFAULT(StringServerConfigParam("STK Server", "server-name",
92  "Name of server, encode in XML if you want to use unicode "
93  "characters."));
94 
95  SERVER_CFG_PREFIX IntServerConfigParam m_server_port
96  SERVER_CFG_DEFAULT(IntServerConfigParam(0, "server-port",
97  "Port used in server, if you specify 0, it will use the server port "
98  "specified in stk_config.xml. If you wish to use a random port, "
99  "set random-server-port to '1' in user config. STK will automatically "
100  "switch to a random port if the port you specify fails to be bound."));
101 
102  SERVER_CFG_PREFIX IntServerConfigParam m_server_mode
103  SERVER_CFG_DEFAULT(IntServerConfigParam(3, "server-mode",
104  "Game mode in server, 0 is normal race (grand prix), "
105  "1 is time trial (grand prix), 3 is normal race, "
106  "4 time trial, 6 is soccer, 7 is free-for-all and "
107  "8 is capture the flag. Notice: grand prix server doesn't "
108  "allow for players to join and wait for ongoing game."));
109 
110  SERVER_CFG_PREFIX IntServerConfigParam m_server_difficulty
111  SERVER_CFG_DEFAULT(IntServerConfigParam(0, "server-difficulty",
112  "Difficulty in server, 0 is beginner, 1 is intermediate, 2 is expert "
113  "and 3 is supertux (the most difficult)."));
114 
115  SERVER_CFG_PREFIX IntServerConfigParam m_gp_track_count
116  SERVER_CFG_DEFAULT(IntServerConfigParam(3, "gp-track-count",
117  "Number of grand prix tracks per game (If grand prix enabled)."));
118 
119  SERVER_CFG_PREFIX BoolServerConfigParam m_soccer_goal_target
120  SERVER_CFG_DEFAULT(BoolServerConfigParam(false, "soccer-goal-target",
121  "Use goal target in soccer."));
122 
123  SERVER_CFG_PREFIX BoolServerConfigParam m_wan_server
124  SERVER_CFG_DEFAULT(BoolServerConfigParam(true, "wan-server",
125  "Enable wan server, which requires you to have an stk-addons account "
126  "with a saved session. Check init-user command for details."));
127 
128  SERVER_CFG_PREFIX BoolServerConfigParam m_enable_console
129  SERVER_CFG_DEFAULT(BoolServerConfigParam(false, "enable-console",
130  "Enable network console, which can do for example kickban."));
131 
132  SERVER_CFG_PREFIX IntServerConfigParam m_server_max_players
133  SERVER_CFG_DEFAULT(IntServerConfigParam(8, "server-max-players",
134  "Maximum number of players on the server, setting this to a value "
135  "greater than 8 can cause performance degradation."));
136 
137  SERVER_CFG_PREFIX IntServerConfigParam m_max_players_in_game
138  SERVER_CFG_DEFAULT(IntServerConfigParam(0, "max-players-in-game",
139  "Maximum number of players in the game, all other players on "
140  "the server are spectators. Specify 0 to allow all players on "
141  "the server to play."));
142 
143  SERVER_CFG_PREFIX StringServerConfigParam m_private_server_password
144  SERVER_CFG_DEFAULT(StringServerConfigParam("",
145  "private-server-password", "Password for private server, "
146  "leave empty for a public server."));
147 
148  SERVER_CFG_PREFIX StringServerConfigParam m_motd
149  SERVER_CFG_DEFAULT(StringServerConfigParam("",
150  "motd", "Message of today shown in lobby, you can enter encoded XML "
151  "words here or a file.txt and let STK load it."));
152 
153  SERVER_CFG_PREFIX BoolServerConfigParam m_chat
154  SERVER_CFG_DEFAULT(BoolServerConfigParam(true, "chat",
155  "If this value is set to false, the server will ignore chat messages "
156  "from all players."));
157 
158  SERVER_CFG_PREFIX IntServerConfigParam m_chat_consecutive_interval
159  SERVER_CFG_DEFAULT(IntServerConfigParam(8, "chat-consecutive-interval",
160  "If client sends more than chat-consecutive-interval / 2 chats within "
161  "this value (read in seconds), it will be ignore, negative value to "
162  "disable."));
163 
164  SERVER_CFG_PREFIX BoolServerConfigParam m_track_voting
165  SERVER_CFG_DEFAULT(BoolServerConfigParam(true, "track-voting",
166  "Allow players to vote for which track to play. If this value is set "
167  "to false, the server will randomly pick the next track to play."));
168 
169  SERVER_CFG_PREFIX FloatServerConfigParam m_voting_timeout
170  SERVER_CFG_DEFAULT(FloatServerConfigParam(30.0f, "voting-timeout",
171  "Timeout in seconds for selecting karts and (or) voting tracks in "
172  "server, you may want to use a lower value if you have track-voting "
173  "off."));
174 
175  SERVER_CFG_PREFIX FloatServerConfigParam m_validation_timeout
176  SERVER_CFG_DEFAULT(FloatServerConfigParam(20.0f, "validation-timeout",
177  "Timeout in seconds for validation of clients in wan, currently "
178  "STK will use the stk-addons server to share AES key between the client "
179  "and server."));
180 
181  SERVER_CFG_PREFIX BoolServerConfigParam m_validating_player
182  SERVER_CFG_DEFAULT(BoolServerConfigParam(true, "validating-player",
183  "By default WAN server will always validate player and LAN will not, "
184  "disable it to allow non-validated player in WAN."));
185 
186  SERVER_CFG_PREFIX BoolServerConfigParam m_firewalled_server
187  SERVER_CFG_DEFAULT(BoolServerConfigParam(true, "firewalled-server",
188  "Disable it to turn off all stun related code in server, "
189  "it allows for saving of server resources if your server is not "
190  "behind a firewall."));
191 
192  SERVER_CFG_PREFIX BoolServerConfigParam m_ipv6_connection
193  SERVER_CFG_DEFAULT(BoolServerConfigParam(true, "ipv6-connection",
194  "Enable to allow IPv6 connection if you have a public IPv6 address. "
195  "STK currently uses dual-stack mode which requires server to have both "
196  "IPv4 and IPv6 and listen to same port. If STK detects your server "
197  "has no public IPv6 address or port differs between IPv4 and IPv6 "
198  "then it will use IPv4 only socket. For system which doesn't support "
199  "dual-stack socket (like OpenBSD) you may fail to be connected by "
200  "IPv4 clients. You can override the detection in config.xml at "
201  "supertuxkart config-0.10 folder, with default-ip-type option."));
202 
203  SERVER_CFG_PREFIX BoolServerConfigParam m_owner_less
204  SERVER_CFG_DEFAULT(BoolServerConfigParam(false, "owner-less",
205  "No server owner in lobby which can control the starting of game or "
206  "kick any players."));
207 
208  SERVER_CFG_PREFIX FloatServerConfigParam m_start_game_counter
209  SERVER_CFG_DEFAULT(FloatServerConfigParam(60.0f, "start-game-counter",
210  "Time to wait before entering kart selection screen "
211  "if satisfied min-start-game-players below for owner less or ranked "
212  "server."));
213 
214  SERVER_CFG_PREFIX FloatServerConfigParam m_official_karts_threshold
215  SERVER_CFG_DEFAULT(FloatServerConfigParam(1.0f,
216  "official-karts-threshold",
217  "Clients below this value will be rejected from joining this server. "
218  "It's determined by number of official karts in client / number of "
219  "official karts in server"));
220 
221  SERVER_CFG_PREFIX FloatServerConfigParam m_official_tracks_threshold
222  SERVER_CFG_DEFAULT(FloatServerConfigParam(0.7f,
223  "official-tracks-threshold",
224  "Clients below this value will be rejected from joining this server. "
225  "It's determined by number of official tracks in client / number of "
226  "official tracks in server, setting this value too high will prevent "
227  "android players from joining this server, because STK android apk "
228  "has some official tracks removed."));
229 
230  SERVER_CFG_PREFIX IntServerConfigParam m_min_start_game_players
231  SERVER_CFG_DEFAULT(IntServerConfigParam(2, "min-start-game-players",
232  "Only auto start kart selection when number of "
233  "connected player is larger than or equals this value, for "
234  "owner less or ranked server, after start-game-counter reaches 0."));
235 
236  SERVER_CFG_PREFIX BoolServerConfigParam m_auto_end
237  SERVER_CFG_DEFAULT(BoolServerConfigParam(false, "auto-end",
238  "Automatically end linear race game after 1st player finished "
239  "for some time (currently his finished time * 0.25 + 15.0)."));
240 
241  SERVER_CFG_PREFIX BoolServerConfigParam m_team_choosing
242  SERVER_CFG_DEFAULT(BoolServerConfigParam(true, "team-choosing",
243  "Enable team choosing in lobby in team game (soccer and CTF). "
244  "If owner-less is enabled and live-spectate is not enabled, than this "
245  "option is always disabled."));
246 
247  SERVER_CFG_PREFIX BoolServerConfigParam m_strict_players
248  SERVER_CFG_DEFAULT(BoolServerConfigParam(false, "strict-players",
249  "If strict-players is on, no duplicated online id or split screen "
250  "players are allowed, which can prevent someone using more than 1 "
251  "network AI with this server."));
252 
253  SERVER_CFG_PREFIX BoolServerConfigParam m_ranked
254  SERVER_CFG_DEFAULT(BoolServerConfigParam(false, "ranked",
255  "Server will submit ranking to stk-addons server "
256  "for linear race games, you require permission for that. "
257  "validating-player, auto-end, strict-player and owner-less will be "
258  "turned on."));
259 
260  SERVER_CFG_PREFIX BoolServerConfigParam m_server_configurable
261  SERVER_CFG_DEFAULT(BoolServerConfigParam(false, "server-configurable",
262  "If true, the server owner can config the difficulty and game mode in "
263  "the GUI of lobby. This option cannot be used with owner-less or "
264  "grand prix server, and will be automatically turned on if the server "
265  "was created using the in-game GUI. The changed difficulty and game "
266  "mode will not be saved in this config file."));
267 
268  SERVER_CFG_PREFIX BoolServerConfigParam m_live_players
269  SERVER_CFG_DEFAULT(BoolServerConfigParam(true, "live-spectate",
270  "If true, players can live join or spectate the in-progress game. "
271  "Currently live joining is only available if the current game mode "
272  "used in server is FFA, CTF or soccer, also official-karts-threshold "
273  "will be made 1.0. If false addon karts will use their original "
274  "hitbox other than tux, all players having it restriction applies."));
275 
276  SERVER_CFG_PREFIX BoolServerConfigParam m_real_addon_karts
277  SERVER_CFG_DEFAULT(BoolServerConfigParam(true, "real-addon-karts",
278  "If true, server will send its addon karts real physics (kart size, "
279  "length, type, etc) to client. If false or client chooses an addon "
280  "kart which server is missing, tux's kart physics and kart type of "
281  "the original addon is sent."));
282 
283  SERVER_CFG_PREFIX FloatServerConfigParam m_flag_return_timeout
284  SERVER_CFG_DEFAULT(FloatServerConfigParam(20.0f, "flag-return-timeout",
285  "Time in seconds when a flag is dropped a by player in CTF "
286  "returning to its own base."));
287 
288  SERVER_CFG_PREFIX FloatServerConfigParam m_flag_deactivated_time
289  SERVER_CFG_DEFAULT(FloatServerConfigParam(3.0f, "flag-deactivated-time",
290  "Time in seconds to deactivate a flag when it's captured or returned "
291  "to own base by players."));
292 
293  SERVER_CFG_PREFIX IntServerConfigParam m_hit_limit
294  SERVER_CFG_DEFAULT(IntServerConfigParam(20, "hit-limit",
295  "Hit limit of free for all, zero to disable hit limit."));
296 
297  SERVER_CFG_PREFIX IntServerConfigParam m_time_limit_ffa
298  SERVER_CFG_DEFAULT(IntServerConfigParam(360,
299  "time-limit-ffa", "Time limit of free for all in seconds, zero to "
300  "disable time limit."));
301 
302  SERVER_CFG_PREFIX IntServerConfigParam m_capture_limit
303  SERVER_CFG_DEFAULT(IntServerConfigParam(5, "capture-limit",
304  "Capture limit of CTF, zero to disable capture limit."));
305 
306  SERVER_CFG_PREFIX IntServerConfigParam m_time_limit_ctf
307  SERVER_CFG_DEFAULT(IntServerConfigParam(600, "time-limit-ctf",
308  "Time limit of CTF in seconds, zero to disable time limit."));
309 
310  SERVER_CFG_PREFIX FloatServerConfigParam m_auto_game_time_ratio
311  SERVER_CFG_DEFAULT(FloatServerConfigParam(-1.0f, "auto-game-time-ratio",
312  "Value used by server to automatically estimate each game time. "
313  "For races, it decides the lap of each race in network game, "
314  "if more than 0.0f, the number of lap of each track vote in "
315  "linear race will be determined by "
316  "max(1.0f, auto-game-time-ratio * default lap of that track). "
317  "For soccer if more than 0.0f, for time limit game it will be "
318  "auto-game-time-ratio * soccer-time-limit in UserConfig, for goal "
319  "limit game it will be auto-game-time-ratio * numgoals "
320  "in UserConfig, -1 to disable for all."));
321 
322  SERVER_CFG_PREFIX IntServerConfigParam m_max_ping
323  SERVER_CFG_DEFAULT(IntServerConfigParam(300, "max-ping",
324  "Maximum ping allowed for a player (in ms), it's recommended to use "
325  "default value if live-spectate is on."));
326 
327  SERVER_CFG_PREFIX IntServerConfigParam m_jitter_tolerance
328  SERVER_CFG_DEFAULT(IntServerConfigParam(100, "jitter-tolerance",
329  "Tolerance of jitter in network allowed (in ms), it's recommended to "
330  "use default value if live-spectate is on."));
331 
332  SERVER_CFG_PREFIX BoolServerConfigParam m_kick_high_ping_players
333  SERVER_CFG_DEFAULT(BoolServerConfigParam(false,
334  "kick-high-ping-players",
335  "Kick players whose ping is above max-ping."));
336 
337  SERVER_CFG_PREFIX BoolServerConfigParam m_high_ping_workaround
338  SERVER_CFG_DEFAULT(BoolServerConfigParam(true,
339  "high-ping-workaround",
340  "Allow players exceeding max-ping to have a playable game, if enabled "
341  "kick-high-ping-players will be disabled, please also use a default "
342  "value for max-ping and jitter-tolerance with it."));
343 
344  SERVER_CFG_PREFIX IntServerConfigParam m_kick_idle_player_seconds
345  SERVER_CFG_DEFAULT(IntServerConfigParam(60,
346  "kick-idle-player-seconds",
347  "Kick idle player which has no network activity to server for more "
348  "than some seconds during game, unless he has finished the race. "
349  "Negative value to disable, and this option will always be disabled "
350  "for LAN server."));
351 
352  SERVER_CFG_PREFIX IntServerConfigParam m_state_frequency
353  SERVER_CFG_DEFAULT(IntServerConfigParam(10,
354  "state-frequency",
355  "Set how many states the server will send per second, the higher this "
356  "value, the more bandwidth requires, also each client will trigger "
357  "more rewind, which clients with slow device may have problem playing "
358  "this server, use the default value is recommended."));
359 
360  SERVER_CFG_PREFIX BoolServerConfigParam m_sql_management
361  SERVER_CFG_DEFAULT(BoolServerConfigParam(false,
362  "sql-management",
363  "Use sql database for handling server stats and maintenance, STK "
364  "needs to be compiled with sqlite3 supported."));
365 
366  SERVER_CFG_PREFIX StringServerConfigParam m_database_file
367  SERVER_CFG_DEFAULT(StringServerConfigParam("stkservers.db",
368  "database-file",
369  "Database filename for sqlite to use, it can be shared for all "
370  "servers created in this machine, and STK will create specific table "
371  "for each server. You need to create the database yourself first, see "
372  "NETWORKING.md for details"));
373 
374  SERVER_CFG_PREFIX IntServerConfigParam m_database_timeout
375  SERVER_CFG_DEFAULT(IntServerConfigParam(1000,
376  "database-timeout",
377  "Specified in millisecond for maximum time waiting in "
378  "sqlite3_busy_handler. You may need a higher value if your database "
379  "is shared by many servers or having a slow hard disk."));
380 
381  SERVER_CFG_PREFIX StringServerConfigParam m_ip_ban_table
382  SERVER_CFG_DEFAULT(StringServerConfigParam("ip_ban",
383  "ip-ban-table",
384  "IPv4 ban list table name, you need to create the table first, see "
385  "NETWORKING.md for details, empty to disable. "
386  "This table can be shared for all servers if you use the same name. "
387  "STK can auto kick active peer from ban list (update per minute) which"
388  "allows live kicking peer by inserting record to database."));
389 
390  SERVER_CFG_PREFIX StringServerConfigParam m_ipv6_ban_table
391  SERVER_CFG_DEFAULT(StringServerConfigParam("ipv6_ban",
392  "ipv6-ban-table",
393  "IPv6 ban list table name, you need to create the table first, see "
394  "NETWORKING.md for details, empty to disable. "
395  "This table can be shared for all servers if you use the same name. "
396  "STK can auto kick active peer from ban list (update per minute) "
397  "which allows live kicking peer by inserting record to database."));
398 
399  SERVER_CFG_PREFIX StringServerConfigParam m_online_id_ban_table
400  SERVER_CFG_DEFAULT(StringServerConfigParam("online_id_ban",
401  "online-id-ban-table",
402  "Online ID ban list table name, you need to create the table first, "
403  "see NETWORKING.md for details, empty to disable. "
404  "This table can be shared for all servers if you use the same name. "
405  "STK can auto kick active peer from ban list (update per minute) "
406  "which allows live kicking peer by inserting record to database."));
407 
408  SERVER_CFG_PREFIX StringServerConfigParam m_player_reports_table
409  SERVER_CFG_DEFAULT(StringServerConfigParam("player_reports",
410  "player-reports-table",
411  "Player reports table name, which will be written when a player "
412  "reports player in the network user dialog, you need to create the "
413  "table first, see NETWORKING.md for details, empty to disable. "
414  "This table can be shared for all servers if you use the same name."));
415 
416  SERVER_CFG_PREFIX FloatServerConfigParam m_player_reports_expired_days
417  SERVER_CFG_DEFAULT(FloatServerConfigParam(3.0f,
418  "player-reports-expired-days", "Days to keep player reports, "
419  "older than that will be auto cleared, 0 to keep them forever."));
420 
421  SERVER_CFG_PREFIX StringServerConfigParam m_ip_geolocation_table
422  SERVER_CFG_DEFAULT(StringServerConfigParam("ip_mapping",
423  "ip-geolocation-table",
424  "IP geolocation table, you only need this table if you want to "
425  "geolocate IP from non-stk-addons connection, as all validated "
426  "players connecting from stk-addons will provide the location info, "
427  "you need to create the table first, see NETWORKING.md for details, "
428  "empty to disable. "
429  "This table can be shared for all servers if you use the same name."));
430 
431  SERVER_CFG_PREFIX StringServerConfigParam m_ipv6_geolocation_table
432  SERVER_CFG_DEFAULT(StringServerConfigParam("ipv6_mapping",
433  "ipv6-geolocation-table",
434  "IPv6 geolocation table, you only need this table if you want to "
435  "geolocate IP from non-stk-addons connection, as all validated "
436  "players connecting from stk-addons will provide the location info, "
437  "you need to create the table first, see NETWORKING.md for details, "
438  "empty to disable. "
439  "This table can be shared for all servers if you use the same name."));
440 
441  SERVER_CFG_PREFIX BoolServerConfigParam m_ai_handling
442  SERVER_CFG_DEFAULT(BoolServerConfigParam(false, "ai-handling",
443  "If true this server will auto add / remove AI connected with "
444  "network-ai=x, which will kick N - 1 bot(s) where N is the number "
445  "of human players. Only use this for non-GP racing server."));
446 
447  SERVER_CFG_PREFIX BoolServerConfigParam m_ai_anywhere
448  SERVER_CFG_DEFAULT(BoolServerConfigParam(false, "ai-anywhere",
449  "If true this server will allow AI instance to be connected from "
450  "anywhere. (other than LAN network only)"));
451 
452  // ========================================================================
454  static const uint32_t m_server_version = 6;
455  // ========================================================================
458  static const uint32_t m_server_db_version = 1;
459  // ========================================================================
461  extern std::string m_server_uid;
462  // ========================================================================
463  void loadServerConfig(const std::string& path = "");
464  // ------------------------------------------------------------------------
465  void loadServerConfigXML(const XMLNode* root, bool default_config = false);
466  // ------------------------------------------------------------------------
467  std::string getServerConfigXML();
468  // ------------------------------------------------------------------------
469  void writeServerConfigToDisk();
470  // ------------------------------------------------------------------------
471  std::pair<RaceManager::MinorRaceModeType, RaceManager::MajorRaceModeType>
472  getLocalGameModeFromConfig();
473  // ------------------------------------------------------------------------
474  std::pair<RaceManager::MinorRaceModeType, RaceManager::MajorRaceModeType>
475  getLocalGameMode(int mode);
476  // ------------------------------------------------------------------------
477  core::stringw getModeName(unsigned id);
478  // ------------------------------------------------------------------------
479  inline bool unsupportedGameMode()
480  { return m_server_mode == 2 || m_server_mode == 5; }
481  // ------------------------------------------------------------------------
482  void loadServerLobbyFromConfig();
483  // ------------------------------------------------------------------------
484  std::string getConfigDirectory();
485 
486 }; // namespace ServerConfig
487 
488 #endif // HEADER_SERVER_CONFIG
Definition: user_config.hpp:296
Definition: user_config.hpp:329
Definition: user_config.hpp:194
ATM only map with 1 key and 1 value is supported.
Definition: user_config.hpp:110
Definition: server_config.hpp:58
Definition: server_config.hpp:42
Definition: server_config.hpp:50
Definition: server_config.hpp:75
Definition: server_config.hpp:66
Definition: user_config.hpp:256
utility class used to parse XML files
Definition: xml_node.hpp:48