Dual version entity ID rewriting

This commit is contained in:
md_5 2014-01-27 11:39:10 +11:00
parent b2f517fa63
commit 842392d59c
4 changed files with 31 additions and 10 deletions

View File

@ -2,7 +2,6 @@ package net.md_5.bungee;
import io.netty.buffer.ByteBuf;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.PacketWrapper;
/**
* Class to rewrite integers within packets.
@ -10,13 +9,13 @@ import net.md_5.bungee.protocol.PacketWrapper;
public class EntityMap
{
private final static boolean[] clientboundInts = new boolean[ 256 ];
private final static boolean[] clientboundVarInts = new boolean[ 256 ];
private final boolean[] clientboundInts = new boolean[ 256 ];
private final boolean[] clientboundVarInts = new boolean[ 256 ];
private final static boolean[] serverboundInts = new boolean[ 256 ];
private final static boolean[] serverboundVarInts = new boolean[ 256 ];
private final boolean[] serverboundInts = new boolean[ 256 ];
private final boolean[] serverboundVarInts = new boolean[ 256 ];
static
public EntityMap(int version)
{
clientboundInts[0x04] = true; // Entity Equipment
clientboundInts[0x0A] = true; // Use bed
@ -46,14 +45,32 @@ public class EntityMap
serverboundInts[0x02] = true; // Use Entity
serverboundInts[0x0A] = true; // Animation
serverboundInts[0x0B] = true; // Entity Action
if ( version >= 7 )
{
migrateIntToVarint( clientboundInts, clientboundVarInts );
migrateIntToVarint( serverboundInts, serverboundVarInts );
}
}
public static void rewriteServerbound(ByteBuf packet, int serverEntityId, int clientEntityId)
private void migrateIntToVarint(boolean[] ints, boolean[] varints)
{
for ( int i = 0; i < ints.length; i++ )
{
if ( ints[i] = true )
{
varints[i] = true;
ints[i] = false;
}
}
}
public void rewriteServerbound(ByteBuf packet, int serverEntityId, int clientEntityId)
{
rewrite( packet, serverEntityId, clientEntityId, serverboundInts, serverboundVarInts );
}
public static void rewriteClientbound(ByteBuf packet, int serverEntityId, int clientEntityId)
public void rewriteClientbound(ByteBuf packet, int serverEntityId, int clientEntityId)
{
rewrite( packet, serverEntityId, clientEntityId, clientboundInts, clientboundVarInts );

View File

@ -103,6 +103,8 @@ public final class UserConnection implements ProxiedPlayer
/*========================================================================*/
@Getter
private String displayName;
@Getter
private EntityMap entityRewrite;
/*========================================================================*/
private final Unsafe unsafe = new Unsafe()
{
@ -115,6 +117,8 @@ public final class UserConnection implements ProxiedPlayer
public void init()
{
this.entityRewrite = new EntityMap( getPendingConnection().getVersion() );
this.displayName = name;
try
{

View File

@ -79,7 +79,7 @@ public class DownstreamBridge extends PacketHandler
{
if ( !server.isObsolete() )
{
EntityMap.rewriteClientbound( packet.buf, con.getServerEntityId(), con.getClientEntityId() );
con.getEntityRewrite().rewriteClientbound( packet.buf, con.getServerEntityId(), con.getClientEntityId() );
con.sendPacket( packet );
}
}

View File

@ -60,7 +60,7 @@ public class UpstreamBridge extends PacketHandler
@Override
public void handle(PacketWrapper packet) throws Exception
{
EntityMap.rewriteServerbound( packet.buf, con.getClientEntityId(), con.getServerEntityId() );
con.getEntityRewrite().rewriteServerbound( packet.buf, con.getClientEntityId(), con.getServerEntityId() );
if ( con.getServer() != null )
{
con.getServer().getCh().write( packet );