Fix packet handling

This commit is contained in:
KingRainbow44 2023-09-16 19:25:37 -04:00
parent 3d2e0d0451
commit 539fa16160
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
3 changed files with 6 additions and 8 deletions

View File

@ -77,7 +77,7 @@ public final class GameServerPacketHandler {
// Invoke event. // Invoke event.
var event = new ReceivePacketEvent(session, opcode, payload); var event = new ReceivePacketEvent(session, opcode, payload);
if (!event.call()) // If event is not canceled, continue. if (event.call()) // If event is not canceled, continue.
handler.handle(session, header, event.getPacketData()); handler.handle(session, header, event.getPacketData());
} catch (Exception ex) { } catch (Exception ex) {
Grasscutter.getLogger().warn("Unable to handle packet.", ex); Grasscutter.getLogger().warn("Unable to handle packet.", ex);

View File

@ -148,7 +148,7 @@ public class GameSession implements KcpChannel {
if (packet.shouldEncrypt) { if (packet.shouldEncrypt) {
Crypto.xor(bytes, packet.useDispatchKey() ? Crypto.DISPATCH_KEY : this.encryptKey); Crypto.xor(bytes, packet.useDispatchKey() ? Crypto.DISPATCH_KEY : this.encryptKey);
} }
tunnel.writeData(bytes); this.tunnel.writeData(bytes);
} catch (Exception ignored) { } catch (Exception ignored) {
Grasscutter.getLogger().debug("Unable to send packet to client."); Grasscutter.getLogger().debug("Unable to send packet to client.");
} }
@ -228,8 +228,8 @@ public class GameSession implements KcpChannel {
// Handle // Handle
getServer().getPacketHandler().handle(this, opcode, header, payload); getServer().getPacketHandler().handle(this, opcode, header, payload);
} }
} catch (Exception e) { } catch (Exception exception) {
e.printStackTrace(); Grasscutter.getLogger().warn("Unable to handle packet.", exception);
} finally { } finally {
// byteBuf.release(); //Needn't // byteBuf.release(); //Needn't
packet.release(); packet.release();

View File

@ -70,10 +70,8 @@ public final class GameSessionManager implements KcpListener {
} }
// Handle the message in a separate thread. // Handle the message in a separate thread.
executor.submit(() -> {
var bytes = Utils.byteBufToArray(byteBuf); var bytes = Utils.byteBufToArray(byteBuf);
session.onMessage(bytes); executor.submit(() -> session.onMessage(bytes));
});
} }
@Override @Override