From f966a34c1ad6ec39407b21af22183678b009dde8 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Mon, 16 Sep 2024 22:35:46 +0200 Subject: [PATCH] Log play state disconnect messages --- .../client2proxy/Client2ProxyHandler.java | 1 + .../DisconnectPacketHandler.java | 46 +++++++++++++++++++ .../packethandler/LoginPacketHandler.java | 10 ++-- 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 src/main/java/net/raphimc/viaproxy/proxy/packethandler/DisconnectPacketHandler.java diff --git a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java index c021fcb..c57aee4 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java @@ -242,6 +242,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler { } this.proxyConnection.getPacketHandlers().add(new CompressionPacketHandler(this.proxyConnection)); this.proxyConnection.getPacketHandlers().add(new LoginPacketHandler(this.proxyConnection)); + this.proxyConnection.getPacketHandlers().add(new DisconnectPacketHandler(this.proxyConnection)); if (clientVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) { this.proxyConnection.getPacketHandlers().add(new TransferPacketHandler(this.proxyConnection)); } diff --git a/src/main/java/net/raphimc/viaproxy/proxy/packethandler/DisconnectPacketHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/packethandler/DisconnectPacketHandler.java new file mode 100644 index 0000000..32403a0 --- /dev/null +++ b/src/main/java/net/raphimc/viaproxy/proxy/packethandler/DisconnectPacketHandler.java @@ -0,0 +1,46 @@ +/* + * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy + * Copyright (C) 2021-2024 RK_01/RaphiMC and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.raphimc.viaproxy.proxy.packethandler; + +import io.netty.channel.ChannelFutureListener; +import net.raphimc.netminecraft.packet.Packet; +import net.raphimc.netminecraft.packet.impl.common.S2CDisconnectPacket; +import net.raphimc.netminecraft.packet.impl.login.S2CLoginDisconnectPacket; +import net.raphimc.viaproxy.cli.ConsoleFormatter; +import net.raphimc.viaproxy.proxy.session.ProxyConnection; +import net.raphimc.viaproxy.util.logging.Logger; + +import java.util.List; + +public class DisconnectPacketHandler extends PacketHandler { + + public DisconnectPacketHandler(ProxyConnection proxyConnection) { + super(proxyConnection); + } + + @Override + public boolean handleP2S(Packet packet, List listeners) throws Exception { + if (packet instanceof S2CLoginDisconnectPacket loginDisconnectPacket) { + Logger.u_info("server disconnect", this.proxyConnection, ConsoleFormatter.convert(loginDisconnectPacket.reason.asLegacyFormatString())); + } else if (packet instanceof S2CDisconnectPacket disconnectPacket) { + Logger.u_info("server disconnect", this.proxyConnection, ConsoleFormatter.convert(disconnectPacket.reason.asLegacyFormatString())); + } + return super.handleP2S(packet, listeners); + } + +} diff --git a/src/main/java/net/raphimc/viaproxy/proxy/packethandler/LoginPacketHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/packethandler/LoginPacketHandler.java index d4dc512..88ba13a 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/packethandler/LoginPacketHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/packethandler/LoginPacketHandler.java @@ -25,11 +25,13 @@ import net.raphimc.netminecraft.constants.MCPipeline; import net.raphimc.netminecraft.netty.crypto.AESEncryption; import net.raphimc.netminecraft.netty.crypto.CryptUtil; import net.raphimc.netminecraft.packet.Packet; -import net.raphimc.netminecraft.packet.impl.login.*; +import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket; +import net.raphimc.netminecraft.packet.impl.login.C2SLoginKeyPacket; +import net.raphimc.netminecraft.packet.impl.login.S2CLoginGameProfilePacket; +import net.raphimc.netminecraft.packet.impl.login.S2CLoginHelloPacket; import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.protocol.release.r1_6_4tor1_7_2_5.storage.ProtocolMetadataStorage; import net.raphimc.viaproxy.ViaProxy; -import net.raphimc.viaproxy.cli.ConsoleFormatter; import net.raphimc.viaproxy.plugins.events.ClientLoggedInEvent; import net.raphimc.viaproxy.plugins.events.ShouldVerifyOnlineModeEvent; import net.raphimc.viaproxy.proxy.LoginState; @@ -138,9 +140,7 @@ public class LoginPacketHandler extends PacketHandler { @Override public boolean handleP2S(Packet packet, List listeners) throws GeneralSecurityException, ExecutionException, InterruptedException { - if (packet instanceof S2CLoginDisconnectPacket loginDisconnectPacket) { - Logger.u_info("server kick", this.proxyConnection, ConsoleFormatter.convert(loginDisconnectPacket.reason.asLegacyFormatString())); - } else if (packet instanceof S2CLoginHelloPacket loginHelloPacket) { + if (packet instanceof S2CLoginHelloPacket loginHelloPacket) { final PublicKey publicKey = CryptUtil.decodeRsaPublicKey(loginHelloPacket.publicKey); final SecretKey secretKey = CryptUtil.generateSecretKey(); final String serverHash = new BigInteger(CryptUtil.computeServerIdHash(loginHelloPacket.serverId, publicKey, secretKey)).toString(16);