add ic chat validation class thing

This commit is contained in:
scatterflower 2020-09-06 10:39:44 -05:00
parent ab5571ef0d
commit 0f692a4103
4 changed files with 111 additions and 1 deletions

View File

@ -20,9 +20,11 @@
#include "include/aopacket.h"
#include "include/server.h"
#include "include/icchatpacket.h"
#include <QHostAddress>
#include <QTcpSocket>
#include <QDateTime>
class Server;
@ -72,6 +74,8 @@ class AOClient : public QObject {
QString hwid;
QString ipid;
long last_wtce_time;
QString last_message;
};
#endif // AOCLIENT_H

65
include/icchatpacket.h Normal file
View File

@ -0,0 +1,65 @@
//////////////////////////////////////////////////////////////////////////////////////
// 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 ICCHATPACKET_H
#define ICCHATPACKET_H
#endif // ICCHATPACKET_H
#include "include/aopacket.h"
class ICChatPacket : public AOPacket
{
public:
ICChatPacket(AOPacket packet);
const int MIN_FIELDS = 15;
const int MAX_FIELDS = 30;
bool is_valid;
QString desk_override;
QString preanim;
QString character;
QString emote;
QString message;
QString side;
QString sfx_name;
int emote_modifier;
int char_id;
QString sfx_delay;
int objection_modifier;
QString evidence;
bool flip;
bool realization;
int text_color;
QString showname;
int other_charid;
QString other_name;
QString other_emote;
int self_offset;
int other_offset;
bool other_flip;
bool noninterrupting_preanim;
bool sfx_looping;
bool screenshake;
QString frames_shake;
QString frames_realization;
QString frames_sfx;
bool additive;
QString effect;
};

View File

@ -28,6 +28,8 @@ AOClient::AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent)
current_char = "";
remote_ip = p_socket->peerAddress();
is_partial = false;
last_wtce_time = 0;
last_message = "";
}
void AOClient::clientData()
@ -153,7 +155,9 @@ void AOClient::handlePacket(AOPacket packet)
}
else if (packet.header == "MS") {
// TODO: validate, validate, validate
server->broadcast(packet, current_area);
ICChatPacket ic_packet(packet);
if (ic_packet.is_valid)
server->broadcast(ic_packet, current_area);
}
else if (packet.header == "CT") {
// TODO: commands
@ -191,6 +195,12 @@ void AOClient::handlePacket(AOPacket packet)
}
}
}
else if (packet.header == "RT") {
if (QDateTime::currentDateTime().toSecsSinceEpoch() - last_wtce_time <= 5)
return;
last_wtce_time = QDateTime::currentDateTime().toSecsSinceEpoch();
server->broadcast(packet, current_area);
}
else {
qDebug() << "Unimplemented packet:" << packet.header;
qDebug() << packet.contents;

31
src/icchatpacket.cpp Normal file
View File

@ -0,0 +1,31 @@
//////////////////////////////////////////////////////////////////////////////////////
// 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/>. //
//////////////////////////////////////////////////////////////////////////////////////
#include "include/icchatpacket.h"
ICChatPacket::ICChatPacket(AOPacket packet)
: AOPacket(packet.header, packet.contents)
{
// Perform some basic validation
if (packet.contents.length() > MAX_FIELDS || packet.contents.length() < MIN_FIELDS) {
is_valid = false;
return;
}
// Populate information about the message
is_valid = true;
}