forked from BLOCKFANTASY/LOOHP-Limbo
Added BungeeGuard behaviour for slightly increased safety from the BungeeGuard plugin
This commit is contained in:
parent
69ef34dc54
commit
b35a2ca54d
|
|
@ -1,5 +1,6 @@
|
||||||
package com.loohp.limbo.file;
|
package com.loohp.limbo.file;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
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;
|
||||||
|
|
@ -10,6 +11,7 @@ import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
@ -35,7 +37,7 @@ public class ServerProperties {
|
||||||
private boolean bungeecord;
|
private boolean bungeecord;
|
||||||
private boolean velocityModern;
|
private boolean velocityModern;
|
||||||
private boolean bungeeGuard;
|
private boolean bungeeGuard;
|
||||||
private String[] forwardingSecrets;
|
private List<String> forwardingSecrets;
|
||||||
private int viewDistance;
|
private int viewDistance;
|
||||||
private double ticksPerSecond;
|
private double ticksPerSecond;
|
||||||
private boolean handshakeVerbose;
|
private boolean handshakeVerbose;
|
||||||
|
|
@ -97,7 +99,7 @@ public class ServerProperties {
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.forwardingSecrets = forwardingSecretsStr.split(";");
|
this.forwardingSecrets = Lists.newArrayList(forwardingSecretsStr.split(";"));
|
||||||
if (bungeecord) {
|
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");
|
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;
|
bungeecord = false;
|
||||||
|
|
@ -148,7 +150,7 @@ public class ServerProperties {
|
||||||
return bungeeGuard;
|
return bungeeGuard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getForwardingSecrets() {
|
public List<String> getForwardingSecrets() {
|
||||||
return forwardingSecrets;
|
return forwardingSecrets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package com.loohp.limbo.server;
|
package com.loohp.limbo.server;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
import com.loohp.limbo.Limbo;
|
import com.loohp.limbo.Limbo;
|
||||||
import com.loohp.limbo.events.player.*;
|
import com.loohp.limbo.events.player.*;
|
||||||
import com.loohp.limbo.events.status.StatusPingEvent;
|
import com.loohp.limbo.events.status.StatusPingEvent;
|
||||||
|
|
@ -19,7 +22,6 @@ import com.loohp.limbo.world.BlockPosition;
|
||||||
import com.loohp.limbo.world.World;
|
import com.loohp.limbo.world.World;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.chat.ComponentSerializer;
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
|
|
||||||
|
|
@ -46,6 +48,7 @@ public class ClientConnection extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
|
private final JsonParser jsonParser = new JsonParser();
|
||||||
|
|
||||||
private final Socket client_socket;
|
private final Socket client_socket;
|
||||||
private boolean running;
|
private boolean running;
|
||||||
|
|
@ -162,6 +165,7 @@ public class ClientConnection extends Thread {
|
||||||
PacketHandshakingIn handshake = new PacketHandshakingIn(input);
|
PacketHandshakingIn handshake = new PacketHandshakingIn(input);
|
||||||
|
|
||||||
boolean isBungeecord = Limbo.getInstance().getServerProperties().isBungeecord();
|
boolean isBungeecord = Limbo.getInstance().getServerProperties().isBungeecord();
|
||||||
|
boolean isBungeeGuard = Limbo.getInstance().getServerProperties().isBungeeGuard();
|
||||||
boolean isVelocityModern = Limbo.getInstance().getServerProperties().isVelocityModern();
|
boolean isVelocityModern = Limbo.getInstance().getServerProperties().isVelocityModern();
|
||||||
String bungeeForwarding = handshake.getServerAddress();
|
String bungeeForwarding = handshake.getServerAddress();
|
||||||
UUID bungeeUUID = null;
|
UUID bungeeUUID = null;
|
||||||
|
|
@ -197,7 +201,7 @@ public class ClientConnection extends Thread {
|
||||||
case LOGIN:
|
case LOGIN:
|
||||||
state = ClientState.LOGIN;
|
state = ClientState.LOGIN;
|
||||||
|
|
||||||
if (isBungeecord) {
|
if (isBungeecord || isBungeeGuard) {
|
||||||
try {
|
try {
|
||||||
String[] data = bungeeForwarding.split("\\x00");
|
String[] data = bungeeForwarding.split("\\x00");
|
||||||
//String host = data[0];
|
//String host = data[0];
|
||||||
|
|
@ -205,14 +209,27 @@ public class ClientConnection extends Thread {
|
||||||
|
|
||||||
bungeeUUID = UUID.fromString(data[2].replaceFirst("([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)", "$1-$2-$3-$4-$5"));
|
bungeeUUID = UUID.fromString(data[2].replaceFirst("([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)", "$1-$2-$3-$4-$5"));
|
||||||
inetAddress = InetAddress.getByName(ip);
|
inetAddress = InetAddress.getByName(ip);
|
||||||
|
|
||||||
|
boolean bungeeGuardFound = false;
|
||||||
if (data.length > 3) {
|
if (data.length > 3) {
|
||||||
String skinJson = data[3];
|
JsonArray skinJson = this.jsonParser.parse(data[3]).getAsJsonArray();
|
||||||
|
|
||||||
String skin = skinJson.split("\"value\":\"")[1].split("\"")[0];
|
for (JsonElement property : skinJson) {
|
||||||
String signature = skinJson.split("\"signature\":\"")[1].split("\"")[0];
|
if (property.getAsJsonObject().get("name").getAsString().equals("textures")) {
|
||||||
forwardedSkin = new SkinResponse(skin, signature);
|
String skin = property.getAsJsonObject().get("value").getAsString();
|
||||||
|
String signature = property.getAsJsonObject().get("signature").getAsString();
|
||||||
|
forwardedSkin = new SkinResponse(skin, signature);
|
||||||
|
} else if (isBungeeGuard && property.getAsJsonObject().get("name").getAsString().equals("bungeeguard-token")) {
|
||||||
|
String token = property.getAsJsonObject().get("value").getAsString();
|
||||||
|
bungeeGuardFound = Limbo.getInstance().getServerProperties().getForwardingSecrets().contains(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isBungeeGuard && !bungeeGuardFound) {
|
||||||
|
disconnectDuringLogin(TextComponent.fromLegacyText("Invalid information forwarding"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Limbo.getInstance().getConsole().sendMessage("If you wish to use bungeecord's IP forwarding, please enable that in your bungeecord config.yml as well!");
|
Limbo.getInstance().getConsole().sendMessage("If you wish to use bungeecord's IP forwarding, please enable that in your bungeecord config.yml as well!");
|
||||||
disconnectDuringLogin(new BaseComponent[] {new TextComponent(ChatColor.RED + "Please connect from the proxy!")});
|
disconnectDuringLogin(new BaseComponent[] {new TextComponent(ChatColor.RED + "Please connect from the proxy!")});
|
||||||
|
|
@ -237,7 +254,7 @@ public class ClientConnection extends Thread {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID uuid = isBungeecord ? bungeeUUID : UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(StandardCharsets.UTF_8));
|
UUID uuid = isBungeecord || isBungeeGuard ? bungeeUUID : UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
PacketLoginOutLoginSuccess success = new PacketLoginOutLoginSuccess(uuid, username);
|
PacketLoginOutLoginSuccess success = new PacketLoginOutLoginSuccess(uuid, username);
|
||||||
sendPacket(success);
|
sendPacket(success);
|
||||||
|
|
@ -253,15 +270,15 @@ public class ClientConnection extends Thread {
|
||||||
PacketLoginInPluginMessaging response = new PacketLoginInPluginMessaging(input, size, packetId);
|
PacketLoginInPluginMessaging response = new PacketLoginInPluginMessaging(input, size, packetId);
|
||||||
if (response.getMessageId() != messageId) {
|
if (response.getMessageId() != messageId) {
|
||||||
disconnectDuringLogin(TextComponent.fromLegacyText("Internal error, messageId did not match"));
|
disconnectDuringLogin(TextComponent.fromLegacyText("Internal error, messageId did not match"));
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
if (response.getData() == null) {
|
if (response.getData() == null) {
|
||||||
disconnectDuringLogin(TextComponent.fromLegacyText("Unknown login plugin response packet!"));
|
disconnectDuringLogin(TextComponent.fromLegacyText("Unknown login plugin response packet!"));
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
if (!ForwardingUtils.validateVelocityModernResponse(response.getData())) {
|
if (!ForwardingUtils.validateVelocityModernResponse(response.getData())) {
|
||||||
disconnectDuringLogin(TextComponent.fromLegacyText("Invalid playerinfo forwarding!"));
|
disconnectDuringLogin(TextComponent.fromLegacyText("Invalid playerinfo forwarding!"));
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
ForwardingUtils.VelocityModernForwardingData data = ForwardingUtils.getVelocityDataFrom(response.getData());
|
ForwardingUtils.VelocityModernForwardingData data = ForwardingUtils.getVelocityDataFrom(response.getData());
|
||||||
inetAddress = InetAddress.getByName(data.getIpAddress());
|
inetAddress = InetAddress.getByName(data.getIpAddress());
|
||||||
|
|
@ -310,7 +327,7 @@ public class ClientConnection extends Thread {
|
||||||
sendPacket(join);
|
sendPacket(join);
|
||||||
Limbo.getInstance().getUnsafe().setPlayerGameModeSilently(player, properties.getDefaultGamemode());
|
Limbo.getInstance().getUnsafe().setPlayerGameModeSilently(player, properties.getDefaultGamemode());
|
||||||
|
|
||||||
SkinResponse skinresponce = (isVelocityModern || isBungeecord) && forwardedSkin != null ? forwardedSkin : MojangAPIUtils.getSkinFromMojangServer(player.getName());
|
SkinResponse skinresponce = (isVelocityModern || isBungeeGuard || isBungeecord) && forwardedSkin != null ? forwardedSkin : MojangAPIUtils.getSkinFromMojangServer(player.getName());
|
||||||
PlayerSkinProperty skin = skinresponce != null ? new PlayerSkinProperty(skinresponce.getSkin(), skinresponce.getSignature()) : null;
|
PlayerSkinProperty skin = skinresponce != null ? new PlayerSkinProperty(skinresponce.getSkin(), skinresponce.getSignature()) : null;
|
||||||
PacketPlayOutPlayerInfo info = new PacketPlayOutPlayerInfo(PlayerInfoAction.ADD_PLAYER, player.getUniqueId(), new PlayerInfoData.PlayerInfoDataAddPlayer(player.getName(), Optional.ofNullable(skin), properties.getDefaultGamemode(), 0, false, Optional.empty()));
|
PacketPlayOutPlayerInfo info = new PacketPlayOutPlayerInfo(PlayerInfoAction.ADD_PLAYER, player.getUniqueId(), new PlayerInfoData.PlayerInfoDataAddPlayer(player.getName(), Optional.ofNullable(skin), properties.getDefaultGamemode(), 0, false, Optional.empty()));
|
||||||
sendPacket(info);
|
sendPacket(info);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue