mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-12-31 21:18:10 +01:00
174 lines
8.3 KiB
Diff
174 lines
8.3 KiB
Diff
From 949366cf4d86f210fa406e98c0e48fbbef9eca54 Mon Sep 17 00:00:00 2001
|
|
From: Juan Cruz Linsalata <LinsaFTW@users.noreply.github.com>
|
|
Date: Thu, 3 Sep 2020 18:37:43 -0300
|
|
Subject: [PATCH] FlameCord Whitelist servers addresses
|
|
|
|
|
|
diff --git a/flamecord/.factorypath b/flamecord/.factorypath
|
|
index f398f41e..ed4e646c 100644
|
|
--- a/flamecord/.factorypath
|
|
+++ b/flamecord/.factorypath
|
|
@@ -1,4 +1,5 @@
|
|
<factorypath>
|
|
+ <factorypathentry kind="VARJAR" id="M2_REPO/com/google/code/gson/gson/2.8.0/gson-2.8.0.jar" enabled="true" runInBatchMode="false"/>
|
|
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/guava/21.0/guava-21.0.jar" enabled="true" runInBatchMode="false"/>
|
|
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/code/findbugs/findbugs-annotations/3.0.1/findbugs-annotations-3.0.1.jar" enabled="true" runInBatchMode="false"/>
|
|
<factorypathentry kind="VARJAR" id="M2_REPO/org/projectlombok/lombok/1.18.10/lombok-1.18.10.jar" enabled="true" runInBatchMode="false"/>
|
|
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java
|
|
index 3a7f56ee..29c1573a 100644
|
|
--- a/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java
|
|
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java
|
|
@@ -1,5 +1,6 @@
|
|
package dev._2lstudios.flamecord;
|
|
|
|
+import java.util.Collection;
|
|
import java.util.logging.Logger;
|
|
|
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
|
@@ -21,21 +22,25 @@ public class FlameCord {
|
|
private final ModulesConfiguration modulesConfiguration;
|
|
@Getter
|
|
private final MessagesConfiguration messagesConfiguration;
|
|
+ @Getter
|
|
private final Thread thread;
|
|
|
|
- public static void renew(final Logger logger) {
|
|
+ public static void renew(final Logger logger, final Collection<String> whitelistedAddresses) {
|
|
if (FlameCord.instance != null) {
|
|
FlameCord.instance.thread.interrupt();
|
|
}
|
|
|
|
- FlameCord.instance = new FlameCord(logger);
|
|
+ final FlameCord instance = new FlameCord(logger, whitelistedAddresses);
|
|
+
|
|
+ FlameCord.instance = instance;
|
|
}
|
|
|
|
- private FlameCord(final Logger logger) {
|
|
- final ConfigurationProvider configurationProvider = YamlConfiguration.getProvider(YamlConfiguration.class);
|
|
+ private FlameCord(final Logger logger, final Collection<String> whitelistedAddresses) {
|
|
+ final ConfigurationProvider configurationProvider = ConfigurationProvider.getProvider(YamlConfiguration.class);
|
|
|
|
this.flameCordConfiguration = new FlameCordConfiguration(configurationProvider);
|
|
- this.firewallManager = new FirewallManager(logger, flameCordConfiguration.getFirewallSeconds());
|
|
+ this.firewallManager = new FirewallManager(logger, whitelistedAddresses,
|
|
+ flameCordConfiguration.getFirewallSeconds());
|
|
this.modulesConfiguration = new ModulesConfiguration(configurationProvider);
|
|
this.messagesConfiguration = new MessagesConfiguration(logger, configurationProvider);
|
|
this.thread = new Thread() {
|
|
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/firewall/FirewallManager.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/firewall/FirewallManager.java
|
|
index a90c8426..8a474758 100644
|
|
--- a/flamecord/src/main/java/dev/_2lstudios/flamecord/firewall/FirewallManager.java
|
|
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/firewall/FirewallManager.java
|
|
@@ -12,20 +12,35 @@ import lombok.Getter;
|
|
|
|
public class FirewallManager {
|
|
private final Logger logger;
|
|
+ private final Collection<String> whitelistedAddresses;
|
|
private final Collection<String> firewalled;
|
|
private final int defaultSeconds;
|
|
@Getter
|
|
private int seconds;
|
|
|
|
- public FirewallManager(final Logger logger, final int defaultSeconds) {
|
|
+ public FirewallManager(final Logger logger, final Collection<String> whitelistedAddresses,
|
|
+ final int defaultSeconds) {
|
|
this.logger = logger;
|
|
+ this.whitelistedAddresses = whitelistedAddresses;
|
|
this.firewalled = new HashSet<>();
|
|
this.defaultSeconds = defaultSeconds;
|
|
this.seconds = defaultSeconds;
|
|
}
|
|
|
|
+ public boolean isWhitelisted(final SocketAddress address) {
|
|
+ final String addressString = address.toString();
|
|
+
|
|
+ for (final String whitelistedAddressString : whitelistedAddresses) {
|
|
+ if (addressString.endsWith(whitelistedAddressString)) {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return false;
|
|
+ }
|
|
+
|
|
public void addFirewalled(final SocketAddress address) {
|
|
- if (FlameCord.getInstance().getFlameCordConfiguration().isFirewallEnabled()) {
|
|
+ if (FlameCord.getInstance().getFlameCordConfiguration().isFirewallEnabled() && !isWhitelisted(address)) {
|
|
final InetSocketAddress iNetSocketAddress = (InetSocketAddress) address;
|
|
final String hostString = iNetSocketAddress.getHostString();
|
|
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
|
|
index d6d4cd6e..34c0b675 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
|
|
@@ -288,19 +288,30 @@ public class BungeeCord extends ProxyServer {
|
|
workerEventLoopGroup = PipelineUtils.newEventLoopGroup(0,
|
|
new ThreadFactoryBuilder().setNameFormat("Netty Worker IO Thread #%1$d").build());
|
|
|
|
+ // FlameCord - Load config before
|
|
+ config.load();
|
|
+
|
|
// FlameCord - Use own module system and reload FlameCord
|
|
/*
|
|
* File moduleDirectory = new File( "modules" ); moduleManager.load( this,
|
|
* moduleDirectory ); pluginManager.detectPlugins( moduleDirectory );
|
|
*/
|
|
- FlameCord.renew(logger);
|
|
+ // FlameCord - Collect ips from servers
|
|
+ final Collection<String> whitelistedAddresses = new HashSet<>();
|
|
+
|
|
+ for (final ServerInfo serverInfo : getServers().values()) {
|
|
+ whitelistedAddresses.add(serverInfo.getSocketAddress().toString());
|
|
+ }
|
|
+
|
|
+ FlameCord.renew(logger, whitelistedAddresses);
|
|
registerModules();
|
|
|
|
pluginsFolder.mkdir();
|
|
pluginManager.detectPlugins(pluginsFolder);
|
|
|
|
pluginManager.loadPlugins();
|
|
- config.load();
|
|
+ // FlameCord - Load config before
|
|
+ // config.load();
|
|
|
|
if (config.isForgeSupport()) {
|
|
registerChannel(ForgeConstants.FML_TAG);
|
|
@@ -828,7 +839,14 @@ public class BungeeCord extends ProxyServer {
|
|
break;
|
|
}
|
|
case "reload": {
|
|
- FlameCord.renew(logger);
|
|
+ // FlameCord - Collect ips from servers
|
|
+ final Collection<String> whitelistedAddresses = new HashSet<>();
|
|
+
|
|
+ for (final ServerInfo serverInfo : getServers().values()) {
|
|
+ whitelistedAddresses.add(serverInfo.getSocketAddress().toString());
|
|
+ }
|
|
+
|
|
+ FlameCord.renew(logger, whitelistedAddresses);
|
|
sender.sendMessage(TextComponent
|
|
.fromLegacyText(messagesConfiguration.getTranslation("flamecord_reload")));
|
|
break;
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java
|
|
index 687bf518..0f6ac089 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java
|
|
@@ -146,11 +146,7 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter {
|
|
final SocketAddress remoteAddress = channel.remoteAddress();
|
|
|
|
if (remoteAddress != null) {
|
|
- final Throwable causeCause = cause.getCause();
|
|
-
|
|
- if (causeCause == null || !causeCause.getMessage().contains("TO_CLIENT")) {
|
|
- flameCord.getFirewallManager().addFirewalled(remoteAddress);
|
|
- }
|
|
+ flameCord.getFirewallManager().addFirewalled(remoteAddress);
|
|
}
|
|
}
|
|
|
|
--
|
|
2.27.0.windows.1
|
|
|