check whether a player is actually in the game before kicking/banning
remove an assert() on sending to an unknown socket, rather log and return
This commit is contained in:
parent
608cb3d286
commit
5434ce96d1
3 changed files with 14 additions and 7 deletions
|
@ -667,13 +667,14 @@ void send_data(const config& cfg, connection connection_num)
|
|||
LOG_NW << "server socket: " << server_socket << "\ncurrent socket: " << *i << "\n";
|
||||
send_data(cfg,*i);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const connection_map::iterator info = connections.find(connection_num);
|
||||
wassert(info != connections.end());
|
||||
if (info != connections.end()) {
|
||||
WRN_NW << "Warning: socket: " << connection_num << "\tnot found. Not sending...\n";
|
||||
return;
|
||||
}
|
||||
|
||||
network_worker_pool::queue_data(info->second.sock,cfg);
|
||||
}
|
||||
|
|
|
@ -126,8 +126,8 @@ connection receive_data(config& cfg, connection connection_num, int timeout);
|
|||
//! Throws error.
|
||||
void send_data(const config& cfg, connection connection_num=0);
|
||||
|
||||
//! Function to queue data to be sent.
|
||||
//! queue_data(cfg,sock) is equivalent to send_data(cfg,sock,0,QUEUE_ONLY)
|
||||
//! Function to queue data to be sent. (deprecated)
|
||||
//! queue_data(cfg,sock) is equivalent to send_data(cfg,sock)
|
||||
void queue_data(const config& cfg, connection connection_num=0);
|
||||
|
||||
//! Function to send any data that is in a connection's send_queue,
|
||||
|
|
|
@ -717,7 +717,7 @@ void server::process_login(const network::connection sock, const config& data)
|
|||
// Send other players in the lobby the update that the player has joined
|
||||
lobby_players_.send_data(sync_initial_response(),sock);
|
||||
|
||||
WRN_SERVER << network::ip_address(sock) << "\t" << username << "\thas logged on.\n";
|
||||
WRN_SERVER << network::ip_address(sock) << "\t" << username << "\thas logged on. (socket: " << sock << ")\n";
|
||||
|
||||
for(std::vector<game>::iterator g = games_.begin(); g != games_.end(); ++g) {
|
||||
g->send_data_observers(construct_server_message(username + " has logged into the lobby",*g));
|
||||
|
@ -1284,8 +1284,10 @@ void server::process_data_from_player_in_game(const network::connection sock, co
|
|||
break;
|
||||
}
|
||||
}
|
||||
if(pl != players_.end() && pl->first != sock) {
|
||||
// is the player even in this game?
|
||||
if(!g->is_member(pl->first)) return;
|
||||
|
||||
if(pl->first != sock && pl != players_.end()) {
|
||||
if (ban) {
|
||||
network::send_data(construct_server_message("You have been banned", *g), pl->first);
|
||||
g->send_data(construct_server_message(name + " has been banned", *g));
|
||||
|
@ -1317,17 +1319,21 @@ void server::process_data_from_player_in_game(const network::connection sock, co
|
|||
|
||||
// Send all other players in the lobby the update to the lobby
|
||||
lobby_players_.send_data(sync_initial_response(), sock);
|
||||
return;
|
||||
} else if(pl == players_.end()) {
|
||||
network::send_data(construct_server_message("Kick/ban failed: user '" + name + "' not found", *g), sock);
|
||||
return;
|
||||
}
|
||||
} else if(data.child("ban")) {
|
||||
const config& response = construct_server_message(
|
||||
"You cannot ban: not the game host", *g);
|
||||
network::send_data(response,sock);
|
||||
return;
|
||||
} else if(data.child("kick")) {
|
||||
const config& response = construct_server_message(
|
||||
"You cannot kick: not the game host", *g);
|
||||
network::send_data(response,sock);
|
||||
return;
|
||||
}
|
||||
|
||||
config* const turn = data.child("turn");
|
||||
|
|
Loading…
Add table
Reference in a new issue