32 #define ERR_GAME LOG_STREAM(err, log_server) 33 #define WRN_GAME LOG_STREAM(warn, log_server) 34 #define LOG_GAME LOG_STREAM(info, log_server) 35 #define DBG_GAME LOG_STREAM(debug, log_server) 38 #define WRN_CONFIG LOG_STREAM(warn, log_config) 45 res.push_back(span.
to_int());
49 template<
typename TResult,
typename TConvert>
52 std::vector<TResult> res;
57 while(i2 != val.
end()) {
80 const std::string& name,
82 const std::string& replay_save_path)
84 , player_connections_(player_connections)
99 , description_(nullptr)
101 , current_side_index_(0)
103 , all_observers_muted_(false)
106 , players_not_advanced_()
108 , save_replays_(save_replays)
109 , replay_save_path_(replay_save_path)
111 , last_choice_request_id_(-1)
130 }
catch(
const boost::coroutines::detail::forced_unwind&) {
131 ERR_GAME <<
"Caught forced_unwind in game destructor!";
143 ERR_GAME <<
"no [multiplayer] found. Returning root";
178 return iter->info().name();
185 for(
auto user : users) {
190 list += user->info().name();
200 DBG_GAME <<
"****\n Performing controller tweaks. sides = ";
206 for(
unsigned side_index = 0; side_index < sides.size(); ++side_index) {
209 if(side[
"controller"] != side_controller::none) {
212 std::stringstream
msg;
213 msg <<
"Side " << side_index + 1
214 <<
" had no controller during controller tweaks! The host was assigned control.";
235 std::stringstream
msg;
236 msg <<
"Side " << side_index + 1 <<
" had no controller AFTER controller tweaks! Ruh Roh!";
254 DBG_GAME <<
"****\n Starting game. sides = ";
264 const bool save = multiplayer[
"savegame"].to_bool();
266 << starter->client_ip() <<
"\t" << starter->name() <<
"\t" 267 << (advance ?
"advanced" :
"started") << (save ?
" reloaded" :
"") <<
" game:\t\"" <<
name_ <<
"\" (" <<
id_ 269 <<
". Settings: map: " << multiplayer[
"mp_scenario"]
270 <<
"\tera: " << multiplayer[
"mp_era"]
271 <<
"\tXP: " << multiplayer[
"experience_modifier"]
272 <<
"\tGPV: " << multiplayer[
"mp_village_gold"]
273 <<
"\tfog: " << multiplayer[
"mp_fog"]
274 <<
"\tshroud: " << multiplayer[
"mp_shroud"]
275 <<
"\tobservers: " << multiplayer[
"observer"]
276 <<
"\tshuffle: " << multiplayer[
"shuffle_sides"]
277 <<
"\ttimer: " << multiplayer[
"mp_countdown"]
278 << (multiplayer[
"mp_countdown"].to_bool()
279 ?
"\treservoir time: " + multiplayer[
"mp_countdown_reservoir_time"].to_string()
280 +
"\tinit time: " + multiplayer[
"mp_countdown_init_time"].to_string()
281 +
"\taction bonus: " + multiplayer[
"mp_countdown_action_bonus"].to_string()
282 +
"\tturn bonus: " + multiplayer[
"mp_countdown_turn_bonus"].to_string()
286 for(
unsigned side_index = 0; side_index < sides.size(); ++side_index) {
289 if(side[
"controller"] != side_controller::none) {
290 if(side_index >=
sides_.size()) {
295 std::stringstream
msg;
296 msg <<
"Side " << side_index + 1
297 <<
" has no controller but should! The host needs to assign control for the game to proceed past " 312 turn = lexical_cast_default<int>((*snapshot)[
"turn_at"], 1);
313 side = lexical_cast_default<int>((*snapshot)[
"playing_team"], 0);
314 LOG_GAME <<
"Reload from turn: " << turn <<
". Current side is: " << side + 1 <<
".";
329 const std::size_t side_index = (*side)[
"side"].to_int() - 1;
332 if(side_index >=
sides_.size()) {
365 if(((*side)[
"controller"] == side_controller::human || (*side)[
"controller"] == side_controller::reserved)
366 && (*side)[
"current_player"] == user->name().c_str()) {
376 if((*side)[
"controller"] == side_controller::human) {
383 DBG_GAME <<
"take_side: there are no more sides available";
426 for(
auto iter : users) {
428 bool side_found =
false;
429 for(
unsigned side_index = 0; side_index < level_sides.size(); ++side_index) {
440 if(player_id == iter->info().name().c_str()) {
442 if(controller != side_controller::human && controller != side_controller::ai) {
449 sides_[side_index] = iter;
451 }
else if(iter ==
owner_ && controller == side_controller::none) {
474 DBG_GAME <<
"transfer_side_control...";
482 const unsigned int side_num = cfg[
"side"].to_int();
483 if(side_num < 1 || side_num >
sides_.size()) {
484 std::ostringstream
msg;
485 msg <<
"The side number has to be between 1 and " <<
sides_.size() <<
".";
496 auto old_player =
sides_[side_num - 1];
497 const std::string& controller_type = cfg[
"to"].to_string();
499 const std::string old_player_name = old_player ?
username(*old_player) :
"null";
502 if(newplayer_name.
empty()) {
503 std::stringstream
msg;
504 msg <<
"Received invalid [change_controller] with no player= attribute specified";
511 if(!(player == old_player || player ==
owner_)) {
512 std::stringstream
msg;
513 msg <<
"You can't give away side " << side_num <<
". It's controlled by '" << old_player_name <<
"' not you.";
520 auto newplayer {
find_user(newplayer_name) };
523 if(!newplayer || !
is_member(*newplayer)) {
528 if(newplayer == old_player) {
534 std::stringstream
msg;
535 msg <<
"Side " << side_num <<
" is already controlled by " << newplayer_name <<
".";
545 sides_[side_num - 1].reset();
576 const std::size_t side_index,
player_iterator player,
const std::string& player_name,
const bool player_left)
580 const std::string& side = lexical_cast_default<std::string, std::size_t>(side_index + 1);
581 sides_[side_index] = player;
602 response->root().child(
"change_controller")->set_attr(
"is_local",
"yes");
609 const std::string& side = std::to_string(side_index + 1);
620 return response.
clone();
629 std::string message = owner_name +
" has been chosen as the new host.";
640 int available_slots = 0;
645 if(((*side)[
"allow_player"].to_bool(
true) ==
false) || (*side)[
"controller"] == side_controller::none) {
667 auto ban = std::find(
bans_.begin(),
bans_.end(), player->client_ip());
703 if(username.
empty()) {
730 << (*user)->client_ip() <<
")\tin game:\t\"" <<
name_ <<
"\" (" <<
id_ <<
", " <<
db_id_ <<
")";
744 if(username.
empty()) {
762 << (*user)->client_ip() <<
")\tin game:\t\"" <<
name_ <<
"\" (" <<
id_ <<
", " <<
db_id_ <<
")";
787 }
else if(user == kicker) {
790 }
else if((*user)->info().is_moderator()) {
796 << (*user)->client_ip() <<
")\tfrom game:\t\"" <<
name_ <<
"\" (" <<
id_ <<
", " <<
db_id_ <<
")";
819 }
else if(user == banner) {
825 }
else if((*user)->info().is_moderator()) {
831 << (*user)->client_ip() <<
")\tfrom game:\t\"" <<
name_ <<
"\" (" <<
id_ <<
", " <<
db_id_ <<
")";
833 bans_.push_back((*user)->client_ip());
869 << unbanner->client_ip() <<
"\t" << unbanner->info().name()
870 <<
"\tunbanned: " << username <<
" (" << (*user)->client_ip() <<
")\tfrom game:\t\"" <<
name_ <<
"\" (" 882 message->
set_attr_dup(
"sender", user->info().name().c_str());
893 const bool is_host = user ==
owner_;
897 const std::size_t from_side_index = command[
"from_side"].to_int() - 1;
900 if(command[
"from_side"] ==
"server") {
904 if(from_side_index >=
sides_.size() ||
sides_[from_side_index] != user) {
921 if(command.
child(
"speak")) {
924 if(command.
child(
"surrender")) {
939 if(is_player && command.
has_attr(
"dependent") && command.
has_attr(
"from_side")) {
943 if((is_player || is_host) && (
944 command.
child(
"label") ||
945 command.
child(
"clear_labels") ||
946 command.
child(
"rename") ||
947 command.
child(
"countdown_update")
963 bool turn_ended =
false;
968 bool repackage =
false;
970 std::vector<int> marked;
975 DBG_GAME <<
"game " <<
id_ <<
", " <<
db_id_ <<
" received [" << (*command).first_child() <<
"] from player '" <<
username(user)
981 std::stringstream
msg;
982 msg <<
"Removing illegal command '" << (*command).first_child().to_string() <<
"' from: " <<
username(user)
988 marked.push_back(index - marked.size());
989 }
else if((*command).child(
"speak")) {
1005 const std::size_t side_index = speak[
"side"].to_int() - 1;
1007 if(side_index >=
sides_.size() ||
sides_[side_index] != user) {
1011 const auto s = std::find(
sides_.begin(),
sides_.end(), user);
1012 speak.
set_attr_dup(
"side", lexical_cast_default<std::string>(
s -
sides_.begin() + 1).c_str());
1016 }
else if (command->child(
"surrender")) {
1017 std::size_t side_index = 0;
1026 if(side_index < sides_.size()) {
1028 std::string playername;
1033 auto new_side_index = (side_index + 1) % sides_.size();
1034 auto new_owner = sides_[new_side_index];
1036 new_side_index = (new_side_index + 1) % sides_.size();
1037 if(new_side_index == side_index) {
1038 ERR_GAME <<
"Ran out of sides to surrender to.";
1041 new_owner = sides_[new_side_index];
1054 turn_ended =
end_turn(endturn[
"next_player_number"].to_int());
1060 for(
const int j : marked) {
1076 if(speak ==
nullptr) {
1077 auto mdata = std::make_unique<simple_wml::document>();
1079 (*command).
copy_into(mturn.add_child(
"command"));
1093 auto message = std::make_unique<simple_wml::document>();
1096 message_turn_command.
set_attr(
"undo",
"no");
1099 if(to_sides.
empty()) {
1117 std::stringstream stream;
1118 stream << std::setfill(
'0') << std::setw(
sizeof(uint32_t) * 2) << std::hex << seed;
1120 auto mdata = std::make_unique<simple_wml::document>();
1125 random_seed.
set_attr_dup(
"new_seed", stream.str().c_str());
1127 command.
set_attr(
"from_side",
"server");
1128 command.
set_attr(
"dependent",
"yes");
1143 const std::size_t side_index = req[
"side"].to_int() - 1;
1147 if(!new_controller) {
1149 "Could not handle [request_choice] [change_controller] with invalid controller '" + req[
"new_controller"].to_string() +
"'");
1153 if(!old_controller) {
1155 "Could not handle [request_choice] [change_controller] with invalid controller '" + req[
"old_controller"].to_string() +
"'");
1161 "Found unexpected old_controller= '" +
side_controller::get_string(*old_controller) +
"' in [request_choice] [change_controller]");
1164 if(side_index >=
sides_.size()) {
1166 "Could not handle [request_choice] [change_controller] with invalid side '" + req[
"side"].to_string() +
"'");
1170 const bool was_null = this->
side_controllers_[side_index] == side_controller::type::none;
1171 const bool becomes_null = new_controller == side_controller::type::none;
1174 assert(!
sides_[side_index]);
1179 sides_[side_index].reset();
1184 auto mdata = std::make_unique<simple_wml::document>();
1190 change_controller_wml.
set_attr(
"is_local",
"yes");
1192 command.
set_attr(
"from_side",
"server");
1193 command.
set_attr(
"dependent",
"yes");
1199 change_controller_wml.
set_attr(
"is_local",
"no");
1228 int request_id = lexical_cast_default<int>(data[
"request_id"], -10);
1234 DBG_GAME <<
"answering choice request " << request_id <<
" by player " 1235 << user->info().name();
1238 if(data.child(
"random_seed")) {
1242 }
else if(data.child(
"add_side_wml")) {
1259 std::size_t
const side_index = wb_node[
"side"].to_int() - 1;
1261 if(side_index >=
sides_.size() ||
sides_[side_index] != user) {
1262 std::ostringstream
msg;
1263 msg <<
"Ignoring illegal whiteboard data, sent from user '" << user->info().name()
1264 <<
"' which had an invalid side '" << side_index + 1 <<
"' specified" << std::endl;
1266 const std::string& msg_str = msg.str();
1284 const int num_turns = ctw_node[
"max"].to_int();
1285 if(num_turns > 10000 || current_turn > 10000) {
1293 assert(static_cast<int>(this->
current_turn()) == current_turn);
1355 ERR_GAME <<
"ERROR: Player is already in this game.";
1363 bool became_observer =
false;
1375 became_observer =
true;
1383 user->info().name() +
" is now observing the game.", player);
1387 observer_join.
root()
1396 << player->client_ip() <<
"\t" << user->info().name() <<
"\tjoined game:\t\"" 1397 <<
name_ <<
"\" (" <<
id_ <<
", " <<
db_id_ <<
")" << (observer ?
" as an observer" :
"") <<
".";
1399 user->info().mark_available(
id_,
name_);
1422 if(!clones.empty()) {
1424 user->info().name() +
" has the same IP as: " + clones);
1427 if(became_observer) {
1438 ERR_GAME <<
"ERROR: User is not in this game.";
1445 const bool host = (player ==
owner_);
1457 << user->client_ip()
1458 <<
"\t" << user->info().name()
1459 << ((game_ended && !(observer && destruct)) ? (
started_ ?
"\tended" :
"\taborted") :
"\thas left")
1460 <<
" game:\t\"" <<
name_ <<
"\" (" <<
id_ <<
", " <<
db_id_ <<
")" 1461 << (game_ended &&
started_ && !(observer && destruct)
1462 ?
" at turn: " + lexical_cast_default<std::string, std::size_t>(
current_turn())
1465 << (observer ?
" as an observer" :
"") << (disconnect ?
" and disconnected" :
"") <<
".";
1467 if(game_ended &&
started_ && !(observer && destruct)) {
1471 if(game_ended || destruct) {
1479 user->info().mark_available();
1486 + (disconnect ?
" has disconnected." :
" has left the game."), player);
1495 bool ai_transfer =
false;
1499 for(
unsigned side_index = 0; side_index <
sides_.size(); ++side_index) {
1500 auto side =
sides_[side_index];
1502 if(side != player) {
1514 DBG_GAME <<
"making the owner a player...";
1522 const std::string side_drop = lexical_cast_default<std::string, std::size_t>(side_index + 1);
1527 node_side_drop.
set_attr_dup(
"side_num", side_drop.c_str());
1530 DBG_GAME <<
"*** sending side drop: \n" << drop.output();
1570 assert(sender ==
owner_);
1573 if(user_ptr != sender) {
1589 DBG_GAME <<
"****\n loading next scenario for a client. sides info = ";
1615 for(
const auto& side_user :
sides_) {
1617 cfg_controller.
set_attr(
"is_local", side_user == user ?
"yes" :
"no");
1632 template<
typename Container>
1635 for(
const auto&
player : players) {
1649 std::optional<player_iterator> exclude)
1651 std::vector<int> sides_vec = ::split<int>(sides, ::split_conv_impl);
1655 decltype(
players_) filtered_players;
1657 std::copy_if(
players_.begin(),
players_.end(), std::back_inserter(filtered_players),
1665 for(
int side : sides) {
1666 std::size_t side_index = side - 1;
1668 if(side_index <
sides_.size() &&
sides_[side_index] == player) {
1679 const std::string ip = user->client_ip();
1682 for(
auto u : users) {
1683 if(ip == u->client_ip() && user != u) {
1684 clones += (clones.empty() ?
"" :
", ") + u->info().name();
1716 observer_quit.
root()
1718 .
set_attr_dup(
"name", observer->info().name().c_str());
1744 history_.push_back(std::move(doc));
1752 return !(isalnum(c) ||
1772 std::stringstream
name;
1774 std::string filename(name.str());
1775 std::replace(filename.begin(), filename.end(),
' ',
'_');
1786 std::string replay_commands;
1797 std::stringstream replay_data;
1804 const bool has_old_replay =
level_.
child(
"replay") !=
nullptr;
1816 << (has_old_replay ?
"" :
"\t[command]\n\t\t[start]\n\t\t[/start]\n\t[/command]\n")
1817 << replay_commands <<
"[/replay]\n";
1819 std::string replay_data_str = replay_data.str();
1823 DBG_GAME <<
"saving replay: " << filename;
1826 (*os) <<
replay.output_compressed(
true);
1829 ERR_GAME <<
"Could not save replay! (" << filename <<
")";
1839 history_.push_back(std::move(data));
1881 std::stringstream result;
1882 result <<
"game id: " <<
id_ <<
", " <<
db_id_ <<
"\n";
1885 result <<
"player: " << user->info().name().c_str() <<
"\n";
1889 result <<
"observer: " << user->info().name().c_str() <<
"\n";
1892 return result.str();
1897 std::stringstream result;
1898 result <<
"game id: " <<
id_ <<
", " <<
db_id_ <<
"\n";
1901 result <<
"\t\t level, server\n";
1905 <<
"side " << (*s)[
"side"].to_int()
1906 <<
" :\t" << (*s)[
"controller"].to_string()
1908 <<
"\t( " << (*s)[
"current_player"].to_string() <<
" )\n";
1911 return result.str();
1926 auto doc = std::make_unique<simple_wml::document>();
1945 if(docptr ==
nullptr) {
1959 std::stringstream ss;
1960 ss << ::std::time(
nullptr);
1977 return multiplayer.
has_attr(
"savegame") && multiplayer[
"savegame"].to_bool();
node & add_child(const char *name)
const char * const_iterator
bool save_replays_
Whether to save a replay of this game.
void remove()
Removes a tip.
const string_span & attr(const char *key) const
bool is_muted_observer(player_iterator player) const
void handle_choice(const simple_wml::node &data, player_iterator user)
Handle a choice requested by a client, such as changing a side's controller, if initiated by WML/lua...
std::set< const player_record * > players_not_advanced_
in multiplayer campaigns it can happen that some players are still in the previous scenario keep trac...
int db_id_
Used for unique identification of games played in the database.
void send_and_record_server_message(const char *message, std::optional< player_iterator > exclude={})
Send data to all players in this game except 'exclude'.
std::string to_string() const
void send_observerquit(player_iterator observer)
const std::string & name() const
void save_replay()
Move the level information and recorded history into a replay file and save it.
player_connections & player_connections_
void mute_observer(const simple_wml::node &mute, player_iterator muter)
Mute an observer or give a message of all currently muted observers if no name is given...
std::optional< player_iterator > ban_user(const simple_wml::node &ban, player_iterator banner)
Ban a user by name.
void send_to_players(simple_wml::document &data, const Container &players, std::optional< player_iterator > exclude={})
Send data to all players except those excluded.
bool has_attr(const char *key) const
void process_change_turns_wml(simple_wml::document &data, player_iterator user)
Handles incoming [change_turns_wml] data.
bool is_player(player_iterator player) const
std::vector< std::unique_ptr< simple_wml::document > > history_
Replay data.
const simple_wml::node::child_list & get_sides_list() const
void process_message(simple_wml::document &data, player_iterator user)
Sends an ingame message to all other players.
bool is_current_player(player_iterator player) const
New lexcical_cast header.
user_vector muted_observers_
A vector of muted observers.
void update_side_data()
Resets the side configuration according to the scenario data.
bool player_is_banned(player_iterator player, const std::string &name) const
std::string username(player_iterator pl) const
node & set_attr_int(const char *key, int value)
uint32_t get_next_random()
Get a new random number.
node & set_attr(const char *key, const char *value)
std::optional< player_iterator > find_user(const simple_wml::string_span &name)
Shortcut to a convenience function for finding a user by name.
std::size_t current_side() const
int nsides_
Number of sides in the current scenario.
user_vector observers_
A vector of observers (members not owning a side).
void send_leave_game(player_iterator user) const
Tells a player to leave the game.
bool is_observer(player_iterator player) const
bool all_observers_muted_
Whether all observers should be treated as muted.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
std::string get_unknown_exception_type()
Utility function for finding the type of thing caught with catch(...).
bool is_member(player_iterator player) const
std::string termination_
The reason the game ended.
randomness::mt_rng rng_
A wrapper for mersenne twister rng which generates randomness for this game.
node & set_attr_dup(const char *key, const char *value)
const child_list & children(const char *name) const
player_iterator owner_
The game host or later owner (if the host left).
bool process_turn(simple_wml::document &data, player_iterator user)
Handles [end_turn], repackages [commands] with private [speak]s in them and sends the data...
filesystem::scoped_ostream ostream_file(const std::string &fname, std::ios_base::openmode mode, bool create_directory)
player_connections::const_iterator player_iterator
void handle_add_side_wml()
Adds a new, empty side owned by no one.
std::vector< std::string > bans_
List of banned IPs.
bool is_legal_command(const simple_wml::node &command, player_iterator user)
std::unique_ptr< document > clone()
node * child(const char *name)
node * child(const char *name)
const char * begin() const
bmi::multi_index_container< player_record, bmi::indexed_by< bmi::ordered_unique< bmi::tag< socket_t >, bmi::const_mem_fun< player_record, const any_socket_ptr, &player_record::socket > >, bmi::hashed_unique< bmi::tag< name_t >, bmi::const_mem_fun< player_record, const std::string &, &player_record::name > >, bmi::ordered_non_unique< bmi::tag< game_t >, bmi::const_mem_fun< player_record, int, &player_record::game_id > > > > player_connections
int last_choice_request_id_
The ID of the last request received from a client.
void truncate_message(const simple_wml::string_span &str, simple_wml::node &message)
Function to ensure a text message is within the allowed length.
bool end_turn(int new_side)
Function which should be called every time a player ends their turn (i.e.
static lg::log_domain log_config("config")
void reset_sides()
calculates the initial value for sides_, side_controllerds_, nsides_
void process_whiteboard(simple_wml::document &data, player_iterator user)
Handles incoming [whiteboard] data.
int num_turns_
The maximum number of turns before the game ends.
void send_history(player_iterator sock) const
void update_turn_data()
Set or update the current and max turn values in the game's description.
bool allow_observers() const
void handle_controller_choice(const simple_wml::node &data)
Handle a request to change a side's controller.
bool describe_slots()
Set the description to the number of available slots.
void transfer_side_control(player_iterator player, const simple_wml::node &cfg)
Lets a player owning a side give it to another player or observer.
static bool is_invalid_filename_char(char c)
void handle_random_choice()
Send a randomly generated number to the requestor.
static lg::log_domain log_server("server")
static int db_id_num
Incremented to retrieve a unique ID per wesnothd instance for game instances within the database...
std::string get_replay_filename()
std::optional< player_iterator > current_player() const
void new_scenario(player_iterator sender)
When the host sends the new scenario of a mp campaign.
void start_game(player_iterator starter)
Starts the game (if a new game) or starts the next scenario of an MP campaign.
const user_vector all_game_users() const
bool controls_side(const std::vector< int > &sides, player_iterator player) const
Function which returns true if 'player' controls any of the sides specified in 'sides'.
void perform_controller_tweaks()
This is performed just before starting and before the [start_game] signal.
bool remove_player(player_iterator player, const bool disconnect=false, const bool destruct=false)
Removes a user from the game.
int id_
This game's ID within wesnothd.
std::unique_ptr< simple_wml::document > change_controller_type(const std::size_t side_index, player_iterator player, const std::string &player_name)
Tell everyone else but the source player that the controller type changed.
void send_data(simple_wml::document &data, std::optional< player_iterator > exclude={})
Send data to all players and observers except those excluded.
std::optional< player_iterator > kick_member(const simple_wml::node &kick, player_iterator kicker)
Kick a user from this game by name.
void load_next_scenario(player_iterator user)
A user asks for the next scenario to advance to.
bool is_owner(player_iterator player) const
std::unique_ptr< std::ostream > scoped_ostream
void send_to_player(player_iterator player, simple_wml::document &data)
static simple_wml::node * starting_pos(simple_wml::node &data)
The non-const version.
void send_server_message(const char *message, std::optional< player_iterator > player={}, simple_wml::document *doc=nullptr) const
Send a server message to the specified player.
std::vector< std::string > name_bans_
List of banned usernames.
void record_data(std::unique_ptr< simple_wml::document > data)
Records a WML document in the game's history.
node & set_attr_dup(const char *key, const char *value)
static constexpr std::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
void send_observerjoins(std::optional< player_iterator > player={})
Send a document per observer in the game.
static map_location::DIRECTION s
std::vector< side_controller::type > side_controllers_
A vector containiner the controller type for each side.
void change_controller(const std::size_t side_index, player_iterator player, const std::string &player_name, const bool player_left=true)
Send [change_controller] message to tell all clients the new controller's name or controller type (hu...
void remove_child(const char *name, std::size_t index)
std::vector< node * > child_list
bool add_player(player_iterator player, bool observer=false)
Add a user to the game.
std::size_t current_turn() const
Declarations for File-IO.
int current_side_index_
The index of the current side.
side_vector sides_
A vector of side owners.
void notify_new_host()
In case of a host transfer, notify the new host about its status.
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
void set_description(simple_wml::node *desc)
Set the game's description.
std::string has_same_ip(player_iterator user) const
Checks whether a user has the same IP as any other members of this game.
void send_data_sides(simple_wml::document &data, const simple_wml::string_span &sides, std::optional< player_iterator > exclude={})
Sends a document to the provided list of sides.
static const simple_wml::node & get_multiplayer(const simple_wml::node &root)
returns const so that operator [] won't create empty keys if not existent
std::string list_users(user_vector users) const
simple_wml::node * description_
Pointer to the game's description in the games_and_users_list_.
std::string name_
The name of the game.
void unban_user(const simple_wml::node &unban, player_iterator unbanner)
Unban a user by name.
std::string debug_sides_info() const
Helps debugging controller tweaks.
static int id_num
Incremented to retrieve a unique ID for game instances within wesnothd.
std::vector< std::string > split(const config_attribute_value &val)
std::vector< player_iterator > user_vector
void send_user_list(std::optional< player_iterator > exclude={})
Function to send a list of users to all clients.
const std::string & termination_reason() const
Provides the reason the game was ended.
std::string replay_save_path_
Where to save the replay of this game.
int current_turn_
The game's current turn.
Standard logging facilities (interface).
user_vector players_
A vector of players (members owning a side).
void send_server_message_to_all(const char *message, std::optional< player_iterator > exclude={})
Sends a message to all players in this game that aren't excluded.
std::string password_
The password needed to join the game.
void send_muted_observers(player_iterator user) const
Sends a message either stating that all observers are muted or listing the observers that are muted...
bool started_
Whether the game has been started or not.
bool send_taken_side(simple_wml::document &cfg, const simple_wml::node *side) const
Tell the host who owns a side.
void copy_into(node &n) const
std::string debug_player_info() const
Helps debugging player and observer lists.
void unmute_observer(const simple_wml::node &unmute, player_iterator unmuter)
Unmute an observer or unmute all currently muted observers if no name is given.
simple_wml::document level_
The current scenario data.
void clear_history()
Clears the history of recorded WML documents.
void mute_all_observers()
Toggles whether all observers are muted or not.
bool take_side(player_iterator user)
Figures out which side to take and tells that side to the game owner.
void set_termination_reason(const std::string &reason)
Sets the termination reason for this game.
game(wesnothd::server &server, player_connections &player_connections, player_iterator host, const std::string &name="", bool save_replays=false, const std::string &replay_save_path="")
std::string node_to_string(const node &n)
const std::string observer_team_name
observer team name used for observer team chat
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.