diff --git a/src/server/forum_user_handler.cpp b/src/server/forum_user_handler.cpp index 3bee479f4f99..22a2db623005 100644 --- a/src/server/forum_user_handler.cpp +++ b/src/server/forum_user_handler.cpp @@ -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){ +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){ try { - prepared_statement("INSERT INTO `" + db_game_player_info_table_ + "`(INSTANCE_UUID, GAME_ID, USER_ID, SIDE_NUMBER, IS_HOST, FACTION) VALUES(?, ?, IFNULL((SELECT user_id FROM `"+db_users_table_+"` WHERE username = ?), -1), ?, ?, ?)", - uuid, game_id, username, side_number, is_host, faction); + prepared_statement("INSERT INTO `" + db_game_player_info_table_ + "`(INSTANCE_UUID, GAME_ID, USER_ID, SIDE_NUMBER, IS_HOST, FACTION, CLIENT_VERSION) VALUES(?, ?, IFNULL((SELECT user_id FROM `"+db_users_table_+"` WHERE username = ?), -1), ?, ?, ?, ?)", + uuid, game_id, username, side_number, is_host, faction, version); } 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 4a6ea61376a9..40dc9720ed85 100644 --- a/src/server/forum_user_handler.hpp +++ b/src/server/forum_user_handler.hpp @@ -73,7 +73,7 @@ class fuh : public user_handler { 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_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); + 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); 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/server.cpp b/src/server/server.cpp index 6121537a582b..e33cb8691ca1 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -1620,7 +1620,8 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptrdb_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()); + std::string version = player_connections_.get().find(side["player_id"].to_string())->info().version(); + 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); } const std::string mods = multiplayer["active_mods"].to_string(); diff --git a/src/server/user_handler.hpp b/src/server/user_handler.hpp index 29506fcde0d0..4d626e90b6f5 100644 --- a/src/server/user_handler.hpp +++ b/src/server/user_handler.hpp @@ -138,7 +138,7 @@ class user_handler { 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_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) =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) =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 a6db11a4c0d4..3383b48bfe1b 100644 --- a/utils/mp-server/table_definitions.sql +++ b/utils/mp-server/table_definitions.sql @@ -81,12 +81,13 @@ create table game_info -- STATUS: the status of the side, currently only updated at game end create table game_player_info ( - INSTANCE_UUID CHAR(36) NOT NULL, - GAME_ID INT UNSIGNED NOT NULL, - USER_ID INT NOT NULL, - SIDE_NUMBER SMALLINT UNSIGNED NOT NULL, - IS_HOST BIT(1) NOT NULL, - FACTION VARCHAR(255) NOT NULL, + INSTANCE_UUID CHAR(36) NOT NULL, + GAME_ID INT UNSIGNED NOT NULL, + USER_ID INT NOT NULL, + SIDE_NUMBER SMALLINT UNSIGNED NOT NULL, + IS_HOST BIT(1) NOT NULL, + FACTION VARCHAR(255) NOT NULL, + CLIENT_VERSION VARCHAR(255) NOT NULL DEFAULT '', PRIMARY KEY (INSTANCE_UUID, GAME_ID, SIDE_NUMBER) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;