diff --git a/src/main/java/com/loohp/limbo/file/ServerProperties.java b/src/main/java/com/loohp/limbo/file/ServerProperties.java index 203f4f1..e44954f 100644 --- a/src/main/java/com/loohp/limbo/file/ServerProperties.java +++ b/src/main/java/com/loohp/limbo/file/ServerProperties.java @@ -1,26 +1,19 @@ package com.loohp.limbo.file; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.Properties; - -import javax.imageio.ImageIO; - import com.loohp.limbo.Limbo; import com.loohp.limbo.location.Location; import com.loohp.limbo.utils.GameMode; import com.loohp.limbo.utils.NamespacedKey; import com.loohp.limbo.world.World; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.Properties; + public class ServerProperties { public static final String COMMENT = "For explaination of what each of the options does, please visit:\nhttps://github.com/LOOHP/Limbo/blob/master/src/main/resources/server.properties"; @@ -40,6 +33,9 @@ public class ServerProperties { private String versionString; private int protocol; private boolean bungeecord; + private boolean velocityModern; + private boolean bungeeGuard; + private String[] forwardingSecrets; private int viewDistance; private double ticksPerSecond; private boolean handshakeVerbose; @@ -91,6 +87,27 @@ public class ServerProperties { motdJson = prop.getProperty("motd"); versionString = prop.getProperty("version"); bungeecord = Boolean.parseBoolean(prop.getProperty("bungeecord")); + velocityModern = Boolean.parseBoolean(prop.getProperty("velocity-modern")); + bungeeGuard = Boolean.parseBoolean(prop.getProperty("bungee-guard")); + if (velocityModern || bungeeGuard) { + String forwardingSecretsStr = prop.getProperty("forwarding-secrets"); + if (forwardingSecretsStr == null || forwardingSecretsStr.equals("")) { + Limbo.getInstance().getConsole().sendMessage("Velocity Modern Forwarding or BungeeGuard is enabled but no forwarding-secret was found!"); + Limbo.getInstance().getConsole().sendMessage("Server will exit!"); + System.exit(1); + return; + } + this.forwardingSecrets = forwardingSecretsStr.split(";"); + if (bungeecord) { + Limbo.getInstance().getConsole().sendMessage("BungeeCord is enabled but so is Velocity Modern Forwarding or BungeeGuard, We will automatically disable BungeeCord forwarding because of this"); + bungeecord = false; + } + if (velocityModern && bungeeGuard) { + Limbo.getInstance().getConsole().sendMessage("Both Velocity Modern Forwarding and BungeeGuard are enabled! Because of this we always prefer Modern Forwarding, disabling BungeeGuard"); + bungeeGuard = false; + } + } + viewDistance = Integer.parseInt(prop.getProperty("view-distance")); ticksPerSecond = Double.parseDouble(prop.getProperty("ticks-per-second")); handshakeVerbose = Boolean.parseBoolean(prop.getProperty("handshake-verbose")); @@ -123,6 +140,18 @@ public class ServerProperties { return bungeecord; } + public boolean isVelocityModern() { + return velocityModern; + } + + public boolean isBungeeGuard() { + return bungeeGuard; + } + + public String[] getForwardingSecrets() { + return forwardingSecrets; + } + public Optional getFavicon() { return favicon; } diff --git a/src/main/java/com/loohp/limbo/server/packets/PacketLoginInPluginMessaging.java b/src/main/java/com/loohp/limbo/server/packets/PacketLoginInPluginMessaging.java index 5e6e166..d0a1582 100644 --- a/src/main/java/com/loohp/limbo/server/packets/PacketLoginInPluginMessaging.java +++ b/src/main/java/com/loohp/limbo/server/packets/PacketLoginInPluginMessaging.java @@ -1,39 +1,39 @@ package com.loohp.limbo.server.packets; +import com.loohp.limbo.utils.DataTypeIO; + import java.io.DataInputStream; import java.io.IOException; -import java.nio.charset.StandardCharsets; - -import com.loohp.limbo.utils.DataTypeIO; -import com.loohp.limbo.utils.NamespacedKey; public class PacketLoginInPluginMessaging extends PacketIn { private int messageId; - private NamespacedKey channel; - private byte[] data; + private boolean successful; + private byte[] data = null; - public PacketLoginInPluginMessaging(int messageId, NamespacedKey channel, byte[] data) { + public PacketLoginInPluginMessaging(int messageId, boolean successful, byte[] data) { this.messageId = messageId; - this.channel = channel; this.data = data; } public PacketLoginInPluginMessaging(DataInputStream in, int packetLength, int packetId) throws IOException { messageId = DataTypeIO.readVarInt(in); - String rawChannel = DataTypeIO.readString(in, StandardCharsets.UTF_8); - channel = new NamespacedKey(rawChannel); - int dataLength = packetLength - DataTypeIO.getVarIntLength(packetId) - DataTypeIO.getVarIntLength(messageId) - DataTypeIO.getStringLength(rawChannel, StandardCharsets.UTF_8); - data = new byte[dataLength]; - in.read(data); + successful = in.readBoolean(); + if (successful) { + int dataLength = packetLength - DataTypeIO.getVarIntLength(packetId) - DataTypeIO.getVarIntLength(messageId) - 1; + if (dataLength != 0) { + data = new byte[dataLength]; + in.readFully(data); + } + } } public int getMessageId() { return messageId; } - public NamespacedKey getChannel() { - return channel; + public boolean isSuccessful() { + return successful; } public byte[] getData() { diff --git a/src/main/java/com/loohp/limbo/server/packets/PacketLoginOutPluginMessaging.java b/src/main/java/com/loohp/limbo/server/packets/PacketLoginOutPluginMessaging.java index a5a890a..bcd0ec3 100644 --- a/src/main/java/com/loohp/limbo/server/packets/PacketLoginOutPluginMessaging.java +++ b/src/main/java/com/loohp/limbo/server/packets/PacketLoginOutPluginMessaging.java @@ -1,19 +1,23 @@ package com.loohp.limbo.server.packets; +import com.loohp.limbo.utils.DataTypeIO; +import com.loohp.limbo.utils.NamespacedKey; + import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; -import com.loohp.limbo.utils.DataTypeIO; -import com.loohp.limbo.utils.NamespacedKey; - public class PacketLoginOutPluginMessaging extends PacketOut { private int messageId; private NamespacedKey channel; private byte[] data; + public PacketLoginOutPluginMessaging(int messageId, NamespacedKey channel) { + this(messageId, channel, null); + } + public PacketLoginOutPluginMessaging(int messageId, NamespacedKey channel, byte[] data) { this.messageId = messageId; this.channel = channel; @@ -40,7 +44,9 @@ public class PacketLoginOutPluginMessaging extends PacketOut { output.writeByte(Packet.getLoginOut().get(getClass())); DataTypeIO.writeVarInt(output, messageId); DataTypeIO.writeString(output, channel.toString(), StandardCharsets.UTF_8); - output.write(data); + if (data != null) { + output.write(data); + } return buffer.toByteArray(); } diff --git a/src/main/java/com/loohp/limbo/utils/DataTypeIO.java b/src/main/java/com/loohp/limbo/utils/DataTypeIO.java index dbf376f..d9f7331 100644 --- a/src/main/java/com/loohp/limbo/utils/DataTypeIO.java +++ b/src/main/java/com/loohp/limbo/utils/DataTypeIO.java @@ -23,6 +23,10 @@ public class DataTypeIO { out.writeLong(uuid.getMostSignificantBits()); out.writeLong(uuid.getLeastSignificantBits()); } + + public static UUID readUUID(DataInputStream in) throws IOException { + return new UUID(in.readLong(), in.readLong()); + } public static void writeCompoundTag(DataOutputStream out, CompoundTag tag) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); diff --git a/src/main/resources/mapping.json b/src/main/resources/mapping.json index 0e1e2a9..76341ff 100644 --- a/src/main/resources/mapping.json +++ b/src/main/resources/mapping.json @@ -9,7 +9,7 @@ "LoginOut": { "PacketLoginOutLoginSuccess": "0x02", "PacketLoginOutDisconnect": "0x00", - "PacketLoginOutPluginMessaging": "0x04", + "PacketLoginOutPluginMessaging": "0x04" }, "PlayIn": { "0x0F": "PacketPlayInKeepAlive", diff --git a/src/main/resources/server.properties b/src/main/resources/server.properties index 6211af4..cc712b1 100644 --- a/src/main/resources/server.properties +++ b/src/main/resources/server.properties @@ -7,9 +7,21 @@ server-port=30000 #Server ip, localhost for local access only server-ip=0.0.0.0 -#Whether this is server is behind a bungeecord proxy +#Whether this server is behind a bungeecord proxy +#Mutually exclusive with velocity-modern and bungee-guard bungeecord=false +#Whether this server is behind a velocity proxy with modern player forwarding +#Mutually exclusive with bungeecord and bungee-guard +velocity-modern=false + +#Whether this server is behind a bungeecord proxy with BungeeGuard installed (velocity can do this too for <1.13) +#Mutually exclusive with bungeecord and velocity-modern +bungee-guard=false + +#For Velocity Modern Forwarding or BungeeGuard a list (separated by `;`) of valid secrets +forwarding-secrets= + #World Name and the Schematic file containing map level-name=world;spawn.schem