start implemented the actual server

This commit is contained in:
scatterflower 2020-08-23 14:43:19 -05:00
parent ce46fa1657
commit a3d2c1aa66
7 changed files with 37 additions and 14 deletions

View File

@ -8,7 +8,7 @@
#include <QApplication> #include <QApplication>
#include <QHostAddress> #include <QHostAddress>
class Advertiser : public QObject{ class Advertiser : public QObject {
Q_OBJECT Q_OBJECT
public: public:

View File

@ -3,6 +3,7 @@
#include <include/advertiser.h> #include <include/advertiser.h>
#include <include/config_manager.h> #include <include/config_manager.h>
#include <include/server.h>
#include <QMainWindow> #include <QMainWindow>
#include <QSettings> #include <QSettings>
@ -28,5 +29,6 @@ public:
private: private:
Ui::AkashiMain *ui; Ui::AkashiMain *ui;
Advertiser *advertiser; Advertiser *advertiser;
Server *server;
}; };
#endif // AKASHIMAIN_H #endif // AKASHIMAIN_H

View File

@ -15,7 +15,7 @@ public:
void generateDefaultConfig(bool backup_old); void generateDefaultConfig(bool backup_old);
void updateConfig(int current_version); 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); bool loadServerSettings(QString* ms_ip, int* port, int* ws_port, int* local_port, QString* name, QString* description, bool* advertise_server);
private: private:
QSettings* config; QSettings* config;

View File

@ -1,11 +1,20 @@
#ifndef SERVER_H #ifndef SERVER_H
#define SERVER_H #define SERVER_H
#include <QTcpServer>
#include <QString>
class Server class Server : public QObject
{ {
Q_OBJECT
public: public:
Server(); Server(int p_port, int p_ws_port);
void start();
private:
int port;
int ws_port;
}; };
#endif // SERVER_H #endif // SERVER_H

View File

@ -12,18 +12,25 @@ 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
// TODO: start the server here
// TODO: send signal server starting
// Validate some of the config before passing it on // Validate some of the config before passing it on
QString ms_ip, name, description; QString ms_ip, name, description;
int port, ws_port, local_port; int port, ws_port, local_port;
bool advertise_server; bool advertise_server;
config_manager.loadAdvertiserSettings(&ms_ip, &port, &ws_port, &local_port, &name, &description, &advertise_server); bool config_valid = config_manager.loadServerSettings(&ms_ip, &port, &ws_port, &local_port, &name, &description, &advertise_server);
if(advertise_server){ if(!config_valid) {
advertiser = new Advertiser(ms_ip, port, ws_port, local_port, name, description); // TODO: send signal config invalid
advertiser->contactMasterServer(); config_manager.generateDefaultConfig(true);
} else {
if(advertise_server) {
advertiser = new Advertiser(ms_ip, port, ws_port, local_port, name, description);
advertiser->contactMasterServer();
}
// TODO: start the server here
// TODO: send signal server starting.
server = new Server(port, ws_port);
server->start();
} }
} }
} }

View File

@ -103,9 +103,8 @@ 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::loadAdvertiserSettings(QString* ms_ip, int* port, int* ws_port, int* local_port, QString* name, QString* description, bool* advertise_server) bool ConfigManager::loadServerSettings(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 port_conversion_success;
bool ws_port_conversion_success; bool ws_port_conversion_success;
bool local_port_conversion_success; bool local_port_conversion_success;

View File

@ -1,6 +1,12 @@
#include "include/server.h" #include "include/server.h"
Server::Server() Server::Server(int p_port, int p_ws_port)
{
port = p_port;
ws_port = p_ws_port;
}
void Server::start()
{ {
} }