send a server message when a player with the same IP...
...as an existing game member enters
This commit is contained in:
parent
ee68d42529
commit
c4ee600465
2 changed files with 24 additions and 2 deletions
|
@ -879,12 +879,12 @@ void game::add_player(const network::connection player, bool observer) {
|
|||
}
|
||||
user->second.mark_available(id_, name_);
|
||||
DBG_GAME << debug_player_info();
|
||||
std::string clones = has_same_ip(network::ip_address(player));
|
||||
bool became_observer = false;
|
||||
if (!started_ && !observer && take_side(user)) {
|
||||
DBG_GAME << "adding player...\n";
|
||||
players_.push_back(player);
|
||||
send_server_message((user->second.name()
|
||||
+ " has joined the game.").c_str(), player);
|
||||
send_and_record_server_message((user->second.name() + " has joined the game.").c_str(), player);
|
||||
} else if (!allow_observers()) {
|
||||
return; //false;
|
||||
} else {
|
||||
|
@ -899,6 +899,10 @@ void game::add_player(const network::connection player, bool observer) {
|
|||
send_data(observer_join, player);
|
||||
}
|
||||
DBG_GAME << debug_player_info();
|
||||
|
||||
if (!clones.empty()) {
|
||||
send_and_record_server_message((user->second.name() + " has the same IP as: " + clones).c_str());
|
||||
}
|
||||
// Send the user the game data.
|
||||
//std::cerr << "SENDING LEVEL {{{" << level_.output() << "}}}\n";
|
||||
simple_wml::string_span level_data = level_.output_compressed();
|
||||
|
@ -1117,6 +1121,23 @@ bool game::is_on_team(const simple_wml::string_span& team, const network::connec
|
|||
return false;
|
||||
}
|
||||
|
||||
std::string game::has_same_ip(const std::string& ip) const {
|
||||
user_vector users = all_game_users();
|
||||
std::string clones;
|
||||
bool first = true;
|
||||
for (user_vector::const_iterator i = users.begin(); i != users.end(); ++i) {
|
||||
if (ip == network::ip_address(*i)) {
|
||||
if (!first) clones += ", ";
|
||||
else first = false;
|
||||
const player_map::const_iterator pl = player_info_->find(*i);
|
||||
if (pl != player_info_->end()) {
|
||||
clones += pl->second.name();
|
||||
}
|
||||
}
|
||||
}
|
||||
return clones;
|
||||
}
|
||||
|
||||
//! Send [observer] tags of all the observers in the game to the user or
|
||||
//! everyone if none given.
|
||||
void game::send_observerjoins(const network::connection sock) const {
|
||||
|
|
|
@ -157,6 +157,7 @@ private:
|
|||
bool is_legal_command(const simple_wml::node& command, bool is_player);
|
||||
//! Function which returns true iff 'player' is on 'team'.
|
||||
bool is_on_team(const simple_wml::string_span& team, const network::connection player) const;
|
||||
std::string has_same_ip(const std::string& ip) const;
|
||||
|
||||
//! Function which should be called every time a player ends their turn
|
||||
//! (i.e. [end_turn] received). This will update the 'turn' attribute for
|
||||
|
|
Loading…
Add table
Reference in a new issue