From ce46fa1657310b84c11d914a4e44f961748e44b0 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sun, 23 Aug 2020 14:28:16 -0500 Subject: [PATCH] move more config logic into config_manager.cpp --- include/config_manager.h | 2 ++ src/akashimain.cpp | 23 ++++++----------------- src/config_manager.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/include/config_manager.h b/include/config_manager.h index 9149660..a0b60c4 100644 --- a/include/config_manager.h +++ b/include/config_manager.h @@ -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; }; diff --git a/src/akashimain.cpp b/src/akashimain.cpp index 733b9ce..f7f34a7 100644 --- a/src/akashimain.cpp +++ b/src/akashimain.cpp @@ -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(); } diff --git a/src/config_manager.cpp b/src/config_manager.cpp index d2dcb12..fe72120 100644 --- a/src/config_manager.cpp +++ b/src/config_manager.cpp @@ -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; + } +}