Skip to content

Commit

Permalink
wesnothd: fix prematurely adding new players to games_and_users_list_
Browse files Browse the repository at this point in the history
If dc happens during asio read that would call server::add_player
then a "ghost" player will appear in games_and_users_list_. Fix works by
moving the list update into the handler, it will be called only if read is
successful.

This should prevent issue #2989 unless it has some other mechanism

(cherry-picked from commit 787a1a0)
  • Loading branch information
loonycyborg committed Oct 7, 2018
1 parent 325864d commit 231bb48
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/server/server.cpp
Expand Up @@ -772,11 +772,9 @@ bool server::is_login_allowed(socket_ptr socket, const simple_wml::node* const l
}
}

simple_wml::node& player_cfg = games_and_users_list_.root().add_child("user");

async_send_doc(socket, join_lobby_response_,
std::bind(&server::add_player, this, _1,
wesnothd::player(
async_send_doc(socket, join_lobby_response_, [this, username, registered, version](socket_ptr socket) {
simple_wml::node& player_cfg = games_and_users_list_.root().add_child("user");
add_player(socket, wesnothd::player(
username,
player_cfg,
registered,
Expand All @@ -785,8 +783,8 @@ bool server::is_login_allowed(socket_ptr socket, const simple_wml::node* const l
default_time_period_,
user_handler_ && user_handler_->user_is_moderator(username)
)
)
);
);
});

LOG_SERVER << client_address(socket) << "\t" << username << "\thas logged on"
<< (registered ? " to a registered account" : "") << "\n";
Expand Down

0 comments on commit 231bb48

Please sign in to comment.