From e60097afcf3c45de54d27a58a85ae714cf8f6080 Mon Sep 17 00:00:00 2001 From: Pentarctagon Date: Mon, 26 Oct 2020 11:30:16 -0500 Subject: [PATCH] Move the game content info (scenario/era/modifications) into their own table. Backport of d74136532525481cdc8efd07b1320afb0e819be9 --- .gitignore | 1 + src/server/forum_user_handler.cpp | 16 ++++++++-------- src/server/forum_user_handler.hpp | 6 +++--- src/server/sample_user_handler.hpp | 4 ++-- src/server/server.cpp | 11 ++++++++--- src/server/user_handler.hpp | 4 ++-- utils/mp-server/table_definitions.sql | 25 ++++++++++++------------- 7 files changed, 36 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 9eb886e0d801..d9da1c70fb3a 100644 --- a/.gitignore +++ b/.gitignore @@ -213,3 +213,4 @@ config.h .kdev* callgrind.out.* data/dist +clean.sh diff --git a/src/server/forum_user_handler.cpp b/src/server/forum_user_handler.cpp index 9aed66685e2e..b9f5790edd4e 100644 --- a/src/server/forum_user_handler.cpp +++ b/src/server/forum_user_handler.cpp @@ -44,7 +44,7 @@ fuh::fuh(const config& c) , db_extra_table_(c["db_extra_table"].str()) , db_game_info_table_(c["db_game_info_table"].str()) , db_game_player_info_table_(c["db_game_player_info_table"].str()) - , db_game_modification_info_table_(c["db_game_modification_info_table"].str()) + , db_game_content_info_table_(c["db_game_content_info_table"].str()) , db_user_group_table_(c["db_user_group_table"].str()) , mp_mod_group_(0) , conn(mysql_init(nullptr)) @@ -443,10 +443,10 @@ std::string fuh::get_uuid(){ } } -void fuh::db_insert_game_info(const std::string& uuid, int game_id, const std::string& version, const std::string& name, const std::string& map_name, const std::string& era_name, int reload, int observers, int is_public, int has_password, const std::string& map_source, const std::string& map_version, const std::string& era_source, const std::string& era_version){ +void fuh::db_insert_game_info(const std::string& uuid, int game_id, const std::string& version, const std::string& name, int reload, int observers, int is_public, int has_password){ try { - prepared_statement("insert into `" + db_game_info_table_ + "`(INSTANCE_UUID, GAME_ID, INSTANCE_VERSION, GAME_NAME, MAP_NAME, ERA_NAME, RELOAD, OBSERVERS, PUBLIC, PASSWORD, MAP_SOURCE_ADDON, MAP_VERSION, ERA_SOURCE_ADDON, ERA_VERSION) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - uuid, game_id, version, name, map_name, era_name, reload, observers, is_public, has_password, map_source, map_version, era_source, era_version); + prepared_statement("insert into `" + db_game_info_table_ + "`(INSTANCE_UUID, GAME_ID, INSTANCE_VERSION, GAME_NAME, RELOAD, OBSERVERS, PUBLIC, PASSWORD) values(?, ?, ?, ?, ?, ?, ?, ?)", + uuid, game_id, version, name, reload, observers, is_public, has_password); } catch (const sql_error& e) { ERR_UH << "Could not insert into table `" + db_game_info_table_ + "`:" << e.message << std::endl; } @@ -470,12 +470,12 @@ void fuh::db_insert_game_player_info(const std::string& uuid, int game_id, const } } -void fuh::db_insert_modification_info(const std::string& uuid, int game_id, const std::string& modification_name, const std::string& modification_source, const std::string& modification_version){ +void fuh::db_insert_content_info(const std::string& uuid, int game_id, const std::string& type, const std::string& id, const std::string& source, const std::string& version){ try { - prepared_statement("insert into `" + db_game_modification_info_table_ + "`(INSTANCE_UUID, GAME_ID, MODIFICATION_NAME, SOURCE_ADDON, VERSION) values(?, ?, ?, ?, ?)", - uuid, game_id, modification_name, modification_source, modification_version); + prepared_statement("insert into `" + db_game_content_info_table_ + "`(INSTANCE_UUID, GAME_ID, TYPE, ID, SOURCE, VERSION) values(?, ?, ?, ?, ?, ?)", + uuid, game_id, type, id, source, version); } catch (const sql_error& e) { - ERR_UH << "Could not insert the game's modification information on table `" + db_game_modification_info_table_ + "`:" << e.message << std::endl; + ERR_UH << "Could not insert the game's content information on table `" + db_game_content_info_table_ + "`:" << e.message << std::endl; } } diff --git a/src/server/forum_user_handler.hpp b/src/server/forum_user_handler.hpp index f60a44b7e6b5..d6ea6c0d1e0d 100644 --- a/src/server/forum_user_handler.hpp +++ b/src/server/forum_user_handler.hpp @@ -81,10 +81,10 @@ class fuh : public user_handler { bool use_phpbb_encryption() const { return true; } std::string get_uuid(); - void db_insert_game_info(const std::string& uuid, int game_id, const std::string& version, const std::string& name, const std::string& map_name, const std::string& era_name, int reload, int observers, int is_public, int has_password, const std::string& map_source, const std::string& map_version, const std::string& era_source, const std::string& era_version); + void db_insert_game_info(const std::string& uuid, int game_id, const std::string& version, const std::string& 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, const std::string& current_user); - void db_insert_modification_info(const std::string& uuid, int game_id, const std::string& modification_name, const std::string& modification_source, const std::string& modification_version); + void db_insert_content_info(const std::string& uuid, int game_id, const std::string& type, const std::string& id, const std::string& source, const std::string& version); void db_set_oos_flag(const std::string& uuid, int game_id); private: @@ -104,7 +104,7 @@ class fuh : public user_handler { std::time_t retrieve_ban_duration_internal(const std::string& col, const std::string& detail); std::time_t retrieve_ban_duration_internal(const std::string& col, unsigned int detail); - std::string db_name_, db_host_, db_user_, db_password_, db_users_table_, db_banlist_table_, db_extra_table_, db_game_info_table_, db_game_player_info_table_, db_game_modification_info_table_, db_user_group_table_; + std::string db_name_, db_host_, db_user_, db_password_, db_users_table_, db_banlist_table_, db_extra_table_, db_game_info_table_, db_game_player_info_table_, db_game_content_info_table_, db_user_group_table_; unsigned int mp_mod_group_; MYSQL *conn; diff --git a/src/server/sample_user_handler.hpp b/src/server/sample_user_handler.hpp index a51a21940251..c4aad4a755be 100644 --- a/src/server/sample_user_handler.hpp +++ b/src/server/sample_user_handler.hpp @@ -68,10 +68,10 @@ class suh : public user_handler { bool use_phpbb_encryption() const { return false; } std::string get_uuid(); - void db_insert_game_info(const std::string&, int, const std::string&, const std::string&, const std::string&, const std::string&, int, int, int, int, const std::string&, const std::string&, const std::string&, const std::string&){} + void db_insert_game_info(const std::string&, int, const std::string&, const std::string&, int, int, int, int){} void db_update_game_end(const std::string&, int, const std::string&){} void db_insert_game_player_info(const std::string&, int, const std::string&, int, int, const std::string&, const std::string&, const std::string&, const std::string&){} - void db_insert_modification_info(const std::string&, int, const std::string&, const std::string&, const std::string&){} + void db_insert_content_info(const std::string&, int, const std::string&, const std::string&, const std::string&, const std::string&){} void db_set_oos_flag(const std::string&, int){} private: diff --git a/src/server/server.cpp b/src/server/server.cpp index 4c21ae3b5828..5d9c016889ea 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -1752,7 +1752,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptrdb_insert_game_info(uuid_, g.db_id(), game_config::wesnoth_version.str(), g.name(), m["mp_scenario"].to_string(), m["mp_era"].to_string(), g.is_reload(), m["observer"].to_bool(), is_public, g.has_password(), m["mp_scenario_addon_id"].to_string(), m["mp_scenario_addon_version"].to_string(), m["mp_era_addon_id"].to_string(), m["mp_era_addon_version"].to_string()); + user_handler_->db_insert_game_info(uuid_, g.db_id(), game_config::wesnoth_version.str(), g.name(), g.is_reload(), m["observer"].to_bool(), is_public, 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) { @@ -1783,13 +1783,18 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptrdb_insert_modification_info(uuid_, g.db_id(), mods[i], "", ""); + user_handler_->db_insert_content_info(uuid_, g.db_id(), "modification", mods[i], "", ""); } else { - user_handler_->db_insert_modification_info(uuid_, g.db_id(), mods[i], mod_sources[i], mod_versions[i]); + user_handler_->db_insert_content_info(uuid_, g.db_id(), "modification", mods[i], mod_sources[i], mod_versions[i]); } } + // scenario + user_handler_->db_insert_content_info(uuid_, g.db_id(), "scenario", m["mp_scenario"].to_string(), m["mp_scenario_addon_id"].to_string(), m["mp_scenario_addon_version"].to_string()); + // era + user_handler_->db_insert_content_info(uuid_, g.db_id(), "era", m["mp_era"].to_string(), m["mp_era_addon_id"].to_string(), m["mp_era_addon_version"].to_string()); } // update the game having changed in the lobby diff --git a/src/server/user_handler.hpp b/src/server/user_handler.hpp index 5028cd566e84..aec88b66dc4c 100644 --- a/src/server/user_handler.hpp +++ b/src/server/user_handler.hpp @@ -172,10 +172,10 @@ class user_handler { virtual bool use_phpbb_encryption() const =0; 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, const std::string& map_name, const std::string& era_name, int reload, int observers, int is_public, int has_password, const std::string& map_source, const std::string& map_version, const std::string& era_source, const std::string& era_version) =0; + virtual void db_insert_game_info(const std::string& uuid, int game_id, const std::string& version, const std::string& 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, const std::string& current_user) =0; - virtual void db_insert_modification_info(const std::string& uuid, int game_id, const std::string& modification_name, const std::string& modification_source, const std::string& modification_version) =0; + virtual void db_insert_content_info(const std::string& uuid, int game_id, const std::string& type, const std::string& id, const std::string& source, const std::string& version) =0; virtual void db_set_oos_flag(const std::string& uuid, int game_id) =0; protected: diff --git a/utils/mp-server/table_definitions.sql b/utils/mp-server/table_definitions.sql index 83cc17eba305..530cb4a4b0b5 100644 --- a/utils/mp-server/table_definitions.sql +++ b/utils/mp-server/table_definitions.sql @@ -21,7 +21,7 @@ -- table which the forum inserts bans into, which wesnothd checks during login -- create table ban -- ( --- BAN_USERID VARCHAR(100) NOT NULL, +-- BAN_USERID INT(10) UNSIGNED NOT NULL, -- BAN_END INT(10) UNSIGNED NOT NULL DEFAULT 0, -- BAN_IP VARCHAR(100) DEFAULT NULL, -- BAN_EMAIL VARCHAR(100) DEFAULT NULL, @@ -66,12 +66,6 @@ create table game_info GAME_NAME VARCHAR(255) NOT NULL, START_TIME TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, END_TIME TIMESTAMP NULL DEFAULT NULL, - MAP_NAME VARCHAR(255) NOT NULL, - MAP_SOURCE_ADDON VARCHAR(255) NOT NULL DEFAULT '', - MAP_VERSION VARCHAR(255) NOT NULL DEFAULT '', - ERA_NAME VARCHAR(255) NOT NULL, - ERA_SOURCE_ADDON VARCHAR(255) NOT NULL DEFAULT '', - ERA_VERSION VARCHAR(255) NOT NULL DEFAULT '', REPLAY_NAME VARCHAR(255), OOS BIT(1) NOT NULL DEFAULT 0, RELOAD BIT(1) NOT NULL, @@ -104,13 +98,18 @@ create table game_player_info PRIMARY KEY (INSTANCE_UUID, GAME_ID, SIDE_NUMBER) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; --- information about any modifications that the game present in game_info has enabled -create table game_modification_info +-- information about the scenario/era/modifications for the game +-- TYPE: one of era/scenario/modification +-- ID: the id of the content +-- SOURCE: the id of the add-on that the particular content came from +-- VERSION: the version of the source add-on +create table game_content_info ( INSTANCE_UUID CHAR(36) NOT NULL, GAME_ID INT UNSIGNED NOT NULL, - MODIFICATION_NAME VARCHAR(255) NOT NULL, - SOURCE_ADDON VARCHAR(255) NOT NULL DEFAULT '', - VERSION VARCHAR(255) NOT NULL DEFAULT '', - PRIMARY KEY (INSTANCE_UUID, GAME_ID, MODIFICATION_NAME) + TYPE VARCHAR(255) NOT NULL, + ID VARCHAR(255) NOT NULL, + SOURCE VARCHAR(255) NOT NULL, + VERSION VARCHAR(255) NOT NULL, + PRIMARY KEY (INSTANCE_UUID, GAME_ID, TYPE, ID) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;