extend server room class a bit, for future use
This commit is contained in:
parent
69d151a452
commit
d821674817
3 changed files with 50 additions and 14 deletions
|
@ -28,6 +28,16 @@ namespace wesnothd {
|
|||
room::room(const std::string& name)
|
||||
: name_(name)
|
||||
, members_()
|
||||
, persistent_()
|
||||
, topic_()
|
||||
{
|
||||
}
|
||||
|
||||
room::room(const simple_wml::node& wml)
|
||||
: name_(wml.attr("name").to_string())
|
||||
, members_()
|
||||
, persistent_(wml.attr("persistent").to_bool())
|
||||
, topic_(wml.attr("topic").to_string())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -36,6 +46,16 @@ const std::string& room::name() const
|
|||
return name_;
|
||||
}
|
||||
|
||||
bool room::persistent() const
|
||||
{
|
||||
return persistent_;
|
||||
}
|
||||
|
||||
const std::string& room::topic() const
|
||||
{
|
||||
return topic_;
|
||||
}
|
||||
|
||||
bool room::add_player(network::connection player)
|
||||
{
|
||||
if (is_member(player)) {
|
||||
|
@ -47,13 +67,6 @@ bool room::add_player(network::connection player)
|
|||
return true;
|
||||
}
|
||||
|
||||
void room::add_players(const wesnothd::game& game)
|
||||
{
|
||||
foreach (network::connection player, game.all_game_users()) {
|
||||
add_player(player);
|
||||
}
|
||||
}
|
||||
|
||||
void room::remove_player(network::connection player)
|
||||
{
|
||||
const user_vector::iterator itor =
|
||||
|
|
|
@ -31,12 +31,31 @@ class game;
|
|||
class room {
|
||||
public:
|
||||
/**
|
||||
* Construct a room
|
||||
* Construct a room with just a name and default settings
|
||||
*/
|
||||
room(const std::string& name);
|
||||
|
||||
/**
|
||||
* Construct a room from WML
|
||||
*/
|
||||
room(const simple_wml::node& wml);
|
||||
|
||||
/**
|
||||
* The name of this room
|
||||
*/
|
||||
const std::string& name() const;
|
||||
|
||||
/**
|
||||
* Whether this room should be 'persistent', i.e. not deleted when there
|
||||
* are no players within.
|
||||
*/
|
||||
bool persistent() const;
|
||||
|
||||
/**
|
||||
* This room's topic/motd, sent to all joining players
|
||||
*/
|
||||
const std::string& topic() const;
|
||||
|
||||
/**
|
||||
* Return the number of players in this room
|
||||
*/
|
||||
|
@ -44,6 +63,13 @@ public:
|
|||
return members_.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true iif the room is empty
|
||||
*/
|
||||
bool empty() const {
|
||||
return members_.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the members of this room
|
||||
*/
|
||||
|
@ -65,11 +91,6 @@ public:
|
|||
*/
|
||||
bool add_player(network::connection player);
|
||||
|
||||
/**
|
||||
* Add all players from a game into this room
|
||||
*/
|
||||
void add_players(const game& game);
|
||||
|
||||
/**
|
||||
* Leaving the room
|
||||
*/
|
||||
|
@ -113,6 +134,8 @@ public:
|
|||
private:
|
||||
std::string name_;
|
||||
connection_vector members_;
|
||||
bool persistent_;
|
||||
std::string topic_;
|
||||
};
|
||||
|
||||
} //end namespace wesnothd
|
||||
|
|
|
@ -315,7 +315,7 @@ void room_manager::process_room_part(simple_wml::document &data, const player_ma
|
|||
player_exits_room(user->first, r);
|
||||
msg->set_attr_dup("player", user->second.name().c_str());
|
||||
r->send_data(data);
|
||||
if (r->members().empty()) {
|
||||
if (r->empty() && !r->persistent()) {
|
||||
LOG_LOBBY << "Last player left room " << room_name << ". Deleting room.\n";
|
||||
rooms_by_name_.erase(room_name);
|
||||
delete r;
|
||||
|
|
Loading…
Add table
Reference in a new issue