properly disallow observers to join unobservable games
send observer join even though the client will forget about it anyway once the game starts.. (fixes bug #10355, unslottable observers)
This commit is contained in:
parent
e240e1a4e7
commit
096509cb8b
3 changed files with 21 additions and 10 deletions
|
@ -666,7 +666,9 @@ void game::add_player(const network::connection player, const bool observer) {
|
|||
if (human_sides > players_.size()){
|
||||
DBG_GAME << "adding player...\n";
|
||||
players_.push_back(player);
|
||||
} else{
|
||||
} else if (!allow_observers_) {
|
||||
return; //false;
|
||||
} else {
|
||||
DBG_GAME << "adding observer...\n";
|
||||
observers_.push_back(player);
|
||||
}
|
||||
|
@ -676,9 +678,6 @@ void game::add_player(const network::connection player, const bool observer) {
|
|||
network::send_data(level_, player);
|
||||
//if the game has already started, we add the player as an observer
|
||||
if(started_) {
|
||||
if(!allow_observers_) {
|
||||
return;
|
||||
}
|
||||
//tell this player that the game has started
|
||||
network::queue_data(config("start_game"), player);
|
||||
// Send the player the history of the game to-date.
|
||||
|
@ -696,11 +695,11 @@ void game::add_player(const network::connection player, const bool observer) {
|
|||
}
|
||||
}
|
||||
}
|
||||
config observer_join;
|
||||
observer_join.add_child("observer").values["name"] = user->second.name();
|
||||
// Send observer join to everyone except the new observer.
|
||||
send_data(observer_join, player);
|
||||
}
|
||||
config observer_join;
|
||||
observer_join.add_child("observer").values["name"] = user->second.name();
|
||||
// Send observer join to everyone except the new observer.
|
||||
send_data(observer_join, player);
|
||||
}
|
||||
|
||||
void game::remove_player(const network::connection player, const bool notify_creator) {
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
bool is_owner(const network::connection player) const { return (player == owner_); }
|
||||
bool is_member(const network::connection player) const
|
||||
{ return is_player(player) || is_observer(player); }
|
||||
bool allow_observers() const { return allow_observers_; }
|
||||
bool is_observer(const network::connection player) const;
|
||||
bool is_muted_observer(const network::connection player) const;
|
||||
bool all_observers_muted() const { return all_observers_muted_; }
|
||||
|
|
|
@ -853,8 +853,7 @@ void server::process_data_from_player_in_lobby(const network::connection sock, c
|
|||
"Attempt to join unknown game."), sock);
|
||||
network::send_data(games_and_users_list_, sock);
|
||||
return;
|
||||
}
|
||||
if (g->player_is_banned(sock)) {
|
||||
} else if (g->player_is_banned(sock)) {
|
||||
DBG_SERVER << network::ip_address(sock) << "\tReject banned player: "
|
||||
<< pl->second.name() << "\tfrom game:\t\"" << g->name()
|
||||
<< "\" (" << id << ").\n";
|
||||
|
@ -863,6 +862,15 @@ void server::process_data_from_player_in_lobby(const network::connection sock, c
|
|||
"You are banned from this game."), sock);
|
||||
network::send_data(games_and_users_list_, sock);
|
||||
return;
|
||||
} else if (observer && !g->allow_observers()){
|
||||
WRN_SERVER << network::ip_address(sock) << "\t" << pl->second.name()
|
||||
<< "\tattempted to observe game:\t\"" << g->name() << "\" ("
|
||||
<< id << ") which doesn't allow observers.\n";
|
||||
network::send_data(config("leave_game"), sock);
|
||||
network::send_data(lobby_.construct_server_message(
|
||||
"Attempt to observe a game that doesn't allow observers."), sock);
|
||||
network::send_data(games_and_users_list_, sock);
|
||||
return;
|
||||
}
|
||||
LOG_SERVER << network::ip_address(sock) << "\t" << pl->second.name()
|
||||
<< "\tjoined game:\t\"" << g->name()
|
||||
|
@ -931,6 +939,9 @@ void server::process_data_from_player_in_game(const network::connection sock, co
|
|||
<< pl->second.name() << ". (socket:" << sock << ")\n";
|
||||
return;
|
||||
}
|
||||
// Ignore client side pings for now.
|
||||
const string_map::const_iterator ping = data.values.find("ping");
|
||||
if (ping != data.values.end()) return;
|
||||
|
||||
// If this is data describing the level for a game.
|
||||
if (data.child("side") != NULL) {
|
||||
|
|
Loading…
Add table
Reference in a new issue