Skip to content

Commit

Permalink
Store the client version in the database.
Browse files Browse the repository at this point in the history
This will now store the version of the client playing a side in `game_player_info`.
  • Loading branch information
Pentarctagon committed Oct 20, 2019
1 parent f7a21a0 commit c04ecaa
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/server/forum_user_handler.cpp
Expand Up @@ -445,10 +445,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){
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){
try {
prepared_statement<void>("INSERT INTO `" + db_game_player_info_table_ + "`(INSTANCE_UUID, GAME_ID, USER_ID, SIDE_NUMBER, IS_HOST, FACTION) VALUES(?, ?, IFNULL((SELECT user_id FROM `"+db_users_table_+"` WHERE username = ?), -1), ?, ?, ?)",
uuid, game_id, username, side_number, is_host, faction);
prepared_statement<void>("INSERT INTO `" + db_game_player_info_table_ + "`(INSTANCE_UUID, GAME_ID, USER_ID, SIDE_NUMBER, IS_HOST, FACTION, CLIENT_VERSION) VALUES(?, ?, IFNULL((SELECT user_id FROM `"+db_users_table_+"` WHERE username = ?), -1), ?, ?, ?, ?)",
uuid, game_id, username, side_number, is_host, faction, version);
} 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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/forum_user_handler.hpp
Expand Up @@ -73,7 +73,7 @@ class fuh : public user_handler {
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_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);
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);
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);

Expand Down
3 changes: 2 additions & 1 deletion src/server/server.cpp
Expand Up @@ -1620,7 +1620,8 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
const simple_wml::node::child_list& sides = g.get_sides_list();
for(unsigned side_index = 0; side_index < sides.size(); ++side_index) {
const simple_wml::node& side = *sides[side_index];
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());
std::string version = player_connections_.get<name_t>().find(side["player_id"].to_string())->info().version();
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);
}

const std::string mods = multiplayer["active_mods"].to_string();
Expand Down
2 changes: 1 addition & 1 deletion src/server/user_handler.hpp
Expand Up @@ -138,7 +138,7 @@ class user_handler {
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_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) =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) =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;
};
13 changes: 7 additions & 6 deletions utils/mp-server/table_definitions.sql
Expand Up @@ -81,12 +81,13 @@ create table game_info
-- STATUS: the status of the side, currently only updated at game end
create table game_player_info
(
INSTANCE_UUID CHAR(36) NOT NULL,
GAME_ID INT UNSIGNED NOT NULL,
USER_ID INT NOT NULL,
SIDE_NUMBER SMALLINT UNSIGNED NOT NULL,
IS_HOST BIT(1) NOT NULL,
FACTION VARCHAR(255) NOT NULL,
INSTANCE_UUID CHAR(36) NOT NULL,
GAME_ID INT UNSIGNED NOT NULL,
USER_ID INT NOT NULL,
SIDE_NUMBER SMALLINT UNSIGNED NOT NULL,
IS_HOST BIT(1) NOT NULL,
FACTION VARCHAR(255) NOT NULL,
CLIENT_VERSION VARCHAR(255) NOT NULL DEFAULT '',
PRIMARY KEY (INSTANCE_UUID, GAME_ID, SIDE_NUMBER)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Expand Down

0 comments on commit c04ecaa

Please sign in to comment.