Merge pull request #15 from AttorneyOnline/feature/dezalgo
Add "dezalgo" for IC and OOC chat
This commit is contained in:
commit
d0dbd41232
@ -28,6 +28,7 @@
|
|||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QRegExp>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#if QT_VERSION > QT_VERSION_CHECK(5, 10, 0)
|
#if QT_VERSION > QT_VERSION_CHECK(5, 10, 0)
|
||||||
#include <QRandomGenerator>
|
#include <QRandomGenerator>
|
||||||
@ -127,6 +128,7 @@ class AOClient : public QObject {
|
|||||||
// Packet helper functions
|
// Packet helper functions
|
||||||
void sendEvidenceList(AreaData* area);
|
void sendEvidenceList(AreaData* area);
|
||||||
AOPacket validateIcPacket(AOPacket packet);
|
AOPacket validateIcPacket(AOPacket packet);
|
||||||
|
QString dezalgo(QString p_text);
|
||||||
|
|
||||||
// Packet helper global variables
|
// Packet helper global variables
|
||||||
int char_id = -1;
|
int char_id = -1;
|
||||||
|
@ -40,6 +40,7 @@ class ConfigManager {
|
|||||||
QString name;
|
QString name;
|
||||||
QString description;
|
QString description;
|
||||||
bool advertise_server;
|
bool advertise_server;
|
||||||
|
int zalgo_tolerance;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool loadServerSettings(server_settings* settings);
|
bool loadServerSettings(server_settings* settings);
|
||||||
|
@ -131,6 +131,7 @@ bool ConfigManager::loadServerSettings(server_settings* settings)
|
|||||||
bool port_conversion_success;
|
bool port_conversion_success;
|
||||||
bool ws_port_conversion_success;
|
bool ws_port_conversion_success;
|
||||||
bool local_port_conversion_success;
|
bool local_port_conversion_success;
|
||||||
|
bool zalgo_tolerance_conversion_success;
|
||||||
config.beginGroup("Options");
|
config.beginGroup("Options");
|
||||||
settings->ms_ip =
|
settings->ms_ip =
|
||||||
config.value("ms_ip", "master.aceattorneyonline.com").toString();
|
config.value("ms_ip", "master.aceattorneyonline.com").toString();
|
||||||
@ -144,6 +145,8 @@ bool ConfigManager::loadServerSettings(server_settings* settings)
|
|||||||
settings->description =
|
settings->description =
|
||||||
config.value("server_description", "This is my flashy new server")
|
config.value("server_description", "This is my flashy new server")
|
||||||
.toString();
|
.toString();
|
||||||
|
settings->zalgo_tolerance =
|
||||||
|
config.value("zalgo_tolerance", "3").toInt(&zalgo_tolerance_conversion_success);
|
||||||
config.endGroup();
|
config.endGroup();
|
||||||
if (!port_conversion_success || !ws_port_conversion_success ||
|
if (!port_conversion_success || !ws_port_conversion_success ||
|
||||||
!local_port_conversion_success) {
|
!local_port_conversion_success) {
|
||||||
|
@ -177,20 +177,21 @@ void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket pa
|
|||||||
|
|
||||||
void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket packet)
|
void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket packet)
|
||||||
{
|
{
|
||||||
ooc_name = argv[0];
|
ooc_name = dezalgo(argv[0]);
|
||||||
if(argv[1].at(0) == '/') {
|
QString message = dezalgo(argv[1]);
|
||||||
QStringList cmd_argv = argv[1].split(" ", QString::SplitBehavior::SkipEmptyParts);
|
AOPacket final_packet("CT", {ooc_name, message, "0"});
|
||||||
|
if(message.at(0) == '/') {
|
||||||
|
QStringList cmd_argv = message.split(" ", QString::SplitBehavior::SkipEmptyParts);
|
||||||
QString command = cmd_argv[0].trimmed().toLower();
|
QString command = cmd_argv[0].trimmed().toLower();
|
||||||
command = command.right(command.length() - 1);
|
command = command.right(command.length() - 1);
|
||||||
cmd_argv.removeFirst();
|
cmd_argv.removeFirst();
|
||||||
int cmd_argc = cmd_argv.length();
|
int cmd_argc = cmd_argv.length();
|
||||||
area->logger->logCmd(this, &packet, command, cmd_argv);
|
area->logger->logCmd(this, &final_packet, command, cmd_argv);
|
||||||
handleCommand(command, cmd_argc, cmd_argv);
|
handleCommand(command, cmd_argc, cmd_argv);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: zalgo strip
|
server->broadcast(final_packet, current_area);
|
||||||
server->broadcast(packet, current_area);
|
area->logger->logOOC(this, &final_packet);
|
||||||
area->logger->logOOC(this, &packet);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,7 +376,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
|
|||||||
args.append(emote);
|
args.append(emote);
|
||||||
|
|
||||||
// message text
|
// message text
|
||||||
QString incoming_msg = incoming_args[4].toString().trimmed();
|
QString incoming_msg = dezalgo(incoming_args[4].toString().trimmed());
|
||||||
if (incoming_msg == last_message)
|
if (incoming_msg == last_message)
|
||||||
return invalid;
|
return invalid;
|
||||||
|
|
||||||
@ -453,7 +454,8 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
|
|||||||
// 2.6 packet extensions
|
// 2.6 packet extensions
|
||||||
if (incoming_args.length() > 15) {
|
if (incoming_args.length() > 15) {
|
||||||
// showname
|
// showname
|
||||||
args.append(incoming_args[15].toString());
|
QString showname = dezalgo(incoming_args[15].toString().trimmed());
|
||||||
|
args.append(showname);
|
||||||
|
|
||||||
// other char id
|
// other char id
|
||||||
// things get a bit hairy here
|
// things get a bit hairy here
|
||||||
@ -534,3 +536,17 @@ AOPacket AOClient::validateIcPacket(AOPacket packet)
|
|||||||
|
|
||||||
return AOPacket("MS", args);
|
return AOPacket("MS", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString AOClient::dezalgo(QString p_text)
|
||||||
|
{
|
||||||
|
QSettings config("config/config.ini", QSettings::IniFormat);
|
||||||
|
config.beginGroup("Options");
|
||||||
|
bool zalgo_tolerance_conversion_success;
|
||||||
|
int zalgo_tolerance = config.value("zalgo_tolerance", "3").toInt(&zalgo_tolerance_conversion_success);
|
||||||
|
if (!zalgo_tolerance_conversion_success)
|
||||||
|
zalgo_tolerance = 3;
|
||||||
|
|
||||||
|
QRegExp rxp("([\u0300-\u036f\u1ab0-\u1aff\u1dc0-\u1dff\u20d0-\u20ff\ufe20-\ufe2f\u115f\u1160\u3164]{" + QRegExp::escape(QString::number(zalgo_tolerance)) + ",})");
|
||||||
|
QString filtered = p_text.replace(rxp, "");
|
||||||
|
return filtered;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user