diff --git a/src/server/forum_user_handler.cpp b/src/server/forum_user_handler.cpp index c9a735fc446d..6477af10e816 100644 --- a/src/server/forum_user_handler.cpp +++ b/src/server/forum_user_handler.cpp @@ -427,10 +427,10 @@ void fuh::db_insert_game_info(const std::string& uuid, int game_id, const std::s } } -void fuh::db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, int reload){ +void fuh::db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, int reload, int observers, int is_public, int has_password){ try { - prepared_statement("UPDATE `" + db_game_info_table_ + "` SET START_TIME = CURRENT_TIMESTAMP, MAP_NAME = ?, ERA_NAME = ?, RELOAD = ? WHERE INSTANCE_UUID = ? AND GAME_ID = ?", - map_name, era_name, reload, uuid, game_id); + prepared_statement("UPDATE `" + db_game_info_table_ + "` SET START_TIME = CURRENT_TIMESTAMP, MAP_NAME = ?, ERA_NAME = ?, RELOAD = ?, OBSERVERS = ?, PUBLIC = ?, PASSWORD = ? WHERE INSTANCE_UUID = ? AND GAME_ID = ?", + map_name, era_name, reload, observers, is_public, has_password, uuid, game_id); } catch (const sql_error& e) { ERR_UH << "Could not update the game's starting information on table `" + db_game_info_table_ + "`:" << e.message << std::endl; } @@ -445,10 +445,10 @@ void fuh::db_update_game_end(const std::string& uuid, int game_id, const std::st } } -void fuh::db_insert_game_player_info(const std::string& uuid, int game_id, const std::string& username, int side_number, int is_host, const std::string& faction, const std::string& version, const std::string& source){ +void fuh::db_insert_game_player_info(const std::string& uuid, int game_id, const std::string& username, int side_number, int is_host, const std::string& faction, const std::string& version, const std::string& source, const std::string& current_user){ try { - prepared_statement("INSERT INTO `" + db_game_player_info_table_ + "`(INSTANCE_UUID, GAME_ID, USER_ID, SIDE_NUMBER, IS_HOST, FACTION, CLIENT_VERSION, CLIENT_SOURCE) VALUES(?, ?, IFNULL((SELECT user_id FROM `"+db_users_table_+"` WHERE username = ?), -1), ?, ?, ?, ?, ?)", - uuid, game_id, username, side_number, is_host, faction, version, source); + prepared_statement("INSERT INTO `" + db_game_player_info_table_ + "`(INSTANCE_UUID, GAME_ID, USER_ID, SIDE_NUMBER, IS_HOST, FACTION, CLIENT_VERSION, CLIENT_SOURCE, USER_NAME) VALUES(?, ?, IFNULL((SELECT user_id FROM `"+db_users_table_+"` WHERE username = ?), -1), ?, ?, ?, ?, ?, ?)", + uuid, game_id, username, side_number, is_host, faction, version, source, current_user); } catch (const sql_error& e) { ERR_UH << "Could not insert the game's player information on table `" + db_game_player_info_table_ + "`:" << e.message << std::endl; } diff --git a/src/server/forum_user_handler.hpp b/src/server/forum_user_handler.hpp index 61d0c5c5130f..4917b6d29cae 100644 --- a/src/server/forum_user_handler.hpp +++ b/src/server/forum_user_handler.hpp @@ -71,9 +71,9 @@ class fuh : public user_handler { std::string get_uuid(); void db_insert_game_info(const std::string& uuid, int game_id, const std::string& version, const std::string& name); - void db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, int reload); + void db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, int reload, int observers, int is_public, int has_password); void db_update_game_end(const std::string& uuid, int game_id, const std::string& replay_location); - void db_insert_game_player_info(const std::string& uuid, int game_id, const std::string& username, int side_number, int is_host, const std::string& faction, const std::string& version, const std::string& source); + void db_insert_game_player_info(const std::string& uuid, int game_id, const std::string& username, int side_number, int is_host, const std::string& faction, const std::string& version, const std::string& source, const std::string& current_user); void db_insert_modification_info(const std::string& uuid, int game_id, const std::string& modification_name); void db_set_oos_flag(const std::string& uuid, int game_id); diff --git a/src/server/game.hpp b/src/server/game.hpp index ecae0a156c9d..0aee9c7c470d 100644 --- a/src/server/game.hpp +++ b/src/server/game.hpp @@ -294,6 +294,11 @@ class game return password_.empty() || passwd == password_; } + bool has_password() const + { + return !password_.empty(); + } + const std::string& termination_reason() const { static const std::string aborted = "aborted"; diff --git a/src/server/server.cpp b/src/server/server.cpp index 9978c75a3014..3f0b7d8efe67 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -1620,7 +1620,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptrdb_update_game_start(uuid_, g.id(), multiplayer["mp_scenario"].to_string(), multiplayer["mp_era"].to_string(), g.is_reload()); + user_handler_->db_update_game_start(uuid_, g.id(), multiplayer["mp_scenario"].to_string(), multiplayer["mp_era"].to_string(), g.is_reload(), multiplayer["observer"].to_bool(), multiplayer["observer"].to_bool(), g.has_password()); const simple_wml::node::child_list& sides = g.get_sides_list(); for(unsigned side_index = 0; side_index < sides.size(); ++side_index) { @@ -1637,7 +1637,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptrinfo().version(); source = player->info().source(); } - user_handler_->db_insert_game_player_info(uuid_, g.id(), side["player_id"].to_string(), side["side"].to_int(), side["is_host"].to_bool(), side["faction"].to_string(), version, source); + user_handler_->db_insert_game_player_info(uuid_, g.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()); } const std::string mods = multiplayer["active_mods"].to_string(); diff --git a/src/server/user_handler.hpp b/src/server/user_handler.hpp index f1126d7ed651..2ca49d65d26a 100644 --- a/src/server/user_handler.hpp +++ b/src/server/user_handler.hpp @@ -136,9 +136,9 @@ class user_handler { virtual std::string get_uuid() =0; virtual void db_insert_game_info(const std::string& uuid, int game_id, const std::string& version, const std::string& name) =0; - virtual void db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, int reload) =0; + virtual void db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, int reload, int observers, int is_public, int has_password) =0; virtual void db_update_game_end(const std::string& uuid, int game_id, const std::string& replay_location) =0; - virtual void db_insert_game_player_info(const std::string& uuid, int game_id, const std::string& username, int side_number, int is_host, const std::string& faction, const std::string& version, const std::string& source) =0; + virtual void db_insert_game_player_info(const std::string& uuid, int game_id, const std::string& username, int side_number, int is_host, const std::string& faction, const std::string& version, const std::string& source, const std::string& current_user) =0; virtual void db_insert_modification_info(const std::string& uuid, int game_id, const std::string& modification_name) =0; virtual void db_set_oos_flag(const std::string& uuid, int game_id) =0; }; diff --git a/utils/mp-server/table_definitions.sql b/utils/mp-server/table_definitions.sql index 668fa605b623..fc3ac8b2228f 100644 --- a/utils/mp-server/table_definitions.sql +++ b/utils/mp-server/table_definitions.sql @@ -69,6 +69,9 @@ create table game_info REPLAY_NAME VARCHAR(255), OOS BIT(1) NOT NULL DEFAULT 0, RELOAD BIT(1), + OBSERVERS BIT(1), + PASSWORD BIT(1), + PUBLIC BIT(1), PRIMARY KEY (INSTANCE_UUID, GAME_ID) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; @@ -91,6 +94,7 @@ create table game_player_info FACTION VARCHAR(255) NOT NULL, CLIENT_VERSION VARCHAR(255) NOT NULL DEFAULT '', CLIENT_SOURCE VARCHAR(255) NOT NULL DEFAULT '', + USER_NAME VARCHAR(255) NOT NULL DEFAULT '', PRIMARY KEY (INSTANCE_UUID, GAME_ID, SIDE_NUMBER) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;