From 078dca1f40a1a95f8d6c528ad5187bf67038ae36 Mon Sep 17 00:00:00 2001 From: Zack Piispanen Date: Sat, 19 Oct 2013 02:34:15 -0400 Subject: [PATCH] Add in code to auto kill clients that have large buffers. This is disabled, and set to 5mb. If enabled, this would silently kill players as their buffer is full, which could have bad consequences in large servers with lag. This is intended to deal with the issue where servers are running out of memory. --- TShockAPI/ConfigFile.cs | 4 ++++ TShockAPI/PacketBufferer.cs | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index 84a923ee..152a8ab8 100755 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -274,6 +274,10 @@ namespace TShockAPI [Description("Disables a player if this number of tiles is painted within 1 second.")] public int TilePaintThreshold = 15; + [Description("Enables max packet bufferer size.")] public bool EnableMaxBytesInBuffer = false; + + [Description("Number of bytes in the packet buffer before we disconnect the player.")] public int MaxBytesInBuffer = 5242880; + /// /// Reads a configuration file from a given path /// diff --git a/TShockAPI/PacketBufferer.cs b/TShockAPI/PacketBufferer.cs index ebab27d1..c656fdbb 100644 --- a/TShockAPI/PacketBufferer.cs +++ b/TShockAPI/PacketBufferer.cs @@ -182,6 +182,12 @@ namespace TShockAPI { buffers[socket.whoAmI].AddRange(ms.ToArray()); } + + if (TShock.Config.EnableMaxBytesInBuffer && buffers[socket.whoAmI].Count > TShock.Config.MaxBytesInBuffer) + { + buffers[socket.whoAmI].Clear(); + socket.kill = true; + } } }