2023-09-23 03:27:23 +02:00
|
|
|
From 49229d1749cebd2fbd7ce9f73925e2f88ba6d46c Mon Sep 17 00:00:00 2001
|
2016-05-28 18:34:39 +02:00
|
|
|
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
|
2020-02-01 16:39:53 +01:00
|
|
|
index 6495e7f2..b6845bc4 100644
|
2016-05-28 18:34:39 +02:00
|
|
|
--- a/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
|
|
|
|
+++ b/api/src/main/java/net/md_5/bungee/api/ProxyConfig.java
|
2020-02-01 16:39:53 +01:00
|
|
|
@@ -130,4 +130,21 @@ public interface ProxyConfig
|
2018-07-22 18:40:31 +02:00
|
|
|
// Waterfall Options
|
|
|
|
//
|
|
|
|
|
2016-05-28 18:34:39 +02:00
|
|
|
+ // Throttling options
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * How often tab-complete packets can be sent.
|
2019-03-30 17:09:06 +01:00
|
|
|
+ * <br>
|
2016-05-28 18:34:39 +02:00
|
|
|
+ * Values in milliseconds.
|
2019-03-30 17:09:06 +01:00
|
|
|
+ *
|
|
|
|
+ * @return how often tab-complete packets can be sent in milliseconds
|
2016-05-28 18:34:39 +02:00
|
|
|
+ */
|
|
|
|
+ int getTabThrottle();
|
2018-10-06 20:54:52 +02:00
|
|
|
+
|
|
|
|
+ /**
|
2019-03-30 17:09:06 +01:00
|
|
|
+ * Should we disable the tab completion limit for 1.13+ clients
|
|
|
|
+ *
|
2018-10-06 20:54:52 +02:00
|
|
|
+ * @return should we disable the tab completion limit for 1.13+ clients
|
|
|
|
+ */
|
|
|
|
+ boolean isDisableModernTabLimiter();
|
2016-05-28 18:34:39 +02:00
|
|
|
}
|
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
|
2018-10-06 20:54:52 +02:00
|
|
|
index 741ebfde..91743f01 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
|
2018-10-06 20:54:52 +02:00
|
|
|
@@ -7,11 +7,37 @@ import java.io.File;
|
2018-07-22 18:40:31 +02:00
|
|
|
|
|
|
|
public class WaterfallConfiguration extends Configuration {
|
2016-05-28 18:34:39 +02:00
|
|
|
|
|
|
|
+ /*
|
|
|
|
+ * 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;
|
2018-10-06 20:54:52 +02:00
|
|
|
+ private boolean disableModernTabLimiter = true;
|
2016-05-28 18:34:39 +02:00
|
|
|
+
|
|
|
|
@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);
|
2018-10-06 20:54:52 +02:00
|
|
|
+ disableModernTabLimiter = config.getBoolean("disable_modern_tab_limiter", disableModernTabLimiter);
|
|
|
|
}
|
|
|
|
|
2016-05-28 18:34:39 +02:00
|
|
|
+ @Override
|
|
|
|
+ public int getTabThrottle() {
|
|
|
|
+ return tabThrottle;
|
2018-10-06 20:54:52 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean isDisableModernTabLimiter() {
|
|
|
|
+ return disableModernTabLimiter;
|
|
|
|
+ }
|
2016-05-28 18:34:39 +02:00
|
|
|
}
|
|
|
|
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
|
2023-09-23 03:27:23 +02:00
|
|
|
index 48a523c6..cfad8f53 100644
|
2016-05-28 18:34:39 +02:00
|
|
|
--- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
|
|
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
|
2023-09-23 03:27:23 +02:00
|
|
|
@@ -48,6 +48,8 @@ public class UpstreamBridge extends PacketHandler
|
2016-05-28 18:34:39 +02:00
|
|
|
private final ProxyServer bungee;
|
|
|
|
private final UserConnection con;
|
|
|
|
|
|
|
|
+ private long lastTabCompletion = -1;
|
|
|
|
+
|
|
|
|
public UpstreamBridge(ProxyServer bungee, UserConnection con)
|
|
|
|
{
|
|
|
|
this.bungee = bungee;
|
2023-09-23 03:27:23 +02:00
|
|
|
@@ -214,6 +216,20 @@ public class UpstreamBridge extends PacketHandler
|
2016-05-28 18:34:39 +02:00
|
|
|
@Override
|
|
|
|
public void handle(TabCompleteRequest tabComplete) throws Exception
|
|
|
|
{
|
2018-10-06 20:54:52 +02:00
|
|
|
+ // Waterfall start - tab limiter
|
|
|
|
+ if ( bungee.getConfig().getTabThrottle() > 0 &&
|
|
|
|
+ ( con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13
|
|
|
|
+ && !bungee.getConfig().isDisableModernTabLimiter()))
|
2016-05-28 18:34:39 +02:00
|
|
|
+ {
|
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
|
+ if ( lastTabCompletion > 0 && (now - lastTabCompletion) <= bungee.getConfig().getTabThrottle() )
|
|
|
|
+ {
|
|
|
|
+ throw CancelSendSignal.INSTANCE;
|
|
|
|
+ }
|
|
|
|
+ lastTabCompletion = now;
|
|
|
|
+ }
|
|
|
|
+
|
2018-10-06 20:54:52 +02:00
|
|
|
+ // Waterfall end - tab limiter
|
2016-05-28 18:34:39 +02:00
|
|
|
List<String> suggestions = new ArrayList<>();
|
2021-11-05 08:36:35 +01:00
|
|
|
boolean isRegisteredCommand = false;
|
2023-09-21 12:33:23 +02:00
|
|
|
boolean isCommand = tabComplete.getCursor().startsWith( "/" );
|
2016-05-28 18:34:39 +02:00
|
|
|
--
|
2023-09-21 12:33:23 +02:00
|
|
|
2.42.0
|
2016-05-28 18:34:39 +02:00
|
|
|
|