Dual version entity ID rewriting
This commit is contained in:
parent
b2f517fa63
commit
842392d59c
@ -2,7 +2,6 @@ package net.md_5.bungee;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
import net.md_5.bungee.protocol.PacketWrapper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to rewrite integers within packets.
|
* Class to rewrite integers within packets.
|
||||||
@ -10,13 +9,13 @@ import net.md_5.bungee.protocol.PacketWrapper;
|
|||||||
public class EntityMap
|
public class EntityMap
|
||||||
{
|
{
|
||||||
|
|
||||||
private final static boolean[] clientboundInts = new boolean[ 256 ];
|
private final boolean[] clientboundInts = new boolean[ 256 ];
|
||||||
private final static boolean[] clientboundVarInts = new boolean[ 256 ];
|
private final boolean[] clientboundVarInts = new boolean[ 256 ];
|
||||||
|
|
||||||
private final static boolean[] serverboundInts = new boolean[ 256 ];
|
private final boolean[] serverboundInts = new boolean[ 256 ];
|
||||||
private final static boolean[] serverboundVarInts = new boolean[ 256 ];
|
private final boolean[] serverboundVarInts = new boolean[ 256 ];
|
||||||
|
|
||||||
static
|
public EntityMap(int version)
|
||||||
{
|
{
|
||||||
clientboundInts[0x04] = true; // Entity Equipment
|
clientboundInts[0x04] = true; // Entity Equipment
|
||||||
clientboundInts[0x0A] = true; // Use bed
|
clientboundInts[0x0A] = true; // Use bed
|
||||||
@ -46,14 +45,32 @@ public class EntityMap
|
|||||||
serverboundInts[0x02] = true; // Use Entity
|
serverboundInts[0x02] = true; // Use Entity
|
||||||
serverboundInts[0x0A] = true; // Animation
|
serverboundInts[0x0A] = true; // Animation
|
||||||
serverboundInts[0x0B] = true; // Entity Action
|
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 );
|
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 );
|
rewrite( packet, serverEntityId, clientEntityId, clientboundInts, clientboundVarInts );
|
||||||
|
|
||||||
|
@ -103,6 +103,8 @@ public final class UserConnection implements ProxiedPlayer
|
|||||||
/*========================================================================*/
|
/*========================================================================*/
|
||||||
@Getter
|
@Getter
|
||||||
private String displayName;
|
private String displayName;
|
||||||
|
@Getter
|
||||||
|
private EntityMap entityRewrite;
|
||||||
/*========================================================================*/
|
/*========================================================================*/
|
||||||
private final Unsafe unsafe = new Unsafe()
|
private final Unsafe unsafe = new Unsafe()
|
||||||
{
|
{
|
||||||
@ -115,6 +117,8 @@ public final class UserConnection implements ProxiedPlayer
|
|||||||
|
|
||||||
public void init()
|
public void init()
|
||||||
{
|
{
|
||||||
|
this.entityRewrite = new EntityMap( getPendingConnection().getVersion() );
|
||||||
|
|
||||||
this.displayName = name;
|
this.displayName = name;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -79,7 +79,7 @@ public class DownstreamBridge extends PacketHandler
|
|||||||
{
|
{
|
||||||
if ( !server.isObsolete() )
|
if ( !server.isObsolete() )
|
||||||
{
|
{
|
||||||
EntityMap.rewriteClientbound( packet.buf, con.getServerEntityId(), con.getClientEntityId() );
|
con.getEntityRewrite().rewriteClientbound( packet.buf, con.getServerEntityId(), con.getClientEntityId() );
|
||||||
con.sendPacket( packet );
|
con.sendPacket( packet );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ public class UpstreamBridge extends PacketHandler
|
|||||||
@Override
|
@Override
|
||||||
public void handle(PacketWrapper packet) throws Exception
|
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 )
|
if ( con.getServer() != null )
|
||||||
{
|
{
|
||||||
con.getServer().getCh().write( packet );
|
con.getServer().getCh().write( packet );
|
||||||
|
Loading…
Reference in New Issue
Block a user