move more config logic into config_manager.cpp

This commit is contained in:
scatterflower 2020-08-23 14:28:16 -05:00
parent 04ae43d960
commit ce46fa1657
3 changed files with 39 additions and 17 deletions

View File

@ -15,6 +15,8 @@ public:
void generateDefaultConfig(bool backup_old);
void updateConfig(int current_version);
bool loadAdvertiserSettings(QString* ms_ip, int* port, int* ws_port, int* local_port, QString* name, QString* description, bool* advertise_server);
private:
QSettings* config;
};

View File

@ -16,23 +16,12 @@ AkashiMain::AkashiMain(QWidget *parent)
// TODO: send signal server starting
// Validate some of the config before passing it on
// TODO: Move this logic into config_manager.cpp
bool port_conversion_success;
bool ws_port_conversion_success;
bool local_port_conversion_success;
config.beginGroup("Options");
QString ms_ip = config.value("ms_ip", "master.aceattorneyonline.com").toString();
int port = config.value("ms_port", "27016").toInt(&port_conversion_success);
int ws_port = config.value("webao_port", "27017").toInt(&ws_port_conversion_success);
int local_port = config.value("port", "27016").toInt(&local_port_conversion_success);
QString name = config.value("server_name", "My First Server").toString();
QString description = config.value("server_description", "This is my flashy new server").toString();
config.endGroup();
if(!port_conversion_success || !ws_port_conversion_success || !local_port_conversion_success) {
// TODO: send signal invalid conf due to bad port number
} else {
if(config.value("advertise", "true").toString() != "true")
ws_port = -1;
QString ms_ip, name, description;
int port, ws_port, local_port;
bool advertise_server;
config_manager.loadAdvertiserSettings(&ms_ip, &port, &ws_port, &local_port, &name, &description, &advertise_server);
if(advertise_server){
advertiser = new Advertiser(ms_ip, port, ws_port, local_port, name, description);
advertiser->contactMasterServer();
}

View File

@ -5,6 +5,7 @@ ConfigManager::ConfigManager(QSettings* p_config)
config = p_config;
}
// Validate and set up the config
bool ConfigManager::initConfig()
{
config->beginGroup("Info");
@ -100,3 +101,33 @@ void ConfigManager::updateConfig(int current_version)
}
}
}
// Validate and retriever settings related to advertising and the server
bool ConfigManager::loadAdvertiserSettings(QString* ms_ip, int* port, int* ws_port, int* local_port, QString* name, QString* description, bool* advertise_server)
{
// TODO: Move this logic into config_manager.cpp
bool port_conversion_success;
bool ws_port_conversion_success;
bool local_port_conversion_success;
config->beginGroup("Options");
*ms_ip = config->value("ms_ip", "master.aceattorneyonline.com").toString();
*port = config->value("ms_port", "27016").toInt(&port_conversion_success);
*ws_port = config->value("webao_port", "27017").toInt(&ws_port_conversion_success);
*local_port = config->value("port", "27016").toInt(&local_port_conversion_success);
*name = config->value("server_name", "My First Server").toString();
*description = config->value("server_description", "This is my flashy new server").toString();
config->endGroup();
if(!port_conversion_success || !ws_port_conversion_success || !local_port_conversion_success) {
return false;
} else {
if(config->value("advertise", "true").toString() != "true")
*advertise_server = false;
else
*advertise_server = true;
if(config->value("webao_enable", "true").toString() != "true")
*ws_port = -1;
return true;
}
}