summaryrefslogtreecommitdiff
path: root/src/net/packetlimiter.cpp
diff options
context:
space:
mode:
authorFedja Beader <fedja@protonmail.ch>2025-05-11 11:08:30 +0200
committerFedja Beader <fedja@protonmail.ch>2025-05-11 16:43:38 +0200
commit2b14e0e8db77fda91c3ba9d23aafc415088fb494 (patch)
tree30dd884198c2efb3a7decd54e397952f9a29ce3e /src/net/packetlimiter.cpp
parent90d62a2f151c6ec277be693cb5ce0a05df8d036c (diff)
downloadmanaplus-2b14e0e8db77fda91c3ba9d23aafc415088fb494.tar.gz
manaplus-2b14e0e8db77fda91c3ba9d23aafc415088fb494.tar.bz2
manaplus-2b14e0e8db77fda91c3ba9d23aafc415088fb494.tar.xz
manaplus-2b14e0e8db77fda91c3ba9d23aafc415088fb494.zip
Document packet limiter and add quick reference for server-side
counterparts.
Diffstat (limited to 'src/net/packetlimiter.cpp')
-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;