Store additional fields in the database.
* Whether the game allows observers.
* Whether the game's replay should be publicly available (currently the same as whether observers are allowed pending the second part of #3909).
* Whether the game had a password set.
* The side's name - this differs from what can be retrieved from USER_ID since it will have the name of any AI used.
Backport of 81e2cae74f
This commit is contained in:
parent
4a96799708
commit
91c4b6c134
8 changed files with 27 additions and 18 deletions
|
@ -452,10 +452,10 @@ void fuh::db_insert_game_info(const std::string& uuid, int game_id, const std::s
|
|||
}
|
||||
}
|
||||
|
||||
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){
|
||||
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 = ? where INSTANCE_UUID = ? and GAME_ID = ?",
|
||||
map_name, era_name, reload, uuid, game_id);
|
||||
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;
|
||||
}
|
||||
|
@ -470,10 +470,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, const std::string& version, const std::string& source){
|
||||
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, const std::string& source, const std::string& current_user){
|
||||
try {
|
||||
prepared_statement<void>("insert into `" + db_game_player_info_table_ + "`(INSTANCE_UUID, GAME_ID, USER_ID, SIDE_NUMBER, IS_HOST, FACTION, CLIENT_VERSION, CLIENT_SOURCE) values(?, ?, IFNULL((select user_id from `"+db_users_table_+"` where username = ?), -1), ?, ?, ?, ?, ?)",
|
||||
uuid, game_id, username, side_number, is_host, faction, version, source);
|
||||
prepared_statement<void>("insert into `" + db_game_player_info_table_ + "`(INSTANCE_UUID, GAME_ID, USER_ID, SIDE_NUMBER, IS_HOST, FACTION, CLIENT_VERSION, CLIENT_SOURCE, USER_NAME) values(?, ?, IFNULL((select user_id from `"+db_users_table_+"` where username = ?), -1), ?, ?, ?, ?, ?, ?)",
|
||||
uuid, game_id, username, side_number, is_host, faction, version, source, current_user);
|
||||
} 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;
|
||||
}
|
||||
|
|
|
@ -82,9 +82,9 @@ class fuh : public user_handler {
|
|||
|
||||
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);
|
||||
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_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);
|
||||
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);
|
||||
void db_set_oos_flag(const std::string& uuid, int game_id);
|
||||
|
||||
|
|
|
@ -291,6 +291,11 @@ public:
|
|||
return password_.empty() || passwd == password_;
|
||||
}
|
||||
|
||||
bool has_password() const
|
||||
{
|
||||
return !password_.empty();
|
||||
}
|
||||
|
||||
const std::string& termination_reason() const
|
||||
{
|
||||
static const std::string aborted = "aborted";
|
||||
|
|
|
@ -241,14 +241,14 @@ std::string suh::get_uuid(){
|
|||
void suh::db_insert_game_info(const std::string& uuid, int game_id, const std::string& version, const std::string& name){
|
||||
std::cout << uuid << " - " << game_id << " - " << version << " - " << name << std::endl;
|
||||
}
|
||||
void suh::db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, int reload){
|
||||
std::cout << uuid << " - " << game_id << " - " << map_name << " - " << era_name << " - " << reload << std::endl;
|
||||
void suh::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){
|
||||
std::cout << uuid << " - " << game_id << " - " << map_name << " - " << era_name << " - " << reload << " - " << observers << " - " << is_public << " - " << has_password << std::endl;
|
||||
}
|
||||
void suh::db_update_game_end(const std::string& uuid, int game_id, const std::string& replay_location){
|
||||
std::cout << uuid << " - " << game_id << " - " << replay_location << std::endl;
|
||||
}
|
||||
void suh::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){
|
||||
std::cout << uuid << " - " << game_id << " - " << username << " - " << side_number << " - " << is_host << " - " << faction << " - " << version << " - " << source << std::endl;
|
||||
void suh::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){
|
||||
std::cout << uuid << " - " << game_id << " - " << username << " - " << side_number << " - " << is_host << " - " << faction << " - " << version << " - " << source << " - " << current_user << std::endl;
|
||||
}
|
||||
void suh::db_insert_modification_info(const std::string& uuid, int game_id, const std::string& modification_name){
|
||||
std::cout << uuid << " - " << game_id << " - " << modification_name << std::endl;
|
||||
|
|
|
@ -69,9 +69,9 @@ class suh : public user_handler {
|
|||
|
||||
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);
|
||||
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_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);
|
||||
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);
|
||||
void db_set_oos_flag(const std::string& uuid, int game_id);
|
||||
|
||||
|
|
|
@ -1744,7 +1744,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
|
|||
|
||||
if(user_handler_) {
|
||||
const simple_wml::node& multiplayer = *g.level().root().child("multiplayer");
|
||||
user_handler_->db_update_game_start(uuid_, g.id(), multiplayer["mp_scenario"].to_string(), multiplayer["mp_era"].to_string(), g.is_reload());
|
||||
user_handler_->db_update_game_start(uuid_, g.id(), multiplayer["mp_scenario"].to_string(), multiplayer["mp_era"].to_string(), g.is_reload(), multiplayer["observer"].to_bool(), multiplayer["observer"].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) {
|
||||
|
@ -1761,7 +1761,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
|
|||
version = player->info().version();
|
||||
source = player->info().source();
|
||||
}
|
||||
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, source);
|
||||
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, source, side["current_player"].to_string());
|
||||
}
|
||||
|
||||
const std::string mods = multiplayer["active_mods"].to_string();
|
||||
|
|
|
@ -173,9 +173,9 @@ class user_handler {
|
|||
|
||||
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) =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_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) =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;
|
||||
virtual void db_set_oos_flag(const std::string& uuid, int game_id) =0;
|
||||
|
||||
|
|
|
@ -69,6 +69,9 @@ create table game_info
|
|||
REPLAY_NAME VARCHAR(255),
|
||||
OOS BIT(1) NOT NULL DEFAULT 0,
|
||||
RELOAD BIT(1),
|
||||
OBSERVERS BIT(1),
|
||||
PASSWORD BIT(1),
|
||||
PUBLIC BIT(1),
|
||||
PRIMARY KEY (INSTANCE_UUID, GAME_ID)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
|
@ -91,6 +94,7 @@ create table game_player_info
|
|||
FACTION VARCHAR(255) NOT NULL,
|
||||
CLIENT_VERSION VARCHAR(255) NOT NULL DEFAULT '',
|
||||
CLIENT_SOURCE VARCHAR(255) NOT NULL DEFAULT '',
|
||||
USER_NAME VARCHAR(255) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (INSTANCE_UUID, GAME_ID, SIDE_NUMBER)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue