wesnothd: add a check to prevent crash from accessing game owner not in player_connections_

This commit is contained in:
loonycyborg 2018-05-05 13:37:16 +03:00
parent c580156716
commit 10ee2b2d29

View file

@ -1528,7 +1528,11 @@ bool game::remove_player(const socket_ptr& player, const bool disconnect, const
// Check whether the host is actually a player and make him one if not.
if(!is_player(owner_)) {
DBG_GAME << "making the owner a player...\n";
player_connections_.find(owner_)->info().set_status(player::PLAYING);
auto owner_iter = player_connections_.find(owner_);
if(owner_iter == player_connections_.end())
ERR_GAME << "game owner " << client_address(owner_) << "is not in player_connections_\n";
else
owner_iter->info().set_status(player::PLAYING);
observers_.erase(std::remove(observers_.begin(), observers_.end(), owner_), observers_.end());
players_.push_back(owner_);
send_observerquit(owner_);