From 5bfab582dfe199cb44ca2fb908f3eb931da99e06 Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 14 Mar 2013 20:22:26 +1100 Subject: [PATCH] Fix #156 - Bukkit trying to get client settings. --- .../java/net/md_5/bungee/ServerConnector.java | 6 ++++ .../java/net/md_5/bungee/UserConnection.java | 1 + .../bungee/connection/UpstreamBridge.java | 7 ++++ .../md_5/bungee/packet/PacketCCSettings.java | 32 +++++++++++++++++++ .../net/md_5/bungee/packet/PacketHandler.java | 4 +++ 5 files changed, 50 insertions(+) create mode 100644 proxy/src/main/java/net/md_5/bungee/packet/PacketCCSettings.java diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 9c138201c..d35d4003b 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -56,11 +56,17 @@ public class ServerConnector extends PacketHandler ch.write( BungeeCord.getInstance().registerChannels() ); + // TODO: Race conditions with many connects Queue packetQueue = ( (BungeeServerInfo) target ).getPacketQueue(); while ( !packetQueue.isEmpty() ) { ch.write( packetQueue.poll() ); } + if ( user.settings != null ) + { + ch.write( user.settings ); + } + synchronized ( user.getSwitchMutex() ) { diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 79589cb89..010f646f3 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -60,6 +60,7 @@ public final class UserConnection implements ProxiedPlayer private final Object permMutex = new Object(); @Getter private final Object switchMutex = new Object(); + public PacketCCSettings settings; public UserConnection(BungeeCord bungee, Channel channel, PendingConnection pendingConnection, Packet2Handshake handshake, Packet1Login forgeLogin, List loginMessages) { diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 2021d4e8d..ab62c49d3 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -11,6 +11,7 @@ import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.packet.Packet0KeepAlive; import net.md_5.bungee.packet.Packet3Chat; +import net.md_5.bungee.packet.PacketCCSettings; import net.md_5.bungee.packet.PacketFAPluginMessage; import net.md_5.bungee.packet.PacketHandler; @@ -80,6 +81,12 @@ public class UpstreamBridge extends PacketHandler } } + @Override + public void handle(PacketCCSettings settings) throws Exception + { + con.settings = settings; + } + @Override public void handle(PacketFAPluginMessage pluginMessage) throws Exception { diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketCCSettings.java b/proxy/src/main/java/net/md_5/bungee/packet/PacketCCSettings.java new file mode 100644 index 000000000..d2d652a82 --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/packet/PacketCCSettings.java @@ -0,0 +1,32 @@ +package net.md_5.bungee.packet; + +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@ToString +@EqualsAndHashCode(callSuper = false) +public class PacketCCSettings extends DefinedPacket +{ + + public String locale; + public byte viewDistance; + public byte chatFlags; + public byte difficulty; + public boolean showCape; + + public PacketCCSettings(byte[] buf) + { + super( 0xCC, buf ); + locale = readUTF(); + viewDistance = readByte(); + chatFlags = readByte(); + difficulty = readByte(); + showCape = readBoolean(); + } + + @Override + public void handle(PacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/packet/PacketHandler.java b/proxy/src/main/java/net/md_5/bungee/packet/PacketHandler.java index 8773a2f53..429955fb7 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/PacketHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/PacketHandler.java @@ -48,6 +48,10 @@ public abstract class PacketHandler { } + public void handle(PacketCCSettings settings) throws Exception + { + } + public void handle(PacketCDClientStatus clientStatus) throws Exception { }