Add support for 15w33c and multiple fallback servers
This commit is contained in:
@@ -27,7 +27,7 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
|
||||
{
|
||||
int packetId = DefinedPacket.readVarInt( in );
|
||||
|
||||
DefinedPacket packet = prot.createPacket( packetId );
|
||||
DefinedPacket packet = prot.createPacket( packetId, protocolVersion );
|
||||
if ( packet != null )
|
||||
{
|
||||
packet.read( in, prot.getDirection(), protocolVersion );
|
||||
|
@@ -20,7 +20,7 @@ public class MinecraftEncoder extends MessageToByteEncoder<DefinedPacket>
|
||||
protected void encode(ChannelHandlerContext ctx, DefinedPacket msg, ByteBuf out) throws Exception
|
||||
{
|
||||
Protocol.DirectionData prot = ( server ) ? protocol.TO_CLIENT : protocol.TO_SERVER;
|
||||
DefinedPacket.writeVarInt( prot.getId( msg.getClass() ), out );
|
||||
DefinedPacket.writeVarInt( prot.getId( msg.getClass(), protocolVersion ), out );
|
||||
msg.write( out, prot.getDirection(), protocolVersion );
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,11 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import gnu.trove.map.TIntIntMap;
|
||||
import gnu.trove.map.TIntObjectMap;
|
||||
import gnu.trove.map.TObjectIntMap;
|
||||
import gnu.trove.map.hash.TIntIntHashMap;
|
||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||
import gnu.trove.map.hash.TObjectIntHashMap;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
@@ -68,9 +72,9 @@ public enum Protocol
|
||||
|
||||
TO_SERVER.registerPacket( 0x00, KeepAlive.class );
|
||||
TO_SERVER.registerPacket( 0x01, Chat.class );
|
||||
TO_SERVER.registerPacket( 0x14, TabCompleteRequest.class );
|
||||
TO_SERVER.registerPacket( 0x15, ClientSettings.class );
|
||||
TO_SERVER.registerPacket( 0x17, PluginMessage.class );
|
||||
TO_SERVER.registerPacket( 0x14, 0x15, TabCompleteRequest.class );
|
||||
TO_SERVER.registerPacket( 0x15, 0x16, ClientSettings.class );
|
||||
TO_SERVER.registerPacket( 0x17, 0x18, PluginMessage.class );
|
||||
}
|
||||
},
|
||||
// 1
|
||||
@@ -119,8 +123,27 @@ public enum Protocol
|
||||
private final Class<? extends DefinedPacket>[] packetClasses = new Class[ MAX_PACKET_ID ];
|
||||
private final Constructor<? extends DefinedPacket>[] packetConstructors = new Constructor[ MAX_PACKET_ID ];
|
||||
|
||||
public final DefinedPacket createPacket(int id)
|
||||
private final TIntObjectMap<TIntIntMap> packetRemap = new TIntObjectHashMap<>();
|
||||
private final TIntObjectMap<TIntIntMap> packetRemapInv = new TIntObjectHashMap<>();
|
||||
|
||||
{
|
||||
packetRemap.put( ProtocolConstants.MINECRAFT_1_8, new TIntIntHashMap() );
|
||||
packetRemapInv.put( ProtocolConstants.MINECRAFT_1_8, new TIntIntHashMap() );
|
||||
packetRemap.put( ProtocolConstants.MINECRAFT_SNAPSHOT, new TIntIntHashMap() );
|
||||
packetRemapInv.put( ProtocolConstants.MINECRAFT_SNAPSHOT, new TIntIntHashMap() );
|
||||
}
|
||||
|
||||
public final DefinedPacket createPacket(int id, int protocol)
|
||||
{
|
||||
TIntIntMap remap = packetRemap.get( protocol );
|
||||
if ( remap != null )
|
||||
{
|
||||
if ( !remap.containsKey( id ) )
|
||||
{
|
||||
throw new BadPacketException( "No packet with id " + id );
|
||||
}
|
||||
id = remap.get( id );
|
||||
}
|
||||
if ( id > MAX_PACKET_ID )
|
||||
{
|
||||
throw new BadPacketException( "Packet with id " + id + " outside of range " );
|
||||
@@ -137,6 +160,11 @@ public enum Protocol
|
||||
}
|
||||
|
||||
protected final void registerPacket(int id, Class<? extends DefinedPacket> packetClass)
|
||||
{
|
||||
registerPacket( id, id, packetClass );
|
||||
}
|
||||
|
||||
protected final void registerPacket(int id, int newId, Class<? extends DefinedPacket> packetClass)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -147,6 +175,11 @@ public enum Protocol
|
||||
}
|
||||
packetClasses[id] = packetClass;
|
||||
packetMap.put( packetClass, id );
|
||||
|
||||
packetRemap.get( ProtocolConstants.MINECRAFT_1_8 ).put( id, id );
|
||||
packetRemapInv.get( ProtocolConstants.MINECRAFT_1_8 ).put(id, id);
|
||||
packetRemap.get( ProtocolConstants.MINECRAFT_SNAPSHOT ).put( newId, id );
|
||||
packetRemapInv.get( ProtocolConstants.MINECRAFT_SNAPSHOT ).put( id, newId );
|
||||
}
|
||||
|
||||
protected final void unregisterPacket(int id)
|
||||
@@ -156,11 +189,17 @@ public enum Protocol
|
||||
packetConstructors[id] = null;
|
||||
}
|
||||
|
||||
final int getId(Class<? extends DefinedPacket> packet)
|
||||
final int getId(Class<? extends DefinedPacket> packet, int protocol)
|
||||
{
|
||||
Preconditions.checkArgument( packetMap.containsKey( packet ), "Cannot get ID for packet " + packet );
|
||||
Preconditions.checkArgument(packetMap.containsKey(packet), "Cannot get ID for packet " + packet);
|
||||
|
||||
return packetMap.get( packet );
|
||||
int id = packetMap.get( packet );
|
||||
TIntIntMap remap = packetRemapInv.get( protocol );
|
||||
if ( remap != null )
|
||||
{
|
||||
return remap.get( id );
|
||||
}
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,16 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ProtocolConstants
|
||||
{
|
||||
public static final int MINECRAFT_1_8 = 47;
|
||||
public static final int MINECRAFT_SNAPSHOT = 54;
|
||||
public static final int MINECRAFT_SNAPSHOT = 57;
|
||||
public static final List<String> SUPPORTED_VERSIONS = Arrays.asList(
|
||||
"1.8.X",
|
||||
"15w33c"
|
||||
);
|
||||
|
||||
public enum Direction
|
||||
{
|
||||
|
@@ -18,19 +18,24 @@ public class ClientSettings extends DefinedPacket
|
||||
|
||||
private String locale;
|
||||
private byte viewDistance;
|
||||
private byte chatFlags;
|
||||
private int chatFlags;
|
||||
private boolean chatColours;
|
||||
private byte difficulty;
|
||||
private byte skinParts;
|
||||
private int mainHand;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
locale = readString( buf );
|
||||
viewDistance = buf.readByte();
|
||||
chatFlags = buf.readByte();
|
||||
chatFlags = protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT ? DefinedPacket.readVarInt( buf ) : buf.readUnsignedByte();
|
||||
chatColours = buf.readBoolean();
|
||||
skinParts = buf.readByte();
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
mainHand = DefinedPacket.readVarInt( buf );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,9 +43,19 @@ public class ClientSettings extends DefinedPacket
|
||||
{
|
||||
writeString( locale, buf );
|
||||
buf.writeByte( viewDistance );
|
||||
buf.writeByte( chatFlags );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
DefinedPacket.writeVarInt( chatFlags, buf );
|
||||
} else
|
||||
{
|
||||
buf.writeByte( chatFlags );
|
||||
}
|
||||
buf.writeBoolean( chatColours );
|
||||
buf.writeByte( skinParts );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
DefinedPacket.writeVarInt(mainHand, buf);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user