The Battle for Wesnoth  1.17.0-dev
game.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "mt_rng.hpp"
22 #include "utils/make_enum.hpp"
23 
24 #include <map>
25 #include <optional>
26 #include <vector>
27 
28 // class player;
29 
30 namespace wesnothd
31 {
32 typedef std::vector<player_iterator> user_vector;
33 typedef std::vector<std::optional<player_iterator>> side_vector;
34 class server;
35 
36 class game
37 {
38 public:
39  MAKE_ENUM(CONTROLLER,
40  (HUMAN, "human")
41  (AI, "ai")
42  (EMPTY, "null")
43  );
44 
46  player_iterator host,
47  const std::string& name = "",
48  bool save_replays = false,
49  const std::string& replay_save_path = "");
50 
51  ~game();
52 
53  int id() const
54  {
55  return id_;
56  }
57 
58  int db_id() const
59  {
60  return db_id_;
61  }
62 
63  void next_db_id()
64  {
65  db_id_ = db_id_num++;
66  }
67 
68  const std::string& name() const
69  {
70  return name_;
71  }
72 
74  {
75  return (player == owner_);
76  }
77 
79  {
80  return is_player(player) || is_observer(player);
81  }
82 
83  bool allow_observers() const;
85  bool is_player(player_iterator player) const;
86 
87  /** Checks whether the connection's ip address or username is banned. */
88  bool player_is_banned(player_iterator player, const std::string& name) const;
89 
90  /** when the host sends the new scenario of a mp campaign */
91  void new_scenario(player_iterator player);
92 
93  bool level_init() const
94  {
95  return level_.child("snapshot") || level_.child("scenario");
96  }
97 
99  {
100  if(simple_wml::node* scenario = data.child("scenario")) {
101  return scenario;
102  } else if(simple_wml::node* snapshot = data.child("snapshot")) {
103  return snapshot;
104  }
105 
106  return &data;
107  }
108 
109  static const simple_wml::node* starting_pos(const simple_wml::node& data)
110  {
111  if(const simple_wml::node* scenario = data.child("scenario")) {
112  return scenario;
113  } else if(const simple_wml::node* snapshot = data.child("snapshot")) {
114  return snapshot;
115  }
116 
117  return &data;
118  }
119 
121  {
122  return starting_pos(level_.root())->children("side");
123  }
124 
125  bool started() const
126  {
127  return started_;
128  }
129 
130  std::size_t nplayers() const
131  {
132  return players_.size();
133  }
134 
135  std::size_t nobservers() const
136  {
137  return observers_.size();
138  }
139 
140  std::size_t current_turn() const
141  {
142  return current_turn_;
143  }
144 
145  void set_current_turn(int turn)
146  {
147  current_turn_ = turn;
148  }
149 
150  std::string get_replay_filename();
151 
152  void mute_all_observers();
153 
154  /**
155  * Mute an observer or give a message of all currently muted observers if no
156  * name is given.
157  */
158  void mute_observer(const simple_wml::node& mute, player_iterator muter);
159 
160  void unmute_observer(const simple_wml::node& unmute, player_iterator unmuter);
161 
162  /**
163  * Kick a member by name.
164  *
165  * @return The iterator to the removed member if
166  * successful, empty optional otherwise.
167  */
168  std::optional<player_iterator> kick_member(const simple_wml::node& kick, player_iterator kicker);
169 
170  /**
171  * Ban and kick a user by name.
172  *
173  * The user does not need to be in this game but logged in.
174  *
175  * @return The iterator to the banned player if he
176  * was in this game, empty optional otherwise.
177  */
178  std::optional<player_iterator> ban_user(const simple_wml::node& ban, player_iterator banner);
179 
180  void unban_user(const simple_wml::node& unban, player_iterator unbanner);
181 
182  /**
183  * Add a user to the game.
184  *
185  * @return True iff the user successfully joined the game.
186  */
187  bool add_player(player_iterator player, bool observer = false);
188 
189  /**
190  * Removes a user from the game.
191  *
192  * @return True iff the game ends. That is, if there are
193  * no more players or the host left on a not yet
194  * started game.
195  */
196  bool remove_player(player_iterator player, const bool disconnect = false, const bool destruct = false);
197 
198  /** Adds players and observers into one vector and returns that. */
199  const user_vector all_game_users() const;
200 
201  void start_game(player_iterator starter);
202 
203  // this is performed just before starting and before [start_game] signal
204  // send scenario_diff's specific to each client so that they locally
205  // control their human sides
207 
208  void update_game();
209 
210  /** A user (player only?) asks for the next scenario to advance to. */
211  void load_next_scenario(player_iterator user); // const
212 
213  // iceiceice: I unmarked this const because I want to send and record server messages when I fail to tweak sides
214  // properly
215 
216  /** Resets the side configuration according to the scenario data. */
217  void update_side_data();
218 
219  /** Let's a player owning a side give it to another player or observer. */
220  void transfer_side_control(player_iterator player, const simple_wml::node& cfg);
221 
223 
224  /**
225  * Handles [end_turn], repackages [commands] with private [speak]s in them
226  * and sends the data.
227  * Also filters commands from all but the current player.
228  * Currently removes all commands but [speak] for observers and all but
229  * [speak], [label] and [rename] for players.
230  *
231  * @returns True if the turn ended.
232  */
234 
235  /** Handles incoming [whiteboard] data. */
237  /** Handles incoming [change_turns_wml] data. */
239 
240  /**
241  * Set the description to the number of available slots.
242  *
243  * @returns True iff the number of slots has changed.
244  */
245  bool describe_slots();
246 
247  void send_server_message_to_all(const char* message, std::optional<player_iterator> exclude = {});
248  void send_server_message_to_all(const std::string& message, std::optional<player_iterator> exclude = {})
249  {
250  send_server_message_to_all(message.c_str(), exclude);
251  }
252 
253  void send_server_message(
254  const char* message, std::optional<player_iterator> player = {}, simple_wml::document* doc = nullptr) const;
256  const std::string& message, std::optional<player_iterator> player = {}, simple_wml::document* doc = nullptr) const
257  {
258  send_server_message(message.c_str(), player, doc);
259  }
260 
261  /** Send data to all players in this game except 'exclude'. */
262  void send_and_record_server_message(const char* message, std::optional<player_iterator> exclude = {});
263  void send_and_record_server_message(const std::string& message, std::optional<player_iterator> exclude = {})
264  {
265  send_and_record_server_message(message.c_str(), exclude);
266  }
267 
268  template<typename Container>
269  void send_to_players(simple_wml::document& data, const Container& players, std::optional<player_iterator> exclude = {});
270  void send_data(simple_wml::document& data, std::optional<player_iterator> exclude = {}, std::string packet_type = "");
271 
272  void clear_history();
273  void record_data(std::unique_ptr<simple_wml::document> data);
274  void save_replay();
275 
276  /** The full scenario data. */
278  {
279  return level_;
280  }
281 
282  /**
283  * Functions to set/get the address of the game's summary description as
284  * sent to players in the lobby.
285  */
286  void set_description(simple_wml::node* desc);
287 
289  {
290  return description_;
291  }
292 
293  void set_password(const std::string& passwd)
294  {
295  password_ = passwd;
296  }
297 
298  void set_name_bans(const std::vector<std::string> name_bans)
299  {
300  name_bans_ = name_bans;
301  }
302 
303  bool password_matches(const std::string& passwd) const
304  {
305  return password_.empty() || passwd == password_;
306  }
307 
308  bool has_password() const
309  {
310  return !password_.empty();
311  }
312 
313  const std::string& termination_reason() const
314  {
315  static const std::string aborted = "aborted";
316  static const std::string not_started = "not started";
317 
318  return started_ ? (termination_.empty() ? aborted : termination_) : not_started;
319  }
320 
321  void set_termination_reason(const std::string& reason);
322 
323  void handle_choice(const simple_wml::node& data, player_iterator user);
324 
325  void handle_random_choice(const simple_wml::node& data);
326 
327  void handle_controller_choice(const simple_wml::node& data);
328 
329  void handle_add_side_wml(const simple_wml::node& req);
330 
332  {
334  }
335 
336  /**
337  * Function which returns true iff 'player' controls any of the sides spcified in 'sides'.
338  */
339  bool controls_side(const std::vector<int>& sides, player_iterator player) const;
340 
341  bool is_reload() const;
342 
343 private:
344  // forbidden operations
345  game(const game&) = delete;
346  game& operator=(const game&) = delete;
347 
348  std::size_t current_side() const
349  {
350  return nsides_ ? (current_side_index_ % nsides_) : 0;
351  }
352 
353  std::optional<player_iterator> current_player() const
354  {
355  return sides_[current_side()];
356  }
357 
359  {
360  return (current_player() == player);
361  }
362 
363  bool is_muted_observer(player_iterator player) const;
364  bool all_observers_muted() const
365  {
366  return all_observers_muted_;
367  }
368 
369  void send_muted_observers(player_iterator user) const;
370 
371  bool send_taken_side(simple_wml::document& cfg, const simple_wml::node* side) const;
372 
373  /**
374  * Figures out which side to take and tells that side to the game owner.
375  *
376  * The owner then should send a [scenario_diff] that implements the side
377  * change and a subsequent update_side_data() call makes it actually
378  * happen.
379  * First we look for a side where save_id= or current_player= matches the
380  * new user's name then we search for the first controller="network" side.
381  */
382  bool take_side(player_iterator user);
383 
384  /**
385  * Send [change_controller] message to tell all clients the new controller's name
386  * or controller type (human or ai).
387  */
388  void change_controller(const std::size_t side_num,
389  player_iterator sock,
390  const std::string& player_name,
391  const bool player_left = true);
392  std::unique_ptr<simple_wml::document> change_controller_type(const std::size_t side_num,
393  player_iterator player,
394  const std::string& player_name);
395  void transfer_ai_sides(player_iterator player);
396  void send_leave_game(player_iterator user) const;
397 
398  /**
399  * @param data the data to be sent to the sides.
400  * @param sides a comma sperated list of side numbers to which the package should be sent.
401  * @param exclude sides to not send the data to.
402  */
404  const simple_wml::string_span& sides,
405  std::optional<player_iterator> exclude = {});
406 
407  void send_data_observers(
408  simple_wml::document& data, std::optional<player_iterator> exclude = {}, std::string packet_type = "") const;
409 
410  /**
411  * Send [observer] tags of all the observers in the game to the user or
412  * everyone if none given.
413  */
414  void send_observerjoins(std::optional<player_iterator> player = {});
416  void send_history(player_iterator sock) const;
417 
418  /** In case of a host transfer, notify the new host about its status. */
419  void notify_new_host();
420 
421  /** Shortcut to a convenience function for finding a user by name. */
422  std::optional<player_iterator> find_user(const simple_wml::string_span& name);
423 
424  bool observers_can_label() const
425  {
426  return false;
427  }
428 
429  bool observers_can_chat() const
430  {
431  return true;
432  }
433 
434  bool is_legal_command(const simple_wml::node& command, player_iterator user);
435 
436  /**
437  * Checks whether a user has the same IP as any other members of this game.
438  * @return A comma separated string of members with matching IPs.
439  */
440  std::string has_same_ip(player_iterator user) const;
441 
442  /**
443  * Function which should be called every time a player ends their turn
444  * (i.e. [end_turn] received). This will update the 'turn' attribute for
445  * the game's description when appropriate. Will return true iff there has
446  * been a change.
447  */
448  bool end_turn(int new_side);
449 
450  void update_turn_data();
451  /**
452  * Function to send a list of users to all clients.
453  *
454  * Only sends data if the game is initialized but not yet started.
455  */
456  void send_user_list(std::optional<player_iterator> exclude = {});
457 
458  /** Returns the name of the user or "(unfound)". */
459  std::string username(player_iterator pl) const;
460 
461  /** Returns a comma separated list of user names. */
462  std::string list_users(user_vector users) const;
463 
464  /** calculates the initial value for sides_, side_controllerds_, nsides_*/
465  void reset_sides();
466 
467  /** Helps debugging player and observer lists. */
468  std::string debug_player_info() const;
469 
470  /** Helps debugging controller tweaks. */
471  std::string debug_sides_info() const;
472 
474  player_connections& player_connections_;
475 
476  // used for unique identification of game instances within wesnothd
477  static int id_num;
478  int id_;
479 
480  // used for unique identification of games played in the database
481  // necessary since for MP campaigns multiple scenarios can be played within the same game instance
482  // and we need a unique ID per scenario played, not per game instance
483  static int db_id_num;
484  int db_id_;
485 
486  /** The name of the game. */
487  std::string name_;
488  std::string password_;
489 
490  /** The game host or later owner (if the host left). */
492 
493  /** A vector of players (members owning a side). */
494  user_vector players_;
495 
496  /** A vector of observers (members not owning a side). */
497  user_vector observers_;
498  user_vector muted_observers_;
499 
500  /** A vector of side owners. */
501  side_vector sides_;
502 
503  std::vector<CONTROLLER> side_controllers_;
504 
505  /** Number of sides in the current scenario. */
506  int nsides_;
507  bool started_;
508 
509  /**
510  The current scenario data.ยด
511  WRONG! This contains the initial state or the state from which
512  the game was loaded from.
513  Using this to make assumptions about the current gamestate is
514  extremely dangerous and should especially not be done for anything
515  that can be nodified by wml (especially by [modify_side]),
516  like team_name, controller ... in [side].
517  FIXME: move every code here that uses this object to query those
518  information to the clients. But note that there are some checks
519  (like controller == null) that are definitely needed by the server and
520  in this case we should try to modify the client to inform the server if
521  a change of those properties occur. Ofc we shouldn't update level_
522  then, but rather store that information in a separate object
523  (like in side_controllers_).
524  */
526 
527  /** Replay data. */
528  mutable std::vector<std::unique_ptr<simple_wml::document>> history_;
529 
530  /** Pointer to the game's description in the games_and_users_list_. */
532 
537 
538  // IP ban list and name ban list
539  std::vector<std::string> bans_;
540  std::vector<std::string> name_bans_;
541  /**
542  * in multiplayer campaigns it can happen that some players are still in the previous scenario
543  * keep track of those players because processing certain
544  * input from those side wil lead to error (oos)
545  */
546  std::set<const player_record*> players_not_advanced_;
547 
548  std::string termination_;
549 
551  std::string replay_save_path_;
552 
553  /** A wrapper for mersenne twister rng which generates randomness for this game */
556 };
557 
558 } // namespace wesnothd
bool save_replays_
Definition: game.hpp:550
bool started() const
Definition: game.hpp:125
bool is_muted_observer(player_iterator player) const
Definition: game.cpp:155
void handle_choice(const simple_wml::node &data, player_iterator user)
Definition: game.cpp:1200
std::set< const player_record * > players_not_advanced_
in multiplayer campaigns it can happen that some players are still in the previous scenario keep trac...
Definition: game.hpp:546
void send_and_record_server_message(const char *message, std::optional< player_iterator > exclude={})
Send data to all players in this game except &#39;exclude&#39;.
Definition: game.cpp:1930
void set_current_turn(int turn)
Definition: game.hpp:145
void update_game()
Definition: game.cpp:329
void send_observerquit(player_iterator observer)
Definition: game.cpp:1711
const std::string & name() const
Definition: game.hpp:68
void send_server_message_to_all(const std::string &message, std::optional< player_iterator > exclude={})
Definition: game.hpp:248
bool observers_can_label() const
Definition: game.hpp:424
void save_replay()
Definition: game.cpp:1780
player_connections & player_connections_
Definition: game.hpp:474
void mute_observer(const simple_wml::node &mute, player_iterator muter)
Mute an observer or give a message of all currently muted observers if no name is given...
Definition: game.cpp:699
std::optional< player_iterator > ban_user(const simple_wml::node &ban, player_iterator banner)
Ban and kick a user by name.
Definition: game.cpp:811
void send_to_players(simple_wml::document &data, const Container &players, std::optional< player_iterator > exclude={})
Definition: game.cpp:1633
void process_change_turns_wml(simple_wml::document &data, player_iterator user)
Handles incoming [change_turns_wml] data.
Definition: game.cpp:1271
bool is_player(player_iterator player) const
Definition: game.cpp:168
std::vector< std::unique_ptr< simple_wml::document > > history_
Replay data.
Definition: game.hpp:528
void handle_random_choice(const simple_wml::node &data)
Definition: game.cpp:1108
const simple_wml::node::child_list & get_sides_list() const
Definition: game.hpp:120
bool is_current_player(player_iterator player) const
Definition: game.hpp:358
user_vector muted_observers_
Definition: game.hpp:498
void update_side_data()
Resets the side configuration according to the scenario data.
Definition: game.cpp:410
bool player_is_banned(player_iterator player, const std::string &name) const
Checks whether the connection&#39;s ip address or username is banned.
Definition: game.cpp:669
std::string username(player_iterator pl) const
Returns the name of the user or "(unfound)".
Definition: game.cpp:173
void transfer_ai_sides(player_iterator player)
bool level_init() const
Definition: game.hpp:93
std::optional< player_iterator > find_user(const simple_wml::string_span &name)
Shortcut to a convenience function for finding a user by name.
Definition: game.cpp:1920
std::size_t current_side() const
Definition: game.hpp:348
int nsides_
Number of sides in the current scenario.
Definition: game.hpp:506
user_vector observers_
A vector of observers (members not owning a side).
Definition: game.hpp:497
void send_leave_game(player_iterator user) const
Definition: game.cpp:773
bool is_observer(player_iterator player) const
Definition: game.cpp:150
bool all_observers_muted_
Definition: game.hpp:536
bool is_member(player_iterator player) const
Definition: game.hpp:78
std::string termination_
Definition: game.hpp:548
game & operator=(const game &)=delete
void send_data_observers(simple_wml::document &data, std::optional< player_iterator > exclude={}, std::string packet_type="") const
void new_scenario(player_iterator player)
when the host sends the new scenario of a mp campaign
Definition: game.cpp:1568
randomness::mt_rng rng_
A wrapper for mersenne twister rng which generates randomness for this game.
Definition: game.hpp:554
int db_id() const
Definition: game.hpp:58
player_iterator owner_
The game host or later owner (if the host left).
Definition: game.hpp:491
bool process_turn(simple_wml::document &data, player_iterator user)
Handles [end_turn], repackages [commands] with private [speak]s in them and sends the data...
Definition: game.cpp:960
player_connections::const_iterator player_iterator
void send_and_record_server_message(const std::string &message, std::optional< player_iterator > exclude={})
Definition: game.hpp:263
std::vector< std::string > bans_
Definition: game.hpp:539
void next_db_id()
Definition: game.hpp:63
wesnothd::server & server
Definition: game.hpp:473
bool is_legal_command(const simple_wml::node &command, player_iterator user)
Definition: game.cpp:895
node * child(const char *name)
Definition: simple_wml.hpp:262
node * child(const char *name)
Definition: simple_wml.cpp:607
bmi::multi_index_container< player_record, bmi::indexed_by< bmi::ordered_unique< bmi::tag< socket_t >, bmi::const_mem_fun< player_record, const any_socket_ptr, &player_record::socket > >, bmi::hashed_unique< bmi::tag< name_t >, bmi::const_mem_fun< player_record, const std::string &, &player_record::name > >, bmi::ordered_non_unique< bmi::tag< game_t >, bmi::const_mem_fun< player_record, int, &player_record::game_id > > > > player_connections
int last_choice_request_id_
Definition: game.hpp:555
bool password_matches(const std::string &passwd) const
Definition: game.hpp:303
bool end_turn(int new_side)
Function which should be called every time a player ends their turn (i.e.
Definition: game.cpp:1300
void reset_sides()
calculates the initial value for sides_, side_controllerds_, nsides_
Definition: game.cpp:399
std::vector< CONTROLLER > side_controllers_
Definition: game.hpp:503
bool has_password() const
Definition: game.hpp:308
void process_whiteboard(simple_wml::document &data, player_iterator user)
Handles incoming [whiteboard] data.
Definition: game.cpp:1244
int num_turns_
Definition: game.hpp:535
void send_history(player_iterator sock) const
Definition: game.cpp:1723
void update_turn_data()
Definition: game.cpp:1332
bool allow_observers() const
Definition: game.cpp:145
void handle_controller_choice(const simple_wml::node &data)
Definition: game.cpp:1136
bool describe_slots()
Set the description to the number of available slots.
Definition: game.cpp:638
void transfer_side_control(player_iterator player, const simple_wml::node &cfg)
Let&#39;s a player owning a side give it to another player or observer.
Definition: game.cpp:477
std::unique_ptr< simple_wml::document > change_controller_type(const std::size_t side_num, player_iterator player, const std::string &player_name)
Definition: game.cpp:610
void process_message(simple_wml::document &data, player_iterator)
Definition: game.cpp:883
static int db_id_num
Definition: game.hpp:483
std::string get_replay_filename()
Definition: game.cpp:1770
std::optional< player_iterator > current_player() const
Definition: game.hpp:353
std::size_t nobservers() const
Definition: game.hpp:135
void start_game(player_iterator starter)
Definition: game.cpp:252
const user_vector all_game_users() const
Adds players and observers into one vector and returns that.
Definition: game.cpp:1869
bool controls_side(const std::vector< int > &sides, player_iterator player) const
Function which returns true iff &#39;player&#39; controls any of the sides spcified in &#39;sides&#39;.
Definition: game.cpp:1663
void perform_controller_tweaks()
Definition: game.cpp:193
bool remove_player(player_iterator player, const bool disconnect=false, const bool destruct=false)
Removes a user from the game.
Definition: game.cpp:1435
bool all_observers_muted() const
Definition: game.hpp:364
std::optional< player_iterator > kick_member(const simple_wml::node &kick, player_iterator kicker)
Kick a member by name.
Definition: game.cpp:779
void load_next_scenario(player_iterator user)
A user (player only?) asks for the next scenario to advance to.
Definition: game.cpp:1580
bool is_owner(player_iterator player) const
Definition: game.hpp:73
bool observers_can_chat() const
Definition: game.hpp:429
static simple_wml::node * starting_pos(simple_wml::node &data)
Definition: game.hpp:98
void send_server_message(const char *message, std::optional< player_iterator > player={}, simple_wml::document *doc=nullptr) const
Definition: game.cpp:1948
static const simple_wml::node * starting_pos(const simple_wml::node &data)
Definition: game.hpp:109
std::vector< std::string > name_bans_
Definition: game.hpp:540
void record_data(std::unique_ptr< simple_wml::document > data)
Definition: game.cpp:1836
void send_observerjoins(std::optional< player_iterator > player={})
Send [observer] tags of all the observers in the game to the user or everyone if none given...
Definition: game.cpp:1691
std::vector< std::optional< player_iterator > > side_vector
Definition: game.hpp:33
std::vector< node * > child_list
Definition: simple_wml.hpp:126
bool add_player(player_iterator player, bool observer=false)
Add a user to the game.
Definition: game.cpp:1352
std::size_t current_turn() const
Definition: game.hpp:140
void reset_last_synced_context_id()
Definition: game.hpp:331
int current_side_index_
Definition: game.hpp:534
side_vector sides_
A vector of side owners.
Definition: game.hpp:501
void notify_new_host()
In case of a host transfer, notify the new host about its status.
Definition: game.cpp:627
void set_description(simple_wml::node *desc)
Functions to set/get the address of the game&#39;s summary description as sent to players in the lobby...
Definition: game.cpp:1847
std::string has_same_ip(player_iterator user) const
Checks whether a user has the same IP as any other members of this game.
Definition: game.cpp:1676
void change_controller(const std::size_t side_num, player_iterator sock, const std::string &player_name, const bool player_left=true)
Send [change_controller] message to tell all clients the new controller&#39;s name or controller type (hu...
Definition: game.cpp:578
void set_password(const std::string &passwd)
Definition: game.hpp:293
void send_data_sides(simple_wml::document &data, const simple_wml::string_span &sides, std::optional< player_iterator > exclude={})
Definition: game.cpp:1647
std::string observer
std::size_t nplayers() const
Definition: game.hpp:130
void handle_add_side_wml(const simple_wml::node &req)
Definition: game.cpp:1129
std::string list_users(user_vector users) const
Returns a comma separated list of user names.
Definition: game.cpp:178
simple_wml::node * description_
Pointer to the game&#39;s description in the games_and_users_list_.
Definition: game.hpp:531
std::string name_
The name of the game.
Definition: game.hpp:487
void unban_user(const simple_wml::node &unban, player_iterator unbanner)
Definition: game.cpp:853
std::string debug_sides_info() const
Helps debugging controller tweaks.
Definition: game.cpp:1901
static int id_num
Definition: game.hpp:477
MAKE_ENUM(CONTROLLER,(HUMAN, "human")(AI, "ai")(EMPTY, "null"))
std::vector< player_iterator > user_vector
Definition: game.hpp:32
bool is_reload() const
Definition: game.cpp:1977
void send_user_list(std::optional< player_iterator > exclude={})
Function to send a list of users to all clients.
Definition: game.cpp:1545
const std::string & termination_reason() const
Definition: game.hpp:313
std::string replay_save_path_
Definition: game.hpp:551
int current_turn_
Definition: game.hpp:533
user_vector players_
A vector of players (members owning a side).
Definition: game.hpp:494
void send_server_message_to_all(const char *message, std::optional< player_iterator > exclude={})
Definition: game.cpp:1941
std::string password_
Definition: game.hpp:488
void send_muted_observers(player_iterator user) const
Definition: game.cpp:687
bool started_
Definition: game.hpp:507
bool send_taken_side(simple_wml::document &cfg, const simple_wml::node *side) const
Definition: game.cpp:337
std::string debug_player_info() const
Helps debugging player and observer lists.
Definition: game.cpp:1879
void set_name_bans(const std::vector< std::string > name_bans)
Definition: game.hpp:298
void send_server_message(const std::string &message, std::optional< player_iterator > player={}, simple_wml::document *doc=nullptr) const
Definition: game.hpp:255
void unmute_observer(const simple_wml::node &unmute, player_iterator unmuter)
Definition: game.cpp:741
Defines the MAKE_ENUM macro.
simple_wml::document level_
The current scenario data.
Definition: game.hpp:525
void clear_history()
Definition: game.cpp:1842
void mute_all_observers()
Definition: game.cpp:677
bool take_side(player_iterator user)
Figures out which side to take and tells that side to the game owner.
Definition: game.cpp:358
void set_termination_reason(const std::string &reason)
Definition: game.cpp:1855
game(wesnothd::server &server, player_connections &player_connections, player_iterator host, const std::string &name="", bool save_replays=false, const std::string &replay_save_path="")
Definition: game.cpp:78
void send_data(simple_wml::document &data, std::optional< player_iterator > exclude={}, std::string packet_type="")
Definition: game.cpp:1642
simple_wml::document & level()
The full scenario data.
Definition: game.hpp:277
simple_wml::node * description() const
Definition: game.hpp:288
bool save_replays()
Definition: game.cpp:770
int id() const
Definition: game.hpp:53