mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-11-28 21:25:47 +01:00
99 lines
3.4 KiB
Diff
99 lines
3.4 KiB
Diff
From d8a4843bb21d6878bf71cc1acff155ffce7d28e8 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 293ec4e..66d0b8a 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();
|
|
}
|
|
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 056b804..e56d359 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
|
|
@@ -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
|
|
index 92d1da0..654be21 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
|
|
@@ -31,6 +31,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;
|
|
@@ -128,6 +130,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.10.0
|
|
|