Rewrite the spawn player packet's uuid to support skins on non ip-fowarded servers

This commit is contained in:
Thinkofdeath 2014-04-04 12:14:04 +01:00
parent 1d3adc5317
commit cd518690fd
4 changed files with 69 additions and 1 deletions

View File

@ -26,6 +26,7 @@ import java.net.InetSocketAddress;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -33,6 +34,7 @@ import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
@ -101,6 +103,11 @@ public class BungeeCord extends ProxyServer
*/ */
private final Map<String, UserConnection> connections = new CaseInsensitiveMap<>(); private final Map<String, UserConnection> connections = new CaseInsensitiveMap<>();
private final ReadWriteLock connectionLock = new ReentrantReadWriteLock(); private final ReadWriteLock connectionLock = new ReentrantReadWriteLock();
/**
* Skin support for servers that don't support ip-forwarding
*/
private final Map<String, String> uuidMap = new HashMap<>();
private final ReadWriteLock uuidLock = new ReentrantReadWriteLock();
/** /**
* Plugin manager. * 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 @Override
public CustomTabList customTabList(ProxiedPlayer player) public CustomTabList customTabList(ProxiedPlayer player)
{ {

View File

@ -16,8 +16,12 @@ public class EntityMap
private final boolean[] serverboundInts = new boolean[ 256 ]; private final boolean[] serverboundInts = new boolean[ 256 ];
private final boolean[] serverboundVarInts = new boolean[ 256 ]; private final boolean[] serverboundVarInts = new boolean[ 256 ];
private final int version;
public EntityMap(int version) public EntityMap(int version)
{ {
this.version = version;
clientboundInts[0x04] = true; // Entity Equipment clientboundInts[0x04] = true; // Entity Equipment
clientboundInts[0x0A] = true; // Use bed clientboundInts[0x0A] = true; // Use bed
clientboundVarInts[0x0B] = true; // Animation 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 ); packet.readerIndex( readerIndex );
} }

View File

@ -83,6 +83,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection
private InetSocketAddress virtualHost; private InetSocketAddress virtualHost;
@Getter @Getter
private UUID uniqueId; private UUID uniqueId;
@Getter
private UUID offlineId;
private enum State private enum State
{ {
@ -367,10 +369,12 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{ {
if ( ch.getHandle().isActive() ) if ( ch.getHandle().isActive() )
{ {
offlineId = java.util.UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + getName() ).getBytes( Charsets.UTF_8 ) );
if ( uniqueId == null ) 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. // Version 5 == 1.7.6. This is a screwup as 1.7.6 was also a snapshot.
if ( getVersion() == 5 ) if ( getVersion() == 5 )
{ {

View File

@ -52,6 +52,7 @@ public class UpstreamBridge extends PacketHandler
bungee.getPluginManager().callEvent( event ); bungee.getPluginManager().callEvent( event );
con.getTabList().onDisconnect(); con.getTabList().onDisconnect();
BungeeCord.getInstance().removeConnection( con ); BungeeCord.getInstance().removeConnection( con );
BungeeCord.getInstance().removeUUID( con.getPendingConnection().getOfflineId().toString() );
if ( con.getServer() != null ) if ( con.getServer() != null )
{ {