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
IndentWidth: 4
Language: Cpp
PointerAlignment: Left
BreakBeforeBraces: Stroustrup

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
Advertiser::Advertiser(QString p_ip, int p_port, int p_ws_port,
int p_local_port, QString p_name, QString p_description,
QObject *parent)
QObject* parent)
: QObject(parent)
{
ip = p_ip;
@ -40,9 +40,11 @@ void Advertiser::socketConnected()
if (ws_port == -1)
concat_ports = QString::number(local_port);
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()});
QByteArray data = ao_packet.toUtf8();

View File

@ -1,7 +1,7 @@
#include "include/akashimain.h"
#include "ui_akashimain.h"
AkashiMain::AkashiMain(QWidget *parent)
AkashiMain::AkashiMain(QWidget* parent)
: QMainWindow(parent), config_manager(), ui(new Ui::AkashiMain)
{
ui->setupUi(this);
@ -20,7 +20,8 @@ AkashiMain::AkashiMain(QWidget *parent)
else {
if (settings.advertise_server) {
// 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.name, settings.description, this);
advertiser->contactMasterServer();

View File

@ -15,7 +15,8 @@ void AOClient::setHwid(QString 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
QString concat_ip_id = remote_ip.toString() + p_hwid;
hash.addData(concat_ip_id.toUtf8());

View File

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

View File

@ -9,8 +9,7 @@ ConfigManager::ConfigManager()
bool ConfigManager::initConfig()
{
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
QFile char_list("characters.txt");
if (!char_list.open(QIODevice::WriteOnly | QIODevice::Text))
@ -151,7 +150,8 @@ void ConfigManager::updateConfig(int current_version)
if (current_version > CONFIG_VERSION) {
// 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
// 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
generateDefaultConfig(true);
}
@ -161,22 +161,23 @@ void ConfigManager::updateConfig(int current_version)
}
else {
// 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
// fall through as we go up the version ladder.
// Update the config as needed using a switch. This is nice because we
// can fall through as we go up the version ladder.
switch (current_version) {
case 0: // Version 0 doesn't actually exist, but we should check for it just
// in case
case 0: // Version 0 doesn't actually exist, but we should check for it
// just in case
case 1:
config->beginGroup("Info");
config->setValue("version", CONFIG_VERSION);
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
bool ConfigManager::loadServerSettings(server_settings *settings)
bool ConfigManager::loadServerSettings(server_settings* settings)
{
bool port_conversion_success;
bool ws_port_conversion_success;

View File

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

View File

@ -1,6 +1,6 @@
#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);
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
// 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
// be negotiated by sending some extra data over? No idea. I'll wait for long
// to read this massive comment and DM me on discord
// be negotiated by sending some extra data over? No idea. I'll wait for
// long to read this massive comment and DM me on discord
//
// Upon thinking about this a bit more, I realized basically all of the
// communication only happens via QTcpSocket* pointers.
// 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)) {
// TODO: signal server start failed
qDebug() << "Server error:" << server->errorString();
@ -36,8 +37,7 @@ void Server::start()
QFile char_list("characters.txt");
char_list.open(QIODevice::ReadOnly | QIODevice::Text);
while(!char_list.atEnd())
{
while (!char_list.atEnd()) {
characters.append(char_list.readLine().trimmed());
}
@ -48,14 +48,16 @@ void Server::start()
void Server::clientConnected()
{
QTcpSocket *client = server->nextPendingConnection();
AOClient *ao_client = new AOClient(client->peerAddress());
QTcpSocket* client = server->nextPendingConnection();
AOClient* ao_client = new AOClient(client->peerAddress());
clients.insert(client, ao_client);
connect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
connect(client, SIGNAL(readyRead()), this, SLOT(clientData()));
AOPacket decryptor("decryptor", {"NOENCRYPT"}); // This is the infamous workaround for tsuserver4
// It should disable fantacrypt completely in any client 2.4.3 or newer
AOPacket decryptor(
"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());
qDebug() << client->peerAddress().toString() << "connected";
@ -63,12 +65,13 @@ void Server::clientConnected()
void Server::clientDisconnected()
{
if (QTcpSocket *client = dynamic_cast<QTcpSocket *>(sender())) {
if (QTcpSocket* client = dynamic_cast<QTcpSocket*>(sender())) {
qDebug() << client->peerAddress() << "disconnected";
AOClient* ao_client = clients.value(client);
if (ao_client->joined)
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;
clients.remove(client);
@ -77,7 +80,7 @@ void Server::clientDisconnected()
void Server::clientData()
{
if (QTcpSocket *client = dynamic_cast<QTcpSocket *>(sender())) {
if (QTcpSocket* client = dynamic_cast<QTcpSocket*>(sender())) {
QString data = QString::fromUtf8(client->readAll());
// 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
qDebug() << "Received packet:" << packet.header << ":" << packet.contents;
AOClient *client = clients.value(socket);
AreaData *area = areas.value(client->current_area);
AOClient* client = clients.value(socket);
AreaData* area = areas.value(client->current_area);
// Lord forgive me
if (packet.header == "HI") {
AOClient *client = clients.value(socket);
AOClient* client = clients.value(socket);
client->setHwid(packet.contents[0]);
AOPacket response("ID",
{"271828", "akashi", QApplication::applicationVersion()});
AOPacket response(
"ID", {"271828", "akashi", QApplication::applicationVersion()});
socket->write(response.toUtf8());
}
else if (packet.header == "ID") {
@ -124,12 +127,14 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *socket)
// "noencryption" and "fastloading"
// TODO: make the rest of these user configurable
QStringList feature_list = {
"noencryption", "yellowtext", "prezoom", "flipping",
"customobjections", "fastloading", "deskmod", "evidence",
"cccc_ic_support", "arup", "casing_alserts", "modcall_reason",
"noencryption", "yellowtext", "prezoom",
"flipping", "customobjections", "fastloading",
"deskmod", "evidence", "cccc_ic_support",
"arup", "casing_alserts", "modcall_reason",
"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);
socket->write(response_pn.toUtf8());
socket->write(response_fl.toUtf8());
@ -137,7 +142,8 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *socket)
else if (packet.header == "askchaa") {
// TODO: add user configurable content
// 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();
socket->write(response.toUtf8());
}
@ -154,9 +160,10 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *socket)
client->joined = true;
QStringList chars_taken;
for(QString cur_char : area->characters_taken.keys())
{
chars_taken.append(area->characters_taken.value(cur_char) ? QStringLiteral("-1") : QStringLiteral("0"));
for (QString cur_char : area->characters_taken.keys()) {
chars_taken.append(area->characters_taken.value(cur_char)
? QStringLiteral("-1")
: QStringLiteral("0"));
}
AOPacket response_cc("CharsCheck", chars_taken);
@ -172,15 +179,15 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *socket)
else if (packet.header == "CC") {
bool argument_ok;
int char_id = packet.contents[1].toInt(&argument_ok);
if(!argument_ok)
if (!argument_ok)
return;
QString char_selected = characters[char_id];
bool taken = area->characters_taken.value(char_selected);
if(taken || char_selected == "")
if (taken || char_selected == "")
return;
if(client->current_char != "") {
if (client->current_char != "") {
area->characters_taken[client->current_char] = false;
}
@ -188,9 +195,10 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *socket)
client->current_char = char_selected;
QStringList chars_taken;
for(QString cur_char : area->characters_taken.keys())
{
chars_taken.append(area->characters_taken.value(cur_char) ? QStringLiteral("-1") : QStringLiteral("0"));
for (QString cur_char : area->characters_taken.keys()) {
chars_taken.append(area->characters_taken.value(cur_char)
? QStringLiteral("-1")
: QStringLiteral("0"));
}
AOPacket response_cc("CharsCheck", chars_taken);
@ -213,8 +221,8 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *socket)
socket->write(response.toUtf8());
}
else if (packet.header == "what") {
AOPacket response("CT",
{"Made with love", "by scatterflower and windrammer"});
AOPacket response(
"CT", {"Made with love", "by scatterflower and windrammer"});
}
else {
qDebug() << "Unimplemented packet:" << packet.header;
@ -225,15 +233,15 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *socket)
void Server::broadcast(AOPacket packet)
{
for (QTcpSocket *client : clients.keys()) {
for (QTcpSocket* client : clients.keys()) {
client->write(packet.toUtf8());
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)
return client;
}