forked from BLOCKFANTASY/LOOHP-Limbo
Added new Server Properties and cleaned up Login Plugin Packets
- Added option for Modern Forwarding and BungeeGuard (for proxies that are connected to older servers) - Made Modern, Bungeecord and Bungeeguard mutually exclusive - Fixed PacketLoginInPluginMessaging, structure was incorrect - Added `readUUID` in DataTypeIO
This commit is contained in:
parent
7be0b5f9da
commit
c7378beb2b
|
|
@ -1,26 +1,19 @@
|
||||||
package com.loohp.limbo.file;
|
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.Limbo;
|
||||||
import com.loohp.limbo.location.Location;
|
import com.loohp.limbo.location.Location;
|
||||||
import com.loohp.limbo.utils.GameMode;
|
import com.loohp.limbo.utils.GameMode;
|
||||||
import com.loohp.limbo.utils.NamespacedKey;
|
import com.loohp.limbo.utils.NamespacedKey;
|
||||||
import com.loohp.limbo.world.World;
|
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 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";
|
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 String versionString;
|
||||||
private int protocol;
|
private int protocol;
|
||||||
private boolean bungeecord;
|
private boolean bungeecord;
|
||||||
|
private boolean velocityModern;
|
||||||
|
private boolean bungeeGuard;
|
||||||
|
private String[] forwardingSecrets;
|
||||||
private int viewDistance;
|
private int viewDistance;
|
||||||
private double ticksPerSecond;
|
private double ticksPerSecond;
|
||||||
private boolean handshakeVerbose;
|
private boolean handshakeVerbose;
|
||||||
|
|
@ -91,6 +87,27 @@ public class ServerProperties {
|
||||||
motdJson = prop.getProperty("motd");
|
motdJson = prop.getProperty("motd");
|
||||||
versionString = prop.getProperty("version");
|
versionString = prop.getProperty("version");
|
||||||
bungeecord = Boolean.parseBoolean(prop.getProperty("bungeecord"));
|
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"));
|
viewDistance = Integer.parseInt(prop.getProperty("view-distance"));
|
||||||
ticksPerSecond = Double.parseDouble(prop.getProperty("ticks-per-second"));
|
ticksPerSecond = Double.parseDouble(prop.getProperty("ticks-per-second"));
|
||||||
handshakeVerbose = Boolean.parseBoolean(prop.getProperty("handshake-verbose"));
|
handshakeVerbose = Boolean.parseBoolean(prop.getProperty("handshake-verbose"));
|
||||||
|
|
@ -123,6 +140,18 @@ public class ServerProperties {
|
||||||
return bungeecord;
|
return bungeecord;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isVelocityModern() {
|
||||||
|
return velocityModern;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBungeeGuard() {
|
||||||
|
return bungeeGuard;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getForwardingSecrets() {
|
||||||
|
return forwardingSecrets;
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<BufferedImage> getFavicon() {
|
public Optional<BufferedImage> getFavicon() {
|
||||||
return favicon;
|
return favicon;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,39 @@
|
||||||
package com.loohp.limbo.server.packets;
|
package com.loohp.limbo.server.packets;
|
||||||
|
|
||||||
|
import com.loohp.limbo.utils.DataTypeIO;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
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 {
|
public class PacketLoginInPluginMessaging extends PacketIn {
|
||||||
|
|
||||||
private int messageId;
|
private int messageId;
|
||||||
private NamespacedKey channel;
|
private boolean successful;
|
||||||
private byte[] data;
|
private byte[] data = null;
|
||||||
|
|
||||||
public PacketLoginInPluginMessaging(int messageId, NamespacedKey channel, byte[] data) {
|
public PacketLoginInPluginMessaging(int messageId, boolean successful, byte[] data) {
|
||||||
this.messageId = messageId;
|
this.messageId = messageId;
|
||||||
this.channel = channel;
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketLoginInPluginMessaging(DataInputStream in, int packetLength, int packetId) throws IOException {
|
public PacketLoginInPluginMessaging(DataInputStream in, int packetLength, int packetId) throws IOException {
|
||||||
messageId = DataTypeIO.readVarInt(in);
|
messageId = DataTypeIO.readVarInt(in);
|
||||||
String rawChannel = DataTypeIO.readString(in, StandardCharsets.UTF_8);
|
successful = in.readBoolean();
|
||||||
channel = new NamespacedKey(rawChannel);
|
if (successful) {
|
||||||
int dataLength = packetLength - DataTypeIO.getVarIntLength(packetId) - DataTypeIO.getVarIntLength(messageId) - DataTypeIO.getStringLength(rawChannel, StandardCharsets.UTF_8);
|
int dataLength = packetLength - DataTypeIO.getVarIntLength(packetId) - DataTypeIO.getVarIntLength(messageId) - 1;
|
||||||
|
if (dataLength != 0) {
|
||||||
data = new byte[dataLength];
|
data = new byte[dataLength];
|
||||||
in.read(data);
|
in.readFully(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMessageId() {
|
public int getMessageId() {
|
||||||
return messageId;
|
return messageId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NamespacedKey getChannel() {
|
public boolean isSuccessful() {
|
||||||
return channel;
|
return successful;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getData() {
|
public byte[] getData() {
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,23 @@
|
||||||
package com.loohp.limbo.server.packets;
|
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.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import com.loohp.limbo.utils.DataTypeIO;
|
|
||||||
import com.loohp.limbo.utils.NamespacedKey;
|
|
||||||
|
|
||||||
public class PacketLoginOutPluginMessaging extends PacketOut {
|
public class PacketLoginOutPluginMessaging extends PacketOut {
|
||||||
|
|
||||||
private int messageId;
|
private int messageId;
|
||||||
private NamespacedKey channel;
|
private NamespacedKey channel;
|
||||||
private byte[] data;
|
private byte[] data;
|
||||||
|
|
||||||
|
public PacketLoginOutPluginMessaging(int messageId, NamespacedKey channel) {
|
||||||
|
this(messageId, channel, null);
|
||||||
|
}
|
||||||
|
|
||||||
public PacketLoginOutPluginMessaging(int messageId, NamespacedKey channel, byte[] data) {
|
public PacketLoginOutPluginMessaging(int messageId, NamespacedKey channel, byte[] data) {
|
||||||
this.messageId = messageId;
|
this.messageId = messageId;
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
|
|
@ -40,7 +44,9 @@ public class PacketLoginOutPluginMessaging extends PacketOut {
|
||||||
output.writeByte(Packet.getLoginOut().get(getClass()));
|
output.writeByte(Packet.getLoginOut().get(getClass()));
|
||||||
DataTypeIO.writeVarInt(output, messageId);
|
DataTypeIO.writeVarInt(output, messageId);
|
||||||
DataTypeIO.writeString(output, channel.toString(), StandardCharsets.UTF_8);
|
DataTypeIO.writeString(output, channel.toString(), StandardCharsets.UTF_8);
|
||||||
|
if (data != null) {
|
||||||
output.write(data);
|
output.write(data);
|
||||||
|
}
|
||||||
|
|
||||||
return buffer.toByteArray();
|
return buffer.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,10 @@ public class DataTypeIO {
|
||||||
out.writeLong(uuid.getLeastSignificantBits());
|
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 {
|
public static void writeCompoundTag(DataOutputStream out, CompoundTag tag) throws IOException {
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
"LoginOut": {
|
"LoginOut": {
|
||||||
"PacketLoginOutLoginSuccess": "0x02",
|
"PacketLoginOutLoginSuccess": "0x02",
|
||||||
"PacketLoginOutDisconnect": "0x00",
|
"PacketLoginOutDisconnect": "0x00",
|
||||||
"PacketLoginOutPluginMessaging": "0x04",
|
"PacketLoginOutPluginMessaging": "0x04"
|
||||||
},
|
},
|
||||||
"PlayIn": {
|
"PlayIn": {
|
||||||
"0x0F": "PacketPlayInKeepAlive",
|
"0x0F": "PacketPlayInKeepAlive",
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,21 @@ server-port=30000
|
||||||
#Server ip, localhost for local access only
|
#Server ip, localhost for local access only
|
||||||
server-ip=0.0.0.0
|
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
|
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
|
#World Name and the Schematic file containing map
|
||||||
level-name=world;spawn.schem
|
level-name=world;spawn.schem
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue