proper aopacket type

This commit is contained in:
scatterflower 2020-08-23 15:23:12 -05:00
parent 28ed456386
commit 0359628645
8 changed files with 59 additions and 31 deletions

View File

@ -1,7 +1,7 @@
#ifndef MASTER_H #ifndef MASTER_H
#define MASTER_H #define MASTER_H
#include <include/packet_manager.h> #include <include/aopacket.h>
#include <QApplication> #include <QApplication>
#include <QHostAddress> #include <QHostAddress>

19
include/aopacket.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef PACKET_MANAGER_H
#define PACKET_MANAGER_H
#include <QByteArray>
#include <QString>
#include <QStringList>
class AOPacket {
public:
AOPacket(QString p_header, QStringList p_contents);
QString toString();
QByteArray toUtf8();
private:
QString header;
QStringList contents;
};
#endif // PACKET_MANAGER_H

View File

@ -1,12 +0,0 @@
#ifndef PACKET_MANAGER_H
#define PACKET_MANAGER_H
#include <QString>
#include <QStringList>
class PacketManager {
public:
static QString buildPacket(QString header, QStringList contents);
};
#endif // PACKET_MANAGER_H

View File

@ -27,7 +27,7 @@ void Advertiser::readData()
// The information coming back from the MS isn't very useful // The information coming back from the MS isn't very useful
// However, it can be useful to see it when debugging // However, it can be useful to see it when debugging
// TODO: master network debug switch // TODO: master network debug switch
// qDebug() << socket->readAll(); qDebug() << "From MS:" << socket->readAll();
} }
void Advertiser::socketConnected() void Advertiser::socketConnected()
@ -40,12 +40,13 @@ void Advertiser::socketConnected()
else else
concat_ports = QString::number(local_port) + "&" + QString::number(ws_port); concat_ports = QString::number(local_port) + "&" + QString::number(ws_port);
QString ao_packet = PacketManager::buildPacket( AOPacket ao_packet("SCC", {concat_ports, name, description,
"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);
// TODO: master network debug switch
qDebug() << "To MS:" << data;
socket->flush(); socket->flush();
} }

24
src/aopacket.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <include/aopacket.h>
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();
}

View File

@ -36,8 +36,13 @@ int main(int argc, char *argv[])
QCommandLineOption headlessOption( QCommandLineOption headlessOption(
QStringList() << "l" QStringList() << "l"
<< "headless", << "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(headlessOption);
parser.addOption(verboseNetworkOption);
parser.process(app); parser.process(app);
bool headless = parser.isSet(headlessOption); bool headless = parser.isSet(headlessOption);

View File

@ -1,12 +0,0 @@
#include <include/packet_manager.h>
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;
}

View File

@ -6,4 +6,7 @@ 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()
{
}