Waterfall/BungeeCord-Patches/0019-Add-basic-support-for-configurable-tab-complete-thro.patch
Shane Freeder 757945e1eb give the project some TLC
- Respect bungeecords new "log ping" configuration along side our own
  Waterfalls patch will likely be dropped by the end of the year, migrate!
- Drop 'Don't allow channel buffers to grow beyond a reasonable limit'
  This is already included upstream and is configurable using system properties
- Drop 'Security enhancements for EncryptionUtil'
  This patch is somewhat misguided given how mojangs auth service works and offers
  no real improvements to security
- cleanup some patches
  updated headers for changes which have been removed/extracted into other patches
  cleaned up some code formatting changes in misc sections
- touch up the contributing guide to reflect the recent script changes
2018-09-17 03:07:48 +01:00

93 lines
3.2 KiB
Diff

From 87e8a20022494a50d02a3306da2f2f5882984b68 Mon Sep 17 00:00:00 2001
From: Johannes Donath <johannesd@torchmind.com>
Date: Sat, 4 Jul 2015 06:31:33 +0200
Subject: [PATCH] Add basic support for configurable tab-complete throttling
diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
index b30541be..3750dc59 100644
--- a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
+++ b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
@@ -84,4 +84,12 @@ public interface ProxyConfig
// Waterfall Options
//
+ // Throttling options
+
+ /**
+ * How often tab-complete packets can be sent.
+ * <p/>
+ * Values in milliseconds.
+ */
+ int getTabThrottle();
}
diff --git a/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java b/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
index 741ebfde..0abb4075 100644
--- a/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
+++ b/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
@@ -7,11 +7,31 @@ import java.io.File;
public class WaterfallConfiguration extends Configuration {
+ /*
+ * Throttling options
+ * Helps prevent players from overloading the servers behind us
+ */
+
+ /**
+ * How often players are allowed to send tab throttle.
+ * Value in milliseconds.
+ * <p/>
+ * Default is one packet per second.
+ */
+ private int tabThrottle = 1000;
+
@Override
public void load() {
super.load();
YamlConfig config = new YamlConfig(new File("waterfall.yml"));
config.load(false); // Load, but no permissions
+ // Throttling options
+ tabThrottle = config.getInt("throttling.tab_complete", tabThrottle);
+ }
+
+ @Override
+ public int getTabThrottle() {
+ return tabThrottle;
}
}
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
index 9666e7a2..f08f464a 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
@@ -33,6 +33,8 @@ public class UpstreamBridge extends PacketHandler
private final ProxyServer bungee;
private final UserConnection con;
+ private long lastTabCompletion = -1;
+
public UpstreamBridge(ProxyServer bungee, UserConnection con)
{
this.bungee = bungee;
@@ -149,6 +151,16 @@ public class UpstreamBridge extends PacketHandler
@Override
public void handle(TabCompleteRequest tabComplete) throws Exception
{
+ if ( bungee.getConfig().getTabThrottle() > 0 )
+ {
+ long now = System.currentTimeMillis();
+ if ( lastTabCompletion > 0 && (now - lastTabCompletion) <= bungee.getConfig().getTabThrottle() )
+ {
+ throw CancelSendSignal.INSTANCE;
+ }
+ lastTabCompletion = now;
+ }
+
List<String> suggestions = new ArrayList<>();
if ( tabComplete.getCursor().startsWith( "/" ) )
--
2.19.0