Paper/CraftBukkit-Patches/0055-BungeeCord-Support.patch

217 lines
10 KiB
Diff
Raw Normal View History

2015-06-01 11:22:52 +02:00
From 9919455a6939de744d08eb063e10ba966448d67a Mon Sep 17 00:00:00 2001
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
2015-05-25 14:05:40 +02:00
index d0374d0..8a6ef45 100644
--- a/src/main/java/net/minecraft/server/HandshakeListener.java
+++ b/src/main/java/net/minecraft/server/HandshakeListener.java
2015-02-28 12:36:22 +01:00
@@ -7,6 +7,7 @@ import java.util.HashMap;
public class HandshakeListener implements PacketHandshakingInListener {
2015-02-28 12:36:22 +01: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;
2014-11-28 02:17:45 +01:00
@@ -71,6 +72,26 @@ public class HandshakeListener implements PacketHandshakingInListener {
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");
+ if ( split.length == 3 || split.length == 4 ) {
+ packethandshakinginsetprotocol.b = split[0];
2015-02-28 12:36:22 +01:00
+ b.l = new java.net.InetSocketAddress(split[1], ((java.net.InetSocketAddress) b.getSocketAddress()).getPort());
2014-11-28 02:17:45 +01:00
+ 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!");
2014-11-28 02:17:45 +01:00
+ this.b.handle(new PacketLoginOutDisconnect(chatcomponenttext));
+ this.b.close(chatcomponenttext);
+ return;
+ }
+ if ( split.length == 4 )
+ {
2014-11-28 02:17:45 +01:00
+ b.spoofedProfile = gson.fromJson(split[3], com.mojang.authlib.properties.Property[].class);
+ }
+ }
+ // 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
2015-05-25 14:05:40 +02:00
index 1fa9626..541cec7 100644
--- a/src/main/java/net/minecraft/server/LoginListener.java
+++ b/src/main/java/net/minecraft/server/LoginListener.java
2015-02-28 12:36:22 +01:00
@@ -84,9 +84,24 @@ public class LoginListener implements PacketLoginInListener, IUpdatePlayerListBo
// 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)
+ {
2014-11-28 02:17:45 +01:00
+ for ( com.mojang.authlib.properties.Property property : networkManager.spoofedProfile )
+ {
+ this.i.getProperties().put( property.getName(), property );
+ }
+ }
}
// Spigot end
@@ -148,13 +163,19 @@ public class LoginListener implements PacketLoginInListener, IUpdatePlayerListBo
2015-05-09 22:23:26 +02:00
this.networkManager.handle(new PacketLoginOutEncryptionBegin(this.j, this.server.Q().getPublic(), this.e));
} else {
// Spigot start
- try {
- initUUID();
- new LoginHandler().fireEvents();
- } catch (Exception ex) {
- disconnect("Failed to verify username!");
- server.server.getLogger().log(java.util.logging.Level.WARNING, "Exception verifying " + i.getName(), ex);
- }
+ initUUID();
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ try{
+ new LoginHandler().fireEvents();
+ } catch (Exception ex) {
+ disconnect("Failed to verify username!");
+ server.server.getLogger().log(java.util.logging.Level.WARNING, "Exception verifying " + i.getName(), ex);
+ }
+ }
+ }).start();
// Spigot end
}
diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
2015-05-09 22:23:26 +02:00
index cd67d2b..54298b4 100644
--- a/src/main/java/net/minecraft/server/NetworkManager.java
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
2015-02-28 12:36:22 +01:00
@@ -64,7 +64,11 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet> {
private final Queue<NetworkManager.QueuedPacket> i = Queues.newConcurrentLinkedQueue();
private final ReentrantReadWriteLock j = new ReentrantReadWriteLock();
2015-05-09 22:23:26 +02:00
public Channel channel; // CraftBukkit - public
2015-02-28 12:36:22 +01:00
- private SocketAddress l;
+ // Spigot Start
2015-02-28 12:36:22 +01:00
+ public SocketAddress l;
+ public java.util.UUID spoofedUUID;
2014-11-28 02:17:45 +01:00
+ public com.mojang.authlib.properties.Property[] spoofedProfile;
+ // Spigot End
2015-02-28 12:36:22 +01:00
private PacketListener m;
private IChatBaseComponent n;
private boolean o;
@@ -322,4 +326,11 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet> {
this.b = agenericfuturelistener;
}
}
+
+ // Spigot Start
+ public SocketAddress getRawAddress()
+ {
2015-05-09 22:23:26 +02:00
+ 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
2015-06-01 11:22:52 +02:00
index a1c5869..c91a695 100644
--- a/src/main/java/net/minecraft/server/PacketHandshakingInSetProtocol.java
+++ b/src/main/java/net/minecraft/server/PacketHandshakingInSetProtocol.java
2015-02-28 12:36:22 +01:00
@@ -13,7 +13,7 @@ public class PacketHandshakingInSetProtocol implements Packet<PacketHandshakingI
2015-02-28 12:36:22 +01:00
public void a(PacketDataSerializer packetdataserializer) throws IOException {
2014-11-28 02:17:45 +01:00
this.a = packetdataserializer.e();
- this.b = packetdataserializer.c(255);
+ this.b = packetdataserializer.c(Short.MAX_VALUE); // Spigot
this.c = packetdataserializer.readUnsignedShort();
2014-11-28 02:17:45 +01:00
this.d = EnumProtocol.a(packetdataserializer.e());
}
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
2015-05-25 14:05:40 +02:00
index 665d58e..0dcf37e 100644
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
2015-02-28 12:36:22 +01:00
@@ -403,7 +403,7 @@ public abstract class PlayerList {
2014-11-28 02:17:45 +01:00
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), gameprofile, new PlayerInteractManager(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-11-28 02:17:45 +01:00
if (getProfileBans().isBanned(gameprofile) && !getProfileBans().get(gameprofile).hasExpired()) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2015-06-01 11:22:52 +02:00
index d07b3b8..2801b5c 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2015-06-01 11:22:52 +02:00
@@ -557,7 +557,13 @@ public final class CraftServer implements Server {
@Override
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
}
@Override
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2015-05-09 22:23:26 +02:00
index a5b7b75..28b4647 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1320,6 +1320,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 34def7b..824ba7a 100644
--- a/src/main/java/org/spigotmc/SpigotConfig.java
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
@@ -211,4 +211,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 );
+ }
}
--
2015-06-01 11:22:52 +02:00
2.1.4