15 #ifndef GAME_HPP_INCLUDED
16 #define GAME_HPP_INCLUDED
29 #include <boost/ptr_container/ptr_vector.hpp>
51 int id()
const {
return id_; }
232 static const std::string not_started =
"not started";
282 const bool player_left =
true);
395 typedef boost::ptr_vector<simple_wml::document>
t_history;
bool process_turn(simple_wml::document &data, const socket_ptr user)
Handles [end_turn], repackages [commands] with private [speak]s in them and sends the data...
bool player_is_banned(const socket_ptr player) const
Checks whether the connection's ip address is banned.
void start_game(const socket_ptr starter)
rand_rng::mt_rng rng_
A wrapper for mersenne twister rng which generates randomness for this game.
bool allow_observers() const
void set_current_turn(int turn)
bool password_matches(const std::string &passwd) const
std::string debug_sides_info() const
Helps debugging controller tweaks.
void unmute_observer(const simple_wml::node &unmute, const socket_ptr unmuter)
void send_observerquit(const socket_ptr observer) const
player_connections & player_connections_
const std::string & name() const
void send_server_message(const char *message, socket_ptr sock=socket_ptr(), simple_wml::document *doc=nullptr) const
void handle_random_choice(const simple_wml::node &data)
void change_controller(const size_t side_num, const socket_ptr sock, const std::string &player_name, const bool player_left=true)
Send [change_controller] message to tell all clients the new controller's name or controller type (hu...
size_t nobservers() const
bool observers_can_label() const
user_vector muted_observers_
void update_side_data()
Resets the side configuration according to the scenario data.
std::vector< socket_ptr > side_vector
socket_ptr const std::string bool save_replays
std::string has_same_ip(const socket_ptr user, bool observer) const
Checks whether a user has the same IP as members of this game.
bool operator()(const game &g) const
void transfer_side_control(const socket_ptr sock, const simple_wml::node &cfg)
Let's a player owning a side give it to another player or observer.
int nsides_
Number of sides in the current scenario.
user_vector observers_
A vector of observers (members not owning a side).
void process_message(simple_wml::document &data, const socket_ptr user)
const user_vector all_game_users() const
Adds players and observers into one vector and returns that.
socket_ptr find_user(const simple_wml::string_span &name)
Shortcut to a convenience function for finding a user by name.
MAKE_ENUM(CONTROLLER,(HUMAN,"human")(AI,"ai")(EMPTY,"null")) game(player_connections &player_connections
bool is_member(const socket_ptr player) const
bool all_observers_muted_
size_t current_side() const
bool operator()(const game &g) const
const simple_wml::node::child_list & get_sides_list() const
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
socket_ptr const std::string bool const std::string & replay_save_path
boost::ptr_vector< simple_wml::document > t_history
Replay data.
std::vector< std::string > bans_
bool take_side(const socket_ptr user)
Figures out which side to take and tells that side to the game owner.
bool is_player(const socket_ptr player) const
node * child(const char *name)
node * child(const char *name)
socket_ptr kick_member(const simple_wml::node &kick, const socket_ptr kicker)
Kick a member by name.
socket_ptr current_player() const
bool send_taken_side(simple_wml::document &cfg, const simple_wml::node::child_list::const_iterator side) const
void handle_choice(const simple_wml::node &data, const socket_ptr user)
int last_choice_request_id_
void send_and_record_server_message(const char *message, const socket_ptr exclude=socket_ptr())
Send data to all players in this game except 'exclude'.
std::string username(const socket_ptr pl) const
Returns the name of the user or "(unfound)".
void reset_sides()
calculates the initial value for sides_, side_controllerds_, nsides_
void send_data(simple_wml::document &data, const socket_ptr exclude=socket_ptr(), std::string packet_type="") const
std::vector< CONTROLLER > side_controllers_
simple_wml::node * description() const
const std::string & termination_reason() const
void handle_controller_choice(const simple_wml::node &data)
bool describe_slots()
Set the description to the number of available slots.
socket_ptr ban_user(const simple_wml::node &ban, const socket_ptr banner)
Ban and kick a user by name.
bool controls_side(const std::vector< int > &sides, const socket_ptr player) const
Function which returns true iff 'player' controls any of the sides spcified in 'sides'.
bool registered_users_only() const
void missing_user(socket_ptr socket, const std::string &func) const
Function to log when we don't find a connection in player_info_.
bool is_legal_command(const simple_wml::node &command, const socket_ptr user)
void perform_controller_tweaks()
bool add_player(const socket_ptr player, bool observer=false)
Add a user to the game.
void send_leave_game(socket_ptr user) const
void send_history(const socket_ptr sock) const
socket_ptr owner_
The game host or later owner (if the host left).
static simple_wml::node * starting_pos(simple_wml::node &data)
bool is_observer(const socket_ptr player) const
bool is_owner(const socket_ptr player) const
static const simple_wml::node * starting_pos(const simple_wml::node &data)
void process_whiteboard(simple_wml::document &data, const socket_ptr user)
Handles incoming [whiteboard] data.
std::string list_users(user_vector users, const std::string &func) const
Returns a comma separated list of user names.
multi_index_container< player_record, indexed_by< ordered_unique< tag< socket_t >, BOOST_MULTI_INDEX_CONST_MEM_FUN(player_record, const socket_ptr, socket)>, hashed_unique< tag< name_t >, BOOST_MULTI_INDEX_CONST_MEM_FUN(player_record, const std::string &, name)>, ordered_non_unique< tag< game_t >, BOOST_MULTI_INDEX_CONST_MEM_FUN(player_record, int, game_id)> >> player_connections
std::vector< node * > child_list
void reset_last_synced_context_id()
void record_data(simple_wml::document *data)
side_vector sides_
A vector of side owners.
void notify_new_host()
In case of a host transfer, notify the new host about its status.
void send_and_record_server_message(const std::string &message, const socket_ptr exclude=socket_ptr())
bool disconnect(connection s)
Function to disconnect from a certain host, or close all connections if connection_num is 0...
void load_next_scenario(const socket_ptr user)
A user (player only?) asks for the next scenario to advance to.
void set_description(simple_wml::node *desc)
Functions to set/get the address of the game's summary description as sent to players in the lobby...
void set_password(const std::string &passwd)
void send_server_message_to_all(const char *message, socket_ptr exclude=socket_ptr()) const
size_t current_turn() const
game_is_member(socket_ptr sock)
GLuint const GLchar * name
simple_wml::node * description_
Pointer to the game's description in the games_and_users_list_.
std::string name_
The name of the game.
bool observers_can_chat() const
bool is_current_player(const socket_ptr player) const
bool is_muted_observer(const socket_ptr player) const
void send_data_observers(simple_wml::document &data, const socket_ptr exclude=socket_ptr(), std::string packet_type="") const
std::string replay_save_path_
void send_data_sides(simple_wml::document &data, const simple_wml::string_span &sides, const socket_ptr exclude=socket_ptr(), std::string packet_type="") const
user_vector players_
A vector of players (members owning a side).
std::vector< socket_ptr > user_vector
GLsizei GLenum GLuint GLuint GLsizei char * message
void send_observerjoins(const socket_ptr sock=socket_ptr()) const
Send [observer] tags of all the observers in the game to the user or everyone if none given...
bool all_observers_muted() const
void send_server_message(const std::string &message, socket_ptr sock=socket_ptr(), simple_wml::document *doc=nullptr) const
void process_change_turns_wml(simple_wml::document &data, const socket_ptr user)
Handles incoming [change_turns_wml] data.
void operator=(const game &)
boost::shared_ptr< boost::asio::ip::tcp::socket > socket_ptr
void mute_observer(const simple_wml::node &mute, const socket_ptr muter)
Mute an observer or give a message of all currently muted observers if no name is given...
void send_user_list(const socket_ptr exclude=socket_ptr()) const
Function to send a list of users to all clients.
std::string debug_player_info() const
Helps debugging player and observer lists.
bool end_turn()
Function which should be called every time a player ends their turn (i.e.
void transfer_ai_sides(const socket_ptr player)
void unban_user(const simple_wml::node &unban, const socket_ptr unbanner)
void send_server_message_to_all(const std::string &message, socket_ptr exclude=socket_ptr()) const
Defines the MAKE_ENUM macro.
simple_wml::document level_
The current scenario data.
GLsizei const GLcharARB ** string
void send_muted_observers(const socket_ptr user) const
void mute_all_observers()
bool remove_player(const socket_ptr player, const bool disconnect=false, const bool destruct=false)
Removes a user from the game.
void set_termination_reason(const std::string &reason)
simple_wml::document & level()
The full scenario data.