32 typedef std::vector<utils::optional<player_iterator>>
side_vector;
40 const std::string&
name =
"",
41 bool save_replays =
false,
42 const std::string& replay_save_path =
"");
80 const std::string&
name()
const
394 const char* message, utils::optional<player_iterator> player = {},
simple_wml::document* doc =
nullptr)
const;
428 template<
typename Container>
529 static const std::string aborted =
"aborted";
530 static const std::string not_started =
"not started";
680 const std::string& player_name,
681 const bool player_left =
true);
693 const std::string& player_name);
711 utils::optional<player_iterator> exclude = {});
764 void send_user_list(utils::optional<player_iterator> exclude = {});
865 mutable std::vector<std::unique_ptr<simple_wml::document>>
history_;
node * child(const char *name)
const child_list & children(const char *name) const
std::vector< node * > child_list
void handle_controller_choice(const simple_wml::node &data)
Handle a request to change a side's controller.
utils::optional< player_iterator > ban_user(const simple_wml::node &ban, player_iterator banner)
Ban a user by name.
std::string debug_player_info() const
Helps debugging player and observer lists.
void send_user_list(utils::optional< player_iterator > exclude={})
Function to send a list of users to all clients.
void mute_all_observers()
Toggles whether all observers are muted or not.
static const simple_wml::node * starting_pos(const simple_wml::node &data)
The const version.
int current_side_index_
The index of the current side.
std::vector< std::unique_ptr< simple_wml::document > > history_
Replay data.
bool is_legal_command(const simple_wml::node &command, player_iterator user)
void send_and_record_server_message(const std::string &message, utils::optional< player_iterator > exclude={})
send_and_record_server_message
void clear_chat_history()
Clears the history of recorded chat WML documents.
std::vector< std::string > bans_
List of banned IPs.
bool is_owner(player_iterator player) const
void send_history(player_iterator sock) const
void process_change_turns_wml(simple_wml::document &data, player_iterator user)
Handles incoming [change_turns_wml] data.
bool is_current_player(player_iterator player) const
randomness::mt_rng rng_
A wrapper for mersenne twister rng which generates randomness for this game.
std::string has_same_ip(player_iterator user) const
Checks whether a user has the same IP as any other members of this game.
std::string name_
The name of the game.
void notify_new_host()
In case of a host transfer, notify the new host about its status.
void send_chat_history(player_iterator sock) const
void update_side_data()
Resets the side configuration according to the scenario data.
std::string replay_save_path_
Where to save the replay of this game.
void send_leave_game(player_iterator user) const
Tells a player to leave the game.
void handle_random_choice()
Send a randomly generated number to the requestor.
void set_termination_reason(const std::string &reason)
Sets the termination reason for this game.
void unban_user(const simple_wml::node &unban, player_iterator unbanner)
Unban a user by name.
std::vector< std::unique_ptr< simple_wml::document > > chat_history_
Replay chat history data.
void perform_controller_tweaks()
This is performed just before starting and before the [start_game] signal.
void record_data(std::unique_ptr< simple_wml::document > data)
Records a WML document in the game's history.
std::vector< side_controller::type > side_controllers_
A vector containiner the controller type for each side.
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.
void handle_add_side_wml()
Adds a new, empty side owned by no one.
void clear_history()
Clears the history of recorded WML documents.
std::size_t nobservers() const
bool password_matches(const std::string &passwd) const
int current_turn_
The game's current turn.
bool save_replays_
Whether to save a replay of this game.
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.
void load_next_scenario(player_iterator user)
A user asks for the next scenario to advance to.
bool add_player(player_iterator player, bool observer=false)
Add a user to the game.
utils::optional< player_iterator > current_player() const
void new_scenario(player_iterator sender)
When the host sends the new scenario of a mp campaign.
const user_vector all_game_users() const
void send_data(simple_wml::document &data, utils::optional< player_iterator > exclude={})
Send data to all players and observers except those excluded.
void start_game(player_iterator starter)
Starts the game (if a new game) or starts the next scenario of an MP campaign.
static simple_wml::node * starting_pos(simple_wml::node &data)
The non-const version.
void send_and_record_server_message(const char *message, utils::optional< player_iterator > exclude={})
Send data to all players in this game except 'exclude'.
std::vector< std::string > name_bans_
List of banned usernames.
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="")
bool remove_player(player_iterator player, const bool disconnect=false, const bool destruct=false)
Removes a user from the game.
int id_
This game's ID within wesnothd.
simple_wml::document & level()
std::size_t current_side() const
utils::optional< player_iterator > find_user(const simple_wml::string_span &name)
Shortcut to a convenience function for finding a user by name.
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.
std::size_t current_turn() const
std::string username(player_iterator pl) const
void process_whiteboard(simple_wml::document &data, player_iterator user)
Handles incoming [whiteboard] data.
player_connections & player_connections_
void send_server_message_to_all(const std::string &message, utils::optional< player_iterator > exclude={})
send_server_message_to_all
void send_server_message(const std::string &message, utils::optional< player_iterator > player={}, simple_wml::document *doc=nullptr) const
send_server_message
bool all_observers_muted() const
bool is_member(player_iterator player) const
int db_id_
Used for unique identification of games played in the database.
void reset_sides()
calculates the initial value for sides_, side_controllerds_, nsides_
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.
std::string list_users(user_vector users) const
user_vector muted_observers_
A vector of muted observers.
bool is_muted_observer(player_iterator player) const
std::set< const player_record * > players_not_advanced_
in multiplayer campaigns it can happen that some players are still in the previous scenario keep trac...
void save_replay()
Move the level information and recorded history into a replay file and save it.
simple_wml::node * description() const
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.
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.
bool started_
Whether the game has been started or not.
int db_id() const
This ID is not reused between scenarios of MP campaigns.
utils::optional< player_iterator > kick_member(const simple_wml::node &kick, player_iterator kicker)
Kick a user from this game by name.
bool has_password() const
std::string debug_sides_info() const
Helps debugging controller tweaks.
std::string termination_
The reason the game ended.
const std::string & name() const
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.
const simple_wml::node::child_list & get_sides_list() const
simple_wml::node * description_
Pointer to the game's description in the games_and_users_list_.
game(const game &)=delete
user_vector observers_
A vector of observers (members not owning a side).
static int db_id_num
Incremented to retrieve a unique ID per wesnothd instance for game instances within the database.
void set_description(simple_wml::node *desc)
Set the game's description.
int num_turns_
The maximum number of turns before the game ends.
bool all_observers_muted_
Whether all observers should be treated as muted.
side_vector sides_
A vector of side owners.
int nsides_
Number of sides in the current scenario.
int id() const
This ID is reused between scenarios of MP campaigns.
simple_wml::document level_
The current scenario data.
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.
bool take_side(player_iterator user)
Figures out which side to take and tells that side to the game owner.
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 (hu...
bool allow_observers() const
user_vector players_
A vector of players (members owning a side).
void next_db_id()
Increments the ID used when running database queries.
void send_observerquit(player_iterator observer)
bool send_taken_side(simple_wml::document &cfg, const simple_wml::node *side) const
Tell the host who owns a side.
wesnothd::server & server
The wesnothd server instance this game exists on.
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.
std::string password_
The password needed to join the game.
bool is_observer(player_iterator player) const
bool describe_slots()
Set the description to the number of available slots.
void reset_last_synced_context_id()
Reset the internal counter for choice requests made by clients to the server.
bool is_player(player_iterator player) const
int last_choice_request_id_
The ID of the last request received from a client.
const std::string & termination_reason() const
Provides the reason the game was ended.
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'.
void send_observerjoins(utils::optional< player_iterator > player={})
Send a document per observer in the game.
static int id_num
Incremented to retrieve a unique ID for game instances within wesnothd.
bool player_is_banned(player_iterator player, const std::string &name) const
std::string get_replay_filename()
void set_password(const std::string &passwd)
Sets the password required to access the game.
void send_to_players(simple_wml::document &data, const Container &players, utils::optional< player_iterator > exclude={})
Send data to all players except those excluded.
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.
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.
void update_turn_data()
Set or update the current and max turn values in the game's description.
game & operator=(const game &)=delete
bool end_turn(int new_side)
Function which should be called every time a player ends their turn (i.e.
player_iterator owner_
The game host or later owner (if the host left).
void process_message(simple_wml::document &data, player_iterator user)
Sends an ingame message to all other players.
std::size_t nplayers() const
std::vector< player_iterator > user_vector
player_connections::const_iterator player_iterator
std::vector< utils::optional< player_iterator > > side_vector
bmi::multi_index_container< player_record, bmi::indexed_by< bmi::ordered_unique< bmi::tag< socket_t >, bmi::const_mem_fun< player_record, const any_socket_ptr, &player_record::socket > >, bmi::hashed_unique< bmi::tag< name_t >, bmi::const_mem_fun< player_record, const std::string &, &player_record::name > >, bmi::ordered_non_unique< bmi::tag< game_t >, bmi::const_mem_fun< player_record, int, &player_record::game_id > > > > player_connections