diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 3f277ee75..70e7c8460 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -26,6 +26,7 @@ import java.net.InetSocketAddress; import java.text.MessageFormat; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.Locale; import java.util.Map; @@ -33,6 +34,7 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Timer; import java.util.TimerTask; +import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -101,6 +103,11 @@ public class BungeeCord extends ProxyServer */ private final Map connections = new CaseInsensitiveMap<>(); private final ReadWriteLock connectionLock = new ReentrantReadWriteLock(); + /** + * Skin support for servers that don't support ip-forwarding + */ + private final Map uuidMap = new HashMap<>(); + private final ReadWriteLock uuidLock = new ReentrantReadWriteLock(); /** * Plugin manager. */ @@ -538,6 +545,42 @@ public class BungeeCord extends ProxyServer } } + public void addUUID(String offlineUUID, String actualUUID) + { + uuidLock.writeLock().lock(); + try + { + uuidMap.put( offlineUUID, actualUUID ); + } finally + { + uuidLock.writeLock().unlock(); + } + } + + public void removeUUID(String offlineUUID) + { + uuidLock.writeLock().lock(); + try + { + uuidMap.remove( offlineUUID ); + } finally + { + uuidLock.writeLock().unlock(); + } + } + + public String getActualUUID(String offlineUUID) + { + uuidLock.readLock().lock(); + try + { + return uuidMap.get( offlineUUID ); + } finally + { + uuidLock.readLock().unlock(); + } + } + @Override public CustomTabList customTabList(ProxiedPlayer player) { diff --git a/proxy/src/main/java/net/md_5/bungee/EntityMap.java b/proxy/src/main/java/net/md_5/bungee/EntityMap.java index 7e40f4ef3..bdeb728d1 100644 --- a/proxy/src/main/java/net/md_5/bungee/EntityMap.java +++ b/proxy/src/main/java/net/md_5/bungee/EntityMap.java @@ -16,8 +16,12 @@ public class EntityMap private final boolean[] serverboundInts = new boolean[ 256 ]; private final boolean[] serverboundVarInts = new boolean[ 256 ]; + private final int version; + public EntityMap(int version) { + this.version = version; + clientboundInts[0x04] = true; // Entity Equipment clientboundInts[0x0A] = true; // Use bed clientboundVarInts[0x0B] = true; // Animation @@ -137,6 +141,22 @@ public class EntityMap } } } + } else if ( packetId == 0x0C /* Spawn Player */ && version == 5 ) + { + DefinedPacket.readVarInt( packet ); + int idLength = packet.readerIndex() - readerIndex - packetIdLength; + String uuid = DefinedPacket.readString( packet ); + if ( uuid.length() == 36 ) { + String actualUUID = BungeeCord.getInstance().getActualUUID( uuid ); + if ( actualUUID != null ) + { + packet.readerIndex( readerIndex ); + int writerIndex = packet.writerIndex(); + packet.writerIndex( readerIndex + packetIdLength + idLength ); + DefinedPacket.writeString( actualUUID, packet ); + packet.writerIndex( writerIndex ); + } + } } packet.readerIndex( readerIndex ); } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index cb88ca70a..ec73271d3 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -83,6 +83,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection private InetSocketAddress virtualHost; @Getter private UUID uniqueId; + @Getter + private UUID offlineId; private enum State { @@ -367,10 +369,12 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( ch.getHandle().isActive() ) { + offlineId = java.util.UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + getName() ).getBytes( Charsets.UTF_8 ) ); if ( uniqueId == null ) { - uniqueId = java.util.UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + getName() ).getBytes( Charsets.UTF_8 ) ); + uniqueId = offlineId; } + BungeeCord.getInstance().addUUID( offlineId.toString(), uniqueId.toString() ); // Version 5 == 1.7.6. This is a screwup as 1.7.6 was also a snapshot. if ( getVersion() == 5 ) { 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 e5e402ff1..42882fc52 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 @@ -52,6 +52,7 @@ public class UpstreamBridge extends PacketHandler bungee.getPluginManager().callEvent( event ); con.getTabList().onDisconnect(); BungeeCord.getInstance().removeConnection( con ); + BungeeCord.getInstance().removeUUID( con.getPendingConnection().getOfflineId().toString() ); if ( con.getServer() != null ) {