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