Merge pull request #118 from AttorneyOnline/add-ic-floodguard
Set a floodguard between IC messages
This commit is contained in:
commit
2ee842d66b
@ -19,6 +19,7 @@ logging=modcall
|
|||||||
maximum_statements=10
|
maximum_statements=10
|
||||||
multiclient_limit=15
|
multiclient_limit=15
|
||||||
maximum_characters=256
|
maximum_characters=256
|
||||||
|
message_floodguard=250
|
||||||
|
|
||||||
[Dice]
|
[Dice]
|
||||||
max_value=100
|
max_value=100
|
||||||
|
@ -303,6 +303,21 @@ class Server : public QObject {
|
|||||||
*/
|
*/
|
||||||
int max_chars;
|
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:
|
public slots:
|
||||||
/**
|
/**
|
||||||
* @brief Handles a new connection.
|
* @brief Handles a new connection.
|
||||||
@ -312,6 +327,13 @@ class Server : public QObject {
|
|||||||
*/
|
*/
|
||||||
void clientConnected();
|
void clientConnected();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets #can_send_messages to true.
|
||||||
|
*
|
||||||
|
* @details Called whenever #next_message_timer reaches 0.
|
||||||
|
*/
|
||||||
|
void allowMessage();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,6 +157,10 @@ void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket pa
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!server->can_send_ic_messages) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
AOPacket validated_packet = validateIcPacket(packet);
|
AOPacket validated_packet = validateIcPacket(packet);
|
||||||
if (validated_packet.header == "INVALID")
|
if (validated_packet.header == "INVALID")
|
||||||
return;
|
return;
|
||||||
@ -168,6 +172,9 @@ void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket pa
|
|||||||
server->broadcast(validated_packet, current_area);
|
server->broadcast(validated_packet, current_area);
|
||||||
area->last_ic_message.clear();
|
area->last_ic_message.clear();
|
||||||
area->last_ic_message.append(validated_packet.contents);
|
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)
|
void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket packet)
|
||||||
@ -884,3 +891,4 @@ void AOClient::loginAttempt(QString message)
|
|||||||
is_logging_in = false;
|
is_logging_in = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,6 +104,7 @@ void Server::start()
|
|||||||
QString area_name = raw_area_names[i];
|
QString area_name = raw_area_names[i];
|
||||||
areas.insert(i, new AreaData(area_name, i));
|
areas.insert(i, new AreaData(area_name, i));
|
||||||
}
|
}
|
||||||
|
connect(&next_message_timer, SIGNAL(timeout()), this, SLOT(allowMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::clientConnected()
|
void Server::clientConnected()
|
||||||
@ -290,6 +291,10 @@ void Server::loadServerConfig()
|
|||||||
max_chars = config.value("maximum_characters", "256").toInt(&max_char_conversion_success);
|
max_chars = config.value("maximum_characters", "256").toInt(&max_char_conversion_success);
|
||||||
if (!max_char_conversion_success)
|
if (!max_char_conversion_success)
|
||||||
max_chars = 256;
|
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();
|
config.endGroup();
|
||||||
|
|
||||||
//Load dice values
|
//Load dice values
|
||||||
@ -306,6 +311,11 @@ void Server::loadServerConfig()
|
|||||||
config.endGroup();
|
config.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server::allowMessage()
|
||||||
|
{
|
||||||
|
can_send_ic_messages = true;
|
||||||
|
}
|
||||||
|
|
||||||
Server::~Server()
|
Server::~Server()
|
||||||
{
|
{
|
||||||
for (AOClient* client : clients) {
|
for (AOClient* client : clients) {
|
||||||
|
Loading…
Reference in New Issue
Block a user