Store in the database whether the game is a reload or not.

This commit is contained in:
pentarctagon 2019-09-27 11:34:03 -05:00 committed by Gunter Labes
parent 5aaf179728
commit 7cb6482b32
8 changed files with 17 additions and 7 deletions

View file

@ -475,7 +475,7 @@ void mp_lobby::adjust_game_row_contents(const mp::game_info& game, grid* grid, b
}
}
// TODO: move to some general are of the code.
// TODO: move to some general area of the code.
const auto yes_or_no = [](bool val) { return val ? _("yes") : _("no"); };
ss << "\n<big>" << colorize(_("Settings"), font::TITLE_COLOR) << "</big>\n";

View file

@ -427,10 +427,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){
void fuh::db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, bool reload){
try {
prepared_statement<void>("UPDATE `" + db_game_info_table_ + "` SET START_TIME = CURRENT_TIMESTAMP, MAP_NAME = ?, ERA_NAME = ? WHERE INSTANCE_UUID = ? AND GAME_ID = ?",
map_name, era_name, uuid, game_id);
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, std::string(reload?"Y":"N"), 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;
}

View file

@ -71,7 +71,7 @@ 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);
void db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, bool 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, const std::string& is_host, const std::string& faction);
void db_insert_modification_info(const std::string& uuid, int game_id, const std::string& modification_name);

View file

@ -2045,4 +2045,11 @@ void game::send_server_message(const char* message, const socket_ptr& sock, simp
send_to_player(sock, doc);
}
}
bool game::is_reload() const
{
const simple_wml::node& multiplayer = get_multiplayer(level_.root());
return multiplayer.has_attr("savegame") && multiplayer["savegame"].to_bool();
}
} // namespace wesnothd

View file

@ -320,6 +320,8 @@ public:
*/
bool controls_side(const std::vector<int>& sides, const socket_ptr& player) const;
bool is_reload() const;
private:
// forbidden operations
game(const game&) = delete;

View file

@ -1615,7 +1615,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());
user_handler_->db_update_game_start(uuid_, g.id(), multiplayer["mp_scenario"].to_string(), multiplayer["mp_era"].to_string(), g.is_reload());
const simple_wml::node::child_list& sides = g.get_sides_list();
for(unsigned side_index = 0; side_index < sides.size(); ++side_index) {

View file

@ -136,7 +136,7 @@ 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) =0;
virtual void db_update_game_start(const std::string& uuid, int game_id, const std::string& map_name, const std::string& era_name, bool 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, const std::string& is_host, const std::string& faction) =0;
virtual void db_insert_modification_info(const std::string& uuid, int game_id, const std::string& modification_name) =0;

View file

@ -67,6 +67,7 @@ create table game_info
ERA_NAME VARCHAR(255),
REPLAY_NAME VARCHAR(255),
OOS CHAR(1) NOT NULL DEFAULT 'N',
RELOAD CHAR(1),
primary key (INSTANCE_UUID, GAME_ID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;