Skip to content

Commit

Permalink
support for snapshot 24w03a (1.20.5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Outfluencer committed Jan 20, 2024
1 parent a1cd694 commit ec7e867
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@
import net.md_5.bungee.protocol.packet.StartConfiguration;
import net.md_5.bungee.protocol.packet.StatusRequest;
import net.md_5.bungee.protocol.packet.StatusResponse;
import net.md_5.bungee.protocol.packet.StoreCookie;
import net.md_5.bungee.protocol.packet.Subtitle;
import net.md_5.bungee.protocol.packet.SystemChat;
import net.md_5.bungee.protocol.packet.TabCompleteRequest;
import net.md_5.bungee.protocol.packet.TabCompleteResponse;
import net.md_5.bungee.protocol.packet.Team;
import net.md_5.bungee.protocol.packet.Title;
import net.md_5.bungee.protocol.packet.TitleTimes;
import net.md_5.bungee.protocol.packet.Transfer;
import net.md_5.bungee.protocol.packet.ViewDistance;

public abstract class AbstractPacketHandler
Expand Down Expand Up @@ -243,4 +245,12 @@ public void handle(StartConfiguration startConfiguration) throws Exception
public void handle(FinishConfiguration finishConfiguration) throws Exception
{
}

public void handle(Transfer transfer) throws Exception
{
}

public void handle(StoreCookie storeCookie) throws Exception
{
}
}
134 changes: 103 additions & 31 deletions protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class ProtocolConstants
{

private static final boolean SNAPSHOT_SUPPORT = Boolean.getBoolean( "net.md_5.bungee.protocol.snapshot" );
private static final boolean SNAPSHOT_SUPPORT = true || Boolean.getBoolean( "net.md_5.bungee.protocol.snapshot" );
public static final int MINECRAFT_1_8 = 47;
public static final int MINECRAFT_1_9 = 107;
public static final int MINECRAFT_1_9_1 = 108;
Expand Down Expand Up @@ -45,6 +45,7 @@ public class ProtocolConstants
public static final int MINECRAFT_1_20 = 763;
public static final int MINECRAFT_1_20_2 = 764;
public static final int MINECRAFT_1_20_3 = 765;
public static final int MINECRAFT_1_20_5 = 1073741996;
public static final List<String> SUPPORTED_VERSIONS;
public static final List<Integer> SUPPORTED_VERSION_IDS;

Expand Down Expand Up @@ -108,8 +109,7 @@ public class ProtocolConstants

if ( SNAPSHOT_SUPPORT )
{
// supportedVersions.add( "1.20.x" );
// supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_20_3 );
supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_20_5 );
}

SUPPORTED_VERSIONS = supportedVersions.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ public class EncryptionRequest extends DefinedPacket
private String serverId;
private byte[] publicKey;
private byte[] verifyToken;
private boolean shouldAuthenticate;

@Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
serverId = readString( buf );
publicKey = readArray( buf );
verifyToken = readArray( buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 )
{
shouldAuthenticate = buf.readBoolean();
}
}

@Override
Expand All @@ -34,6 +39,10 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc
writeString( serverId, buf );
writeArray( publicKey, buf );
writeArray( verifyToken, buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 )
{
buf.writeBoolean( shouldAuthenticate );
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Login extends DefinedPacket
private boolean flat;
private Location deathLocation;
private int portalCooldown;
private boolean secureProfile;

@Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
Expand Down Expand Up @@ -135,7 +136,13 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco
dimension = readString( buf );
worldName = readString( buf );
seed = buf.readLong();
gameMode = buf.readUnsignedByte();
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 )
{
gameMode = buf.readByte();
} else
{
gameMode = buf.readUnsignedByte();
}
previousGameMode = buf.readByte();
}
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
Expand All @@ -154,6 +161,11 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco
{
portalCooldown = readVarInt( buf );
}

if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 )
{
secureProfile = buf.readBoolean();
}
}

@Override
Expand Down Expand Up @@ -275,6 +287,11 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc
{
writeVarInt( portalCooldown, buf );
}

if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_5 )
{
buf.writeBoolean( secureProfile );
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco
{
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_4 )
{
icon = DefinedPacket.readArray( buf );
icon = readArray( buf );
} else
{
icon = readString( buf );
Expand All @@ -45,7 +45,7 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco
preview = buf.readBoolean();
}

if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 )
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 && protocolVersion < ProtocolConstants.MINECRAFT_1_20_5 )
{
enforceSecure = buf.readBoolean();
}
Expand Down Expand Up @@ -76,7 +76,7 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc
buf.writeBoolean( true );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_4 )
{
DefinedPacket.writeArray( (byte[]) icon, buf );
writeArray( (byte[]) icon, buf );
} else
{
writeString( (String) icon, buf );
Expand All @@ -91,7 +91,7 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc
buf.writeBoolean( preview );
}

if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 )
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_1 && protocolVersion < ProtocolConstants.MINECRAFT_1_20_5 )
{
buf.writeBoolean( enforceSecure );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package net.md_5.bungee.protocol.packet;

import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import net.md_5.bungee.protocol.AbstractPacketHandler;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;

@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class StoreCookie extends DefinedPacket
{

private String key;
private byte[] data;

@Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
key = readString( buf );
data = readArray( buf, 5120 );
}

@Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
writeString( key, buf );
writeArray( data, buf );
}

@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.md_5.bungee.protocol.packet;

import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import net.md_5.bungee.protocol.AbstractPacketHandler;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;


@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class Transfer extends DefinedPacket
{

private String host;
private int port;

@Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
host = readString( buf );
port = readVarInt( buf );
}

@Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
writeString( host, buf );
writeVarInt( port, buf );
}

@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}

}
3 changes: 2 additions & 1 deletion proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public static EncryptionRequest encryptRequest()
byte[] pubKey = keys.getPublic().getEncoded();
byte[] verify = new byte[ 4 ];
random.nextBytes( verify );
return new EncryptionRequest( hash, pubKey, verify );
// always auth for now
return new EncryptionRequest( hash, pubKey, verify, true );
}

public static boolean check(PlayerPublicKey publicKey, UUID uuid) throws GeneralSecurityException
Expand Down
2 changes: 1 addition & 1 deletion proxy/src/main/java/net/md_5/bungee/ServerConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public static void handleLogin(ProxyServer bungee, ChannelWrapper ch, UserConnec
// Set tab list size, TODO: what shall we do about packet mutability
Login modLogin = new Login( login.getEntityId(), login.isHardcore(), login.getGameMode(), login.getPreviousGameMode(), login.getWorldNames(), login.getDimensions(), login.getDimension(), login.getWorldName(), login.getSeed(), login.getDifficulty(),
(byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.getViewDistance(), login.getSimulationDistance(), login.isReducedDebugInfo(), login.isNormalRespawn(), login.isLimitedCrafting(), login.isDebug(), login.isFlat(), login.getDeathLocation(),
login.getPortalCooldown() );
login.getPortalCooldown(), login.isSecureProfile() );

user.unsafe().sendPacket( modLogin );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public void sendPacket(DefinedPacket packet)
private boolean legacy;
@Getter
private String extraDataInHandshake = "";
@Getter
private boolean transferred;
private UserConnection userCon;

@Override
Expand Down Expand Up @@ -349,6 +351,8 @@ public void handle(Handshake handshake) throws Exception
ch.setProtocol( Protocol.STATUS );
break;
case 2:
case 3: // transferred
this.transferred = handshake.getRequestedProtocol() == 3;
// Login
bungee.getLogger().log( Level.INFO, "{0} has connected", this );
thisState = State.USERNAME;
Expand Down
2 changes: 2 additions & 0 deletions proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public static EntityMap getEntityMap(int version)
return EntityMap_1_16_2.INSTANCE_1_20_2;
case ProtocolConstants.MINECRAFT_1_20_3:
return EntityMap_1_16_2.INSTANCE_1_20_3;
case ProtocolConstants.MINECRAFT_1_20_5:
return EntityMap_1_16_2.INSTANCE_1_20_5;
}
throw new RuntimeException( "Version " + version + " has no entity map" );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class EntityMap_1_16_2 extends EntityMap
static final EntityMap_1_16_2 INSTANCE_1_19_4 = new EntityMap_1_16_2( 0x03, 0x30 );
static final EntityMap_1_16_2 INSTANCE_1_20_2 = new EntityMap_1_16_2( -1, 0x33 );
static final EntityMap_1_16_2 INSTANCE_1_20_3 = new EntityMap_1_16_2( -1, 0x34 );
static final EntityMap_1_16_2 INSTANCE_1_20_5 = new EntityMap_1_16_2( -1, 111 );
//
private final int spawnPlayerId;
private final int spectateId;
Expand Down

0 comments on commit ec7e867

Please sign in to comment.