Skip to content

Commit

Permalink
fix(proxy): don't send packets to a client when client server is null
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed Oct 31, 2024
1 parent 42abe28 commit 17d3bbc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion proxy/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Versions 2.0.x and 2.1.x are protocol-compatible,
so there’s no need to worry if the server hasn't been updated to 2.1.x.

### Changes in 2.1.2
- Fixed buffer overflow when using AudioSender with delayed first frame.
- Fixed buffer overflow when using AudioSender with delayed first frame.
- Fixed client EncoderException on server switch caused by UDP packets sent to a client when client's server is null.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ private boolean sendPacket(ChannelHandlerContext ctx, NettyPacketUdp nettyPacket
} else {
receiver = connection.getRemoteAddress();
receiverSecret = connection.getSecret();

if (!connection.isConnected()) return true;
}

// rewrite to backend server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public final class NettyUdpProxyConnection implements UdpProxyConnection, Server
private InetSocketAddress remoteAddress;
@Setter
private RemoteServer remoteServer;
@Getter
private boolean connected = true;

@Override
Expand All @@ -52,6 +51,8 @@ public Optional<RemoteServer> getRemoteServer() {

@Override
public void sendPacket(Packet<?> packet) {
if (!isConnected()) return;

byte[] encoded = PacketUdpCodec.encode(packet, secret);
if (encoded == null) return;

Expand All @@ -70,6 +71,11 @@ public void disconnect() {
this.connected = false;
}

@Override
public boolean isConnected() {
return connected && player.getInstance().getServer() != null;
}

@Override
public void handle(@NotNull PingPacket packet) {
}
Expand Down

0 comments on commit 17d3bbc

Please sign in to comment.