Skip to content

Commit

Permalink
Wesnothd: added a login response, including admin status (#5349)
Browse files Browse the repository at this point in the history
* Wesnothd: added a login response, including admin status

This adds an `is_moderator` key to the [join_lobby] response containing the moderator status.

This is instead of having the server send a message after the login is complete and before the initial gamelist.
Since we wait at the loading screen for the latter (e41534d), this has needed
to be handled here (2b4ae20), but it doesn't make much sense to be handled this
way. Many years ago this message was meant to show up in chat, but after the former change that no longer happened,
(IIRC) and after the latter change it most certainly won't.
  • Loading branch information
Vultraz committed Dec 9, 2020
1 parent 2f5ed53 commit 68e6a2a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 28 deletions.
24 changes: 10 additions & 14 deletions src/game_initialization/multiplayer.cpp
Expand Up @@ -21,8 +21,6 @@
#include "game_config_manager.hpp"
#include "game_initialization/mp_game_utils.hpp"
#include "game_initialization/playcampaign.hpp"
#include "preferences/credentials.hpp"
#include "preferences/game.hpp"
#include "gettext.hpp"
#include "gui/dialogs/loading_screen.hpp"
#include "gui/dialogs/message.hpp"
Expand All @@ -34,18 +32,19 @@
#include "gui/widgets/settings.hpp"
#include "hash.hpp"
#include "log.hpp"
#include "multiplayer_error_codes.hpp"
#include "map_settings.hpp"
#include "multiplayer_error_codes.hpp"
#include "preferences/credentials.hpp"
#include "preferences/game.hpp"
#include "replay.hpp"
#include "resources.hpp"
#include "sound.hpp"
#include "statistics.hpp"
#include "utils/parse_network_address.hpp"
#include "wesnothd_connection.hpp"
#include "resources.hpp"
#include "replay.hpp"

#include <functional>

#include <fstream>
#include <functional>

static lg::log_domain log_mp("mp/main");
#define DBG_MP LOG_STREAM(debug, log_mp)
Expand Down Expand Up @@ -170,12 +169,6 @@ std::pair<std::unique_ptr<wesnothd_connection>, config> open_connection(std::str
throw wesnothd_rejected_client_error(error_message);
}

// The only message we should get here is the admin authentication message.
// It's sent after [join_lobby] and before the initial gamelist.
if(const config& message = data.child("message")) {
preferences::parse_admin_authentication(message["sender"], message["message"]);
}

// Continue if we did not get a direction to login
if(!data.has_child("mustlogin")) {
continue;
Expand Down Expand Up @@ -378,9 +371,12 @@ std::pair<std::unique_ptr<wesnothd_connection>, config> open_connection(std::str
if(!*error) break;
} // end login loop

if(data.has_child("join_lobby")) {
if(const config& join_lobby = data.child("join_lobby")) {
received_join_lobby = true;

// Flag us as authenticated, if applicable...
preferences::set_admin_authentication(join_lobby["is_moderator"].to_bool(false));

gui2::dialogs::loading_screen::progress(loading_stage::download_lobby_data);
}
} while(!received_join_lobby || !received_gamelist);
Expand Down
5 changes: 5 additions & 0 deletions src/preferences/game.cpp
Expand Up @@ -190,6 +190,11 @@ void parse_admin_authentication(const std::string& sender, const std::string& me
}
}

void set_admin_authentication(bool authed)
{
authenticated = authed;
}

admin_authentication_reset::admin_authentication_reset()
{
}
Expand Down
1 change: 1 addition & 0 deletions src/preferences/game.hpp
Expand Up @@ -41,6 +41,7 @@ class acquaintance;

bool is_authenticated();
void parse_admin_authentication(const std::string& sender, const std::string& message);
void set_admin_authentication(bool authed);

/**
* Used to reset is_authenticated flag after disconnecting.
Expand Down
18 changes: 5 additions & 13 deletions src/server/wesnothd/server.cpp
Expand Up @@ -261,7 +261,6 @@ server::server(int port,
, failed_login_buffer_size_()
, version_query_response_("[version]\n[/version]\n", simple_wml::INIT_COMPRESSED)
, login_response_("[mustlogin]\n[/mustlogin]\n", simple_wml::INIT_COMPRESSED)
, join_lobby_response_("[join_lobby]\n[/join_lobby]\n", simple_wml::INIT_COMPRESSED)
, games_and_users_list_("[gamelist]\n[/gamelist]\n", simple_wml::INIT_STATIC)
, metrics_()
, dump_stats_timer_(io_service_)
Expand Down Expand Up @@ -803,7 +802,10 @@ bool server::is_login_allowed(socket_ptr socket, const simple_wml::node* const l
}
}

async_send_doc(socket, join_lobby_response_, [this, username, registered, version, source](socket_ptr socket) {
simple_wml::document join_lobby_response;
join_lobby_response.root().add_child("join_lobby").set_attr("is_moderator", is_moderator ? "yes" : "no");

async_send_doc(socket, join_lobby_response, [this, username, registered, version, source](socket_ptr socket) {
simple_wml::node& player_cfg = games_and_users_list_.root().add_child("user");
add_player(socket, wesnothd::player(
username,
Expand Down Expand Up @@ -831,16 +833,6 @@ bool server::is_login_allowed(socket_ptr socket, const simple_wml::node* const l
}
}

if(is_moderator) {
LOG_SERVER << "Admin automatically recognized: IP: " << client_address(socket) << "\tnick: " << username
<< std::endl;

// This string is parsed by the client!
send_server_message(socket,
"You are now recognized as an administrator. "
"If you no longer want to be automatically authenticated use '/query signout'.", "alert");
}

if(auth_ban.type) {
send_server_message(socket, "You are currently banned by the forum administration.", "alert");
}
Expand Down Expand Up @@ -2143,7 +2135,7 @@ void server::roll_handler(const std::string& issuer_name,
if(parameters.empty()) {
return;
}

int N;
try {
N = std::stoi(parameters);
Expand Down
1 change: 0 additions & 1 deletion src/server/wesnothd/server.hpp
Expand Up @@ -170,7 +170,6 @@ class server : public server_base

simple_wml::document version_query_response_;
simple_wml::document login_response_;
simple_wml::document join_lobby_response_;
simple_wml::document games_and_users_list_;

metrics metrics_;
Expand Down

0 comments on commit 68e6a2a

Please sign in to comment.