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,30 +24,16 @@ 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 = readArray( buf );
{ verifyToken = readArray( buf );
publicKey = readArrayLegacy( buf );
verifyToken = readArrayLegacy( buf );
} else
{
publicKey = 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 ) writeArray( publicKey, buf );
{ writeArray( verifyToken, buf );
writeArrayLegacy( publicKey, buf, false );
writeArrayLegacy( verifyToken, buf, false );
} else
{
writeArray( publicKey, buf );
writeArray( verifyToken, buf );
}
} }
@Override @Override

View File

@ -22,29 +22,15 @@ 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 = readArray( buf );
{ verifyToken = readArray( buf );
sharedSecret = readArrayLegacy( buf );
verifyToken = readArrayLegacy( buf );
} else
{
sharedSecret = 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 ) writeArray( sharedSecret, buf );
{ writeArray( verifyToken, buf );
writeArrayLegacy( sharedSecret, buf, false );
writeArrayLegacy( verifyToken, buf, false );
} else
{
writeArray( sharedSecret, buf );
writeArray( verifyToken, buf );
}
} }
@Override @Override

View File

@ -21,25 +21,13 @@ 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

@ -22,63 +22,53 @@ 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 ) action = Action.values()[ DefinedPacket.readVarInt( buf )];
items = new Item[ DefinedPacket.readVarInt( buf ) ];
for ( int i = 0; i < items.length; i++ )
{ {
items = new Item[ 1 ]; Item item = items[ i ] = new Item();
Item item = items[ 0 ] = new Item(); item.setUuid( DefinedPacket.readUUID( buf ) );
item.displayName = item.username = readString( buf ); switch ( action )
action = !buf.readBoolean() ? Action.REMOVE_PLAYER : Action.ADD_PLAYER;
item.ping = buf.readShort();
} else
{
action = Action.values()[ DefinedPacket.readVarInt( buf )];
items = new Item[ DefinedPacket.readVarInt( buf ) ];
for ( int i = 0; i < items.length; i++ )
{ {
Item item = items[ i ] = new Item(); case ADD_PLAYER:
item.setUuid( DefinedPacket.readUUID( buf ) ); item.username = DefinedPacket.readString( buf );
switch ( action ) item.properties = new String[ DefinedPacket.readVarInt( buf ) ][];
{ for ( int j = 0; j < item.properties.length; j++ )
case ADD_PLAYER: {
item.username = DefinedPacket.readString( buf ); String name = DefinedPacket.readString( buf );
item.properties = new String[ DefinedPacket.readVarInt( buf ) ][]; String value = DefinedPacket.readString( buf );
for ( int j = 0; j < item.properties.length; j++ )
{
String name = DefinedPacket.readString( buf );
String value = DefinedPacket.readString( buf );
if ( buf.readBoolean() )
{
item.properties[ j] = new String[]
{
name, value, DefinedPacket.readString( buf )
};
} else
{
item.properties[ j ] = new String[]
{
name, value
};
}
}
item.gamemode = DefinedPacket.readVarInt( buf );
item.ping = DefinedPacket.readVarInt( buf );
if ( buf.readBoolean() ) if ( buf.readBoolean() )
{ {
item.displayName = DefinedPacket.readString( buf ); item.properties[ j] = new String[]
} {
break; name, value, DefinedPacket.readString( buf )
case UPDATE_GAMEMODE: };
item.gamemode = DefinedPacket.readVarInt( buf ); } else
break;
case UPDATE_LATENCY:
item.ping = DefinedPacket.readVarInt( buf );
break;
case UPDATE_DISPLAY_NAME:
if ( buf.readBoolean() )
{ {
item.displayName = DefinedPacket.readString( buf ); item.properties[ j ] = new String[]
{
name, value
};
} }
} }
item.gamemode = DefinedPacket.readVarInt( buf );
item.ping = DefinedPacket.readVarInt( buf );
if ( buf.readBoolean() )
{
item.displayName = DefinedPacket.readString( buf );
}
break;
case UPDATE_GAMEMODE:
item.gamemode = DefinedPacket.readVarInt( buf );
break;
case UPDATE_LATENCY:
item.ping = DefinedPacket.readVarInt( buf );
break;
case UPDATE_DISPLAY_NAME:
if ( buf.readBoolean() )
{
item.displayName = DefinedPacket.readString( buf );
}
} }
} }
} }
@ -86,59 +76,50 @@ 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 ) DefinedPacket.writeVarInt( action.ordinal(), buf );
DefinedPacket.writeVarInt( items.length, buf );
for ( Item item : items )
{ {
Item item = items[0]; // Only one at a time DefinedPacket.writeUUID( item.uuid, buf );
writeString( item.displayName, buf ); // TODO: Server unique only! switch ( action )
buf.writeBoolean( action != Action.REMOVE_PLAYER );
buf.writeShort( item.ping );
} else
{
DefinedPacket.writeVarInt( action.ordinal(), buf );
DefinedPacket.writeVarInt( items.length, buf );
for ( Item item : items )
{ {
DefinedPacket.writeUUID( item.uuid, buf ); case ADD_PLAYER:
switch ( action ) DefinedPacket.writeString( item.username, buf );
{ DefinedPacket.writeVarInt( item.properties.length, buf );
case ADD_PLAYER: for ( String[] prop : item.properties )
DefinedPacket.writeString( item.username, buf ); {
DefinedPacket.writeVarInt( item.properties.length, buf ); DefinedPacket.writeString( prop[ 0], buf );
for ( String[] prop : item.properties ) DefinedPacket.writeString( prop[ 1], buf );
if ( prop.length >= 3 )
{ {
DefinedPacket.writeString( prop[ 0], buf ); buf.writeBoolean( true );
DefinedPacket.writeString( prop[ 1], buf ); DefinedPacket.writeString( prop[ 2], buf );
if ( prop.length >= 3 ) } else
{
buf.writeBoolean( true );
DefinedPacket.writeString( prop[ 2], buf );
} else
{
buf.writeBoolean( false );
}
}
DefinedPacket.writeVarInt( item.gamemode, buf );
DefinedPacket.writeVarInt( item.ping, buf );
buf.writeBoolean( item.displayName != null );
if ( item.displayName != null )
{ {
DefinedPacket.writeString( item.displayName, buf ); buf.writeBoolean( false );
} }
break; }
case UPDATE_GAMEMODE: DefinedPacket.writeVarInt( item.gamemode, buf );
DefinedPacket.writeVarInt( item.gamemode, buf ); DefinedPacket.writeVarInt( item.ping, buf );
break; buf.writeBoolean( item.displayName != null );
case UPDATE_LATENCY: if ( item.displayName != null )
DefinedPacket.writeVarInt( item.ping, buf ); {
break; DefinedPacket.writeString( item.displayName, buf );
case UPDATE_DISPLAY_NAME: }
buf.writeBoolean( item.displayName != null ); break;
if ( item.displayName != null ) case UPDATE_GAMEMODE:
{ DefinedPacket.writeVarInt( item.gamemode, buf );
DefinedPacket.writeString( item.displayName, buf ); break;
} case UPDATE_LATENCY:
break; DefinedPacket.writeVarInt( item.ping, buf );
} break;
case UPDATE_DISPLAY_NAME:
buf.writeBoolean( item.displayName != null );
if ( item.displayName != null )
{
DefinedPacket.writeString( item.displayName, buf );
}
break;
} }
} }
} }

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,29 +32,17 @@ 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 ) int maxSize = direction == ProtocolConstants.Direction.TO_SERVER ? Short.MAX_VALUE : 0x100000;
{ Preconditions.checkArgument(buf.readableBytes() < maxSize);
data = readArrayLegacy( buf ); data = new byte[ buf.readableBytes() ];
} else buf.readBytes( data );
{
int maxSize = direction == ProtocolConstants.Direction.TO_SERVER ? Short.MAX_VALUE : 0x100000;
Preconditions.checkArgument(buf.readableBytes() < maxSize);
data = new byte[ buf.readableBytes() ];
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 ) buf.writeBytes( data );
{
writeArrayLegacy( data, buf, allowExtendedPacket );
} else
{
buf.writeBytes( data );
}
} }
@Override @Override
@ -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,20 +29,10 @@ 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 );
if ( action != 1 )
{ {
scoreName = readString( buf ); value = readVarInt( buf );
if ( action != 1 )
{
value = readVarInt( buf );
}
} else
{
if ( action != 1 )
{
scoreName = readString( buf );
value = buf.readInt();
}
} }
} }
@ -51,20 +41,10 @@ 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 );
if ( action != 1 )
{ {
writeString( scoreName, buf ); writeVarInt( value, buf );
if ( action != 1 )
{
writeVarInt( value, buf );
}
} else
{
if ( action != 1 )
{
writeString( scoreName, buf );
buf.writeInt( value );
}
} }
} }

View File

@ -24,12 +24,9 @@ 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();
}
} }
} }
@ -37,13 +34,10 @@ public class TabCompleteRequest extends DefinedPacket
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 );
if ( hasPositon )
{ {
buf.writeBoolean( hasPositon ); buf.writeLong( position );
if ( hasPositon )
{
buf.writeLong( position );
}
} }
} }

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 );
{ color = buf.readByte();
nameTagVisibility = readString( buf );
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 );
{ buf.writeByte( color );
writeString( nameTagVisibility, buf );
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 ) sendPacket( player, clear );
{ sendPacket( player, reset );
// Send the packets in the correct order sendPacket( player, times );
sendPacket( player, clear ); sendPacket( player, subtitle );
sendPacket( player, reset ); sendPacket( player, title );
sendPacket( player, times );
sendPacket( player, subtitle );
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.getUniqueId().toString() );
{
out.addProperty( "id", src.getId() );
} else
{
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 ) ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
{ DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")", brand );
MinecraftOutput out = new MinecraftOutput(); user.unsafe().sendPacket( new PluginMessage( "MC|Brand", brand.array().clone(), handshakeHandler.isServerForge() ) );
out.writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket( ProxyServer.getInstance().getName() + " (" + ProxyServer.getInstance().getVersion() + ")" ); brand.release();
user.unsafe().sendPacket( new PluginMessage( "MC|Brand", out.toArray(), handshakeHandler.isServerForge() ) );
} else
{
ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")", brand );
user.unsafe().sendPacket( new PluginMessage( "MC|Brand", brand.array().clone(), handshakeHandler.isServerForge() ) );
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
@ -541,25 +541,19 @@ 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(
{ ( header != null ) ? ComponentSerializer.toString( header ) : EMPTY_TEXT,
unsafe().sendPacket( new PlayerListHeaderFooter( ( footer != null ) ? ComponentSerializer.toString( footer ) : EMPTY_TEXT
( header != null ) ? ComponentSerializer.toString( header ) : 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(
{ ( header != null ) ? ComponentSerializer.toString( header ) : EMPTY_TEXT,
unsafe().sendPacket( new PlayerListHeaderFooter( ( footer != null ) ? ComponentSerializer.toString( footer ) : EMPTY_TEXT
( header != null ) ? ComponentSerializer.toString( header ) : EMPTY_TEXT, ) );
( footer != null ) ? ComponentSerializer.toString( footer ) : EMPTY_TEXT
) );
}
} }
@Override @Override

View File

@ -229,28 +229,13 @@ 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 ) ByteBuf brand = Unpooled.wrappedBuffer( pluginMessage.getData() );
{ String serverBrand = DefinedPacket.readString( brand );
try brand.release();
{ brand = ByteBufAllocator.DEFAULT.heapBuffer();
ByteBuf brand = Unpooled.wrappedBuffer( pluginMessage.getData() ); DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand, brand );
String serverBrand = DefinedPacket.readString( brand ); pluginMessage.setData( brand.array().clone() );
brand.release(); brand.release();
brand = ByteBufAllocator.DEFAULT.heapBuffer();
DefinedPacket.writeString( bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand, brand );
pluginMessage.setData( brand.array().clone() );
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

@ -74,10 +74,7 @@ public class UpstreamBridge extends PacketHandler
} ); } );
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,19 +87,15 @@ 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. // Get the version from the mod list.
if ( con.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_8 ) int buildNumber = ForgeUtils.getFmlBuildNumber( clientModList );
{
// Get the version from the mod list.
int buildNumber = ForgeUtils.getFmlBuildNumber( clientModList );
// If we get 0, we're probably using a testing build, so let it though. Otherwise, check the build number. // If we get 0, we're probably using a testing build, so let it though. Otherwise, check the build number.
if ( buildNumber < ForgeConstants.FML_MIN_BUILD_VERSION && buildNumber != 0 ) if ( buildNumber < ForgeConstants.FML_MIN_BUILD_VERSION && buildNumber != 0 )
{ {
// Mark the user as an old Forge user. This will then cause any Forge ServerConnectors to cancel any // Mark the user as an old Forge user. This will then cause any Forge ServerConnectors to cancel any
// connections to it. // connections to it.
con.getForgeClientHandler().setForgeOutdated( true ); con.getForgeClientHandler().setForgeOutdated( true );
}
} }
} }

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)
{ {
@ -26,22 +25,10 @@ public class ServerUnique extends TabList
{ {
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