Minecraft 1.13-pre7 support
This commit is contained in:
@@ -246,7 +246,6 @@ public class BungeeCord extends ProxyServer
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
|
||||
public void start() throws Exception
|
||||
{
|
||||
@@ -616,8 +615,13 @@ public class BungeeCord extends ProxyServer
|
||||
return Collections.unmodifiableCollection( pluginChannels );
|
||||
}
|
||||
|
||||
public PluginMessage registerChannels()
|
||||
public PluginMessage registerChannels(int protocolVersion)
|
||||
{
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
|
||||
{
|
||||
return new PluginMessage( "minecraft:register", Util.format( Iterables.transform( pluginChannels, PluginMessage.MODERNISE ), "\00" ).getBytes( Charsets.UTF_8 ), false );
|
||||
}
|
||||
|
||||
return new PluginMessage( "REGISTER", Util.format( pluginChannels, "\00" ).getBytes( Charsets.UTF_8 ), false );
|
||||
}
|
||||
|
||||
|
@@ -14,5 +14,4 @@ public class PacketConstants
|
||||
{
|
||||
0, 0, 0, 0, 0, 2
|
||||
}, false );
|
||||
public static final PluginMessage I_AM_BUNGEE = new PluginMessage( "BungeeCord", new byte[ 0 ], false );
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import io.netty.buffer.ByteBufAllocator;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
@@ -30,7 +31,9 @@ import net.md_5.bungee.netty.ChannelWrapper;
|
||||
import net.md_5.bungee.netty.HandlerBoss;
|
||||
import net.md_5.bungee.netty.PacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.PacketWrapper;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
import net.md_5.bungee.protocol.packet.EncryptionRequest;
|
||||
import net.md_5.bungee.protocol.packet.Handshake;
|
||||
import net.md_5.bungee.protocol.packet.Kick;
|
||||
@@ -42,6 +45,7 @@ import net.md_5.bungee.protocol.packet.Respawn;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardObjective;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardScore;
|
||||
import net.md_5.bungee.protocol.packet.SetCompression;
|
||||
import net.md_5.bungee.util.BufUtil;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class ServerConnector extends PacketHandler
|
||||
@@ -118,6 +122,15 @@ public class ServerConnector extends PacketHandler
|
||||
user.getPendingConnects().remove( target );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PacketWrapper packet) throws Exception
|
||||
{
|
||||
if ( packet.packet == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "Unexpected packet received during server login process!\n" + BufUtil.dump( packet.buf, 64 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(LoginSuccess loginSuccess) throws Exception
|
||||
{
|
||||
@@ -162,7 +175,7 @@ public class ServerConnector extends PacketHandler
|
||||
ServerConnectedEvent event = new ServerConnectedEvent( user, server );
|
||||
bungee.getPluginManager().callEvent( event );
|
||||
|
||||
ch.write( BungeeCord.getInstance().registerChannels() );
|
||||
ch.write( BungeeCord.getInstance().registerChannels( user.getPendingConnection().getVersion() ) );
|
||||
Queue<DefinedPacket> packetQueue = target.getPacketQueue();
|
||||
synchronized ( packetQueue )
|
||||
{
|
||||
@@ -201,7 +214,7 @@ public class ServerConnector extends PacketHandler
|
||||
|
||||
ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
|
||||
DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")", brand );
|
||||
user.unsafe().sendPacket( new PluginMessage( "MC|Brand", DefinedPacket.toArray( brand ), handshakeHandler.isServerForge() ) );
|
||||
user.unsafe().sendPacket( new PluginMessage( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand", DefinedPacket.toArray( brand ), handshakeHandler.isServerForge() ) );
|
||||
brand.release();
|
||||
|
||||
user.setDimension( login.getDimension() );
|
||||
@@ -213,7 +226,7 @@ public class ServerConnector extends PacketHandler
|
||||
Scoreboard serverScoreboard = user.getServerSentScoreboard();
|
||||
for ( Objective objective : serverScoreboard.getObjectives() )
|
||||
{
|
||||
user.unsafe().sendPacket( new ScoreboardObjective( objective.getName(), objective.getValue(), objective.getType(), (byte) 1 ) );
|
||||
user.unsafe().sendPacket( new ScoreboardObjective( objective.getName(), objective.getValue(), ScoreboardObjective.HealthDisplay.fromString( objective.getType() ), (byte) 1 ) );
|
||||
}
|
||||
for ( Score score : serverScoreboard.getScores() )
|
||||
{
|
||||
|
@@ -30,6 +30,7 @@ import net.md_5.bungee.netty.ChannelWrapper;
|
||||
import net.md_5.bungee.netty.PacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.PacketWrapper;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
import net.md_5.bungee.protocol.packet.BossBar;
|
||||
import net.md_5.bungee.protocol.packet.KeepAlive;
|
||||
import net.md_5.bungee.protocol.packet.PlayerListItem;
|
||||
@@ -125,7 +126,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
switch ( objective.getAction() )
|
||||
{
|
||||
case 0:
|
||||
serverScoreboard.addObjective( new Objective( objective.getName(), objective.getValue(), objective.getType() ) );
|
||||
serverScoreboard.addObjective( new Objective( objective.getName(), objective.getValue(), objective.getType().toString() ) );
|
||||
break;
|
||||
case 1:
|
||||
serverScoreboard.removeObjective( objective.getName() );
|
||||
@@ -135,7 +136,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
if ( oldObjective != null )
|
||||
{
|
||||
oldObjective.setValue( objective.getValue() );
|
||||
oldObjective.setType( objective.getType() );
|
||||
oldObjective.setType( objective.getType().toString() );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -231,7 +232,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
throw CancelSendSignal.INSTANCE;
|
||||
}
|
||||
|
||||
if ( pluginMessage.getTag().equals( "MC|Brand" ) )
|
||||
if ( pluginMessage.getTag().equals( con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand" ) )
|
||||
{
|
||||
ByteBuf brand = Unpooled.wrappedBuffer( pluginMessage.getData() );
|
||||
String serverBrand = DefinedPacket.readString( brand );
|
||||
@@ -476,6 +477,12 @@ public class DownstreamBridge extends PacketHandler
|
||||
@Override
|
||||
public void handle(TabCompleteResponse tabCompleteResponse) throws Exception
|
||||
{
|
||||
if ( tabCompleteResponse.getCommands() == null )
|
||||
{
|
||||
// Passthrough on 1.13 style command responses - unclear of a sane way to process them at the moment, contributions welcome
|
||||
return;
|
||||
}
|
||||
|
||||
TabCompleteResponseEvent tabCompleteResponseEvent = new TabCompleteResponseEvent( server, con, tabCompleteResponse.getCommands() );
|
||||
|
||||
if ( !bungee.getPluginManager().callEvent( tabCompleteResponseEvent ).isCancelled() )
|
||||
|
@@ -57,6 +57,7 @@ import net.md_5.bungee.protocol.packet.Handshake;
|
||||
import net.md_5.bungee.protocol.packet.Kick;
|
||||
import net.md_5.bungee.protocol.packet.LegacyHandshake;
|
||||
import net.md_5.bungee.protocol.packet.LegacyPing;
|
||||
import net.md_5.bungee.protocol.packet.LoginPayloadResponse;
|
||||
import net.md_5.bungee.protocol.packet.LoginRequest;
|
||||
import net.md_5.bungee.protocol.packet.LoginSuccess;
|
||||
import net.md_5.bungee.protocol.packet.PingPacket;
|
||||
@@ -64,6 +65,7 @@ import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||
import net.md_5.bungee.protocol.packet.StatusRequest;
|
||||
import net.md_5.bungee.protocol.packet.StatusResponse;
|
||||
import net.md_5.bungee.util.BoundedArrayList;
|
||||
import net.md_5.bungee.util.BufUtil;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
@@ -129,6 +131,15 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
disconnect( ChatColor.RED + Util.exception( t ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PacketWrapper packet) throws Exception
|
||||
{
|
||||
if ( packet.packet == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "Unexpected packet received during login process!\n" + BufUtil.dump( packet.buf, 64 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PluginMessage pluginMessage) throws Exception
|
||||
{
|
||||
@@ -532,6 +543,12 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
bungee.getPluginManager().callEvent( new LoginEvent( InitialHandler.this, complete ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(LoginPayloadResponse response) throws Exception
|
||||
{
|
||||
disconnect( "Unexpected custom LoginPayloadResponse" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(String reason)
|
||||
{
|
||||
|
@@ -13,10 +13,12 @@ import net.md_5.bungee.netty.PacketHandler;
|
||||
import net.md_5.bungee.netty.PipelineUtils;
|
||||
import net.md_5.bungee.protocol.MinecraftDecoder;
|
||||
import net.md_5.bungee.protocol.MinecraftEncoder;
|
||||
import net.md_5.bungee.protocol.PacketWrapper;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
import net.md_5.bungee.protocol.packet.Handshake;
|
||||
import net.md_5.bungee.protocol.packet.StatusRequest;
|
||||
import net.md_5.bungee.protocol.packet.StatusResponse;
|
||||
import net.md_5.bungee.util.BufUtil;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class PingHandler extends PacketHandler
|
||||
@@ -48,6 +50,15 @@ public class PingHandler extends PacketHandler
|
||||
callback.done( null, t );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PacketWrapper packet) throws Exception
|
||||
{
|
||||
if ( packet.packet == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "Unexpected packet received during ping process!\n" + BufUtil.dump( packet.buf, 64 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
|
||||
public void handle(StatusResponse statusResponse) throws Exception
|
||||
|
@@ -40,7 +40,7 @@ public class UpstreamBridge extends PacketHandler
|
||||
|
||||
BungeeCord.getInstance().addConnection( con );
|
||||
con.getTabListHandler().onConnect();
|
||||
con.unsafe().sendPacket( BungeeCord.getInstance().registerChannels() );
|
||||
con.unsafe().sendPacket( BungeeCord.getInstance().registerChannels( con.getPendingConnection().getVersion() ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -167,7 +167,12 @@ public class UpstreamBridge extends PacketHandler
|
||||
List<String> results = tabCompleteEvent.getSuggestions();
|
||||
if ( !results.isEmpty() )
|
||||
{
|
||||
con.unsafe().sendPacket( new TabCompleteResponse( results ) );
|
||||
// Unclear how to handle 1.13 commands at this point. Because we don't inject into the command packets we are unlikely to get this far unless
|
||||
// Bungee plugins are adding results for commands they don't own anyway
|
||||
if ( con.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_13 )
|
||||
{
|
||||
con.unsafe().sendPacket( new TabCompleteResponse( results ) );
|
||||
}
|
||||
throw CancelSendSignal.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
@@ -47,6 +47,8 @@ public abstract class EntityMap
|
||||
case ProtocolConstants.MINECRAFT_1_12_1:
|
||||
case ProtocolConstants.MINECRAFT_1_12_2:
|
||||
return EntityMap_1_12_1.INSTANCE;
|
||||
case ProtocolConstants.MINECRAFT_1_13:
|
||||
return EntityMap_1_13.INSTANCE;
|
||||
}
|
||||
throw new RuntimeException( "Version " + version + " has no entity map" );
|
||||
}
|
||||
@@ -76,11 +78,21 @@ public abstract class EntityMap
|
||||
rewrite( packet, oldId, newId, serverboundInts, serverboundVarInts );
|
||||
}
|
||||
|
||||
public void rewriteServerbound(ByteBuf packet, int oldId, int newId, int protocolVersion)
|
||||
{
|
||||
rewriteServerbound( packet, oldId, newId );
|
||||
}
|
||||
|
||||
public void rewriteClientbound(ByteBuf packet, int oldId, int newId)
|
||||
{
|
||||
rewrite( packet, oldId, newId, clientboundInts, clientboundVarInts );
|
||||
}
|
||||
|
||||
public void rewriteClientbound(ByteBuf packet, int oldId, int newId, int protocolVersion)
|
||||
{
|
||||
rewriteClientbound( packet, oldId, newId );
|
||||
}
|
||||
|
||||
protected static void rewriteInt(ByteBuf packet, int oldId, int newId, int offset)
|
||||
{
|
||||
int readId = packet.getInt( offset );
|
||||
@@ -111,6 +123,11 @@ public abstract class EntityMap
|
||||
}
|
||||
|
||||
protected static void rewriteMetaVarInt(ByteBuf packet, int oldId, int newId, int metaIndex)
|
||||
{
|
||||
rewriteMetaVarInt( packet, oldId, newId, metaIndex, -1 );
|
||||
}
|
||||
|
||||
protected static void rewriteMetaVarInt(ByteBuf packet, int oldId, int newId, int metaIndex, int protocolVersion)
|
||||
{
|
||||
int readerIndex = packet.readerIndex();
|
||||
|
||||
@@ -118,6 +135,37 @@ public abstract class EntityMap
|
||||
while ( ( index = packet.readUnsignedByte() ) != 0xFF )
|
||||
{
|
||||
int type = DefinedPacket.readVarInt( packet );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
case 5: // optional chat
|
||||
if ( packet.readBoolean() )
|
||||
{
|
||||
DefinedPacket.readString( packet );
|
||||
}
|
||||
break;
|
||||
case 14: // particle
|
||||
int particleId = DefinedPacket.readVarInt( packet );
|
||||
switch ( particleId )
|
||||
{
|
||||
case 3:
|
||||
case 20:
|
||||
DefinedPacket.readVarInt( packet ); // block state
|
||||
break;
|
||||
case 11: // dust
|
||||
packet.skipBytes( 16 ); // float, float, float, flat
|
||||
break;
|
||||
case 27: // item
|
||||
readSkipSlot( packet );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
type--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch ( type )
|
||||
{
|
||||
@@ -141,24 +189,7 @@ public abstract class EntityMap
|
||||
DefinedPacket.readString( packet );
|
||||
break;
|
||||
case 5:
|
||||
if ( packet.readShort() != -1 )
|
||||
{
|
||||
packet.skipBytes( 3 ); // byte, short
|
||||
|
||||
int position = packet.readerIndex();
|
||||
if ( packet.readByte() != 0 )
|
||||
{
|
||||
packet.readerIndex( position );
|
||||
|
||||
try
|
||||
{
|
||||
new NBTInputStream( new ByteBufInputStream( packet ), false ).readTag();
|
||||
} catch ( IOException ex )
|
||||
{
|
||||
throw Throwables.propagate( ex );
|
||||
}
|
||||
}
|
||||
}
|
||||
readSkipSlot( packet );
|
||||
break;
|
||||
case 6:
|
||||
packet.skipBytes( 1 ); // boolean
|
||||
@@ -204,6 +235,28 @@ public abstract class EntityMap
|
||||
packet.readerIndex( readerIndex );
|
||||
}
|
||||
|
||||
private static void readSkipSlot(ByteBuf packet)
|
||||
{
|
||||
if ( packet.readShort() != -1 )
|
||||
{
|
||||
packet.skipBytes( 3 ); // byte, short
|
||||
|
||||
int position = packet.readerIndex();
|
||||
if ( packet.readByte() != 0 )
|
||||
{
|
||||
packet.readerIndex( position );
|
||||
|
||||
try
|
||||
{
|
||||
new NBTInputStream( new ByteBufInputStream( packet ), false ).readTag();
|
||||
} catch ( IOException ex )
|
||||
{
|
||||
throw Throwables.propagate( ex );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handles simple packets
|
||||
private static void rewrite(ByteBuf packet, int oldId, int newId, boolean[] ints, boolean[] varints)
|
||||
{
|
||||
|
@@ -0,0 +1,183 @@
|
||||
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_13 extends EntityMap
|
||||
{
|
||||
|
||||
static final EntityMap_1_13 INSTANCE = new EntityMap_1_13();
|
||||
|
||||
EntityMap_1_13()
|
||||
{
|
||||
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( 0x1C, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Status : PacketPlayOutEntityStatus
|
||||
addRewrite( 0x27, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity : PacketPlayOutEntity
|
||||
addRewrite( 0x28, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Relative Move : PacketPlayOutRelEntityMove
|
||||
addRewrite( 0x29, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look and Relative Move : PacketPlayOutRelEntityMoveLook
|
||||
addRewrite( 0x2A, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look : PacketPlayOutEntityLook
|
||||
addRewrite( 0x33, ProtocolConstants.Direction.TO_CLIENT, true ); // Use bed : PacketPlayOutBed
|
||||
addRewrite( 0x36, ProtocolConstants.Direction.TO_CLIENT, true ); // Remove Entity Effect : PacketPlayOutRemoveEntityEffect
|
||||
addRewrite( 0x39, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Head Look : PacketPlayOutEntityHeadRotation
|
||||
addRewrite( 0x3C, ProtocolConstants.Direction.TO_CLIENT, true ); // Camera : PacketPlayOutCamera
|
||||
addRewrite( 0x3F, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Metadata : PacketPlayOutEntityMetadata
|
||||
addRewrite( 0x40, ProtocolConstants.Direction.TO_CLIENT, false ); // Attach Entity : PacketPlayOutAttachEntity
|
||||
addRewrite( 0x41, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Velocity : PacketPlayOutEntityVelocity
|
||||
addRewrite( 0x42, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Equipment : PacketPlayOutEntityEquipment
|
||||
addRewrite( 0x46, ProtocolConstants.Direction.TO_CLIENT, true ); // Set Passengers : PacketPlayOutMount
|
||||
addRewrite( 0x4F, ProtocolConstants.Direction.TO_CLIENT, true ); // Collect Item : PacketPlayOutCollect
|
||||
addRewrite( 0x50, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Teleport : PacketPlayOutEntityTeleport
|
||||
addRewrite( 0x52, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Properties : PacketPlayOutUpdateAttributes
|
||||
addRewrite( 0x53, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Effect : PacketPlayOutEntityEffect
|
||||
|
||||
addRewrite( 0x0D, ProtocolConstants.Direction.TO_SERVER, true ); // Use Entity : PacketPlayInUseEntity
|
||||
addRewrite( 0x19, ProtocolConstants.Direction.TO_SERVER, true ); // Entity Action : PacketPlayInEntityAction
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
|
||||
public void rewriteClientbound(ByteBuf packet, int oldId, int newId, int protocolVersion)
|
||||
{
|
||||
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 0x40 /* Attach Entity : PacketPlayOutAttachEntity */:
|
||||
rewriteInt( packet, oldId, newId, readerIndex + packetIdLength + 4 );
|
||||
break;
|
||||
case 0x4F /* Collect Item : PacketPlayOutCollect */:
|
||||
DefinedPacket.readVarInt( packet );
|
||||
rewriteVarInt( packet, oldId, newId, packet.readerIndex() );
|
||||
break;
|
||||
case 0x46 /* Set Passengers : PacketPlayOutMount */:
|
||||
DefinedPacket.readVarInt( packet );
|
||||
jumpIndex = packet.readerIndex();
|
||||
// Fall through on purpose to int array of IDs
|
||||
case 0x35 /* 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 0x2F /* 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;
|
||||
case 0x3F /* EntityMetadata : PacketPlayOutEntityMetadata */:
|
||||
DefinedPacket.readVarInt( packet ); // Entity ID
|
||||
rewriteMetaVarInt( packet, oldId + 1, newId + 1, 6, protocolVersion ); // fishing hook
|
||||
rewriteMetaVarInt( packet, oldId, newId, 7, protocolVersion ); // fireworks (et al)
|
||||
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 == 0x28 /* 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 );
|
||||
}
|
||||
}
|
15
proxy/src/main/java/net/md_5/bungee/util/BufUtil.java
Normal file
15
proxy/src/main/java/net/md_5/bungee/util/BufUtil.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package net.md_5.bungee.util;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@NoArgsConstructor
|
||||
public class BufUtil
|
||||
{
|
||||
|
||||
public static String dump(ByteBuf buf, int maxLen)
|
||||
{
|
||||
return ByteBufUtil.hexDump( buf, 0, Math.min( buf.writerIndex(), maxLen ) );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user