From 17d3bbcae5bb25ba88b84bba7bbd65e29800080d Mon Sep 17 00:00:00 2001 From: Apehum <36326454+Apehum@users.noreply.github.com> Date: Thu, 31 Oct 2024 19:01:41 +0800 Subject: [PATCH] fix(proxy): don't send packets to a client when client server is null --- proxy/changelog.md | 3 ++- .../su/plo/voice/proxy/socket/NettyPacketHandler.java | 2 ++ .../plo/voice/proxy/socket/NettyUdpProxyConnection.java | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/proxy/changelog.md b/proxy/changelog.md index 69ba0ade..8c44a4ac 100644 --- a/proxy/changelog.md +++ b/proxy/changelog.md @@ -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. \ No newline at end of file +- 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. \ No newline at end of file diff --git a/proxy/common/src/main/java/su/plo/voice/proxy/socket/NettyPacketHandler.java b/proxy/common/src/main/java/su/plo/voice/proxy/socket/NettyPacketHandler.java index ef091696..8a27bd41 100644 --- a/proxy/common/src/main/java/su/plo/voice/proxy/socket/NettyPacketHandler.java +++ b/proxy/common/src/main/java/su/plo/voice/proxy/socket/NettyPacketHandler.java @@ -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 diff --git a/proxy/common/src/main/java/su/plo/voice/proxy/socket/NettyUdpProxyConnection.java b/proxy/common/src/main/java/su/plo/voice/proxy/socket/NettyUdpProxyConnection.java index ae90a5b7..f483db06 100644 --- a/proxy/common/src/main/java/su/plo/voice/proxy/socket/NettyUdpProxyConnection.java +++ b/proxy/common/src/main/java/su/plo/voice/proxy/socket/NettyUdpProxyConnection.java @@ -42,7 +42,6 @@ public final class NettyUdpProxyConnection implements UdpProxyConnection, Server private InetSocketAddress remoteAddress; @Setter private RemoteServer remoteServer; - @Getter private boolean connected = true; @Override @@ -52,6 +51,8 @@ public Optional getRemoteServer() { @Override public void sendPacket(Packet packet) { + if (!isConnected()) return; + byte[] encoded = PacketUdpCodec.encode(packet, secret); if (encoded == null) return; @@ -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) { }