From b43b46d1e7cdf0bff17e50a7e00f9f93faf9ee33 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 1 Dec 2013 18:18:41 +1100 Subject: [PATCH] BungeeCord Support Provides support for IP forwarding via BungeeCord. diff --git a/src/main/java/net/minecraft/server/HandshakeListener.java b/src/main/java/net/minecraft/server/HandshakeListener.java index ee987b9..ed20034 100644 --- a/src/main/java/net/minecraft/server/HandshakeListener.java +++ b/src/main/java/net/minecraft/server/HandshakeListener.java @@ -7,6 +7,7 @@ import java.util.HashMap; public class HandshakeListener implements PacketHandshakingInListener { + private static final com.google.gson.Gson gson = new com.google.gson.Gson(); // Spigot // CraftBukkit start - add fields private static final HashMap throttleTracker = new HashMap(); private static int throttleCounter = 0; @@ -71,6 +72,26 @@ public class HandshakeListener implements PacketHandshakingInListener { this.b.close(chatcomponenttext); } else { this.b.setPacketListener(new LoginListener(this.a, this.b)); + // Spigot Start + if (org.spigotmc.SpigotConfig.bungee) { + String[] split = packethandshakinginsetprotocol.hostname.split("\00"); + if ( split.length == 3 || split.length == 4 ) { + packethandshakinginsetprotocol.hostname = split[0]; + b.l = new java.net.InetSocketAddress(split[1], ((java.net.InetSocketAddress) b.getSocketAddress()).getPort()); + b.spoofedUUID = com.mojang.util.UUIDTypeAdapter.fromString( split[2] ); + } else + { + chatcomponenttext = new ChatComponentText("If you wish to use IP forwarding, please enable it in your BungeeCord config as well!"); + this.b.sendPacket(new PacketLoginOutDisconnect(chatcomponenttext)); + this.b.close(chatcomponenttext); + return; + } + if ( split.length == 4 ) + { + b.spoofedProfile = gson.fromJson(split[3], com.mojang.authlib.properties.Property[].class); + } + } + // Spigot End ((LoginListener) this.b.i()).hostname = packethandshakinginsetprotocol.hostname + ":" + packethandshakinginsetprotocol.port; // CraftBukkit - set hostname } break; diff --git a/src/main/java/net/minecraft/server/LoginListener.java b/src/main/java/net/minecraft/server/LoginListener.java index 71d24b2..efa785f 100644 --- a/src/main/java/net/minecraft/server/LoginListener.java +++ b/src/main/java/net/minecraft/server/LoginListener.java @@ -84,9 +84,24 @@ public class LoginListener implements PacketLoginInListener, ITickable { // Spigot start public void initUUID() { - UUID uuid = UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + this.i.getName() ).getBytes( Charsets.UTF_8 ) ); + UUID uuid; + if ( networkManager.spoofedUUID != null ) + { + uuid = networkManager.spoofedUUID; + } else + { + uuid = UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + this.i.getName() ).getBytes( Charsets.UTF_8 ) ); + } this.i = new GameProfile( uuid, this.i.getName() ); + + if (networkManager.spoofedProfile != null) + { + for ( com.mojang.authlib.properties.Property property : networkManager.spoofedProfile ) + { + this.i.getProperties().put( property.getName(), property ); + } + } } // Spigot end diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java index 5ed2c96..c3ff6c2 100644 --- a/src/main/java/net/minecraft/server/NetworkManager.java +++ b/src/main/java/net/minecraft/server/NetworkManager.java @@ -64,7 +64,11 @@ public class NetworkManager extends SimpleChannelInboundHandler> { private final Queue i = Queues.newConcurrentLinkedQueue(); private final ReentrantReadWriteLock j = new ReentrantReadWriteLock(); public Channel channel; - private SocketAddress l; + // Spigot Start // PAIL + public SocketAddress l; + public java.util.UUID spoofedUUID; + public com.mojang.authlib.properties.Property[] spoofedProfile; + // Spigot End private PacketListener m; private IChatBaseComponent n; private boolean o; @@ -323,4 +327,11 @@ public class NetworkManager extends SimpleChannelInboundHandler> { this.b = agenericfuturelistener; } } + + // Spigot Start + public SocketAddress getRawAddress() + { + return this.channel.remoteAddress(); + } + // Spigot End } diff --git a/src/main/java/net/minecraft/server/PacketHandshakingInSetProtocol.java b/src/main/java/net/minecraft/server/PacketHandshakingInSetProtocol.java index 86f1be7..e6ab607 100644 --- a/src/main/java/net/minecraft/server/PacketHandshakingInSetProtocol.java +++ b/src/main/java/net/minecraft/server/PacketHandshakingInSetProtocol.java @@ -13,7 +13,7 @@ public class PacketHandshakingInSetProtocol implements Packet