47 #include <boost/algorithm/string.hpp>
48 #include <boost/scope_exit.hpp>
66 #define ERR_SERVER LOG_STREAM(err, log_server)
69 #define WRN_SERVER LOG_STREAM(warn, log_server)
72 #define LOG_SERVER LOG_STREAM(info, log_server)
73 #define DBG_SERVER LOG_STREAM(debug, log_server)
76 #define ERR_CONFIG LOG_STREAM(err, log_config)
77 #define WRN_CONFIG LOG_STREAM(warn, log_config)
79 using namespace std::chrono_literals;
90 if(!out.
child(
"gamelist_diff")) {
103 assert(!children.empty());
106 index = children.size() - 1;
109 assert(
index <
static_cast<int>(children.size()));
116 const char* gamelist,
121 if(!out.
child(
"gamelist_diff")) {
133 const auto itor = std::find(children.begin(), children.end(),
remove);
135 if(itor == children.end()) {
139 const int index = std::distance(children.begin(), itor);
149 const char* gamelist,
154 if(!out.
child(
"gamelist_diff")) {
166 const auto itor = std::find(children.begin(), children.end(), item);
168 if(itor == children.end()) {
175 const int index = std::distance(children.begin(), itor);
191 std::ostringstream out;
193 <<
" logged on for " <<
lg::format_timespan(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() -
player.login_time));
197 const std::string
denied_msg =
"You're not allowed to execute this command.";
199 "Available commands are: adminmsg <msg>,"
200 " ban <mask> <time> <reason>, bans [deleted] [<ipmask>], clones,"
201 " dul|deny_unregistered_login [yes|no], kick <mask> [<reason>],"
202 " k[ick]ban <mask> <time> <reason>, help, games, metrics,"
203 " [lobby]msg <message>, motd [<message>],"
204 " pm|privatemsg <nickname> <message>, requests, roll <sides>, sample, searchlog <mask>,"
205 " signout, stats, status [<mask>], stopgame <nick> [<reason>], unban <ipmask>\n"
206 "Specific strings (those not in between <> like the command names)"
207 " are case insensitive.";
209 server::server(
int port,
211 const std::string& config_file)
216 , user_handler_(nullptr)
217 , die_(static_cast<unsigned>(std::time(nullptr)))
222 , config_file_(config_file)
224 , accepted_versions_()
225 , redirected_versions_()
227 , disallowed_names_()
234 , default_max_messages_(0)
235 , default_time_period_(0)
236 , concurrent_connections_(0)
237 , graceful_restart(false)
240 , max_ip_log_size_(0)
241 , deny_unregistered_login_(false)
242 , save_replays_(false)
243 , replay_save_path_()
244 , allow_remote_shutdown_(false)
247 , failed_login_limit_()
248 , failed_login_ban_()
249 , failed_login_buffer_size_()
254 , dump_stats_timer_(io_service_)
255 , tournaments_timer_(io_service_)
257 , timer_(io_service_)
258 , lan_server_timer_(io_service_)
259 , dummy_player_timer_(io_service_)
260 , dummy_player_timer_interval_(30)
277 WRN_SERVER <<
"SIGHUP caught, reloading config";
290 if(
games().empty()) {
291 process_command(
"msg All games ended. Shutting down now. Reconnect to the new server instance.",
"system");
322 if(res != 0 && errno != EEXIST) {
326 int fifo = open(
input_path_.c_str(), O_RDWR | O_NONBLOCK);
328 LOG_SERVER <<
"opened fifo at '" <<
input_path_ <<
"'. Server commands may be written to this file.";
338 std::cout << error.message() << std::endl;
344 std::getline(is, cmd);
351 if(!cmd.empty() && cmd.at(0) ==
'+') {
354 <<
"[/admin_command_response]";
366 #define SETUP_HANDLER(name, function) \
367 cmd_handlers_[name] = std::bind(function, this, \
368 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
412 return configuration;
419 read(configuration, *stream);
425 return configuration;
432 #warning No FIFODIR set
433 #define FIFODIR "/var/run/wesnothd"
435 const std::string fifo_path
436 = (
cfg_[
"fifo_path"].
empty() ? std::string(
FIFODIR) +
"/socket" : std::string(
cfg_[
"fifo_path"]));
463 for(
const std::string& source :
utils::split(
cfg_[
"client_sources"].str())) {
468 if(
cfg_[
"disallow_names"].empty()) {
499 const std::string& versions =
cfg_[
"versions_accepted"];
500 if(versions.empty() ==
false) {
516 for(
const std::string& version :
utils::split(proxy[
"version"])) {
532 ERR_SERVER <<
"The server id must be set when database support is used";
544 if(
cfg_[
"dummy_player_count"].to_int() > 0) {
545 for(
int i = 0;
i <
cfg_[
"dummy_player_count"].to_int();
i++) {
552 dummy_user.
set_attr_dup(
"name", (
"player"+std::to_string(
i)).c_str());
556 if(
cfg_[
"dummy_player_timer_interval"].to_int() > 0) {
569 std::size_t connections = 0;
571 if(
player.client_ip() == ip) {
599 ERR_SERVER <<
"Error waiting for dump stats timer: " << ec.message();
603 <<
"\tnumber_of_games = " <<
games().size()
617 ERR_SERVER <<
"Error waiting for dummy player timer: " << ec.message();
660 ERR_SERVER <<
"Error waiting for tournament refresh timer: " << ec.message();
671 boost::asio::spawn(
io_service_, [socket,
this](boost::asio::yield_context yield) {
login_client(yield, socket); }
672 #if BOOST_VERSION >= 108000
673 , [](std::exception_ptr
e) {
if (
e) std::rethrow_exception(
e); }
680 boost::asio::spawn(
io_service_, [socket,
this](boost::asio::yield_context yield) {
login_client(yield, socket); }
681 #if BOOST_VERSION >= 108000
682 , [](std::exception_ptr
e) {
if (
e) std::rethrow_exception(
e); }
687 template<
class SocketPtr>
695 std::string client_version, client_source;
698 client_version = std::string { version_str_span.
begin(), version_str_span.
end() };
701 client_source = std::string { source_str_span.
begin(), source_str_span.
end() };
709 <<
":\ttelling them to log in.";
718 <<
":\tredirecting them to " << redirect_version.second[
"host"] <<
":"
719 << redirect_version.second[
"port"];
722 for(
const auto& attr : redirect_version.second.attribute_range()) {
723 redirect.set_attr_dup(attr.first.c_str(), attr.second.str().c_str());
732 <<
":\trejecting them";
747 std::string username;
748 bool registered, is_moderator;
755 username = (*login)[
"username"].to_string();
757 if(
is_login_allowed(yield, socket, login, username, registered, is_moderator)) {
780 std::tie(new_player, inserted) =
player_connections_.insert(player_connections::value_type(socket, player_data));
781 assert(inserted &&
"unexpected duplicate username");
784 join_lobby_response.
root().
add_child(
"join_lobby").
set_attr(
"is_moderator", is_moderator ?
"yes" :
"no");
785 join_lobby_response.
root().
child(
"join_lobby")->
set_attr_dup(
"profile_url_prefix",
"https://r.wesnoth.org/u");
789 [
this, socket, new_player](boost::asio::yield_context yield) {
handle_player(yield, socket, new_player); }
790 #if BOOST_VERSION >= 108000
791 , [](std::exception_ptr
e) {
if (
e) std::rethrow_exception(
e); }
796 << (registered ?
" to a registered account" :
"");
798 std::shared_ptr<game> last_sent;
800 auto g_ptr = record.get_game();
801 if(g_ptr != last_sent) {
803 g_ptr->send_server_message_to_all(username +
" has logged into the lobby");
823 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)
828 "The nickname '" + username +
"' contains invalid "
829 "characters. Only alpha-numeric characters, underscores and hyphens are allowed.",
836 if(username.size() > 20) {
837 async_send_error(socket,
"The nickname '" + username +
"' is too long. Nicks must be 20 characters or less.",
846 async_send_error(socket,
"The nickname '" + username +
"' is reserved and cannot be used by players",
859 if(!
authenticate(socket, username, (*login)[
"password"].to_string(), name_taken, registered))
865 "The nickname '" + username +
"' is not registered. This server disallows unregistered nicknames.",
880 std::string ban_type_desc;
881 std::string ban_reason;
882 const char* msg_numeric;
883 std::string ban_duration = std::to_string(auth_ban.
duration.count());
885 switch(auth_ban.
type) {
887 ban_type_desc =
"account";
889 ban_reason =
"a ban has been issued on your user account.";
892 ban_type_desc =
"IP address";
894 ban_reason =
"a ban has been issued on your IP address.";
897 ban_type_desc =
"email address";
899 ban_reason =
"a ban has been issued on your email address.";
902 ban_type_desc =
"<unknown ban type>";
904 ban_reason = ban_type_desc;
907 ban_reason +=
" (" + ban_duration +
")";
910 LOG_SERVER <<
log_address(socket) <<
"\t" << username <<
"\tis banned by user_handler (" << ban_type_desc
914 async_send_error(socket,
"You are banned from this server: " + ban_reason, msg_numeric, {{
"duration", ban_duration}});
917 async_send_error(socket,
"You are banned from this server: " + ban_reason, msg_numeric);
921 LOG_SERVER <<
log_address(socket) <<
"\t" << username <<
"\tis banned by user_handler (" << ban_type_desc
922 <<
"), " <<
"ignoring due to moderator flag";
929 process_command(
"kick " + username +
" autokick by registered user", username);
932 boost::asio::post(yield);
941 send_server_message(socket,
"You are currently banned by the forum administration.",
"alert");
948 SocketPtr socket,
const std::string& username,
const std::string& password,
bool name_taken,
bool& registered)
964 "The nickname '" + username +
"' is inactive. You cannot claim ownership of this "
965 "nickname until you activate your account via email or ask an administrator to do it for you.",
968 const std::string salt =
user_handler_->extract_salt(username);
971 "Even though your nickname is registered on this server you "
972 "cannot log in due to an error in the hashing algorithm. "
973 "Logging into your forum account on https://forums.wesnoth.org "
974 "may fix this problem.");
977 const std::string hashed_password =
hash_password(password, salt, username);
980 if(password.empty()) {
985 "The nickname '" + username +
"' is registered on this server."
986 "\n\nWARNING: There is already a client using this username, "
987 "logging in will cause that client to be kicked!",
997 if(hashed_password.empty()) {
1002 else if(!(
user_handler_->login(username, hashed_password))) {
1003 const auto steady_now = std::chrono::steady_clock::now();
1029 "Maximum login attempts exceeded",
"automatic",
"", username);
1034 "The password you provided for the nickname '" + username +
"' was incorrect.",
1040 <<
"Login attempt with incorrect password for nickname '" << username <<
"'.";
1054 const std::string&
msg,
1055 const char* error_code,
1056 bool force_confirmation)
1060 e.set_attr_dup(
"message",
msg.c_str());
1061 e.set_attr(
"password_request",
"yes");
1062 e.set_attr(
"force_confirmation", force_confirmation ?
"yes" :
"no");
1064 if(*error_code !=
'\0') {
1065 e.set_attr(
"error_code", error_code);
1076 BOOST_SCOPE_EXIT_ALL(
this, &
player) {
1084 if(!
motd_.empty()) {
1106 if(doc->child(
"refresh_lobby")) {
1153 int offset = request->attr(
"offset").to_int();
1158 if(request->has_attr(
"search_player") && request->attr(
"search_player").to_string() !=
"") {
1159 std::string player_name = request->attr(
"search_player").to_string();
1164 player_id = player_ptr->info().config_address()->attr(
"forum_id").to_int();
1168 std::string search_game_name = request->attr(
"search_game_name").to_string();
1169 int search_content_type = request->attr(
"search_content_type").to_int();
1170 std::string search_content = request->attr(
"search_content").to_string();
1171 LOG_SERVER <<
"Querying game history requested by player `" <<
player->info().
name() <<
"` for player id `" << player_id <<
"`."
1172 <<
"Searching for game name `" << search_game_name <<
"`, search content type `" << search_content_type <<
"`, search content `" << search_content <<
"`.";
1173 user_handler_->async_get_and_send_game_history(
io_service_, *
this,
player, player_id, offset, search_game_name, search_content_type, search_content);
1181 if((whisper[
"receiver"].empty()) || (whisper[
"message"].empty())) {
1184 "message=\"Invalid number of arguments\"\n"
1185 "sender=\"server\"\n"
1194 whisper.set_attr_dup(
"sender",
player->
name().c_str());
1211 whisper.copy_into(trunc_whisper);
1223 const std::string command(query[
"type"].to_string());
1224 std::ostringstream response;
1226 const std::string& query_help_msg =
1227 "Available commands are: adminmsg <msg>, help, games, metrics,"
1228 " motd, requests, roll <sides>, sample, stats, status, version, wml.";
1231 if(command ==
"status") {
1234 command.compare(0, 8,
"adminmsg") == 0 ||
1235 command.compare(0, 6,
"report") == 0 ||
1236 command ==
"games" ||
1237 command ==
"metrics" ||
1238 command ==
"motd" ||
1239 command.compare(0, 7,
"version") == 0 ||
1240 command ==
"requests" ||
1241 command.compare(0, 4,
"roll") == 0 ||
1242 command ==
"sample" ||
1243 command ==
"stats" ||
1249 if(command ==
"signout") {
1253 response <<
"You are no longer recognized as an administrator.";
1258 LOG_SERVER <<
"Admin Command: type: " << command <<
"\tIP: " << iter->client_ip()
1263 }
else if(command ==
"help" || command.empty()) {
1264 response << query_help_msg;
1265 }
else if(command ==
"admin" || command.compare(0, 6,
"admin ") == 0) {
1272 if(command.size() >= 6) {
1273 passwd = command.substr(6);
1277 LOG_SERVER <<
"New Admin recognized: IP: " << iter->client_ip() <<
"\tnick: " <<
player.
name();
1280 response <<
"You are now recognized as an administrator.";
1286 WRN_SERVER <<
"FAILED Admin attempt with password: '" << passwd <<
"'\tIP: " << iter->client_ip()
1288 response <<
"Error: wrong password";
1291 response <<
"Error: unrecognized query: '" << command <<
"'\n" << query_help_msg;
1306 if(nickserv.
child(
"info")) {
1308 std::string res =
user_handler_->user_info((*nickserv.
child(
"info"))[
"name"].to_string());
1312 "There was an error looking up the details of the user '"
1313 + (*nickserv.
child(
"info"))[
"name"].to_string() +
"'. "
1314 +
" The error message was: " +
e.message,
"error"
1324 if(user->info().is_message_flooding()) {
1326 "Warning: you are sending too many messages too fast. Your message has not been relayed.",
"error");
1331 message.set_attr_dup(
"sender", user->name().c_str());
1334 message.copy_into(trunc_message);
1340 LOG_SERVER << user->client_ip() <<
"\t<" << user->name()
1343 LOG_SERVER << user->client_ip() <<
"\t<" << user->name() <<
"> " <<
msg;
1356 "This server is shutting down. You aren't allowed to make new games. Please "
1357 "reconnect to the new server.",
"error");
1363 const std::string game_name = create_game[
"name"].to_string();
1364 const std::string game_password = create_game[
"password"].to_string();
1365 const std::string initial_bans = create_game[
"ignored"].to_string();
1368 <<
"\tcreates a new game: \"" << game_name <<
"\".";
1381 DBG_SERVER <<
"initial bans: " << initial_bans;
1382 if(initial_bans !=
"") {
1386 if(game_password.empty() ==
false) {
1387 g.set_password(game_password);
1402 assert(gamelist !=
nullptr);
1415 const std::size_t
index = std::distance(
games.begin(),
g);
1419 LOG_SERVER <<
"Could not find game (" << game_ptr->
id() <<
", " << game_ptr->
db_id() <<
") to delete in games_and_users_list_.";
1430 const std::string& password =
join[
"password"].to_string();
1431 int game_id =
join[
"id"].to_int();
1435 std::shared_ptr<game>
g;
1437 g = g_iter->get_game();
1443 <<
"\tattempted to join unknown game:\t" << game_id <<
".";
1448 }
else if(!
g->level_init()) {
1450 <<
"\tattempted to join uninitialized game:\t\"" <<
g->name() <<
"\" (" << game_id <<
").";
1459 <<
"\tReject banned player: " <<
player->info().
name()
1460 <<
"\tfrom game:\t\"" <<
g->name() <<
"\" (" << game_id <<
").";
1465 }
else if(!
g->password_matches(password)) {
1467 <<
"\tattempted to join game:\t\"" <<
g->name() <<
"\" (" << game_id <<
") with bad password";
1477 <<
"\tattempted to observe game:\t\"" <<
g->name() <<
"\" (" << game_id
1478 <<
") which doesn't allow observers.";
1482 "Attempt to observe a game that doesn't allow observers. (You probably joined the "
1483 "game shortly after it filled up.)",
"error");
1492 g->describe_slots();
1500 if(diff1 || diff2) {
1511 game&
g = *(
p->get_game());
1512 std::weak_ptr<game> g_ptr{
p->get_game()};
1515 if(
data.child(
"snapshot") ||
data.child(
"scenario")) {
1516 if(!
g.is_owner(
p)) {
1526 if(!
g.level_init()) {
1528 <<
g.id() <<
", " <<
g.db_id() <<
").";
1532 assert(gamelist !=
nullptr);
1535 g.level().root().copy_into(desc);
1541 <<
g.name() <<
"\" (" <<
g.id() <<
", " <<
g.db_id() <<
") without a 'multiplayer' child.";
1543 g.set_description(&desc);
1547 "The scenario data is missing the [multiplayer] tag which contains the "
1548 "game settings. Game aborted.",
"error");
1552 g.set_description(&desc);
1556 <<
g.name() <<
"\" (" <<
g.id() <<
", " <<
g.db_id() <<
") although it's already initialized.";
1570 if(!
data[
"mp_shroud"].to_bool()) {
1575 if(!
e->attr(
"require_era").to_bool(
true)) {
1576 desc.
set_attr(
"require_era",
"no");
1580 if(
s[
"require_scenario"].to_bool(
false)) {
1581 desc.
set_attr(
"require_scenario",
"yes");
1590 desc.
child(
"modification")->
set_attr_dup(
"require_modification", m->attr(
"require_modification"));
1594 g.level().swap(
data);
1599 g.update_side_data();
1612 }
else if(!
g.level_init()) {
1614 <<
" while the scenario wasn't yet initialized."
1619 if(!
g.is_owner(
p)) {
1623 if(!
g.level_init()) {
1625 <<
"\tsent [store_next_scenario] in game:\t\"" <<
g.name() <<
"\" (" <<
g.id()
1626 <<
", " <<
g.db_id() <<
") while the scenario is not yet initialized.";
1636 g.reset_last_synced_context_id();
1640 scenario->copy_into(
g.level().root());
1643 if(
g.description() ==
nullptr) {
1644 ERR_SERVER <<
p->client_ip() <<
"\tERROR: \"" <<
g.name() <<
"\" (" <<
g.id()
1645 <<
", " <<
g.db_id() <<
") is initialized but has no description_.";
1656 <<
g.name() <<
"\" (" <<
g.id() <<
", " <<
g.db_id() <<
") without a 'multiplayer' child.";
1661 "The scenario data is missing the [multiplayer] tag which contains the game "
1662 "settings. Game aborted.",
"error");
1669 desc.
set_attr_dup(
"map_data",
s[
"mp_shroud"].to_bool() ?
"" :
s[
"map_data"]);
1672 if(!
e->attr(
"require_era").to_bool(
true)) {
1673 desc.
set_attr(
"require_era",
"no");
1677 if(
s[
"require_scenario"].to_bool(
false)) {
1678 desc.
set_attr(
"require_scenario",
"yes");
1684 g.send_data(notify_next_scenario,
p);
1690 }
else if(
data.child(
"load_next_scenario")) {
1691 g.load_next_scenario(
p);
1693 }
else if(
data.child(
"start_game")) {
1694 if(!
g.is_owner(
p)) {
1699 g.perform_controller_tweaks();
1711 std::set<std::string> primary_keys;
1712 for(
const auto& addon : m.
children(
"addon")) {
1713 for(
const auto& content : addon->children(
"content")) {
1714 std::string key =
uuid_+
"-"+std::to_string(
g.db_id())+
"-"+content->attr(
"type").to_string()+
"-"+content->attr(
"id").to_string()+
"-"+addon->attr(
"id").to_string();
1715 if(primary_keys.count(key) == 0) {
1716 primary_keys.emplace(key);
1717 unsigned long long rows_inserted =
user_handler_->db_insert_game_content_info(
uuid_,
g.db_id(), content->attr(
"type").to_string(), content->attr(
"name").to_string(), content->attr(
"id").to_string(), addon->attr(
"id").to_string(), addon->attr(
"version").to_string());
1718 if(rows_inserted == 0) {
1719 WRN_SERVER <<
"Did not insert content row for [addon] data with uuid '" <<
uuid_ <<
"', game ID '" <<
g.db_id() <<
"', type '" << content->attr(
"type").to_string() <<
"', and content ID '" << content->attr(
"id").to_string() <<
"'";
1724 if(m.
children(
"addon").size() == 0) {
1725 WRN_SERVER <<
"Game content info missing for game with uuid '" <<
uuid_ <<
"', game ID '" <<
g.db_id() <<
"', named '" <<
g.name() <<
"'";
1728 user_handler_->db_insert_game_info(
uuid_,
g.db_id(),
server_id_,
g.name(),
g.is_reload(), m[
"observer"].to_bool(), !m[
"private_replay"].to_bool(),
g.has_password());
1731 for(
unsigned side_index = 0; side_index < sides.size(); ++side_index) {
1734 std::string version;
1753 std::vector<std::string> leaders;
1755 if(side.
attr(
"type") !=
"") {
1760 if(
unit->attr(
"canrecruit") ==
"yes") {
1761 leaders.emplace_back(
unit->attr(
"type").to_string());
1765 for(
const auto leader : side.
children(
"leader")) {
1766 leaders.emplace_back(leader->attr(
"type").to_string());
1769 user_handler_->db_insert_game_player_info(
uuid_,
g.db_id(), side[
"player_id"].to_string(), side[
"side"].to_int(), side[
"is_host"].to_bool(), side[
"faction"].to_string(), version, source, side[
"current_player"].to_string(),
utils::join(leaders));
1776 }
else if(
data.child(
"leave_game")) {
1777 if(
g.remove_player(
p)) {
1780 auto description =
g.description();
1786 if(
auto gStrong = g_ptr.lock()) {
1787 gStrong->describe_slots();
1795 if(diff1 || diff2) {
1806 if(!
g.is_owner(
p)) {
1810 g.level().root().apply_diff(*scenario_diff);
1814 g.update_side_data();
1817 if(
g.describe_slots()) {
1824 }
else if(
data.child(
"change_faction")) {
1829 g.transfer_side_control(
p, *change);
1830 if(
g.describe_slots()) {
1836 }
else if(
data.child(
"muteall")) {
1837 if(!
g.is_owner(
p)) {
1838 g.send_server_message(
"You cannot mute: not the game host.",
p);
1842 g.mute_all_observers();
1846 g.mute_observer(*mute,
p);
1850 g.unmute_observer(*unmute,
p);
1853 }
else if(
data.child(
"kick") ||
data.child(
"ban")) {
1854 bool ban = (
data.child(
"ban") !=
nullptr);
1856 ?
g.ban_user(*
data.child(
"ban"),
p)
1857 :
g.kick_member(*
data.child(
"kick"),
p)};
1861 if(
g.describe_slots()) {
1878 g.unban_user(*unban,
p);
1882 if(!
g.is_player(
p)) {
1886 if((*
info)[
"type"] ==
"termination") {
1887 g.set_termination_reason((*
info)[
"condition"].to_string());
1888 if((*
info)[
"condition"].to_string() ==
"out of sync") {
1889 g.send_and_record_server_message(
player.
name() +
" reports out of sync errors.");
1897 }
else if(
data.child(
"turn")) {
1901 if(
g.process_turn(
data,
p)) {
1906 }
else if(
data.child(
"whiteboard")) {
1907 g.process_whiteboard(
data,
p);
1909 }
else if(
data.child(
"change_turns_wml")) {
1910 g.process_change_turns_wml(
data,
p);
1914 g.handle_choice(*sch,
p);
1916 }
else if(
data.child(
"message")) {
1917 g.process_message(
data,
p);
1919 }
else if(
data.child(
"stop_updates")) {
1924 data.child(
"error") ||
1925 data.child(
"side_secured") ||
1926 data.root().has_attr(
"failed") ||
1927 data.root().has_attr(
"side")
1933 <<
" in game: \"" <<
g.name() <<
"\" (" <<
g.id() <<
", " <<
g.db_id() <<
")\n"
1941 msg.set_attr(
"sender",
"server");
1942 msg.set_attr_dup(
"message", message.c_str());
1943 msg.set_attr_dup(
"type",
type.c_str());
1950 utils::visit([](
auto&& socket) {
1952 socket->async_shutdown([socket](...) {});
1953 const char buffer[] =
"";
1954 async_write(*socket, boost::asio::buffer(buffer), [socket](...) { socket->lowest_layer().close(); });
1956 socket->lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_receive);
1963 std::string ip = iter->client_ip();
1965 const std::shared_ptr<game>
g = iter->get_game();
1966 bool game_ended =
false;
1968 game_ended =
g->remove_player(iter,
true,
false);
1972 const std::size_t
index =
1973 std::distance(users.begin(), std::find(users.begin(), users.end(), iter->info().config_address()));
1983 LOG_SERVER << ip <<
"\t" << iter->info().name() <<
"\thas logged off";
1987 user_handler_->db_update_logout(iter->info().get_login_id());
1993 i->log_off = std::chrono::system_clock::now();
2054 if(issuer_name ==
"*socket*" && !query.empty() && query.at(0) ==
'+') {
2058 auto issuer_end = std::find(query.begin(), query.end(),
':');
2060 std::string issuer(query.begin() + 1, issuer_end);
2061 if(!issuer.empty()) {
2062 issuer_name =
"+" + issuer +
"+";
2063 query = std::string(issuer_end + 1, query.end());
2068 const auto i = std::find(query.begin(), query.end(),
' ');
2071 const std::string command =
utf8::lowercase(std::string(query.begin(),
i));
2073 std::string parameters = (
i == query.end() ?
"" : std::string(
i + 1, query.end()));
2076 std::ostringstream out;
2080 out <<
"Command '" << command <<
"' is not recognized.\n" <<
help_msg;
2082 const cmd_handler& handler = handler_itor->second;
2084 handler(issuer_name, query, parameters, &out);
2085 }
catch(
const std::bad_function_call& ex) {
2086 ERR_SERVER <<
"While handling a command '" << command
2087 <<
"', caught a std::bad_function_call exception.";
2089 out <<
"An internal server error occurred (std::bad_function_call) while executing '" << command
2097 std::string
msg =
"While handling a command, caught an invalid utf8 exception: ";
2100 return (
msg +
'\n');
2106 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2108 assert(out !=
nullptr);
2115 if(parameters ==
"now") {
2127 "msg The server is shutting down. You may finish your games but can't start new ones. Once all "
2128 "games have ended the server will exit.",
2132 *out <<
"Server is doing graceful shut down.";
2137 const std::string& ,
2139 std::ostringstream* out)
2141 assert(out !=
nullptr);
2149 *out <<
"No restart_command configured! Not restarting.";
2160 "msg The server has been restarted. You may finish current games but can't start new ones and "
2161 "new players can't join this (old) server instance. (So if a player of your game disconnects "
2162 "you have to save, reconnect and reload the game on the new server instance. It is actually "
2163 "recommended to do that right away.)",
2167 *out <<
"New server started.";
2172 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2174 assert(out !=
nullptr);
2176 if(parameters.empty()) {
2179 }
else if(issuer_name !=
"*socket*") {
2186 *out <<
"Sampling turned off.";
2193 const std::string& ,
2195 std::ostringstream* out)
2197 assert(out !=
nullptr);
2202 const std::string& ,
2204 std::ostringstream* out)
2206 assert(out !=
nullptr);
2212 const std::string& ,
2214 std::ostringstream* out)
2216 assert(out !=
nullptr);
2221 const std::string& ,
2223 std::ostringstream* out)
2225 assert(out !=
nullptr);
2230 const std::string& ,
2231 std::string& parameters,
2232 std::ostringstream* out)
2234 assert(out !=
nullptr);
2235 if(parameters.empty()) {
2241 N = std::stoi(parameters);
2242 }
catch(
const std::invalid_argument&) {
2243 *out <<
"The number of die sides must be a number!";
2245 }
catch(
const std::out_of_range&) {
2246 *out <<
"The number of sides is too big for the die!";
2251 *out <<
"The die cannot have less than 1 side!";
2254 std::uniform_int_distribution<int> dice_distro(1, N);
2255 std::string value = std::to_string(dice_distro(
die_));
2257 *out <<
"You rolled a die [1 - " + parameters +
"] and got a " + value +
".";
2264 auto g_ptr = player_ptr->get_game();
2266 g_ptr->send_server_message_to_all(issuer_name +
" rolled a die [1 - " + parameters +
"] and got a " + value +
".",
player_connections_.project<0>(player_ptr));
2268 *out <<
" (The result is shown to others only in a game.)";
2273 const std::string& ,
2275 std::ostringstream* out)
2277 assert(out !=
nullptr);
2282 const std::string& ,
2284 std::ostringstream* out)
2286 assert(out !=
nullptr);
2291 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2293 assert(out !=
nullptr);
2295 if(parameters.empty()) {
2296 *out <<
"You must type a message.";
2300 const std::string& sender = issuer_name;
2301 const std::string& message = parameters;
2303 << (message.find(
"/me ") == 0 ? std::string(message.begin() + 3, message.end()) +
">" :
"> " + message);
2307 msg.set_attr_dup(
"sender", (
"admin message from " + sender).c_str());
2308 msg.set_attr_dup(
"message", message.c_str());
2318 bool is_admin =
false;
2328 *out <<
"Your report has been logged and sent to the server administrators. Thanks!";
2332 *out <<
"Your report has been logged and sent to " <<
n <<
" online administrators. Thanks!";
2336 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2338 assert(out !=
nullptr);
2340 auto first_space = std::find(parameters.begin(), parameters.end(),
' ');
2341 if(first_space == parameters.end()) {
2342 *out <<
"You must name a receiver.";
2346 const std::string& sender = issuer_name;
2347 const std::string receiver(parameters.begin(), first_space);
2349 std::string message(first_space + 1, parameters.end());
2352 if(message.empty()) {
2353 *out <<
"You must type a message.";
2361 msg.set_attr_dup(
"sender", (
"server message from " + sender).c_str());
2362 msg.set_attr_dup(
"message", message.c_str());
2365 if(receiver !=
player.info().
name().c_str()) {
2370 *out <<
"Message to " << receiver <<
" successfully sent.";
2374 *out <<
"No such nick: " << receiver;
2378 const std::string& ,
2379 std::string& parameters,
2380 std::ostringstream* out)
2382 assert(out !=
nullptr);
2384 if(parameters.empty()) {
2385 *out <<
"You must type a message.";
2392 << (parameters.find(
"/me ") == 0
2393 ? std::string(parameters.begin() + 3, parameters.end()) +
">"
2394 :
"> " + parameters);
2396 *out <<
"message '" << parameters <<
"' relayed to players";
2400 const std::string& ,
2401 std::string& parameters,
2402 std::ostringstream* out)
2404 assert(out !=
nullptr);
2406 if(parameters.empty()) {
2407 *out <<
"You must type a message.";
2413 << (parameters.find(
"/me ") == 0
2414 ? std::string(parameters.begin() + 3, parameters.end()) +
">"
2415 :
"> " + parameters);
2417 *out <<
"message '" << parameters <<
"' relayed to players";
2421 const std::string& ,
const std::string& , std::string& parameters, std::ostringstream* out)
2423 assert(out !=
nullptr);
2425 if(parameters.empty()) {
2432 *out <<
"Player " << parameters <<
" is using wesnoth " <<
player.info().
version();
2437 *out <<
"Player '" << parameters <<
"' not found.";
2441 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2443 assert(out !=
nullptr);
2445 *out <<
"STATUS REPORT for '" << parameters <<
"'";
2446 bool found_something =
false;
2452 parameters =
player.client_ip();
2453 found_something =
true;
2458 if(!found_something) {
2466 const bool match_ip = ((std::count(parameters.begin(), parameters.end(),
'.') >= 1) || (std::count(parameters.begin(), parameters.end(),
':') >= 1));
2468 if(parameters.empty() || parameters ==
"*" ||
2472 found_something =
true;
2477 if(!found_something) {
2478 *out <<
"\nNo match found. You may want to check with 'searchlog'.";
2483 const std::string& ,
2485 std::ostringstream* out)
2487 assert(out !=
nullptr);
2488 *out <<
"CLONES STATUS REPORT";
2490 std::set<std::string> clones;
2493 if(clones.find(it->client_ip()) != clones.end()) {
2499 if(it->client_ip() == clone->client_ip()) {
2502 clones.insert(it->client_ip());
2511 if(clones.empty()) {
2512 *out << std::endl <<
"No clones found.";
2517 const std::string& ,
2518 std::string& parameters,
2519 std::ostringstream* out)
2521 assert(out !=
nullptr);
2524 if(parameters.empty()) {
2529 std::string mask = parameters.substr(7);
2537 ERR_SERVER <<
"While handling bans, caught an invalid utf8 exception: " <<
e.what();
2542 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2544 assert(out !=
nullptr);
2547 auto first_space = std::find(parameters.begin(), parameters.end(),
' ');
2549 if(first_space == parameters.end()) {
2554 auto second_space = std::find(first_space + 1, parameters.end(),
' ');
2555 const std::string target(parameters.begin(), first_space);
2556 const std::string duration(first_space + 1, second_space);
2564 if(second_space == parameters.end()) {
2568 std::string reason(second_space + 1, parameters.end());
2571 if(reason.empty()) {
2572 *out <<
"You need to give a reason for the ban.";
2576 std::string dummy_group;
2580 if(std::count(target.begin(), target.end(),
'.') >= 1) {
2583 *out <<
ban_manager_.
ban(target, parsed_time, reason, issuer_name, dummy_group);
2593 const std::string ip =
player.client_ip();
2594 *out <<
ban_manager_.
ban(ip, parsed_time, reason, issuer_name, dummy_group, target);
2599 *out <<
"Nickname mask '" << target <<
"' did not match, no bans set.";
2605 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2607 assert(out !=
nullptr);
2610 auto first_space = std::find(parameters.begin(), parameters.end(),
' ');
2611 if(first_space == parameters.end()) {
2616 auto second_space = std::find(first_space + 1, parameters.end(),
' ');
2617 const std::string target(parameters.begin(), first_space);
2618 const std::string duration(first_space + 1, second_space);
2626 if(second_space == parameters.end()) {
2630 std::string reason(second_space + 1, parameters.end());
2633 if(reason.empty()) {
2634 *out <<
"You need to give a reason for the ban.";
2638 std::string dummy_group;
2639 std::vector<player_iterator> users_to_kick;
2643 if(std::count(target.begin(), target.end(),
'.') >= 1) {
2646 *out <<
ban_manager_.
ban(target, parsed_time, reason, issuer_name, dummy_group);
2650 users_to_kick.push_back(
player);
2662 const std::string ip =
player->client_ip();
2663 *out <<
ban_manager_.
ban(ip, parsed_time, reason, issuer_name, dummy_group, target);
2664 users_to_kick.push_back(
player);
2669 *out <<
"Nickname mask '" << target <<
"' did not match, no bans set.";
2673 for(
auto user : users_to_kick) {
2674 *out <<
"\nKicked " << user->info().name() <<
" (" << user->client_ip() <<
").";
2675 utils::visit([
this,reason](
auto&& socket) {
async_send_error(socket,
"You have been banned. Reason: " + reason); }, user->socket());
2681 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2683 assert(out !=
nullptr);
2686 auto first_space = std::find(parameters.begin(), parameters.end(),
' ');
2687 if(first_space == parameters.end()) {
2692 auto second_space = std::find(first_space + 1, parameters.end(),
' ');
2693 const std::string target(parameters.begin(), first_space);
2695 std::string group = std::string(first_space + 1, second_space);
2696 first_space = second_space;
2697 second_space = std::find(first_space + 1, parameters.end(),
' ');
2699 const std::string duration(first_space + 1, second_space);
2707 if(second_space == parameters.end()) {
2711 std::string reason(second_space + 1, parameters.end());
2714 if(reason.empty()) {
2715 *out <<
"You need to give a reason for the ban.";
2721 if(std::count(target.begin(), target.end(),
'.') >= 1) {
2724 *out <<
ban_manager_.
ban(target, parsed_time, reason, issuer_name, group);
2734 const std::string ip =
player.client_ip();
2735 *out <<
ban_manager_.
ban(ip, parsed_time, reason, issuer_name, group, target);
2740 *out <<
"Nickname mask '" << target <<
"' did not match, no bans set.";
2746 const std::string& ,
2747 std::string& parameters,
2748 std::ostringstream* out)
2750 assert(out !=
nullptr);
2752 if(parameters.empty()) {
2753 *out <<
"You must enter an ipmask to unban.";
2761 const std::string& ,
2762 std::string& parameters,
2763 std::ostringstream* out)
2765 assert(out !=
nullptr);
2767 if(parameters.empty()) {
2768 *out <<
"You must enter an ipmask to ungban.";
2776 const std::string& ,
2777 std::string& parameters,
2778 std::ostringstream* out)
2780 assert(out !=
nullptr);
2782 if(parameters.empty()) {
2783 *out <<
"You must enter a mask to kick.";
2787 auto i = std::find(parameters.begin(), parameters.end(),
' ');
2788 const std::string kick_mask = std::string(parameters.begin(),
i);
2789 const std::string kick_message = (
i == parameters.end()
2790 ?
"You have been kicked."
2791 :
"You have been kicked. Reason: " + std::string(
i + 1, parameters.end()));
2793 bool kicked =
false;
2796 const bool match_ip = (std::count(kick_mask.begin(), kick_mask.end(),
'.') >= 1);
2798 std::vector<player_iterator> users_to_kick;
2803 users_to_kick.push_back(
player);
2807 for(
const auto&
player : users_to_kick) {
2814 *out <<
"Kicked " <<
player->
name() <<
" (" <<
player->client_ip() <<
"). '"
2815 << kick_message <<
"'";
2817 utils::visit([
this, &kick_message](
auto&& socket) {
async_send_error(socket, kick_message); },
player->socket());
2822 *out <<
"No user matched '" << kick_mask <<
"'.";
2827 const std::string& ,
2828 std::string& parameters,
2829 std::ostringstream* out)
2831 assert(out !=
nullptr);
2833 if(parameters.empty()) {
2834 if(!
motd_.empty()) {
2835 *out <<
"Message of the day:\n" <<
motd_;
2838 *out <<
"No message of the day set.";
2844 *out <<
"Message of the day set to: " <<
motd_;
2848 const std::string& ,
2849 std::string& parameters,
2850 std::ostringstream* out)
2852 assert(out !=
nullptr);
2854 if(parameters.empty()) {
2855 *out <<
"You must enter a mask to search for.";
2859 *out <<
"IP/NICK LOG for '" << parameters <<
"'";
2863 const bool match_ip = (std::count(parameters.begin(), parameters.end(),
'.') >= 1);
2866 bool found_something =
false;
2869 const std::string& username =
i.nick;
2870 const std::string& ip =
i.ip;
2875 found_something =
true;
2881 *out <<
"\n'" << username <<
"' @ " << ip
2887 if(!found_something) {
2888 *out <<
"\nNo match found.";
2901 const std::string& ,
2902 std::string& parameters,
2903 std::ostringstream* out)
2905 assert(out !=
nullptr);
2908 if(parameters.empty()) {
2916 ERR_SERVER <<
"While handling dul (deny unregistered logins), caught an invalid utf8 exception: " <<
e.what();
2921 const std::string& ,
2922 std::string& parameters,
2923 std::ostringstream* out)
2925 const std::string nick = parameters.substr(0, parameters.find(
' '));
2926 const std::string reason = parameters.length() > nick.length()+1 ? parameters.substr(nick.length()+1) :
"";
2930 std::shared_ptr<game>
g =
player->get_game();
2932 *out <<
"Player '" << nick <<
"' is in game with id '" <<
g->id() <<
", " <<
g->db_id() <<
"' named '" <<
g->name() <<
"'. Ending game for reason: '" << reason <<
"'...";
2935 *out <<
"Player '" << nick <<
"' is not currently in a game.";
2938 *out <<
"Player '" << nick <<
"' is not currently logged in.";
2949 std::vector<decltype(range_pair)::first_type> range_vctor;
2951 for(
auto it = range_pair.first; it != range_pair.second; ++it) {
2952 range_vctor.push_back(it);
2953 it->info().mark_available();
2959 ERR_SERVER <<
"ERROR: delete_game(): Could not find user in players_.";
2966 for(
const auto& it : range_vctor) {
2973 for(
const auto& it : range_vctor) {
2977 leave_game_doc_reason.
child(
"leave_game")->
set_attr_dup(
"reason", reason.c_str());
2999 bool keep_alive =
false;
3001 srand(
static_cast<unsigned>(std::time(
nullptr)));
3003 std::string config_file;
3012 for(
int arg = 1; arg != argc; ++arg) {
3013 const std::string val(argv[arg]);
3018 if((val ==
"--config" || val ==
"-c") && arg + 1 != argc) {
3019 config_file = argv[++arg];
3020 }
else if(val ==
"--verbose" || val ==
"-v") {
3022 }
else if(val ==
"--dump-wml" || val ==
"-w") {
3024 }
else if(val.substr(0, 6) ==
"--log-") {
3025 std::size_t
p = val.find(
'=');
3026 if(
p == std::string::npos) {
3031 std::string
s = val.substr(6,
p - 6);
3036 }
else if(
s ==
"warning") {
3038 }
else if(
s ==
"info") {
3040 }
else if(
s ==
"debug") {
3047 while(
p != std::string::npos) {
3048 std::size_t q = val.find(
',',
p + 1);
3049 s = val.substr(
p + 1, q == std::string::npos ? q : q - (
p + 1));
3058 }
else if((val ==
"--port" || val ==
"-p") && arg + 1 != argc) {
3059 port = atoi(argv[++arg]);
3060 }
else if(val ==
"--keepalive") {
3062 }
else if(val ==
"--help" || val ==
"-h") {
3063 std::cout <<
"usage: " << argv[0]
3064 <<
" [-dvwV] [-c path] [-p port]\n"
3065 <<
" -c, --config <path> Tells wesnothd where to find the config file to use.\n"
3066 <<
" -d, --daemon Runs wesnothd as a daemon.\n"
3067 <<
" -h, --help Shows this usage message.\n"
3068 <<
" --log-<level>=<domain1>,<domain2>,...\n"
3069 <<
" sets the severity level of the debug domains.\n"
3070 <<
" 'all' can be used to match any debug domain.\n"
3071 <<
" Available levels: error, warning, info, debug.\n"
3072 <<
" -p, --port <port> Binds the server to the specified port.\n"
3073 <<
" --keepalive Enable TCP keepalive.\n"
3074 <<
" -v --verbose Turns on more verbose logging.\n"
3075 <<
" -V, --version Returns the server version.\n"
3076 <<
" -w, --dump-wml Print all WML sent to clients to stdout.\n";
3078 }
else if(val ==
"--version" || val ==
"-V") {
3081 }
else if(val ==
"--daemon" || val ==
"-d") {
3083 ERR_SERVER <<
"Running as a daemon is not supported on this platform";
3086 const pid_t pid = fork();
3088 ERR_SERVER <<
"Could not fork and run as a daemon";
3090 }
else if(pid > 0) {
3091 std::cout <<
"Started wesnothd as a daemon with process id " << pid <<
"\n";
3097 }
else if(val ==
"--request_sample_frequency" && arg + 1 != argc) {
int main(int argc, char **argv)
A config object defines a single node in a WML file, with access to child nodes.
child_itors child_range(config_key_type key)
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
A class to handle the non-SQL logic for connecting to the phpbb forum database.
severity get_severity() const
std::ostream & requests(std::ostream &out) const
std::ostream & games(std::ostream &out) const
void game_terminated(const std::string &reason)
Base class for implementing servers that use gzipped-WML network protocol.
std::string hash_password(const std::string &pw, const std::string &salt, const std::string &username)
Handles hashing the password provided by the player before comparing it to the hashed password in the...
boost::asio::signal_set sighup_
boost::asio::streambuf admin_cmd_
void async_send_error(SocketPtr socket, const std::string &msg, const char *error_code="", const info_table &info={})
std::unique_ptr< simple_wml::document > coro_receive_doc(SocketPtr socket, boost::asio::yield_context yield)
Receive WML document from a coroutine.
boost::asio::ip::tcp::acceptor acceptor_v4_
void async_send_doc_queued(SocketPtr socket, simple_wml::document &doc)
High level wrapper for sending a WML document.
void coro_send_doc(SocketPtr socket, simple_wml::document &doc, boost::asio::yield_context yield)
Send a WML document from within a coroutine.
void async_send_warning(SocketPtr socket, const std::string &msg, const char *warning_code="", const info_table &info={})
boost::asio::io_service io_service_
boost::asio::posix::stream_descriptor input_
void load_tls_config(const config &cfg)
boost::asio::ip::tcp::acceptor acceptor_v6_
node & set_attr_dup(const char *key, const char *value)
static std::string stats()
node * child(const char *name)
const string_span & attr(const char *key) const
void remove_child(const char *name, std::size_t index)
const child_list & children(const char *name) const
node & set_attr_int(const char *key, int value)
node * child(const char *name)
std::vector< node * > child_list
node & add_child(const char *name)
node & set_attr(const char *key, const char *value)
node & add_child_at(const char *name, std::size_t index)
void copy_into(node &n) const
node & set_attr_dup(const char *key, const char *value)
std::string to_string() const
const char * begin() const
This class represents a single unit of a specific type.
An interface class to handle nick registration To activate it put a [user_handler] section into the s...
@ BAN_EMAIL
Account email address ban.
@ BAN_USER
User account/name ban.
Thrown by operations encountering invalid UTF-8 data.
Represents version numbers.
std::string str() const
Serializes the version number into string form.
std::string ban(const std::string &ip, const utils::optional< std::chrono::system_clock::time_point > &end_time, const std::string &reason, const std::string &who_banned, const std::string &group, const std::string &nick="")
void list_bans(std::ostringstream &out, const std::string &mask="*")
void unban(std::ostringstream &os, const std::string &ip, bool immediate_write=true)
std::pair< bool, utils::optional< std::chrono::system_clock::time_point > > parse_time(const std::string &duration, std::chrono::system_clock::time_point start_time) const
Parses the given duration and adds it to *time except if the duration is '0' or 'permanent' in which ...
void unban_group(std::ostringstream &os, const std::string &group)
const std::string & get_ban_help() const
std::string is_ip_banned(const std::string &ip)
void list_deleted_bans(std::ostringstream &out, const std::string &mask="*") const
void load_config(const config &)
static simple_wml::node * starting_pos(simple_wml::node &data)
The non-const version.
simple_wml::node * description() const
int db_id() const
This ID is not reused between scenarios of MP campaigns.
int id() const
This ID is reused between scenarios of MP campaigns.
const std::string & termination_reason() const
Provides the reason the game was ended.
std::string get_replay_filename()
void set_game(std::shared_ptr< game > new_game)
const std::shared_ptr< game > get_game() const
const std::string & version() const
const simple_wml::node * config_address() const
void set_moderator(bool moderator)
const std::string & name() const
bool is_moderator() const
const std::string & source() const
void send_to_lobby(simple_wml::document &data, utils::optional< player_iterator > exclude={})
std::unique_ptr< user_handler > user_handler_
const std::string config_file_
boost::asio::steady_timer dummy_player_timer_
void handle_message(player_iterator player, simple_wml::node &message)
void searchlog_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
std::vector< std::string > disallowed_names_
void clones_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void ban_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void start_dummy_player_updates()
std::string input_path_
server socket/fifo.
void unban_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
std::map< std::string, config > proxy_versions_
void handle_sighup(const boost::system::error_code &error, int signal_number)
int dummy_player_timer_interval_
void stats_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void delete_game(int, const std::string &reason="")
void refresh_tournaments(const boost::system::error_code &ec)
std::string recommended_version_
void gban_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void pm_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
std::function< void(const std::string &, const std::string &, std::string &, std::ostringstream *)> cmd_handler
void adminmsg_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void start_tournaments_timer()
std::string replay_save_path_
void handle_query(player_iterator player, simple_wml::node &query)
void handle_player_in_game(player_iterator player, simple_wml::document &doc)
std::string restart_command
void lobbymsg_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
bool ip_exceeds_connection_limit(const std::string &ip) const
std::chrono::seconds failed_login_ban_
void handle_graceful_timeout(const boost::system::error_code &error)
void cleanup_game(game *)
void handle_whisper(player_iterator player, simple_wml::node &whisper)
bool is_login_allowed(boost::asio::yield_context yield, SocketPtr socket, const simple_wml::node *const login, const std::string &username, bool ®istered, bool &is_moderator)
void handle_new_client(socket_ptr socket)
void status_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
std::string announcements_
std::deque< connection_log > ip_log_
void bans_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void kick_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void dul_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void handle_join_game(player_iterator player, simple_wml::node &join)
std::deque< login_log >::size_type failed_login_buffer_size_
void wml_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void send_server_message(SocketPtr socket, const std::string &message, const std::string &type)
void handle_player(boost::asio::yield_context yield, SocketPtr socket, player_iterator player)
player_connections player_connections_
simple_wml::document games_and_users_list_
void help_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void requests_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void dump_stats(const boost::system::error_code &ec)
void remove_player(player_iterator player)
boost::asio::steady_timer timer_
void handle_read_from_fifo(const boost::system::error_code &error, std::size_t bytes_transferred)
simple_wml::document login_response_
boost::asio::steady_timer tournaments_timer_
std::string is_ip_banned(const std::string &ip)
std::set< std::string > client_sources_
bool player_is_in_game(player_iterator player) const
void abort_lan_server_timer()
void handle_lan_server_shutdown(const boost::system::error_code &error)
bool authenticate(SocketPtr socket, const std::string &username, const std::string &password, bool name_taken, bool ®istered)
std::string admin_passwd_
void motd_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void load_config()
Parse the server config into local variables.
bool deny_unregistered_login_
std::vector< std::string > accepted_versions_
std::chrono::seconds lan_server_
void dummy_player_updates(const boost::system::error_code &ec)
void handle_create_game(player_iterator player, simple_wml::node &create_game)
void send_server_message_to_lobby(const std::string &message, utils::optional< player_iterator > exclude={})
void kickban_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void send_server_message_to_all(const std::string &message, utils::optional< player_iterator > exclude={})
void handle_nickserv(player_iterator player, simple_wml::node &nickserv)
std::string process_command(std::string cmd, std::string issuer_name)
Process commands from admins and users.
void login_client(boost::asio::yield_context yield, SocketPtr socket)
void stopgame(const std::string &, const std::string &, std::string &, std::ostringstream *)
std::deque< login_log > failed_logins_
std::size_t default_max_messages_
std::size_t max_ip_log_size_
void restart_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void msg_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
boost::asio::steady_timer lan_server_timer_
void shut_down_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
std::map< std::string, config > redirected_versions_
void metrics_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
std::map< std::string, cmd_handler > cmd_handlers_
void send_to_player(player_iterator player, simple_wml::document &data)
void update_game_in_lobby(const game &g, utils::optional< player_iterator > exclude={})
wesnothd::ban_manager ban_manager_
config read_config() const
Read the server config from file 'config_file_'.
boost::asio::steady_timer dump_stats_timer_
void handle_player_in_lobby(player_iterator player, simple_wml::document &doc)
std::vector< std::string > tor_ip_list_
void roll_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void games_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
std::deque< std::shared_ptr< game > > games() const
simple_wml::document version_query_response_
void version_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
std::size_t concurrent_connections_
void send_password_request(SocketPtr socket, const std::string &msg, const char *error_code="", bool force_confirmation=false)
void sample_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
void start_lan_server_timer()
void disconnect_player(player_iterator player)
bool allow_remote_shutdown_
void ungban_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
std::chrono::seconds default_time_period_
Definitions for the interface to Wesnoth Markup Language (WML).
Declarations for File-IO.
Interfaces for manipulating version numbers of engine, add-ons, etc.
Standard logging facilities (interface).
Define the errors the server may send during the login procedure.
#define MP_INCORRECT_PASSWORD_ERROR
#define MP_NAME_AUTH_BAN_USER_ERROR
#define MP_NAME_RESERVED_ERROR
#define MP_PASSWORD_REQUEST_FOR_LOGGED_IN_NAME
#define MP_NAME_AUTH_BAN_EMAIL_ERROR
#define MP_TOO_MANY_ATTEMPTS_ERROR
#define MP_HASHING_PASSWORD_FAILED
#define MP_NAME_TOO_LONG_ERROR
#define MP_NAME_AUTH_BAN_IP_ERROR
#define MP_PASSWORD_REQUEST
#define MP_NAME_INACTIVE_WARNING
#define MP_NAME_UNREGISTERED_ERROR
#define MP_INVALID_CHARS_IN_NAME_ERROR
#define MP_NAME_TAKEN_ERROR
std::string client_address(const any_socket_ptr &sock)
auto parse_duration(const config_attribute_value &val, const Duration &def=Duration{0})
auto format_local_timestamp(const std::chrono::system_clock::time_point &time, std::string_view format="%F %T")
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
std::unique_ptr< std::istream > scoped_istream
void set_user_data_dir(std::string newprefdir)
const version_info wesnoth_version(VERSION)
void remove()
Removes a tip.
bool exists(const image::locator &i_locator)
Returns true if the given image actually exists, without loading it.
std::string format_timespan(const std::chrono::seconds &span)
TODO: we also have utils::format_timespan, which does something very similar...
bool set_log_domain_severity(const std::string &name, severity severity)
std::string node_to_string(const node &n)
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
std::string & insert(std::string &str, const std::size_t pos, const std::string &insert)
Insert a UTF-8 string at the specified position.
std::string lowercase(const std::string &s)
Returns a lowercased version of the string.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
constexpr bool decayed_is_same
Equivalent to as std::is_same_v except both types are passed through std::decay first.
void trim(std::string_view &s)
void to_sql_wildcards(std::string &str, bool underscores)
Converts '*' to '' and optionally escapes '_'.
bool wildcard_string_match(const std::string &str, const std::string &match)
Match using '*' as any number of characters (including none), '+' as one or more characters,...
bool isvalid_username(const std::string &username)
Check if the username contains only valid characters.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::vector< std::string > split(const config_attribute_value &val)
void truncate_message(const simple_wml::string_span &str, simple_wml::node &message)
Function to ensure a text message is within the allowed length.
static void make_add_diff(const simple_wml::node &src, const char *gamelist, const char *type, simple_wml::document &out, int index=-1)
static bool make_change_diff(const simple_wml::node &src, const char *gamelist, const char *type, const simple_wml::node *item, simple_wml::document &out)
int request_sample_frequency
const std::string help_msg
player_connections::const_iterator player_iterator
static std::string player_status(const wesnothd::player_record &player)
static bool make_delete_diff(const simple_wml::node &src, const char *gamelist, const char *type, const simple_wml::node *remove, simple_wml::document &out)
version_info secure_version
const std::string denied_msg
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
static bool read_config(config &src, config &dst)
filesystem::scoped_istream preprocess_file(const std::string &fname, preproc_map *defines)
Function to use the WML preprocessor on a file.
void read(config &cfg, std::istream &in, abstract_validator *validator)
std::shared_ptr< boost::asio::ssl::stream< socket_ptr::element_type > > tls_socket_ptr
std::string log_address(SocketPtr socket)
std::shared_ptr< boost::asio::ip::tcp::socket > socket_ptr
rect src
Non-transparent portion of the surface to compose.
std::chrono::seconds duration
Ban duration (0 if permanent)
static map_location::direction n
static map_location::direction s
#define LOG_SERVER
normal events
#define WRN_SERVER
clients send wrong/unexpected data
#define SETUP_HANDLER(name, function)
#define ERR_SERVER
fatal and directly server related errors/warnings, ie not caused by erroneous client data
static lg::log_domain log_server("server")
static lg::log_domain log_config("config")