2014-06-22 09:25:10 +00:00
From 56e3bbd8f04384743c0661bfd79b8e45e2a5b515 Mon Sep 17 00:00:00 2001
2014-04-12 04:18:37 +00:00
From: md_5 <md_5@live.com.au>
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
2014-04-14 01:41:45 +00:00
index b98079c..ee24038 100644
2014-04-12 04:18:37 +00:00
--- a/src/main/java/net/minecraft/server/HandshakeListener.java
+++ b/src/main/java/net/minecraft/server/HandshakeListener.java
2014-04-14 01:41:45 +00:00
@@ -1,14 +1,17 @@
package net.minecraft.server;
+import net.minecraft.util.com.mojang.authlib.properties.Property; // Spigot
import net.minecraft.util.io.netty.util.concurrent.GenericFutureListener;
2014-04-12 04:38:17 +00:00
// CraftBukkit start
import java.net.InetAddress;
import java.util.HashMap;
+import net.minecraft.util.com.mojang.util.UUIDTypeAdapter;
// CraftBukkit end
public class HandshakeListener implements PacketHandshakingInListener {
2014-04-14 01:41:45 +00:00
+ private static final com.google.gson.Gson gson = new com.google.gson.Gson(); // Spigot
// CraftBukkit start - add fields
private static final HashMap<InetAddress, Long> throttleTracker = new HashMap<InetAddress, Long>();
private static int throttleCounter = 0;
@@ -73,6 +76,26 @@ public class HandshakeListener implements PacketHandshakingInListener {
2014-04-12 04:18:37 +00:00
this.b.close(chatcomponenttext);
} else {
this.b.a((PacketListener) (new LoginListener(this.a, this.b)));
+ // Spigot Start
+ if (org.spigotmc.SpigotConfig.bungee) {
+ String[] split = packethandshakinginsetprotocol.b.split("\00");
2014-04-14 01:41:45 +00:00
+ if ( split.length == 3 || split.length == 4 ) {
2014-04-12 04:18:37 +00:00
+ packethandshakinginsetprotocol.b = split[0];
+ b.n = new java.net.InetSocketAddress(split[1], ((java.net.InetSocketAddress) b.getSocketAddress()).getPort());
2014-04-12 04:38:17 +00:00
+ b.spoofedUUID = UUIDTypeAdapter.fromString( split[2] );
2014-04-12 04:18:37 +00:00
+ } else
+ {
+ chatcomponenttext = new ChatComponentText("If you wish to use IP forwarding, please enable it in your BungeeCord config as well!");
+ this.b.handle(new PacketLoginOutDisconnect(chatcomponenttext), new GenericFutureListener[0]);
+ this.b.close(chatcomponenttext);
+ return;
+ }
2014-04-14 01:41:45 +00:00
+ if ( split.length == 4 )
+ {
+ b.spoofedProfile = gson.fromJson(split[3], Property[].class);
+ }
2014-04-12 04:18:37 +00:00
+ }
+ // Spigot End
((LoginListener) this.b.getPacketListener()).hostname = packethandshakinginsetprotocol.b + ":" + packethandshakinginsetprotocol.c; // CraftBukkit - set hostname
}
break;
diff --git a/src/main/java/net/minecraft/server/LoginListener.java b/src/main/java/net/minecraft/server/LoginListener.java
2014-04-14 01:41:45 +00:00
index 0755d36..e380a70 100644
2014-04-12 04:18:37 +00:00
--- a/src/main/java/net/minecraft/server/LoginListener.java
+++ b/src/main/java/net/minecraft/server/LoginListener.java
2014-04-14 01:41:45 +00:00
@@ -9,6 +9,7 @@ import javax.crypto.SecretKey;
import net.minecraft.util.com.google.common.base.Charsets;
import net.minecraft.util.com.mojang.authlib.GameProfile;
+import net.minecraft.util.com.mojang.authlib.properties.Property;
import net.minecraft.util.io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.util.org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.LogManager;
@@ -62,9 +63,24 @@ public class LoginListener implements PacketLoginInListener {
2014-04-12 04:18:37 +00:00
// Spigot start
public void initUUID()
{
2014-04-12 04:38:17 +00:00
- UUID uuid = UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + this.i.getName() ).getBytes( Charsets.UTF_8 ) );
+ UUID uuid;
2014-04-12 04:18:37 +00:00
+ if ( networkManager.spoofedUUID != null )
+ {
+ uuid = networkManager.spoofedUUID;
+ } else
+ {
2014-04-12 04:38:17 +00:00
+ uuid = UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + this.i.getName() ).getBytes( Charsets.UTF_8 ) );
2014-04-12 04:18:37 +00:00
+ }
2014-04-12 04:38:17 +00:00
2014-04-12 04:18:37 +00:00
this.i = new GameProfile( uuid, this.i.getName() );
2014-04-14 01:41:45 +00:00
+
+ if (networkManager.spoofedProfile != null)
+ {
+ for ( Property property : networkManager.spoofedProfile )
+ {
+ this.i.getProperties().put( property.getName(), property );
+ }
+ }
2014-04-12 04:18:37 +00:00
}
2014-04-14 01:41:45 +00:00
// Spigot end
2014-04-12 04:18:37 +00:00
diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
2014-04-17 19:47:40 +00:00
index 1b080c7..31d6008 100644
2014-04-12 04:18:37 +00:00
--- a/src/main/java/net/minecraft/server/NetworkManager.java
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
2014-04-14 01:41:45 +00:00
@@ -6,6 +6,7 @@ import javax.crypto.SecretKey;
import net.minecraft.util.com.google.common.collect.Queues;
import net.minecraft.util.com.google.common.util.concurrent.ThreadFactoryBuilder;
+import net.minecraft.util.com.mojang.authlib.properties.Property;
import net.minecraft.util.io.netty.channel.Channel;
import net.minecraft.util.io.netty.channel.ChannelFutureListener;
import net.minecraft.util.io.netty.channel.ChannelHandlerContext;
2014-04-17 19:47:40 +00:00
@@ -37,7 +38,11 @@ public class NetworkManager extends SimpleChannelInboundHandler {
2014-04-12 04:18:37 +00:00
private final Queue k = Queues.newConcurrentLinkedQueue();
private final Queue l = Queues.newConcurrentLinkedQueue();
private Channel m;
- private SocketAddress n;
2014-04-14 01:41:45 +00:00
+ // Spigot Start
+ public SocketAddress n;
+ public java.util.UUID spoofedUUID;
+ public Property[] spoofedProfile;
+ // Spigot End
2014-04-12 04:18:37 +00:00
private PacketListener o;
private EnumProtocol p;
private IChatBaseComponent q;
2014-04-17 19:47:40 +00:00
@@ -207,4 +212,11 @@ public class NetworkManager extends SimpleChannelInboundHandler {
2014-04-12 04:18:37 +00:00
static Channel a(NetworkManager networkmanager) {
return networkmanager.m;
}
+
+ // Spigot Start
+ public SocketAddress getRawAddress()
+ {
+ return this.m.remoteAddress();
+ }
+ // Spigot End
}
2014-04-14 01:41:45 +00:00
diff --git a/src/main/java/net/minecraft/server/PacketHandshakingInSetProtocol.java b/src/main/java/net/minecraft/server/PacketHandshakingInSetProtocol.java
index 16d4765..39692ee 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 extends Packet {
public void a(PacketDataSerializer packetdataserializer) throws IOException { // CraftBukkit - added throws
this.a = packetdataserializer.a();
- this.b = packetdataserializer.c(255);
+ this.b = packetdataserializer.c(Short.MAX_VALUE); // Spigot
this.c = packetdataserializer.readUnsignedShort();
this.d = EnumProtocol.a(packetdataserializer.a());
}
2014-04-12 04:18:37 +00:00
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
2014-04-17 19:47:40 +00:00
index 4c5d77e..cd9a8f5 100644
2014-04-12 04:18:37 +00:00
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
@@ -350,7 +350,7 @@ public abstract class PlayerList {
EntityPlayer entity = new EntityPlayer(this.server, this.server.getWorldServer(0), gameprofile, new PlayerInteractManager(this.server.getWorldServer(0)));
Player player = entity.getBukkitEntity();
- PlayerLoginEvent event = new PlayerLoginEvent(player, hostname, ((java.net.InetSocketAddress) socketaddress).getAddress());
+ PlayerLoginEvent event = new PlayerLoginEvent(player, hostname, ((java.net.InetSocketAddress) socketaddress).getAddress(), ((java.net.InetSocketAddress) loginlistener.networkManager.getRawAddress()).getAddress());
String s;
2014-04-17 19:47:40 +00:00
if (this.j.isBanned(gameprofile) && !this.j.get(gameprofile).e()) { // Should be hasExpired
2014-05-06 06:10:35 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2014-05-14 13:02:09 +00:00
index 73d92fd..4c13657 100644
2014-05-06 06:10:35 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2014-05-14 13:02:09 +00:00
@@ -646,7 +646,13 @@ public final class CraftServer implements Server {
2014-05-06 06:10:35 +00:00
}
public long getConnectionThrottle() {
- return this.configuration.getInt("settings.connection-throttle");
+ // Spigot Start - Automatically set connection throttle for bungee configurations
+ if (org.spigotmc.SpigotConfig.bungee) {
+ return -1;
+ } else {
+ return this.configuration.getInt("settings.connection-throttle");
+ }
+ // Spigot End
}
public int getTicksPerAnimalSpawns() {
2014-04-12 04:18:37 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2014-06-22 09:25:10 +00:00
index 7d16bab..c0a0b43 100644
2014-04-12 04:18:37 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1299,6 +1299,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
{
@Override
+ public InetSocketAddress getRawAddress()
+ {
+ return (InetSocketAddress) getHandle().playerConnection.networkManager.getRawAddress();
+ }
+
+ @Override
public boolean getCollidesWithEntities()
{
return getHandle().collidesWithEntities;
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
index 2b499fe..8bfffa5 100644
--- a/src/main/java/org/spigotmc/SpigotConfig.java
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
@@ -192,4 +192,14 @@ public class SpigotConfig
commands.put( "restart", new RestartCommand( "restart" ) );
WatchdogThread.doStart( timeoutTime, restartOnCrash );
}
+
+ public static boolean bungee;
+ private static void bungee() {
+ if ( version < 4 )
+ {
+ set( "settings.bungeecord", false );
+ System.out.println( "Oudated config, disabling BungeeCord support!" );
+ }
+ bungee = getBoolean( "settings.bungeecord", false );
+ }
}
--
2014-04-18 23:15:23 +00:00
1.9.1
2014-04-12 04:18:37 +00:00