Backport of PR#4707.
Validate the dist value server-side rather than client-side. Make the list of sources configurable on wesnothd. Only store game information once the game starts.
This commit is contained in:
parent
465ba7cc41
commit
24398709f0
9 changed files with 27 additions and 45 deletions
|
@ -164,14 +164,7 @@ std::pair<wesnothd_connection_ptr, config> open_connection(std::string host)
|
|||
if(infofile.is_open()){
|
||||
infofile >> info;
|
||||
infofile.close();
|
||||
|
||||
if(info == "Default" || info == "Steam" || info == "SourceForge" || info == "Flatpak"
|
||||
|| info == "macOS App Store" || info == "Linux repository" || info == "iOS" || info == "Android"
|
||||
|| info == "BSD repository") {
|
||||
cfg["client_source"] = info;
|
||||
} else {
|
||||
cfg["client_source"] = "Default";
|
||||
}
|
||||
cfg["client_source"] = info;
|
||||
} else {
|
||||
cfg["client_source"] = "Default";
|
||||
}
|
||||
|
|
|
@ -443,24 +443,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 = ?",
|
||||
|
|
|
@ -81,8 +81,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);
|
||||
|
|
|
@ -238,11 +238,8 @@ std::string suh::get_uuid(){
|
|||
return "";
|
||||
}
|
||||
|
||||
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, 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_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){
|
||||
std::cout << uuid << " - " << game_id << " - " << version << " - " << name << " - " << 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;
|
||||
|
|
|
@ -68,8 +68,7 @@ class suh : public user_handler {
|
|||
bool use_phpbb_encryption() const { return false; }
|
||||
|
||||
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);
|
||||
|
|
|
@ -252,6 +252,7 @@ server::server(int port,
|
|||
, save_replays_(false)
|
||||
, replay_save_path_()
|
||||
, allow_remote_shutdown_(false)
|
||||
, client_sources_()
|
||||
, tor_ip_list_()
|
||||
, failed_login_limit_()
|
||||
, failed_login_ban_()
|
||||
|
@ -464,6 +465,10 @@ void server::load_config()
|
|||
|
||||
allow_remote_shutdown_ = cfg_["allow_remote_shutdown"].to_bool();
|
||||
|
||||
for(const std::string& source : utils::split(cfg_["client_sources"].str())) {
|
||||
client_sources_.insert(source);
|
||||
}
|
||||
|
||||
disallowed_names_.clear();
|
||||
if(cfg_["disallow_names"].empty()) {
|
||||
disallowed_names_.push_back("*admin*");
|
||||
|
@ -1416,10 +1421,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)
|
||||
|
@ -1747,7 +1748,7 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
|
|||
// 1.14.9 and earlier also use whether observers are allowed to determine if the replay should be public
|
||||
// 1.14.10+ have a separate attribute for that
|
||||
bool is_public = m["private_replay"].to_string() == "" ? m["observer"].to_bool() : !m["private_replay"].to_bool();
|
||||
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(), is_public, 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(), is_public, 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) {
|
||||
|
@ -1763,6 +1764,10 @@ void server::handle_player_in_game(socket_ptr socket, std::shared_ptr<simple_wml
|
|||
} else {
|
||||
version = player->info().version();
|
||||
source = player->info().source();
|
||||
|
||||
if(client_sources_.count(source) == 0) {
|
||||
source = "Default";
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -152,6 +152,7 @@ private:
|
|||
bool save_replays_;
|
||||
std::string replay_save_path_;
|
||||
bool allow_remote_shutdown_;
|
||||
std::set<std::string> client_sources_;
|
||||
std::vector<std::string> tor_ip_list_;
|
||||
int failed_login_limit_;
|
||||
time_t failed_login_ban_;
|
||||
|
|
|
@ -172,8 +172,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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue