implemented feature to tell observers when a new player has arrived in the lobby

This commit is contained in:
Dave White 2004-07-18 23:21:15 +00:00
parent 799810a178
commit 6062b614d2
3 changed files with 28 additions and 0 deletions

View File

@ -359,6 +359,15 @@ void game::send_data_team(const config& data, const std::string& team, network::
} }
} }
void game::send_data_observers(const config& data)
{
for(std::vector<network::connection>::const_iterator i = players_.begin(); i != players_.end(); ++i) {
if(is_observer(*i)) {
network::queue_data(data,*i);
}
}
}
void game::record_data(const config& data) void game::record_data(const config& data)
{ {
history_.append(data); history_.append(data);

View File

@ -47,6 +47,8 @@ public:
void send_data(const config& data, network::connection exclude=0); void send_data(const config& data, network::connection exclude=0);
void send_data_team(const config& data, const std::string& team, network::connection exclude=0); void send_data_team(const config& data, const std::string& team, network::connection exclude=0);
void send_data_observers(const config& data);
void record_data(const config& data); void record_data(const config& data);
//the full scenario data //the full scenario data

View File

@ -26,6 +26,18 @@ config construct_error(const std::string& msg)
return cfg; return cfg;
} }
config construct_system_message(const std::string& message)
{
config turn;
config& cmd = turn.add_child("turn");
config& cfg = cmd.add_child("command");
config& msg = cfg.add_child("speak");
msg["description"] = "system";
msg["message"] = message;
return turn;
}
class server class server
{ {
public: public:
@ -171,6 +183,11 @@ void server::run()
std::cerr << "'" << username << "' (" << network::ip_address(sock) << ") has logged on\n"; std::cerr << "'" << username << "' (" << network::ip_address(sock) << ") has logged on\n";
const config msg(construct_system_message(username + " has logged into the lobby"));
for(std::vector<game>::iterator g = games_.begin(); g != games_.end(); ++g) {
g->send_data_observers(msg);
}
} else if(lobby_players_.is_member(sock)) { } else if(lobby_players_.is_member(sock)) {
const config* const create_game = data.child("create_game"); const config* const create_game = data.child("create_game");
if(create_game != NULL) { if(create_game != NULL) {