#1862: Support 1.7 pings
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Iterables;
|
||||
import gnu.trove.map.TIntObjectMap;
|
||||
import gnu.trove.map.TObjectIntMap;
|
||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||
@@ -217,8 +218,8 @@ public enum Protocol
|
||||
/*========================================================================*/
|
||||
public static final int MAX_PACKET_ID = 0xFF;
|
||||
/*========================================================================*/
|
||||
public final DirectionData TO_SERVER = new DirectionData( ProtocolConstants.Direction.TO_SERVER );
|
||||
public final DirectionData TO_CLIENT = new DirectionData( ProtocolConstants.Direction.TO_CLIENT );
|
||||
public final DirectionData TO_SERVER = new DirectionData(this, ProtocolConstants.Direction.TO_SERVER );
|
||||
public final DirectionData TO_CLIENT = new DirectionData(this, ProtocolConstants.Direction.TO_CLIENT );
|
||||
|
||||
@RequiredArgsConstructor
|
||||
private static class ProtocolData {
|
||||
@@ -242,6 +243,7 @@ public enum Protocol
|
||||
public static class DirectionData
|
||||
{
|
||||
|
||||
private final Protocol protocolPhase;
|
||||
private final TIntObjectMap<ProtocolData> protocols = new TIntObjectHashMap<>();
|
||||
{
|
||||
for ( int protocol : ProtocolConstants.SUPPORTED_VERSION_IDS )
|
||||
@@ -263,12 +265,22 @@ public enum Protocol
|
||||
@Getter
|
||||
private final ProtocolConstants.Direction direction;
|
||||
|
||||
public final DefinedPacket createPacket(int id, int protocol)
|
||||
private ProtocolData getProtocolData(int version)
|
||||
{
|
||||
ProtocolData protocolData = protocols.get( protocol );
|
||||
ProtocolData protocol = protocols.get( version );
|
||||
if ( protocol == null && ( protocolPhase == Protocol.HANDSHAKE || protocolPhase == Protocol.STATUS ) )
|
||||
{
|
||||
protocol = Iterables.getFirst( protocols.valueCollection(), null );
|
||||
}
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public final DefinedPacket createPacket(int id, int version)
|
||||
{
|
||||
ProtocolData protocolData = getProtocolData( version );
|
||||
if (protocolData == null)
|
||||
{
|
||||
throw new BadPacketException( "Unsupported protocol" );
|
||||
throw new BadPacketException( "Unsupported protocol version" );
|
||||
}
|
||||
if ( id > MAX_PACKET_ID )
|
||||
{
|
||||
@@ -319,13 +331,13 @@ public enum Protocol
|
||||
}
|
||||
}
|
||||
|
||||
final int getId(Class<? extends DefinedPacket> packet, int protocol)
|
||||
final int getId(Class<? extends DefinedPacket> packet, int version)
|
||||
{
|
||||
|
||||
ProtocolData protocolData = protocols.get( protocol );
|
||||
ProtocolData protocolData = getProtocolData( version );
|
||||
if (protocolData == null)
|
||||
{
|
||||
throw new BadPacketException( "Unsupported protocol" );
|
||||
throw new BadPacketException( "Unsupported protocol version" );
|
||||
}
|
||||
Preconditions.checkArgument( protocolData.packetMap.containsKey( packet ), "Cannot get ID for packet " + packet );
|
||||
|
||||
|
Reference in New Issue
Block a user