Skip to content

Commit

Permalink
Move the game content info (scenario/era/modifications) into their ow…
Browse files Browse the repository at this point in the history
…n table.

Backport of d741365
  • Loading branch information
Pentarctagon committed Oct 26, 2020
1 parent b0a30dd commit e60097a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -213,3 +213,4 @@ config.h
.kdev*
callgrind.out.*
data/dist
clean.sh
16 changes: 8 additions & 8 deletions src/server/forum_user_handler.cpp
Expand Up @@ -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))
Expand Down Expand Up @@ -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<void>("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<void>("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;
}
Expand All @@ -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<void>("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<void>("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;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/server/forum_user_handler.hpp
Expand Up @@ -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:
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/server/sample_user_handler.hpp
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions src/server/server.cpp
Expand Up @@ -1752,7 +1752,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
// 1.14.9 and earlier also use whether observers are allowed to determine if the replay should be public
// 1.14.10+ have a separate attribute for that
bool is_public = m["private_replay"].to_string() == "" ? m["observer"].to_bool() : !m["private_replay"].to_bool();
user_handler_->db_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) {
Expand Down Expand Up @@ -1783,13 +1783,18 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
if(!mod_info_present && (!mod_sources.empty() || !mod_versions.empty())) {
WRN_SERVER << "mod info mismatch for game " << g.id() << ", " << g.db_id() << " - mods: '" << m["active_mods"].to_string() << "', mod_versions: '" << m["active_mod_versions"].to_string() << "', mod_sources: '" << m["active_mod_addon_ids"].to_string() << "'";
}
// insert modifications
for(unsigned int i = 0; i < mods.size(); i++){
if(!mod_info_present) {
user_handler_->db_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
Expand Down
4 changes: 2 additions & 2 deletions src/server/user_handler.hpp
Expand Up @@ -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:
Expand Down
25 changes: 12 additions & 13 deletions utils/mp-server/table_definitions.sql
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;

0 comments on commit e60097a

Please sign in to comment.