akashi-esquizolandia/include/aoclient.h
2020-09-28 20:00:51 -05:00

154 lines
5.9 KiB
C++

//////////////////////////////////////////////////////////////////////////////////////
// akashi - a server for Attorney Online 2 //
// Copyright (C) 2020 scatterflower //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//////////////////////////////////////////////////////////////////////////////////////
#ifndef AOCLIENT_H
#define AOCLIENT_H
#include "include/aopacket.h"
#include "include/server.h"
#include "include/icchatpacket.h"
#include "include/area_data.h"
#include <algorithm>
#include <QHostAddress>
#include <QTcpSocket>
#include <QDateTime>
class Server;
class AOClient : public QObject {
Q_OBJECT
public:
AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent = nullptr);
~AOClient();
QString getHwid();
void setHwid(QString p_hwid);
QString getIpid();
QHostAddress remote_ip;
QString password;
bool joined;
int current_area;
QString current_char;
bool authenticated = false;
QString ooc_name = "";
public slots:
void clientDisconnected();
void clientData();
void sendPacket(AOPacket packet);
void sendPacket(QString header, QStringList contents);
void sendPacket(QString header);
private:
Server* server;
QTcpSocket* socket;
enum ARUPType {
PLAYER_COUNT,
STATUS,
CM,
LOCKED
};
void handlePacket(AOPacket packet);
void handleCommand(QString command, int argc, QStringList argv);
void changeArea(int new_area);
void arup(ARUPType type, bool broadcast);
void fullArup();
void sendServerMessage(QString message);
// Packet headers
void pktDefault(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktHardwareId(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktSoftwareId(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktBeginLoad(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktRequestChars(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktRequestMusic(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktLoadingDone(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktCharPassword(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktSelectChar(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktPing(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktChangeMusic(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktWtCe(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktHpBar(AreaData* area, int argc, QStringList argv, AOPacket packet);
void pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPacket packet);
struct PacketInfo {
int minArgs;
void (AOClient::*action)(AreaData*, int, QStringList, AOPacket);
};
const QMap<QString, PacketInfo> packets {
{"HI", {1, &AOClient::pktHardwareId}},
{"ID", {2, &AOClient::pktSoftwareId}},
{"askchaa", {0, &AOClient::pktBeginLoad}},
{"RC", {0, &AOClient::pktRequestChars}},
{"RM", {0, &AOClient::pktRequestMusic}},
{"RD", {0, &AOClient::pktLoadingDone}},
{"PW", {1, &AOClient::pktCharPassword}},
{"CC", {3, &AOClient::pktSelectChar}},
{"MS", {1, &AOClient::pktIcChat}}, // TODO: doublecheck
{"CT", {2, &AOClient::pktOocChat}},
{"CH", {1, &AOClient::pktPing}},
{"MC", {2, &AOClient::pktChangeMusic}},
{"RT", {1, &AOClient::pktWtCe}},
{"HP", {2, &AOClient::pktHpBar}},
{"WSIP", {1, &AOClient::pktWebSocketIp}}
};
// Commands
void cmdDefault(int argc, QStringList argv);
void cmdLogin(int argc, QStringList argv);
void cmdGetAreas(int argc, QStringList argv);
void cmdGetArea(int argc, QStringList argv);
void cmdBan(int argc, QStringList argv);
void cmdKick(int argc, QStringList argv);
// Command helper functions
QStringList buildAreaList(int area_idx);
struct CommandInfo {
bool privileged;
int minArgs;
void (AOClient::*action)(int, QStringList);
};
const QMap<QString, CommandInfo> commands {
{"login", {false, 1, &AOClient::cmdLogin}},
{"getareas", {false, 0 , &AOClient::cmdGetAreas}},
{"getarea", {false, 0, &AOClient::cmdGetArea}},
{"ban", {true, 2, &AOClient::cmdBan}},
{"kick", {true, 2, &AOClient::cmdKick}}
};
QString partial_packet;
bool is_partial;
QString hwid;
QString ipid;
long last_wtce_time;
QString last_message;
};
#endif // AOCLIENT_H