mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-11-16 23:35:22 +01:00
Further Optimizations
This commit is contained in:
parent
8755112cba
commit
a4d3e218ef
@ -1,4 +1,4 @@
|
||||
From 66f5de5d3b8b5b1881a499f11bfb6433bdb6d2df Mon Sep 17 00:00:00 2001
|
||||
From 5c22787833121046061ec3b21c14c22b21e7c90f Mon Sep 17 00:00:00 2001
|
||||
From: LinsaFTW <25271111+linsaftw@users.noreply.github.com>
|
||||
Date: Fri, 4 Mar 2022 13:35:53 -0300
|
||||
Subject: [PATCH] Antibot System
|
||||
@ -27,19 +27,21 @@ index 20edd9001..f48f1e60b 100644
|
||||
|
||||
<build>
|
||||
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java
|
||||
index c78ab3a7c..ec880c07d 100644
|
||||
index c78ab3a7c..e5c8ed3e6 100644
|
||||
--- a/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java
|
||||
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java
|
||||
@@ -3,6 +3,8 @@ package dev._2lstudios.flamecord;
|
||||
@@ -3,6 +3,10 @@ package dev._2lstudios.flamecord;
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
+import dev._2lstudios.flamecord.antibot.AddressDataManager;
|
||||
+import dev._2lstudios.flamecord.antibot.CheckManager;
|
||||
+import dev._2lstudios.flamecord.antibot.LoggerWrapper;
|
||||
+import dev._2lstudios.flamecord.antibot.StatsData;
|
||||
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||||
import dev._2lstudios.flamecord.configuration.MessagesConfiguration;
|
||||
import dev._2lstudios.flamecord.configuration.ModulesConfiguration;
|
||||
@@ -18,26 +20,31 @@ public class FlameCord {
|
||||
@@ -18,26 +22,37 @@ public class FlameCord {
|
||||
if (FlameCord.instance != null) {
|
||||
instance.reload(logger);
|
||||
} else {
|
||||
@ -55,6 +57,10 @@ index c78ab3a7c..ec880c07d 100644
|
||||
+ private AddressDataManager addressDataManager;
|
||||
+ @Getter
|
||||
+ private CheckManager checkManager;
|
||||
+ @Getter
|
||||
+ private StatsData statsData;
|
||||
+ @Getter
|
||||
+ private LoggerWrapper loggerWrapper;
|
||||
+ @Getter
|
||||
private ModulesConfiguration modulesConfiguration;
|
||||
@Getter
|
||||
@ -74,6 +80,8 @@ index c78ab3a7c..ec880c07d 100644
|
||||
- reload(logger);
|
||||
+ this.addressDataManager = new AddressDataManager();
|
||||
+ this.checkManager = new CheckManager(addressDataManager, flameCordConfiguration);
|
||||
+ this.statsData = new StatsData();
|
||||
+ this.loggerWrapper = new LoggerWrapper(Logger.getLogger("BungeeCord"));
|
||||
}
|
||||
}
|
||||
\ No newline at end of file
|
||||
@ -121,10 +129,10 @@ index 000000000..5e7fa6bfb
|
||||
+}
|
||||
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/AddressData.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/AddressData.java
|
||||
new file mode 100644
|
||||
index 000000000..b8448bdf2
|
||||
index 000000000..c3ccae2b6
|
||||
--- /dev/null
|
||||
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/AddressData.java
|
||||
@@ -0,0 +1,154 @@
|
||||
@@ -0,0 +1,162 @@
|
||||
+package dev._2lstudios.flamecord.antibot;
|
||||
+
|
||||
+import java.util.Collection;
|
||||
@ -135,9 +143,10 @@ index 000000000..b8448bdf2
|
||||
+
|
||||
+public class AddressData {
|
||||
+ private FlameCordConfiguration config;
|
||||
+ private final Collection<String> nicknames = new HashSet<>();
|
||||
+ private StatsData statsData;
|
||||
+ private Collection<String> nicknames = null;
|
||||
+ private final String hostString;
|
||||
+ private String lastNickname = "";
|
||||
+ private String lastNickname = null;
|
||||
+ private String country = null;
|
||||
+ private String firewallReason = null;
|
||||
+ private long lastPing = 0;
|
||||
@ -151,10 +160,13 @@ index 000000000..b8448bdf2
|
||||
+
|
||||
+ public AddressData(final String hostString) {
|
||||
+ this.config = FlameCord.getInstance().getFlameCordConfiguration();
|
||||
+ this.statsData = FlameCord.getInstance().getStatsData();
|
||||
+ this.hostString = hostString;
|
||||
+ }
|
||||
+
|
||||
+ public Collection<String> getNicknames() {
|
||||
+ if (nicknames == null) nicknames = new HashSet<>();
|
||||
+
|
||||
+ return nicknames;
|
||||
+ }
|
||||
+
|
||||
@ -163,7 +175,9 @@ index 000000000..b8448bdf2
|
||||
+ }
|
||||
+
|
||||
+ public void addNickname(final String nickname) {
|
||||
+ if (!lastNickname.equals(nickname)) {
|
||||
+ if (nicknames == null) nicknames = new HashSet<>();
|
||||
+
|
||||
+ if (lastNickname == null || !lastNickname.equals(nickname)) {
|
||||
+ this.lastNickname = nickname;
|
||||
+ this.totalConnections = 1;
|
||||
+ }
|
||||
@ -199,6 +213,7 @@ index 000000000..b8448bdf2
|
||||
+ }
|
||||
+
|
||||
+ public void addPing() {
|
||||
+ statsData.addPing();
|
||||
+ updatePingsSecond();
|
||||
+ lastPing = System.currentTimeMillis();
|
||||
+ pingsSecond++;
|
||||
@ -223,6 +238,7 @@ index 000000000..b8448bdf2
|
||||
+ public void addConnection() {
|
||||
+ final long currentTime = System.currentTimeMillis();
|
||||
+
|
||||
+ statsData.addConnection();
|
||||
+ updateConnectionsSecond();
|
||||
+ penultimateConnection = lastConnection == 0 ? currentTime : lastConnection;
|
||||
+ lastConnection = currentTime;
|
||||
@ -281,10 +297,10 @@ index 000000000..b8448bdf2
|
||||
+}
|
||||
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/AddressDataManager.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/AddressDataManager.java
|
||||
new file mode 100644
|
||||
index 000000000..97b26f938
|
||||
index 000000000..9f74116b3
|
||||
--- /dev/null
|
||||
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/AddressDataManager.java
|
||||
@@ -0,0 +1,31 @@
|
||||
@@ -0,0 +1,35 @@
|
||||
+package dev._2lstudios.flamecord.antibot;
|
||||
+
|
||||
+import java.net.InetSocketAddress;
|
||||
@ -315,6 +331,10 @@ index 000000000..97b26f938
|
||||
+
|
||||
+ return getAddressData(addressString);
|
||||
+ }
|
||||
+
|
||||
+ public int getAddresCount() {
|
||||
+ return addressData.size();
|
||||
+ }
|
||||
+}
|
||||
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/CheckManager.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/CheckManager.java
|
||||
new file mode 100644
|
||||
@ -546,6 +566,40 @@ index 000000000..682e1c314
|
||||
+ return false;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/LoggerWrapper.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/LoggerWrapper.java
|
||||
new file mode 100644
|
||||
index 000000000..bbd84ce5c
|
||||
--- /dev/null
|
||||
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/LoggerWrapper.java
|
||||
@@ -0,0 +1,28 @@
|
||||
+package dev._2lstudios.flamecord.antibot;
|
||||
+
|
||||
+import java.util.logging.Level;
|
||||
+import java.util.logging.Logger;
|
||||
+
|
||||
+public class LoggerWrapper {
|
||||
+ private Logger logger;
|
||||
+
|
||||
+ // Last time a log was done
|
||||
+ private long lastLog = System.currentTimeMillis();
|
||||
+
|
||||
+ public LoggerWrapper(Logger logger) {
|
||||
+ this.logger = logger;
|
||||
+ }
|
||||
+
|
||||
+ public void log(Level level, String msg, Object ...params) {
|
||||
+ long currentTime = System.currentTimeMillis();
|
||||
+
|
||||
+ // Throttle logs by 100ms
|
||||
+ if (lastLog - currentTime > 100) {
|
||||
+ // Set the last log
|
||||
+ lastLog = currentTime;
|
||||
+
|
||||
+ // Log the text
|
||||
+ logger.log(level, msg, params);
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/NicknameCheck.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/NicknameCheck.java
|
||||
new file mode 100644
|
||||
index 000000000..165963629
|
||||
@ -945,6 +999,71 @@ index 000000000..68cc4c217
|
||||
+ return false;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/StatsData.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/StatsData.java
|
||||
new file mode 100644
|
||||
index 000000000..2d60ec2b4
|
||||
--- /dev/null
|
||||
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/antibot/StatsData.java
|
||||
@@ -0,0 +1,59 @@
|
||||
+package dev._2lstudios.flamecord.antibot;
|
||||
+
|
||||
+public class StatsData {
|
||||
+ // Time of the last second
|
||||
+ private long lastSecond = System.currentTimeMillis();
|
||||
+
|
||||
+ // Current second connections and pings
|
||||
+ private int currentPings = 0;
|
||||
+ private int currentConnections = 0;
|
||||
+
|
||||
+ // Last second connections and pings
|
||||
+ private int lastPings = 0;
|
||||
+ private int lastConnections = 0;
|
||||
+
|
||||
+ public void resetData() {
|
||||
+ // Get current time
|
||||
+ long currentTime = System.currentTimeMillis();
|
||||
+
|
||||
+ // Check if one second passed
|
||||
+ if (lastSecond - currentTime > 1000) {
|
||||
+ // Set the last second to this one
|
||||
+ lastSecond = currentTime;
|
||||
+
|
||||
+ // Reset the data
|
||||
+ lastPings = currentPings;
|
||||
+ lastConnections = currentConnections;
|
||||
+ currentPings = 0;
|
||||
+ currentConnections = 0;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public void addPing() {
|
||||
+ currentPings++;
|
||||
+ }
|
||||
+
|
||||
+ public void addConnection() {
|
||||
+ currentConnections++;
|
||||
+ }
|
||||
+
|
||||
+ public int getCurrentPings() {
|
||||
+ resetData();
|
||||
+ return currentPings;
|
||||
+ }
|
||||
+
|
||||
+ public int getCurrentConnections() {
|
||||
+ resetData();
|
||||
+ return currentConnections;
|
||||
+ }
|
||||
+
|
||||
+ public int getLastPings() {
|
||||
+ resetData();
|
||||
+ return lastPings;
|
||||
+ }
|
||||
+
|
||||
+ public int getLastConnections() {
|
||||
+ resetData();
|
||||
+ return lastConnections;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java
|
||||
index a1d23f74d..d42e3d75f 100644
|
||||
--- a/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java
|
||||
@ -1120,10 +1239,10 @@ index a1d23f74d..d42e3d75f 100644
|
||||
|
||||
this.loggerInitialhandler = setIfUnexistant("logger.initialhandler", this.loggerInitialhandler, configuration);
|
||||
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/MessagesConfiguration.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/MessagesConfiguration.java
|
||||
index 4f306660e..5faab6166 100644
|
||||
index 4f306660e..fdcd1544d 100644
|
||||
--- a/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/MessagesConfiguration.java
|
||||
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/MessagesConfiguration.java
|
||||
@@ -82,12 +82,26 @@ public class MessagesConfiguration extends FlameConfig {
|
||||
@@ -82,12 +82,27 @@ public class MessagesConfiguration extends FlameConfig {
|
||||
setIfUnexistant("command_ip", "&9IP of {0} is {1}", configuration);
|
||||
setIfUnexistant("illegal_chat_characters", "&cIllegal characters in chat ({0})", configuration);
|
||||
|
||||
@ -1136,6 +1255,7 @@ index 4f306660e..5faab6166 100644
|
||||
+ setIfUnexistant("antibot_ratelimit", "&c&lFlameCord\n\n&cYou are connecting too fast! ({0})\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||
+ setIfUnexistant("antibot_reconnect", "&c&lFlameCord\n\n&cReconnect {0} more times to enter!\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||
+ setIfUnexistant("antibot_country", "&c&lFlameCord\n\n&cYour country {0} is blacklisted!\n\n&cError? Contact us on discord.gg/gF36AT3", configuration);
|
||||
+ setIfUnexistant("antibot_stats", "&aFlameCord Antibot Stats\n &ePings: {0}\n &eConnections: {1}", configuration);
|
||||
+ // FlameCord end - Antibot System
|
||||
+
|
||||
// FlameCord
|
||||
@ -1281,18 +1401,19 @@ index c0d371426..403ccba98 100644
|
||||
|
||||
@Override
|
||||
diff --git a/proxy/src/main/java/dev/_2lstudios/flamecord/commands/FlameCordCommand.java b/proxy/src/main/java/dev/_2lstudios/flamecord/commands/FlameCordCommand.java
|
||||
index cc76325b2..1ddae60be 100644
|
||||
index cc76325b2..c64e7f2e4 100644
|
||||
--- a/proxy/src/main/java/dev/_2lstudios/flamecord/commands/FlameCordCommand.java
|
||||
+++ b/proxy/src/main/java/dev/_2lstudios/flamecord/commands/FlameCordCommand.java
|
||||
@@ -4,6 +4,7 @@ import java.util.Collection;
|
||||
@@ -4,6 +4,8 @@ import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
import dev._2lstudios.flamecord.FlameCord;
|
||||
+import dev._2lstudios.flamecord.antibot.AddressDataManager;
|
||||
+import dev._2lstudios.flamecord.antibot.StatsData;
|
||||
import dev._2lstudios.flamecord.configuration.MessagesConfiguration;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
@@ -27,9 +28,7 @@ private final BungeeCord bungeeCord;
|
||||
@@ -27,9 +29,7 @@ private final BungeeCord bungeeCord;
|
||||
|
||||
if (sender.hasPermission("flamecord.usage")) {
|
||||
if (args.length > 0) {
|
||||
@ -1303,10 +1424,19 @@ index cc76325b2..1ddae60be 100644
|
||||
case "reload": {
|
||||
// FlameCord - Collect ips from servers
|
||||
final Collection<String> whitelistedAddresses = new HashSet<>();
|
||||
@@ -43,9 +42,34 @@ private final BungeeCord bungeeCord;
|
||||
@@ -43,9 +43,43 @@ private final BungeeCord bungeeCord;
|
||||
.fromLegacyText(messagesConfiguration.getTranslation("flamecord_reload")));
|
||||
break;
|
||||
}
|
||||
+ case "stats": {
|
||||
+ StatsData statsData = FlameCord.getInstance().getStatsData();
|
||||
+ int pings = statsData.getLastPings();
|
||||
+ int connections = statsData.getLastConnections();
|
||||
+ int addressCount = FlameCord.getInstance().getAddressDataManager().getAddresCount();
|
||||
+
|
||||
+ sender.sendMessage(TextComponent.fromLegacyText(messagesConfiguration.getTranslation("antibot_stats", pings, connections, addressCount)));
|
||||
+ break;
|
||||
+ }
|
||||
+ case "firewall": {
|
||||
+ if (args.length > 2) {
|
||||
+ String ip = "/" + args[2];
|
||||
|
@ -0,0 +1,79 @@
|
||||
From c109df033824883c45ec038d327ab6de14094434 Mon Sep 17 00:00:00 2001
|
||||
From: LinsaFTW <25271111+linsaftw@users.noreply.github.com>
|
||||
Date: Sat, 31 Dec 2022 14:44:10 -0300
|
||||
Subject: [PATCH] Disable fromLegacyText Links
|
||||
|
||||
|
||||
diff --git a/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java b/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java
|
||||
index 4371374a9..1df68c300 100644
|
||||
--- a/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java
|
||||
+++ b/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java
|
||||
@@ -47,7 +47,6 @@ public final class TextComponent extends BaseComponent
|
||||
ArrayList<BaseComponent> components = new ArrayList<>();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
TextComponent component = new TextComponent();
|
||||
- Matcher matcher = url.matcher( message );
|
||||
|
||||
for ( int i = 0; i < message.length(); i++ )
|
||||
{
|
||||
@@ -128,29 +127,6 @@ public final class TextComponent extends BaseComponent
|
||||
{
|
||||
pos = message.length();
|
||||
}
|
||||
- if ( matcher.region( i, pos ).find() )
|
||||
- { //Web link handling
|
||||
-
|
||||
- if ( builder.length() > 0 )
|
||||
- {
|
||||
- TextComponent old = component;
|
||||
- component = new TextComponent( old );
|
||||
- old.setText( builder.toString() );
|
||||
- builder = new StringBuilder();
|
||||
- components.add( old );
|
||||
- }
|
||||
-
|
||||
- TextComponent old = component;
|
||||
- component = new TextComponent( old );
|
||||
- String urlString = message.substring( i, pos );
|
||||
- component.setText( urlString );
|
||||
- component.setClickEvent( new ClickEvent( ClickEvent.Action.OPEN_URL,
|
||||
- urlString.startsWith( "http" ) ? urlString : "http://" + urlString ) );
|
||||
- components.add( component );
|
||||
- i += pos - i - 1;
|
||||
- component = old;
|
||||
- continue;
|
||||
- }
|
||||
builder.append( c );
|
||||
}
|
||||
|
||||
diff --git a/chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java b/chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java
|
||||
index d212d76cb..4a2c9a885 100644
|
||||
--- a/chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java
|
||||
+++ b/chat/src/test/java/net/md_5/bungee/api/chat/ComponentsTest.java
|
||||
@@ -354,23 +354,6 @@ public class ComponentsTest
|
||||
|
||||
Assert.assertEquals( "Aqua RedBold", BaseComponent.toPlainText( test1 ) );
|
||||
Assert.assertEquals( ChatColor.AQUA + "Aqua " + ChatColor.RED + ChatColor.BOLD + "RedBold", BaseComponent.toLegacyText( test1 ) );
|
||||
-
|
||||
- BaseComponent[] test2 = TextComponent.fromLegacyText( "Text http://spigotmc.org " + ChatColor.GREEN + "google.com/test" );
|
||||
-
|
||||
- Assert.assertEquals( "Text http://spigotmc.org google.com/test", BaseComponent.toPlainText( test2 ) );
|
||||
- //The extra ChatColor instances are sometimes inserted when not needed but it doesn't change the result
|
||||
- Assert.assertEquals( ChatColor.WHITE + "Text " + ChatColor.WHITE + "http://spigotmc.org" + ChatColor.WHITE
|
||||
- + " " + ChatColor.GREEN + "google.com/test" + ChatColor.GREEN, BaseComponent.toLegacyText( test2 ) );
|
||||
-
|
||||
- ClickEvent url1 = test2[1].getClickEvent();
|
||||
- Assert.assertNotNull( url1 );
|
||||
- Assert.assertTrue( url1.getAction() == ClickEvent.Action.OPEN_URL );
|
||||
- Assert.assertEquals( "http://spigotmc.org", url1.getValue() );
|
||||
-
|
||||
- ClickEvent url2 = test2[3].getClickEvent();
|
||||
- Assert.assertNotNull( url2 );
|
||||
- Assert.assertTrue( url2.getAction() == ClickEvent.Action.OPEN_URL );
|
||||
- Assert.assertEquals( "http://google.com/test", url2.getValue() );
|
||||
}
|
||||
|
||||
@Test
|
||||
--
|
||||
2.37.3.windows.1
|
||||
|
Loading…
Reference in New Issue
Block a user