Add support for Minecraft 1.11

Improve QueryHandler session handling as suggested by IchBinJoe
This commit is contained in:
md_5 2016-11-15 02:40:46 +11:00
parent 1ad81564ad
commit 9ecdde2292
23 changed files with 240 additions and 46 deletions

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId> <artifactId>bungeecord-parent</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId> <artifactId>bungeecord-api</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>BungeeCord-API</name> <name>BungeeCord-API</name>

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId> <artifactId>bungeecord-parent</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-bootstrap</artifactId> <artifactId>bungeecord-bootstrap</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>BungeeCord-Bootstrap</name> <name>BungeeCord-Bootstrap</name>

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId> <artifactId>bungeecord-parent</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-chat</artifactId> <artifactId>bungeecord-chat</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>BungeeCord-Chat</name> <name>BungeeCord-Chat</name>

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId> <artifactId>bungeecord-parent</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-config</artifactId> <artifactId>bungeecord-config</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>BungeeCord-Config</name> <name>BungeeCord-Config</name>

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId> <artifactId>bungeecord-parent</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-event</artifactId> <artifactId>bungeecord-event</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>BungeeCord-Event</name> <name>BungeeCord-Event</name>

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId> <artifactId>bungeecord-parent</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-log</artifactId> <artifactId>bungeecord-log</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>BungeeCord-Log</name> <name>BungeeCord-Log</name>

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId> <artifactId>bungeecord-module</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-module-cmd-alert</artifactId> <artifactId>bungeecord-module-cmd-alert</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>cmd_alert</name> <name>cmd_alert</name>

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId> <artifactId>bungeecord-module</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-module-cmd-find</artifactId> <artifactId>bungeecord-module-cmd-find</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>cmd_find</name> <name>cmd_find</name>

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId> <artifactId>bungeecord-module</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-module-cmd-list</artifactId> <artifactId>bungeecord-module-cmd-list</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>cmd_list</name> <name>cmd_list</name>

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId> <artifactId>bungeecord-module</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-module-cmd-send</artifactId> <artifactId>bungeecord-module-cmd-send</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>cmd_send</name> <name>cmd_send</name>

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId> <artifactId>bungeecord-module</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-module-cmd-server</artifactId> <artifactId>bungeecord-module-cmd-server</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>cmd_server</name> <name>cmd_server</name>

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId> <artifactId>bungeecord-parent</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId> <artifactId>bungeecord-module</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>BungeeCord Modules</name> <name>BungeeCord Modules</name>

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-module</artifactId> <artifactId>bungeecord-module</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-module-reconnect-yaml</artifactId> <artifactId>bungeecord-module-reconnect-yaml</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>reconnect_yaml</name> <name>reconnect_yaml</name>

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId> <artifactId>bungeecord-parent</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-native</artifactId> <artifactId>bungeecord-native</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>BungeeCord-Native</name> <name>BungeeCord-Native</name>

View File

@ -11,7 +11,7 @@
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId> <artifactId>bungeecord-parent</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>BungeeCord-Parent</name> <name>BungeeCord-Parent</name>
@ -66,7 +66,7 @@
<properties> <properties>
<build.number>unknown</build.number> <build.number>unknown</build.number>
<netty.version>4.1.5.Final</netty.version> <netty.version>4.1.6.Final</netty.version>
<maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId> <artifactId>bungeecord-parent</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-protocol</artifactId> <artifactId>bungeecord-protocol</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>BungeeCord-Protocol</name> <name>BungeeCord-Protocol</name>

View File

@ -261,7 +261,8 @@ public enum Protocol
ProtocolConstants.MINECRAFT_1_9_1, ProtocolConstants.MINECRAFT_1_9_1,
ProtocolConstants.MINECRAFT_1_9_2, ProtocolConstants.MINECRAFT_1_9_2,
ProtocolConstants.MINECRAFT_1_9_4, ProtocolConstants.MINECRAFT_1_9_4,
ProtocolConstants.MINECRAFT_1_10 ProtocolConstants.MINECRAFT_1_10,
ProtocolConstants.MINECRAFT_1_11
) ); ) );
} }

View File

@ -12,17 +12,20 @@ public class ProtocolConstants
public static final int MINECRAFT_1_9_2 = 109; public static final int MINECRAFT_1_9_2 = 109;
public static final int MINECRAFT_1_9_4 = 110; public static final int MINECRAFT_1_9_4 = 110;
public static final int MINECRAFT_1_10 = 210; public static final int MINECRAFT_1_10 = 210;
public static final int MINECRAFT_1_11 = 315;
public static final List<String> SUPPORTED_VERSIONS = Arrays.asList( public static final List<String> SUPPORTED_VERSIONS = Arrays.asList(
"1.8.x", "1.8.x",
"1.9.x", "1.9.x",
"1.10.x" "1.10.x",
"1.11.x"
); );
public static final List<Integer> SUPPORTED_VERSION_IDS = Arrays.asList( ProtocolConstants.MINECRAFT_1_8, public static final List<Integer> SUPPORTED_VERSION_IDS = Arrays.asList( ProtocolConstants.MINECRAFT_1_8,
ProtocolConstants.MINECRAFT_1_9, ProtocolConstants.MINECRAFT_1_9,
ProtocolConstants.MINECRAFT_1_9_1, ProtocolConstants.MINECRAFT_1_9_1,
ProtocolConstants.MINECRAFT_1_9_2, ProtocolConstants.MINECRAFT_1_9_2,
ProtocolConstants.MINECRAFT_1_9_4, ProtocolConstants.MINECRAFT_1_9_4,
ProtocolConstants.MINECRAFT_1_10 ProtocolConstants.MINECRAFT_1_10,
ProtocolConstants.MINECRAFT_1_11
); );
public enum Direction public enum Direction

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId> <artifactId>bungeecord-parent</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-proxy</artifactId> <artifactId>bungeecord-proxy</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>BungeeCord-Proxy</name> <name>BungeeCord-Proxy</name>

View File

@ -35,6 +35,8 @@ public abstract class EntityMap
return EntityMap_1_9_4.INSTANCE; return EntityMap_1_9_4.INSTANCE;
case ProtocolConstants.MINECRAFT_1_10: case ProtocolConstants.MINECRAFT_1_10:
return EntityMap_1_10.INSTANCE; return EntityMap_1_10.INSTANCE;
case ProtocolConstants.MINECRAFT_1_11:
return EntityMap_1_11.INSTANCE;
} }
throw new RuntimeException( "Version " + version + " has no entity map" ); throw new RuntimeException( "Version " + version + " has no entity map" );
} }

View File

@ -0,0 +1,178 @@
package net.md_5.bungee.entitymap;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.buffer.ByteBuf;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;
import java.util.UUID;
class EntityMap_1_11 extends EntityMap
{
static final EntityMap_1_11 INSTANCE = new EntityMap_1_11();
EntityMap_1_11()
{
addRewrite( 0x00, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Object : PacketPlayOutSpawnEntity
addRewrite( 0x01, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Experience Orb : PacketPlayOutSpawnEntityExperienceOrb
addRewrite( 0x03, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Mob : PacketPlayOutSpawnEntityLiving
addRewrite( 0x04, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Painting : PacketPlayOutSpawnEntityPainting
addRewrite( 0x05, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Player : PacketPlayOutNamedEntitySpawn
addRewrite( 0x06, ProtocolConstants.Direction.TO_CLIENT, true ); // Animation : PacketPlayOutAnimation
addRewrite( 0x08, ProtocolConstants.Direction.TO_CLIENT, true ); // Block Break Animation : PacketPlayOutBlockBreakAnimation
addRewrite( 0x1B, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Status : PacketPlayOutEntityStatus
addRewrite( 0x25, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Relative Move : PacketPlayOutRelEntityMove
addRewrite( 0x26, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look and Relative Move : PacketPlayOutRelEntityMoveLook
addRewrite( 0x27, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look : PacketPlayOutEntityLook
addRewrite( 0x28, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity : PacketPlayOutEntity
addRewrite( 0x2F, ProtocolConstants.Direction.TO_CLIENT, true ); // Use bed : PacketPlayOutBed
addRewrite( 0x31, ProtocolConstants.Direction.TO_CLIENT, true ); // Remove Entity Effect : PacketPlayOutRemoveEntityEffect
addRewrite( 0x34, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Head Look : PacketPlayOutEntityHeadRotation
addRewrite( 0x36, ProtocolConstants.Direction.TO_CLIENT, true ); // Camera : PacketPlayOutCamera
addRewrite( 0x39, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Metadata : PacketPlayOutEntityMetadata
addRewrite( 0x3A, ProtocolConstants.Direction.TO_CLIENT, false ); // Attach Entity : PacketPlayOutAttachEntity
addRewrite( 0x3B, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Velocity : PacketPlayOutEntityVelocity
addRewrite( 0x3C, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Equipment : PacketPlayOutEntityEquipment
addRewrite( 0x40, ProtocolConstants.Direction.TO_CLIENT, true ); // Attach Entity : PacketPlayOutMount
addRewrite( 0x48, ProtocolConstants.Direction.TO_CLIENT, true ); // Collect Item : PacketPlayOutCollect
addRewrite( 0x49, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Teleport : PacketPlayOutEntityTeleport
addRewrite( 0x4A, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Properties : PacketPlayOutUpdateAttributes
addRewrite( 0x4B, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Effect : PacketPlayOutEntityEffect
addRewrite( 0x0A, ProtocolConstants.Direction.TO_SERVER, true ); // Use Entity : PacketPlayInUseEntity
addRewrite( 0x14, ProtocolConstants.Direction.TO_SERVER, true ); // Entity Action : PacketPlayInEntityAction
}
@Override
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
public void rewriteClientbound(ByteBuf packet, int oldId, int newId)
{
super.rewriteClientbound( packet, oldId, newId );
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int jumpIndex = packet.readerIndex();
switch ( packetId )
{
case 0x3A /* Attach Entity : PacketPlayOutAttachEntity */:
rewriteInt( packet, oldId, newId, readerIndex + packetIdLength + 4 );
break;
case 0x48 /* Collect Item : PacketPlayOutCollect */:
DefinedPacket.readVarInt( packet );
rewriteVarInt( packet, oldId, newId, packet.readerIndex() );
break;
case 0x40 /* Attach Entity : PacketPlayOutMount */:
DefinedPacket.readVarInt( packet );
jumpIndex = packet.readerIndex();
// Fall through on purpose to int array of IDs
case 0x30 /* Destroy Entities : PacketPlayOutEntityDestroy */:
int count = DefinedPacket.readVarInt( packet );
int[] ids = new int[ count ];
for ( int i = 0; i < count; i++ )
{
ids[i] = DefinedPacket.readVarInt( packet );
}
packet.readerIndex( jumpIndex );
packet.writerIndex( jumpIndex );
DefinedPacket.writeVarInt( count, packet );
for ( int id : ids )
{
if ( id == oldId )
{
id = newId;
} else if ( id == newId )
{
id = oldId;
}
DefinedPacket.writeVarInt( id, packet );
}
break;
case 0x00 /* Spawn Object : PacketPlayOutSpawnEntity */:
DefinedPacket.readVarInt( packet );
DefinedPacket.readUUID( packet );
int type = packet.readUnsignedByte();
if ( type == 60 || type == 90 || type == 91 )
{
if ( type == 60 || type == 91 )
{
oldId = oldId + 1;
newId = newId + 1;
}
packet.skipBytes( 26 ); // double, double, double, byte, byte
int position = packet.readerIndex();
int readId = packet.readInt();
if ( readId == oldId )
{
packet.setInt( position, newId );
} else if ( readId == newId )
{
packet.setInt( position, oldId );
}
}
break;
case 0x05 /* Spawn Player : PacketPlayOutNamedEntitySpawn */:
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
packet.writerIndex( previous );
}
break;
case 0x2C /* Combat Event : PacketPlayOutCombatEvent */:
int event = packet.readUnsignedByte();
if ( event == 1 /* End Combat*/ )
{
DefinedPacket.readVarInt( packet );
rewriteInt( packet, oldId, newId, packet.readerIndex() );
} else if ( event == 2 /* Entity Dead */ )
{
int position = packet.readerIndex();
rewriteVarInt( packet, oldId, newId, packet.readerIndex() );
packet.readerIndex( position );
DefinedPacket.readVarInt( packet );
rewriteInt( packet, oldId, newId, packet.readerIndex() );
}
break;
}
packet.readerIndex( readerIndex );
}
@Override
public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
{
super.rewriteServerbound( packet, oldId, newId );
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
if ( ( player = BungeeCord.getInstance().getPlayer( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
packet.writerIndex( previous );
}
}
packet.readerIndex( readerIndex );
}
}

View File

@ -6,13 +6,13 @@
<parent> <parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-parent</artifactId> <artifactId>bungeecord-parent</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-query</artifactId> <artifactId>bungeecord-query</artifactId>
<version>1.10-SNAPSHOT</version> <version>1.11-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>BungeeCord-Query</name> <name>BungeeCord-Query</name>

View File

@ -1,17 +1,19 @@
package net.md_5.bungee.query; package net.md_5.bungee.query;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.AddressedEnvelope; import io.netty.channel.AddressedEnvelope;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.DatagramPacket;
import java.nio.ByteOrder; import java.net.InetAddress;
import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import lombok.Data;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ListenerInfo; import net.md_5.bungee.api.config.ListenerInfo;
@ -25,11 +27,11 @@ public class QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
private final ListenerInfo listener; private final ListenerInfo listener;
/*========================================================================*/ /*========================================================================*/
private final Random random = new Random(); private final Random random = new Random();
private final Map<Integer, Long> sessions = new HashMap<>(); private final Cache<InetAddress, QuerySession> sessions = CacheBuilder.newBuilder().expireAfterWrite( 30, TimeUnit.SECONDS).build();
private void writeShort(ByteBuf buf, int s) private void writeShort(ByteBuf buf, int s)
{ {
buf.order( ByteOrder.LITTLE_ENDIAN ).writeShort( s ); buf.writeShortLE( s );
} }
private void writeNumber(ByteBuf buf, int i) private void writeNumber(ByteBuf buf, int i)
@ -68,7 +70,7 @@ public class QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
out.writeInt( sessionId ); out.writeInt( sessionId );
int challengeToken = random.nextInt(); int challengeToken = random.nextInt();
sessions.put( challengeToken, System.currentTimeMillis() ); sessions.put( msg.sender().getAddress(), new QuerySession( challengeToken, System.currentTimeMillis() ) );
writeNumber( out, challengeToken ); writeNumber( out, challengeToken );
} }
@ -76,8 +78,8 @@ public class QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
if ( type == 0x00 ) if ( type == 0x00 )
{ {
int challengeToken = in.readInt(); int challengeToken = in.readInt();
Long session = sessions.get( challengeToken ); QuerySession session = sessions.getIfPresent( msg.sender().getAddress() );
if ( session == null || System.currentTimeMillis() - session > TimeUnit.SECONDS.toMillis( 30 ) ) if ( session == null || session.getToken() != challengeToken )
{ {
throw new IllegalStateException( "No session!" ); throw new IllegalStateException( "No session!" );
} }
@ -147,4 +149,12 @@ public class QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
{ {
bungee.getLogger().log( Level.WARNING, "Error whilst handling query packet from " + ctx.channel().remoteAddress(), cause ); bungee.getLogger().log( Level.WARNING, "Error whilst handling query packet from " + ctx.channel().remoteAddress(), cause );
} }
@Data
private static class QuerySession
{
private final int token;
private final long time;
}
} }