Waterfall/Waterfall-Proxy-Patches/0026-Custom-motd-system.patch
Luccboy 2554ec2219
Updated Upstream (Waterfall)
Upstream has released updates that appear 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:
59dbd08 Updated Upstream (BungeeCord) (#747)
9719e25 Temp disable protocol limits for 1.19
9b0080a Fix crash on startup (#743)
958ae29 Updated Upstream (BungeeCord) (#741)
29f1cfb Improve login state transition
a44c78a Various library bumps
2022-06-08 01:19:01 +02:00

205 lines
9.6 KiB
Diff

From d9798110ca3de1602a74372db57a5161cc07c382 Mon Sep 17 00:00:00 2001
From: LinsaFTW <25271111+linsaftw@users.noreply.github.com>
Date: Thu, 7 Oct 2021 21:37:24 -0300
Subject: [PATCH] Custom motd system
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 c327841a..de2cc947 100644
--- a/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/FlameCordConfiguration.java
@@ -3,15 +3,80 @@ package dev._2lstudios.flamecord.configuration;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
+import java.util.List;
+import java.util.Random;
import lombok.Getter;
+import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
public class FlameCordConfiguration extends FlameConfig {
+ private List<String> colors(final List<String> strings) {
+ for (int i = 0; i < strings.size(); i++) {
+ strings.set(i, ChatColor.translateAlternateColorCodes('&', strings.get(i)));
+ }
+
+ return strings;
+ }
+
+ 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[] getSample(final int maxPlayers, final int onlinePlayers) {
+ final String sample = samples.get(new Random().nextInt(samples.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<String> motds = Collections.singletonList("&eDefault &cFlameCord&e custom motd!\n&eChange me in &cflamecord.yml&e file!");
+
+ @Getter
+ private boolean sampleEnabled = false;
+ @Getter
+ private List<String> 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
@@ -36,6 +101,19 @@ public class FlameCordConfiguration extends FlameConfig {
configuration = configurationProvider.load(configurationFile);
}
+ 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);
this.loggerDump = setIfUnexistant("logger.dump", this.loggerDump, 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 477ca39a..e6b5e5da 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
@@ -22,6 +22,8 @@ import javax.crypto.spec.SecretKeySpec;
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;
@@ -252,7 +254,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection
Preconditions.checkState( thisState == State.STATUS, "Not expecting STATUS" );
ServerInfo forced = AbstractReconnectHandler.getForcedHost( this );
- final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd();
final int protocol = ( ProtocolConstants.SUPPORTED_VERSION_IDS.contains( handshake.getProtocolVersion() ) ) ? handshake.getProtocolVersion() : bungee.getProtocolVersion();
Callback<ServerPing> pingBack = new Callback<ServerPing>()
@@ -315,7 +316,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() ? onlinePlayers + 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.36.1.windows.1