Skip to content

Commit

Permalink
SpigotMC#3656: Improve online mode support where IP forwarding is dis…
Browse files Browse the repository at this point in the history
…abled
  • Loading branch information
Outfluencer authored and thxrben committed Jun 16, 2024
1 parent f61b2f8 commit 9740c0a
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 55 deletions.
4 changes: 2 additions & 2 deletions proxy/src/main/java/net/md_5/bungee/ServerConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void connected(ChannelWrapper channel) throws Exception
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
Expand Down Expand Up @@ -365,7 +365,7 @@ private void cutThrough(ServerConnection server)
} 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 );
}
}
Expand Down
5 changes: 5 additions & 0 deletions proxy/src/main/java/net/md_5/bungee/UserConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,11 @@ public UUID getUniqueId()
return getPendingConnection().getUniqueId();
}

public UUID getRewriteId()
{
return getPendingConnection().getRewriteId();
}

public void setSettings(ClientSettings settings)
{
this.settings = settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public void sendPacket(DefinedPacket packet)
@Getter
private UUID offlineId;
@Getter
private UUID rewriteId;
@Getter
private LoginResult loginProfile;
@Getter
private boolean legacy;
Expand Down Expand Up @@ -556,6 +558,7 @@ private void finish()
{
uniqueId = offlineId;
}
rewriteId = ( bungee.config.isIpForward() ) ? uniqueId : offlineId;

if ( BungeeCord.getInstance().config.isEnforceSecureProfile() )
{
Expand Down Expand Up @@ -635,7 +638,7 @@ public void run()

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void disconnected(ChannelWrapper channel) throws Exception
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
Expand All @@ -94,7 +94,7 @@ public void disconnected(ChannelWrapper channel) throws Exception
PlayerListItemRemove newPacket = new PlayerListItemRemove();
newPacket.setUuids( new UUID[]
{
con.getUniqueId()
con.getRewriteId()
} );

for ( ProxiedPlayer player : con.getServer().getInfo().getPlayers() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ public void rewriteClientbound(ByteBuf packet, int oldId, int newId)
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;
Expand Down Expand Up @@ -164,7 +164,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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;
Expand All @@ -173,7 +173,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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 );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ public void rewriteClientbound(ByteBuf packet, int oldId, int newId)
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;
Expand Down Expand Up @@ -165,7 +165,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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;
Expand All @@ -174,7 +174,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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 );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ public void rewriteClientbound(ByteBuf packet, int oldId, int newId)
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;
Expand Down Expand Up @@ -165,7 +165,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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;
Expand All @@ -174,7 +174,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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 );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ public void rewriteClientbound(ByteBuf packet, int oldId, int newId)
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;
Expand Down Expand Up @@ -165,7 +165,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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;
Expand All @@ -174,7 +174,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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 );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ public void rewriteClientbound(ByteBuf packet, int oldId, int newId, int protoco
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;
Expand Down Expand Up @@ -165,7 +165,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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;
Expand All @@ -174,7 +174,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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 );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ public void rewriteClientbound(ByteBuf packet, int oldId, int newId, int protoco
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;
Expand Down Expand Up @@ -169,7 +169,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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;
Expand All @@ -178,7 +178,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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 );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ public void rewriteClientbound(ByteBuf packet, int oldId, int newId, int protoco
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;
Expand Down Expand Up @@ -169,7 +169,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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;
Expand All @@ -178,7 +178,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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 );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ public void rewriteClientbound(ByteBuf packet, int oldId, int newId, int protoco
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;
Expand Down Expand Up @@ -169,7 +169,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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;
Expand All @@ -178,7 +178,7 @@ public void rewriteServerbound(ByteBuf packet, int oldId, int newId)
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 );
}
}
Expand Down
Loading

0 comments on commit 9740c0a

Please sign in to comment.