#3656: Improve online mode support where IP forwarding is disabled

This commit is contained in:
Outfluencer 2024-04-17 21:05:26 +10:00 committed by md_5
parent 8525b44961
commit 1be25b6c74
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
17 changed files with 63 additions and 55 deletions

View File

@ -130,7 +130,7 @@ public class ServerConnector extends PacketHandler
channel.write( copiedHandshake );
channel.setProtocol( Protocol.LOGIN );
channel.write( new LoginRequest( user.getName(), null, user.getUniqueId() ) );
channel.write( new LoginRequest( user.getName(), null, user.getRewriteId() ) );
}
@Override
@ -365,7 +365,7 @@ public class ServerConnector extends PacketHandler
} else
{
LoginResult loginProfile = user.getPendingConnection().getLoginProfile();
user.unsafe().sendPacket( new LoginSuccess( user.getUniqueId(), user.getName(), ( loginProfile == null ) ? null : loginProfile.getProperties() ) );
user.unsafe().sendPacket( new LoginSuccess( user.getRewriteId(), user.getName(), ( loginProfile == null ) ? null : loginProfile.getProperties() ) );
user.getCh().setEncodeProtocol( Protocol.CONFIGURATION );
}
}

View File

@ -642,6 +642,11 @@ public final class UserConnection implements ProxiedPlayer
return getPendingConnection().getUniqueId();
}
public UUID getRewriteId()
{
return getPendingConnection().getRewriteId();
}
public void setSettings(ClientSettings settings)
{
this.settings = settings;

View File

@ -126,6 +126,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Getter
private UUID offlineId;
@Getter
private UUID rewriteId;
@Getter
private LoginResult loginProfile;
@Getter
private boolean legacy;
@ -556,6 +558,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{
uniqueId = offlineId;
}
rewriteId = ( bungee.config.isIpForward() ) ? uniqueId : offlineId;
if ( BungeeCord.getInstance().config.isEnforceSecureProfile() )
{
@ -635,7 +638,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
if ( getVersion() < ProtocolConstants.MINECRAFT_1_20_2 )
{
unsafe.sendPacket( new LoginSuccess( getUniqueId(), getName(), ( loginProfile == null ) ? null : loginProfile.getProperties() ) );
unsafe.sendPacket( new LoginSuccess( getRewriteId(), getName(), ( loginProfile == null ) ? null : loginProfile.getProperties() ) );
ch.setProtocol( Protocol.GAME );
}
finish2();

View File

@ -85,7 +85,7 @@ public class UpstreamBridge extends PacketHandler
PlayerListItem oldPacket = new PlayerListItem();
oldPacket.setAction( PlayerListItem.Action.REMOVE_PLAYER );
PlayerListItem.Item item = new PlayerListItem.Item();
item.setUuid( con.getUniqueId() );
item.setUuid( con.getRewriteId() );
oldPacket.setItems( new PlayerListItem.Item[]
{
item
@ -94,7 +94,7 @@ public class UpstreamBridge extends PacketHandler
PlayerListItemRemove newPacket = new PlayerListItemRemove();
newPacket.setUuids( new UUID[]
{
con.getUniqueId()
con.getRewriteId()
} );
for ( ProxiedPlayer player : con.getServer().getInfo().getPlayers() )

View File

@ -121,13 +121,13 @@ class EntityMap_1_10 extends EntityMap
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
UserConnection player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
DefinedPacket.writeUUID( player.getRewriteId(), packet );
packet.writerIndex( previous );
}
break;
@ -164,7 +164,7 @@ class EntityMap_1_10 extends EntityMap
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
@ -173,7 +173,7 @@ class EntityMap_1_10 extends EntityMap
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
DefinedPacket.writeUUID( ( (UserConnection) player ).getRewriteId(), packet );
packet.writerIndex( previous );
}
}

View File

@ -121,13 +121,13 @@ class EntityMap_1_11 extends EntityMap
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
UserConnection player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
DefinedPacket.writeUUID( player.getRewriteId(), packet );
packet.writerIndex( previous );
}
break;
@ -165,7 +165,7 @@ class EntityMap_1_11 extends EntityMap
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
@ -174,7 +174,7 @@ class EntityMap_1_11 extends EntityMap
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
DefinedPacket.writeUUID( ( (UserConnection) player ).getRewriteId(), packet );
packet.writerIndex( previous );
}
}

View File

@ -121,13 +121,13 @@ class EntityMap_1_12 extends EntityMap
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
UserConnection player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
DefinedPacket.writeUUID( player.getRewriteId(), packet );
packet.writerIndex( previous );
}
break;
@ -165,7 +165,7 @@ class EntityMap_1_12 extends EntityMap
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x1E /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
if ( packetId == 0x1E /* Spectate : PacketPlayInSpectate */ )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
@ -174,7 +174,7 @@ class EntityMap_1_12 extends EntityMap
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
DefinedPacket.writeUUID( ( (UserConnection) player ).getRewriteId(), packet );
packet.writerIndex( previous );
}
}

View File

@ -121,13 +121,13 @@ class EntityMap_1_12_1 extends EntityMap
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
UserConnection player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
DefinedPacket.writeUUID( player.getRewriteId(), packet );
packet.writerIndex( previous );
}
break;
@ -165,7 +165,7 @@ class EntityMap_1_12_1 extends EntityMap
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x1E /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
if ( packetId == 0x1E /* Spectate : PacketPlayInSpectate */ )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
@ -174,7 +174,7 @@ class EntityMap_1_12_1 extends EntityMap
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
DefinedPacket.writeUUID( ( (UserConnection) player ).getRewriteId(), packet );
packet.writerIndex( previous );
}
}

View File

@ -121,13 +121,13 @@ class EntityMap_1_13 extends EntityMap
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
UserConnection player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
DefinedPacket.writeUUID( player.getRewriteId(), packet );
packet.writerIndex( previous );
}
break;
@ -165,7 +165,7 @@ class EntityMap_1_13 extends EntityMap
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x28 /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
if ( packetId == 0x28 /* Spectate : PacketPlayInSpectate */ )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
@ -174,7 +174,7 @@ class EntityMap_1_13 extends EntityMap
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
DefinedPacket.writeUUID( ( (UserConnection) player ).getRewriteId(), packet );
packet.writerIndex( previous );
}
}

View File

@ -120,13 +120,13 @@ class EntityMap_1_14 extends EntityMap
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
UserConnection player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
DefinedPacket.writeUUID( player.getRewriteId(), packet );
packet.writerIndex( previous );
}
break;
@ -169,7 +169,7 @@ class EntityMap_1_14 extends EntityMap
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x2B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
if ( packetId == 0x2B /* Spectate : PacketPlayInSpectate */ )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
@ -178,7 +178,7 @@ class EntityMap_1_14 extends EntityMap
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
DefinedPacket.writeUUID( ( (UserConnection) player ).getRewriteId(), packet );
packet.writerIndex( previous );
}
}

View File

@ -120,13 +120,13 @@ class EntityMap_1_15 extends EntityMap
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
UserConnection player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
DefinedPacket.writeUUID( player.getRewriteId(), packet );
packet.writerIndex( previous );
}
break;
@ -169,7 +169,7 @@ class EntityMap_1_15 extends EntityMap
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x2B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
if ( packetId == 0x2B /* Spectate : PacketPlayInSpectate */ )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
@ -178,7 +178,7 @@ class EntityMap_1_15 extends EntityMap
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
DefinedPacket.writeUUID( ( (UserConnection) player ).getRewriteId(), packet );
packet.writerIndex( previous );
}
}

View File

@ -120,13 +120,13 @@ class EntityMap_1_16 extends EntityMap
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
UserConnection player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
DefinedPacket.writeUUID( player.getRewriteId(), packet );
packet.writerIndex( previous );
}
break;
@ -169,7 +169,7 @@ class EntityMap_1_16 extends EntityMap
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x2C /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
if ( packetId == 0x2C /* Spectate : PacketPlayInSpectate */ )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
@ -178,7 +178,7 @@ class EntityMap_1_16 extends EntityMap
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
DefinedPacket.writeUUID( ( (UserConnection) player ).getRewriteId(), packet );
packet.writerIndex( previous );
}
}

View File

@ -41,13 +41,13 @@ class EntityMap_1_16_2 extends EntityMap
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
UserConnection player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
DefinedPacket.writeUUID( player.getRewriteId(), packet );
packet.writerIndex( previous );
}
}
@ -62,7 +62,7 @@ class EntityMap_1_16_2 extends EntityMap
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == spectateId && !BungeeCord.getInstance().getConfig().isIpForward() )
if ( packetId == spectateId )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
@ -71,7 +71,7 @@ class EntityMap_1_16_2 extends EntityMap
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
DefinedPacket.writeUUID( ( (UserConnection) player ).getRewriteId(), packet );
packet.writerIndex( previous );
}
}

View File

@ -121,13 +121,13 @@ class EntityMap_1_8 extends EntityMap
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
UserConnection player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
DefinedPacket.writeUUID( player.getRewriteId(), packet );
packet.writerIndex( previous );
}
} else if ( packetId == 0x42 /* Combat Event */ )
@ -158,7 +158,7 @@ class EntityMap_1_8 extends EntityMap
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x18 /* Spectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
if ( packetId == 0x18 /* Spectate */ )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
@ -167,7 +167,7 @@ class EntityMap_1_8 extends EntityMap
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
DefinedPacket.writeUUID( ( (UserConnection) player ).getRewriteId(), packet );
packet.writerIndex( previous );
}
}

View File

@ -121,13 +121,13 @@ class EntityMap_1_9 extends EntityMap
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
UserConnection player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
DefinedPacket.writeUUID( player.getRewriteId(), packet );
packet.writerIndex( previous );
}
break;
@ -164,7 +164,7 @@ class EntityMap_1_9 extends EntityMap
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
@ -173,7 +173,7 @@ class EntityMap_1_9 extends EntityMap
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
DefinedPacket.writeUUID( ( (UserConnection) player ).getRewriteId(), packet );
packet.writerIndex( previous );
}
}

View File

@ -121,13 +121,13 @@ class EntityMap_1_9_4 extends EntityMap
DefinedPacket.readVarInt( packet ); // Entity ID
int idLength = packet.readerIndex() - readerIndex - packetIdLength;
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
UserConnection player;
if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null )
{
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength + idLength );
DefinedPacket.writeUUID( player.getUniqueId(), packet );
DefinedPacket.writeUUID( player.getRewriteId(), packet );
packet.writerIndex( previous );
}
break;
@ -164,7 +164,7 @@ class EntityMap_1_9_4 extends EntityMap
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ )
{
UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player;
@ -173,7 +173,7 @@ class EntityMap_1_9_4 extends EntityMap
int previous = packet.writerIndex();
packet.readerIndex( readerIndex );
packet.writerIndex( readerIndex + packetIdLength );
DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet );
DefinedPacket.writeUUID( ( (UserConnection) player ).getRewriteId(), packet );
packet.writerIndex( previous );
}
}

View File

@ -46,7 +46,7 @@ public abstract class TabList
UserConnection player = BungeeCord.getInstance().getPlayerByOfflineUUID( playerListItem.getUuids()[i] );
if ( player != null )
{
playerListItem.getUuids()[i] = player.getUniqueId();
playerListItem.getUuids()[i] = player.getRewriteId();
}
}
@ -72,7 +72,7 @@ public abstract class TabList
UserConnection player = BungeeCord.getInstance().getPlayerByOfflineUUID( item.getUuid() );
if ( player != null )
{
item.setUuid( player.getUniqueId() );
item.setUuid( player.getRewriteId() );
if ( item.getProperties() != null )
{