Waterfall/Waterfall-Proxy-Patches/0019-FlameCord-General-Patch.patch
Luccboy d75d7d1edc
Updated Upstream (Waterfall)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by 2LStudios and as with ANY update, please do your own testing

Waterfall Changes:
a5c78a9 (Maybe) Fix javadoc search
eb920b8 Updated Upstream (BungeeCord)
8e9b90a fix compile-native not working on linux
ee819df Updated Upstream (BungeeCord)
66601f7 [ci skip] link to javadocs page instead of attempting direct
2021-07-04 22:22:11 +02:00

384 lines
16 KiB
Diff

From 1f6d89b080f89d2a235554957815deb3047dab05 Mon Sep 17 00:00:00 2001
From: Juan Cruz Linsalata <LinsaFTW@users.noreply.github.com>
Date: Mon, 12 Oct 2020 15:40:53 -0300
Subject: [PATCH] FlameCord General Patch
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java
new file mode 100644
index 00000000..252612a3
--- /dev/null
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java
@@ -0,0 +1,34 @@
+package dev._2lstudios.flamecord;
+
+import java.util.Collection;
+import java.util.logging.Logger;
+
+import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
+import lombok.Getter;
+import net.md_5.bungee.config.ConfigurationProvider;
+import net.md_5.bungee.config.YamlConfiguration;
+
+public class FlameCord {
+ @Getter
+ private static FlameCord instance;
+ @Getter
+ private final FlameCordConfiguration flameCordConfiguration;
+ @Getter
+ private boolean running = true;
+
+ public static void renew(final Logger logger, final Collection<String> whitelistedAddresses) {
+ if (FlameCord.instance != null) {
+ FlameCord.instance.running = false;
+ }
+
+ final FlameCord instance = new FlameCord(logger, whitelistedAddresses);
+
+ FlameCord.instance = instance;
+ }
+
+ private FlameCord(final Logger logger, final Collection<String> whitelistedAddresses) {
+ final ConfigurationProvider configurationProvider = ConfigurationProvider.getProvider(YamlConfiguration.class);
+
+ this.flameCordConfiguration = new FlameCordConfiguration(configurationProvider);
+ }
+}
\ No newline at end of file
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java
new file mode 100644
index 00000000..81ded224
--- /dev/null
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java
@@ -0,0 +1,64 @@
+package dev._2lstudios.flamecord.configuration;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+
+import lombok.Getter;
+import net.md_5.bungee.config.Configuration;
+import net.md_5.bungee.config.ConfigurationProvider;
+
+public class FlameCordConfiguration {
+ public FlameCordConfiguration(final ConfigurationProvider configurationProvider) {
+ try {
+ final String fileName = "./flamecord.yml";
+ final File configurationFile = new File(fileName);
+ final Configuration configuration;
+ final boolean configurationExists = configurationFile.exists();
+
+ if (!configurationExists) {
+ configuration = new Configuration();
+ } else {
+ configuration = configurationProvider.load(configurationFile);
+ }
+
+ if (!configurationExists) {
+ configurationProvider.save(configuration, configurationFile);
+ }
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private int setIfUnexistant(final String arg1, final int arg2, final Configuration configuration) {
+ return (int) setIfUnexistant(arg1, (Object) arg2, configuration);
+ }
+
+ private boolean setIfUnexistant(final String arg1, final boolean arg2, final Configuration configuration) {
+ return (boolean) setIfUnexistant(arg1, (Object) arg2, configuration);
+ }
+
+ private Object setIfUnexistant(final String arg1, final Object arg2, final Configuration configuration) {
+ if (!configuration.contains(arg1)) {
+ configuration.set(arg1, arg2);
+
+ return arg2;
+ } else {
+ return configuration.get(arg1);
+ }
+ }
+
+ private Collection<String> setIfUnexistant(final String arg1, final Collection<String> arg2,
+ final Configuration configuration) {
+ if (!configuration.contains(arg1)) {
+ configuration.set(arg1, new ArrayList<>(arg2));
+
+ return arg2;
+ } else {
+ return new HashSet<>(configuration.getStringList(arg1));
+ }
+ }
+}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
index ec07ae6f..91da8ab6 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
@@ -1,5 +1,6 @@
package net.md_5.bungee.protocol;
+import dev._2lstudios.flamecord.FlameCord;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
diff --git a/proxy/src/main/java/dev/_2lstudios/flamecord/commands/FlameCordCommand.java b/proxy/src/main/java/dev/_2lstudios/flamecord/commands/FlameCordCommand.java
new file mode 100644
index 00000000..a323598e
--- /dev/null
+++ b/proxy/src/main/java/dev/_2lstudios/flamecord/commands/FlameCordCommand.java
@@ -0,0 +1,58 @@
+package dev._2lstudios.flamecord.commands;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import dev._2lstudios.flamecord.FlameCord;
+import net.md_5.bungee.BungeeCord;
+import net.md_5.bungee.api.CommandSender;
+import net.md_5.bungee.api.chat.TextComponent;
+import net.md_5.bungee.api.config.ServerInfo;
+import net.md_5.bungee.api.plugin.Command;
+
+public class FlameCordCommand extends Command {
+private final BungeeCord bungeeCord;
+
+ public FlameCordCommand(final BungeeCord bungeeCord) {
+ super("flamecord");
+
+ this.bungeeCord = bungeeCord;
+ }
+
+ @Override
+ public void execute(final CommandSender sender, final String[] args) {
+ final FlameCord flameCord = FlameCord.getInstance();
+
+ if (sender.hasPermission("flamecord.usage")) {
+ if (args.length > 0) {
+ final String arg0 = args[0];
+
+ switch (arg0) {
+ case "reload": {
+ // FlameCord - Collect ips from servers
+ final Collection<String> whitelistedAddresses = new HashSet<>();
+
+ for (final ServerInfo serverInfo : bungeeCord.getServers().values()) {
+ whitelistedAddresses.add(serverInfo.getSocketAddress().toString());
+ }
+
+ FlameCord.renew(bungeeCord.getLogger(), whitelistedAddresses);
+ sender.sendMessage(TextComponent
+ .fromLegacyText("flamecord_reload"));
+ break;
+ }
+ default: {
+ sender.sendMessage(TextComponent.fromLegacyText("flamecord_help"));
+ break;
+ }
+ }
+ } else {
+ sender.sendMessage(TextComponent
+ .fromLegacyText("flamecord_help"));
+ }
+ } else {
+ sender.sendMessage(TextComponent
+ .fromLegacyText("flamecord_nopermission"));
+ }
+ }
+}
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 778fe4a1..9c45f305 100644
--- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
+++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
@@ -9,6 +9,9 @@ import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+
+import dev._2lstudios.flamecord.FlameCord;
+import dev._2lstudios.flamecord.commands.FlameCordCommand;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.github.waterfallmc.waterfall.conf.WaterfallConfiguration;
import io.github.waterfallmc.waterfall.event.ProxyExceptionEvent;
@@ -86,6 +89,12 @@ import net.md_5.bungee.conf.Configuration;
import net.md_5.bungee.conf.YamlConfig;
import net.md_5.bungee.forge.ForgeConstants;
import net.md_5.bungee.module.ModuleManager;
+import net.md_5.bungee.module.cmd.alert.CommandAlert;
+import net.md_5.bungee.module.cmd.find.CommandFind;
+import net.md_5.bungee.module.cmd.list.CommandList;
+import net.md_5.bungee.module.cmd.send.CommandSend;
+import net.md_5.bungee.module.cmd.server.CommandServer;
+import net.md_5.bungee.module.reconnect.yaml.YamlReconnectHandler;
import net.md_5.bungee.netty.PipelineUtils;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;
@@ -225,11 +234,12 @@ public class BungeeCord extends ProxyServer
// Waterfall end
pluginManager = new PluginManager( this );
- getPluginManager().registerCommand( null, new CommandReload() );
- getPluginManager().registerCommand( null, new CommandEnd() );
- getPluginManager().registerCommand( null, new CommandIP() );
- getPluginManager().registerCommand( null, new CommandBungee() );
- getPluginManager().registerCommand( null, new CommandPerms() );
+ // FlameCord - We register commands in our new method
+ //getPluginManager().registerCommand( null, new CommandReload() );
+ //getPluginManager().registerCommand( null, new CommandEnd() );
+ //getPluginManager().registerCommand( null, new CommandIP() );
+ //getPluginManager().registerCommand( null, new CommandBungee() );
+ //getPluginManager().registerCommand( null, new CommandPerms() );
if ( !Boolean.getBoolean( "net.md_5.bungee.native.disable" ) )
{
@@ -278,6 +288,15 @@ public class BungeeCord extends ProxyServer
pluginManager.loadPlugins();
config.load();
+ // FlameCord - Renew and register modules
+ final Collection<String> whitelistedAddresses = new HashSet<>();
+
+ for (final ServerInfo serverInfo : getServers().values()) {
+ whitelistedAddresses.add(serverInfo.getSocketAddress().toString());
+ }
+
+ FlameCord.renew(logger, whitelistedAddresses);
+
if ( config.isForgeSupport() )
{
registerChannel( ForgeConstants.FML_TAG );
@@ -569,9 +588,7 @@ public class BungeeCord extends ProxyServer
String translation = "<translation '" + name + "' missing>";
try
{
- final String string = customBundle != null && customBundle.containsKey( name ) ? customBundle.getString( name ) : baseBundle.getString( name );
-
- translation = ( args.length == 0 ) ? string : MessageFormat.format( string, args );
+ translation = MessageFormat.format( customBundle != null && customBundle.containsKey( name ) ? customBundle.getString( name ) : baseBundle.getString( name ), args );
} catch ( MissingResourceException ex )
{
}
diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
index f5e09292..3e3e42a2 100644
--- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
+++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
@@ -1,6 +1,8 @@
package net.md_5.bungee;
import com.google.common.base.Preconditions;
+
+import dev._2lstudios.flamecord.FlameCord;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import java.net.InetSocketAddress;
@@ -163,7 +165,7 @@ public class ServerConnector extends PacketHandler
{
if ( packet.packet == null )
{
- throw new QuietException( "Unexpected packet received during server login process!\n" + BufUtil.dump( packet.buf, 16 ) );
+ throw new QuietException( "Unexpected packet received during server connector process!\n" + BufUtil.dump(packet.buf, 16) );
}
}
diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
index db79b58a..a847c049 100644
--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java
+++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
@@ -36,6 +36,7 @@ import net.md_5.bungee.api.SkinConfiguration;
import net.md_5.bungee.api.Title;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
+import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PermissionCheckEvent;
@@ -66,6 +67,7 @@ import net.md_5.bungee.tab.ServerUnique;
import net.md_5.bungee.tab.TabList;
import net.md_5.bungee.util.CaseInsensitiveSet;
import net.md_5.bungee.util.ChatComponentTransformer;
+import net.md_5.bungee.util.QuietException;
@RequiredArgsConstructor
public final class UserConnection implements ProxiedPlayer
@@ -390,9 +392,11 @@ public final class UserConnection implements ProxiedPlayer
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, request.getConnectTimeout() )
.remoteAddress( target.getAddress() );
// Windows is bugged, multi homed users will just have to live with random connecting IPs
- if ( getPendingConnection().getListener().isSetLocalAddress() && !PlatformDependent.isWindows() && getPendingConnection().getListener().getSocketAddress() instanceof InetSocketAddress )
+ // FlameCord - Use listenerInfo
+ final ListenerInfo listenerInfo = getPendingConnection().getListener();
+ if ( listenerInfo.isSetLocalAddress() && !PlatformDependent.isWindows() && listenerInfo.getSocketAddress() instanceof InetSocketAddress )
{
- b.localAddress( getPendingConnection().getListener().getHost().getHostString(), 0 );
+ b.localAddress( listenerInfo.getHost().getHostString(), 0 );
}
b.connect().addListener( listener );
}
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java
index dc5b64b7..e88ec72a 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java
@@ -14,6 +14,8 @@ import java.util.logging.Level;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
+import dev._2lstudios.flamecord.FlameCord;
+
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.BungeeCord;
@@ -150,7 +152,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{
if ( packet.packet == null )
{
- throw new QuietException( "Unexpected packet received during login process! " + BufUtil.dump( packet.buf, 16 ) );
+ throw new QuietException( "Unexpected packet received during server login process!\n" + BufUtil.dump(packet.buf, 16) );
}
}
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java
index 6df3f3dd..264c22e8 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java
@@ -1,6 +1,7 @@
package net.md_5.bungee.connection;
import com.google.gson.Gson;
+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.BungeeCord;
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 3bbc1510..4c53e02c 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
@@ -1,6 +1,8 @@
package net.md_5.bungee.netty;
import com.google.common.base.Preconditions;
+
+import dev._2lstudios.flamecord.FlameCord;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.CorruptedFrameException;
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
index 654203ab..a840bc70 100644
--- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
@@ -1,6 +1,8 @@
package net.md_5.bungee.netty;
import com.google.common.base.Preconditions;
+
+import dev._2lstudios.flamecord.FlameCord;
import io.github.waterfallmc.waterfall.event.ConnectionInitEvent;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.Channel;
--
2.32.0.windows.1