Only store game information once the game starts.

This commit is contained in:
Pentarctagon 2020-01-17 13:25:52 -06:00 committed by Pentarctagon
parent 8c2f533298
commit 95dc6b5f45
5 changed files with 13 additions and 30 deletions

View file

@ -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<void>("INSERT INTO `" + db_game_info_table_ + "`(INSTANCE_UUID, GAME_ID, INSTANCE_VERSION, GAME_NAME) VALUES(?, ?, ?, ?)",
uuid, game_id, version, name);
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) 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<void>("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<void>("UPDATE `" + db_game_info_table_ + "` SET END_TIME = CURRENT_TIMESTAMP, REPLAY_NAME = ? WHERE INSTANCE_UUID = ? AND GAME_ID = ?",

View file

@ -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);

View file

@ -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_ptr<simple_wml
if(user_handler_) {
const simple_wml::node& m = *g.level().root().child("multiplayer");
user_handler_->db_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) {

View file

@ -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;

View file

@ -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;