Replace literal numbers with usages of the ProtocolConstants class.

This commit is contained in:
md_5 2014-04-16 10:18:16 +10:00
parent 994a996981
commit bc2b4db419
6 changed files with 21 additions and 8 deletions

View File

@ -93,7 +93,7 @@ public enum Protocol
}; };
/*========================================================================*/ /*========================================================================*/
public static final int MAX_PACKET_ID = 0xFF; public static final int MAX_PACKET_ID = 0xFF;
public static List<Integer> supportedVersions = Arrays.asList( 4, 5, 8 ); public static List<Integer> supportedVersions = Arrays.asList( ProtocolConstants.MINECRAFT_1_7_2, ProtocolConstants.MINECRAFT_1_7_6 );
/*========================================================================*/ /*========================================================================*/
public final ProtocolDirection TO_SERVER = new ProtocolDirection( "TO_SERVER" ); public final ProtocolDirection TO_SERVER = new ProtocolDirection( "TO_SERVER" );
public final ProtocolDirection TO_CLIENT = new ProtocolDirection( "TO_CLIENT" ); public final ProtocolDirection TO_CLIENT = new ProtocolDirection( "TO_CLIENT" );

View File

@ -0,0 +1,9 @@
package net.md_5.bungee.protocol;
public class ProtocolConstants
{
public static int MINECRAFT_1_7_2 = 4;
public static int MINECRAFT_1_7_6 = 5;
public static int MINECRAFT_14_11_a = 14;
}

View File

@ -65,6 +65,7 @@ import net.md_5.bungee.log.LoggingOutputStream;
import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.netty.PipelineUtils;
import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.Protocol; 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.Chat;
import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.PluginMessage;
import net.md_5.bungee.query.RemoteQuery; import net.md_5.bungee.query.RemoteQuery;
@ -127,10 +128,10 @@ public class BungeeCord extends ProxyServer
@Getter @Getter
private final Logger logger; private final Logger logger;
public final Gson gson = new GsonBuilder() public final Gson gson = new GsonBuilder()
.registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer( 5 ) ) .registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer( ProtocolConstants.MINECRAFT_1_7_6 ) )
.registerTypeAdapter( Favicon.class, Favicon.getFaviconTypeAdapter() ).create(); .registerTypeAdapter( Favicon.class, Favicon.getFaviconTypeAdapter() ).create();
public final Gson gsonLegacy = new GsonBuilder() public final Gson gsonLegacy = new GsonBuilder()
.registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer( 4 ) ) .registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer( ProtocolConstants.MINECRAFT_1_7_2 ) )
.registerTypeAdapter( Favicon.class, Favicon.getFaviconTypeAdapter() ).create(); .registerTypeAdapter( Favicon.class, Favicon.getFaviconTypeAdapter() ).create();
@Getter @Getter
private ConnectionThrottle connectionThrottle; private ConnectionThrottle connectionThrottle;

View File

@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.connection.LoginResult; import net.md_5.bungee.connection.LoginResult;
import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;
import net.md_5.bungee.protocol.packet.LoginRequest; import net.md_5.bungee.protocol.packet.LoginRequest;
/** /**
@ -143,7 +144,7 @@ public class EntityMap
} }
} }
} }
} else if ( packetId == 0x0C /* Spawn Player */ && version == 5 ) } else if ( packetId == 0x0C /* Spawn Player */ && version == ProtocolConstants.MINECRAFT_1_7_6 )
{ {
DefinedPacket.readVarInt( packet ); DefinedPacket.readVarInt( packet );
int idLength = packet.readerIndex() - readerIndex - packetIdLength; int idLength = packet.readerIndex() - readerIndex - packetIdLength;

View File

@ -48,6 +48,7 @@ import net.md_5.bungee.api.AbstractReconnectHandler;
import net.md_5.bungee.api.event.PlayerHandshakeEvent; import net.md_5.bungee.api.event.PlayerHandshakeEvent;
import net.md_5.bungee.api.event.PreLoginEvent; import net.md_5.bungee.api.event.PreLoginEvent;
import net.md_5.bungee.protocol.Protocol; 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.LegacyHandshake;
import net.md_5.bungee.protocol.packet.LegacyPing; import net.md_5.bungee.protocol.packet.LegacyPing;
import net.md_5.bungee.protocol.packet.LoginRequest; import net.md_5.bungee.protocol.packet.LoginRequest;
@ -166,7 +167,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
result = bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result ) ).getResponse(); result = bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result ) ).getResponse();
BungeeCord.getInstance().getConnectionThrottle().unthrottle( getAddress().getAddress() ); BungeeCord.getInstance().getConnectionThrottle().unthrottle( getAddress().getAddress() );
Gson gson = handshake.getProtocolVersion() == 4 ? BungeeCord.getInstance().gsonLegacy : BungeeCord.getInstance().gson; Gson gson = handshake.getProtocolVersion() == ProtocolConstants.MINECRAFT_1_7_2 ? BungeeCord.getInstance().gsonLegacy : BungeeCord.getInstance().gson;
unsafe.sendPacket( new StatusResponse( gson.toJson( result ) ) ); unsafe.sendPacket( new StatusResponse( gson.toJson( result ) ) );
} }
}; };
@ -381,8 +382,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{ {
uniqueId = offlineId; uniqueId = offlineId;
} }
// Version 5 == 1.7.6. This is a screwup as 1.7.6 was also a snapshot.
if ( getVersion() == 5 ) if ( getVersion() == ProtocolConstants.MINECRAFT_1_7_6 )
{ {
unsafe.sendPacket( new LoginSuccess( getUniqueId().toString(), getName() ) ); // With dashes in between unsafe.sendPacket( new LoginSuccess( getUniqueId().toString(), getName() ) ); // With dashes in between
} else } else

View File

@ -13,6 +13,7 @@ import net.md_5.bungee.netty.PipelineUtils;
import net.md_5.bungee.protocol.MinecraftDecoder; import net.md_5.bungee.protocol.MinecraftDecoder;
import net.md_5.bungee.protocol.MinecraftEncoder; import net.md_5.bungee.protocol.MinecraftEncoder;
import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.Protocol;
import net.md_5.bungee.protocol.ProtocolConstants;
import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.Handshake;
import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusRequest;
import net.md_5.bungee.protocol.packet.StatusResponse; import net.md_5.bungee.protocol.packet.StatusResponse;
@ -50,7 +51,7 @@ public class PingHandler extends PacketHandler
@Override @Override
public void handle(StatusResponse statusResponse) throws Exception public void handle(StatusResponse statusResponse) throws Exception
{ {
Gson gson = protocol == 4 ? BungeeCord.getInstance().gsonLegacy : BungeeCord.getInstance().gson; Gson gson = protocol == ProtocolConstants.MINECRAFT_1_7_2 ? BungeeCord.getInstance().gsonLegacy : BungeeCord.getInstance().gson;
callback.done( gson.fromJson( statusResponse.getResponse(), ServerPing.class ), null ); callback.done( gson.fromJson( statusResponse.getResponse(), ServerPing.class ), null );
channel.close(); channel.close();
} }