The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
wesnothd::room_manager Class Reference

The room manager manages the lobby and other rooms in the server, and related client message processing. More...

#include <room_manager.hpp>

Inheritance diagram for wesnothd::room_manager:
Inheritance graph

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...
 
roomget_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
 
roomcreate_room (const std::string &name)
 Create room named "name" if it does not exist already. More...
 
roomget_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...
 
roomrequire_room (const std::string &room_name, const player_map::iterator user, const char *log_string="use")
 Check if the room exists, log failures. More...
 
roomrequire_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 roomlobby () 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_mapall_players_
 Reference to the all players map. More...
 
roomlobby_
 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...
 

Detailed Description

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.

Member Typedef Documentation

Room names stored for players that have entered a game.

Definition at line 225 of file room_manager.hpp.

Rooms by name.

Definition at line 217 of file room_manager.hpp.

Rooms by player.

Definition at line 221 of file room_manager.hpp.

Member Enumeration Documentation

Enumerator
PP_EVERYONE 
PP_REGISTERED 
PP_ADMINS 
PP_NOBODY 
PP_COUNT 

Definition at line 44 of file room_manager.hpp.

Constructor & Destructor Documentation

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().

Member Function Documentation

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().

bool wesnothd::room_manager::dirty ( ) const
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_.

void wesnothd::room_manager::do_room_join ( network::connection  player,
const std::string room_name 
)
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().

void wesnothd::room_manager::enter_lobby ( const game game)

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().

void wesnothd::room_manager::fill_member_list ( const room room,
simple_wml::node root 
)
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().

void wesnothd::room_manager::fill_room_list ( simple_wml::node root)
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.

Returns
a valid pointer to a room or nullptr if the room did not exist and could not be created.

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
Returns
true iif the player is in the lobby

Definition at line 233 of file room_manager.cpp.

References wesnothd::room::is_member(), and lobby_.

void wesnothd::room_manager::load_config ( const config cfg)

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().

const room& wesnothd::room_manager::lobby ( ) const
inline

Lobby convenience accesor.

Definition at line 165 of file room_manager.hpp.

References lobby_.

bool wesnothd::room_manager::player_enters_room ( network::connection  player,
wesnothd::room room 
)
private

Adds a player to a room, maintaining internal consistency Will send appropriate error messages to the player.

Returns
true iif the operation was successful, false otherwise

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().

void wesnothd::room_manager::player_exits_room ( network::connection  player,
wesnothd::room room 
)
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().

room_manager::PRIVILEGE_POLICY wesnothd::room_manager::pp_from_string ( const std::string str)
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 
)
void wesnothd::room_manager::process_room_join ( simple_wml::document data,
const player_map::iterator  user 
)
void wesnothd::room_manager::process_room_part ( simple_wml::document data,
const player_map::iterator  user 
)
void wesnothd::room_manager::process_room_query ( simple_wml::document data,
const player_map::iterator  user 
)
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.

Returns
non-nullptr iff the room exists and the player is a member

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.

Returns
non-nullptr iff the room exists and the player is a member

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
Parameters
namethe room name to check
Returns
true iif the room existst

Definition at line 149 of file room_manager.cpp.

References rooms_by_name_.

Referenced by create_room(), and read_rooms().

void wesnothd::room_manager::store_player_rooms ( network::connection  player)
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().

void wesnothd::room_manager::unstore_player_rooms ( const player_map::iterator  user)
private
void wesnothd::room_manager::unstore_player_rooms ( network::connection  player)
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().

Member Data Documentation

player_map& wesnothd::room_manager::all_players_
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().

bool wesnothd::room_manager::compress_stored_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().

bool wesnothd::room_manager::dirty_
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().

std::string wesnothd::room_manager::filename_
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().

room* wesnothd::room_manager::lobby_
private
const char *const wesnothd::room_manager::lobby_name_ = "lobby"
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().

PRIVILEGE_POLICY wesnothd::room_manager::new_room_policy_
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().

t_player_stored_rooms_ wesnothd::room_manager::player_stored_rooms_
private

Definition at line 226 of file room_manager.hpp.

Referenced by remove_player(), store_player_rooms(), and unstore_player_rooms().

t_rooms_by_name_ wesnothd::room_manager::rooms_by_name_
private
t_rooms_by_player_ wesnothd::room_manager::rooms_by_player_
private

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