Waterfall/BungeeCord-Patches/0020-Add-basic-support-for-configurable-tab-complete-thro.patch

99 lines
3.4 KiB
Diff
Raw Normal View History

2017-08-18 11:36:42 +02:00
From c1900744f556a04f6c65ebb14bea70873a03847d 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
2017-08-18 11:36:42 +02:00
index 293ec4e3..66d0b8a1 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
@@ -88,4 +88,13 @@ public interface ProxyConfig
* If metrics is enabled
*/
boolean isMetrics();
+
+ // Throttling options
+
+ /**
+ * How often tab-complete packets can be sent.
+ * <p/>
+ * Values in milliseconds.
+ */
+ int getTabThrottle();
}
2016-11-26 21:39:19 +01:00
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
2017-08-18 11:36:42 +02:00
index 056b8040..e56d3591 100644
2016-11-26 21:39:19 +01:00
--- a/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
+++ b/proxy/src/main/java/io/github/waterfallmc/waterfall/conf/WaterfallConfiguration.java
@@ -16,16 +16,36 @@ public class WaterfallConfiguration extends Configuration {
*/
private boolean metrics = true;
+ /*
+ * 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
metrics = config.getBoolean("metrics", metrics);
+ // Throttling options
+ tabThrottle = config.getInt("throttling.tab_complete", tabThrottle);
}
@Override
public boolean isMetrics() {
return metrics;
}
+
+ @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
2017-08-18 11:36:42 +02:00
index 167f1f88..02a4ca37 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
2017-08-18 11:36:42 +02:00
@@ -32,6 +32,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;
2017-08-18 11:36:42 +02:00
@@ -145,6 +147,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( "/" ) )
--
2017-08-18 11:36:42 +02:00
2.14.1