clang format
This commit is contained in:
		
							parent
							
								
									e342c45806
								
							
						
					
					
						commit
						274c217e52
					
				@ -1,12 +1,11 @@
 | 
			
		||||
#ifndef AOCLIENT_H
 | 
			
		||||
#define AOCLIENT_H
 | 
			
		||||
 | 
			
		||||
#include <QTcpSocket>
 | 
			
		||||
#include <QHostAddress>
 | 
			
		||||
#include <QCryptographicHash>
 | 
			
		||||
#include <QHostAddress>
 | 
			
		||||
#include <QTcpSocket>
 | 
			
		||||
 | 
			
		||||
class AOClient
 | 
			
		||||
{
 | 
			
		||||
class AOClient {
 | 
			
		||||
public:
 | 
			
		||||
  AOClient(QHostAddress p_remote_ip);
 | 
			
		||||
  ~AOClient();
 | 
			
		||||
 | 
			
		||||
@ -1,16 +1,16 @@
 | 
			
		||||
#ifndef SERVER_H
 | 
			
		||||
#define SERVER_H
 | 
			
		||||
 | 
			
		||||
#include "include/aopacket.h"
 | 
			
		||||
#include "include/aoclient.h"
 | 
			
		||||
#include "include/aopacket.h"
 | 
			
		||||
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <QMap>
 | 
			
		||||
#include <QSettings>
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <QTcpServer>
 | 
			
		||||
#include <QTcpSocket>
 | 
			
		||||
#include <QMap>
 | 
			
		||||
 | 
			
		||||
class Server : public QObject {
 | 
			
		||||
  Q_OBJECT
 | 
			
		||||
 | 
			
		||||
@ -7,27 +7,20 @@ AOClient::AOClient(QHostAddress p_remote_ip)
 | 
			
		||||
  remote_ip = p_remote_ip;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString AOClient::getHwid(){
 | 
			
		||||
    return hwid;
 | 
			
		||||
}
 | 
			
		||||
QString AOClient::getHwid() { return hwid; }
 | 
			
		||||
 | 
			
		||||
void AOClient::setHwid(QString p_hwid)
 | 
			
		||||
{
 | 
			
		||||
  hwid = p_hwid;
 | 
			
		||||
 | 
			
		||||
    QCryptographicHash hash(QCryptographicHash::Md5); // Don't need security, just hashing for uniqueness
 | 
			
		||||
  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());
 | 
			
		||||
 | 
			
		||||
  ipid = hash.result().toHex().right(8);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString AOClient::getIpid()
 | 
			
		||||
{
 | 
			
		||||
    return ipid;
 | 
			
		||||
}
 | 
			
		||||
QString AOClient::getIpid() { return ipid; }
 | 
			
		||||
 | 
			
		||||
AOClient::~AOClient()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
AOClient::~AOClient() {}
 | 
			
		||||
 | 
			
		||||
@ -22,7 +22,8 @@ AOPacket::AOPacket(QString p_packet)
 | 
			
		||||
    else if (packet_contents[0] == "615810BC07D12A5A")
 | 
			
		||||
      header = "askchaa";
 | 
			
		||||
    else
 | 
			
		||||
            header = packet_contents[0]; // If no known decryption exists, just leave the packet as-is
 | 
			
		||||
      header = packet_contents[0]; // If no known decryption exists, just leave
 | 
			
		||||
                                   // the packet as-is
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    header = packet_contents[0];
 | 
			
		||||
 | 
			
		||||
@ -1,7 +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()));
 | 
			
		||||
@ -15,24 +14,22 @@ Server::Server(int p_port, int p_ws_port, QObject* parent)
 | 
			
		||||
void Server::start()
 | 
			
		||||
{
 | 
			
		||||
  // TODO: websockets lul
 | 
			
		||||
    // Maybe websockets should be handled by a separate intermediate part of the 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
 | 
			
		||||
  // Maybe websockets should be handled by a separate intermediate part of the
 | 
			
		||||
  // 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
 | 
			
		||||
  //
 | 
			
		||||
  // 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
 | 
			
		||||
    if(!server->listen(QHostAddress::Any, port))
 | 
			
		||||
    {
 | 
			
		||||
  if (!server->listen(QHostAddress::Any, port)) {
 | 
			
		||||
    // TODO: signal server start failed
 | 
			
		||||
    qDebug() << "Server error:" << server->errorString();
 | 
			
		||||
  }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
  else {
 | 
			
		||||
    // TODO: signal server start success
 | 
			
		||||
    qDebug() << "Server listening on" << port;
 | 
			
		||||
  }
 | 
			
		||||
@ -80,8 +77,7 @@ void Server::clientData()
 | 
			
		||||
    QStringList all_packets = data.split("%");
 | 
			
		||||
    all_packets.removeLast(); // Remove the entry after the last delimiter
 | 
			
		||||
 | 
			
		||||
        for(QString single_packet : all_packets)
 | 
			
		||||
        {
 | 
			
		||||
    for (QString single_packet : all_packets) {
 | 
			
		||||
      AOPacket packet(single_packet);
 | 
			
		||||
      handlePacket(packet, client);
 | 
			
		||||
    }
 | 
			
		||||
@ -97,35 +93,46 @@ 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"){
 | 
			
		||||
  }
 | 
			
		||||
  else if (packet.header == "ID") {
 | 
			
		||||
    QSettings config("config.ini", QSettings::IniFormat);
 | 
			
		||||
    config.beginGroup("Options");
 | 
			
		||||
    QString max_players = config.value("max_players").toString();
 | 
			
		||||
    config.endGroup();
 | 
			
		||||
 | 
			
		||||
    // Full feature list as of AO 2.8.5
 | 
			
		||||
        // The only ones that are critical to ensuring the server works are "noencryption" and "fastloading"
 | 
			
		||||
    // The only ones that are critical to ensuring the server works are
 | 
			
		||||
    // "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", "looping_sfx", "additive", "effects"};
 | 
			
		||||
    QStringList feature_list = {
 | 
			
		||||
        "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_fl("FL", feature_list);
 | 
			
		||||
    socket->write(response_pn.toUtf8());
 | 
			
		||||
    socket->write(response_fl.toUtf8());
 | 
			
		||||
    } else if(packet.header == "askchaa"){
 | 
			
		||||
  }
 | 
			
		||||
  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", {"2", "0", "1"});
 | 
			
		||||
    socket->write(response.toUtf8());
 | 
			
		||||
    } else if(packet.header == "RC") {
 | 
			
		||||
  }
 | 
			
		||||
  else if (packet.header == "RC") {
 | 
			
		||||
    AOPacket response("SC", {"Phoenix", "Edgeworth"});
 | 
			
		||||
    socket->write(response.toUtf8());
 | 
			
		||||
    } else if(packet.header == "RM") {
 | 
			
		||||
  }
 | 
			
		||||
  else if (packet.header == "RM") {
 | 
			
		||||
    AOPacket response("SM", {"~stop.mp3"});
 | 
			
		||||
    socket->write(response.toUtf8());
 | 
			
		||||
    } else if(packet.header == "RD") {
 | 
			
		||||
  }
 | 
			
		||||
  else if (packet.header == "RD") {
 | 
			
		||||
    player_count++;
 | 
			
		||||
    client->joined = true;
 | 
			
		||||
 | 
			
		||||
@ -135,28 +142,37 @@ void Server::handlePacket(AOPacket packet, QTcpSocket* socket)
 | 
			
		||||
    socket->write(response_cc.toUtf8());
 | 
			
		||||
    socket->write(response_op.toUtf8());
 | 
			
		||||
    socket->write(response_done.toUtf8());
 | 
			
		||||
    } else if(packet.header == "PW") {
 | 
			
		||||
  }
 | 
			
		||||
  else if (packet.header == "PW") {
 | 
			
		||||
    client->password = packet.contents[0];
 | 
			
		||||
    } else if(packet.header == "CC") {
 | 
			
		||||
  }
 | 
			
		||||
  else if (packet.header == "CC") {
 | 
			
		||||
    // TODO: properly implement this when adding characters
 | 
			
		||||
        qDebug() << client->getIpid() << "chose character" << packet.contents[1] << "using password" << client->password;
 | 
			
		||||
    qDebug() << client->getIpid() << "chose character" << packet.contents[1]
 | 
			
		||||
             << "using password" << client->password;
 | 
			
		||||
 | 
			
		||||
    AOPacket response("PV", {"271828", "CID", packet.contents[1]});
 | 
			
		||||
    socket->write(response.toUtf8());
 | 
			
		||||
    } else if(packet.header == "MS") {
 | 
			
		||||
  }
 | 
			
		||||
  else if (packet.header == "MS") {
 | 
			
		||||
    // TODO: validate, validate, validate
 | 
			
		||||
    broadcast(packet);
 | 
			
		||||
    } else if(packet.header == "CT") {
 | 
			
		||||
  }
 | 
			
		||||
  else if (packet.header == "CT") {
 | 
			
		||||
    // TODO: commands
 | 
			
		||||
    // TODO: zalgo strip
 | 
			
		||||
    broadcast(packet);
 | 
			
		||||
    } else if(packet.header == "CH") {
 | 
			
		||||
  }
 | 
			
		||||
  else if (packet.header == "CH") {
 | 
			
		||||
    // Why does this packet exist
 | 
			
		||||
    AOPacket response("CHECK", {});
 | 
			
		||||
    socket->write(response.toUtf8());
 | 
			
		||||
    } else if(packet.header == "what") {
 | 
			
		||||
        AOPacket response("CT", {"Made with love", "by scatterflower and windrammer"});
 | 
			
		||||
    } else {
 | 
			
		||||
  }
 | 
			
		||||
  else if (packet.header == "what") {
 | 
			
		||||
    AOPacket response("CT",
 | 
			
		||||
                      {"Made with love", "by scatterflower and windrammer"});
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    qDebug() << "Unimplemented packet:" << packet.header;
 | 
			
		||||
    qDebug() << packet.contents;
 | 
			
		||||
  }
 | 
			
		||||
@ -165,8 +181,7 @@ 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();
 | 
			
		||||
  }
 | 
			
		||||
@ -174,8 +189,7 @@ void Server::broadcast(AOPacket packet)
 | 
			
		||||
 | 
			
		||||
QTcpSocket *Server::getClient(QString ipid)
 | 
			
		||||
{
 | 
			
		||||
    for(QTcpSocket* client : clients.keys())
 | 
			
		||||
    {
 | 
			
		||||
  for (QTcpSocket *client : clients.keys()) {
 | 
			
		||||
    if (clients.value(client)->getIpid() == ipid)
 | 
			
		||||
      return client;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user