diff --git a/src/main/java/emu/grasscutter/config/ConfigContainer.java b/src/main/java/emu/grasscutter/config/ConfigContainer.java index 0fbe27ea..d8acb37f 100644 --- a/src/main/java/emu/grasscutter/config/ConfigContainer.java +++ b/src/main/java/emu/grasscutter/config/ConfigContainer.java @@ -95,8 +95,8 @@ public class ConfigContainer { } public static class Server { - public Set debugWhitelist = Set.of(); - public Set debugBlacklist = Set.of(); + public Set debugWhitelist = Set.of(); + public Set debugBlacklist = Set.of(); public ServerRunMode runMode = ServerRunMode.HYBRID; public boolean logCommands = false; diff --git a/src/main/java/emu/grasscutter/net/packet/PacketOpcodesUtils.java b/src/main/java/emu/grasscutter/net/packet/PacketOpcodesUtils.java index 4810f3d2..14ad2e41 100644 --- a/src/main/java/emu/grasscutter/net/packet/PacketOpcodesUtils.java +++ b/src/main/java/emu/grasscutter/net/packet/PacketOpcodesUtils.java @@ -20,24 +20,24 @@ import messages.VERSION; public class PacketOpcodesUtils { private static Int2ObjectMap opcodeMap; - public static final Set BANNED_PACKETS = Set.of( - PacketOpcodes.WindSeedClientNotify, - PacketOpcodes.PlayerLuaShellNotify + public static final Set BANNED_PACKETS = Set.of( + "WindSeedClientNotify", + "PlayerLuaShellNotify" ); - public static final Set LOOP_PACKETS = Set.of( - PacketOpcodes.PingReq, - PacketOpcodes.PingRsp, - PacketOpcodes.WorldPlayerRTTNotify, - PacketOpcodes.UnionCmdNotify, - PacketOpcodes.QueryPathReq, - PacketOpcodes.QueryPathRsp, + public static final Set LOOP_PACKETS = Set.of( + "PingReq", + "PingRsp", + "WorldPlayerRTTNotify", + "UnionCmdNotify", + "QueryPathReq", + "QueryPathRsp", // Satiation sends these every tick - PacketOpcodes.PlayerTimeNotify, - PacketOpcodes.PlayerGameTimeNotify, - PacketOpcodes.AvatarPropNotify, - PacketOpcodes.AvatarSatiationDataNotify + "PlayerTimeNotify", + "PlayerGameTimeNotify", + "AvatarPropNotify", + "AvatarSatiationDataNotify" ); static { diff --git a/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java b/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java index 7c14f766..11bde50d 100644 --- a/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java +++ b/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java @@ -2,8 +2,6 @@ package emu.grasscutter.server.game; import static emu.grasscutter.config.Configuration.*; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -14,7 +12,6 @@ import emu.grasscutter.server.event.game.ReceivePacketEvent; import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter.ServerDebugMode; import emu.grasscutter.server.game.GameSession.SessionState; -import interfaces.ProtoModel; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; @@ -77,34 +74,34 @@ public class GameServerPacketHandler { } @Nullable - private PacketHandler getHandler(GameSession session, int opcode) { - String name = session.getPackageIdProvider().getPacketName(opcode); - PacketHandler handler = this.versionHandlers.get(name); + private PacketHandler getHandler(String packageName, int opcode) { + PacketHandler handler = this.versionHandlers.get(packageName); return handler!= null ? handler : this.handlers.get(opcode); } public void handle(GameSession session, int opcode, byte[] header, byte[] payload) { - PacketHandler handler = getHandler(session, opcode); + String packageName = session.getPackageIdProvider().getPacketName(opcode); + PacketHandler handler = getHandler(packageName, opcode); if (handler != null) { try { // Make sure session is ready for packets SessionState state = session.getState(); - if (opcode == PacketOpcodes.PingReq) { + if ("PingReq".equals(packageName)) { // Always continue if packet is ping request - } else if (opcode == PacketOpcodes.GetPlayerTokenReq) { + } else if ("GetPlayerTokenReq".equals(packageName)) { if (state != SessionState.WAITING_FOR_TOKEN) { return; } } else if (state == SessionState.ACCOUNT_BANNED) { session.close(); return; - } else if (opcode == PacketOpcodes.PlayerLoginReq) { + } else if ("PlayerLoginReq".equals(packageName)) { if (state != SessionState.WAITING_FOR_LOGIN) { return; } - } else if (opcode == PacketOpcodes.SetPlayerBornDataReq) { + } else if ("SetPlayerBornDataReq".equals(packageName)) { if (state != SessionState.PICKING_CHARACTER) { return; } diff --git a/src/main/java/emu/grasscutter/server/game/GameSession.java b/src/main/java/emu/grasscutter/server/game/GameSession.java index ed143ac5..cc51e12a 100644 --- a/src/main/java/emu/grasscutter/server/game/GameSession.java +++ b/src/main/java/emu/grasscutter/server/game/GameSession.java @@ -9,7 +9,6 @@ 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.server.event.game.SendPacketEvent; import emu.grasscutter.utils.Crypto; @@ -20,6 +19,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import lombok.Getter; import lombok.Setter; +import lombok.val; import org.anime_game_servers.core.base.Version; import packet_id.PacketIds; @@ -124,19 +124,20 @@ public class GameSession implements GameSessionManager.KcpChannel { } // Log + val paketName = PacketOpcodesUtils.getOpcodeName(packet.getOpcode(this), this); switch (GAME_INFO.logPackets) { case ALL -> { - if (!PacketOpcodesUtils.LOOP_PACKETS.contains(packet.getOpcode(this)) || GAME_INFO.isShowLoopPackets) { + if (!PacketOpcodesUtils.LOOP_PACKETS.contains(paketName) || GAME_INFO.isShowLoopPackets) { logPacket("SEND", packet.getOpcode(this), packet.getData(version)); } } case WHITELIST -> { - if (SERVER.debugWhitelist.contains(packet.getOpcode(this))) { + if (SERVER.debugWhitelist.contains(paketName)) { logPacket("SEND", packet.getOpcode(this), packet.getData(version)); } } case BLACKLIST -> { - if (!SERVER.debugBlacklist.contains(packet.getOpcode(this))) { + if (!SERVER.debugBlacklist.contains(paketName)) { logPacket("SEND", packet.getOpcode(this), packet.getData(version)); } } @@ -244,7 +245,8 @@ public class GameSession implements GameSessionManager.KcpChannel { player.onLogout(); } try { - send(new BasePacket(PacketOpcodes.ServerDisconnectClientNotify)); + val disconnectPacketId = getPackageIdProvider().getPacketId("ServerDisconnectClientNotify"); + send(new BasePacket(disconnectPacketId)); } catch (Throwable ignore) { Grasscutter.getLogger().warn("closing {} error", getAddress().getAddress().getHostAddress()); }