Skip to content

Commit

Permalink
wesnothd: Fix server crash if client is autokicked by registered login
Browse files Browse the repository at this point in the history
  • Loading branch information
loonycyborg committed Oct 27, 2021
1 parent 71422ea commit 8cdf833
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/server/wesnothd/server.cpp
Expand Up @@ -754,7 +754,7 @@ void server::login_client(boost::asio::yield_context yield, SocketPtr socket)
if(const simple_wml::node* const login = login_response->child("login")) {
username = (*login)["username"].to_string();

if(is_login_allowed(socket, login, username, registered, is_moderator)) {
if(is_login_allowed(yield, socket, login, username, registered, is_moderator)) {
break;
} else continue;
}
Expand Down Expand Up @@ -813,7 +813,7 @@ void server::login_client(boost::asio::yield_context yield, SocketPtr socket)
}
}

template<class SocketPtr> bool server::is_login_allowed(SocketPtr socket, const simple_wml::node* const login, const std::string& username, bool& registered, bool& is_moderator)
template<class SocketPtr> bool server::is_login_allowed(boost::asio::yield_context yield, SocketPtr socket, const simple_wml::node* const login, const std::string& username, bool& registered, bool& is_moderator)
{
// Check if the username is valid (all alpha-numeric plus underscore and hyphen)
if(!utils::isvalid_username(username)) {
Expand Down Expand Up @@ -920,6 +920,10 @@ template<class SocketPtr> bool server::is_login_allowed(SocketPtr socket, const
if(registered) {
// If there is already a client using this username kick it
process_command("kick " + p->info().name() + " autokick by registered user", username);
// need to wait for it to process
while(player_connections_.get<name_t>().count(p->info().name()) > 0) {
boost::asio::post(yield);
}
} else {
async_send_error(socket, "The nickname '" + username + "' is already taken.", MP_NAME_TAKEN_ERROR);
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/server/wesnothd/server.hpp
Expand Up @@ -49,7 +49,7 @@ class server : public server_base
void handle_new_client(tls_socket_ptr socket);

template<class SocketPtr> void login_client(boost::asio::yield_context yield, SocketPtr socket);
template<class SocketPtr> bool is_login_allowed(SocketPtr socket, const simple_wml::node* const login, const std::string& username, bool& registered, bool& is_moderator);
template<class SocketPtr> bool is_login_allowed(boost::asio::yield_context yield, SocketPtr socket, const simple_wml::node* const login, const std::string& username, bool& registered, bool& is_moderator);
template<class SocketPtr> bool authenticate(SocketPtr socket, const std::string& username, const std::string& password, bool name_taken, bool& registered);
template<class SocketPtr> void send_password_request(SocketPtr socket, const std::string& msg, const char* error_code = "", bool force_confirmation = false);
bool accepting_connections() const { return !graceful_restart; }
Expand Down

0 comments on commit 8cdf833

Please sign in to comment.