Remove 1.7.x Support

This commit is contained in:
Thinkofdeath 2016-03-01 09:13:12 +11:00 committed by md_5
parent 219819b738
commit dfaa687f71
29 changed files with 165 additions and 547 deletions

View File

@ -33,36 +33,6 @@ public abstract class DefinedPacket
return new String( b, Charsets.UTF_8 ); return new String( b, Charsets.UTF_8 );
} }
public static void writeArrayLegacy(byte[] b, ByteBuf buf, boolean allowExtended)
{
// (Integer.MAX_VALUE & 0x1FFF9A ) = 2097050 - Forge's current upper limit
if ( allowExtended )
{
Preconditions.checkArgument( b.length <= ( Integer.MAX_VALUE & 0x1FFF9A ), "Cannot send array longer than 2097050 (got %s bytes)", b.length );
} else
{
Preconditions.checkArgument( b.length <= Short.MAX_VALUE, "Cannot send array longer than Short.MAX_VALUE (got %s bytes)", b.length );
}
// Write a 2 or 3 byte number that represents the length of the packet. (3 byte "shorts" for Forge only)
// No vanilla packet should give a 3 byte packet, this method will still retain vanilla behaviour.
writeVarShort( buf, b.length );
buf.writeBytes( b );
}
public static byte[] readArrayLegacy(ByteBuf buf)
{
// Read in a 2 or 3 byte number that represents the length of the packet. (3 byte "shorts" for Forge only)
// No vanilla packet should give a 3 byte packet, this method will still retain vanilla behaviour.
int len = readVarShort( buf );
// (Integer.MAX_VALUE & 0x1FFF9A ) = 2097050 - Forge's current upper limit
Preconditions.checkArgument( len <= ( Integer.MAX_VALUE & 0x1FFF9A ), "Cannot receive array longer than 2097050 (got %s bytes)", len );
byte[] ret = new byte[ len ];
buf.readBytes( ret );
return ret;
}
public static void writeArray(byte[] b, ByteBuf buf) public static void writeArray(byte[] b, ByteBuf buf)
{ {
writeVarInt( b.length, buf ); writeVarInt( b.length, buf );

View File

@ -1,38 +0,0 @@
package net.md_5.bungee.protocol;
import io.netty.buffer.ByteBuf;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public class MinecraftInput
{
private final ByteBuf buf;
public byte readByte()
{
return buf.readByte();
}
public short readUnsignedByte()
{
return buf.readUnsignedByte();
}
public int readInt()
{
return buf.readInt();
}
public String readString()
{
short len = buf.readShort();
char[] c = new char[ len ];
for ( int i = 0; i < c.length; i++ )
{
c[i] = buf.readChar();
}
return new String( c );
}
}

View File

@ -1,56 +0,0 @@
package net.md_5.bungee.protocol;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.nio.charset.Charset;
import java.util.Arrays;
public class MinecraftOutput
{
private final ByteBuf buf;
public MinecraftOutput()
{
buf = Unpooled.buffer();
}
public byte[] toArray()
{
if ( buf.hasArray() )
{
return Arrays.copyOfRange( buf.array(), buf.arrayOffset(), buf.arrayOffset() + buf.writerIndex() );
} else
{
byte[] b = new byte[ buf.writerIndex() ];
buf.readBytes( b );
return b;
}
}
public MinecraftOutput writeByte(byte b)
{
buf.writeByte( b );
return this;
}
public void writeInt(int i)
{
buf.writeInt( i );
}
public void writeString(String s)
{
char[] cc = s.toCharArray();
buf.writeShort( cc.length );
for ( char c : cc )
{
buf.writeChar( c );
}
}
public void writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket(String s)
{
buf.writeBytes( s.getBytes( Charset.forName( "UTF-8" ) ) );
}
}

View File

@ -102,9 +102,8 @@ 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( public static List<Integer> supportedVersions = Arrays.asList(
ProtocolConstants.MINECRAFT_1_7_2, ProtocolConstants.MINECRAFT_1_8,
ProtocolConstants.MINECRAFT_1_7_6, ProtocolConstants.MINECRAFT_SNAPSHOT
ProtocolConstants.MINECRAFT_1_8
); );
/*========================================================================*/ /*========================================================================*/
public final DirectionData TO_SERVER = new DirectionData( ProtocolConstants.Direction.TO_SERVER ); public final DirectionData TO_SERVER = new DirectionData( ProtocolConstants.Direction.TO_SERVER );

View File

@ -2,10 +2,8 @@ package net.md_5.bungee.protocol;
public class ProtocolConstants public class ProtocolConstants
{ {
public static final int MINECRAFT_1_7_2 = 4;
public static final int MINECRAFT_1_7_6 = 5;
public static final int MINECRAFT_1_8 = 47; public static final int MINECRAFT_1_8 = 47;
public static final int MINECRAFT_SNAPSHOT = 54;
public enum Direction public enum Direction
{ {

View File

@ -28,7 +28,7 @@ public class Chat extends DefinedPacket
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{ {
message = readString( buf ); message = readString( buf );
if ( direction == ProtocolConstants.Direction.TO_CLIENT && protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) if ( direction == ProtocolConstants.Direction.TO_CLIENT )
{ {
position = buf.readByte(); position = buf.readByte();
} }
@ -38,7 +38,7 @@ public class Chat extends DefinedPacket
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{ {
writeString( message, buf ); writeString( message, buf );
if ( direction == ProtocolConstants.Direction.TO_CLIENT && protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) if ( direction == ProtocolConstants.Direction.TO_CLIENT )
{ {
buf.writeByte( position ); buf.writeByte( position );
} }

View File

@ -30,10 +30,6 @@ public class ClientSettings extends DefinedPacket
viewDistance = buf.readByte(); viewDistance = buf.readByte();
chatFlags = buf.readByte(); chatFlags = buf.readByte();
chatColours = buf.readBoolean(); chatColours = buf.readBoolean();
if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_7_6 )
{
difficulty = buf.readByte();
}
skinParts = buf.readByte(); skinParts = buf.readByte();
} }
@ -44,10 +40,6 @@ public class ClientSettings extends DefinedPacket
buf.writeByte( viewDistance ); buf.writeByte( viewDistance );
buf.writeByte( chatFlags ); buf.writeByte( chatFlags );
buf.writeBoolean( chatColours ); buf.writeBoolean( chatColours );
if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_7_6 )
{
buf.writeByte( difficulty );
}
buf.writeByte( skinParts ); buf.writeByte( skinParts );
} }

View File

@ -24,31 +24,17 @@ public class EncryptionRequest extends DefinedPacket
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{ {
serverId = readString( buf ); serverId = readString( buf );
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 )
{
publicKey = readArrayLegacy( buf );
verifyToken = readArrayLegacy( buf );
} else
{
publicKey = readArray( buf ); publicKey = readArray( buf );
verifyToken = readArray( buf ); verifyToken = readArray( buf );
} }
}
@Override @Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{ {
writeString( serverId, buf ); writeString( serverId, buf );
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 )
{
writeArrayLegacy( publicKey, buf, false );
writeArrayLegacy( verifyToken, buf, false );
} else
{
writeArray( publicKey, buf ); writeArray( publicKey, buf );
writeArray( verifyToken, buf ); writeArray( verifyToken, buf );
} }
}
@Override @Override
public void handle(AbstractPacketHandler handler) throws Exception public void handle(AbstractPacketHandler handler) throws Exception

View File

@ -21,31 +21,17 @@ public class EncryptionResponse extends DefinedPacket
@Override @Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 )
{
sharedSecret = readArrayLegacy( buf );
verifyToken = readArrayLegacy( buf );
} else
{ {
sharedSecret = readArray( buf ); sharedSecret = readArray( buf );
verifyToken = readArray( buf ); verifyToken = readArray( buf );
} }
}
@Override @Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 )
{
writeArrayLegacy( sharedSecret, buf, false );
writeArrayLegacy( verifyToken, buf, false );
} else
{ {
writeArray( sharedSecret, buf ); writeArray( sharedSecret, buf );
writeArray( verifyToken, buf ); writeArray( verifyToken, buf );
} }
}
@Override @Override
public void handle(AbstractPacketHandler handler) throws Exception public void handle(AbstractPacketHandler handler) throws Exception

View File

@ -20,26 +20,14 @@ public class KeepAlive extends DefinedPacket
@Override @Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 )
{ {
randomId = readVarInt( buf ); randomId = readVarInt( buf );
} else
{
randomId = buf.readInt();
}
} }
@Override @Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 )
{ {
writeVarInt( randomId, buf ); writeVarInt( randomId, buf );
} else
{
buf.writeInt( randomId );
}
} }
@Override @Override

View File

@ -21,15 +21,6 @@ public class PlayerListItem extends DefinedPacket
@Override @Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 )
{
items = new Item[ 1 ];
Item item = items[ 0 ] = new Item();
item.displayName = item.username = readString( buf );
action = !buf.readBoolean() ? Action.REMOVE_PLAYER : Action.ADD_PLAYER;
item.ping = buf.readShort();
} else
{ {
action = Action.values()[ DefinedPacket.readVarInt( buf )]; action = Action.values()[ DefinedPacket.readVarInt( buf )];
items = new Item[ DefinedPacket.readVarInt( buf ) ]; items = new Item[ DefinedPacket.readVarInt( buf ) ];
@ -81,18 +72,9 @@ public class PlayerListItem extends DefinedPacket
} }
} }
} }
}
@Override @Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 )
{
Item item = items[0]; // Only one at a time
writeString( item.displayName, buf ); // TODO: Server unique only!
buf.writeBoolean( action != Action.REMOVE_PLAYER );
buf.writeShort( item.ping );
} else
{ {
DefinedPacket.writeVarInt( action.ordinal(), buf ); DefinedPacket.writeVarInt( action.ordinal(), buf );
DefinedPacket.writeVarInt( items.length, buf ); DefinedPacket.writeVarInt( items.length, buf );
@ -141,7 +123,6 @@ public class PlayerListItem extends DefinedPacket
} }
} }
} }
}
@Override @Override
public void handle(AbstractPacketHandler handler) throws Exception public void handle(AbstractPacketHandler handler) throws Exception

View File

@ -3,7 +3,6 @@ package net.md_5.bungee.protocol.packet;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.DefinedPacket;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.DataInput; import java.io.DataInput;
import java.io.DataInputStream; import java.io.DataInputStream;
@ -11,7 +10,6 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import net.md_5.bungee.protocol.MinecraftInput;
import net.md_5.bungee.protocol.AbstractPacketHandler; import net.md_5.bungee.protocol.AbstractPacketHandler;
import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.ProtocolConstants;
@ -34,30 +32,18 @@ public class PluginMessage extends DefinedPacket
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{ {
tag = readString( buf ); tag = readString( buf );
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 )
{
data = readArrayLegacy( buf );
} else
{
int maxSize = direction == ProtocolConstants.Direction.TO_SERVER ? Short.MAX_VALUE : 0x100000; int maxSize = direction == ProtocolConstants.Direction.TO_SERVER ? Short.MAX_VALUE : 0x100000;
Preconditions.checkArgument(buf.readableBytes() < maxSize); Preconditions.checkArgument(buf.readableBytes() < maxSize);
data = new byte[ buf.readableBytes() ]; data = new byte[ buf.readableBytes() ];
buf.readBytes( data ); buf.readBytes( data );
} }
}
@Override @Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{ {
writeString( tag, buf ); writeString( tag, buf );
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_8 )
{
writeArrayLegacy( data, buf, allowExtendedPacket );
} else
{
buf.writeBytes( data ); buf.writeBytes( data );
} }
}
@Override @Override
public void handle(AbstractPacketHandler handler) throws Exception public void handle(AbstractPacketHandler handler) throws Exception
@ -69,9 +55,4 @@ public class PluginMessage extends DefinedPacket
{ {
return new DataInputStream( new ByteArrayInputStream( data ) ); return new DataInputStream( new ByteArrayInputStream( data ) );
} }
public MinecraftInput getMCStream()
{
return new MinecraftInput( Unpooled.wrappedBuffer( data ) );
}
} }

View File

@ -28,12 +28,8 @@ public class ScoreboardObjective extends DefinedPacket
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{ {
name = readString( buf ); name = readString( buf );
if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_7_6 )
{
value = readString( buf );
}
action = buf.readByte(); action = buf.readByte();
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 && ( action == 0 || action == 2 ) ) if ( action == 0 || action == 2 )
{ {
value = readString( buf ); value = readString( buf );
type = readString( buf ); type = readString( buf );
@ -44,12 +40,8 @@ public class ScoreboardObjective extends DefinedPacket
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{ {
writeString( name, buf ); writeString( name, buf );
if ( protocolVersion <= ProtocolConstants.MINECRAFT_1_7_6 )
{
writeString( value, buf );
}
buf.writeByte( action ); buf.writeByte( action );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 && ( action == 0 || action == 2 ) ) if ( action == 0 || action == 2 )
{ {
writeString( value, buf ); writeString( value, buf );
writeString( type, buf ); writeString( type, buf );

View File

@ -29,21 +29,11 @@ public class ScoreboardScore extends DefinedPacket
{ {
itemName = readString( buf ); itemName = readString( buf );
action = buf.readByte(); action = buf.readByte();
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 )
{
scoreName = readString( buf ); scoreName = readString( buf );
if ( action != 1 ) if ( action != 1 )
{ {
value = readVarInt( buf ); value = readVarInt( buf );
} }
} else
{
if ( action != 1 )
{
scoreName = readString( buf );
value = buf.readInt();
}
}
} }
@Override @Override
@ -51,21 +41,11 @@ public class ScoreboardScore extends DefinedPacket
{ {
writeString( itemName, buf ); writeString( itemName, buf );
buf.writeByte( action ); buf.writeByte( action );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 )
{
writeString( scoreName, buf ); writeString( scoreName, buf );
if ( action != 1 ) if ( action != 1 )
{ {
writeVarInt( value, buf ); writeVarInt( value, buf );
} }
} else
{
if ( action != 1 )
{
writeString( scoreName, buf );
buf.writeInt( value );
}
}
} }
@Override @Override

View File

@ -24,28 +24,22 @@ public class TabCompleteRequest extends DefinedPacket
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{ {
cursor = readString( buf ); cursor = readString( buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 )
{
if ( hasPositon = buf.readBoolean() ) if ( hasPositon = buf.readBoolean() )
{ {
position = buf.readLong(); position = buf.readLong();
} }
} }
}
@Override @Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{ {
writeString( cursor, buf ); writeString( cursor, buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 )
{
buf.writeBoolean( hasPositon ); buf.writeBoolean( hasPositon );
if ( hasPositon ) if ( hasPositon )
{ {
buf.writeLong( position ); buf.writeLong( position );
} }
} }
}
@Override @Override
public void handle(AbstractPacketHandler handler) throws Exception public void handle(AbstractPacketHandler handler) throws Exception

View File

@ -50,15 +50,12 @@ public class Team extends DefinedPacket
prefix = readString( buf ); prefix = readString( buf );
suffix = readString( buf ); suffix = readString( buf );
friendlyFire = buf.readByte(); friendlyFire = buf.readByte();
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 )
{
nameTagVisibility = readString( buf ); nameTagVisibility = readString( buf );
color = buf.readByte(); color = buf.readByte();
} }
}
if ( mode == 0 || mode == 3 || mode == 4 ) if ( mode == 0 || mode == 3 || mode == 4 )
{ {
int len = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 ) ? readVarInt( buf ) : buf.readShort(); int len = readVarInt( buf );
players = new String[ len ]; players = new String[ len ];
for ( int i = 0; i < len; i++ ) for ( int i = 0; i < len; i++ )
{ {
@ -78,21 +75,12 @@ public class Team extends DefinedPacket
writeString( prefix, buf ); writeString( prefix, buf );
writeString( suffix, buf ); writeString( suffix, buf );
buf.writeByte( friendlyFire ); buf.writeByte( friendlyFire );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 )
{
writeString( nameTagVisibility, buf ); writeString( nameTagVisibility, buf );
buf.writeByte( color ); buf.writeByte( color );
} }
}
if ( mode == 0 || mode == 3 || mode == 4 ) if ( mode == 0 || mode == 3 || mode == 4 )
{
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 )
{ {
writeVarInt( players.length, buf ); writeVarInt( players.length, buf );
} else
{
buf.writeShort( players.length );
}
for ( String player : players ) for ( String player : players )
{ {
writeString( player, buf ); writeString( player, buf );

View File

@ -139,10 +139,7 @@ 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( ProtocolConstants.MINECRAFT_1_7_6 ) ) .registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer() )
.registerTypeAdapter( Favicon.class, Favicon.getFaviconTypeAdapter() ).create();
public final Gson gsonLegacy = new GsonBuilder()
.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

@ -152,16 +152,11 @@ public class BungeeTitle implements Title
@Override @Override
public Title send(ProxiedPlayer player) public Title send(ProxiedPlayer player)
{ {
if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 )
{
// Send the packets in the correct order
sendPacket( player, clear ); sendPacket( player, clear );
sendPacket( player, reset ); sendPacket( player, reset );
sendPacket( player, times ); sendPacket( player, times );
sendPacket( player, subtitle ); sendPacket( player, subtitle );
sendPacket( player, title ); sendPacket( player, title );
}
return this; return this;
} }
} }

View File

@ -14,21 +14,13 @@ import java.util.UUID;
public class PlayerInfoSerializer implements JsonSerializer<ServerPing.PlayerInfo>, JsonDeserializer<ServerPing.PlayerInfo> public class PlayerInfoSerializer implements JsonSerializer<ServerPing.PlayerInfo>, JsonDeserializer<ServerPing.PlayerInfo>
{ {
private final int protocol;
public PlayerInfoSerializer(int protocol)
{
this.protocol = protocol;
}
@Override @Override
public ServerPing.PlayerInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException public ServerPing.PlayerInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{ {
JsonObject js = json.getAsJsonObject(); JsonObject js = json.getAsJsonObject();
ServerPing.PlayerInfo info = new ServerPing.PlayerInfo( js.get( "name" ).getAsString(), (UUID) null ); ServerPing.PlayerInfo info = new ServerPing.PlayerInfo( js.get( "name" ).getAsString(), (UUID) null );
String id = js.get( "id" ).getAsString(); String id = js.get( "id" ).getAsString();
if ( protocol == 4 || !id.contains( "-" ) ) if ( !id.contains( "-" ) )
{ {
info.setId( id ); info.setId( id );
} else } else
@ -43,13 +35,7 @@ public class PlayerInfoSerializer implements JsonSerializer<ServerPing.PlayerInf
{ {
JsonObject out = new JsonObject(); JsonObject out = new JsonObject();
out.addProperty( "name", src.getName() ); out.addProperty( "name", src.getName() );
if ( protocol == 4 )
{
out.addProperty( "id", src.getId() );
} else
{
out.addProperty( "id", src.getUniqueId().toString() ); out.addProperty( "id", src.getUniqueId().toString() );
}
return out; return out;
} }
} }

View File

@ -28,7 +28,6 @@ import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.HandlerBoss; import net.md_5.bungee.netty.HandlerBoss;
import net.md_5.bungee.netty.PacketHandler; import net.md_5.bungee.netty.PacketHandler;
import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.MinecraftOutput;
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.ProtocolConstants;
import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.EncryptionRequest;
@ -193,18 +192,10 @@ public class ServerConnector extends PacketHandler
user.unsafe().sendPacket( modLogin ); user.unsafe().sendPacket( modLogin );
if ( user.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_8 )
{
MinecraftOutput out = new MinecraftOutput();
out.writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket( ProxyServer.getInstance().getName() + " (" + ProxyServer.getInstance().getVersion() + ")" );
user.unsafe().sendPacket( new PluginMessage( "MC|Brand", out.toArray(), handshakeHandler.isServerForge() ) );
} else
{
ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer(); ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")", brand ); DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")", brand );
user.unsafe().sendPacket( new PluginMessage( "MC|Brand", brand.array().clone(), handshakeHandler.isServerForge() ) ); user.unsafe().sendPacket( new PluginMessage( "MC|Brand", brand.array().clone(), handshakeHandler.isServerForge() ) );
brand.release(); brand.release();
}
} else } else
{ {
user.getServer().setObsolete( true ); user.getServer().setObsolete( true );

View File

@ -391,7 +391,7 @@ public final class UserConnection implements ProxiedPlayer
public void sendMessage(ChatMessageType position, BaseComponent... message) public void sendMessage(ChatMessageType position, BaseComponent... message)
{ {
// Action bar doesn't display the new JSON formattings, legacy works - send it using this for now // Action bar doesn't display the new JSON formattings, legacy works - send it using this for now
if ( position == ChatMessageType.ACTION_BAR && pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_1_8 ) if ( position == ChatMessageType.ACTION_BAR )
{ {
sendMessage( position, ComponentSerializer.toString( new TextComponent( TextComponent.toLegacyText( message ) ) ) ); sendMessage( position, ComponentSerializer.toString( new TextComponent( TextComponent.toLegacyText( message ) ) ) );
} else } else
@ -404,7 +404,7 @@ public final class UserConnection implements ProxiedPlayer
public void sendMessage(ChatMessageType position, BaseComponent message) public void sendMessage(ChatMessageType position, BaseComponent message)
{ {
// Action bar doesn't display the new JSON formattings, legacy works - send it using this for now // Action bar doesn't display the new JSON formattings, legacy works - send it using this for now
if ( position == ChatMessageType.ACTION_BAR && pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_1_8 ) if ( position == ChatMessageType.ACTION_BAR )
{ {
sendMessage( position, ComponentSerializer.toString( new TextComponent( TextComponent.toLegacyText( message ) ) ) ); sendMessage( position, ComponentSerializer.toString( new TextComponent( TextComponent.toLegacyText( message ) ) ) );
} else } else
@ -540,27 +540,21 @@ public final class UserConnection implements ProxiedPlayer
@Override @Override
public void setTabHeader(BaseComponent header, BaseComponent footer) public void setTabHeader(BaseComponent header, BaseComponent footer)
{
if ( pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_1_8 )
{ {
unsafe().sendPacket( new PlayerListHeaderFooter( unsafe().sendPacket( new PlayerListHeaderFooter(
( header != null ) ? ComponentSerializer.toString( header ) : EMPTY_TEXT, ( header != null ) ? ComponentSerializer.toString( header ) : EMPTY_TEXT,
( footer != null ) ? ComponentSerializer.toString( footer ) : EMPTY_TEXT ( footer != null ) ? ComponentSerializer.toString( footer ) : EMPTY_TEXT
) ); ) );
} }
}
@Override @Override
public void setTabHeader(BaseComponent[] header, BaseComponent[] footer) public void setTabHeader(BaseComponent[] header, BaseComponent[] footer)
{
if ( pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_1_8 )
{ {
unsafe().sendPacket( new PlayerListHeaderFooter( unsafe().sendPacket( new PlayerListHeaderFooter(
( header != null ) ? ComponentSerializer.toString( header ) : EMPTY_TEXT, ( header != null ) ? ComponentSerializer.toString( header ) : EMPTY_TEXT,
( footer != null ) ? ComponentSerializer.toString( footer ) : EMPTY_TEXT ( footer != null ) ? ComponentSerializer.toString( footer ) : EMPTY_TEXT
) ); ) );
} }
}
@Override @Override
public void resetTabHeader() public void resetTabHeader()

View File

@ -228,10 +228,6 @@ public class DownstreamBridge extends PacketHandler
} }
if ( pluginMessage.getTag().equals( "MC|Brand" ) ) if ( pluginMessage.getTag().equals( "MC|Brand" ) )
{
if ( con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 )
{
try
{ {
ByteBuf brand = Unpooled.wrappedBuffer( pluginMessage.getData() ); ByteBuf brand = Unpooled.wrappedBuffer( pluginMessage.getData() );
String serverBrand = DefinedPacket.readString( brand ); String serverBrand = DefinedPacket.readString( brand );
@ -240,17 +236,6 @@ public class DownstreamBridge extends PacketHandler
DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand, brand ); DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand, brand );
pluginMessage.setData( brand.array().clone() ); pluginMessage.setData( brand.array().clone() );
brand.release(); brand.release();
} catch ( Exception ignored )
{
// TODO: Remove this
// Older spigot protocol builds sent the brand incorrectly
return;
}
} else
{
String serverBrand = new String( pluginMessage.getData(), "UTF-8" );
pluginMessage.setData( ( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand ).getBytes( "UTF-8" ) );
}
// changes in the packet are ignored so we need to send it manually // changes in the packet are ignored so we need to send it manually
con.unsafe().sendPacket( pluginMessage ); con.unsafe().sendPacket( pluginMessage );
throw CancelSendSignal.INSTANCE; throw CancelSendSignal.INSTANCE;

View File

@ -213,7 +213,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
public void done(ProxyPingEvent pingResult, Throwable error) public void done(ProxyPingEvent pingResult, Throwable error)
{ {
BungeeCord.getInstance().getConnectionThrottle().unthrottle( getAddress().getAddress() ); BungeeCord.getInstance().getConnectionThrottle().unthrottle( getAddress().getAddress() );
Gson gson = handshake.getProtocolVersion() == ProtocolConstants.MINECRAFT_1_7_2 ? BungeeCord.getInstance().gsonLegacy : BungeeCord.getInstance().gson; Gson gson = BungeeCord.getInstance().gson;
unsafe.sendPacket( new StatusResponse( gson.toJson( pingResult.getResponse() ) ) ); unsafe.sendPacket( new StatusResponse( gson.toJson( pingResult.getResponse() ) ) );
} }
}; };
@ -478,13 +478,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
userCon.setCompressionThreshold( BungeeCord.getInstance().config.getCompressionThreshold() ); userCon.setCompressionThreshold( BungeeCord.getInstance().config.getCompressionThreshold() );
userCon.init(); userCon.init();
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
{
unsafe.sendPacket( new LoginSuccess( getUUID(), getName() ) ); // Without dashes, for older clients.
}
ch.setProtocol( Protocol.GAME ); ch.setProtocol( Protocol.GAME );
ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) ); ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) );

View File

@ -53,7 +53,7 @@ public class PingHandler extends PacketHandler
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR") @SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public void handle(StatusResponse statusResponse) throws Exception public void handle(StatusResponse statusResponse) throws Exception
{ {
Gson gson = protocol == ProtocolConstants.MINECRAFT_1_7_2 ? BungeeCord.getInstance().gsonLegacy : BungeeCord.getInstance().gson; Gson gson = 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();
} }

View File

@ -73,12 +73,9 @@ public class UpstreamBridge extends PacketHandler
item item
} ); } );
for ( ProxiedPlayer player : con.getServer().getInfo().getPlayers() ) for ( ProxiedPlayer player : con.getServer().getInfo().getPlayers() )
{
if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 )
{ {
player.unsafe().sendPacket( packet ); player.unsafe().sendPacket( packet );
} }
}
con.getServer().disconnect( "Quitting" ); con.getServer().disconnect( "Quitting" );
} }
} }

View File

@ -25,10 +25,6 @@ public abstract class EntityMap
{ {
switch ( version ) switch ( version )
{ {
case ProtocolConstants.MINECRAFT_1_7_2:
return EntityMap_1_7_2.INSTANCE;
case ProtocolConstants.MINECRAFT_1_7_6:
return EntityMap_1_7_6.INSTANCE;
case ProtocolConstants.MINECRAFT_1_8: case ProtocolConstants.MINECRAFT_1_8:
return EntityMap_1_8.INSTANCE; return EntityMap_1_8.INSTANCE;
} }

View File

@ -87,9 +87,6 @@ enum ForgeClientHandshakeState implements IForgeClientPacketHandler<ForgeClientH
Map<String, String> clientModList = ForgeUtils.readModList( message ); Map<String, String> clientModList = ForgeUtils.readModList( message );
con.getForgeClientHandler().setClientModList( clientModList ); con.getForgeClientHandler().setClientModList( clientModList );
// If the user is running 1.8 or above, we don't need to check the version of FML - it's always an OK version.
if ( con.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_8 )
{
// Get the version from the mod list. // Get the version from the mod list.
int buildNumber = ForgeUtils.getFmlBuildNumber( clientModList ); int buildNumber = ForgeUtils.getFmlBuildNumber( clientModList );
@ -101,7 +98,6 @@ enum ForgeClientHandshakeState implements IForgeClientPacketHandler<ForgeClientH
con.getForgeClientHandler().setForgeOutdated( true ); con.getForgeClientHandler().setForgeOutdated( true );
} }
} }
}
return WAITINGSERVERDATA; return WAITINGSERVERDATA;
} }

View File

@ -90,24 +90,7 @@ public class Global extends TabList
item.setGamemode( ( (UserConnection) p ).getGamemode() ); item.setGamemode( ( (UserConnection) p ).getGamemode() );
item.setPing( p.getPing() ); item.setPing( p.getPing() );
} }
if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 )
{
player.unsafe().sendPacket( playerListItem ); player.unsafe().sendPacket( playerListItem );
} else
{
// Split up the packet
for ( PlayerListItem.Item item : playerListItem.getItems() )
{
PlayerListItem packet = new PlayerListItem();
packet.setAction( playerListItem.getAction() );
packet.setItems( new PlayerListItem.Item[]
{
item
} );
player.unsafe().sendPacket( packet );
}
}
PlayerListItem packet = new PlayerListItem(); PlayerListItem packet = new PlayerListItem();
packet.setAction( PlayerListItem.Action.ADD_PLAYER ); packet.setAction( PlayerListItem.Action.ADD_PLAYER );
PlayerListItem.Item item = new PlayerListItem.Item(); PlayerListItem.Item item = new PlayerListItem.Item();

View File

@ -12,7 +12,6 @@ public class ServerUnique extends TabList
{ {
private final Collection<UUID> uuids = new HashSet<>(); private final Collection<UUID> uuids = new HashSet<>();
private final Collection<String> usernames = new HashSet<>(); // Support for <=1.7.9
public ServerUnique(ProxiedPlayer player) public ServerUnique(ProxiedPlayer player)
{ {
@ -25,23 +24,11 @@ public class ServerUnique extends TabList
for ( PlayerListItem.Item item : playerListItem.getItems() ) for ( PlayerListItem.Item item : playerListItem.getItems() )
{ {
if ( playerListItem.getAction() == PlayerListItem.Action.ADD_PLAYER ) if ( playerListItem.getAction() == PlayerListItem.Action.ADD_PLAYER )
{
if ( item.getUuid() != null )
{ {
uuids.add( item.getUuid() ); uuids.add( item.getUuid() );
} else
{
usernames.add( item.getUsername() );
}
} else if ( playerListItem.getAction() == PlayerListItem.Action.REMOVE_PLAYER ) } else if ( playerListItem.getAction() == PlayerListItem.Action.REMOVE_PLAYER )
{
if ( item.getUuid() != null )
{ {
uuids.remove( item.getUuid() ); uuids.remove( item.getUuid() );
} else
{
usernames.remove( item.getUsername() );
}
} }
} }
player.unsafe().sendPacket( playerListItem ); player.unsafe().sendPacket( playerListItem );
@ -58,40 +45,16 @@ public class ServerUnique extends TabList
{ {
PlayerListItem packet = new PlayerListItem(); PlayerListItem packet = new PlayerListItem();
packet.setAction( PlayerListItem.Action.REMOVE_PLAYER ); packet.setAction( PlayerListItem.Action.REMOVE_PLAYER );
PlayerListItem.Item[] items = new PlayerListItem.Item[ uuids.size() + usernames.size() ]; PlayerListItem.Item[] items = new PlayerListItem.Item[ uuids.size() ];
int i = 0; int i = 0;
for ( UUID uuid : uuids ) for ( UUID uuid : uuids )
{ {
PlayerListItem.Item item = items[i++] = new PlayerListItem.Item(); PlayerListItem.Item item = items[i++] = new PlayerListItem.Item();
item.setUuid( uuid ); item.setUuid( uuid );
} }
for ( String username : usernames )
{
PlayerListItem.Item item = items[i++] = new PlayerListItem.Item();
item.setUsername( username );
item.setDisplayName( username );
}
packet.setItems( items ); packet.setItems( items );
if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 )
{
player.unsafe().sendPacket( packet ); player.unsafe().sendPacket( packet );
} else
{
// Split up the packet
for ( PlayerListItem.Item item : packet.getItems() )
{
PlayerListItem p2 = new PlayerListItem();
p2.setAction( packet.getAction() );
p2.setItems( new PlayerListItem.Item[]
{
item
} );
player.unsafe().sendPacket( p2 );
}
}
uuids.clear(); uuids.clear();
usernames.clear();
} }
@Override @Override