diff --git a/gradlew-jar.bat b/gradlew-jar.bat new file mode 100644 index 00000000..d9fde181 --- /dev/null +++ b/gradlew-jar.bat @@ -0,0 +1,2 @@ +call .\gradlew jar +pause diff --git a/src/main/java/emu/grasscutter/config/ConfigContainer.java b/src/main/java/emu/grasscutter/config/ConfigContainer.java index 2e36dbaa..3f9550c6 100644 --- a/src/main/java/emu/grasscutter/config/ConfigContainer.java +++ b/src/main/java/emu/grasscutter/config/ConfigContainer.java @@ -1,5 +1,6 @@ package emu.grasscutter.config; +import ch.qos.logback.classic.Level; import com.google.gson.JsonObject; import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter.ServerDebugMode; @@ -101,6 +102,7 @@ public class ConfigContainer { public Game game = new Game(); public Dispatch dispatch = new Dispatch(); + public DebugMode debugMode = new DebugMode(); } public static class Language { @@ -150,6 +152,10 @@ public class ConfigContainer { public int kcpInterval = 20; /* Controls whether packets should be logged in console or not */ public ServerDebugMode logPackets = ServerDebugMode.NONE; + /* Show packet payload in console or no (in any case the payload is shown in encrypted view) */ + public Boolean isShowPacketPayload = false; + /* Show annoying loop packets or no */ + public Boolean isShowLoopPackets = false; public GameOptions gameOptions = new GameOptions(); public JoinOptions joinOptions = new JoinOptions(); @@ -163,9 +169,33 @@ public class ConfigContainer { public String defaultName = "Grasscutter"; + /* Controls whether http requests should be logged in console or not */ public ServerDebugMode logRequests = ServerDebugMode.NONE; } + /* Debug options container, used when jar launch argument is -debug | -debugall and override default values + * (see StartupArguments.enableDebug) */ + public static class DebugMode { + /* Log level of the main server code (works only with -debug arg) */ + public Level serverLoggerLevel = Level.DEBUG; + + /* Log level of the third-party services (works only with -debug arg): + javalin, quartz, reflections, jetty, mongodb.driver*/ + public Level servicesLoggersLevel = Level.INFO; + + /* Controls whether packets should be logged in console or not */ + public ServerDebugMode logPackets = ServerDebugMode.ALL; + + /* Show packet payload in console or no (in any case the payload is shown in encrypted view) */ + public Boolean isShowPacketPayload = false; + + /* Show annoying loop packets or no */ + public Boolean isShowLoopPackets = false; + + /* Controls whether http requests should be logged in console or not */ + public ServerDebugMode logRequests = ServerDebugMode.ALL; + } + public static class Encryption { public boolean useEncryption = true; /* Should 'https' be appended to URLs? */ diff --git a/src/main/java/emu/grasscutter/config/Configuration.java b/src/main/java/emu/grasscutter/config/Configuration.java index 98041bad..410cbd52 100644 --- a/src/main/java/emu/grasscutter/config/Configuration.java +++ b/src/main/java/emu/grasscutter/config/Configuration.java @@ -38,6 +38,7 @@ public final class Configuration extends ConfigContainer { public static final HTTP HTTP_INFO = config.server.http; public static final Game GAME_INFO = config.server.game; public static final Dispatch DISPATCH_INFO = config.server.dispatch; + public static final DebugMode DEBUG_MODE_INFO = config.server.debugMode; public static final Encryption HTTP_ENCRYPTION = config.server.http.encryption; public static final Policies HTTP_POLICIES = config.server.http.policies; diff --git a/src/main/java/emu/grasscutter/net/packet/PacketOpcodesUtils.java b/src/main/java/emu/grasscutter/net/packet/PacketOpcodesUtils.java index 0b5e32fb..73feb807 100644 --- a/src/main/java/emu/grasscutter/net/packet/PacketOpcodesUtils.java +++ b/src/main/java/emu/grasscutter/net/packet/PacketOpcodesUtils.java @@ -27,7 +27,8 @@ public class PacketOpcodesUtils { PacketOpcodes.PingRsp, PacketOpcodes.WorldPlayerRTTNotify, PacketOpcodes.UnionCmdNotify, - PacketOpcodes.QueryPathReq + PacketOpcodes.QueryPathReq, + PacketOpcodes.QueryPathRsp ); static { diff --git a/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java b/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java index 2808e6e8..260dc84b 100644 --- a/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java +++ b/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java @@ -99,7 +99,7 @@ public class GameServerPacketHandler { } // Log unhandled packets - if (GAME_INFO.logPackets == ServerDebugMode.MISSING) { + if (GAME_INFO.logPackets == ServerDebugMode.MISSING || GAME_INFO.logPackets == ServerDebugMode.ALL) { Grasscutter.getLogger().info("Unhandled packet (" + opcode + "): " + emu.grasscutter.net.packet.PacketOpcodesUtils.getOpcodeName(opcode)); } } diff --git a/src/main/java/emu/grasscutter/server/game/GameSession.java b/src/main/java/emu/grasscutter/server/game/GameSession.java index 11254f87..3788b8f6 100644 --- a/src/main/java/emu/grasscutter/server/game/GameSession.java +++ b/src/main/java/emu/grasscutter/server/game/GameSession.java @@ -98,7 +98,8 @@ public class GameSession implements GameSessionManager.KcpChannel { public void logPacket(String sendOrRecv, int opcode, byte[] payload) { Grasscutter.getLogger().info(sendOrRecv + ": " + PacketOpcodesUtils.getOpcodeName(opcode) + " (" + opcode + ")"); - System.out.println(Utils.bytesToHex(payload)); + if (GAME_INFO.isShowPacketPayload) + System.out.println(Utils.bytesToHex(payload)); } public void send(BasePacket packet) { @@ -122,7 +123,7 @@ public class GameSession implements GameSessionManager.KcpChannel { // Log switch (GAME_INFO.logPackets) { case ALL -> { - if (!PacketOpcodesUtils.LOOP_PACKETS.contains(packet.getOpcode())) { + if (!PacketOpcodesUtils.LOOP_PACKETS.contains(packet.getOpcode()) || GAME_INFO.isShowLoopPackets) { logPacket("SEND", packet.getOpcode(), packet.getData()); } } @@ -154,7 +155,6 @@ public class GameSession implements GameSessionManager.KcpChannel { Grasscutter.getLogger().info(translate("messages.game.connect", this.getAddress().toString())); } - @Override public void handleReceive(byte[] bytes) { // Decrypt and turn back into a packet @@ -200,7 +200,7 @@ public class GameSession implements GameSessionManager.KcpChannel { // Log packet switch (GAME_INFO.logPackets) { case ALL -> { - if (!PacketOpcodesUtils.LOOP_PACKETS.contains(opcode)) { + if (!PacketOpcodesUtils.LOOP_PACKETS.contains(opcode) || GAME_INFO.isShowLoopPackets) { logPacket("RECV", opcode, payload); } } diff --git a/src/main/java/emu/grasscutter/utils/StartupArguments.java b/src/main/java/emu/grasscutter/utils/StartupArguments.java index 7d93079c..90fff043 100644 --- a/src/main/java/emu/grasscutter/utils/StartupArguments.java +++ b/src/main/java/emu/grasscutter/utils/StartupArguments.java @@ -6,12 +6,13 @@ import emu.grasscutter.BuildConfig; import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter.ServerRunMode; import emu.grasscutter.net.packet.PacketOpcodesUtils; -import io.javalin.core.util.JavalinLogger; import org.slf4j.LoggerFactory; import java.util.Map; import java.util.function.Function; +import static emu.grasscutter.config.Configuration.*; + /** * A parser for start-up arguments. */ @@ -80,14 +81,21 @@ public final class StartupArguments { * @return False to continue execution. */ private static boolean enableDebug(String parameter) { - // Get the level by parameter. - var loggerLevel = parameter != null && parameter.equals("all") - ? Level.DEBUG : Level.INFO; + if (parameter != null && parameter.equals("all")) { + // Override default debug configs + GAME_INFO.isShowLoopPackets = DEBUG_MODE_INFO.isShowLoopPackets; + GAME_INFO.isShowPacketPayload = DEBUG_MODE_INFO.isShowPacketPayload; + GAME_INFO.logPackets = DEBUG_MODE_INFO.logPackets; + DISPATCH_INFO.logRequests = DEBUG_MODE_INFO.logRequests; + } - // Set the logger to debug. - Grasscutter.getLogger().setLevel(Level.DEBUG); + // Set the main logger to debug. + Grasscutter.getLogger().setLevel(DEBUG_MODE_INFO.serverLoggerLevel); Grasscutter.getLogger().debug("The logger is now running in debug mode."); + // Log level to other third-party services + Level loggerLevel = DEBUG_MODE_INFO.servicesLoggersLevel; + // Change loggers to debug. ((Logger) LoggerFactory.getLogger("io.javalin")) .setLevel(loggerLevel);