The room manager manages the lobby and other rooms in the server, and related client message processing. More...
#include <room_manager.hpp>
Public Types | |
enum | PRIVILEGE_POLICY { PP_EVERYONE, PP_REGISTERED, PP_ADMINS, PP_NOBODY, PP_COUNT } |
Public Member Functions | |
room_manager (player_map &all_players) | |
Room manager constructor. More... | |
~room_manager () | |
Room manager destructor. More... | |
void | load_config (const config &cfg) |
Load settings from the main config file. More... | |
void | read_rooms () |
Reads stored rooms from a file on disk, or returns immediately if load_config was not called before or the storage filename is empty. More... | |
void | write_rooms () |
Writes rooms to the storage file or returns immediately if load_config was not called beforethe storage filename is empty. More... | |
bool | dirty () const |
Dirty flag for rooms – true if there were changes that should be written to disk. More... | |
room * | get_room (const std::string &name) |
Get a room by name, or nullptr if it does not exist. More... | |
bool | room_exists (const std::string &name) const |
room * | create_room (const std::string &name) |
Create room named "name" if it does not exist already. More... | |
room * | get_create_room (const std::string &name, network::connection player) |
Get a room by name or create that room if it does not exist and creating rooms is allowed. More... | |
bool | in_lobby (network::connection player) const |
void | enter_lobby (network::connection player) |
Player-enters-lobby action. More... | |
void | enter_lobby (const game &game) |
All players from a game re-enter the lobby. More... | |
void | exit_lobby (network::connection player) |
Player exits lobby. More... | |
void | remove_player (network::connection player) |
Remove info abut given player from all rooms. More... | |
room * | require_room (const std::string &room_name, const player_map::iterator user, const char *log_string="use") |
Check if the room exists, log failures. More... | |
room * | require_member (const std::string &room_name, const player_map::iterator user, const char *log_string="use") |
Check if the room exists and if the player is a member, log failures. More... | |
void | process_message (simple_wml::document &data, const player_map::iterator user) |
Process a message (chat message) sent to a room. More... | |
void | process_room_join (simple_wml::document &data, const player_map::iterator user) |
Process a player's request to join a room. More... | |
void | process_room_part (simple_wml::document &data, const player_map::iterator user) |
Process a player's request to leave a room. More... | |
void | process_room_query (simple_wml::document &data, const player_map::iterator user) |
Process a general room query. More... | |
const room & | lobby () const |
Lobby convenience accesor. More... | |
Static Public Member Functions | |
static PRIVILEGE_POLICY | pp_from_string (const std::string &str) |
Private Types | |
typedef std::map< std::string, room * > | t_rooms_by_name_ |
Rooms by name. More... | |
typedef std::map < network::connection, std::set< room * > > | t_rooms_by_player_ |
Rooms by player. More... | |
typedef std::map < network::connection, std::set< std::string > > | t_player_stored_rooms_ |
Room names stored for players that have entered a game. More... | |
Private Member Functions | |
void | do_room_join (network::connection player, const std::string &room_name) |
bool | player_enters_room (network::connection player, room *room) |
Adds a player to a room, maintaining internal consistency Will send appropriate error messages to the player. More... | |
void | player_exits_room (network::connection player, room *room) |
Removes a player from a room, maintaining internal consistency. More... | |
void | store_player_rooms (network::connection player) |
Stores the room names (other than lobby) of the given player for future use (rejoin) More... | |
void | unstore_player_rooms (const player_map::iterator user) |
Unstores (rejoins) player's rooms that were previously stored. More... | |
void | unstore_player_rooms (network::connection player) |
Helper function that calls the player_map::iterator version of unstore_player_rooms. More... | |
void | fill_member_list (const room *room, simple_wml::node &root) |
Fill a wml node (message) with members of a room. More... | |
void | fill_room_list (simple_wml::node &root) |
Fill a wml node (message) with a room list. More... | |
Private Attributes | |
player_map & | all_players_ |
Reference to the all players map. More... | |
room * | lobby_ |
The lobby-room, treated separetely. More... | |
t_rooms_by_name_ | rooms_by_name_ |
t_rooms_by_player_ | rooms_by_player_ |
t_player_stored_rooms_ | player_stored_rooms_ |
std::string | filename_ |
Persistent room storage filename. More... | |
bool | compress_stored_rooms_ |
Flag controlling whether to compress the stored rooms or not. More... | |
PRIVILEGE_POLICY | new_room_policy_ |
Policy regarding who can create new rooms. More... | |
bool | dirty_ |
'Dirty' flag with regards to room info that will be stored on disk More... | |
Static Private Attributes | |
static const char *const | lobby_name_ = "lobby" |
The main (lobby) room name. More... | |
The room manager manages the lobby and other rooms in the server, and related client message processing.
The lobby represents players that are on the server, but not in any game.
Definition at line 31 of file room_manager.hpp.
|
private |
Room names stored for players that have entered a game.
Definition at line 225 of file room_manager.hpp.
|
private |
Rooms by name.
Definition at line 217 of file room_manager.hpp.
|
private |
Rooms by player.
Definition at line 221 of file room_manager.hpp.
Enumerator | |
---|---|
PP_EVERYONE | |
PP_REGISTERED | |
PP_ADMINS | |
PP_NOBODY | |
PP_COUNT |
Definition at line 44 of file room_manager.hpp.
wesnothd::room_manager::room_manager | ( | player_map & | all_players | ) |
Room manager constructor.
Definition at line 41 of file room_manager.cpp.
wesnothd::room_manager::~room_manager | ( | ) |
Room manager destructor.
Definition at line 54 of file room_manager.cpp.
References i, rooms_by_name_, and write_rooms().
room * wesnothd::room_manager::create_room | ( | const std::string & | name | ) |
Create room named "name" if it does not exist already.
Definition at line 154 of file room_manager.cpp.
References DBG_LOBBY, room_exists(), and rooms_by_name_.
Referenced by get_create_room(), and read_rooms().
|
inline |
Dirty flag for rooms – true if there were changes that should be written to disk.
Definition at line 75 of file room_manager.hpp.
References dirty_.
|
private |
void wesnothd::room_manager::enter_lobby | ( | network::connection | player | ) |
Player-enters-lobby action.
Will autorejoin "stored" rooms (the ones the player was before enetering a game, for instance)
Definition at line 204 of file room_manager.cpp.
References wesnothd::room::add_player(), lobby_, and unstore_player_rooms().
Referenced by enter_lobby().
All players from a game re-enter the lobby.
Definition at line 210 of file room_manager.cpp.
References wesnothd::game::all_game_users(), and enter_lobby().
void wesnothd::room_manager::exit_lobby | ( | network::connection | player | ) |
Player exits lobby.
Definition at line 217 of file room_manager.cpp.
References i, lobby_, wesnothd::room::remove_player(), rooms_by_player_, and store_player_rooms().
|
private |
Fill a wml node (message) with members of a room.
Definition at line 537 of file room_manager.cpp.
References simple_wml::node::add_child(), all_players_, wesnothd::room::members(), and simple_wml::node::set_attr_dup().
Referenced by process_room_join(), process_room_query(), and unstore_player_rooms().
|
private |
Fill a wml node (message) with a room list.
Definition at line 526 of file room_manager.cpp.
References simple_wml::node::add_child(), wesnothd::room::members(), wesnothd::room::name(), rooms_by_name_, and simple_wml::node::set_attr_dup().
Referenced by process_room_query().
room * wesnothd::room_manager::get_create_room | ( | const std::string & | name, |
network::connection | player | ||
) |
Get a room by name or create that room if it does not exist and creating rooms is allowed.
Definition at line 165 of file room_manager.cpp.
References all_players_, create_room(), get_room(), i, lobby_, new_room_policy_, PP_ADMINS, PP_EVERYONE, PP_REGISTERED, and wesnothd::room::send_server_message().
Referenced by process_room_join(), and unstore_player_rooms().
room * wesnothd::room_manager::get_room | ( | const std::string & | name | ) |
Get a room by name, or nullptr if it does not exist.
Definition at line 139 of file room_manager.cpp.
References i, and rooms_by_name_.
Referenced by get_create_room(), read_rooms(), and require_room().
bool wesnothd::room_manager::in_lobby | ( | network::connection | player | ) | const |
Definition at line 233 of file room_manager.cpp.
References wesnothd::room::is_member(), and lobby_.
Load settings from the main config file.
Definition at line 78 of file room_manager.cpp.
References compress_stored_rooms_, filename_, new_room_policy_, PP_COUNT, and pp_from_string().
|
inline |
|
private |
Adds a player to a room, maintaining internal consistency Will send appropriate error messages to the player.
Definition at line 286 of file room_manager.cpp.
References wesnothd::room::add_player(), wesnothd::room::is_member(), rooms_by_player_, and wesnothd::room::send_server_message().
Referenced by process_room_join(), and unstore_player_rooms().
|
private |
Removes a player from a room, maintaining internal consistency.
Definition at line 298 of file room_manager.cpp.
References wesnothd::room::remove_player(), and rooms_by_player_.
Referenced by process_room_part().
|
static |
Definition at line 64 of file room_manager.cpp.
References PP_ADMINS, PP_COUNT, PP_EVERYONE, PP_NOBODY, and PP_REGISTERED.
Referenced by load_config().
void wesnothd::room_manager::process_message | ( | simple_wml::document & | data, |
const player_map::iterator | user | ||
) |
Process a message (chat message) sent to a room.
Check conditions and resend to other players in the room.
Definition at line 354 of file room_manager.cpp.
References simple_wml::node::attr(), simple_wml::string_span::begin(), simple_wml::node::child(), network::ip_address(), lobby_, lobby_name_, LOG_SERVER, wesnothd::room::logged(), game_logic::msg(), require_member(), simple_wml::document::root(), wesnothd::room::send_data(), wesnothd::room::send_server_message(), simple_wml::node::set_attr_dup(), simple_wml::string_span::size(), simple_wml::string_span::to_string(), and wesnothd::chat_message::truncate_message().
void wesnothd::room_manager::process_room_join | ( | simple_wml::document & | data, |
const player_map::iterator | user | ||
) |
Process a player's request to join a room.
Definition at line 391 of file room_manager.cpp.
References simple_wml::node::attr(), simple_wml::node::child(), fill_member_list(), get_create_room(), game_logic::msg(), player_enters_room(), simple_wml::document::root(), wesnothd::room::send_data(), simple_wml::node::set_attr_dup(), simple_wml::string_span::to_string(), and wesnothd::room::topic().
void wesnothd::room_manager::process_room_part | ( | simple_wml::document & | data, |
const player_map::iterator | user | ||
) |
Process a player's request to leave a room.
Definition at line 412 of file room_manager.cpp.
References simple_wml::node::attr(), simple_wml::node::child(), wesnothd::room::empty(), lobby_, lobby_name_, LOG_LOBBY, game_logic::msg(), wesnothd::room::persistent(), player_exits_room(), require_member(), rooms_by_name_, simple_wml::document::root(), wesnothd::room::send_data(), wesnothd::room::send_server_message(), simple_wml::node::set_attr_dup(), and simple_wml::string_span::to_string().
void wesnothd::room_manager::process_room_query | ( | simple_wml::document & | data, |
const player_map::iterator | user | ||
) |
Process a general room query.
Definition at line 434 of file room_manager.cpp.
References simple_wml::node::add_child(), simple_wml::node::attr(), simple_wml::node::child(), dirty_, simple_wml::string_span::empty(), fill_member_list(), fill_room_list(), lobby_name_, game_logic::msg(), wesnothd::room::persistent(), require_room(), simple_wml::document::root(), wesnothd::room::send_server_message(), simple_wml::node::set_attr(), simple_wml::node::set_attr_dup(), wesnothd::room::set_logged(), wesnothd::room::set_persistent(), wesnothd::room::set_topic(), simple_wml::string_span::to_bool(), simple_wml::string_span::to_string(), wesnothd::room::topic(), and WRN_LOBBY.
void wesnothd::room_manager::read_rooms | ( | ) |
Reads stored rooms from a file on disk, or returns immediately if load_config was not called before or the storage filename is empty.
Definition at line 86 of file room_manager.cpp.
References config::child_range(), compress_stored_rooms_, create_room(), dirty_, ERR_LOBBY, filesystem::file_exists(), filename_, get_room(), filesystem::istream_file(), lobby_, lobby_name_, LOG_LOBBY, wesnothd::room::name(), read(), read_gz(), room_exists(), rooms_by_name_, wesnothd::room::set_logged(), and wesnothd::room::set_persistent().
void wesnothd::room_manager::remove_player | ( | network::connection | player | ) |
Remove info abut given player from all rooms.
Definition at line 238 of file room_manager.cpp.
References i, lobby_, player_stored_rooms_, wesnothd::room::remove_player(), and rooms_by_player_.
room * wesnothd::room_manager::require_member | ( | const std::string & | room_name, |
const player_map::iterator | user, | ||
const char * | log_string = "use" |
||
) |
Check if the room exists and if the player is a member, log failures.
Definition at line 269 of file room_manager.cpp.
References wesnothd::room::is_member(), lobby_, require_room(), wesnothd::room::send_server_message(), and WRN_LOBBY.
Referenced by process_message(), and process_room_part().
room * wesnothd::room_manager::require_room | ( | const std::string & | room_name, |
const player_map::iterator | user, | ||
const char * | log_string = "use" |
||
) |
Check if the room exists, log failures.
Definition at line 253 of file room_manager.cpp.
References get_room(), lobby_, wesnothd::room::send_server_message(), and WRN_LOBBY.
Referenced by process_room_query(), and require_member().
bool wesnothd::room_manager::room_exists | ( | const std::string & | name | ) | const |
name | the room name to check |
Definition at line 149 of file room_manager.cpp.
References rooms_by_name_.
Referenced by create_room(), and read_rooms().
|
private |
Stores the room names (other than lobby) of the given player for future use (rejoin)
Definition at line 304 of file room_manager.cpp.
References i, wesnothd::room::name(), player_stored_rooms_, rooms_by_player_, and floating_point_emulation::detail::store().
Referenced by exit_lobby().
|
private |
Unstores (rejoins) player's rooms that were previously stored.
No action if not stored earlier or no rooms.
Definition at line 329 of file room_manager.cpp.
References simple_wml::node::add_child(), fill_member_list(), get_create_room(), LOG_LOBBY, player_enters_room(), player_stored_rooms_, simple_wml::node::remove_child(), simple_wml::document::root(), wesnothd::room::send_data(), simple_wml::node::set_attr_dup(), and wesnothd::room::topic().
Referenced by enter_lobby(), and unstore_player_rooms().
|
private |
Helper function that calls the player_map::iterator version of unstore_player_rooms.
Definition at line 321 of file room_manager.cpp.
References all_players_, i, and unstore_player_rooms().
void wesnothd::room_manager::write_rooms | ( | ) |
Writes rooms to the storage file or returns immediately if load_config was not called beforethe storage filename is empty.
Definition at line 118 of file room_manager.cpp.
References config::add_child(), compress_stored_rooms_, dirty_, filename_, LOG_LOBBY, filesystem::ostream_file(), wesnothd::room::persistent(), rooms_by_name_, config_writer::write(), wesnothd::room::write(), and writer().
Referenced by ~room_manager().
|
private |
Reference to the all players map.
Definition at line 211 of file room_manager.hpp.
Referenced by fill_member_list(), get_create_room(), and unstore_player_rooms().
|
private |
Flag controlling whether to compress the stored rooms or not.
Definition at line 236 of file room_manager.hpp.
Referenced by load_config(), read_rooms(), and write_rooms().
|
private |
'Dirty' flag with regards to room info that will be stored on disk
Definition at line 246 of file room_manager.hpp.
Referenced by dirty(), process_room_query(), read_rooms(), and write_rooms().
|
private |
Persistent room storage filename.
If empty, rooms are not stored on disk.
Definition at line 231 of file room_manager.hpp.
Referenced by load_config(), read_rooms(), and write_rooms().
|
private |
The lobby-room, treated separetely.
Definition at line 214 of file room_manager.hpp.
Referenced by enter_lobby(), exit_lobby(), get_create_room(), in_lobby(), lobby(), process_message(), process_room_part(), read_rooms(), remove_player(), require_member(), and require_room().
|
staticprivate |
The main (lobby) room name.
Definition at line 251 of file room_manager.hpp.
Referenced by process_message(), process_room_part(), process_room_query(), and read_rooms().
|
private |
Policy regarding who can create new rooms.
Definition at line 241 of file room_manager.hpp.
Referenced by get_create_room(), and load_config().
|
private |
Definition at line 226 of file room_manager.hpp.
Referenced by remove_player(), store_player_rooms(), and unstore_player_rooms().
|
private |
Definition at line 218 of file room_manager.hpp.
Referenced by create_room(), fill_room_list(), get_room(), process_room_part(), read_rooms(), room_exists(), write_rooms(), and ~room_manager().
|
private |
Definition at line 222 of file room_manager.hpp.
Referenced by exit_lobby(), player_enters_room(), player_exits_room(), remove_player(), and store_player_rooms().