#include <game.hpp>
Public Member Functions | |
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_list & | get_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... | |
utils::optional< player_iterator > | kick_member (const simple_wml::node &kick, player_iterator kicker) |
Kick a user from this game by name. More... | |
utils::optional< player_iterator > | ban_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, utils::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, utils::optional< player_iterator > exclude={}) |
send_server_message_to_all More... | |
void | send_server_message (const char *message, utils::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, utils::optional< player_iterator > player={}, simple_wml::document *doc=nullptr) const |
send_server_message More... | |
void | send_and_record_server_message (const char *message, utils::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, utils::optional< player_iterator > exclude={}) |
send_and_record_server_message More... | |
template<typename Container > | |
void | send_to_players (simple_wml::document &data, const Container &players, utils::optional< player_iterator > exclude={}) |
Send data to all players except those excluded. More... | |
void | send_data (simple_wml::document &data, utils::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 | clear_chat_history () |
Clears the history of recorded chat 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::document & | level () |
void | set_description (simple_wml::node *desc) |
Set the game's description. More... | |
simple_wml::node * | description () 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 |
void | emergency_cleanup () |
Static Public Member Functions | |
static simple_wml::node * | starting_pos (simple_wml::node &data) |
The non-const version. More... | |
static const simple_wml::node * | starting_pos (const simple_wml::node &data) |
The const version. More... | |
Private Member Functions | |
game (const game &)=delete | |
game & | operator= (const game &)=delete |
std::size_t | current_side () const |
utils::optional< player_iterator > | current_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::document > | change_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, utils::optional< player_iterator > exclude={}) |
Sends a document to the provided list of sides. More... | |
void | send_observerjoins (utils::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 | send_chat_history (player_iterator sock) const |
void | notify_new_host () |
In case of a host transfer, notify the new host about its status. More... | |
utils::optional< player_iterator > | find_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 (utils::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::server & | server |
The wesnothd server instance this game exists on. More... | |
player_connections & | player_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< side_controller::type > | 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... | |
std::vector< std::unique_ptr< simple_wml::document > > | chat_history_ |
Replay chat history data. More... | |
simple_wml::node * | description_ |
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... | |
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 = "" |
||
) |
wesnothd::game::~game | ( | ) |
Definition at line 118 of file game.cpp.
References all_game_users(), clear_history(), ERR_GAME, utils::get_unknown_exception_type(), remove_player(), and save_replay().
|
privatedelete |
bool wesnothd::game::add_player | ( | player_iterator | player, |
bool | observer = false |
||
) |
Add a user to the game.
player | The player to add. |
observer | Whether to add the player as an observer. |
Definition at line 1353 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, wesnothd::player::name(), name_, game_config::images::observer, observers_, wesnothd::player::OBSERVING, players_, wesnothd::player::PLAYING, simple_wml::document::root(), send_and_record_server_message(), send_chat_history(), 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().
const user_vector wesnothd::game::all_game_users | ( | ) | const |
Definition at line 1888 of file game.cpp.
References observers_, and players_.
Referenced by has_same_ip(), new_scenario(), send_data(), send_user_list(), update_side_data(), and ~game().
|
inlineprivate |
Definition at line 634 of file game.hpp.
References all_observers_muted_.
bool wesnothd::game::allow_observers | ( | ) | const |
Definition at line 146 of file game.cpp.
References wesnothd::get_multiplayer(), level_, and simple_wml::document::root().
Referenced by add_player().
utils::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.
ban | The user to ban. |
banner | The player doing the banning. |
Definition at line 805 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(), and username().
|
private |
Send [change_controller] message to tell all clients the new controller's name or controller type (human or ai).
side_index | The index of the side whose controller is changing. |
player | The player who is taking control of the side. |
player_name | The name of the player who is taking control of the side. |
player_left | We 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 574 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 perform_controller_tweaks(), remove_player(), and transfer_side_control().
|
private |
Tell everyone else but the source player that the controller type changed.
side_index | The index of the side whose controller type is changing. |
player | The player who owns the side whose controller type is changing. |
player_name | The name of the player who owns the side whose controller type is changing. |
Definition at line 606 of file game.cpp.
References simple_wml::node::add_child(), simple_wml::document::clone(), string_enums::enum_base< Definition >::get_string(), simple_wml::document::root(), send_data(), simple_wml::node::set_attr(), simple_wml::node::set_attr_dup(), and side_controllers_.
Referenced by change_controller(), and transfer_side_control().
void wesnothd::game::clear_chat_history | ( | ) |
Clears the history of recorded chat WML documents.
Definition at line 1861 of file game.cpp.
References chat_history_.
Referenced by start_game().
void wesnothd::game::clear_history | ( | ) |
Clears the history of recorded WML documents.
Definition at line 1856 of file game.cpp.
References history_.
Referenced by start_game(), and ~game().
bool wesnothd::game::controls_side | ( | const std::vector< int > & | sides, |
player_iterator | player | ||
) | const |
|
inlineprivate |
Definition at line 611 of file game.hpp.
References current_side(), and sides_.
Referenced by handle_controller_choice(), is_current_player(), and process_turn().
|
inlineprivate |
Definition at line 603 of file game.hpp.
References current_side_index_, and nsides_.
Referenced by current_player(), end_turn(), and process_turn().
|
inline |
Definition at line 211 of file game.hpp.
References current_turn_.
Referenced by get_replay_filename(), process_change_turns_wml(), remove_player(), and update_turn_data().
|
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.
Definition at line 64 of file game.hpp.
References db_id_.
Referenced by wesnothd::server::cleanup_game().
|
private |
Helps debugging player and observer lists.
Definition at line 1898 of file game.cpp.
References db_id_, id_, observers_, and players_.
Referenced by add_player(), remove_player(), and update_side_data().
|
private |
Helps debugging controller tweaks.
Definition at line 1914 of file game.cpp.
References db_id_, get_sides_list(), string_enums::enum_base< Definition >::get_string(), id_, s, and side_controllers_.
Referenced by load_next_scenario(), perform_controller_tweaks(), and start_game().
bool wesnothd::game::describe_slots | ( | ) |
Set the description to the number of available slots.
Definition at line 633 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_.
|
inline |
Definition at line 480 of file game.hpp.
References description_.
Referenced by wesnothd::server::cleanup_game().
|
inline |
Definition at line 589 of file game.hpp.
References observers_, and players_.
Referenced by wesnothd::server::cleanup_game().
|
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.
new_side | The side number whose turn to move it has become. |
Definition at line 1306 of file game.cpp.
References current_side(), current_side_index_, current_turn_, description_, i, nsides_, side_controllers_, and update_turn_data().
Referenced by process_turn().
|
private |
Shortcut to a convenience function for finding a user by name.
name | The name of the user to find. |
Definition at line 1933 of file game.cpp.
References name(), and player_connections_.
Referenced by ban_user(), kick_member(), mute_observer(), transfer_side_control(), unban_user(), and unmute_observer().
std::string wesnothd::game::get_replay_filename | ( | ) |
Definition at line 1784 of file game.cpp.
References current_turn(), db_id_, utils::erase_if(), filename, wesnothd::is_invalid_filename_char(), level_, name(), simple_wml::document::root(), and starting_pos().
Referenced by wesnothd::server::cleanup_game(), and save_replay().
|
inline |
Definition at line 179 of file game.hpp.
References simple_wml::node::children(), level_, simple_wml::document::root(), and starting_pos().
Referenced by debug_sides_info(), describe_slots(), perform_controller_tweaks(), reset_sides(), start_game(), take_side(), transfer_side_control(), and update_side_data().
void wesnothd::game::handle_add_side_wml | ( | ) |
Adds a new, empty side owned by no one.
Definition at line 1134 of file game.cpp.
References nsides_, side_controllers_, and sides_.
Referenced by 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.
data | The data needed to process the choice. |
user | The player making the request. |
Definition at line 1206 of file game.cpp.
References data, 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_.
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.
data | Contains the information about which side to change the controller of. |
Definition at line 1141 of file game.cpp.
References simple_wml::node::add_child(), current_player(), string_enums::enum_base< Definition >::get_enum(), string_enums::enum_base< Definition >::get_string(), last_choice_request_id_, 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(), simple_wml::node::set_attr_int(), side_controllers_, and sides_.
Referenced by handle_choice().
void wesnothd::game::handle_random_choice | ( | ) |
Send a randomly generated number to the requestor.
Definition at line 1112 of file game.cpp.
References simple_wml::node::add_child(), randomness::mt_rng::get_next_random(), last_choice_request_id_, record_data(), rng_, send_data(), simple_wml::node::set_attr(), simple_wml::node::set_attr_dup(), and simple_wml::node::set_attr_int().
Referenced by handle_choice().
|
inline |
|
private |
Checks whether a user has the same IP as any other members of this game.
Definition at line 1679 of file game.cpp.
References all_game_users().
Referenced by add_player().
|
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.
Definition at line 52 of file game.hpp.
References id_.
Referenced by wesnothd::server::cleanup_game().
|
inlineprivate |
player | The player being checked. |
Definition at line 620 of file game.hpp.
References current_player().
Referenced by is_legal_command(), and process_turn().
|
private |
Definition at line 889 of file game.cpp.
References simple_wml::node::attr(), simple_wml::node::child(), simple_wml::node::has_attr(), is_current_player(), simple_wml::string_span::is_null(), is_player(), simple_wml::node::one_child(), owner_, sides_, and simple_wml::string_span::to_int().
Referenced by process_turn().
|
inline |
player | The player being checked. |
Definition at line 98 of file game.hpp.
References is_observer(), and is_player().
Referenced by add_player(), ban_user(), kick_member(), remove_player(), and transfer_side_control().
|
private |
player | The observer being checked. |
Definition at line 156 of file game.cpp.
References all_observers_muted_, is_observer(), and muted_observers_.
Referenced by mute_observer(), process_turn(), and unmute_observer().
bool wesnothd::game::is_observer | ( | player_iterator | player | ) | const |
player | The player being checked. |
Definition at line 151 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().
|
inline |
player | The player being checked. |
Definition at line 89 of file game.hpp.
References owner_.
Referenced by send_user_list().
bool wesnothd::game::is_player | ( | player_iterator | player | ) | const |
player | The player being checked. |
Definition at line 169 of file game.cpp.
References players_.
Referenced by handle_choice(), is_legal_command(), is_member(), process_change_turns_wml(), process_turn(), process_whiteboard(), remove_player(), and transfer_side_control().
bool wesnothd::game::is_reload | ( | ) | const |
Definition at line 1993 of file game.cpp.
References wesnothd::get_multiplayer(), simple_wml::node::has_attr(), level_, and simple_wml::document::root().
utils::optional< player_iterator > wesnothd::game::kick_member | ( | const simple_wml::node & | kick, |
player_iterator | kicker | ||
) |
Kick a user from this game by name.
kick | The user to kick. |
kicker | The player doing the kicking. |
Definition at line 773 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(), and username().
|
inline |
|
inline |
Definition at line 137 of file game.hpp.
References simple_wml::document::child(), and level_.
|
private |
users | The users to create a comma separated list from. |
Definition at line 179 of file game.cpp.
Referenced by send_muted_observers(), and start_game().
void wesnothd::game::load_next_scenario | ( | player_iterator | user | ) |
A user asks for the next scenario to advance to.
user | The user asking for the next scenario. |
Definition at line 1583 of file game.cpp.
References simple_wml::node::add_child(), simple_wml::node::copy_into(), DBG_GAME, debug_sides_info(), level_, players_not_advanced_, simple_wml::document::root(), send_history(), send_observerjoins(), send_server_message_to_all(), wesnothd::server::send_to_player(), simple_wml::node::set_attr(), sides_, and started_.
void wesnothd::game::mute_all_observers | ( | ) |
Toggles whether all observers are muted or not.
Definition at line 672 of file game.cpp.
References all_observers_muted_, and send_and_record_server_message().
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.
mute | The observer to mute. Empty if sending a message to muted observers. |
muter | The player doing the muting. |
Definition at line 694 of file game.cpp.
References db_id_, 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(), and username().
|
inline |
Definition at line 80 of file game.hpp.
References name_.
Referenced by find_user(), get_replay_filename(), and player_is_banned().
void wesnothd::game::new_scenario | ( | player_iterator | sender | ) |
When the host sends the new scenario of a mp campaign.
sender | The player sending the scenario data. |
Definition at line 1571 of file game.cpp.
References all_game_users(), owner_, players_not_advanced_, and started_.
|
inline |
|
inline |
Definition at line 203 of file game.hpp.
References observers_.
|
private |
In case of a host transfer, notify the new host about its status.
Definition at line 622 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 remove_player().
|
inline |
|
inline |
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 194 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().
bool wesnothd::game::player_is_banned | ( | player_iterator | player, |
const std::string & | name | ||
) | const |
player | The player being checked (by iterator). |
name | The player being checked (by username). |
Definition at line 664 of file game.cpp.
References bans_, name(), and name_bans_.
Referenced by ban_user(), and unban_user().
void wesnothd::game::process_change_turns_wml | ( | simple_wml::document & | data, |
player_iterator | user | ||
) |
Handles incoming [change_turns_wml] data.
data | The [change_turns_wml] data. |
user | The player changing turns. |
Definition at line 1277 of file game.cpp.
References simple_wml::node::add_child(), simple_wml::node::child(), simple_wml::node::copy_into(), current_turn(), current_turn_, data, description_, is_player(), num_turns_, and started_.
void wesnothd::game::process_message | ( | simple_wml::document & | data, |
player_iterator | user | ||
) |
Sends an ingame message to all other players.
data | The message to send. |
user | The user sending the message. |
Definition at line 877 of file game.cpp.
References chat_history_, data, wfl::msg(), send_data(), and wesnothd::chat_message::truncate_message().
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.
data | The turn commands. |
user | The user who sent a command to be processed during the turn. This may not be the player whose turn it currently is. |
Definition at line 954 of file game.cpp.
References simple_wml::node::add_child(), simple_wml::node::child(), simple_wml::node::children(), simple_wml::node::copy_into(), current_player(), current_side(), current_side_index_, current_turn_, data, db_id_, DBG_GAME, simple_wml::string_span::empty(), end_turn(), ERR_GAME, 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().
void wesnothd::game::process_whiteboard | ( | simple_wml::document & | data, |
player_iterator | user | ||
) |
Handles incoming [whiteboard] data.
data | The whiteboard data. |
user | The user sending the whiteboard data. |
Definition at line 1250 of file game.cpp.
References data, is_player(), LOG_GAME, wfl::msg(), send_and_record_server_message(), send_data_sides(), sides_, and started_.
void wesnothd::game::record_data | ( | std::unique_ptr< simple_wml::document > | data | ) |
Records a WML document in the game's history.
data | The WML document to record. |
Definition at line 1850 of file game.cpp.
References data, and history_.
Referenced by change_controller(), handle_controller_choice(), handle_random_choice(), process_turn(), and send_and_record_server_message().
bool wesnothd::game::remove_player | ( | player_iterator | player, |
const bool | disconnect = false , |
||
const bool | destruct = false |
||
) |
Removes a user from the game.
player | The player to remove. |
disconnect | If the player disconnected from the server entirely. |
destruct | If the game is ending as well. |
Definition at line 1438 of file game.cpp.
References simple_wml::node::add_child(), change_controller(), current_turn(), db_id_, DBG_GAME, debug_player_info(), utils::erase(), ERR_GAME, string_enums::enum_base< Definition >::get_string(), id_, is_member(), is_observer(), is_player(), LOG_GAME, name_, notify_new_host(), game_config::images::observer, observers_, simple_wml::document::output(), owner_, player_connections_, players_, players_not_advanced_, wesnothd::player::PLAYING, 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(), kick_member(), and ~game().
|
inline |
Reset the internal counter for choice requests made by clients to the server.
Definition at line 571 of file game.hpp.
References last_choice_request_id_.
|
private |
calculates the initial value for sides_, side_controllerds_, nsides_
Definition at line 388 of file game.cpp.
References get_sides_list(), nsides_, side_controllers_, and sides_.
Referenced by update_side_data().
void wesnothd::game::save_replay | ( | ) |
Move the level information and recorded history into a replay file and save it.
Definition at line 1794 of file game.cpp.
References simple_wml::document::child(), DBG_GAME, e, ERR_GAME, filename, get_replay_filename(), h, history_, simple_wml::INIT_STATIC, level_, name_, simple_wml::node_to_string(), filesystem::ostream_file(), simple_wml::document::output(), replay_save_path_, save_replays_, simple_wml::document::set_attr_dup(), started_, and WRN_CONFIG.
Referenced by ~game().
void wesnothd::game::send_and_record_server_message | ( | const char * | message, |
utils::optional< player_iterator > | exclude = {} |
||
) |
Send data to all players in this game except 'exclude'.
Also record this data for the replay.
message | The message to send. |
exclude | The players to not send the message to. |
Definition at line 1943 of file game.cpp.
References record_data(), send_data(), send_server_message(), and started_.
Referenced by add_player(), ban_user(), change_controller(), handle_choice(), handle_controller_choice(), kick_member(), mute_all_observers(), mute_observer(), notify_new_host(), perform_controller_tweaks(), process_turn(), process_whiteboard(), remove_player(), start_game(), transfer_side_control(), unban_user(), and unmute_observer().
|
inline |
|
private |
Definition at line 1753 of file game.cpp.
References chat_history_, h, and wesnothd::server::send_to_player().
Referenced by add_player().
void wesnothd::game::send_data | ( | simple_wml::document & | data, |
utils::optional< player_iterator > | exclude = {} |
||
) |
Send data to all players and observers except those excluded.
data | The data to send. |
exclude | The players/observers to not send the data to. |
Definition at line 1645 of file game.cpp.
References all_game_users(), data, and send_to_players().
Referenced by add_player(), change_controller_type(), handle_controller_choice(), 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().
|
private |
Sends a document to the provided list of sides.
data | The data to be sent to the provided sides. |
sides | A comma sperated list of side numbers to which the document should be sent. |
exclude | Players to not send the data to. |
Definition at line 1650 of file game.cpp.
References data, DBG_GAME, players_, and send_to_players().
Referenced by process_turn(), and process_whiteboard().
|
private |
Definition at line 1726 of file game.cpp.
References e, h, history_, simple_wml::INIT_STATIC, wesnothd::server::send_to_player(), and WRN_CONFIG.
Referenced by add_player(), and load_next_scenario().
|
private |
Tells a player to leave the game.
user | The player leaving the game. |
Definition at line 767 of file game.cpp.
References simple_wml::INIT_COMPRESSED, and wesnothd::server::send_to_player().
Referenced by ban_user(), and kick_member().
|
private |
Sends a message either stating that all observers are muted or listing the observers that are muted.
user | The player to send the message to. |
Definition at line 682 of file game.cpp.
References all_observers_muted_, list_users(), muted_observers_, and send_server_message().
Referenced by mute_observer().
|
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.
player | The observer who joined. |
Definition at line 1694 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(), load_next_scenario(), and start_game().
|
private |
Definition at line 1714 of file game.cpp.
References simple_wml::node::add_child(), game_config::images::observer, simple_wml::document::root(), send_data(), and simple_wml::node::set_attr_dup().
Referenced by remove_player(), and transfer_side_control().
void wesnothd::game::send_server_message | ( | const char * | message, |
utils::optional< player_iterator > | player = {} , |
||
simple_wml::document * | doc = nullptr |
||
) | const |
Send a server message to the specified player.
message | The message to send. |
player | The player to send the message to. If empty then the message is not sent. |
doc | The document to create the message in. If nullptr then a new document is created. |
Definition at line 1961 of file game.cpp.
References simple_wml::node::add_child(), wfl::msg(), simple_wml::document::root(), wesnothd::server::send_to_player(), chrono::serialize_timestamp(), simple_wml::node::set_attr(), and started_.
Referenced by add_player(), ban_user(), kick_member(), mute_observer(), process_turn(), send_and_record_server_message(), send_muted_observers(), send_server_message_to_all(), transfer_side_control(), unban_user(), and unmute_observer().
|
inline |
void wesnothd::game::send_server_message_to_all | ( | const char * | message, |
utils::optional< player_iterator > | exclude = {} |
||
) |
Sends a message to all players in this game that aren't excluded.
message | The message to send. |
exclude | The players to not send the message to. |
Definition at line 1954 of file game.cpp.
References send_data(), and send_server_message().
Referenced by load_next_scenario(), and remove_player().
|
inline |
|
private |
Tell the host who owns a side.
cfg | The document to send to the host. |
side | The side information to send. |
Definition at line 326 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 take_side().
void wesnothd::game::send_to_players | ( | simple_wml::document & | data, |
const Container & | players, | ||
utils::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.
data | The data to send. |
players | The players to send the data to. |
exclude | The player from players to not send the data to. |
Definition at line 1636 of file game.cpp.
References data, and wesnothd::server::send_to_player().
Referenced by process_turn(), send_data(), and send_data_sides().
|
private |
Function to send a list of users to all clients.
Only sends data if the game is initialized but not yet started.
exclude | The players to not send the list of users to. |
Definition at line 1548 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(), and remove_player().
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.
desc | The node containing the game's description. |
Definition at line 1866 of file game.cpp.
References description_, password_, and simple_wml::node::set_attr().
|
inline |
Set a list of usernames that should all be banned from joining the game.
name_bans | The list of usernames. |
Definition at line 500 of file game.hpp.
References name_bans_.
|
inline |
void wesnothd::game::set_termination_reason | ( | const std::string & | reason | ) |
Sets the termination reason for this game.
reason | The termination reason. |
Definition at line 1874 of file game.cpp.
References termination_.
void wesnothd::game::start_game | ( | player_iterator | starter | ) |
Starts the game (if a new game) or starts the next scenario of an MP campaign.
starter | The game's host. |
Definition at line 249 of file game.cpp.
References simple_wml::node::child(), clear_chat_history(), clear_history(), current_side_index_, current_turn_, db_id_, DBG_GAME, debug_sides_info(), wesnothd::get_multiplayer(), get_sides_list(), id_, level_, list_users(), LOG_GAME, wfl::msg(), name_, nsides_, num_turns_, players_, simple_wml::document::root(), send_and_record_server_message(), send_observerjoins(), sides_, started_, starting_pos(), and update_turn_data().
|
inline |
|
inlinestatic |
|
inlinestatic |
The non-const version.
data | The data describing the level for a game. |
Definition at line 148 of file game.hpp.
References data.
Referenced by get_replay_filename(), get_sides_list(), wesnothd::server::handle_player_in_game(), and start_game().
|
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=human or reserved side.
user | The player taking a side. |
Definition at line 347 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().
|
inline |
Provides the reason the game was ended.
Definition at line 527 of file game.hpp.
References started_, and termination_.
Referenced by wesnothd::server::cleanup_game(), and remove_player().
void wesnothd::game::transfer_side_control | ( | player_iterator | player, |
const simple_wml::node & | cfg | ||
) |
Lets a player owning a side give it to another player or observer.
player | The player owning the side. |
cfg | The node containing the transfer information. |
Definition at line 471 of file game.cpp.
References simple_wml::node::add_child(), change_controller(), change_controller_type(), DBG_GAME, simple_wml::string_span::empty(), utils::erase(), find_user(), string_enums::enum_base< Definition >::get_enum(), get_sides_list(), is_member(), is_observer(), is_player(), wfl::msg(), observers_, wesnothd::player::OBSERVING, owner_, players_, wesnothd::player::PLAYING, simple_wml::document::root(), send_and_record_server_message(), send_data(), send_observerquit(), send_server_message(), simple_wml::node::set_attr_dup(), side_controllers_, sides_, utf8::size(), simple_wml::string_span::to_string(), and username().
Referenced by process_turn().
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.
unban | The user to unban. |
unbanner | The player doing the unbanning. |
Definition at line 847 of file game.cpp.
References bans_, db_id_, utils::erase(), find_user(), id_, LOG_GAME, name_, name_bans_, owner_, player_is_banned(), send_and_record_server_message(), send_server_message(), and username().
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.
unmute | The observer to unmute. Empty if unmuting all observers. |
unmuter | The player doing the unmuting. |
Definition at line 735 of file game.cpp.
References db_id_, utils::erase(), find_user(), id_, is_muted_observer(), is_observer(), LOG_GAME, muted_observers_, name_, owner_, send_and_record_server_message(), send_server_message(), and username().
void wesnothd::game::update_side_data | ( | ) |
Resets the side configuration according to the scenario data.
Definition at line 399 of file game.cpp.
References all_game_users(), DBG_GAME, debug_player_info(), string_enums::enum_base< Definition >::get_enum(), get_sides_list(), observers_, wesnothd::player::OBSERVING, owner_, players_, wesnothd::player::PLAYING, reset_sides(), side_controllers_, sides_, and started_.
Referenced by perform_controller_tweaks().
|
private |
Set or update the current and max turn values in the game's description.
Definition at line 1338 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 end_turn(), and start_game().
|
private |
pl | The player. |
Definition at line 174 of file game.cpp.
Referenced by ban_user(), kick_member(), mute_observer(), notify_new_host(), perform_controller_tweaks(), process_turn(), remove_player(), transfer_side_control(), unban_user(), and unmute_observer().
|
private |
Whether all observers should be treated as muted.
Definition at line 879 of file game.hpp.
Referenced by all_observers_muted(), is_muted_observer(), mute_all_observers(), and send_muted_observers().
|
private |
List of banned IPs.
Definition at line 882 of file game.hpp.
Referenced by ban_user(), player_is_banned(), and unban_user().
|
mutableprivate |
Replay chat history data.
Definition at line 867 of file game.hpp.
Referenced by clear_chat_history(), process_message(), and send_chat_history().
|
private |
The index of the current side.
The side number is current_side_index_+1.
Definition at line 875 of file game.hpp.
Referenced by current_side(), end_turn(), process_turn(), and start_game().
|
private |
The game's current turn.
Definition at line 873 of file game.hpp.
Referenced by current_turn(), end_turn(), process_change_turns_wml(), process_turn(), and start_game().
|
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 815 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().
|
staticprivate |
Incremented to retrieve a unique ID per wesnothd instance for game instances within the database.
Definition at line 809 of file game.hpp.
Referenced by next_db_id().
|
private |
Pointer to the game's description in the games_and_users_list_.
Definition at line 870 of file game.hpp.
Referenced by describe_slots(), description(), end_turn(), process_change_turns_wml(), set_description(), and update_turn_data().
|
mutableprivate |
Replay data.
Definition at line 865 of file game.hpp.
Referenced by clear_history(), record_data(), save_replay(), and send_history().
|
private |
This game's ID within wesnothd.
Definition at line 804 of file game.hpp.
Referenced by add_player(), ban_user(), debug_player_info(), debug_sides_info(), game(), id(), kick_member(), mute_observer(), perform_controller_tweaks(), process_turn(), remove_player(), start_game(), unban_user(), and unmute_observer().
|
staticprivate |
|
private |
The ID of the last request received from a client.
New requests should never have a lower value than this.
Definition at line 907 of file game.hpp.
Referenced by handle_choice(), handle_controller_choice(), handle_random_choice(), and reset_last_synced_context_id().
|
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 862 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().
|
private |
A vector of muted observers.
Definition at line 831 of file game.hpp.
Referenced by is_muted_observer(), mute_observer(), send_muted_observers(), and unmute_observer().
|
private |
The name of the game.
Definition at line 818 of file game.hpp.
Referenced by add_player(), ban_user(), game(), kick_member(), mute_observer(), name(), remove_player(), save_replay(), start_game(), unban_user(), and unmute_observer().
|
private |
List of banned usernames.
Definition at line 884 of file game.hpp.
Referenced by ban_user(), player_is_banned(), set_name_bans(), and unban_user().
|
private |
Number of sides in the current scenario.
Definition at line 840 of file game.hpp.
Referenced by current_side(), end_turn(), handle_add_side_wml(), process_turn(), reset_sides(), and start_game().
|
private |
The maximum number of turns before the game ends.
Definition at line 877 of file game.hpp.
Referenced by process_change_turns_wml(), start_game(), and update_turn_data().
|
private |
A vector of observers (members not owning a side).
Definition at line 829 of file game.hpp.
Referenced by add_player(), all_game_users(), debug_player_info(), emergency_cleanup(), is_observer(), nobservers(), process_turn(), remove_player(), send_observerjoins(), transfer_side_control(), and update_side_data().
|
private |
The game host or later owner (if the host left).
Definition at line 823 of file game.hpp.
Referenced by ban_user(), game(), handle_choice(), is_legal_command(), is_owner(), kick_member(), mute_observer(), new_scenario(), notify_new_host(), perform_controller_tweaks(), process_turn(), remove_player(), send_taken_side(), transfer_side_control(), unban_user(), unmute_observer(), and update_side_data().
|
private |
The password needed to join the game.
Definition at line 820 of file game.hpp.
Referenced by has_password(), password_matches(), set_description(), and set_password().
|
private |
Definition at line 797 of file game.hpp.
Referenced by find_user(), and remove_player().
|
private |
A vector of players (members owning a side).
Definition at line 826 of file game.hpp.
Referenced by add_player(), all_game_users(), debug_player_info(), emergency_cleanup(), game(), is_player(), nplayers(), remove_player(), send_data_sides(), start_game(), transfer_side_control(), and update_side_data().
|
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 891 of file game.hpp.
Referenced by handle_choice(), load_next_scenario(), new_scenario(), and remove_player().
|
private |
Where to save the replay of this game.
Definition at line 899 of file game.hpp.
Referenced by save_replay().
|
private |
A wrapper for mersenne twister rng which generates randomness for this game.
Definition at line 902 of file game.hpp.
Referenced by handle_random_choice().
|
private |
Whether to save a replay of this game.
Definition at line 897 of file game.hpp.
Referenced by save_replay().
|
private |
|
private |
A vector containiner the controller type for each side.
Definition at line 837 of file game.hpp.
Referenced by change_controller(), change_controller_type(), debug_sides_info(), end_turn(), handle_add_side_wml(), handle_controller_choice(), remove_player(), reset_sides(), transfer_side_control(), and update_side_data().
|
private |
A vector of side owners.
Definition at line 834 of file game.hpp.
Referenced by change_controller(), controls_side(), current_player(), describe_slots(), handle_add_side_wml(), handle_controller_choice(), is_legal_command(), load_next_scenario(), perform_controller_tweaks(), process_turn(), process_whiteboard(), remove_player(), reset_sides(), send_taken_side(), start_game(), transfer_side_control(), and update_side_data().
|
private |
Whether the game has been started or not.
Definition at line 842 of file game.hpp.
Referenced by add_player(), change_controller(), describe_slots(), handle_choice(), load_next_scenario(), new_scenario(), process_change_turns_wml(), process_turn(), process_whiteboard(), remove_player(), save_replay(), send_and_record_server_message(), send_server_message(), send_user_list(), start_game(), started(), take_side(), termination_reason(), and update_side_data().
|
private |
The reason the game ended.
Definition at line 894 of file game.hpp.
Referenced by set_termination_reason(), and termination_reason().