Merge pull request #118 from AttorneyOnline/add-ic-floodguard

Set a floodguard between IC messages
This commit is contained in:
Denton Poss 2021-05-03 18:37:36 -05:00 committed by GitHub
commit 2ee842d66b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 0 deletions

View File

@ -19,6 +19,7 @@ logging=modcall
maximum_statements=10
multiclient_limit=15
maximum_characters=256
message_floodguard=250
[Dice]
max_value=100

View File

@ -303,6 +303,21 @@ class Server : public QObject {
*/
int max_chars;
/**
* @brief Timer until the next IC message can be sent.
*/
QTimer next_message_timer;
/**
* @brief If false, IC messages will be rejected.
*/
bool can_send_ic_messages = true;
/**
* @brief The minimum time between IC messages, in milliseconds.
*/
int message_floodguard;
public slots:
/**
* @brief Handles a new connection.
@ -312,6 +327,13 @@ class Server : public QObject {
*/
void clientConnected();
/**
* @brief Sets #can_send_messages to true.
*
* @details Called whenever #next_message_timer reaches 0.
*/
void allowMessage();
signals:
/**

View File

@ -157,6 +157,10 @@ void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket pa
return;
}
if (!server->can_send_ic_messages) {
return;
}
AOPacket validated_packet = validateIcPacket(packet);
if (validated_packet.header == "INVALID")
return;
@ -168,6 +172,9 @@ void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket pa
server->broadcast(validated_packet, current_area);
area->last_ic_message.clear();
area->last_ic_message.append(validated_packet.contents);
server->can_send_ic_messages = false;
server->next_message_timer.start(server->message_floodguard);
}
void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket packet)
@ -884,3 +891,4 @@ void AOClient::loginAttempt(QString message)
is_logging_in = false;
return;
}

View File

@ -104,6 +104,7 @@ void Server::start()
QString area_name = raw_area_names[i];
areas.insert(i, new AreaData(area_name, i));
}
connect(&next_message_timer, SIGNAL(timeout()), this, SLOT(allowMessage()));
}
void Server::clientConnected()
@ -290,6 +291,10 @@ void Server::loadServerConfig()
max_chars = config.value("maximum_characters", "256").toInt(&max_char_conversion_success);
if (!max_char_conversion_success)
max_chars = 256;
bool message_floodguard_conversion_success;
message_floodguard = config.value("message_floodguard", "250").toInt(&message_floodguard_conversion_success);
if (!message_floodguard_conversion_success)
message_floodguard = 30;
config.endGroup();
//Load dice values
@ -306,6 +311,11 @@ void Server::loadServerConfig()
config.endGroup();
}
void Server::allowMessage()
{
can_send_ic_messages = true;
}
Server::~Server()
{
for (AOClient* client : clients) {