From 95dc6b5f45b31d5f1caf5cea502d0efe077e15f2 Mon Sep 17 00:00:00 2001 From: Pentarctagon Date: Fri, 17 Jan 2020 13:25:52 -0600 Subject: [PATCH] Only store game information once the game starts. --- src/server/forum_user_handler.cpp | 15 +++------------ src/server/forum_user_handler.hpp | 3 +-- src/server/server.cpp | 6 +----- src/server/user_handler.hpp | 3 +-- utils/mp-server/table_definitions.sql | 16 +++++++--------- 5 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/server/forum_user_handler.cpp b/src/server/forum_user_handler.cpp index 6477af10e81..02082020a7d 100644 --- a/src/server/forum_user_handler.cpp +++ b/src/server/forum_user_handler.cpp @@ -418,24 +418,15 @@ 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){ +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){ try { - prepared_statement("INSERT INTO `" + db_game_info_table_ + "`(INSTANCE_UUID, GAME_ID, INSTANCE_VERSION, GAME_NAME) VALUES(?, ?, ?, ?)", - uuid, game_id, version, name); + prepared_statement("INSERT INTO `" + db_game_info_table_ + "`(INSTANCE_UUID, GAME_ID, INSTANCE_VERSION, GAME_NAME, MAP_NAME, ERA_NAME, RELOAD, OBSERVERS, PUBLIC, PASSWORD) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + uuid, game_id, version, name, map_name, era_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; } } -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 = ?, 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; - } -} - void fuh::db_update_game_end(const std::string& uuid, int game_id, const std::string& replay_location){ try { prepared_statement("UPDATE `" + db_game_info_table_ + "` SET END_TIME = CURRENT_TIMESTAMP, REPLAY_NAME = ? WHERE INSTANCE_UUID = ? AND GAME_ID = ?", diff --git a/src/server/forum_user_handler.hpp b/src/server/forum_user_handler.hpp index 4917b6d29ca..9fecbd0ae7c 100644 --- a/src/server/forum_user_handler.hpp +++ b/src/server/forum_user_handler.hpp @@ -70,8 +70,7 @@ 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); - 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_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); 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); diff --git a/src/server/server.cpp b/src/server/server.cpp index 54e67623784..1a683c1b839 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -1298,10 +1298,6 @@ void server::create_game(player_record& host_record, simple_wml::node& create_ga } create_game.copy_into(g.level().root()); - - if(user_handler_) { - user_handler_->db_insert_game_info(uuid_, g.id(), game_config::wesnoth_version.str(), g.name()); - } } void server::cleanup_game(game* game_ptr) @@ -1625,7 +1621,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptrdb_update_game_start(uuid_, g.id(), m["mp_scenario"].to_string(), m["mp_era"].to_string(), g.is_reload(), m["observer"].to_bool(), !m["private_replay"].to_bool(), g.has_password()); + user_handler_->db_insert_game_info(uuid_, g.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(), !m["private_replay"].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) { diff --git a/src/server/user_handler.hpp b/src/server/user_handler.hpp index 2ca49d65d26..cdad3c85af4 100644 --- a/src/server/user_handler.hpp +++ b/src/server/user_handler.hpp @@ -135,8 +135,7 @@ 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) =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_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) =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) =0; diff --git a/utils/mp-server/table_definitions.sql b/utils/mp-server/table_definitions.sql index fc3ac8b2228..b3c462c45d1 100644 --- a/utils/mp-server/table_definitions.sql +++ b/utils/mp-server/table_definitions.sql @@ -48,7 +48,6 @@ create table extra -- GAME_ID: a sequential id wesnoth generates, resets on restart -- INSTANCE_VERSION: the version of the server -- GAME_NAME: the game's displayed title in the lobby --- CREATE_TIME: when the game is made available in the lobby -- START_TIME: when the players enter the game and begin playing -- END_TIME: when the game ends, for any particular reason -- MAP_NAME: the mp_scenario attribute value @@ -61,17 +60,16 @@ create table game_info GAME_ID INT UNSIGNED NOT NULL, INSTANCE_VERSION VARCHAR(255) NOT NULL, GAME_NAME VARCHAR(255) NOT NULL, - CREATE_TIME TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - START_TIME TIMESTAMP NULL DEFAULT NULL, + START_TIME TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, END_TIME TIMESTAMP NULL DEFAULT NULL, - MAP_NAME VARCHAR(255), - ERA_NAME VARCHAR(255), + MAP_NAME VARCHAR(255) NOT NULL, + ERA_NAME VARCHAR(255) NOT NULL, REPLAY_NAME VARCHAR(255), OOS BIT(1) NOT NULL DEFAULT 0, - RELOAD BIT(1), - OBSERVERS BIT(1), - PASSWORD BIT(1), - PUBLIC BIT(1), + RELOAD BIT(1) NOT NULL, + OBSERVERS BIT(1) NOT NULL, + PASSWORD BIT(1) NOT NULL, + PUBLIC BIT(1) NOT NULL, PRIMARY KEY (INSTANCE_UUID, GAME_ID) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;