summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/net/packetlimiter.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/net/packetlimiter.cpp b/src/net/packetlimiter.cpp
index b99081714..92640bc99 100644
--- a/src/net/packetlimiter.cpp
+++ b/src/net/packetlimiter.cpp
@@ -33,13 +33,21 @@
#include "debug.h"
+// Client-side packet limiter
+// The time limits here are all in units of 10ms (SDL timer tick).
+// See MILLISECONDS_IN_A_TICK.
+
struct PacketLimit final
{
A_DEFAULT_COPY(PacketLimit)
+ // timer tick of the first packet in a burst
int lastTime;
+ // number of basic ticks in one packet burst
int timeLimit;
+ // number of packets inside an active packet burst
int cnt;
+ // max number of packets allowed inside a packet burst
int cntLimit;
};
@@ -53,6 +61,13 @@ void PacketLimiter::initPacketLimiter()
// here i setting packet limits. but current server is broken,
// and this limits may not help.
+ // see also: server-side logic in:
+ // TMWA: src/map/clif.cpp (clif_check_packet_flood)
+ // Herc: src/map/clif.c (clif_parse)
+ // src/common/socket.c (do_sockets(func_parse))
+ // (herc has no per-packet limits, just a per-connection
+ // fairness system.)
+
mPacketLimits[CAST_SIZE(
PacketType::PACKET_CHAT)].timeLimit = 10 + 5;
mPacketLimits[CAST_SIZE(
@@ -268,10 +283,9 @@ bool PacketLimiter::checkPackets(const PacketTypeT type)
const int cntLimit = limit.cntLimit;
if (lastTime > tick_time)
- {
+ { // integer wrap-around check
// instance()->mPacketLimits[type].lastTime = time;
// instance()->mPacketLimits[type].cnt = 0;
-
return true;
}
else if (lastTime + timeLimit > time)
@@ -308,7 +322,7 @@ bool PacketLimiter::limitPackets(const PacketTypeT type)
const int cntLimit = pack.cntLimit;
if (lastTime > tick_time)
- {
+ { // integer wrap-around check
pack.lastTime = time;
pack.cnt = 0;
return true;