Support Minecraft 1.9.4 and tidy up packet handling
This commit is contained in:
@@ -15,7 +15,6 @@ import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||
import net.md_5.bungee.chat.TextComponentSerializer;
|
||||
import net.md_5.bungee.chat.TranslatableComponentSerializer;
|
||||
import net.md_5.bungee.module.ModuleManager;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
@@ -58,9 +57,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import jline.UnsupportedTerminal;
|
||||
import jline.console.ConsoleReader;
|
||||
import jline.internal.Log;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.Synchronized;
|
||||
@@ -80,7 +77,6 @@ import net.md_5.bungee.forge.ForgeConstants;
|
||||
import net.md_5.bungee.log.LoggingOutputStream;
|
||||
import net.md_5.bungee.netty.PipelineUtils;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
import net.md_5.bungee.protocol.packet.Chat;
|
||||
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||
@@ -590,7 +586,7 @@ public class BungeeCord extends ProxyServer
|
||||
@Override
|
||||
public int getProtocolVersion()
|
||||
{
|
||||
return Protocol.supportedVersions.get( Protocol.supportedVersions.size() - 1 );
|
||||
return ProtocolConstants.SUPPORTED_VERSION_IDS.get( ProtocolConstants.SUPPORTED_VERSION_IDS.size() - 1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -6,12 +6,10 @@ import java.math.BigInteger;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import lombok.Getter;
|
||||
@@ -20,7 +18,6 @@ import net.md_5.bungee.*;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.Favicon;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
@@ -41,6 +38,7 @@ import net.md_5.bungee.netty.cipher.CipherDecoder;
|
||||
import net.md_5.bungee.netty.cipher.CipherEncoder;
|
||||
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.Handshake;
|
||||
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||
import net.md_5.bungee.protocol.packet.EncryptionResponse;
|
||||
@@ -51,7 +49,6 @@ import net.md_5.bungee.api.event.PlayerHandshakeEvent;
|
||||
import net.md_5.bungee.api.event.PreLoginEvent;
|
||||
import net.md_5.bungee.jni.cipher.BungeeCipher;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
import net.md_5.bungee.protocol.packet.LegacyHandshake;
|
||||
import net.md_5.bungee.protocol.packet.LegacyPing;
|
||||
import net.md_5.bungee.protocol.packet.LoginRequest;
|
||||
@@ -235,7 +232,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
( (BungeeServerInfo) forced ).ping( pingBack, handshake.getProtocolVersion() );
|
||||
} else
|
||||
{
|
||||
int protocol = ( Protocol.supportedVersions.contains( handshake.getProtocolVersion() ) ) ? handshake.getProtocolVersion() : bungee.getProtocolVersion();
|
||||
int protocol = ( ProtocolConstants.SUPPORTED_VERSION_IDS.contains( handshake.getProtocolVersion() ) ) ? handshake.getProtocolVersion() : bungee.getProtocolVersion();
|
||||
pingBack.done( new ServerPing(
|
||||
new ServerPing.Protocol( bungee.getName() + " " + bungee.getGameVersion(), protocol ),
|
||||
new ServerPing.Players( listener.getMaxPlayers(), bungee.getOnlineCount(), null ),
|
||||
@@ -312,7 +309,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
Preconditions.checkState( thisState == State.USERNAME, "Not expecting USERNAME" );
|
||||
this.loginRequest = loginRequest;
|
||||
|
||||
if ( !Protocol.supportedVersions.contains( handshake.getProtocolVersion() ) )
|
||||
if ( !ProtocolConstants.SUPPORTED_VERSION_IDS.contains( handshake.getProtocolVersion() ) )
|
||||
{
|
||||
disconnect( bungee.getTranslation( "outdated_server" ) );
|
||||
return;
|
||||
|
@@ -31,6 +31,8 @@ public abstract class EntityMap
|
||||
case ProtocolConstants.MINECRAFT_1_9_1:
|
||||
case ProtocolConstants.MINECRAFT_1_9_2:
|
||||
return EntityMap_1_9.INSTANCE;
|
||||
case ProtocolConstants.MINECRAFT_1_9_4:
|
||||
return EntityMap_1_9_4.INSTANCE;
|
||||
}
|
||||
throw new RuntimeException( "Version " + version + " has no entity map" );
|
||||
}
|
||||
|
@@ -0,0 +1,174 @@
|
||||
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_9_4 extends EntityMap
|
||||
{
|
||||
|
||||
static final EntityMap_1_9_4 INSTANCE = new EntityMap_1_9_4();
|
||||
|
||||
EntityMap_1_9_4()
|
||||
{
|
||||
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( 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 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 );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user