48 #include <boost/algorithm/string.hpp>
49 #include <boost/scope_exit.hpp>
68 #define ERR_SERVER LOG_STREAM(err, log_server)
71 #define WRN_SERVER LOG_STREAM(warn, log_server)
74 #define LOG_SERVER LOG_STREAM(info, log_server)
75 #define DBG_SERVER LOG_STREAM(debug, log_server)
78 #define ERR_CONFIG LOG_STREAM(err, log_config)
79 #define WRN_CONFIG LOG_STREAM(warn, log_config)
81 using namespace std::chrono_literals;
92 if(!out.
child(
"gamelist_diff")) {
105 assert(!children.empty());
108 index = children.size() - 1;
111 assert(
index <
static_cast<int>(children.size()));
118 const char* gamelist,
123 if(!out.
child(
"gamelist_diff")) {
137 if(itor == children.end()) {
141 const int index = std::distance(children.begin(), itor);
151 const char* gamelist,
156 if(!out.
child(
"gamelist_diff")) {
168 const auto itor =
std::find(children.begin(), children.end(), item);
170 if(itor == children.end()) {
177 const int index = std::distance(children.begin(), itor);
194 std::ostringstream out;
197 <<
d.count() <<
" days, "
198 <<
h.count() <<
" hours, "
199 << m.count() <<
" minutes, "
200 <<
s.count() <<
" seconds";
204 const std::string
denied_msg =
"You're not allowed to execute this command.";
206 "Available commands are: adminmsg <msg>,"
207 " ban <mask> <time> <reason>, bans [deleted] [<ipmask>], clones,"
208 " dul|deny_unregistered_login [yes|no], kick <mask> [<reason>],"
209 " k[ick]ban <mask> <time> <reason>, help, games, metrics,"
210 " [lobby]msg <message>, motd [<message>],"
211 " pm|privatemsg <nickname> <message>, requests, roll <sides>, sample, searchlog <mask>,"
212 " signout, stats, status [<mask>], stopgame <nick> [<reason>], reset_queues, unban <ipmask>\n"
213 "Specific strings (those not in between <> like the command names)"
214 " are case insensitive.";
216 server::server(
int port,
218 const std::string& config_file)
224 , user_handler_(nullptr)
225 , die_(static_cast<unsigned>(std::time(nullptr)))
230 , config_file_(config_file)
231 , cfg_(read_config())
232 , accepted_versions_()
233 , redirected_versions_()
235 , disallowed_names_()
242 , default_max_messages_(0)
243 , default_time_period_(0)
244 , concurrent_connections_(0)
245 , graceful_restart(false)
248 , max_ip_log_size_(0)
249 , deny_unregistered_login_(false)
250 , save_replays_(false)
251 , replay_save_path_()
252 , allow_remote_shutdown_(false)
255 , failed_login_limit_()
256 , failed_login_ban_()
257 , failed_login_buffer_size_()
262 , dump_stats_timer_(io_service_)
263 , tournaments_timer_(io_service_)
265 , timer_(io_service_)
266 , lan_server_timer_(io_service_)
267 , dummy_player_timer_(io_service_)
268 , dummy_player_timer_interval_(30)
285 WRN_SERVER <<
"SIGHUP caught, reloading config";
298 if(
games().empty()) {
299 process_command(
"msg All games ended. Shutting down now. Reconnect to the new server instance.",
"system");
330 if(res != 0 && errno != EEXIST) {
334 int fifo = open(
input_path_.c_str(), O_RDWR | O_NONBLOCK);
340 LOG_SERVER <<
"opened fifo at '" <<
input_path_ <<
"'. Server commands may be written to this file.";
350 std::cout << error.message() << std::endl;
356 std::getline(is, cmd);
363 if(!cmd.empty() && cmd.at(0) ==
'+') {
366 <<
"[/admin_command_response]";
378 #define SETUP_HANDLER(name, function) \
379 cmd_handlers_[name] = std::bind(function, this, \
380 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
441 #warning No FIFODIR set
442 #define FIFODIR "/var/run/wesnothd"
444 const std::string fifo_path
445 = (
cfg_[
"fifo_path"].
empty() ? std::string(
FIFODIR) +
"/socket" : std::string(
cfg_[
"fifo_path"]));
466 const config&
game = queue.mandatory_child(
"game");
467 queue_info q =
queue_info(queue[
"id"].to_int(), queue[
"display_name"].str(), queue[
"players_required"].to_int(),
game);
471 std::map<int, queue_info> new_queue_info;
473 const config&
game = queue.mandatory_child(
"game");
474 queue_info q =
queue_info(queue[
"id"].to_int(), queue[
"display_name"].str(), queue[
"players_required"].to_int(),
game);
475 new_queue_info.emplace(q.
id, q);
479 for(
auto& [
id,
info] : new_queue_info) {
484 update.set_attr_dup(
"action",
"add");
485 update.set_attr_dup(
"display_name",
info.display_name.c_str());
486 update.set_attr_int(
"players_required",
info.players_required);
498 update.set_attr_dup(
"action",
"update");
499 update.set_attr_dup(
"display_name",
info.display_name.c_str());
500 update.set_attr_int(
"players_required",
info.players_required);
508 if(new_queue_info.count(
id) == 0) {
512 update.set_attr_dup(
"action",
"remove");
532 for(
const std::string& source :
utils::split(
cfg_[
"client_sources"].str())) {
537 if(
cfg_[
"disallow_names"].empty()) {
568 const std::string& versions =
cfg_[
"versions_accepted"];
569 if(versions.empty() ==
false) {
585 for(
const std::string& version :
utils::split(proxy[
"version"])) {
601 ERR_SERVER <<
"The server id must be set when database support is used";
613 if(
cfg_[
"dummy_player_count"].to_int() > 0) {
614 for(
int i = 0;
i <
cfg_[
"dummy_player_count"].to_int();
i++) {
621 dummy_user.
set_attr_dup(
"name", (
"player"+std::to_string(
i)).c_str());
625 if(
cfg_[
"dummy_player_timer_interval"].to_int() > 0) {
638 std::size_t connections = 0;
640 if(
player.client_ip() == ip) {
657 server_ban_info->get_reason(),
658 server_ban_info->get_remaining_ban_time()
674 ERR_SERVER <<
"Error waiting for dump stats timer: " << ec.message();
678 <<
"\tnumber_of_games = " <<
games().size()
692 ERR_SERVER <<
"Error waiting for dummy player timer: " << ec.message();
735 ERR_SERVER <<
"Error waiting for tournament refresh timer: " << ec.message();
746 boost::asio::spawn(
io_service_, [socket,
this](boost::asio::yield_context yield) {
login_client(std::move(yield), socket); }
747 #if BOOST_VERSION >= 108000
748 , [](
const std::exception_ptr&
e) {
if (
e) std::rethrow_exception(
e); }
755 boost::asio::spawn(
io_service_, [socket,
this](boost::asio::yield_context yield) {
login_client(std::move(yield), socket); }
756 #if BOOST_VERSION >= 108000
757 , [](
const std::exception_ptr&
e) {
if (
e) std::rethrow_exception(
e); }
762 template<
class SocketPtr>
770 std::string client_version, client_source;
773 client_version = std::string { version_str_span.
begin(), version_str_span.
end() };
776 client_source = std::string { source_str_span.
begin(), source_str_span.
end() };
784 <<
":\ttelling them to log in.";
793 <<
":\tredirecting them to " << redirect_version.second[
"host"] <<
":"
794 << redirect_version.second[
"port"];
797 for(
const auto& attr : redirect_version.second.attribute_range()) {
798 redirect.set_attr_dup(attr.first.c_str(), attr.second.str().c_str());
807 <<
":\trejecting them";
822 std::string username;
823 bool registered, is_moderator;
830 username = (*login)[
"username"].to_string();
832 if(
is_login_allowed(yield, socket, login, username, registered, is_moderator)) {
858 assert(inserted &&
"unexpected duplicate username");
861 join_lobby_response.
root().
add_child(
"join_lobby").
set_attr(
"is_moderator", is_moderator ?
"yes" :
"no");
868 queue_node.
set_attr_dup(
"display_name", queue.display_name.c_str());
869 queue_node.
set_attr_int(
"players_required", queue.players_required);
875 [
this, socket, new_player](boost::asio::yield_context yield) {
handle_player(std::move(yield), socket, new_player); }
876 #if BOOST_VERSION >= 108000
877 , [](
const std::exception_ptr&
e) {
if (
e) std::rethrow_exception(
e); }
882 << (registered ?
" to a registered account" :
"");
884 std::shared_ptr<game> last_sent;
886 auto g_ptr = record.get_game();
887 if(g_ptr != last_sent) {
889 g_ptr->send_server_message_to_all(username +
" has logged into the lobby");
909 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)
914 "The nickname '" + username +
"' contains invalid "
915 "characters. Only alpha-numeric characters, underscores and hyphens are allowed.",
922 if(username.size() > 20) {
923 async_send_error(socket,
"The nickname '" + username +
"' is too long. Nicks must be 20 characters or less.",
932 async_send_error(socket,
"The nickname '" + username +
"' is reserved and cannot be used by players",
945 if(!
authenticate(socket, username, (*login)[
"password"].to_string(), name_taken, registered))
951 "The nickname '" + username +
"' is not registered. This server disallows unregistered nicknames.",
966 std::string ban_type_desc;
967 std::string ban_reason;
968 const char* msg_numeric;
969 std::string ban_duration = std::to_string(auth_ban.
duration.count());
971 switch(auth_ban.
type) {
973 ban_type_desc =
"account";
975 ban_reason =
"a ban has been issued on your user account.";
978 ban_type_desc =
"IP address";
980 ban_reason =
"a ban has been issued on your IP address.";
983 ban_type_desc =
"email address";
985 ban_reason =
"a ban has been issued on your email address.";
988 ban_type_desc =
"<unknown ban type>";
990 ban_reason = ban_type_desc;
993 ban_reason +=
" (" + ban_duration +
")";
996 LOG_SERVER <<
log_address(socket) <<
"\t" << username <<
"\tis banned by user_handler (" << ban_type_desc
1000 async_send_error(socket,
"You are banned from this server: " + ban_reason, msg_numeric, {{
"duration", ban_duration}});
1003 async_send_error(socket,
"You are banned from this server: " + ban_reason, msg_numeric);
1007 LOG_SERVER <<
log_address(socket) <<
"\t" << username <<
"\tis banned by user_handler (" << ban_type_desc
1008 <<
"), " <<
"ignoring due to moderator flag";
1015 process_command(
"kick " + username +
" autokick by registered user", username);
1018 boost::asio::post(yield);
1027 send_server_message(socket,
"You are currently banned by the forum administration.",
"alert");
1034 SocketPtr socket,
const std::string& username,
const std::string& password,
bool name_taken,
bool& registered)
1050 "The nickname '" + username +
"' is inactive. You cannot claim ownership of this "
1051 "nickname until you activate your account via email or ask an administrator to do it for you.",
1054 const std::string salt =
user_handler_->extract_salt(username);
1057 "Even though your nickname is registered on this server you "
1058 "cannot log in due to an error in the hashing algorithm. "
1059 "Logging into your forum account on https://forums.wesnoth.org "
1060 "may fix this problem.");
1063 const std::string hashed_password =
hash_password(password, salt, username);
1066 if(password.empty()) {
1071 "The nickname '" + username +
"' is registered on this server."
1072 "\n\nWARNING: There is already a client using this username, "
1073 "logging in will cause that client to be kicked!",
1083 if(hashed_password.empty()) {
1088 else if(!(
user_handler_->login(username, hashed_password))) {
1089 const auto steady_now = std::chrono::steady_clock::now();
1115 "Maximum login attempts exceeded",
"automatic",
"", username);
1120 "The password you provided for the nickname '" + username +
"' was incorrect.",
1126 <<
"Login attempt with incorrect password for nickname '" << username <<
"'.";
1140 const std::string&
msg,
1141 const char* error_code,
1142 bool force_confirmation)
1146 e.set_attr_dup(
"message",
msg.c_str());
1147 e.set_attr(
"password_request",
"yes");
1148 e.set_attr(
"force_confirmation", force_confirmation ?
"yes" :
"no");
1150 if(*error_code !=
'\0') {
1151 e.set_attr(
"error_code", error_code);
1162 BOOST_SCOPE_EXIT_ALL(
this, &
player) {
1170 if(!
motd_.empty()) {
1192 if(doc->child(
"refresh_lobby")) {
1254 int offset = request->attr(
"offset").to_int();
1259 if(request->has_attr(
"search_player") && request->attr(
"search_player").to_string() !=
"") {
1260 std::string player_name = request->attr(
"search_player").to_string();
1265 player_id = player_ptr->info().config_address()->attr(
"forum_id").to_int();
1269 std::string search_game_name = request->attr(
"search_game_name").to_string();
1270 int search_content_type = request->attr(
"search_content_type").to_int();
1271 std::string search_content = request->attr(
"search_content").to_string();
1272 LOG_SERVER <<
"Querying game history requested by player `" <<
player->info().
name() <<
"` for player id `" << player_id <<
"`."
1273 <<
"Searching for game name `" << search_game_name <<
"`, search content type `" << search_content_type <<
"`, search content `" << search_content <<
"`.";
1274 user_handler_->async_get_and_send_game_history(
io_service_, *
this,
player->socket(), player_id, offset, search_game_name, search_content_type, search_content);
1282 if((whisper[
"receiver"].empty()) || (whisper[
"message"].empty())) {
1285 "message=\"Invalid number of arguments\"\n"
1286 "sender=\"server\"\n"
1295 whisper.set_attr_dup(
"sender",
player->
name().c_str());
1312 whisper.copy_into(trunc_whisper);
1324 const std::string command(query[
"type"].to_string());
1325 std::ostringstream response;
1327 const std::string& query_help_msg =
1328 "Available commands are: adminmsg <msg>, help, games, metrics,"
1329 " motd, requests, roll <sides>, sample, stats, status, version, wml.";
1332 if(command ==
"status") {
1335 command.compare(0, 8,
"adminmsg") == 0 ||
1336 command.compare(0, 6,
"report") == 0 ||
1337 command ==
"games" ||
1338 command ==
"metrics" ||
1339 command ==
"motd" ||
1340 command.compare(0, 7,
"version") == 0 ||
1341 command ==
"requests" ||
1342 command.compare(0, 4,
"roll") == 0 ||
1343 command ==
"sample" ||
1344 command ==
"stats" ||
1350 if(command ==
"signout") {
1354 response <<
"You are no longer recognized as an administrator.";
1359 LOG_SERVER <<
"Admin Command: type: " << command <<
"\tIP: " << iter->client_ip()
1364 }
else if(command ==
"help" || command.empty()) {
1365 response << query_help_msg;
1366 }
else if(command ==
"admin" || command.compare(0, 6,
"admin ") == 0) {
1373 if(command.size() >= 6) {
1374 passwd = command.substr(6);
1378 LOG_SERVER <<
"New Admin recognized: IP: " << iter->client_ip() <<
"\tnick: " <<
player.
name();
1381 response <<
"You are now recognized as an administrator.";
1387 WRN_SERVER <<
"FAILED Admin attempt with password: '" << passwd <<
"'\tIP: " << iter->client_ip()
1389 response <<
"Error: wrong password";
1392 response <<
"Error: unrecognized query: '" << command <<
"'\n" << query_help_msg;
1407 if(nickserv.
child(
"info")) {
1409 std::string res =
user_handler_->user_info((*nickserv.
child(
"info"))[
"name"].to_string());
1413 "There was an error looking up the details of the user '"
1414 + (*nickserv.
child(
"info"))[
"name"].to_string() +
"'. "
1415 +
" The error message was: " +
e.message,
"error"
1443 if(user->info().is_message_flooding()) {
1445 "Warning: you are sending too many messages too fast. Your message has not been relayed.",
"error");
1450 message.set_attr_dup(
"sender", user->name().c_str());
1453 message.copy_into(trunc_message);
1459 LOG_SERVER << user->client_ip() <<
"\t<" << user->name()
1462 LOG_SERVER << user->client_ip() <<
"\t<" << user->name() <<
"> " <<
msg;
1472 update.set_attr_int(
"queue_id", queue.
id);
1473 update.set_attr_dup(
"action",
"update");
1486 "This server is shutting down. You aren't allowed to make new games. Please "
1487 "reconnect to the new server.",
"error");
1493 const std::string game_name = create_game[
"name"].to_string();
1494 const std::string game_password = create_game[
"password"].to_string();
1495 const std::string initial_bans = create_game[
"ignored"].to_string();
1497 int queue_id = create_game[
"queue_id"].to_int();
1500 <<
"\tcreates a new game: \"" << game_name <<
"\".";
1513 DBG_SERVER <<
"initial bans: " << initial_bans;
1514 if(initial_bans !=
"") {
1518 if(game_password.empty() ==
false) {
1519 g.set_password(game_password);
1543 assert(gamelist !=
nullptr);
1556 const std::size_t
index = std::distance(
games.begin(),
g);
1560 LOG_SERVER <<
"Could not find game (" << game_ptr->
id() <<
", " << game_ptr->
db_id() <<
") to delete in games_and_users_list_.";
1570 int game_id =
join[
"id"].to_int();
1573 const std::string& password =
join[
"password"].to_string();
1577 std::shared_ptr<game>
g;
1579 g = g_iter->get_game();
1585 <<
"\tattempted to join unknown game:\t" << game_id <<
".";
1590 }
else if(!
g->level_init()) {
1592 <<
"\tattempted to join uninitialized game:\t\"" <<
g->name() <<
"\" (" << game_id <<
").";
1601 <<
"\tReject banned player: " <<
player->info().
name()
1602 <<
"\tfrom game:\t\"" <<
g->name() <<
"\" (" << game_id <<
").";
1607 }
else if(!
g->password_matches(password)) {
1609 <<
"\tattempted to join game:\t\"" <<
g->name() <<
"\" (" << game_id <<
") with bad password";
1619 <<
"\tattempted to observe game:\t\"" <<
g->name() <<
"\" (" << game_id
1620 <<
") which doesn't allow observers.";
1624 "Attempt to observe a game that doesn't allow observers. (You probably joined the "
1625 "game shortly after it filled up.)",
"error");
1634 g->describe_slots();
1641 if(diff1 || diff2) {
1657 int queue_id =
data.attr(
"queue_id").to_int();
1660 ERR_SERVER <<
"player " <<
p->info().name() <<
" attempted to join non-existing server-side queue " <<
data.attr(
"queue_id");
1666 DBG_SERVER <<
"player " <<
p->info().name() <<
" already in server-side queue " <<
data.attr(
"queue_id");
1672 p->info().add_queue(queue.
id);
1690 game.set_attr_dup(
"scenario", scenarios[
index].c_str());
1691 game.set_attr_dup(
"era", queue.
settings[
"era"].str().c_str());
1692 game.set_attr_int(
"fog", queue.
settings[
"fog"].to_int());
1693 game.set_attr_int(
"shroud", queue.
settings[
"shroud"].to_int());
1694 game.set_attr_int(
"village_gold", queue.
settings[
"village_gold"].to_int());
1695 game.set_attr_int(
"village_support", queue.
settings[
"village_support"].to_int());
1696 game.set_attr_int(
"experience_modifier", queue.
settings[
"experience_modifier"].to_int());
1697 game.set_attr_int(
"countdown", queue.
settings[
"countdown"].to_int());
1698 game.set_attr_int(
"random_start_time", queue.
settings[
"random_start_time"].to_int());
1699 game.set_attr_int(
"shuffle_sides", queue.
settings[
"shuffle_sides"].to_int());
1705 if(
game->is_open_queue_game(queue.
id)) {
1719 int queue_id =
data.attr(
"queue_id").to_int();
1722 ERR_SERVER <<
"player " <<
p->info().name() <<
" attempted to leave non-existing server-side queue " <<
data.attr(
"queue_id");
1731 p->info().clear_queues();
1735 ERR_SERVER <<
"player " <<
p->info().name() <<
" already not in server-side queue " <<
data.attr(
"queue_id");
1745 game&
g = *(
p->get_game());
1746 std::weak_ptr<game> g_ptr{
p->get_game()};
1749 if(
data.child(
"snapshot") ||
data.child(
"scenario")) {
1750 if(!
g.is_owner(
p)) {
1760 if(!
g.level_init()) {
1762 <<
g.id() <<
", " <<
g.db_id() <<
").";
1766 assert(gamelist !=
nullptr);
1769 g.level().root().copy_into(desc);
1775 <<
g.name() <<
"\" (" <<
g.id() <<
", " <<
g.db_id() <<
") without a 'multiplayer' child.";
1777 g.set_description(&desc);
1781 "The scenario data is missing the [multiplayer] tag which contains the "
1782 "game settings. Game aborted.",
"error");
1786 g.set_description(&desc);
1790 <<
g.name() <<
"\" (" <<
g.id() <<
", " <<
g.db_id() <<
") although it's already initialized.";
1804 if(!
data[
"mp_shroud"].to_bool()) {
1809 if(!
e->attr(
"require_era").to_bool(
true)) {
1810 desc.
set_attr(
"require_era",
"no");
1814 if(
s[
"require_scenario"].to_bool(
false)) {
1815 desc.
set_attr(
"require_scenario",
"yes");
1824 desc.
child(
"modification")->
set_attr_dup(
"require_modification", m->attr(
"require_modification"));
1828 g.level().swap(
data);
1833 g.update_side_data();
1844 if(
g.q_type() == queue_type::type::server_preset) {
1845 int queue_id =
g.queue_id();
1846 int game_id =
g.id();
1853 std::size_t joined_count = 1;
1854 for(
const std::string& name :
info.players_in_queue) {
1866 for(
int queue : player_ptr->info().get_queues()) {
1874 if(joined_count ==
info.players_required) {
1888 }
else if(!
g.level_init()) {
1890 <<
" while the scenario wasn't yet initialized."
1895 if(!
g.is_owner(
p)) {
1899 if(!
g.level_init()) {
1901 <<
"\tsent [store_next_scenario] in game:\t\"" <<
g.name() <<
"\" (" <<
g.id()
1902 <<
", " <<
g.db_id() <<
") while the scenario is not yet initialized.";
1912 g.reset_last_synced_context_id();
1916 scenario->copy_into(
g.level().root());
1919 if(
g.description() ==
nullptr) {
1920 ERR_SERVER <<
p->client_ip() <<
"\tERROR: \"" <<
g.name() <<
"\" (" <<
g.id()
1921 <<
", " <<
g.db_id() <<
") is initialized but has no description_.";
1932 <<
g.name() <<
"\" (" <<
g.id() <<
", " <<
g.db_id() <<
") without a 'multiplayer' child.";
1937 "The scenario data is missing the [multiplayer] tag which contains the game "
1938 "settings. Game aborted.",
"error");
1945 desc.
set_attr_dup(
"map_data",
s[
"mp_shroud"].to_bool() ?
"" :
s[
"map_data"]);
1948 if(!
e->attr(
"require_era").to_bool(
true)) {
1949 desc.
set_attr(
"require_era",
"no");
1953 if(
s[
"require_scenario"].to_bool(
false)) {
1954 desc.
set_attr(
"require_scenario",
"yes");
1960 g.send_data(notify_next_scenario,
p);
1966 }
else if(
data.child(
"load_next_scenario")) {
1967 g.load_next_scenario(
p);
1969 }
else if(
data.child(
"start_game")) {
1970 if(!
g.is_owner(
p)) {
1975 g.perform_controller_tweaks();
1987 std::set<std::string> primary_keys;
1988 for(
const auto& addon : m.
children(
"addon")) {
1989 for(
const auto& content : addon->children(
"content")) {
1990 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();
1991 if(primary_keys.count(key) == 0) {
1992 primary_keys.emplace(key);
1993 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());
1994 if(rows_inserted == 0) {
1995 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() <<
"'";
2000 if(m.
children(
"addon").size() == 0) {
2001 WRN_SERVER <<
"Game content info missing for game with uuid '" <<
uuid_ <<
"', game ID '" <<
g.db_id() <<
"', named '" <<
g.name() <<
"'";
2004 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());
2007 for(
unsigned side_index = 0; side_index < sides.size(); ++side_index) {
2010 std::string version;
2029 std::vector<std::string> leaders;
2031 if(side.
attr(
"type") !=
"") {
2036 if(
unit->attr(
"canrecruit") ==
"yes") {
2037 leaders.emplace_back(
unit->attr(
"type").to_string());
2041 for(
const auto leader : side.
children(
"leader")) {
2042 leaders.emplace_back(leader->attr(
"type").to_string());
2045 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));
2052 }
else if(
data.child(
"leave_game")) {
2053 if(
g.remove_player(
p)) {
2056 bool has_diff =
false;
2063 if(
auto gStrong = g_ptr.lock()) {
2064 gStrong->describe_slots();
2085 update.set_attr_dup(
"action",
"update");
2094 if(!
g.is_owner(
p)) {
2098 g.level().root().apply_diff(*scenario_diff);
2102 g.update_side_data();
2111 }
else if(
data.child(
"change_faction")) {
2116 g.transfer_side_control(
p, *change);
2122 }
else if(
data.child(
"muteall")) {
2123 if(!
g.is_owner(
p)) {
2124 g.send_server_message(
"You cannot mute: not the game host.",
p);
2128 g.mute_all_observers();
2132 g.mute_observer(*mute,
p);
2136 g.unmute_observer(*unmute,
p);
2139 }
else if(
data.child(
"kick") ||
data.child(
"ban")) {
2140 bool ban = (
data.child(
"ban") !=
nullptr);
2142 ?
g.ban_user(*
data.child(
"ban"),
p)
2143 :
g.kick_member(*
data.child(
"kick"),
p)};
2164 g.unban_user(*unban,
p);
2168 if(!
g.is_player(
p)) {
2172 if((*
info)[
"type"] ==
"termination") {
2173 g.set_termination_reason((*
info)[
"condition"].to_string());
2174 if((*
info)[
"condition"].to_string() ==
"out of sync") {
2175 g.send_and_record_server_message(
player.
name() +
" reports out of sync errors.");
2183 }
else if(
data.child(
"turn")) {
2191 }
else if(
data.child(
"whiteboard")) {
2192 g.process_whiteboard(
data,
p);
2194 }
else if(
data.child(
"change_turns_wml")) {
2195 g.process_change_turns_wml(
data,
p);
2199 g.handle_choice(*sch,
p);
2201 }
else if(
data.child(
"message")) {
2202 g.process_message(
data,
p);
2204 }
else if(
data.child(
"stop_updates")) {
2209 data.child(
"error") ||
2210 data.child(
"side_secured") ||
2211 data.root().has_attr(
"failed") ||
2212 data.root().has_attr(
"side")
2218 <<
" in game: \"" <<
g.name() <<
"\" (" <<
g.id() <<
", " <<
g.db_id() <<
")\n"
2226 msg.set_attr(
"sender",
"server");
2227 msg.set_attr_esc(
"message", message);
2228 msg.set_attr_dup(
"type",
type.c_str());
2235 utils::visit([](
auto&& socket) {
2237 socket->async_shutdown([socket](...) {});
2238 const char buffer[] =
"";
2239 async_write(*socket, boost::asio::buffer(buffer), [socket](...) { socket->lowest_layer().close(); });
2241 socket->lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_receive);
2248 std::string ip = iter->client_ip();
2250 const std::shared_ptr<game>
g = iter->get_game();
2251 bool game_ended =
false;
2253 game_ended =
g->remove_player(iter,
true,
false);
2257 const std::size_t
index =
2258 std::distance(users.begin(),
std::find(users.begin(), users.end(), iter->info().config_address()));
2268 LOG_SERVER << ip <<
"\t" << iter->info().name() <<
"\thas logged off";
2272 user_handler_->db_update_logout(iter->info().get_login_id());
2278 i->log_off = std::chrono::system_clock::now();
2283 if(!queue.players_in_queue.empty()) {
2284 queue.players_in_queue.erase(
std::remove(queue.players_in_queue.begin(), queue.players_in_queue.end(), iter->info().name()));
2346 if(issuer_name ==
"*socket*" && !query.empty() && query.at(0) ==
'+') {
2350 auto issuer_end =
std::find(query.begin(), query.end(),
':');
2352 std::string issuer(query.begin() + 1, issuer_end);
2353 if(!issuer.empty()) {
2354 issuer_name =
"+" + issuer +
"+";
2355 query = std::string(issuer_end + 1, query.end());
2360 const auto i =
std::find(query.begin(), query.end(),
' ');
2363 const std::string command =
utf8::lowercase(std::string(query.begin(),
i));
2365 std::string parameters = (
i == query.end() ?
"" : std::string(
i + 1, query.end()));
2368 std::ostringstream out;
2372 out <<
"Command '" << command <<
"' is not recognized.\n" <<
help_msg;
2374 const cmd_handler& handler = handler_itor->second;
2376 handler(issuer_name, query, parameters, &out);
2377 }
catch(
const std::bad_function_call& ex) {
2378 ERR_SERVER <<
"While handling a command '" << command
2379 <<
"', caught a std::bad_function_call exception.";
2381 out <<
"An internal server error occurred (std::bad_function_call) while executing '" << command
2389 std::string
msg =
"While handling a command, caught an invalid utf8 exception: ";
2392 return (
msg +
'\n');
2398 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2400 assert(out !=
nullptr);
2407 if(parameters ==
"now") {
2419 "msg The server is shutting down. You may finish your games but can't start new ones. Once all "
2420 "games have ended the server will exit.",
2424 *out <<
"Server is doing graceful shut down.";
2429 const std::string& ,
2431 std::ostringstream* out)
2433 assert(out !=
nullptr);
2441 *out <<
"No restart_command configured! Not restarting.";
2452 "msg The server has been restarted. You may finish current games but can't start new ones and "
2453 "new players can't join this (old) server instance. (So if a player of your game disconnects "
2454 "you have to save, reconnect and reload the game on the new server instance. It is actually "
2455 "recommended to do that right away.)",
2459 *out <<
"New server started.";
2464 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2466 assert(out !=
nullptr);
2468 if(parameters.empty()) {
2471 }
else if(issuer_name !=
"*socket*") {
2478 *out <<
"Sampling turned off.";
2485 const std::string& ,
2487 std::ostringstream* out)
2489 assert(out !=
nullptr);
2494 const std::string& ,
2496 std::ostringstream* out)
2498 assert(out !=
nullptr);
2504 const std::string& ,
2506 std::ostringstream* out)
2508 assert(out !=
nullptr);
2513 const std::string& ,
2515 std::ostringstream* out)
2517 assert(out !=
nullptr);
2522 const std::string& ,
2523 std::string& parameters,
2524 std::ostringstream* out)
2526 assert(out !=
nullptr);
2527 if(parameters.empty()) {
2534 }
catch(
const std::invalid_argument&) {
2535 *out <<
"The number of die sides must be a number!";
2537 }
catch(
const std::out_of_range&) {
2538 *out <<
"The number of sides is too big for the die!";
2543 *out <<
"The die cannot have less than 1 side!";
2546 std::uniform_int_distribution<int> dice_distro(1, N);
2547 std::string value = std::to_string(dice_distro(
die_));
2549 *out <<
"You rolled a die [1 - " + parameters +
"] and got a " + value +
".";
2556 auto g_ptr = player_ptr->get_game();
2558 g_ptr->send_server_message_to_all(issuer_name +
" rolled a die [1 - " + parameters +
"] and got a " + value +
".",
player_connections_.project<0>(player_ptr));
2560 *out <<
" (The result is shown to others only in a game.)";
2565 const std::string& ,
2567 std::ostringstream* out)
2569 assert(out !=
nullptr);
2574 const std::string& ,
2576 std::ostringstream* out)
2578 assert(out !=
nullptr);
2583 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2585 assert(out !=
nullptr);
2587 if(parameters.empty()) {
2588 *out <<
"You must type a message.";
2592 const std::string& sender = issuer_name;
2593 const std::string& message = parameters;
2595 << (message.find(
"/me ") == 0 ? std::string(message.begin() + 3, message.end()) +
">" :
"> " + message);
2599 msg.set_attr_dup(
"sender", (
"admin message from " + sender).c_str());
2600 msg.set_attr_dup(
"message", message.c_str());
2610 bool is_admin =
false;
2620 *out <<
"Your report has been logged and sent to the server administrators. Thanks!";
2624 *out <<
"Your report has been logged and sent to " <<
n <<
" online administrators. Thanks!";
2628 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2630 assert(out !=
nullptr);
2632 auto first_space =
std::find(parameters.begin(), parameters.end(),
' ');
2633 if(first_space == parameters.end()) {
2634 *out <<
"You must name a receiver.";
2638 const std::string& sender = issuer_name;
2639 const std::string receiver(parameters.begin(), first_space);
2641 std::string message(first_space + 1, parameters.end());
2644 if(message.empty()) {
2645 *out <<
"You must type a message.";
2653 msg.set_attr_dup(
"sender", (
"server message from " + sender).c_str());
2654 msg.set_attr_dup(
"message", message.c_str());
2657 if(receiver !=
player.info().
name().c_str()) {
2662 *out <<
"Message to " << receiver <<
" successfully sent.";
2666 *out <<
"No such nick: " << receiver;
2670 const std::string& ,
2671 std::string& parameters,
2672 std::ostringstream* out)
2674 assert(out !=
nullptr);
2676 if(parameters.empty()) {
2677 *out <<
"You must type a message.";
2684 << (parameters.find(
"/me ") == 0
2685 ? std::string(parameters.begin() + 3, parameters.end()) +
">"
2686 :
"> " + parameters);
2688 *out <<
"message '" << parameters <<
"' relayed to players";
2692 const std::string& ,
2693 std::string& parameters,
2694 std::ostringstream* out)
2696 assert(out !=
nullptr);
2698 if(parameters.empty()) {
2699 *out <<
"You must type a message.";
2705 << (parameters.find(
"/me ") == 0
2706 ? std::string(parameters.begin() + 3, parameters.end()) +
">"
2707 :
"> " + parameters);
2709 *out <<
"message '" << parameters <<
"' relayed to players";
2713 const std::string& ,
const std::string& , std::string& parameters, std::ostringstream* out)
2715 assert(out !=
nullptr);
2717 if(parameters.empty()) {
2724 *out <<
"Player " << parameters <<
" is using wesnoth " <<
player.info().
version();
2729 *out <<
"Player '" << parameters <<
"' not found.";
2733 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2735 assert(out !=
nullptr);
2737 *out <<
"STATUS REPORT for '" << parameters <<
"'";
2738 bool found_something =
false;
2744 parameters =
player.client_ip();
2745 found_something =
true;
2750 if(!found_something) {
2758 const bool match_ip = ((std::count(parameters.begin(), parameters.end(),
'.') >= 1) || (std::count(parameters.begin(), parameters.end(),
':') >= 1));
2760 if(parameters.empty() || parameters ==
"*" ||
2764 found_something =
true;
2769 if(!found_something) {
2770 *out <<
"\nNo match found. You may want to check with 'searchlog'.";
2775 const std::string& ,
2777 std::ostringstream* out)
2779 assert(out !=
nullptr);
2780 *out <<
"CLONES STATUS REPORT";
2782 std::set<std::string> clones;
2785 if(clones.find(it->client_ip()) != clones.end()) {
2791 if(it->client_ip() == clone->client_ip()) {
2794 clones.insert(it->client_ip());
2803 if(clones.empty()) {
2804 *out << std::endl <<
"No clones found.";
2809 const std::string& ,
2810 std::string& parameters,
2811 std::ostringstream* out)
2813 assert(out !=
nullptr);
2816 if(parameters.empty()) {
2821 std::string mask = parameters.substr(7);
2829 ERR_SERVER <<
"While handling bans, caught an invalid utf8 exception: " <<
e.what();
2834 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2836 assert(out !=
nullptr);
2839 auto first_space =
std::find(parameters.begin(), parameters.end(),
' ');
2841 if(first_space == parameters.end()) {
2846 auto second_space =
std::find(first_space + 1, parameters.end(),
' ');
2847 const std::string target(parameters.begin(), first_space);
2848 const std::string duration(first_space + 1, second_space);
2856 if(second_space == parameters.end()) {
2860 std::string reason(second_space + 1, parameters.end());
2863 if(reason.empty()) {
2864 *out <<
"You need to give a reason for the ban.";
2868 std::string dummy_group;
2872 if(std::count(target.begin(), target.end(),
'.') >= 1) {
2875 *out <<
ban_manager_.
ban(target, parsed_time, reason, issuer_name, dummy_group);
2885 const std::string ip =
player.client_ip();
2886 *out <<
ban_manager_.
ban(ip, parsed_time, reason, issuer_name, dummy_group, target);
2891 *out <<
"Nickname mask '" << target <<
"' did not match, no bans set.";
2897 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2899 assert(out !=
nullptr);
2902 auto first_space =
std::find(parameters.begin(), parameters.end(),
' ');
2903 if(first_space == parameters.end()) {
2908 auto second_space =
std::find(first_space + 1, parameters.end(),
' ');
2909 const std::string target(parameters.begin(), first_space);
2910 const std::string duration(first_space + 1, second_space);
2918 if(second_space == parameters.end()) {
2922 std::string reason(second_space + 1, parameters.end());
2925 if(reason.empty()) {
2926 *out <<
"You need to give a reason for the ban.";
2930 std::string dummy_group;
2931 std::vector<player_iterator> users_to_kick;
2935 if(std::count(target.begin(), target.end(),
'.') >= 1) {
2938 *out <<
ban_manager_.
ban(target, parsed_time, reason, issuer_name, dummy_group);
2942 users_to_kick.push_back(
player);
2954 const std::string ip =
player->client_ip();
2955 *out <<
ban_manager_.
ban(ip, parsed_time, reason, issuer_name, dummy_group, target);
2956 users_to_kick.push_back(
player);
2961 *out <<
"Nickname mask '" << target <<
"' did not match, no bans set.";
2965 for(
auto user : users_to_kick) {
2966 *out <<
"\nKicked " << user->info().name() <<
" (" << user->client_ip() <<
").";
2967 utils::visit([
this,reason](
auto&& socket) {
async_send_error(socket,
"You have been banned. Reason: " + reason); }, user->socket());
2973 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2975 assert(out !=
nullptr);
2978 auto first_space =
std::find(parameters.begin(), parameters.end(),
' ');
2979 if(first_space == parameters.end()) {
2984 auto second_space =
std::find(first_space + 1, parameters.end(),
' ');
2985 const std::string target(parameters.begin(), first_space);
2987 std::string group = std::string(first_space + 1, second_space);
2988 first_space = second_space;
2989 second_space =
std::find(first_space + 1, parameters.end(),
' ');
2991 const std::string duration(first_space + 1, second_space);
2999 if(second_space == parameters.end()) {
3003 std::string reason(second_space + 1, parameters.end());
3006 if(reason.empty()) {
3007 *out <<
"You need to give a reason for the ban.";
3013 if(std::count(target.begin(), target.end(),
'.') >= 1) {
3016 *out <<
ban_manager_.
ban(target, parsed_time, reason, issuer_name, group);
3026 const std::string ip =
player.client_ip();
3027 *out <<
ban_manager_.
ban(ip, parsed_time, reason, issuer_name, group, target);
3032 *out <<
"Nickname mask '" << target <<
"' did not match, no bans set.";
3038 const std::string& ,
3039 std::string& parameters,
3040 std::ostringstream* out)
3042 assert(out !=
nullptr);
3044 if(parameters.empty()) {
3045 *out <<
"You must enter an ipmask to unban.";
3053 const std::string& ,
3054 std::string& parameters,
3055 std::ostringstream* out)
3057 assert(out !=
nullptr);
3059 if(parameters.empty()) {
3060 *out <<
"You must enter an ipmask to ungban.";
3068 const std::string& ,
3069 std::string& parameters,
3070 std::ostringstream* out)
3072 assert(out !=
nullptr);
3074 if(parameters.empty()) {
3075 *out <<
"You must enter a mask to kick.";
3079 auto i =
std::find(parameters.begin(), parameters.end(),
' ');
3080 const std::string kick_mask = std::string(parameters.begin(),
i);
3081 const std::string kick_message = (
i == parameters.end()
3082 ?
"You have been kicked."
3083 :
"You have been kicked. Reason: " + std::string(
i + 1, parameters.end()));
3085 bool kicked =
false;
3088 const bool match_ip = (std::count(kick_mask.begin(), kick_mask.end(),
'.') >= 1);
3090 std::vector<player_iterator> users_to_kick;
3095 users_to_kick.push_back(
player);
3099 for(
const auto&
player : users_to_kick) {
3106 *out <<
"Kicked " <<
player->
name() <<
" (" <<
player->client_ip() <<
"). '"
3107 << kick_message <<
"'";
3109 utils::visit([
this, &kick_message](
auto&& socket) {
async_send_error(socket, kick_message); },
player->socket());
3114 *out <<
"No user matched '" << kick_mask <<
"'.";
3119 const std::string& ,
3120 std::string& parameters,
3121 std::ostringstream* out)
3123 assert(out !=
nullptr);
3125 if(parameters.empty()) {
3126 if(!
motd_.empty()) {
3127 *out <<
"Message of the day:\n" <<
motd_;
3130 *out <<
"No message of the day set.";
3136 *out <<
"Message of the day set to: " <<
motd_;
3140 const std::string& ,
3141 std::string& parameters,
3142 std::ostringstream* out)
3144 assert(out !=
nullptr);
3146 if(parameters.empty()) {
3147 *out <<
"You must enter a mask to search for.";
3151 *out <<
"IP/NICK LOG for '" << parameters <<
"'";
3155 const bool match_ip = (std::count(parameters.begin(), parameters.end(),
'.') >= 1);
3158 bool found_something =
false;
3161 const std::string& username =
i.nick;
3162 const std::string& ip =
i.ip;
3167 found_something =
true;
3173 *out <<
"\n'" << username <<
"' @ " << ip
3179 if(!found_something) {
3180 *out <<
"\nNo match found.";
3193 const std::string& ,
3194 std::string& parameters,
3195 std::ostringstream* out)
3197 assert(out !=
nullptr);
3200 if(parameters.empty()) {
3208 ERR_SERVER <<
"While handling dul (deny unregistered logins), caught an invalid utf8 exception: " <<
e.what();
3213 const std::string& ,
3214 std::string& parameters,
3215 std::ostringstream* out)
3217 assert(out !=
nullptr);
3219 const std::string nick = parameters.substr(0, parameters.find(
' '));
3220 const std::string reason = parameters.length() > nick.length()+1 ? parameters.substr(nick.length()+1) :
"";
3224 std::shared_ptr<game>
g =
player->get_game();
3226 *out <<
"Player '" << nick <<
"' is in game with id '" <<
g->id() <<
", " <<
g->db_id() <<
"' named '" <<
g->name() <<
"'. Ending game for reason: '" << reason <<
"'...";
3229 *out <<
"Player '" << nick <<
"' is not currently in a game.";
3232 *out <<
"Player '" << nick <<
"' is not currently logged in.";
3237 const std::string& ,
3239 std::ostringstream* out)
3241 assert(out !=
nullptr);
3248 queue.players_in_queue.clear();
3252 *out <<
"Reset all queues";
3262 std::vector<decltype(range_pair)::first_type> range_vctor;
3264 for(
auto it = range_pair.first; it != range_pair.second; ++it) {
3265 range_vctor.push_back(it);
3266 it->info().mark_available();
3272 ERR_SERVER <<
"ERROR: delete_game(): Could not find user in players_.";
3279 for(
const auto& it : range_vctor) {
3286 for(
const auto& it : range_vctor) {
3290 leave_game_doc_reason.
child(
"leave_game")->
set_attr_dup(
"reason", reason.c_str());
3302 if(
auto p_desc =
g.changed_description()) {
3314 bool keep_alive =
false;
3316 srand(
static_cast<unsigned>(std::time(
nullptr)));
3318 std::string config_file;
3327 for(
int arg = 1; arg != argc; ++arg) {
3328 const std::string val(argv[arg]);
3333 if((val ==
"--config" || val ==
"-c") && arg + 1 != argc) {
3334 config_file = argv[++arg];
3335 }
else if(val ==
"--verbose" || val ==
"-v") {
3337 }
else if(val ==
"--dump-wml" || val ==
"-w") {
3339 }
else if(val.substr(0, 6) ==
"--log-") {
3340 std::size_t
p = val.find(
'=');
3341 if(
p == std::string::npos) {
3346 std::string
s = val.substr(6,
p - 6);
3351 }
else if(
s ==
"warning") {
3353 }
else if(
s ==
"info") {
3355 }
else if(
s ==
"debug") {
3362 while(
p != std::string::npos) {
3363 std::size_t q = val.find(
',',
p + 1);
3364 s = val.substr(
p + 1, q == std::string::npos ? q : q - (
p + 1));
3373 }
else if((val ==
"--port" || val ==
"-p") && arg + 1 != argc) {
3374 port = utils::from_chars<int>(argv[++arg]).value_or(0);
3375 }
else if(val ==
"--keepalive") {
3377 }
else if(val ==
"--help" || val ==
"-h") {
3378 std::cout <<
"usage: " << argv[0]
3379 <<
" [-dvwV] [-c path] [-p port]\n"
3380 <<
" -c, --config <path> Tells wesnothd where to find the config file to use.\n"
3381 <<
" -d, --daemon Runs wesnothd as a daemon.\n"
3382 <<
" -h, --help Shows this usage message.\n"
3383 <<
" --log-<level>=<domain1>,<domain2>,...\n"
3384 <<
" sets the severity level of the debug domains.\n"
3385 <<
" 'all' can be used to match any debug domain.\n"
3386 <<
" Available levels: error, warning, info, debug.\n"
3387 <<
" -p, --port <port> Binds the server to the specified port.\n"
3388 <<
" --keepalive Enable TCP keepalive.\n"
3389 <<
" -v --verbose Turns on more verbose logging.\n"
3390 <<
" -V, --version Returns the server version.\n"
3391 <<
" -w, --dump-wml Print all WML sent to clients to stdout.\n";
3393 }
else if(val ==
"--version" || val ==
"-V") {
3396 }
else if(val ==
"--daemon" || val ==
"-d") {
3398 ERR_SERVER <<
"Running as a daemon is not supported on this platform";
3401 const pid_t pid = fork();
3403 ERR_SERVER <<
"Could not fork and run as a daemon";
3405 }
else if(pid > 0) {
3406 std::cout <<
"Started wesnothd as a daemon with process id " << pid <<
"\n";
3412 }
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.
optional_config_impl< config > optional_child(std::string_view key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
child_itors child_range(std::string_view key)
bool has_child(std::string_view key) const
Determine whether a config has a child or not.
config & mandatory_child(std::string_view key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
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)
uint32_t get_next_random()
Get a new random number.
Base class for implementing servers that use gzipped-WML network protocol.
void async_send_warning(const SocketPtr &socket, const std::string &msg, const char *warning_code="", const info_table &info={})
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={})
boost::asio::ip::tcp::acceptor acceptor_v4_
std::unique_ptr< simple_wml::document > coro_receive_doc(const SocketPtr &socket, const boost::asio::yield_context &yield)
Receive WML document from a coroutine.
boost::asio::io_context io_service_
void async_send_doc_queued(const SocketPtr &socket, simple_wml::document &doc)
High level wrapper for sending a WML document.
boost::asio::posix::stream_descriptor input_
void load_tls_config(const config &cfg)
void coro_send_doc(const SocketPtr &socket, simple_wml::document &doc, const boost::asio::yield_context &yield)
Send a WML document from within a coroutine.
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 ...
banned_ptr get_ban_info(const std::string &ip)
void unban_group(std::ostringstream &os, const std::string &group)
const std::string & get_ban_help() const
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::set< int > & get_queues() const
const std::string & name() const
bool is_moderator() const
const std::string & source() const
utils::optional< server_base::login_ban_info > is_ip_banned(const std::string &ip)
void update_game_in_lobby(game &g, utils::optional< player_iterator > exclude={})
void send_to_lobby(simple_wml::document &data, utils::optional< player_iterator > exclude={})
void stopgame_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
std::unique_ptr< user_handler > user_handler_
void handle_leave_server_queue(player_iterator p, simple_wml::node &data)
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()
void load_config(bool reload)
Parse the server config into local variables.
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)
void stats_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
std::chrono::seconds dummy_player_timer_interval_
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 *)
void send_queue_update(const queue_info &queue, utils::optional< player_iterator > exclude={})
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_server_queue(player_iterator p, simple_wml::node &data)
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::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)
void reset_queues_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
std::string admin_passwd_
void motd_handler(const std::string &, const std::string &, std::string &, std::ostringstream *)
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.
std::map< int, queue_info > queue_info_
void login_client(boost::asio::yield_context yield, SocketPtr socket)
void handle_ping(player_iterator player, simple_wml::node &nickserv)
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)
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_SERVER_IP_BAN_ERROR
#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 serialize_timestamp(const std::chrono::system_clock::time_point &time)
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")
constexpr auto deconstruct_duration(const std::tuple< Ts... > &, const std::chrono::duration< Rep, Period > &span)
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
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.
config read(std::istream &in, abstract_validator *validator)
bool set_log_domain_severity(const std::string &name, severity severity)
std::string node_to_string(const node &n)
std::string lowercase(std::string_view s)
Returns a lowercased version of the 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::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in 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)
int stoi(std::string_view str)
Same interface as std::stoi and meant as a drop in replacement, except:
bool contains(const Container &container, const Value &value)
Returns true iff value is found in container.
bool wildcard_string_match(std::string_view str, std::string_view pat) noexcept
Performs pattern matching with wildcards.
void to_sql_wildcards(std::string &str, bool underscores)
Converts '*' to '' and optionally escapes '_'.
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)
auto * find(Container &container, const Value &value)
Convenience wrapper for using find on a container without needing to comare to end()
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="")
filesystem::scoped_istream preprocess_file(const std::string &fname, preproc_map &defines)
Function to use the WML preprocessor on a file.
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.
The base template for associating string values with enum values.
static constexpr utils::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
std::chrono::seconds duration
Ban duration (0 if permanent)
std::size_t players_required
std::vector< std::string > players_in_queue
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")