clang format, and indentation change

This commit is contained in:
scatterflower 2020-08-25 07:07:08 -05:00
parent be8d8b215e
commit 42df56942b
16 changed files with 613 additions and 596 deletions

View File

@ -1,2 +1,5 @@
BasedOnStyle: LLVM BasedOnStyle: LLVM
IndentWidth: 4
Language: Cpp
PointerAlignment: Left
BreakBeforeBraces: Stroustrup BreakBeforeBraces: Stroustrup

View File

@ -11,19 +11,20 @@
class Advertiser : public QObject { class Advertiser : public QObject {
Q_OBJECT Q_OBJECT
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, QObject *parent = nullptr); QString p_name, QString p_description,
QObject* parent = nullptr);
void contactMasterServer(); void contactMasterServer();
signals: signals:
public slots: public slots:
void readData(); void readData();
void socketConnected(); void socketConnected();
void socketDisconnected(); void socketDisconnected();
private: private:
QString ip; QString ip;
int port; int port;
int ws_port; int ws_port;
@ -31,7 +32,7 @@ private:
QString name; QString name;
QString description; QString description;
QTcpSocket *socket; QTcpSocket* socket;
}; };
#endif // MASTER_H #endif // MASTER_H

View File

@ -18,8 +18,8 @@ QT_END_NAMESPACE
class AkashiMain : public QMainWindow { class AkashiMain : public QMainWindow {
Q_OBJECT Q_OBJECT
public: public:
AkashiMain(QWidget *parent = nullptr); AkashiMain(QWidget* parent = nullptr);
~AkashiMain(); ~AkashiMain();
ConfigManager config_manager; ConfigManager config_manager;
@ -27,9 +27,9 @@ public:
void generateDefaultConfig(bool backup_old); void generateDefaultConfig(bool backup_old);
void updateConfig(int current_version); void updateConfig(int current_version);
private: private:
Ui::AkashiMain *ui; Ui::AkashiMain* ui;
Advertiser *advertiser; Advertiser* advertiser;
Server *server; Server* server;
}; };
#endif // AKASHIMAIN_H #endif // AKASHIMAIN_H

View File

@ -6,7 +6,7 @@
#include <QTcpSocket> #include <QTcpSocket>
class AOClient { class AOClient {
public: public:
AOClient(QHostAddress p_remote_ip); AOClient(QHostAddress p_remote_ip);
~AOClient(); ~AOClient();
@ -21,7 +21,7 @@ public:
int current_area; int current_area;
QString current_char; QString current_char;
private: private:
QString hwid; QString hwid;
QString ipid; QString ipid;
}; };

View File

@ -7,7 +7,7 @@
#include <QStringList> #include <QStringList>
class AOPacket { class AOPacket {
public: public:
AOPacket(QString p_header, QStringList p_contents); AOPacket(QString p_header, QStringList p_contents);
AOPacket(QString packet); AOPacket(QString packet);
QString toString(); QString toString();

View File

@ -1,11 +1,11 @@
#ifndef AREA_DATA_H #ifndef AREA_DATA_H
#define AREA_DATA_H #define AREA_DATA_H
#include <QString>
#include <QMap> #include <QMap>
#include <QString>
class AreaData { class AreaData {
public: public:
AreaData(QStringList characters); AreaData(QStringList characters);
QString name; QString name;

View File

@ -5,12 +5,12 @@
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QFileInfo>
#include <QFile> #include <QFile>
#include <QFileInfo>
#include <QSettings> #include <QSettings>
class ConfigManager { class ConfigManager {
public: public:
ConfigManager(); ConfigManager();
bool initConfig(); bool initConfig();
void generateDefaultConfig(bool backup_old); void generateDefaultConfig(bool backup_old);
@ -26,10 +26,10 @@ public:
bool advertise_server; bool advertise_server;
}; };
bool loadServerSettings(server_settings *settings); bool loadServerSettings(server_settings* settings);
private: private:
QSettings *config; QSettings* config;
}; };
#endif // CONFIG_MANAGER_H #endif // CONFIG_MANAGER_H

View File

@ -7,38 +7,38 @@
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include <QFile>
#include <QMap> #include <QMap>
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QTcpServer> #include <QTcpServer>
#include <QTcpSocket> #include <QTcpSocket>
#include <QFile>
class Server : public QObject { class Server : public QObject {
Q_OBJECT Q_OBJECT
public: public:
Server(int p_port, int p_ws_port, QObject *parent = nullptr); Server(int p_port, int p_ws_port, QObject* parent = nullptr);
void start(); void start();
signals: signals:
public slots: public slots:
void clientConnected(); void clientConnected();
void clientDisconnected(); void clientDisconnected();
void clientData(); void clientData();
private: private:
void handlePacket(AOPacket packet, QTcpSocket *socket); void handlePacket(AOPacket packet, QTcpSocket* socket);
QTcpSocket *getClient(QString ipid); QTcpSocket* getClient(QString ipid);
void broadcast(AOPacket packet); void broadcast(AOPacket packet);
QTcpServer *server; QTcpServer* server;
int port; int port;
int ws_port; int ws_port;
QMap<QTcpSocket *, AOClient *> clients; QMap<QTcpSocket*, AOClient*> clients;
QString partial_packet; QString partial_packet;
bool is_partial; bool is_partial;

View File

@ -2,7 +2,7 @@
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)
: QObject(parent) : QObject(parent)
{ {
ip = p_ip; ip = p_ip;
@ -40,9 +40,11 @@ void Advertiser::socketConnected()
if (ws_port == -1) if (ws_port == -1)
concat_ports = QString::number(local_port); concat_ports = QString::number(local_port);
else else
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();

View File

@ -1,7 +1,7 @@
#include "include/akashimain.h" #include "include/akashimain.h"
#include "ui_akashimain.h" #include "ui_akashimain.h"
AkashiMain::AkashiMain(QWidget *parent) AkashiMain::AkashiMain(QWidget* parent)
: QMainWindow(parent), config_manager(), ui(new Ui::AkashiMain) : QMainWindow(parent), config_manager(), ui(new Ui::AkashiMain)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -20,7 +20,8 @@ AkashiMain::AkashiMain(QWidget *parent)
else { else {
if (settings.advertise_server) { if (settings.advertise_server) {
// TODO: send signal advertiser started // TODO: send signal advertiser started
advertiser = new Advertiser(settings.ms_ip, settings.port, advertiser =
new Advertiser(settings.ms_ip, settings.port,
settings.ws_port, settings.local_port, settings.ws_port, settings.local_port,
settings.name, settings.description, this); settings.name, settings.description, this);
advertiser->contactMasterServer(); advertiser->contactMasterServer();

View File

@ -15,7 +15,8 @@ void AOClient::setHwid(QString p_hwid)
{ {
hwid = p_hwid; hwid = p_hwid;
QCryptographicHash hash(QCryptographicHash::Md5); // Don't need security, just QCryptographicHash hash(
QCryptographicHash::Md5); // Don't need security, just
// hashing for uniqueness // hashing for uniqueness
QString concat_ip_id = remote_ip.toString() + p_hwid; QString concat_ip_id = remote_ip.toString() + p_hwid;
hash.addData(concat_ip_id.toUtf8()); hash.addData(concat_ip_id.toUtf8());

View File

@ -2,8 +2,7 @@
AreaData::AreaData(QStringList characters) AreaData::AreaData(QStringList characters)
{ {
for(QString cur_char : characters) for (QString cur_char : characters) {
{
characters_taken.insert(cur_char, false); characters_taken.insert(cur_char, false);
} }
} }

View File

@ -9,8 +9,7 @@ ConfigManager::ConfigManager()
bool ConfigManager::initConfig() bool ConfigManager::initConfig()
{ {
QFileInfo char_list_info("characters.txt"); QFileInfo char_list_info("characters.txt");
if(!(char_list_info.exists() && char_list_info.isFile())) if (!(char_list_info.exists() && char_list_info.isFile())) {
{
// TODO: signals go here // TODO: signals go here
QFile char_list("characters.txt"); QFile char_list("characters.txt");
if (!char_list.open(QIODevice::WriteOnly | QIODevice::Text)) if (!char_list.open(QIODevice::WriteOnly | QIODevice::Text))
@ -151,7 +150,8 @@ void ConfigManager::updateConfig(int current_version)
if (current_version > CONFIG_VERSION) { if (current_version > CONFIG_VERSION) {
// Config version is newer than the latest version, and the config is // Config version is newer than the latest version, and the config is
// invalid This could also mean the server is out of date, and the user // invalid This could also mean the server is out of date, and the user
// should be shown a relevant message Regardless, regen the config anyways // should be shown a relevant message Regardless, regen the config
// anyways
// TODO: send signal config is invalid // TODO: send signal config is invalid
generateDefaultConfig(true); generateDefaultConfig(true);
} }
@ -161,22 +161,23 @@ void ConfigManager::updateConfig(int current_version)
} }
else { else {
// TODO: send signal config is out of date, and is being updated // TODO: send signal config is out of date, and is being updated
// Update the config as needed using a switch. This is nice because we can // Update the config as needed using a switch. This is nice because we
// fall through as we go up the version ladder. // can fall through as we go up the version ladder.
switch (current_version) { switch (current_version) {
case 0: // Version 0 doesn't actually exist, but we should check for it just case 0: // Version 0 doesn't actually exist, but we should check for it
// in case // just in case
case 1: case 1:
config->beginGroup("Info"); config->beginGroup("Info");
config->setValue("version", CONFIG_VERSION); config->setValue("version", CONFIG_VERSION);
config->endGroup(); config->endGroup();
break; // This is the newest version, and nothing more needs to be done break; // This is the newest version, and nothing more needs to be
// done
} }
} }
} }
// Validate and retriever settings related to advertising and the server // Validate and retriever settings related to advertising and the server
bool ConfigManager::loadServerSettings(server_settings *settings) bool ConfigManager::loadServerSettings(server_settings* settings)
{ {
bool port_conversion_success; bool port_conversion_success;
bool ws_port_conversion_success; bool ws_port_conversion_success;

View File

@ -8,7 +8,7 @@
#include <QSettings> #include <QSettings>
#include <QTranslator> #include <QTranslator>
int main(int argc, char *argv[]) int main(int argc, char* argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
QApplication::setApplicationName("akashi"); QApplication::setApplicationName("akashi");
@ -16,7 +16,8 @@ int main(int argc, char *argv[])
QSettings config("config.ini", QSettings::IniFormat); QSettings config("config.ini", QSettings::IniFormat);
config.beginGroup("Options"); config.beginGroup("Options");
QString language = config.value("language", QLocale().bcp47Name()).toString(); QString language =
config.value("language", QLocale().bcp47Name()).toString();
QTranslator qt_translator; QTranslator qt_translator;
qt_translator.load("qt_" + language, qt_translator.load("qt_" + language,

View File

@ -1,6 +1,6 @@
#include "include/server.h" #include "include/server.h"
Server::Server(int p_port, int p_ws_port, QObject *parent) : QObject(parent) Server::Server(int p_port, int p_ws_port, QObject* parent) : QObject(parent)
{ {
server = new QTcpServer(this); server = new QTcpServer(this);
connect(server, SIGNAL(newConnection()), this, SLOT(clientConnected())); connect(server, SIGNAL(newConnection()), this, SLOT(clientConnected()));
@ -18,13 +18,14 @@ void Server::start()
// code? The idea being that it is a websocket server, and all it does is // code? The idea being that it is a websocket server, and all it does is
// create a local connection to the raw tcp server. The main issue with this // create a local connection to the raw tcp server. The main issue with this
// is that it will cause problems with bans, ipids, etc But perhaps this can // is that it will cause problems with bans, ipids, etc But perhaps this can
// be negotiated by sending some extra data over? No idea. I'll wait for long // be negotiated by sending some extra data over? No idea. I'll wait for
// to read this massive comment and DM me on discord // long to read this massive comment and DM me on discord
// //
// Upon thinking about this a bit more, I realized basically all of the // Upon thinking about this a bit more, I realized basically all of the
// communication only happens via QTcpSocket* pointers. // communication only happens via QTcpSocket* pointers.
// If the Qt WebSocket server gives me QTcpSockets to work with, // If the Qt WebSocket server gives me QTcpSockets to work with,
// then they can all go into the same object. I doubt this is the case, though // then they can all go into the same object. I doubt this is the case,
// though
if (!server->listen(QHostAddress::Any, port)) { if (!server->listen(QHostAddress::Any, port)) {
// TODO: signal server start failed // TODO: signal server start failed
qDebug() << "Server error:" << server->errorString(); qDebug() << "Server error:" << server->errorString();
@ -36,8 +37,7 @@ void Server::start()
QFile char_list("characters.txt"); QFile char_list("characters.txt");
char_list.open(QIODevice::ReadOnly | QIODevice::Text); char_list.open(QIODevice::ReadOnly | QIODevice::Text);
while(!char_list.atEnd()) while (!char_list.atEnd()) {
{
characters.append(char_list.readLine().trimmed()); characters.append(char_list.readLine().trimmed());
} }
@ -48,14 +48,16 @@ void Server::start()
void Server::clientConnected() void Server::clientConnected()
{ {
QTcpSocket *client = server->nextPendingConnection(); QTcpSocket* client = server->nextPendingConnection();
AOClient *ao_client = new AOClient(client->peerAddress()); AOClient* ao_client = new AOClient(client->peerAddress());
clients.insert(client, ao_client); clients.insert(client, ao_client);
connect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected())); connect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
connect(client, SIGNAL(readyRead()), this, SLOT(clientData())); connect(client, SIGNAL(readyRead()), this, SLOT(clientData()));
AOPacket decryptor("decryptor", {"NOENCRYPT"}); // This is the infamous workaround for tsuserver4 AOPacket decryptor(
// It should disable fantacrypt completely in any client 2.4.3 or newer "decryptor", {"NOENCRYPT"}); // This is the infamous workaround for
// tsuserver4 It should disable fantacrypt
// completely in any client 2.4.3 or newer
client->write(decryptor.toUtf8()); client->write(decryptor.toUtf8());
qDebug() << client->peerAddress().toString() << "connected"; qDebug() << client->peerAddress().toString() << "connected";
@ -63,12 +65,13 @@ void Server::clientConnected()
void Server::clientDisconnected() void Server::clientDisconnected()
{ {
if (QTcpSocket *client = dynamic_cast<QTcpSocket *>(sender())) { if (QTcpSocket* client = dynamic_cast<QTcpSocket*>(sender())) {
qDebug() << client->peerAddress() << "disconnected"; qDebug() << client->peerAddress() << "disconnected";
AOClient* ao_client = clients.value(client); AOClient* ao_client = clients.value(client);
if (ao_client->joined) if (ao_client->joined)
player_count--; player_count--;
areas.value(ao_client->current_area)->characters_taken[ao_client->current_char] = false; areas.value(ao_client->current_area)
->characters_taken[ao_client->current_char] = false;
delete ao_client; delete ao_client;
clients.remove(client); clients.remove(client);
@ -77,7 +80,7 @@ void Server::clientDisconnected()
void Server::clientData() void Server::clientData()
{ {
if (QTcpSocket *client = dynamic_cast<QTcpSocket *>(sender())) { if (QTcpSocket* client = dynamic_cast<QTcpSocket*>(sender())) {
QString data = QString::fromUtf8(client->readAll()); QString data = QString::fromUtf8(client->readAll());
// qDebug() << "From" << client->peerAddress() << ":" << data; // qDebug() << "From" << client->peerAddress() << ":" << data;
@ -98,19 +101,19 @@ void Server::clientData()
} }
} }
void Server::handlePacket(AOPacket packet, QTcpSocket *socket) void Server::handlePacket(AOPacket packet, QTcpSocket* socket)
{ {
// TODO: like everything here should send a signal // TODO: like everything here should send a signal
qDebug() << "Received packet:" << packet.header << ":" << packet.contents; qDebug() << "Received packet:" << packet.header << ":" << packet.contents;
AOClient *client = clients.value(socket); AOClient* client = clients.value(socket);
AreaData *area = areas.value(client->current_area); AreaData* area = areas.value(client->current_area);
// Lord forgive me // Lord forgive me
if (packet.header == "HI") { if (packet.header == "HI") {
AOClient *client = clients.value(socket); AOClient* client = clients.value(socket);
client->setHwid(packet.contents[0]); client->setHwid(packet.contents[0]);
AOPacket response("ID", AOPacket response(
{"271828", "akashi", QApplication::applicationVersion()}); "ID", {"271828", "akashi", QApplication::applicationVersion()});
socket->write(response.toUtf8()); socket->write(response.toUtf8());
} }
else if (packet.header == "ID") { else if (packet.header == "ID") {
@ -124,12 +127,14 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *socket)
// "noencryption" and "fastloading" // "noencryption" and "fastloading"
// TODO: make the rest of these user configurable // TODO: make the rest of these user configurable
QStringList feature_list = { QStringList feature_list = {
"noencryption", "yellowtext", "prezoom", "flipping", "noencryption", "yellowtext", "prezoom",
"customobjections", "fastloading", "deskmod", "evidence", "flipping", "customobjections", "fastloading",
"cccc_ic_support", "arup", "casing_alserts", "modcall_reason", "deskmod", "evidence", "cccc_ic_support",
"arup", "casing_alserts", "modcall_reason",
"looping_sfx", "additive", "effects"}; "looping_sfx", "additive", "effects"};
AOPacket response_pn("PN", {QString::number(player_count), max_players}); AOPacket response_pn("PN",
{QString::number(player_count), max_players});
AOPacket response_fl("FL", feature_list); AOPacket response_fl("FL", feature_list);
socket->write(response_pn.toUtf8()); socket->write(response_pn.toUtf8());
socket->write(response_fl.toUtf8()); socket->write(response_fl.toUtf8());
@ -137,7 +142,8 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *socket)
else if (packet.header == "askchaa") { else if (packet.header == "askchaa") {
// TODO: add user configurable content // TODO: add user configurable content
// For testing purposes, we will just send enough to get things working // For testing purposes, we will just send enough to get things working
AOPacket response("SI", {QString::number(characters.length()), "0", "1"}); AOPacket response("SI",
{QString::number(characters.length()), "0", "1"});
qDebug() << response.toString(); qDebug() << response.toString();
socket->write(response.toUtf8()); socket->write(response.toUtf8());
} }
@ -154,9 +160,10 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *socket)
client->joined = true; client->joined = true;
QStringList chars_taken; QStringList chars_taken;
for(QString cur_char : area->characters_taken.keys()) for (QString cur_char : area->characters_taken.keys()) {
{ chars_taken.append(area->characters_taken.value(cur_char)
chars_taken.append(area->characters_taken.value(cur_char) ? QStringLiteral("-1") : QStringLiteral("0")); ? QStringLiteral("-1")
: QStringLiteral("0"));
} }
AOPacket response_cc("CharsCheck", chars_taken); AOPacket response_cc("CharsCheck", chars_taken);
@ -172,15 +179,15 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *socket)
else if (packet.header == "CC") { else if (packet.header == "CC") {
bool argument_ok; bool argument_ok;
int char_id = packet.contents[1].toInt(&argument_ok); int char_id = packet.contents[1].toInt(&argument_ok);
if(!argument_ok) if (!argument_ok)
return; return;
QString char_selected = characters[char_id]; QString char_selected = characters[char_id];
bool taken = area->characters_taken.value(char_selected); bool taken = area->characters_taken.value(char_selected);
if(taken || char_selected == "") if (taken || char_selected == "")
return; return;
if(client->current_char != "") { if (client->current_char != "") {
area->characters_taken[client->current_char] = false; area->characters_taken[client->current_char] = false;
} }
@ -188,9 +195,10 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *socket)
client->current_char = char_selected; client->current_char = char_selected;
QStringList chars_taken; QStringList chars_taken;
for(QString cur_char : area->characters_taken.keys()) for (QString cur_char : area->characters_taken.keys()) {
{ chars_taken.append(area->characters_taken.value(cur_char)
chars_taken.append(area->characters_taken.value(cur_char) ? QStringLiteral("-1") : QStringLiteral("0")); ? QStringLiteral("-1")
: QStringLiteral("0"));
} }
AOPacket response_cc("CharsCheck", chars_taken); AOPacket response_cc("CharsCheck", chars_taken);
@ -213,8 +221,8 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *socket)
socket->write(response.toUtf8()); socket->write(response.toUtf8());
} }
else if (packet.header == "what") { else if (packet.header == "what") {
AOPacket response("CT", AOPacket response(
{"Made with love", "by scatterflower and windrammer"}); "CT", {"Made with love", "by scatterflower and windrammer"});
} }
else { else {
qDebug() << "Unimplemented packet:" << packet.header; qDebug() << "Unimplemented packet:" << packet.header;
@ -225,15 +233,15 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *socket)
void Server::broadcast(AOPacket packet) void Server::broadcast(AOPacket packet)
{ {
for (QTcpSocket *client : clients.keys()) { for (QTcpSocket* client : clients.keys()) {
client->write(packet.toUtf8()); client->write(packet.toUtf8());
client->flush(); client->flush();
} }
} }
QTcpSocket *Server::getClient(QString ipid) QTcpSocket* Server::getClient(QString ipid)
{ {
for (QTcpSocket *client : clients.keys()) { for (QTcpSocket* client : clients.keys()) {
if (clients.value(client)->getIpid() == ipid) if (clients.value(client)->getIpid() == ipid)
return client; return client;
} }