47 #include <boost/algorithm/string.hpp>
48 #include <boost/scope_exit.hpp>
67 #define ERR_SERVER LOG_STREAM(err, log_server)
70 #define WRN_SERVER LOG_STREAM(warn, log_server)
73 #define LOG_SERVER LOG_STREAM(info, log_server)
74 #define DBG_SERVER LOG_STREAM(debug, log_server)
77 #define ERR_CONFIG LOG_STREAM(err, log_config)
78 #define WRN_CONFIG LOG_STREAM(warn, log_config)
80 using namespace std::chrono_literals;
91 if(!out.
child(
"gamelist_diff")) {
104 assert(!children.empty());
107 index = children.size() - 1;
110 assert(
index <
static_cast<int>(children.size()));
117 const char* gamelist,
122 if(!out.
child(
"gamelist_diff")) {
136 if(itor == children.end()) {
140 const int index = std::distance(children.begin(), itor);
150 const char* gamelist,
155 if(!out.
child(
"gamelist_diff")) {
167 const auto itor =
std::find(children.begin(), children.end(), item);
169 if(itor == children.end()) {
176 const int index = std::distance(children.begin(), itor);
193 std::ostringstream out;
196 <<
d.count() <<
" days, "
197 <<
h.count() <<
" hours, "
198 << m.count() <<
" minutes, "
199 <<
s.count() <<
" seconds";
203 const std::string
denied_msg =
"You're not allowed to execute this command.";
205 "Available commands are: adminmsg <msg>,"
206 " ban <mask> <time> <reason>, bans [deleted] [<ipmask>], clones,"
207 " dul|deny_unregistered_login [yes|no], kick <mask> [<reason>],"
208 " k[ick]ban <mask> <time> <reason>, help, games, metrics,"
209 " [lobby]msg <message>, motd [<message>],"
210 " pm|privatemsg <nickname> <message>, requests, roll <sides>, sample, searchlog <mask>,"
211 " signout, stats, status [<mask>], stopgame <nick> [<reason>], reset_queues, unban <ipmask>\n"
212 "Specific strings (those not in between <> like the command names)"
213 " are case insensitive.";
215 server::server(
int port,
217 const std::string& config_file)
222 , user_handler_(nullptr)
223 , die_(static_cast<unsigned>(std::time(nullptr)))
228 , config_file_(config_file)
229 , cfg_(read_config())
230 , accepted_versions_()
231 , redirected_versions_()
233 , disallowed_names_()
240 , default_max_messages_(0)
241 , default_time_period_(0)
242 , concurrent_connections_(0)
243 , graceful_restart(false)
246 , max_ip_log_size_(0)
247 , deny_unregistered_login_(false)
248 , save_replays_(false)
249 , replay_save_path_()
250 , allow_remote_shutdown_(false)
253 , failed_login_limit_()
254 , failed_login_ban_()
255 , failed_login_buffer_size_()
260 , dump_stats_timer_(io_service_)
261 , tournaments_timer_(io_service_)
263 , timer_(io_service_)
264 , lan_server_timer_(io_service_)
265 , dummy_player_timer_(io_service_)
266 , dummy_player_timer_interval_(30)
283 WRN_SERVER <<
"SIGHUP caught, reloading config";
296 if(
games().empty()) {
297 process_command(
"msg All games ended. Shutting down now. Reconnect to the new server instance.",
"system");
328 if(res != 0 && errno != EEXIST) {
332 int fifo = open(
input_path_.c_str(), O_RDWR | O_NONBLOCK);
338 LOG_SERVER <<
"opened fifo at '" <<
input_path_ <<
"'. Server commands may be written to this file.";
348 std::cout << error.message() << std::endl;
354 std::getline(is, cmd);
361 if(!cmd.empty() && cmd.at(0) ==
'+') {
364 <<
"[/admin_command_response]";
376 #define SETUP_HANDLER(name, function) \
377 cmd_handlers_[name] = std::bind(function, this, \
378 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
439 #warning No FIFODIR set
440 #define FIFODIR "/var/run/wesnothd"
442 const std::string fifo_path
443 = (
cfg_[
"fifo_path"].
empty() ? std::string(
FIFODIR) +
"/socket" : std::string(
cfg_[
"fifo_path"]));
464 const config&
game = queue.mandatory_child(
"game");
465 queue_info q =
queue_info(queue[
"id"].to_int(),
game[
"scenario"].str(), queue[
"display_name"].str(), queue[
"players_required"].to_int(),
game);
469 std::map<int, queue_info> new_queue_info;
471 const config&
game = queue.mandatory_child(
"game");
472 queue_info q =
queue_info(queue[
"id"].to_int(),
game[
"scenario"].str(), queue[
"display_name"].str(), queue[
"players_required"].to_int(),
game);
473 new_queue_info.emplace(q.
id, q);
477 for(
auto& [
id,
info] : new_queue_info) {
482 update.set_attr_dup(
"action",
"add");
483 update.set_attr_dup(
"scenario_id",
info.scenario_id.c_str());
484 update.set_attr_dup(
"display_name",
info.display_name.c_str());
485 update.set_attr_int(
"players_required",
info.players_required);
498 update.set_attr_dup(
"action",
"update");
499 update.set_attr_dup(
"scenario_id",
info.scenario_id.c_str());
500 update.set_attr_dup(
"display_name",
info.display_name.c_str());
501 update.set_attr_int(
"players_required",
info.players_required);
509 if(new_queue_info.count(
id) == 0) {
513 update.set_attr_dup(
"action",
"remove");
533 for(
const std::string& source :
utils::split(
cfg_[
"client_sources"].str())) {
538 if(
cfg_[
"disallow_names"].empty()) {
569 const std::string& versions =
cfg_[
"versions_accepted"];
570 if(versions.empty() ==
false) {
586 for(
const std::string& version :
utils::split(proxy[
"version"])) {
602 ERR_SERVER <<
"The server id must be set when database support is used";
614 if(
cfg_[
"dummy_player_count"].to_int() > 0) {
615 for(
int i = 0;
i <
cfg_[
"dummy_player_count"].to_int();
i++) {
622 dummy_user.
set_attr_dup(
"name", (
"player"+std::to_string(
i)).c_str());
626 if(
cfg_[
"dummy_player_timer_interval"].to_int() > 0) {
639 std::size_t connections = 0;
641 if(
player.client_ip() == ip) {
658 server_ban_info->get_reason(),
659 server_ban_info->get_remaining_ban_time()
675 ERR_SERVER <<
"Error waiting for dump stats timer: " << ec.message();
679 <<
"\tnumber_of_games = " <<
games().size()
693 ERR_SERVER <<
"Error waiting for dummy player timer: " << ec.message();
736 ERR_SERVER <<
"Error waiting for tournament refresh timer: " << ec.message();
747 boost::asio::spawn(
io_service_, [socket,
this](boost::asio::yield_context yield) {
login_client(std::move(yield), socket); }
748 #if BOOST_VERSION >= 108000
749 , [](
const std::exception_ptr&
e) {
if (
e) std::rethrow_exception(
e); }
756 boost::asio::spawn(
io_service_, [socket,
this](boost::asio::yield_context yield) {
login_client(std::move(yield), socket); }
757 #if BOOST_VERSION >= 108000
758 , [](
const std::exception_ptr&
e) {
if (
e) std::rethrow_exception(
e); }
763 template<
class SocketPtr>
771 std::string client_version, client_source;
774 client_version = std::string { version_str_span.
begin(), version_str_span.
end() };
777 client_source = std::string { source_str_span.
begin(), source_str_span.
end() };
785 <<
":\ttelling them to log in.";
794 <<
":\tredirecting them to " << redirect_version.second[
"host"] <<
":"
795 << redirect_version.second[
"port"];
798 for(
const auto& attr : redirect_version.second.attribute_range()) {
799 redirect.set_attr_dup(attr.first.c_str(), attr.second.str().c_str());
808 <<
":\trejecting them";
823 std::string username;
824 bool registered, is_moderator;
831 username = (*login)[
"username"].to_string();
833 if(
is_login_allowed(yield, socket, login, username, registered, is_moderator)) {
856 assert(inserted &&
"unexpected duplicate username");
859 join_lobby_response.
root().
add_child(
"join_lobby").
set_attr(
"is_moderator", is_moderator ?
"yes" :
"no");
866 queue_node.
set_attr_dup(
"scenario_id", queue.scenario_id.c_str());
867 queue_node.
set_attr_dup(
"display_name", queue.display_name.c_str());
868 queue_node.
set_attr_int(
"players_required", queue.players_required);
874 [
this, socket, new_player](boost::asio::yield_context yield) {
handle_player(std::move(yield), socket, new_player); }
875 #if BOOST_VERSION >= 108000
876 , [](
const std::exception_ptr&
e) {
if (
e) std::rethrow_exception(
e); }
881 << (registered ?
" to a registered account" :
"");
883 std::shared_ptr<game> last_sent;
885 auto g_ptr = record.get_game();
886 if(g_ptr != last_sent) {
888 g_ptr->send_server_message_to_all(username +
" has logged into the lobby");
908 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)
913 "The nickname '" + username +
"' contains invalid "
914 "characters. Only alpha-numeric characters, underscores and hyphens are allowed.",
921 if(username.size() > 20) {
922 async_send_error(socket,
"The nickname '" + username +
"' is too long. Nicks must be 20 characters or less.",
931 async_send_error(socket,
"The nickname '" + username +
"' is reserved and cannot be used by players",
944 if(!
authenticate(socket, username, (*login)[
"password"].to_string(), name_taken, registered))
950 "The nickname '" + username +
"' is not registered. This server disallows unregistered nicknames.",
965 std::string ban_type_desc;
966 std::string ban_reason;
967 const char* msg_numeric;
968 std::string ban_duration = std::to_string(auth_ban.
duration.count());
970 switch(auth_ban.
type) {
972 ban_type_desc =
"account";
974 ban_reason =
"a ban has been issued on your user account.";
977 ban_type_desc =
"IP address";
979 ban_reason =
"a ban has been issued on your IP address.";
982 ban_type_desc =
"email address";
984 ban_reason =
"a ban has been issued on your email address.";
987 ban_type_desc =
"<unknown ban type>";
989 ban_reason = ban_type_desc;
992 ban_reason +=
" (" + ban_duration +
")";
995 LOG_SERVER <<
log_address(socket) <<
"\t" << username <<
"\tis banned by user_handler (" << ban_type_desc
999 async_send_error(socket,
"You are banned from this server: " + ban_reason, msg_numeric, {{
"duration", ban_duration}});
1002 async_send_error(socket,
"You are banned from this server: " + ban_reason, msg_numeric);
1006 LOG_SERVER <<
log_address(socket) <<
"\t" << username <<
"\tis banned by user_handler (" << ban_type_desc
1007 <<
"), " <<
"ignoring due to moderator flag";
1014 process_command(
"kick " + username +
" autokick by registered user", username);
1017 boost::asio::post(yield);
1026 send_server_message(socket,
"You are currently banned by the forum administration.",
"alert");
1033 SocketPtr socket,
const std::string& username,
const std::string& password,
bool name_taken,
bool& registered)
1049 "The nickname '" + username +
"' is inactive. You cannot claim ownership of this "
1050 "nickname until you activate your account via email or ask an administrator to do it for you.",
1053 const std::string salt =
user_handler_->extract_salt(username);
1056 "Even though your nickname is registered on this server you "
1057 "cannot log in due to an error in the hashing algorithm. "
1058 "Logging into your forum account on https://forums.wesnoth.org "
1059 "may fix this problem.");
1062 const std::string hashed_password =
hash_password(password, salt, username);
1065 if(password.empty()) {
1070 "The nickname '" + username +
"' is registered on this server."
1071 "\n\nWARNING: There is already a client using this username, "
1072 "logging in will cause that client to be kicked!",
1082 if(hashed_password.empty()) {
1087 else if(!(
user_handler_->login(username, hashed_password))) {
1088 const auto steady_now = std::chrono::steady_clock::now();
1114 "Maximum login attempts exceeded",
"automatic",
"", username);
1119 "The password you provided for the nickname '" + username +
"' was incorrect.",
1125 <<
"Login attempt with incorrect password for nickname '" << username <<
"'.";
1139 const std::string&
msg,
1140 const char* error_code,
1141 bool force_confirmation)
1145 e.set_attr_dup(
"message",
msg.c_str());
1146 e.set_attr(
"password_request",
"yes");
1147 e.set_attr(
"force_confirmation", force_confirmation ?
"yes" :
"no");
1149 if(*error_code !=
'\0') {
1150 e.set_attr(
"error_code", error_code);
1161 BOOST_SCOPE_EXIT_ALL(
this, &
player) {
1169 if(!
motd_.empty()) {
1191 if(doc->child(
"refresh_lobby")) {
1253 int offset = request->attr(
"offset").to_int();
1258 if(request->has_attr(
"search_player") && request->attr(
"search_player").to_string() !=
"") {
1259 std::string player_name = request->attr(
"search_player").to_string();
1264 player_id = player_ptr->info().config_address()->attr(
"forum_id").to_int();
1268 std::string search_game_name = request->attr(
"search_game_name").to_string();
1269 int search_content_type = request->attr(
"search_content_type").to_int();
1270 std::string search_content = request->attr(
"search_content").to_string();
1271 LOG_SERVER <<
"Querying game history requested by player `" <<
player->info().
name() <<
"` for player id `" << player_id <<
"`."
1272 <<
"Searching for game name `" << search_game_name <<
"`, search content type `" << search_content_type <<
"`, search content `" << search_content <<
"`.";
1273 user_handler_->async_get_and_send_game_history(
io_service_, *
this,
player->socket(), player_id, offset, search_game_name, search_content_type, search_content);
1281 if((whisper[
"receiver"].empty()) || (whisper[
"message"].empty())) {
1284 "message=\"Invalid number of arguments\"\n"
1285 "sender=\"server\"\n"
1294 whisper.set_attr_dup(
"sender",
player->
name().c_str());
1311 whisper.copy_into(trunc_whisper);
1323 const std::string command(query[
"type"].to_string());
1324 std::ostringstream response;
1326 const std::string& query_help_msg =
1327 "Available commands are: adminmsg <msg>, help, games, metrics,"
1328 " motd, requests, roll <sides>, sample, stats, status, version, wml.";
1331 if(command ==
"status") {
1334 command.compare(0, 8,
"adminmsg") == 0 ||
1335 command.compare(0, 6,
"report") == 0 ||
1336 command ==
"games" ||
1337 command ==
"metrics" ||
1338 command ==
"motd" ||
1339 command.compare(0, 7,
"version") == 0 ||
1340 command ==
"requests" ||
1341 command.compare(0, 4,
"roll") == 0 ||
1342 command ==
"sample" ||
1343 command ==
"stats" ||
1349 if(command ==
"signout") {
1353 response <<
"You are no longer recognized as an administrator.";
1358 LOG_SERVER <<
"Admin Command: type: " << command <<
"\tIP: " << iter->client_ip()
1363 }
else if(command ==
"help" || command.empty()) {
1364 response << query_help_msg;
1365 }
else if(command ==
"admin" || command.compare(0, 6,
"admin ") == 0) {
1372 if(command.size() >= 6) {
1373 passwd = command.substr(6);
1377 LOG_SERVER <<
"New Admin recognized: IP: " << iter->client_ip() <<
"\tnick: " <<
player.
name();
1380 response <<
"You are now recognized as an administrator.";
1386 WRN_SERVER <<
"FAILED Admin attempt with password: '" << passwd <<
"'\tIP: " << iter->client_ip()
1388 response <<
"Error: wrong password";
1391 response <<
"Error: unrecognized query: '" << command <<
"'\n" << query_help_msg;
1406 if(nickserv.
child(
"info")) {
1408 std::string res =
user_handler_->user_info((*nickserv.
child(
"info"))[
"name"].to_string());
1412 "There was an error looking up the details of the user '"
1413 + (*nickserv.
child(
"info"))[
"name"].to_string() +
"'. "
1414 +
" The error message was: " +
e.message,
"error"
1442 if(user->info().is_message_flooding()) {
1444 "Warning: you are sending too many messages too fast. Your message has not been relayed.",
"error");
1449 message.set_attr_dup(
"sender", user->name().c_str());
1452 message.copy_into(trunc_message);
1458 LOG_SERVER << user->client_ip() <<
"\t<" << user->name()
1461 LOG_SERVER << user->client_ip() <<
"\t<" << user->name() <<
"> " <<
msg;
1471 update.set_attr_int(
"queue_id", queue.
id);
1472 update.set_attr_dup(
"action",
"update");
1485 "This server is shutting down. You aren't allowed to make new games. Please "
1486 "reconnect to the new server.",
"error");
1492 const std::string game_name = create_game[
"name"].to_string();
1493 const std::string game_password = create_game[
"password"].to_string();
1494 const std::string initial_bans = create_game[
"ignored"].to_string();
1496 int queue_id = create_game[
"queue_id"].to_int();
1499 <<
"\tcreates a new game: \"" << game_name <<
"\".";
1512 DBG_SERVER <<
"initial bans: " << initial_bans;
1513 if(initial_bans !=
"") {
1517 if(game_password.empty() ==
false) {
1518 g.set_password(game_password);
1542 assert(gamelist !=
nullptr);
1555 const std::size_t
index = std::distance(
games.begin(),
g);
1559 LOG_SERVER <<
"Could not find game (" << game_ptr->
id() <<
", " << game_ptr->
db_id() <<
") to delete in games_and_users_list_.";
1569 int game_id =
join[
"id"].to_int();
1576 if(
game->q_type() == queue_type::type::client_preset &&
1578 join[
"mp_scenario"].to_string() ==
game->get_scenario_id() &&
1579 game->description()->child(
"slot_data")->attr(
"vacant").to_int() != 0) {
1580 game_id =
game->id();
1588 create_game_node.
set_attr_dup(
"mp_scenario",
join[
"mp_scenario"].to_string().c_str());
1606 const std::string& password =
join[
"password"].to_string();
1610 std::shared_ptr<game>
g;
1612 g = g_iter->get_game();
1618 <<
"\tattempted to join unknown game:\t" << game_id <<
".";
1623 }
else if(!
g->level_init()) {
1625 <<
"\tattempted to join uninitialized game:\t\"" <<
g->name() <<
"\" (" << game_id <<
").";
1634 <<
"\tReject banned player: " <<
player->info().
name()
1635 <<
"\tfrom game:\t\"" <<
g->name() <<
"\" (" << game_id <<
").";
1640 }
else if(!
g->password_matches(password)) {
1642 <<
"\tattempted to join game:\t\"" <<
g->name() <<
"\" (" << game_id <<
") with bad password";
1652 <<
"\tattempted to observe game:\t\"" <<
g->name() <<
"\" (" << game_id
1653 <<
") which doesn't allow observers.";
1657 "Attempt to observe a game that doesn't allow observers. (You probably joined the "
1658 "game shortly after it filled up.)",
"error");
1667 g->describe_slots();
1674 if(diff1 || diff2) {
1690 int queue_id =
data.attr(
"queue_id").to_int();
1693 ERR_SERVER <<
"player " <<
p->info().name() <<
" attempted to join non-existing server-side queue " <<
data.attr(
"queue_id");
1699 DBG_SERVER <<
"player " <<
p->info().name() <<
" already in server-side queue " <<
data.attr(
"queue_id");
1705 p->info().add_queue(queue.
id);
1719 game.set_attr_dup(
"scenario", queue.
settings[
"scenario"].str().c_str());
1720 game.set_attr_dup(
"era", queue.
settings[
"era"].str().c_str());
1721 game.set_attr_int(
"fog", queue.
settings[
"fog"].to_int());
1722 game.set_attr_int(
"shroud", queue.
settings[
"shroud"].to_int());
1723 game.set_attr_int(
"village_gold", queue.
settings[
"village_gold"].to_int());
1724 game.set_attr_int(
"village_support", queue.
settings[
"village_support"].to_int());
1725 game.set_attr_int(
"experience_modifier", queue.
settings[
"experience_modifier"].to_int());
1726 game.set_attr_int(
"countdown", queue.
settings[
"countdown"].to_int());
1727 game.set_attr_int(
"random_start_time", queue.
settings[
"random_start_time"].to_int());
1728 game.set_attr_int(
"shuffle_sides", queue.
settings[
"shuffle_sides"].to_int());
1734 if(
game->is_open_queue_game(queue.
id)) {
1748 int queue_id =
data.attr(
"queue_id").to_int();
1751 ERR_SERVER <<
"player " <<
p->info().name() <<
" attempted to leave non-existing server-side queue " <<
data.attr(
"queue_id");
1760 p->info().clear_queues();
1764 ERR_SERVER <<
"player " <<
p->info().name() <<
" already not in server-side queue " <<
data.attr(
"queue_id");
1774 game&
g = *(
p->get_game());
1775 std::weak_ptr<game> g_ptr{
p->get_game()};
1778 if(
data.child(
"snapshot") ||
data.child(
"scenario")) {
1779 if(!
g.is_owner(
p)) {
1789 if(!
g.level_init()) {
1791 <<
g.id() <<
", " <<
g.db_id() <<
").";
1795 assert(gamelist !=
nullptr);
1798 g.level().root().copy_into(desc);
1804 <<
g.name() <<
"\" (" <<
g.id() <<
", " <<
g.db_id() <<
") without a 'multiplayer' child.";
1806 g.set_description(&desc);
1810 "The scenario data is missing the [multiplayer] tag which contains the "
1811 "game settings. Game aborted.",
"error");
1815 g.set_description(&desc);
1819 <<
g.name() <<
"\" (" <<
g.id() <<
", " <<
g.db_id() <<
") although it's already initialized.";
1833 if(!
data[
"mp_shroud"].to_bool()) {
1838 if(!
e->attr(
"require_era").to_bool(
true)) {
1839 desc.
set_attr(
"require_era",
"no");
1843 if(
s[
"require_scenario"].to_bool(
false)) {
1844 desc.
set_attr(
"require_scenario",
"yes");
1853 desc.
child(
"modification")->
set_attr_dup(
"require_modification", m->attr(
"require_modification"));
1857 g.level().swap(
data);
1862 g.update_side_data();
1873 if(
g.q_type() == queue_type::type::server_preset) {
1874 int queue_id =
g.queue_id();
1875 int game_id =
g.id();
1882 std::size_t joined_count = 1;
1883 for(
const std::string& name :
info.players_in_queue) {
1895 for(
int queue : player_ptr->info().get_queues()) {
1903 if(joined_count ==
info.players_required) {
1917 }
else if(!
g.level_init()) {
1919 <<
" while the scenario wasn't yet initialized."
1924 if(!
g.is_owner(
p)) {
1928 if(!
g.level_init()) {
1930 <<
"\tsent [store_next_scenario] in game:\t\"" <<
g.name() <<
"\" (" <<
g.id()
1931 <<
", " <<
g.db_id() <<
") while the scenario is not yet initialized.";
1941 g.reset_last_synced_context_id();
1945 scenario->copy_into(
g.level().root());
1948 if(
g.description() ==
nullptr) {
1949 ERR_SERVER <<
p->client_ip() <<
"\tERROR: \"" <<
g.name() <<
"\" (" <<
g.id()
1950 <<
", " <<
g.db_id() <<
") is initialized but has no description_.";
1961 <<
g.name() <<
"\" (" <<
g.id() <<
", " <<
g.db_id() <<
") without a 'multiplayer' child.";
1966 "The scenario data is missing the [multiplayer] tag which contains the game "
1967 "settings. Game aborted.",
"error");
1974 desc.
set_attr_dup(
"map_data",
s[
"mp_shroud"].to_bool() ?
"" :
s[
"map_data"]);
1977 if(!
e->attr(
"require_era").to_bool(
true)) {
1978 desc.
set_attr(
"require_era",
"no");
1982 if(
s[
"require_scenario"].to_bool(
false)) {
1983 desc.
set_attr(
"require_scenario",
"yes");
1989 g.send_data(notify_next_scenario,
p);
1995 }
else if(
data.child(
"load_next_scenario")) {
1996 g.load_next_scenario(
p);
1998 }
else if(
data.child(
"start_game")) {
1999 if(!
g.is_owner(
p)) {
2004 g.perform_controller_tweaks();
2016 std::set<std::string> primary_keys;
2017 for(
const auto& addon : m.
children(
"addon")) {
2018 for(
const auto& content : addon->children(
"content")) {
2019 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();
2020 if(primary_keys.count(key) == 0) {
2021 primary_keys.emplace(key);
2022 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());
2023 if(rows_inserted == 0) {
2024 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() <<
"'";
2029 if(m.
children(
"addon").size() == 0) {
2030 WRN_SERVER <<
"Game content info missing for game with uuid '" <<
uuid_ <<
"', game ID '" <<
g.db_id() <<
"', named '" <<
g.name() <<
"'";
2033 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());
2036 for(
unsigned side_index = 0; side_index < sides.size(); ++side_index) {
2039 std::string version;
2058 std::vector<std::string> leaders;
2060 if(side.
attr(
"type") !=
"") {
2065 if(
unit->attr(
"canrecruit") ==
"yes") {
2066 leaders.emplace_back(
unit->attr(
"type").to_string());
2070 for(
const auto leader : side.
children(
"leader")) {
2071 leaders.emplace_back(leader->attr(
"type").to_string());
2074 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));
2081 }
else if(
data.child(
"leave_game")) {
2082 if(
g.remove_player(
p)) {
2085 bool has_diff =
false;
2092 if(
auto gStrong = g_ptr.lock()) {
2093 gStrong->describe_slots();
2114 update.set_attr_dup(
"action",
"update");
2123 if(!
g.is_owner(
p)) {
2127 g.level().root().apply_diff(*scenario_diff);
2131 g.update_side_data();
2140 }
else if(
data.child(
"change_faction")) {
2145 g.transfer_side_control(
p, *change);
2151 }
else if(
data.child(
"muteall")) {
2152 if(!
g.is_owner(
p)) {
2153 g.send_server_message(
"You cannot mute: not the game host.",
p);
2157 g.mute_all_observers();
2161 g.mute_observer(*mute,
p);
2165 g.unmute_observer(*unmute,
p);
2168 }
else if(
data.child(
"kick") ||
data.child(
"ban")) {
2169 bool ban = (
data.child(
"ban") !=
nullptr);
2171 ?
g.ban_user(*
data.child(
"ban"),
p)
2172 :
g.kick_member(*
data.child(
"kick"),
p)};
2193 g.unban_user(*unban,
p);
2197 if(!
g.is_player(
p)) {
2201 if((*
info)[
"type"] ==
"termination") {
2202 g.set_termination_reason((*
info)[
"condition"].to_string());
2203 if((*
info)[
"condition"].to_string() ==
"out of sync") {
2204 g.send_and_record_server_message(
player.
name() +
" reports out of sync errors.");
2212 }
else if(
data.child(
"turn")) {
2220 }
else if(
data.child(
"whiteboard")) {
2221 g.process_whiteboard(
data,
p);
2223 }
else if(
data.child(
"change_turns_wml")) {
2224 g.process_change_turns_wml(
data,
p);
2228 g.handle_choice(*sch,
p);
2230 }
else if(
data.child(
"message")) {
2231 g.process_message(
data,
p);
2233 }
else if(
data.child(
"stop_updates")) {
2238 data.child(
"error") ||
2239 data.child(
"side_secured") ||
2240 data.root().has_attr(
"failed") ||
2241 data.root().has_attr(
"side")
2247 <<
" in game: \"" <<
g.name() <<
"\" (" <<
g.id() <<
", " <<
g.db_id() <<
")\n"
2255 msg.set_attr(
"sender",
"server");
2256 msg.set_attr_esc(
"message", message);
2257 msg.set_attr_dup(
"type",
type.c_str());
2264 utils::visit([](
auto&& socket) {
2266 socket->async_shutdown([socket](...) {});
2267 const char buffer[] =
"";
2268 async_write(*socket, boost::asio::buffer(buffer), [socket](...) { socket->lowest_layer().close(); });
2270 socket->lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_receive);
2277 std::string ip = iter->client_ip();
2279 const std::shared_ptr<game>
g = iter->get_game();
2280 bool game_ended =
false;
2282 game_ended =
g->remove_player(iter,
true,
false);
2286 const std::size_t
index =
2287 std::distance(users.begin(),
std::find(users.begin(), users.end(), iter->info().config_address()));
2297 LOG_SERVER << ip <<
"\t" << iter->info().name() <<
"\thas logged off";
2301 user_handler_->db_update_logout(iter->info().get_login_id());
2307 i->log_off = std::chrono::system_clock::now();
2312 if(!queue.players_in_queue.empty()) {
2313 queue.players_in_queue.erase(
std::remove(queue.players_in_queue.begin(), queue.players_in_queue.end(), iter->info().name()));
2375 if(issuer_name ==
"*socket*" && !query.empty() && query.at(0) ==
'+') {
2379 auto issuer_end =
std::find(query.begin(), query.end(),
':');
2381 std::string issuer(query.begin() + 1, issuer_end);
2382 if(!issuer.empty()) {
2383 issuer_name =
"+" + issuer +
"+";
2384 query = std::string(issuer_end + 1, query.end());
2389 const auto i =
std::find(query.begin(), query.end(),
' ');
2392 const std::string command =
utf8::lowercase(std::string(query.begin(),
i));
2394 std::string parameters = (
i == query.end() ?
"" : std::string(
i + 1, query.end()));
2397 std::ostringstream out;
2401 out <<
"Command '" << command <<
"' is not recognized.\n" <<
help_msg;
2403 const cmd_handler& handler = handler_itor->second;
2405 handler(issuer_name, query, parameters, &out);
2406 }
catch(
const std::bad_function_call& ex) {
2407 ERR_SERVER <<
"While handling a command '" << command
2408 <<
"', caught a std::bad_function_call exception.";
2410 out <<
"An internal server error occurred (std::bad_function_call) while executing '" << command
2418 std::string
msg =
"While handling a command, caught an invalid utf8 exception: ";
2421 return (
msg +
'\n');
2427 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2429 assert(out !=
nullptr);
2436 if(parameters ==
"now") {
2448 "msg The server is shutting down. You may finish your games but can't start new ones. Once all "
2449 "games have ended the server will exit.",
2453 *out <<
"Server is doing graceful shut down.";
2458 const std::string& ,
2460 std::ostringstream* out)
2462 assert(out !=
nullptr);
2470 *out <<
"No restart_command configured! Not restarting.";
2481 "msg The server has been restarted. You may finish current games but can't start new ones and "
2482 "new players can't join this (old) server instance. (So if a player of your game disconnects "
2483 "you have to save, reconnect and reload the game on the new server instance. It is actually "
2484 "recommended to do that right away.)",
2488 *out <<
"New server started.";
2493 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2495 assert(out !=
nullptr);
2497 if(parameters.empty()) {
2500 }
else if(issuer_name !=
"*socket*") {
2507 *out <<
"Sampling turned off.";
2514 const std::string& ,
2516 std::ostringstream* out)
2518 assert(out !=
nullptr);
2523 const std::string& ,
2525 std::ostringstream* out)
2527 assert(out !=
nullptr);
2533 const std::string& ,
2535 std::ostringstream* out)
2537 assert(out !=
nullptr);
2542 const std::string& ,
2544 std::ostringstream* out)
2546 assert(out !=
nullptr);
2551 const std::string& ,
2552 std::string& parameters,
2553 std::ostringstream* out)
2555 assert(out !=
nullptr);
2556 if(parameters.empty()) {
2563 }
catch(
const std::invalid_argument&) {
2564 *out <<
"The number of die sides must be a number!";
2566 }
catch(
const std::out_of_range&) {
2567 *out <<
"The number of sides is too big for the die!";
2572 *out <<
"The die cannot have less than 1 side!";
2575 std::uniform_int_distribution<int> dice_distro(1, N);
2576 std::string value = std::to_string(dice_distro(
die_));
2578 *out <<
"You rolled a die [1 - " + parameters +
"] and got a " + value +
".";
2585 auto g_ptr = player_ptr->get_game();
2587 g_ptr->send_server_message_to_all(issuer_name +
" rolled a die [1 - " + parameters +
"] and got a " + value +
".",
player_connections_.project<0>(player_ptr));
2589 *out <<
" (The result is shown to others only in a game.)";
2594 const std::string& ,
2596 std::ostringstream* out)
2598 assert(out !=
nullptr);
2603 const std::string& ,
2605 std::ostringstream* out)
2607 assert(out !=
nullptr);
2612 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2614 assert(out !=
nullptr);
2616 if(parameters.empty()) {
2617 *out <<
"You must type a message.";
2621 const std::string& sender = issuer_name;
2622 const std::string& message = parameters;
2624 << (message.find(
"/me ") == 0 ? std::string(message.begin() + 3, message.end()) +
">" :
"> " + message);
2628 msg.set_attr_dup(
"sender", (
"admin message from " + sender).c_str());
2629 msg.set_attr_dup(
"message", message.c_str());
2639 bool is_admin =
false;
2649 *out <<
"Your report has been logged and sent to the server administrators. Thanks!";
2653 *out <<
"Your report has been logged and sent to " <<
n <<
" online administrators. Thanks!";
2657 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2659 assert(out !=
nullptr);
2661 auto first_space =
std::find(parameters.begin(), parameters.end(),
' ');
2662 if(first_space == parameters.end()) {
2663 *out <<
"You must name a receiver.";
2667 const std::string& sender = issuer_name;
2668 const std::string receiver(parameters.begin(), first_space);
2670 std::string message(first_space + 1, parameters.end());
2673 if(message.empty()) {
2674 *out <<
"You must type a message.";
2682 msg.set_attr_dup(
"sender", (
"server message from " + sender).c_str());
2683 msg.set_attr_dup(
"message", message.c_str());
2686 if(receiver !=
player.info().
name().c_str()) {
2691 *out <<
"Message to " << receiver <<
" successfully sent.";
2695 *out <<
"No such nick: " << receiver;
2699 const std::string& ,
2700 std::string& parameters,
2701 std::ostringstream* out)
2703 assert(out !=
nullptr);
2705 if(parameters.empty()) {
2706 *out <<
"You must type a message.";
2713 << (parameters.find(
"/me ") == 0
2714 ? std::string(parameters.begin() + 3, parameters.end()) +
">"
2715 :
"> " + parameters);
2717 *out <<
"message '" << parameters <<
"' relayed to players";
2721 const std::string& ,
2722 std::string& parameters,
2723 std::ostringstream* out)
2725 assert(out !=
nullptr);
2727 if(parameters.empty()) {
2728 *out <<
"You must type a message.";
2734 << (parameters.find(
"/me ") == 0
2735 ? std::string(parameters.begin() + 3, parameters.end()) +
">"
2736 :
"> " + parameters);
2738 *out <<
"message '" << parameters <<
"' relayed to players";
2742 const std::string& ,
const std::string& , std::string& parameters, std::ostringstream* out)
2744 assert(out !=
nullptr);
2746 if(parameters.empty()) {
2753 *out <<
"Player " << parameters <<
" is using wesnoth " <<
player.info().
version();
2758 *out <<
"Player '" << parameters <<
"' not found.";
2762 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2764 assert(out !=
nullptr);
2766 *out <<
"STATUS REPORT for '" << parameters <<
"'";
2767 bool found_something =
false;
2773 parameters =
player.client_ip();
2774 found_something =
true;
2779 if(!found_something) {
2787 const bool match_ip = ((std::count(parameters.begin(), parameters.end(),
'.') >= 1) || (std::count(parameters.begin(), parameters.end(),
':') >= 1));
2789 if(parameters.empty() || parameters ==
"*" ||
2793 found_something =
true;
2798 if(!found_something) {
2799 *out <<
"\nNo match found. You may want to check with 'searchlog'.";
2804 const std::string& ,
2806 std::ostringstream* out)
2808 assert(out !=
nullptr);
2809 *out <<
"CLONES STATUS REPORT";
2811 std::set<std::string> clones;
2814 if(clones.find(it->client_ip()) != clones.end()) {
2820 if(it->client_ip() == clone->client_ip()) {
2823 clones.insert(it->client_ip());
2832 if(clones.empty()) {
2833 *out << std::endl <<
"No clones found.";
2838 const std::string& ,
2839 std::string& parameters,
2840 std::ostringstream* out)
2842 assert(out !=
nullptr);
2845 if(parameters.empty()) {
2850 std::string mask = parameters.substr(7);
2858 ERR_SERVER <<
"While handling bans, caught an invalid utf8 exception: " <<
e.what();
2863 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2865 assert(out !=
nullptr);
2868 auto first_space =
std::find(parameters.begin(), parameters.end(),
' ');
2870 if(first_space == parameters.end()) {
2875 auto second_space =
std::find(first_space + 1, parameters.end(),
' ');
2876 const std::string target(parameters.begin(), first_space);
2877 const std::string duration(first_space + 1, second_space);
2885 if(second_space == parameters.end()) {
2889 std::string reason(second_space + 1, parameters.end());
2892 if(reason.empty()) {
2893 *out <<
"You need to give a reason for the ban.";
2897 std::string dummy_group;
2901 if(std::count(target.begin(), target.end(),
'.') >= 1) {
2904 *out <<
ban_manager_.
ban(target, parsed_time, reason, issuer_name, dummy_group);
2914 const std::string ip =
player.client_ip();
2915 *out <<
ban_manager_.
ban(ip, parsed_time, reason, issuer_name, dummy_group, target);
2920 *out <<
"Nickname mask '" << target <<
"' did not match, no bans set.";
2926 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
2928 assert(out !=
nullptr);
2931 auto first_space =
std::find(parameters.begin(), parameters.end(),
' ');
2932 if(first_space == parameters.end()) {
2937 auto second_space =
std::find(first_space + 1, parameters.end(),
' ');
2938 const std::string target(parameters.begin(), first_space);
2939 const std::string duration(first_space + 1, second_space);
2947 if(second_space == parameters.end()) {
2951 std::string reason(second_space + 1, parameters.end());
2954 if(reason.empty()) {
2955 *out <<
"You need to give a reason for the ban.";
2959 std::string dummy_group;
2960 std::vector<player_iterator> users_to_kick;
2964 if(std::count(target.begin(), target.end(),
'.') >= 1) {
2967 *out <<
ban_manager_.
ban(target, parsed_time, reason, issuer_name, dummy_group);
2971 users_to_kick.push_back(
player);
2983 const std::string ip =
player->client_ip();
2984 *out <<
ban_manager_.
ban(ip, parsed_time, reason, issuer_name, dummy_group, target);
2985 users_to_kick.push_back(
player);
2990 *out <<
"Nickname mask '" << target <<
"' did not match, no bans set.";
2994 for(
auto user : users_to_kick) {
2995 *out <<
"\nKicked " << user->info().name() <<
" (" << user->client_ip() <<
").";
2996 utils::visit([
this,reason](
auto&& socket) {
async_send_error(socket,
"You have been banned. Reason: " + reason); }, user->socket());
3002 const std::string& issuer_name,
const std::string& , std::string& parameters, std::ostringstream* out)
3004 assert(out !=
nullptr);
3007 auto first_space =
std::find(parameters.begin(), parameters.end(),
' ');
3008 if(first_space == parameters.end()) {
3013 auto second_space =
std::find(first_space + 1, parameters.end(),
' ');
3014 const std::string target(parameters.begin(), first_space);
3016 std::string group = std::string(first_space + 1, second_space);
3017 first_space = second_space;
3018 second_space =
std::find(first_space + 1, parameters.end(),
' ');
3020 const std::string duration(first_space + 1, second_space);
3028 if(second_space == parameters.end()) {
3032 std::string reason(second_space + 1, parameters.end());
3035 if(reason.empty()) {
3036 *out <<
"You need to give a reason for the ban.";
3042 if(std::count(target.begin(), target.end(),
'.') >= 1) {
3045 *out <<
ban_manager_.
ban(target, parsed_time, reason, issuer_name, group);
3055 const std::string ip =
player.client_ip();
3056 *out <<
ban_manager_.
ban(ip, parsed_time, reason, issuer_name, group, target);
3061 *out <<
"Nickname mask '" << target <<
"' did not match, no bans set.";
3067 const std::string& ,
3068 std::string& parameters,
3069 std::ostringstream* out)
3071 assert(out !=
nullptr);
3073 if(parameters.empty()) {
3074 *out <<
"You must enter an ipmask to unban.";
3082 const std::string& ,
3083 std::string& parameters,
3084 std::ostringstream* out)
3086 assert(out !=
nullptr);
3088 if(parameters.empty()) {
3089 *out <<
"You must enter an ipmask to ungban.";
3097 const std::string& ,
3098 std::string& parameters,
3099 std::ostringstream* out)
3101 assert(out !=
nullptr);
3103 if(parameters.empty()) {
3104 *out <<
"You must enter a mask to kick.";
3108 auto i =
std::find(parameters.begin(), parameters.end(),
' ');
3109 const std::string kick_mask = std::string(parameters.begin(),
i);
3110 const std::string kick_message = (
i == parameters.end()
3111 ?
"You have been kicked."
3112 :
"You have been kicked. Reason: " + std::string(
i + 1, parameters.end()));
3114 bool kicked =
false;
3117 const bool match_ip = (std::count(kick_mask.begin(), kick_mask.end(),
'.') >= 1);
3119 std::vector<player_iterator> users_to_kick;
3124 users_to_kick.push_back(
player);
3128 for(
const auto&
player : users_to_kick) {
3135 *out <<
"Kicked " <<
player->
name() <<
" (" <<
player->client_ip() <<
"). '"
3136 << kick_message <<
"'";
3138 utils::visit([
this, &kick_message](
auto&& socket) {
async_send_error(socket, kick_message); },
player->socket());
3143 *out <<
"No user matched '" << kick_mask <<
"'.";
3148 const std::string& ,
3149 std::string& parameters,
3150 std::ostringstream* out)
3152 assert(out !=
nullptr);
3154 if(parameters.empty()) {
3155 if(!
motd_.empty()) {
3156 *out <<
"Message of the day:\n" <<
motd_;
3159 *out <<
"No message of the day set.";
3165 *out <<
"Message of the day set to: " <<
motd_;
3169 const std::string& ,
3170 std::string& parameters,
3171 std::ostringstream* out)
3173 assert(out !=
nullptr);
3175 if(parameters.empty()) {
3176 *out <<
"You must enter a mask to search for.";
3180 *out <<
"IP/NICK LOG for '" << parameters <<
"'";
3184 const bool match_ip = (std::count(parameters.begin(), parameters.end(),
'.') >= 1);
3187 bool found_something =
false;
3190 const std::string& username =
i.nick;
3191 const std::string& ip =
i.ip;
3196 found_something =
true;
3202 *out <<
"\n'" << username <<
"' @ " << ip
3208 if(!found_something) {
3209 *out <<
"\nNo match found.";
3222 const std::string& ,
3223 std::string& parameters,
3224 std::ostringstream* out)
3226 assert(out !=
nullptr);
3229 if(parameters.empty()) {
3237 ERR_SERVER <<
"While handling dul (deny unregistered logins), caught an invalid utf8 exception: " <<
e.what();
3242 const std::string& ,
3243 std::string& parameters,
3244 std::ostringstream* out)
3246 assert(out !=
nullptr);
3248 const std::string nick = parameters.substr(0, parameters.find(
' '));
3249 const std::string reason = parameters.length() > nick.length()+1 ? parameters.substr(nick.length()+1) :
"";
3253 std::shared_ptr<game>
g =
player->get_game();
3255 *out <<
"Player '" << nick <<
"' is in game with id '" <<
g->id() <<
", " <<
g->db_id() <<
"' named '" <<
g->name() <<
"'. Ending game for reason: '" << reason <<
"'...";
3258 *out <<
"Player '" << nick <<
"' is not currently in a game.";
3261 *out <<
"Player '" << nick <<
"' is not currently logged in.";
3266 const std::string& ,
3268 std::ostringstream* out)
3270 assert(out !=
nullptr);
3277 queue.players_in_queue.clear();
3281 *out <<
"Reset all queues";
3291 std::vector<decltype(range_pair)::first_type> range_vctor;
3293 for(
auto it = range_pair.first; it != range_pair.second; ++it) {
3294 range_vctor.push_back(it);
3295 it->info().mark_available();
3301 ERR_SERVER <<
"ERROR: delete_game(): Could not find user in players_.";
3308 for(
const auto& it : range_vctor) {
3315 for(
const auto& it : range_vctor) {
3319 leave_game_doc_reason.
child(
"leave_game")->
set_attr_dup(
"reason", reason.c_str());
3331 if(
auto p_desc =
g.changed_description()) {
3343 bool keep_alive =
false;
3345 srand(
static_cast<unsigned>(std::time(
nullptr)));
3347 std::string config_file;
3356 for(
int arg = 1; arg != argc; ++arg) {
3357 const std::string val(argv[arg]);
3362 if((val ==
"--config" || val ==
"-c") && arg + 1 != argc) {
3363 config_file = argv[++arg];
3364 }
else if(val ==
"--verbose" || val ==
"-v") {
3366 }
else if(val ==
"--dump-wml" || val ==
"-w") {
3368 }
else if(val.substr(0, 6) ==
"--log-") {
3369 std::size_t
p = val.find(
'=');
3370 if(
p == std::string::npos) {
3375 std::string
s = val.substr(6,
p - 6);
3380 }
else if(
s ==
"warning") {
3382 }
else if(
s ==
"info") {
3384 }
else if(
s ==
"debug") {
3391 while(
p != std::string::npos) {
3392 std::size_t q = val.find(
',',
p + 1);
3393 s = val.substr(
p + 1, q == std::string::npos ? q : q - (
p + 1));
3402 }
else if((val ==
"--port" || val ==
"-p") && arg + 1 != argc) {
3403 port = atoi(argv[++arg]);
3404 }
else if(val ==
"--keepalive") {
3406 }
else if(val ==
"--help" || val ==
"-h") {
3407 std::cout <<
"usage: " << argv[0]
3408 <<
" [-dvwV] [-c path] [-p port]\n"
3409 <<
" -c, --config <path> Tells wesnothd where to find the config file to use.\n"
3410 <<
" -d, --daemon Runs wesnothd as a daemon.\n"
3411 <<
" -h, --help Shows this usage message.\n"
3412 <<
" --log-<level>=<domain1>,<domain2>,...\n"
3413 <<
" sets the severity level of the debug domains.\n"
3414 <<
" 'all' can be used to match any debug domain.\n"
3415 <<
" Available levels: error, warning, info, debug.\n"
3416 <<
" -p, --port <port> Binds the server to the specified port.\n"
3417 <<
" --keepalive Enable TCP keepalive.\n"
3418 <<
" -v --verbose Turns on more verbose logging.\n"
3419 <<
" -V, --version Returns the server version.\n"
3420 <<
" -w, --dump-wml Print all WML sent to clients to stdout.\n";
3422 }
else if(val ==
"--version" || val ==
"-V") {
3425 }
else if(val ==
"--daemon" || val ==
"-d") {
3427 ERR_SERVER <<
"Running as a daemon is not supported on this platform";
3430 const pid_t pid = fork();
3432 ERR_SERVER <<
"Could not fork and run as a daemon";
3434 }
else if(pid > 0) {
3435 std::cout <<
"Started wesnothd as a daemon with process id " << pid <<
"\n";
3441 }
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.
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
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.
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")