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

@ -13,7 +13,8 @@ class Advertiser : public QObject {
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:

View File

@ -1,8 +1,8 @@
#ifndef AREA_DATA_H
#define AREA_DATA_H
#include <QString>
#include <QMap>
#include <QString>
class AreaData {
public:

View File

@ -5,8 +5,8 @@
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QFile>
#include <QFileInfo>
#include <QSettings>
class ConfigManager {

View File

@ -7,12 +7,12 @@
#include <QApplication>
#include <QDebug>
#include <QFile>
#include <QMap>
#include <QSettings>
#include <QString>
#include <QTcpServer>
#include <QTcpSocket>
#include <QFile>
class Server : public QObject {
Q_OBJECT

View File

@ -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

@ -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,16 +161,17 @@ 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
}
}
}

View File

@ -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

@ -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());
}
@ -54,8 +54,10 @@ void Server::clientConnected()
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";
@ -68,7 +70,8 @@ void Server::clientDisconnected()
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);
@ -109,8 +112,8 @@ void Server::handlePacket(AOPacket packet, QTcpSocket *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);
@ -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;