Fix server-bound entity ids as well

This commit is contained in:
Thinkofdeath 2013-12-08 16:42:49 +00:00
parent cfda905d98
commit 230cca0f9e
2 changed files with 39 additions and 16 deletions

View File

@ -13,6 +13,9 @@ public class EntityMap
private final static boolean[] clientboundInts = new boolean[256]; private final static boolean[] clientboundInts = new boolean[256];
private final static boolean[] clientboundVarInts = new boolean[256]; private final static boolean[] clientboundVarInts = new boolean[256];
private final static boolean[] serverboundInts = new boolean[256];
private final static boolean[] serverboundVarInts = new boolean[256];
static static
{ {
clientboundInts[0x04] = true; clientboundInts[0x04] = true;
@ -39,15 +42,46 @@ public class EntityMap
clientboundInts[0x20] = true; clientboundInts[0x20] = true;
clientboundVarInts[0x25] = true; clientboundVarInts[0x25] = true;
clientboundVarInts[0x2C] = true; clientboundVarInts[0x2C] = true;
serverboundInts[0x02] = true;
serverboundInts[0x0A] = true;
serverboundInts[0x0B] = true;
}
public static 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 static void rewriteClientbound(ByteBuf packet, int serverEntityId, int clientEntityId)
{
rewrite(packet, serverEntityId, clientEntityId, clientboundInts, clientboundVarInts);
//Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x0D || packetId == 0x1B )
{
int readId = packet.getInt( packetIdLength + 4 );
if ( readId == serverEntityId )
{
packet.setInt( packetIdLength + 4, clientEntityId );
} else if ( readId == clientEntityId )
{
packet.setInt( packetIdLength + 4, serverEntityId );
}
}
packet.readerIndex( readerIndex );
}
private static void rewrite(ByteBuf packet, int serverEntityId, int clientEntityId, boolean[] ints, boolean[] varints)
{ {
int readerIndex = packet.readerIndex(); int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet ); int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex; int packetIdLength = packet.readerIndex() - readerIndex;
if ( clientboundInts[packetId] ) if ( ints[packetId] )
{ {
int readId = packet.getInt( packetIdLength ); int readId = packet.getInt( packetIdLength );
if ( readId == serverEntityId ) if ( readId == serverEntityId )
@ -57,26 +91,14 @@ public class EntityMap
{ {
packet.setInt( packetIdLength, serverEntityId ); packet.setInt( packetIdLength, serverEntityId );
} }
} else if ( varints[packetId] )
if ( packetId == 0x0D || packetId == 0x1B )
{
readId = packet.getInt( packetIdLength + 4 );
if ( readId == serverEntityId )
{
packet.setInt( packetIdLength + 4, clientEntityId );
} else if ( readId == clientEntityId )
{
packet.setInt( packetIdLength + 4, serverEntityId );
}
}
} else if ( clientboundVarInts[packetId] )
{ {
// Need to rewrite the packet because VarInts are variable length // Need to rewrite the packet because VarInts are variable length
int readId = DefinedPacket.readVarInt( packet ); int readId = DefinedPacket.readVarInt( packet );
int readIdLength = packet.readerIndex() - readerIndex - packetIdLength; int readIdLength = packet.readerIndex() - readerIndex - packetIdLength;
if ( readId == serverEntityId || readId == clientEntityId ) if ( readId == serverEntityId || readId == clientEntityId )
{ {
ByteBuf data = packet.slice(); ByteBuf data = packet.slice().copy();
packet.readerIndex( readerIndex ); packet.readerIndex( readerIndex );
packet.writerIndex( packetIdLength ); packet.writerIndex( packetIdLength );
DefinedPacket.writeVarInt( readId == serverEntityId ? clientEntityId : serverEntityId, packet ); DefinedPacket.writeVarInt( readId == serverEntityId ? clientEntityId : serverEntityId, packet );

View File

@ -1,6 +1,7 @@
package net.md_5.bungee.connection; package net.md_5.bungee.connection;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.EntityMap;
import net.md_5.bungee.UserConnection; import net.md_5.bungee.UserConnection;
import net.md_5.bungee.Util; import net.md_5.bungee.Util;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
@ -59,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.rewrite( packet.buf, con.getClientEntityId(), con.getServerEntityId() ); EntityMap.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 );