cleanup some things
This commit is contained in:
		
							parent
							
								
									0359628645
								
							
						
					
					
						commit
						0ab0fcd060
					
				@ -13,7 +13,7 @@ class Advertiser : public QObject {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  Advertiser(QString p_ip, int p_port, int p_ws_port, int p_local_port,
 | 
					  Advertiser(QString p_ip, int p_port, int p_ws_port, int p_local_port,
 | 
				
			||||||
             QString p_name, QString p_description);
 | 
					             QString p_name, QString p_description, QObject *parent = nullptr);
 | 
				
			||||||
  void contactMasterServer();
 | 
					  void contactMasterServer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
signals:
 | 
					signals:
 | 
				
			||||||
 | 
				
			|||||||
@ -22,7 +22,6 @@ public:
 | 
				
			|||||||
  AkashiMain(QWidget *parent = nullptr);
 | 
					  AkashiMain(QWidget *parent = nullptr);
 | 
				
			||||||
  ~AkashiMain();
 | 
					  ~AkashiMain();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  QSettings config;
 | 
					 | 
				
			||||||
  ConfigManager config_manager;
 | 
					  ConfigManager config_manager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void generateDefaultConfig(bool backup_old);
 | 
					  void generateDefaultConfig(bool backup_old);
 | 
				
			||||||
 | 
				
			|||||||
@ -10,14 +10,22 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class ConfigManager {
 | 
					class ConfigManager {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  ConfigManager(QSettings *);
 | 
					  ConfigManager();
 | 
				
			||||||
  bool initConfig();
 | 
					  bool initConfig();
 | 
				
			||||||
  void generateDefaultConfig(bool backup_old);
 | 
					  void generateDefaultConfig(bool backup_old);
 | 
				
			||||||
  void updateConfig(int current_version);
 | 
					  void updateConfig(int current_version);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool loadServerSettings(QString *ms_ip, int *port, int *ws_port,
 | 
					  struct server_settings {
 | 
				
			||||||
                          int *local_port, QString *name, QString *description,
 | 
					    QString ms_ip;
 | 
				
			||||||
                          bool *advertise_server);
 | 
					    int port;
 | 
				
			||||||
 | 
					    int ws_port;
 | 
				
			||||||
 | 
					    int local_port;
 | 
				
			||||||
 | 
					    QString name;
 | 
				
			||||||
 | 
					    QString description;
 | 
				
			||||||
 | 
					    bool advertise_server;
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  bool loadServerSettings(server_settings *settings);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
  QSettings *config;
 | 
					  QSettings *config;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,9 @@
 | 
				
			|||||||
#include "include/advertiser.h"
 | 
					#include "include/advertiser.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Advertiser::Advertiser(QString p_ip, int p_port, int p_ws_port,
 | 
					Advertiser::Advertiser(QString p_ip, int p_port, int p_ws_port,
 | 
				
			||||||
                       int p_local_port, QString p_name, QString p_description)
 | 
					                       int p_local_port, QString p_name, QString p_description,
 | 
				
			||||||
 | 
					                       QObject *parent)
 | 
				
			||||||
 | 
					    : QObject(parent)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  ip = p_ip;
 | 
					  ip = p_ip;
 | 
				
			||||||
  port = p_port;
 | 
					  port = p_port;
 | 
				
			||||||
@ -41,7 +43,7 @@ void Advertiser::socketConnected()
 | 
				
			|||||||
    concat_ports = QString::number(local_port) + "&" + QString::number(ws_port);
 | 
					    concat_ports = QString::number(local_port) + "&" + QString::number(ws_port);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  AOPacket ao_packet("SCC", {concat_ports, name, description,
 | 
					  AOPacket ao_packet("SCC", {concat_ports, name, description,
 | 
				
			||||||
                     "akashi v" + QApplication::applicationVersion()});
 | 
					                             "akashi v" + QApplication::applicationVersion()});
 | 
				
			||||||
  QByteArray data = ao_packet.toUtf8();
 | 
					  QByteArray data = ao_packet.toUtf8();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  socket->write(data);
 | 
					  socket->write(data);
 | 
				
			||||||
 | 
				
			|||||||
@ -2,8 +2,7 @@
 | 
				
			|||||||
#include "ui_akashimain.h"
 | 
					#include "ui_akashimain.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AkashiMain::AkashiMain(QWidget *parent)
 | 
					AkashiMain::AkashiMain(QWidget *parent)
 | 
				
			||||||
    : QMainWindow(parent), config("config.ini", QSettings::IniFormat),
 | 
					    : QMainWindow(parent), config_manager(), ui(new Ui::AkashiMain)
 | 
				
			||||||
      config_manager(&config), ui(new Ui::AkashiMain)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  ui->setupUi(this);
 | 
					  ui->setupUi(this);
 | 
				
			||||||
  qDebug("Main application started");
 | 
					  qDebug("Main application started");
 | 
				
			||||||
@ -11,27 +10,24 @@ AkashiMain::AkashiMain(QWidget *parent)
 | 
				
			|||||||
  if (config_manager.initConfig()) {
 | 
					  if (config_manager.initConfig()) {
 | 
				
			||||||
    // Config is sound, so proceed with starting the server
 | 
					    // Config is sound, so proceed with starting the server
 | 
				
			||||||
    // Validate some of the config before passing it on
 | 
					    // Validate some of the config before passing it on
 | 
				
			||||||
    QString ms_ip, name, description;
 | 
					    ConfigManager::server_settings settings;
 | 
				
			||||||
    int port, ws_port, local_port;
 | 
					    bool config_valid = config_manager.loadServerSettings(&settings);
 | 
				
			||||||
    bool advertise_server;
 | 
					 | 
				
			||||||
    bool config_valid = config_manager.loadServerSettings(
 | 
					 | 
				
			||||||
        &ms_ip, &port, &ws_port, &local_port, &name, &description,
 | 
					 | 
				
			||||||
        &advertise_server);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!config_valid) {
 | 
					    if (!config_valid) {
 | 
				
			||||||
      // TODO: send signal config invalid
 | 
					      // TODO: send signal config invalid
 | 
				
			||||||
      config_manager.generateDefaultConfig(true);
 | 
					      config_manager.generateDefaultConfig(true);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
      if (advertise_server) {
 | 
					      if (settings.advertise_server) {
 | 
				
			||||||
        advertiser =
 | 
					        advertiser = new Advertiser(settings.ms_ip, settings.port,
 | 
				
			||||||
            new Advertiser(ms_ip, port, ws_port, local_port, name, description);
 | 
					                                    settings.ws_port, settings.local_port,
 | 
				
			||||||
 | 
					                                    settings.name, settings.description, this);
 | 
				
			||||||
        advertiser->contactMasterServer();
 | 
					        advertiser->contactMasterServer();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // TODO: start the server here
 | 
					      // TODO: start the server here
 | 
				
			||||||
      // TODO: send signal server starting.
 | 
					      // TODO: send signal server starting.
 | 
				
			||||||
      server = new Server(port, ws_port);
 | 
					      server = new Server(settings.port, settings.ws_port);
 | 
				
			||||||
      server->start();
 | 
					      server->start();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -19,6 +19,6 @@ QString AOPacket::toString()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
QByteArray AOPacket::toUtf8()
 | 
					QByteArray AOPacket::toUtf8()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QString packet_string = toString();
 | 
					  QString packet_string = toString();
 | 
				
			||||||
    return packet_string.toUtf8();
 | 
					  return packet_string.toUtf8();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,9 @@
 | 
				
			|||||||
#include <include/config_manager.h>
 | 
					#include <include/config_manager.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ConfigManager::ConfigManager(QSettings *p_config) { config = p_config; }
 | 
					ConfigManager::ConfigManager()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  config = new QSettings("config.ini", QSettings::IniFormat);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Validate and set up the config
 | 
					// Validate and set up the config
 | 
				
			||||||
bool ConfigManager::initConfig()
 | 
					bool ConfigManager::initConfig()
 | 
				
			||||||
@ -106,23 +109,22 @@ void ConfigManager::updateConfig(int current_version)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Validate and retriever settings related to advertising and the server
 | 
					// Validate and retriever settings related to advertising and the server
 | 
				
			||||||
bool ConfigManager::loadServerSettings(QString *ms_ip, int *port, int *ws_port,
 | 
					bool ConfigManager::loadServerSettings(server_settings *settings)
 | 
				
			||||||
                                       int *local_port, QString *name,
 | 
					 | 
				
			||||||
                                       QString *description,
 | 
					 | 
				
			||||||
                                       bool *advertise_server)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  bool port_conversion_success;
 | 
					  bool port_conversion_success;
 | 
				
			||||||
  bool ws_port_conversion_success;
 | 
					  bool ws_port_conversion_success;
 | 
				
			||||||
  bool local_port_conversion_success;
 | 
					  bool local_port_conversion_success;
 | 
				
			||||||
  config->beginGroup("Options");
 | 
					  config->beginGroup("Options");
 | 
				
			||||||
  *ms_ip = config->value("ms_ip", "master.aceattorneyonline.com").toString();
 | 
					  settings->ms_ip =
 | 
				
			||||||
  *port = config->value("ms_port", "27016").toInt(&port_conversion_success);
 | 
					      config->value("ms_ip", "master.aceattorneyonline.com").toString();
 | 
				
			||||||
  *ws_port =
 | 
					  settings->port =
 | 
				
			||||||
 | 
					      config->value("ms_port", "27016").toInt(&port_conversion_success);
 | 
				
			||||||
 | 
					  settings->ws_port =
 | 
				
			||||||
      config->value("webao_port", "27017").toInt(&ws_port_conversion_success);
 | 
					      config->value("webao_port", "27017").toInt(&ws_port_conversion_success);
 | 
				
			||||||
  *local_port =
 | 
					  settings->local_port =
 | 
				
			||||||
      config->value("port", "27016").toInt(&local_port_conversion_success);
 | 
					      config->value("port", "27016").toInt(&local_port_conversion_success);
 | 
				
			||||||
  *name = config->value("server_name", "My First Server").toString();
 | 
					  settings->name = config->value("server_name", "My First Server").toString();
 | 
				
			||||||
  *description =
 | 
					  settings->description =
 | 
				
			||||||
      config->value("server_description", "This is my flashy new server")
 | 
					      config->value("server_description", "This is my flashy new server")
 | 
				
			||||||
          .toString();
 | 
					          .toString();
 | 
				
			||||||
  config->endGroup();
 | 
					  config->endGroup();
 | 
				
			||||||
@ -132,12 +134,12 @@ bool ConfigManager::loadServerSettings(QString *ms_ip, int *port, int *ws_port,
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
  else {
 | 
					  else {
 | 
				
			||||||
    if (config->value("advertise", "true").toString() != "true")
 | 
					    if (config->value("advertise", "true").toString() != "true")
 | 
				
			||||||
      *advertise_server = false;
 | 
					      settings->advertise_server = false;
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      *advertise_server = true;
 | 
					      settings->advertise_server = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (config->value("webao_enable", "true").toString() != "true")
 | 
					    if (config->value("webao_enable", "true").toString() != "true")
 | 
				
			||||||
      *ws_port = -1;
 | 
					      settings->ws_port = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -6,7 +6,4 @@ Server::Server(int p_port, int p_ws_port)
 | 
				
			|||||||
  ws_port = p_ws_port;
 | 
					  ws_port = p_ws_port;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Server::start()
 | 
					void Server::start() {}
 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user