The Battle for Wesnoth  1.17.0-dev
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
wesnothd::game Class Reference

#include <game.hpp>

Public Member Functions

 MAKE_ENUM (CONTROLLER,(HUMAN, "human")(AI, "ai")(EMPTY, "null"))
 
 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="")
 
 ~game ()
 
int id () const
 This ID is reused between scenarios of MP campaigns. More...
 
int db_id () const
 This ID is not reused between scenarios of MP campaigns. More...
 
void next_db_id ()
 Increments the ID used when running database queries. More...
 
const std::string & name () const
 
bool is_owner (player_iterator player) const
 
bool is_member (player_iterator player) const
 
bool allow_observers () const
 
bool is_observer (player_iterator player) const
 
bool is_player (player_iterator player) const
 
bool player_is_banned (player_iterator player, const std::string &name) const
 
void new_scenario (player_iterator sender)
 When the host sends the new scenario of a mp campaign. More...
 
bool level_init () const
 
const simple_wml::node::child_listget_sides_list () const
 
bool started () const
 
std::size_t nplayers () const
 
std::size_t nobservers () const
 
std::size_t current_turn () const
 
std::string get_replay_filename ()
 
void mute_all_observers ()
 Toggles whether all observers are muted or not. More...
 
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. More...
 
void unmute_observer (const simple_wml::node &unmute, player_iterator unmuter)
 Unmute an observer or unmute all currently muted observers if no name is given. More...
 
std::optional< player_iteratorkick_member (const simple_wml::node &kick, player_iterator kicker)
 Kick a user from this game by name. More...
 
std::optional< player_iteratorban_user (const simple_wml::node &ban, player_iterator banner)
 Ban a user by name. More...
 
void unban_user (const simple_wml::node &unban, player_iterator unbanner)
 Unban a user by name. More...
 
bool add_player (player_iterator player, bool observer=false)
 Add a user to the game. More...
 
bool remove_player (player_iterator player, const bool disconnect=false, const bool destruct=false)
 Removes a user from the game. More...
 
const user_vector all_game_users () const
 
void start_game (player_iterator starter)
 Starts the game (if a new game) or starts the next scenario of an MP campaign. More...
 
void perform_controller_tweaks ()
 This is performed just before starting and before the [start_game] signal. More...
 
void load_next_scenario (player_iterator user)
 A user asks for the next scenario to advance to. More...
 
void update_side_data ()
 Resets the side configuration according to the scenario data. More...
 
void transfer_side_control (player_iterator player, const simple_wml::node &cfg)
 Lets a player owning a side give it to another player or observer. More...
 
void process_message (simple_wml::document &data, player_iterator user)
 Sends an ingame message to all other players. More...
 
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. More...
 
void process_whiteboard (simple_wml::document &data, player_iterator user)
 Handles incoming [whiteboard] data. More...
 
void process_change_turns_wml (simple_wml::document &data, player_iterator user)
 Handles incoming [change_turns_wml] data. More...
 
bool describe_slots ()
 Set the description to the number of available slots. More...
 
void send_server_message_to_all (const char *message, std::optional< player_iterator > exclude={})
 Sends a message to all players in this game that aren't excluded. More...
 
void send_server_message_to_all (const std::string &message, std::optional< player_iterator > exclude={})
 send_server_message_to_all More...
 
void send_server_message (const char *message, std::optional< player_iterator > player={}, simple_wml::document *doc=nullptr) const
 Send a server message to the specified player. More...
 
void send_server_message (const std::string &message, std::optional< player_iterator > player={}, simple_wml::document *doc=nullptr) const
 send_server_message More...
 
void send_and_record_server_message (const char *message, std::optional< player_iterator > exclude={})
 Send data to all players in this game except 'exclude'. More...
 
void send_and_record_server_message (const std::string &message, std::optional< player_iterator > exclude={})
 send_and_record_server_message More...
 
template<typename Container >
void send_to_players (simple_wml::document &data, const Container &players, std::optional< player_iterator > exclude={})
 Send data to all players except those excluded. More...
 
void send_data (simple_wml::document &data, std::optional< player_iterator > exclude={})
 Send data to all players and observers except those excluded. More...
 
void clear_history ()
 Clears the history of recorded WML documents. More...
 
void record_data (std::unique_ptr< simple_wml::document > data)
 Records a WML document in the game's history. More...
 
void save_replay ()
 Move the level information and recorded history into a replay file and save it. More...
 
simple_wml::documentlevel ()
 
void set_description (simple_wml::node *desc)
 Set the game's description. More...
 
simple_wml::nodedescription () const
 
void set_password (const std::string &passwd)
 Sets the password required to access the game. More...
 
void set_name_bans (const std::vector< std::string > name_bans)
 Set a list of usernames that should all be banned from joining the game. More...
 
bool password_matches (const std::string &passwd) const
 
bool has_password () const
 
const std::string & termination_reason () const
 Provides the reason the game was ended. More...
 
void set_termination_reason (const std::string &reason)
 Sets the termination reason for this game. More...
 
void handle_choice (const simple_wml::node &data, player_iterator user)
 Handle a choice requested by a client, such as changing a side's controller, if initiated by WML/lua. More...
 
void handle_random_choice ()
 Send a randomly generated number to the requestor. More...
 
void handle_controller_choice (const simple_wml::node &data)
 Handle a request to change a side's controller. More...
 
void handle_add_side_wml ()
 Adds a new, empty side owned by no one. More...
 
void reset_last_synced_context_id ()
 Reset the internal counter for choice requests made by clients to the server. More...
 
bool controls_side (const std::vector< int > &sides, player_iterator player) const
 Function which returns true if 'player' controls any of the sides specified in 'sides'. More...
 
bool is_reload () const
 

Static Public Member Functions

static simple_wml::nodestarting_pos (simple_wml::node &data)
 The non-const version. More...
 
static const simple_wml::nodestarting_pos (const simple_wml::node &data)
 The const version. More...
 

Private Member Functions

 game (const game &)=delete
 
gameoperator= (const game &)=delete
 
std::size_t current_side () const
 
std::optional< player_iteratorcurrent_player () const
 
bool is_current_player (player_iterator player) const
 
bool is_muted_observer (player_iterator player) const
 
bool all_observers_muted () const
 
void send_muted_observers (player_iterator user) const
 Sends a message either stating that all observers are muted or listing the observers that are muted. More...
 
bool send_taken_side (simple_wml::document &cfg, const simple_wml::node *side) const
 Tell the host who owns a side. More...
 
bool take_side (player_iterator user)
 Figures out which side to take and tells that side to the game owner. More...
 
void change_controller (const std::size_t side_index, player_iterator player, const std::string &player_name, const bool player_left=true)
 Send [change_controller] message to tell all clients the new controller's name or controller type (human or ai). More...
 
std::unique_ptr< simple_wml::documentchange_controller_type (const std::size_t side_index, player_iterator player, const std::string &player_name)
 Tell everyone else but the source player that the controller type changed. More...
 
void send_leave_game (player_iterator user) const
 Tells a player to leave the game. More...
 
void send_data_sides (simple_wml::document &data, const simple_wml::string_span &sides, std::optional< player_iterator > exclude={})
 Sends a document to the provided list of sides. More...
 
void send_observerjoins (std::optional< player_iterator > player={})
 Send a document per observer in the game. More...
 
void send_observerquit (player_iterator observer)
 
void send_history (player_iterator sock) const
 
void notify_new_host ()
 In case of a host transfer, notify the new host about its status. More...
 
std::optional< player_iteratorfind_user (const simple_wml::string_span &name)
 Shortcut to a convenience function for finding a user by name. More...
 
bool is_legal_command (const simple_wml::node &command, player_iterator user)
 
std::string has_same_ip (player_iterator user) const
 Checks whether a user has the same IP as any other members of this game. More...
 
bool end_turn (int new_side)
 Function which should be called every time a player ends their turn (i.e. More...
 
void update_turn_data ()
 Set or update the current and max turn values in the game's description. More...
 
void send_user_list (std::optional< player_iterator > exclude={})
 Function to send a list of users to all clients. More...
 
std::string username (player_iterator pl) const
 
std::string list_users (user_vector users) const
 
void reset_sides ()
 calculates the initial value for sides_, side_controllerds_, nsides_ More...
 
std::string debug_player_info () const
 Helps debugging player and observer lists. More...
 
std::string debug_sides_info () const
 Helps debugging controller tweaks. More...
 

Private Attributes

wesnothd::serverserver
 The wesnothd server instance this game exists on. More...
 
player_connectionsplayer_connections_
 
int id_
 This game's ID within wesnothd. More...
 
int db_id_
 Used for unique identification of games played in the database. More...
 
std::string name_
 The name of the game. More...
 
std::string password_
 The password needed to join the game. More...
 
player_iterator owner_
 The game host or later owner (if the host left). More...
 
user_vector players_
 A vector of players (members owning a side). More...
 
user_vector observers_
 A vector of observers (members not owning a side). More...
 
user_vector muted_observers_
 A vector of muted observers. More...
 
side_vector sides_
 A vector of side owners. More...
 
std::vector< CONTROLLER > side_controllers_
 A vector containiner the controller type for each side. More...
 
int nsides_
 Number of sides in the current scenario. More...
 
bool started_
 Whether the game has been started or not. More...
 
simple_wml::document level_
 The current scenario data. More...
 
std::vector< std::unique_ptr< simple_wml::document > > history_
 Replay data. More...
 
simple_wml::nodedescription_
 Pointer to the game's description in the games_and_users_list_. More...
 
int current_turn_
 The game's current turn. More...
 
int current_side_index_
 The index of the current side. More...
 
int num_turns_
 The maximum number of turns before the game ends. More...
 
bool all_observers_muted_
 Whether all observers should be treated as muted. More...
 
std::vector< std::string > bans_
 List of banned IPs. More...
 
std::vector< std::string > name_bans_
 List of banned usernames. More...
 
std::set< const player_record * > players_not_advanced_
 in multiplayer campaigns it can happen that some players are still in the previous scenario keep track of those players because processing certain input from those side wil lead to error (oos) More...
 
std::string termination_
 The reason the game ended. More...
 
bool save_replays_
 Whether to save a replay of this game. More...
 
std::string replay_save_path_
 Where to save the replay of this game. More...
 
randomness::mt_rng rng_
 A wrapper for mersenne twister rng which generates randomness for this game. More...
 
int last_choice_request_id_
 The ID of the last request received from a client. More...
 

Static Private Attributes

static int id_num = 1
 Incremented to retrieve a unique ID for game instances within wesnothd. More...
 
static int db_id_num = 1
 Incremented to retrieve a unique ID per wesnothd instance for game instances within the database. More...
 

Detailed Description

Definition at line 36 of file game.hpp.

Constructor & Destructor Documentation

◆ game() [1/2]

wesnothd::game::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 at line 78 of file game.cpp.

References id_, name_, owner_, players_, and wesnothd::player::PLAYING.

Referenced by reset_last_synced_context_id().

◆ ~game()

wesnothd::game::~game ( )

Definition at line 120 of file game.cpp.

References all_game_users(), clear_history(), remove_player(), and save_replay().

◆ game() [2/2]

wesnothd::game::game ( const game )
privatedelete

Member Function Documentation

◆ add_player()

bool wesnothd::game::add_player ( player_iterator  player,
bool  observer = false 
)

Add a user to the game.

Todo:
differentiate between "observers not allowed" and "player already in the game" errors. maybe return a string with an error message.
Parameters
playerThe player to add.
observerWhether to add the player as an observer.
Returns
True if the user successfully joined the game, false otherwise.

Definition at line 1333 of file game.cpp.

References simple_wml::node::add_child(), allow_observers(), db_id_, DBG_GAME, debug_player_info(), ERR_GAME, has_same_ip(), id_, simple_wml::INIT_COMPRESSED, is_member(), level_, LOG_GAME, name_, observers_, wesnothd::player::OBSERVING, players_, wesnothd::player::PLAYING, simple_wml::document::root(), send_and_record_server_message(), send_data(), send_history(), send_observerjoins(), send_server_message(), wesnothd::server::send_to_player(), send_user_list(), simple_wml::node::set_attr_dup(), started_, and take_side().

Referenced by current_turn().

◆ all_game_users()

const user_vector wesnothd::game::all_game_users ( ) const
Returns
A vector containing all players and observers currently in this game.

Definition at line 1850 of file game.cpp.

References observers_, and players_.

Referenced by current_turn(), has_same_ip(), new_scenario(), send_data(), send_user_list(), update_side_data(), and ~game().

◆ all_observers_muted()

bool wesnothd::game::all_observers_muted ( ) const
inlineprivate

◆ allow_observers()

bool wesnothd::game::allow_observers ( ) const
Returns
Whether observers are allowed to join.

Definition at line 145 of file game.cpp.

References wesnothd::get_multiplayer(), level_, and simple_wml::document::root().

Referenced by add_player(), and is_member().

◆ ban_user()

std::optional< player_iterator > wesnothd::game::ban_user ( const simple_wml::node ban,
player_iterator  banner 
)

Ban a user by name.

The user does not need to be in this game but logged in.

Parameters
banThe user to ban.
bannerThe player doing the banning.
Returns
The iterator to the banned player if he was in this game, empty optional otherwise.

Definition at line 797 of file game.cpp.

References bans_, db_id_, find_user(), id_, is_member(), LOG_GAME, name_, name_bans_, owner_, player_is_banned(), remove_player(), send_and_record_server_message(), send_leave_game(), send_server_message(), simple_wml::string_span::to_string(), and username().

Referenced by current_turn(), and wesnothd::server::handle_player_in_game().

◆ change_controller()

void wesnothd::game::change_controller ( const std::size_t  side_index,
player_iterator  player,
const std::string &  player_name,
const bool  player_left = true 
)
private

Send [change_controller] message to tell all clients the new controller's name or controller type (human or ai).

Parameters
side_indexThe index of the side whose controller is changing.
playerThe player who is taking control of the side.
player_nameThe name of the player who is taking control of the side.
player_leftWe use the "player_left" field as follows. Normally change_controller sends one message to the owner, and one message to everyone else. In case that a player drops, the owner is gone and should not get a message, instead the host gets a [side_drop] message.

Definition at line 566 of file game.cpp.

References change_controller_type(), DBG_GAME, record_data(), send_and_record_server_message(), wesnothd::server::send_to_player(), side_controllers_, sides_, and started_.

Referenced by all_observers_muted(), perform_controller_tweaks(), remove_player(), and transfer_side_control().

◆ change_controller_type()

std::unique_ptr< simple_wml::document > wesnothd::game::change_controller_type ( const std::size_t  side_index,
player_iterator  player,
const std::string &  player_name 
)
private

Tell everyone else but the source player that the controller type changed.

Parameters
side_indexThe index of the side whose controller type is changing.
playerThe player who owns the side whose controller type is changing.
player_nameThe name of the player who owns the side whose controller type is changing.
Returns
The document that was sent to all other players.

Definition at line 598 of file game.cpp.

References simple_wml::node::add_child(), simple_wml::document::clone(), simple_wml::document::root(), send_data(), simple_wml::node::set_attr(), simple_wml::node::set_attr_dup(), and side_controllers_.

Referenced by all_observers_muted(), change_controller(), and transfer_side_control().

◆ clear_history()

void wesnothd::game::clear_history ( )

Clears the history of recorded WML documents.

Definition at line 1823 of file game.cpp.

References history_.

Referenced by send_and_record_server_message(), start_game(), and ~game().

◆ controls_side()

bool wesnothd::game::controls_side ( const std::vector< int > &  sides,
player_iterator  player 
) const

Function which returns true if 'player' controls any of the sides specified in 'sides'.

Parameters
sidesThe list of sides in this game.
playerThe player being checked for whether they own any sides.

Definition at line 1644 of file game.cpp.

References sides_.

Referenced by reset_last_synced_context_id(), and send_data_sides().

◆ current_player()

std::optional<player_iterator> wesnothd::game::current_player ( ) const
inlineprivate
Returns
The player who owns the current side.

Definition at line 607 of file game.hpp.

References current_side(), and sides_.

Referenced by handle_controller_choice(), is_current_player(), and process_turn().

◆ current_side()

std::size_t wesnothd::game::current_side ( ) const
inlineprivate
Returns
0 if there are no sides, or the current side index otherwise.

Definition at line 599 of file game.hpp.

References current_side_index_, and nsides_.

Referenced by current_player(), end_turn(), and process_turn().

◆ current_turn()

std::size_t wesnothd::game::current_turn ( ) const
inline

◆ db_id()

int wesnothd::game::db_id ( ) const
inline

This ID is not reused between scenarios of MP campaigns.

This ID resets when wesnothd is restarted. This is generally used during database queries.

Returns
an ID that uniquely identifies the game within the currently running wesnothd instance.

Definition at line 71 of file game.hpp.

References db_id_.

Referenced by wesnothd::server::cleanup_game(), and wesnothd::server::handle_player_in_game().

◆ debug_player_info()

std::string wesnothd::game::debug_player_info ( ) const
private

Helps debugging player and observer lists.

Returns
A string listing the game IDs, players, and observers.

Definition at line 1860 of file game.cpp.

References db_id_, id_, observers_, and players_.

Referenced by add_player(), all_observers_muted(), remove_player(), and update_side_data().

◆ debug_sides_info()

std::string wesnothd::game::debug_sides_info ( ) const
private

Helps debugging controller tweaks.

Returns
A string listing the game IDs and side information.

Definition at line 1876 of file game.cpp.

References db_id_, get_sides_list(), id_, s, and side_controllers_.

Referenced by all_observers_muted(), load_next_scenario(), perform_controller_tweaks(), and start_game().

◆ describe_slots()

bool wesnothd::game::describe_slots ( )

Set the description to the number of available slots.

Returns
True if the number of slots has changed.

Definition at line 625 of file game.cpp.

References simple_wml::node::add_child(), simple_wml::node::child(), description_, get_sides_list(), i, simple_wml::node::set_attr_int(), sides_, and started_.

Referenced by current_turn(), and wesnothd::server::handle_player_in_game().

◆ description()

simple_wml::node* wesnothd::game::description ( ) const
inline
Returns
The node containing the game's current description.

Definition at line 482 of file game.hpp.

References description_.

Referenced by wesnothd::server::cleanup_game(), wesnothd::server::handle_player_in_game(), and wesnothd::server::update_game_in_lobby().

◆ end_turn()

bool wesnothd::game::end_turn ( int  new_side)
private

Function which should be called every time a player ends their turn (i.e.

[end_turn] received). This will update the 'turn' attribute for the game's description when appropriate.

Parameters
new_sideThe side number whose turn to move it has become.
Returns
True if the current side and-or current turn values have been updated, false otherwise.

Definition at line 1286 of file game.cpp.

References current_side(), current_side_index_, current_turn_, description_, i, nsides_, side_controllers_, and update_turn_data().

Referenced by all_observers_muted(), and process_turn().

◆ find_user()

std::optional< player_iterator > wesnothd::game::find_user ( const simple_wml::string_span name)
private

Shortcut to a convenience function for finding a user by name.

Parameters
nameThe name of the user to find.
Returns
The player if found, else empty.

Definition at line 1895 of file game.cpp.

References player_connections_, and simple_wml::string_span::to_string().

Referenced by all_observers_muted(), ban_user(), kick_member(), mute_observer(), transfer_side_control(), unban_user(), and unmute_observer().

◆ get_replay_filename()

std::string wesnothd::game::get_replay_filename ( )

◆ get_sides_list()

const simple_wml::node::child_list& wesnothd::game::get_sides_list ( ) const
inline

◆ handle_add_side_wml()

void wesnothd::game::handle_add_side_wml ( )

Adds a new, empty side owned by no one.

Definition at line 1115 of file game.cpp.

References nsides_, side_controllers_, and sides_.

Referenced by handle_choice(), and termination_reason().

◆ handle_choice()

void wesnothd::game::handle_choice ( const simple_wml::node data,
player_iterator  user 
)

Handle a choice requested by a client, such as changing a side's controller, if initiated by WML/lua.

Parameters
dataThe data needed to process the choice.
userThe player making the request.

Definition at line 1186 of file game.cpp.

References simple_wml::node::child(), DBG_GAME, handle_add_side_wml(), handle_controller_choice(), handle_random_choice(), is_player(), last_choice_request_id_, owner_, players_not_advanced_, send_and_record_server_message(), and started_.

Referenced by wesnothd::server::handle_player_in_game(), and termination_reason().

◆ handle_controller_choice()

void wesnothd::game::handle_controller_choice ( const simple_wml::node data)

Handle a request to change a side's controller.

Note that this does not change who owns a side.

Parameters
dataContains the information about which side to change the controller of.

Definition at line 1122 of file game.cpp.

References simple_wml::node::add_child(), current_player(), record_data(), send_and_record_server_message(), send_data(), wesnothd::server::send_to_player(), simple_wml::node::set_attr(), simple_wml::node::set_attr_dup(), side_controllers_, and sides_.

Referenced by handle_choice(), and termination_reason().

◆ handle_random_choice()

void wesnothd::game::handle_random_choice ( )

◆ has_password()

bool wesnothd::game::has_password ( ) const
inline
Returns
Whether the game has a password set.

Definition at line 519 of file game.hpp.

References password_.

Referenced by wesnothd::server::handle_player_in_game().

◆ has_same_ip()

std::string wesnothd::game::has_same_ip ( player_iterator  user) const
private

Checks whether a user has the same IP as any other members of this game.

Returns
A comma separated string of members with matching IPs.

Definition at line 1657 of file game.cpp.

References all_game_users().

Referenced by add_player(), and all_observers_muted().

◆ id()

int wesnothd::game::id ( ) const
inline

This ID is reused between scenarios of MP campaigns.

This ID resets when wesnothd is restarted. This is generally used when needing to find a particular running game.

Returns
an ID that uniquely identifies the game within the currently running wesnothd instance.

Definition at line 59 of file game.hpp.

References id_.

Referenced by wesnothd::server::cleanup_game(), and wesnothd::server::handle_player_in_game().

◆ is_current_player()

bool wesnothd::game::is_current_player ( player_iterator  player) const
inlineprivate
Parameters
playerThe player being checked.
Returns
Whether the player being checked is the current player taking their turn.

Definition at line 616 of file game.hpp.

References current_player(), and is_muted_observer().

Referenced by is_legal_command(), and process_turn().

◆ is_legal_command()

bool wesnothd::game::is_legal_command ( const simple_wml::node command,
player_iterator  user 
)
private

◆ is_member()

bool wesnothd::game::is_member ( player_iterator  player) const
inline
Parameters
playerThe player being checked.
Returns
Whether the provided player has joined the game.

Definition at line 105 of file game.hpp.

References allow_observers(), is_observer(), is_player(), name(), new_scenario(), and player_is_banned().

Referenced by add_player(), ban_user(), kick_member(), remove_player(), and transfer_side_control().

◆ is_muted_observer()

bool wesnothd::game::is_muted_observer ( player_iterator  player) const
private
Parameters
playerThe observer being checked.
Returns
True if the observer is muted or if all observers are muted, false otherwise.

Definition at line 155 of file game.cpp.

References all_observers_muted_, is_observer(), and muted_observers_.

Referenced by is_current_player(), mute_observer(), process_turn(), and unmute_observer().

◆ is_observer()

bool wesnothd::game::is_observer ( player_iterator  player) const
Parameters
playerThe player being checked.
Returns
Whether the provided player is an observer of this game.

Definition at line 150 of file game.cpp.

References observers_.

Referenced by is_member(), is_muted_observer(), mute_observer(), remove_player(), send_user_list(), transfer_side_control(), and unmute_observer().

◆ is_owner()

bool wesnothd::game::is_owner ( player_iterator  player) const
inline
Parameters
playerThe player being checked.
Returns
Whether the provided player is the game's owner(host).

Definition at line 96 of file game.hpp.

References owner_.

Referenced by wesnothd::server::handle_player_in_game(), and send_user_list().

◆ is_player()

bool wesnothd::game::is_player ( player_iterator  player) const
Parameters
playerThe player being checked.
Returns
Whether the provided player is playing this game (aka owns one or more sides).

Definition at line 168 of file game.cpp.

References players_.

Referenced by handle_choice(), wesnothd::server::handle_player_in_game(), is_legal_command(), is_member(), process_change_turns_wml(), process_turn(), process_whiteboard(), remove_player(), and transfer_side_control().

◆ is_reload()

bool wesnothd::game::is_reload ( ) const
Returns
Whether the loaded WML has the attribute indicating that this is a reloaded savegame rather than a brand new game.

Definition at line 1952 of file game.cpp.

References wesnothd::get_multiplayer(), simple_wml::node::has_attr(), level_, and simple_wml::document::root().

Referenced by wesnothd::server::handle_player_in_game(), and reset_last_synced_context_id().

◆ kick_member()

std::optional< player_iterator > wesnothd::game::kick_member ( const simple_wml::node kick,
player_iterator  kicker 
)

Kick a user from this game by name.

Parameters
kickThe user to kick.
kickerThe player doing the kicking.
Returns
The iterator to the removed member if successful, empty optional otherwise.

Definition at line 765 of file game.cpp.

References db_id_, find_user(), id_, is_member(), LOG_GAME, name_, owner_, remove_player(), send_and_record_server_message(), send_leave_game(), send_server_message(), simple_wml::string_span::to_string(), and username().

Referenced by current_turn(), and wesnothd::server::handle_player_in_game().

◆ level()

simple_wml::document& wesnothd::game::level ( )
inline
Returns
The full scenario data.

Definition at line 466 of file game.hpp.

References level_, and set_description().

Referenced by wesnothd::server::handle_create_game(), and wesnothd::server::handle_player_in_game().

◆ level_init()

bool wesnothd::game::level_init ( ) const
inline
Returns
Whether this game contains scenario data and thus has been initialized.

Definition at line 144 of file game.hpp.

References simple_wml::document::child(), and level_.

Referenced by wesnothd::server::handle_player_in_game().

◆ list_users()

std::string wesnothd::game::list_users ( user_vector  users) const
private
Parameters
usersThe users to create a comma separated list from.
Returns
A comma separated list of user names.

Definition at line 178 of file game.cpp.

Referenced by all_observers_muted(), send_muted_observers(), and start_game().

◆ load_next_scenario()

void wesnothd::game::load_next_scenario ( player_iterator  user)

◆ MAKE_ENUM()

wesnothd::game::MAKE_ENUM ( CONTROLLER  ,
(HUMAN, "human")(AI, "ai")(EMPTY, "null")   
)

◆ mute_all_observers()

void wesnothd::game::mute_all_observers ( )

Toggles whether all observers are muted or not.

Definition at line 664 of file game.cpp.

References all_observers_muted_, and send_and_record_server_message().

Referenced by current_turn(), and wesnothd::server::handle_player_in_game().

◆ mute_observer()

void wesnothd::game::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.

Parameters
muteThe observer to mute. Empty if sending a message to muted observers.
muterThe player doing the muting.

Definition at line 686 of file game.cpp.

References db_id_, simple_wml::string_span::empty(), find_user(), id_, is_muted_observer(), is_observer(), LOG_GAME, muted_observers_, name_, owner_, send_and_record_server_message(), send_muted_observers(), send_server_message(), simple_wml::string_span::to_string(), and username().

Referenced by current_turn(), and wesnothd::server::handle_player_in_game().

◆ name()

const std::string& wesnothd::game::name ( ) const
inline
Returns
The game's name.

Definition at line 87 of file game.hpp.

References name_.

Referenced by get_replay_filename(), wesnothd::server::handle_player_in_game(), is_member(), and player_is_banned().

◆ new_scenario()

void wesnothd::game::new_scenario ( player_iterator  sender)

When the host sends the new scenario of a mp campaign.

Parameters
senderThe player sending the scenario data.

Definition at line 1549 of file game.cpp.

References all_game_users(), owner_, players_not_advanced_, and started_.

Referenced by wesnothd::server::handle_player_in_game(), and is_member().

◆ next_db_id()

void wesnothd::game::next_db_id ( )
inline

Increments the ID used when running database queries.

Definition at line 79 of file game.hpp.

References db_id_, and db_id_num.

Referenced by wesnothd::server::handle_player_in_game().

◆ nobservers()

std::size_t wesnothd::game::nobservers ( ) const
inline
Returns
The number of observers in this game.

Definition at line 210 of file game.hpp.

References observers_.

◆ notify_new_host()

void wesnothd::game::notify_new_host ( )
private

In case of a host transfer, notify the new host about its status.

Definition at line 614 of file game.cpp.

References simple_wml::node::add_child(), owner_, simple_wml::document::root(), send_and_record_server_message(), wesnothd::server::send_to_player(), and username().

Referenced by all_observers_muted(), and remove_player().

◆ nplayers()

std::size_t wesnothd::game::nplayers ( ) const
inline
Returns
The number of players. One player can have multiple sides.

Definition at line 202 of file game.hpp.

References players_.

◆ operator=()

game& wesnothd::game::operator= ( const game )
privatedelete

◆ password_matches()

bool wesnothd::game::password_matches ( const std::string &  passwd) const
inline
Parameters
passwdThe password to join with.
Returns
True if the game's password is empty or if the provided password matches, false otherwise.

Definition at line 511 of file game.hpp.

References password_.

◆ perform_controller_tweaks()

void wesnothd::game::perform_controller_tweaks ( )

This is performed just before starting and before the [start_game] signal.

Sends [scenario_diff]s specific to each client so that they locally control their human sides.

Definition at line 193 of file game.cpp.

References change_controller(), db_id_, DBG_GAME, debug_sides_info(), get_sides_list(), id_, LOG_GAME, wfl::msg(), owner_, send_and_record_server_message(), simple_wml::node::set_attr(), sides_, update_side_data(), and username().

Referenced by current_turn(), and wesnothd::server::handle_player_in_game().

◆ player_is_banned()

bool wesnothd::game::player_is_banned ( player_iterator  player,
const std::string &  name 
) const
Parameters
playerThe player being checked (by iterator).
nameThe player being checked (by username).
Returns
Whether the connection's ip address or username is banned from this game.

Definition at line 656 of file game.cpp.

References bans_, name(), and name_bans_.

Referenced by ban_user(), is_member(), and unban_user().

◆ process_change_turns_wml()

void wesnothd::game::process_change_turns_wml ( simple_wml::document data,
player_iterator  user 
)

Handles incoming [change_turns_wml] data.

Parameters
dataThe [change_turns_wml] data.
userThe player changing turns.

Definition at line 1257 of file game.cpp.

References simple_wml::node::add_child(), simple_wml::node::child(), simple_wml::document::child(), simple_wml::node::copy_into(), current_turn(), current_turn_, description_, is_player(), num_turns_, and started_.

Referenced by current_turn(), and wesnothd::server::handle_player_in_game().

◆ process_message()

void wesnothd::game::process_message ( simple_wml::document data,
player_iterator  user 
)

Sends an ingame message to all other players.

Parameters
dataThe message to send.
userThe user sending the message.

Definition at line 869 of file game.cpp.

References simple_wml::node::child(), wfl::msg(), simple_wml::document::root(), send_data(), simple_wml::node::set_attr_dup(), and wesnothd::chat_message::truncate_message().

Referenced by current_turn(), and wesnothd::server::handle_player_in_game().

◆ process_turn()

bool wesnothd::game::process_turn ( simple_wml::document data,
player_iterator  user 
)

Handles [end_turn], repackages [commands] with private [speak]s in them and sends the data.

Also filters commands from all but the current player. Currently removes all commands but [speak] for observers and all but [speak], [label], and [rename] for players.

Parameters
dataThe turn commands.
userThe user who sent a command to be processed during the turn. This may not be the player whose turn it currently is.
Returns
True if the turn ended.

Definition at line 946 of file game.cpp.

References simple_wml::node::add_child(), simple_wml::node::child(), simple_wml::node::children(), simple_wml::document::clone(), simple_wml::node::copy_into(), current_player(), current_side(), current_side_index_, current_turn_, db_id_, DBG_GAME, simple_wml::string_span::empty(), end_turn(), id_, utf8::index(), is_current_player(), is_legal_command(), is_muted_observer(), is_player(), LOG_GAME, wfl::msg(), simple_wml::node::no_children(), simple_wml::node_to_string(), nsides_, game_config::observer_team_name, observers_, owner_, record_data(), simple_wml::node::remove_child(), simple_wml::document::root(), s, send_and_record_server_message(), send_data(), send_data_sides(), send_server_message(), send_to_players(), simple_wml::node::set_attr(), simple_wml::node::set_attr_dup(), sides_, started_, transfer_side_control(), wesnothd::chat_message::truncate_message(), and username().

Referenced by current_turn(), and wesnothd::server::handle_player_in_game().

◆ process_whiteboard()

void wesnothd::game::process_whiteboard ( simple_wml::document data,
player_iterator  user 
)

Handles incoming [whiteboard] data.

Parameters
dataThe whiteboard data.
userThe user sending the whiteboard data.

Definition at line 1230 of file game.cpp.

References simple_wml::document::child(), is_player(), LOG_GAME, wfl::msg(), send_and_record_server_message(), send_data_sides(), sides_, and started_.

Referenced by current_turn(), and wesnothd::server::handle_player_in_game().

◆ record_data()

void wesnothd::game::record_data ( std::unique_ptr< simple_wml::document data)

Records a WML document in the game's history.

Parameters
dataThe WML document to record.

Definition at line 1817 of file game.cpp.

References simple_wml::document::compress(), and history_.

Referenced by change_controller(), handle_controller_choice(), handle_random_choice(), process_turn(), and send_and_record_server_message().

◆ remove_player()

bool wesnothd::game::remove_player ( player_iterator  player,
const bool  disconnect = false,
const bool  destruct = false 
)

Removes a user from the game.

Parameters
playerThe player to remove.
disconnectIf the player disconnected from the server entirely.
destructIf the game is ending as well.
Returns
True if the player's removal ends the game. That is, if there are no more players or the host left on a not yet started game.

Definition at line 1416 of file game.cpp.

References simple_wml::node::add_child(), change_controller(), current_turn(), db_id_, DBG_GAME, debug_player_info(), ERR_GAME, id_, is_member(), is_observer(), is_player(), LOG_GAME, name_, notify_new_host(), game_config::images::observer, observers_, owner_, player_connections_, players_, players_not_advanced_, wesnothd::player::PLAYING, gui2::dialogs::tip::remove(), simple_wml::document::root(), send_and_record_server_message(), send_observerquit(), send_server_message_to_all(), wesnothd::server::send_to_player(), send_user_list(), simple_wml::node::set_attr_dup(), side_controllers_, sides_, started_, termination_reason(), and username().

Referenced by ban_user(), current_turn(), wesnothd::server::handle_player_in_game(), kick_member(), and ~game().

◆ reset_last_synced_context_id()

void wesnothd::game::reset_last_synced_context_id ( )
inline

Reset the internal counter for choice requests made by clients to the server.

Definition at line 573 of file game.hpp.

References controls_side(), game(), is_reload(), last_choice_request_id_, and operator=().

Referenced by wesnothd::server::handle_player_in_game().

◆ reset_sides()

void wesnothd::game::reset_sides ( )
private

calculates the initial value for sides_, side_controllerds_, nsides_

Definition at line 387 of file game.cpp.

References get_sides_list(), nsides_, side_controllers_, and sides_.

Referenced by all_observers_muted(), and update_side_data().

◆ save_replay()

void wesnothd::game::save_replay ( )

◆ send_and_record_server_message() [1/2]

void wesnothd::game::send_and_record_server_message ( const char *  message,
std::optional< player_iterator exclude = {} 
)

◆ send_and_record_server_message() [2/2]

void wesnothd::game::send_and_record_server_message ( const std::string &  message,
std::optional< player_iterator exclude = {} 
)
inline

◆ send_data()

void wesnothd::game::send_data ( simple_wml::document data,
std::optional< player_iterator exclude = {} 
)

Send data to all players and observers except those excluded.

Parameters
dataThe data to send.
excludeThe players/observers to not send the data to.

Definition at line 1623 of file game.cpp.

References all_game_users(), and send_to_players().

Referenced by add_player(), change_controller_type(), handle_controller_choice(), wesnothd::server::handle_player_in_game(), handle_random_choice(), process_message(), process_turn(), send_and_record_server_message(), send_observerjoins(), send_observerquit(), send_server_message_to_all(), send_user_list(), and transfer_side_control().

◆ send_data_sides()

void wesnothd::game::send_data_sides ( simple_wml::document data,
const simple_wml::string_span sides,
std::optional< player_iterator exclude = {} 
)
private

Sends a document to the provided list of sides.

Parameters
dataThe data to be sent to the provided sides.
sidesA comma sperated list of side numbers to which the document should be sent.
excludePlayers to not send the data to.

Definition at line 1628 of file game.cpp.

References controls_side(), DBG_GAME, players_, and send_to_players().

Referenced by all_observers_muted(), process_turn(), and process_whiteboard().

◆ send_history()

void wesnothd::game::send_history ( player_iterator  sock) const
private

◆ send_leave_game()

void wesnothd::game::send_leave_game ( player_iterator  user) const
private

Tells a player to leave the game.

Parameters
userThe player leaving the game.

Definition at line 759 of file game.cpp.

References simple_wml::INIT_COMPRESSED, and wesnothd::server::send_to_player().

Referenced by all_observers_muted(), ban_user(), and kick_member().

◆ send_muted_observers()

void wesnothd::game::send_muted_observers ( player_iterator  user) const
private

Sends a message either stating that all observers are muted or listing the observers that are muted.

Parameters
userThe player to send the message to.

Definition at line 674 of file game.cpp.

References all_observers_muted_, list_users(), muted_observers_, and send_server_message().

Referenced by all_observers_muted(), and mute_observer().

◆ send_observerjoins()

void wesnothd::game::send_observerjoins ( std::optional< player_iterator player = {})
private

Send a document per observer in the game.

If player is blank, send these documents to everyone, else send them to just the observer who joined.

Parameters
playerThe observer who joined.

Definition at line 1672 of file game.cpp.

References simple_wml::node::add_child(), observers_, simple_wml::document::root(), send_data(), wesnothd::server::send_to_player(), and simple_wml::node::set_attr_dup().

Referenced by add_player(), all_observers_muted(), load_next_scenario(), and start_game().

◆ send_observerquit()

void wesnothd::game::send_observerquit ( player_iterator  observer)
private

◆ send_server_message() [1/2]

void wesnothd::game::send_server_message ( const char *  message,
std::optional< player_iterator player = {},
simple_wml::document doc = nullptr 
) const

Send a server message to the specified player.

Parameters
messageThe message to send.
playerThe player to send the message to. If empty then the message is not sent.
docThe document to create the message in. If nullptr then a new document is created.

Definition at line 1923 of file game.cpp.

References simple_wml::node::add_child(), wfl::msg(), simple_wml::document::root(), wesnothd::server::send_to_player(), simple_wml::node::set_attr(), simple_wml::node::set_attr_dup(), and started_.

Referenced by add_player(), ban_user(), wesnothd::server::handle_player_in_game(), kick_member(), mute_observer(), process_turn(), send_and_record_server_message(), send_muted_observers(), send_server_message(), send_server_message_to_all(), transfer_side_control(), unban_user(), and unmute_observer().

◆ send_server_message() [2/2]

void wesnothd::game::send_server_message ( const std::string &  message,
std::optional< player_iterator player = {},
simple_wml::document doc = nullptr 
) const
inline

◆ send_server_message_to_all() [1/2]

void wesnothd::game::send_server_message_to_all ( const char *  message,
std::optional< player_iterator exclude = {} 
)

Sends a message to all players in this game that aren't excluded.

Parameters
messageThe message to send.
excludeThe players to not send the message to.

Definition at line 1916 of file game.cpp.

References send_data(), and send_server_message().

Referenced by current_turn(), load_next_scenario(), remove_player(), and send_server_message_to_all().

◆ send_server_message_to_all() [2/2]

void wesnothd::game::send_server_message_to_all ( const std::string &  message,
std::optional< player_iterator exclude = {} 
)
inline

◆ send_taken_side()

bool wesnothd::game::send_taken_side ( simple_wml::document cfg,
const simple_wml::node side 
) const
private

Tell the host who owns a side.

Parameters
cfgThe document to send to the host.
sideThe side information to send.
Returns
True if the document was sent, false otherwise.

Definition at line 325 of file game.cpp.

References owner_, simple_wml::document::root(), wesnothd::server::send_to_player(), simple_wml::node::set_attr_dup(), and sides_.

Referenced by all_observers_muted(), and take_side().

◆ send_to_players()

template<typename Container >
void wesnothd::game::send_to_players ( simple_wml::document data,
const Container &  players,
std::optional< player_iterator exclude = {} 
)

Send data to all players except those excluded.

For example, to send a message to all players except the player who typed the original message.

Parameters
dataThe data to send.
playersThe players to send the data to.
excludeThe player from players to not send the data to.

Definition at line 1614 of file game.cpp.

References wesnothd::server::send_to_player().

Referenced by process_turn(), send_and_record_server_message(), send_data(), and send_data_sides().

◆ send_user_list()

void wesnothd::game::send_user_list ( std::optional< player_iterator exclude = {})
private

Function to send a list of users to all clients.

Only sends data if the game is initialized but not yet started.

Parameters
excludeThe players to not send the list of users to.

Definition at line 1526 of file game.cpp.

References simple_wml::node::add_child(), all_game_users(), is_observer(), is_owner(), simple_wml::document::root(), send_data(), simple_wml::node::set_attr(), simple_wml::node::set_attr_dup(), and started_.

Referenced by add_player(), all_observers_muted(), and remove_player().

◆ set_description()

void wesnothd::game::set_description ( simple_wml::node desc)

Set the game's description.

Also set the game as requiring a password if a password is set.

Parameters
descThe node containing the game's description.

Definition at line 1828 of file game.cpp.

References description_, password_, and simple_wml::node::set_attr().

Referenced by wesnothd::server::handle_player_in_game(), and level().

◆ set_name_bans()

void wesnothd::game::set_name_bans ( const std::vector< std::string >  name_bans)
inline

Set a list of usernames that should all be banned from joining the game.

Parameters
name_bansThe list of usernames.

Definition at line 502 of file game.hpp.

References name_bans_.

Referenced by wesnothd::server::handle_create_game().

◆ set_password()

void wesnothd::game::set_password ( const std::string &  passwd)
inline

Sets the password required to access the game.

Parameters
passwdThe password to set.

Definition at line 492 of file game.hpp.

References password_.

Referenced by wesnothd::server::handle_create_game().

◆ set_termination_reason()

void wesnothd::game::set_termination_reason ( const std::string &  reason)

Sets the termination reason for this game.

Parameters
reasonThe termination reason.

Definition at line 1836 of file game.cpp.

References termination_.

Referenced by wesnothd::server::handle_player_in_game(), and termination_reason().

◆ start_game()

void wesnothd::game::start_game ( player_iterator  starter)

◆ started()

bool wesnothd::game::started ( ) const
inline
Returns
Whether this game has started yet.

Definition at line 194 of file game.hpp.

References started_.

◆ starting_pos() [1/2]

static simple_wml::node* wesnothd::game::starting_pos ( simple_wml::node data)
inlinestatic

The non-const version.

Parameters
dataThe data describing the level for a game.
Returns
The [scenario] child node if it exists, else the [snapshot] child if it exists, else data.

Definition at line 155 of file game.hpp.

References simple_wml::node::child().

Referenced by get_replay_filename(), get_sides_list(), wesnothd::server::handle_player_in_game(), and start_game().

◆ starting_pos() [2/2]

static const simple_wml::node* wesnothd::game::starting_pos ( const simple_wml::node data)
inlinestatic

The const version.

Parameters
dataThe data describing the level for a game.
Returns
The [scenario] child node if it exists, else the [snapshot] child if it exists, else data.

Definition at line 172 of file game.hpp.

References simple_wml::node::child().

◆ take_side()

bool wesnothd::game::take_side ( player_iterator  user)
private

Figures out which side to take and tells that side to the game owner.

The owner then should send a [scenario_diff] that implements the side change and a subsequent update_side_data() call makes it actually happen. First we look for a side where save_id= or current_player= matches the new user's name then we search for the first controller="network" side.

Parameters
userThe player taking a side.
Returns
True if the side was taken, false otherwise.

Definition at line 346 of file game.cpp.

References DBG_GAME, get_sides_list(), simple_wml::document::root(), send_taken_side(), simple_wml::node::set_attr_dup(), and started_.

Referenced by add_player(), and all_observers_muted().

◆ termination_reason()

const std::string& wesnothd::game::termination_reason ( ) const
inline

Provides the reason the game was ended.

Returns
Either that the game was aborted (after starting), not started, or has some other reason set.

Definition at line 529 of file game.hpp.

References handle_add_side_wml(), handle_choice(), handle_controller_choice(), handle_random_choice(), set_termination_reason(), started_, and termination_.

Referenced by wesnothd::server::cleanup_game(), and remove_player().

◆ transfer_side_control()

void wesnothd::game::transfer_side_control ( player_iterator  player,
const simple_wml::node cfg 
)

◆ unban_user()

void wesnothd::game::unban_user ( const simple_wml::node unban,
player_iterator  unbanner 
)

Unban a user by name.

The user does not need to be in this game but logged in.

Parameters
unbanThe user to unban.
unbannerThe player doing the unbanning.

Definition at line 839 of file game.cpp.

References bans_, db_id_, find_user(), id_, LOG_GAME, name_, name_bans_, owner_, player_is_banned(), gui2::dialogs::tip::remove(), send_and_record_server_message(), send_server_message(), simple_wml::string_span::to_string(), and username().

Referenced by current_turn(), and wesnothd::server::handle_player_in_game().

◆ unmute_observer()

void wesnothd::game::unmute_observer ( const simple_wml::node unmute,
player_iterator  unmuter 
)

Unmute an observer or unmute all currently muted observers if no name is given.

Parameters
unmuteThe observer to unmute. Empty if unmuting all observers.
unmuterThe player doing the unmuting.

Definition at line 727 of file game.cpp.

References db_id_, simple_wml::string_span::empty(), find_user(), id_, is_muted_observer(), is_observer(), LOG_GAME, muted_observers_, name_, owner_, gui2::dialogs::tip::remove(), send_and_record_server_message(), send_server_message(), simple_wml::string_span::to_string(), and username().

Referenced by current_turn(), and wesnothd::server::handle_player_in_game().

◆ update_side_data()

void wesnothd::game::update_side_data ( )

◆ update_turn_data()

void wesnothd::game::update_turn_data ( )
private

Set or update the current and max turn values in the game's description.

Definition at line 1318 of file game.cpp.

References simple_wml::node::add_child(), simple_wml::node::child(), current_turn(), description_, num_turns_, and simple_wml::node::set_attr_int().

Referenced by all_observers_muted(), end_turn(), and start_game().

◆ username()

std::string wesnothd::game::username ( player_iterator  pl) const
private

Member Data Documentation

◆ all_observers_muted_

bool wesnothd::game::all_observers_muted_
private

Whether all observers should be treated as muted.

Definition at line 872 of file game.hpp.

Referenced by all_observers_muted(), is_muted_observer(), mute_all_observers(), and send_muted_observers().

◆ bans_

std::vector<std::string> wesnothd::game::bans_
private

List of banned IPs.

Definition at line 875 of file game.hpp.

Referenced by ban_user(), player_is_banned(), and unban_user().

◆ current_side_index_

int wesnothd::game::current_side_index_
private

The index of the current side.

The side number is current_side_index_+1.

Definition at line 868 of file game.hpp.

Referenced by current_side(), end_turn(), process_turn(), and start_game().

◆ current_turn_

int wesnothd::game::current_turn_
private

The game's current turn.

Definition at line 866 of file game.hpp.

Referenced by current_turn(), end_turn(), process_change_turns_wml(), process_turn(), and start_game().

◆ db_id_

int wesnothd::game::db_id_
private

Used for unique identification of games played in the database.

Necessary since for MP campaigns multiple scenarios can be played within the same game instance and we need a unique ID per scenario played, not per game instance.

Definition at line 810 of file game.hpp.

Referenced by add_player(), ban_user(), db_id(), debug_player_info(), debug_sides_info(), get_replay_filename(), kick_member(), mute_observer(), next_db_id(), perform_controller_tweaks(), process_turn(), remove_player(), start_game(), unban_user(), and unmute_observer().

◆ db_id_num

int wesnothd::game::db_id_num = 1
staticprivate

Incremented to retrieve a unique ID per wesnothd instance for game instances within the database.

Definition at line 804 of file game.hpp.

Referenced by next_db_id().

◆ description_

simple_wml::node* wesnothd::game::description_
private

Pointer to the game's description in the games_and_users_list_.

Definition at line 863 of file game.hpp.

Referenced by describe_slots(), description(), end_turn(), process_change_turns_wml(), set_description(), and update_turn_data().

◆ history_

std::vector<std::unique_ptr<simple_wml::document> > wesnothd::game::history_
mutableprivate

Replay data.

Definition at line 860 of file game.hpp.

Referenced by clear_history(), record_data(), save_replay(), and send_history().

◆ id_

int wesnothd::game::id_
private

◆ id_num

int wesnothd::game::id_num = 1
staticprivate

Incremented to retrieve a unique ID for game instances within wesnothd.

Definition at line 797 of file game.hpp.

◆ last_choice_request_id_

int wesnothd::game::last_choice_request_id_
private

The ID of the last request received from a client.

New requests should never have a lower value than this.

Definition at line 900 of file game.hpp.

Referenced by handle_choice(), and reset_last_synced_context_id().

◆ level_

simple_wml::document wesnothd::game::level_
private

The current scenario data.

WRONG! This contains the initial state or the state from which the game was loaded from. Using this to make assumptions about the current gamestate is extremely dangerous and should especially not be done for anything that can be nodified by wml (especially by [modify_side]), like team_name, controller ... in [side].

FIXME: move every code here that uses this object to query those information to the clients. But note that there are some checks (like controller == null) that are definitely needed by the server and in this case we should try to modify the client to inform the server if a change of those properties occur. Ofc we shouldn't update level_ then, but rather store that information in a separate object (like in side_controllers_).

Definition at line 857 of file game.hpp.

Referenced by add_player(), allow_observers(), get_replay_filename(), get_sides_list(), is_reload(), level(), level_init(), load_next_scenario(), save_replay(), and start_game().

◆ muted_observers_

user_vector wesnothd::game::muted_observers_
private

A vector of muted observers.

Definition at line 826 of file game.hpp.

Referenced by is_muted_observer(), mute_observer(), send_muted_observers(), and unmute_observer().

◆ name_

std::string wesnothd::game::name_
private

◆ name_bans_

std::vector<std::string> wesnothd::game::name_bans_
private

List of banned usernames.

Definition at line 877 of file game.hpp.

Referenced by ban_user(), player_is_banned(), set_name_bans(), and unban_user().

◆ nsides_

int wesnothd::game::nsides_
private

Number of sides in the current scenario.

Definition at line 835 of file game.hpp.

Referenced by current_side(), end_turn(), handle_add_side_wml(), process_turn(), reset_sides(), and start_game().

◆ num_turns_

int wesnothd::game::num_turns_
private

The maximum number of turns before the game ends.

Definition at line 870 of file game.hpp.

Referenced by process_change_turns_wml(), start_game(), and update_turn_data().

◆ observers_

user_vector wesnothd::game::observers_
private

A vector of observers (members not owning a side).

Definition at line 824 of file game.hpp.

Referenced by add_player(), all_game_users(), debug_player_info(), is_observer(), nobservers(), process_turn(), remove_player(), send_observerjoins(), transfer_side_control(), and update_side_data().

◆ owner_

player_iterator wesnothd::game::owner_
private

◆ password_

std::string wesnothd::game::password_
private

The password needed to join the game.

Definition at line 815 of file game.hpp.

Referenced by has_password(), password_matches(), set_description(), and set_password().

◆ player_connections_

player_connections& wesnothd::game::player_connections_
private

Definition at line 792 of file game.hpp.

Referenced by find_user(), and remove_player().

◆ players_

user_vector wesnothd::game::players_
private

A vector of players (members owning a side).

Definition at line 821 of file game.hpp.

Referenced by add_player(), all_game_users(), debug_player_info(), game(), is_player(), nplayers(), remove_player(), send_data_sides(), start_game(), transfer_side_control(), and update_side_data().

◆ players_not_advanced_

std::set<const player_record*> wesnothd::game::players_not_advanced_
private

in multiplayer campaigns it can happen that some players are still in the previous scenario keep track of those players because processing certain input from those side wil lead to error (oos)

Definition at line 884 of file game.hpp.

Referenced by handle_choice(), load_next_scenario(), new_scenario(), and remove_player().

◆ replay_save_path_

std::string wesnothd::game::replay_save_path_
private

Where to save the replay of this game.

Definition at line 892 of file game.hpp.

Referenced by save_replay().

◆ rng_

randomness::mt_rng wesnothd::game::rng_
private

A wrapper for mersenne twister rng which generates randomness for this game.

Definition at line 895 of file game.hpp.

Referenced by handle_random_choice().

◆ save_replays_

bool wesnothd::game::save_replays_
private

Whether to save a replay of this game.

Definition at line 890 of file game.hpp.

Referenced by save_replay().

◆ server

wesnothd::server& wesnothd::game::server
private

The wesnothd server instance this game exists on.

Definition at line 791 of file game.hpp.

◆ side_controllers_

std::vector<CONTROLLER> wesnothd::game::side_controllers_
private

◆ sides_

side_vector wesnothd::game::sides_
private

◆ started_

bool wesnothd::game::started_
private

◆ termination_

std::string wesnothd::game::termination_
private

The reason the game ended.

Definition at line 887 of file game.hpp.

Referenced by set_termination_reason(), and termination_reason().


The documentation for this class was generated from the following files: