diff --git a/Waterfall-Proxy-Patches/0033-More-features-for-custom-motd.patch b/Waterfall-Proxy-Patches/0033-More-features-for-custom-motd.patch new file mode 100644 index 0000000..124a0a3 --- /dev/null +++ b/Waterfall-Proxy-Patches/0033-More-features-for-custom-motd.patch @@ -0,0 +1,205 @@ +From 28d1948625c40a66e5a22557dd1fd1e56af893ad Mon Sep 17 00:00:00 2001 +From: HakanGulgen +Date: Fri, 18 Mar 2022 15:18:09 +0300 +Subject: [PATCH] More features for custom motd. + + +diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameConfig.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameConfig.java +index cfbd55c3..360305b9 100644 +--- a/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameConfig.java ++++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameConfig.java +@@ -11,6 +11,10 @@ public class FlameConfig { + return (int) setIfUnexistant(arg1, (Object) arg2, configuration); + } + ++ String setIfUnexistant(final String arg1, final String arg2, final Configuration configuration) { ++ return (String) setIfUnexistant(arg1, (Object) arg2, configuration); ++ } ++ + boolean setIfUnexistant(final String arg1, final boolean arg2, final Configuration configuration) { + return (boolean) setIfUnexistant(arg1, (Object) arg2, configuration); + } +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 be49f581..929b37ea 100644 +--- a/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java ++++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java +@@ -2,11 +2,7 @@ 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.List; +-import java.util.Random; ++import java.util.*; + + import lombok.Getter; + import net.md_5.bungee.api.ChatColor; +@@ -138,16 +134,59 @@ public class FlameCordConfiguration extends FlameConfig { + return strings; + } + +- @Getter +- private boolean customMotdEnabled = false; +- private List customMotdMotds = Arrays.asList(new String[] { "&eDefault &cFlameCord&e custom motd!\n&eChange me in &cflamecord.yml&e file!" }); ++ public String getMOTD(final int maxPlayers, final int onlinePlayers) { ++ final String motd = motds.get(new Random().nextInt(motds.size())); ++ ++ return motd.replace("%maxplayers%", String.valueOf(maxPlayers)).replace("%onlineplayers%", String.valueOf(onlinePlayers)); ++ } + +- public String getRandomMotd() { +- final Random random = new Random(); ++ public String[] getSample(final int maxPlayers, final int onlinePlayers) { ++ final String sample = samples.get(new Random().nextInt(samples.size())); + +- return customMotdMotds.get(random.nextInt(customMotdMotds.size())); ++ return sample.replace("%maxplayers%", String.valueOf(maxPlayers)).replace("%onlineplayers%", String.valueOf(onlinePlayers)).split("\n"); ++ } ++ ++ public int getFakePlayersAmount(final int players) { ++ switch (fakePlayersMode) { ++ case "STATIC": ++ return fakePlayersAmount; ++ case "RANDOM": ++ return (int) (Math.floor(Math.random() * fakePlayersAmount) + 1); ++ case "DIVISION": ++ return players / fakePlayersAmount; ++ default: ++ return 0; ++ } + } + ++ @Getter ++ private boolean motdEnabled = false; ++ @Getter ++ private List motds = Collections.singletonList("&eDefault &cFlameCord&e custom motd!\n&eChange me in &cflamecord.yml&e file!"); ++ ++ @Getter ++ private boolean sampleEnabled = false; ++ @Getter ++ private List samples = Collections.singletonList("&eDefault &cFlameCord&e sample!\n&eChange me in &cflamecord.yml&e file!"); ++ ++ @Getter ++ private boolean protocolEnabled = false; ++ @Getter ++ private String protocolName = "FlameCord 1.7-1.18"; ++ ++ @Getter ++ private boolean maxPlayersEnabled = false; ++ @Getter ++ private int maxPlayersAmount = 1000; ++ @Getter ++ private boolean maxPlayersOneMore = false; ++ ++ @Getter ++ private boolean fakePlayersEnabled = false; ++ @Getter ++ private int fakePlayersAmount = 3; ++ private String fakePlayersMode = "DIVISION"; ++ + @Getter + private boolean loggerInitialhandler = false; + @Getter +@@ -176,8 +215,18 @@ public class FlameCordConfiguration extends FlameConfig { + + this.tcpFastOpen = setIfUnexistant("tcp-fast-open", this.tcpFastOpen, configuration); + +- this.customMotdEnabled = setIfUnexistant("custom-motd.enabled", this.customMotdEnabled, configuration); +- this.customMotdMotds = colors(new ArrayList<>(setIfUnexistant("custom-motd.motds", this.customMotdMotds, configuration))); ++ this.motdEnabled = setIfUnexistant("custom-motd.motd.enabled", this.motdEnabled, configuration); ++ this.motds = colors(new ArrayList<>(setIfUnexistant("custom-motd.motd.motds", this.motds, configuration))); ++ this.sampleEnabled = setIfUnexistant("custom-motd.sample.enabled", this.sampleEnabled, configuration); ++ this.samples = colors(new ArrayList<>(setIfUnexistant("custom-motd.sample.samples", this.samples, configuration))); ++ this.protocolEnabled = setIfUnexistant("custom-motd.protocol.enabled", this.protocolEnabled, configuration); ++ this.protocolName = setIfUnexistant("custom-motd.protocol.name", this.protocolName, configuration); ++ this.maxPlayersEnabled = setIfUnexistant("custom-motd.maxplayers.enabled", this.maxPlayersEnabled, configuration); ++ this.maxPlayersAmount = setIfUnexistant("custom-motd.maxplayers.amount", this.maxPlayersAmount, configuration); ++ this.maxPlayersOneMore = setIfUnexistant("custom-motd.maxplayers.justonemore", this.maxPlayersOneMore, configuration); ++ this.fakePlayersEnabled = setIfUnexistant("custom-motd.fakeplayers.enabled", this.fakePlayersEnabled, configuration); ++ this.fakePlayersAmount = setIfUnexistant("custom-motd.fakeplayers.amount", this.fakePlayersAmount, configuration); ++ this.fakePlayersMode = setIfUnexistant("custom-motd.fakeplayers.mode", this.fakePlayersMode, configuration); + + this.loggerInitialhandler = setIfUnexistant("logger.initialhandler", this.loggerInitialhandler, configuration); + this.loggerExceptions = setIfUnexistant("logger.exceptions", this.loggerExceptions, configuration); +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 b6cd7e4b..c82098a1 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 +@@ -23,6 +23,8 @@ import dev._2lstudios.antibot.AddressData; + import dev._2lstudios.antibot.CheckManager; + import dev._2lstudios.flamecord.FlameCord; + ++import dev._2lstudios.flamecord.configuration.FlameConfig; ++import dev._2lstudios.flamecord.configuration.FlameCordConfiguration; + import lombok.Getter; + import lombok.RequiredArgsConstructor; + import net.md_5.bungee.BungeeCord; +@@ -253,9 +255,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection + thisState = State.PROCESSING; + + ServerInfo forced = AbstractReconnectHandler.getForcedHost( this ); +- // FlameCord - Custom motd +- final String listenerMotd = FlameCord.getInstance().getFlameCordConfiguration().isCustomMotdEnabled() ? FlameCord.getInstance().getFlameCordConfiguration().getRandomMotd() : listener.getMotd(); +- final String motd = ( forced != null ) ? forced.getMotd() : listenerMotd; + final int protocol = ( ProtocolConstants.SUPPORTED_VERSION_IDS.contains( handshake.getProtocolVersion() ) ) ? handshake.getProtocolVersion() : bungee.getProtocolVersion(); + + Callback pingBack = new Callback() +@@ -318,7 +317,52 @@ public class InitialHandler extends PacketHandler implements PendingConnection + ( (BungeeServerInfo) forced ).ping( pingBack, handshake.getProtocolVersion() ); + } else + { +- pingBack.done( getPingInfo( motd, protocol ), null ); ++ // FlameCord - Custom MOTD ++ final FlameCordConfiguration config = FlameCord.getInstance().getFlameCordConfiguration(); ++ ++ String motd; ++ String protocolName; ++ ++ ServerPing.PlayerInfo[] sample = null; ++ ++ int maxPlayers = listener.getMaxPlayers(); ++ int onlinePlayers = bungee.getOnlineCount(); ++ ++ if (config.isFakePlayersEnabled()) { ++ onlinePlayers += config.getFakePlayersAmount(onlinePlayers); ++ } ++ ++ if (config.isMaxPlayersEnabled()) { ++ maxPlayers = config.isMaxPlayersOneMore() ? maxPlayers + 1 : config.getMaxPlayersAmount(); ++ } ++ ++ if (config.isMotdEnabled()) { ++ motd = config.getMOTD(maxPlayers, onlinePlayers); ++ } else { ++ motd = ( forced != null ) ? forced.getMotd() : listener.getMotd(); ++ } ++ ++ if (config.isProtocolEnabled()) { ++ protocolName = config.getProtocolName(); ++ } else { ++ protocolName = bungee.getName() + " " + bungee.getGameVersion(); ++ } ++ ++ if (config.isSampleEnabled()) { ++ final UUID fakeUuid = new UUID(0, 0); ++ final String[] sampleString = config.getSample(maxPlayers, onlinePlayers); ++ ++ sample = new ServerPing.PlayerInfo[sampleString.length]; ++ ++ for (int i = 0; i < sampleString.length; i++) { ++ sample[i] = new ServerPing.PlayerInfo(sampleString[i], fakeUuid); ++ } ++ } ++ ++ pingBack.done( new ServerPing( ++ new ServerPing.Protocol( protocolName, protocol ), ++ new ServerPing.Players( maxPlayers, onlinePlayers, sample ), ++ motd, BungeeCord.getInstance().config.getFaviconObject() ), null ); + } + + thisState = State.PING; +-- +2.35.1.windows.2 +