From 9dd514a73bdca18c6b4b5d47906b68a20d4eddca Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Thu, 1 Jun 2023 18:17:15 -0400 Subject: [PATCH] Catch exception when unable to write to KCP client --- .../grasscutter/server/game/GameSession.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/emu/grasscutter/server/game/GameSession.java b/src/main/java/emu/grasscutter/server/game/GameSession.java index 46c00e090..0038db015 100644 --- a/src/main/java/emu/grasscutter/server/game/GameSession.java +++ b/src/main/java/emu/grasscutter/server/game/GameSession.java @@ -1,27 +1,21 @@ package emu.grasscutter.server.game; -import static emu.grasscutter.config.Configuration.GAME_INFO; -import static emu.grasscutter.config.Configuration.SERVER; -import static emu.grasscutter.utils.lang.Language.translate; - import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter.ServerDebugMode; import emu.grasscutter.game.Account; import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.packet.PacketOpcodesUtils; +import emu.grasscutter.net.packet.*; import emu.grasscutter.server.event.game.SendPacketEvent; -import emu.grasscutter.utils.Crypto; -import emu.grasscutter.utils.FileUtils; -import emu.grasscutter.utils.Utils; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; +import emu.grasscutter.utils.*; +import io.netty.buffer.*; +import lombok.*; + import java.io.File; import java.net.InetSocketAddress; import java.nio.file.Path; -import lombok.Getter; -import lombok.Setter; + +import static emu.grasscutter.config.Configuration.*; +import static emu.grasscutter.utils.lang.Language.translate; public class GameSession implements GameSessionManager.KcpChannel { private final GameServer server; @@ -139,7 +133,11 @@ public class GameSession implements GameSessionManager.KcpChannel { SendPacketEvent event = new SendPacketEvent(this, packet); event.call(); if (!event.isCanceled()) { // If event is not cancelled, continue. - tunnel.writeData(event.getPacket().build()); + try { + tunnel.writeData(event.getPacket().build()); + } catch (Exception ignored) { + Grasscutter.getLogger().debug("Unable to send packet to client."); + } } }