From 03596286451dc86b6899b7e9ebde1716d8f31f60 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Sun, 23 Aug 2020 15:23:12 -0500 Subject: [PATCH] proper aopacket type --- include/advertiser.h | 2 +- include/aopacket.h | 19 +++++++++++++++++++ include/packet_manager.h | 12 ------------ src/advertiser.cpp | 9 +++++---- src/aopacket.cpp | 24 ++++++++++++++++++++++++ src/main.cpp | 7 ++++++- src/packet_manager.cpp | 12 ------------ src/server.cpp | 5 ++++- 8 files changed, 59 insertions(+), 31 deletions(-) create mode 100644 include/aopacket.h delete mode 100644 include/packet_manager.h create mode 100644 src/aopacket.cpp delete mode 100644 src/packet_manager.cpp diff --git a/include/advertiser.h b/include/advertiser.h index fa631ba..8b18294 100644 --- a/include/advertiser.h +++ b/include/advertiser.h @@ -1,7 +1,7 @@ #ifndef MASTER_H #define MASTER_H -#include +#include #include #include diff --git a/include/aopacket.h b/include/aopacket.h new file mode 100644 index 0000000..4f9f3d7 --- /dev/null +++ b/include/aopacket.h @@ -0,0 +1,19 @@ +#ifndef PACKET_MANAGER_H +#define PACKET_MANAGER_H + +#include +#include +#include + +class AOPacket { +public: + AOPacket(QString p_header, QStringList p_contents); + QString toString(); + QByteArray toUtf8(); + +private: + QString header; + QStringList contents; +}; + +#endif // PACKET_MANAGER_H diff --git a/include/packet_manager.h b/include/packet_manager.h deleted file mode 100644 index 14b9618..0000000 --- a/include/packet_manager.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef PACKET_MANAGER_H -#define PACKET_MANAGER_H - -#include -#include - -class PacketManager { -public: - static QString buildPacket(QString header, QStringList contents); -}; - -#endif // PACKET_MANAGER_H diff --git a/src/advertiser.cpp b/src/advertiser.cpp index 472a7f4..cf84cf6 100644 --- a/src/advertiser.cpp +++ b/src/advertiser.cpp @@ -27,7 +27,7 @@ void Advertiser::readData() // The information coming back from the MS isn't very useful // However, it can be useful to see it when debugging // TODO: master network debug switch - // qDebug() << socket->readAll(); + qDebug() << "From MS:" << socket->readAll(); } void Advertiser::socketConnected() @@ -40,12 +40,13 @@ void Advertiser::socketConnected() else concat_ports = QString::number(local_port) + "&" + QString::number(ws_port); - QString ao_packet = PacketManager::buildPacket( - "SCC", {concat_ports, name, description, - "akashi v" + QApplication::applicationVersion()}); + AOPacket ao_packet("SCC", {concat_ports, name, description, + "akashi v" + QApplication::applicationVersion()}); QByteArray data = ao_packet.toUtf8(); socket->write(data); + // TODO: master network debug switch + qDebug() << "To MS:" << data; socket->flush(); } diff --git a/src/aopacket.cpp b/src/aopacket.cpp new file mode 100644 index 0000000..30ade9e --- /dev/null +++ b/src/aopacket.cpp @@ -0,0 +1,24 @@ +#include + +AOPacket::AOPacket(QString p_header, QStringList p_contents) +{ + header = p_header; + contents = p_contents; +} + +QString AOPacket::toString() +{ + QString ao_packet = header; + for (int i = 0; i < contents.length(); i++) { + ao_packet += "#" + contents[i]; + } + ao_packet += "#%"; + + return ao_packet; +} + +QByteArray AOPacket::toUtf8() +{ + QString packet_string = toString(); + return packet_string.toUtf8(); +} diff --git a/src/main.cpp b/src/main.cpp index 85b1a29..878e546 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,8 +36,13 @@ int main(int argc, char *argv[]) QCommandLineOption headlessOption( QStringList() << "l" << "headless", - app.translate("main", "Run the server without a GUI")); + app.translate("main", "Run the server without a GUI.")); + QCommandLineOption verboseNetworkOption( + QStringList() << "nv" + << "verbose-network", + app.translate("main", "Write all network traffic to the console.")); parser.addOption(headlessOption); + parser.addOption(verboseNetworkOption); parser.process(app); bool headless = parser.isSet(headlessOption); diff --git a/src/packet_manager.cpp b/src/packet_manager.cpp deleted file mode 100644 index db51d25..0000000 --- a/src/packet_manager.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -QString PacketManager::buildPacket(QString header, QStringList contents) -{ - QString ao_packet = header; - for (int i = 0; i < contents.length(); i++) { - ao_packet += "#" + contents[i]; - } - ao_packet += "#%"; - - return ao_packet; -} diff --git a/src/server.cpp b/src/server.cpp index b5a3a6e..5f658b7 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -6,4 +6,7 @@ Server::Server(int p_port, int p_ws_port) ws_port = p_ws_port; } -void Server::start() {} +void Server::start() +{ + +}