disallow joining a second game;...

...should fix bug #13252: MP Server: dogs and cats living together,
mass hysteria
This commit is contained in:
Gunter Labes 2009-03-25 18:19:18 +00:00
parent 99015519a0
commit 3523291960
2 changed files with 23 additions and 0 deletions

View file

@ -308,6 +308,14 @@ private:
std::string termination_;
};
struct game_is_member {
game_is_member(network::connection sock) : sock_(sock) {};
bool operator()(const game* g) const { return g->is_owner(sock_) || g->is_member(sock_); }
private:
network::connection sock_;
};
struct game_id_matches {
game_id_matches(int id) : id_(id) {};
bool operator()(const game* g) const { return g->id() == id_; }

View file

@ -1865,6 +1865,21 @@ void server::process_data_lobby(const network::connection sock,
send_doc(games_and_users_list_, sock);
return;
}
const std::vector<wesnothd::game*>::iterator g2 =
std::find_if(games_.begin(),games_.end(), wesnothd::game_is_member(sock));
if (g2 != games_.end()) {
WRN_SERVER << network::ip_address(sock) << "\t" << pl->second.name()
<< "\tattempted to join a second game. He's already in game:\t\""
<< (*g2)->name() << "\" (" << (*g2)->id() << ")." << "(socket: "
<< sock << ")\n";
send_doc(leave_game_doc, sock);
lobby_.send_server_message(("Attempt to join a second game."
" You're already in game: \"" + (*g2)->name() + "\"."
" (You may have to log off and back on to get your client"
" in sync again.)").c_str(), sock);
send_doc(games_and_users_list_, sock);
return;
}
bool joined = (*g)->add_player(sock, observer, admin);
if (!joined) {
WRN_SERVER << network::ip_address(sock) << "\t" << pl->second.name()