mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-10 04:12:54 +08:00
Added more server debug options (#1444)
Original commits: * Added more server debug options * made server debug code prettier * fixed initialization bug * Enables logging of packets contained in UnionCmdNotify, when debug level is WHITELIST or BLACKLIST
This commit is contained in:
parent
9033c966d8
commit
c79ca3028f
@ -4,6 +4,8 @@ import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import emu.grasscutter.Grasscutter.ServerDebugMode;
|
||||
import emu.grasscutter.auth.AuthenticationSystem;
|
||||
import emu.grasscutter.auth.DefaultAuthentication;
|
||||
import emu.grasscutter.command.CommandMap;
|
||||
@ -412,6 +414,6 @@ public final class Grasscutter {
|
||||
}
|
||||
|
||||
public enum ServerDebugMode {
|
||||
ALL, MISSING, NONE
|
||||
ALL, MISSING, WHITELIST, BLACKLIST, NONE
|
||||
}
|
||||
}
|
||||
|
@ -125,6 +125,10 @@ public class GameSession implements GameSessionManager.KcpChannel {
|
||||
send(basePacket);
|
||||
}
|
||||
|
||||
public void logPacket( String sendOrRecv, int opcode, byte[] payload) {
|
||||
Grasscutter.getLogger().info(sendOrRecv + ": " + PacketOpcodesUtil.getOpcodeName(opcode) + " (" + opcode + ")");
|
||||
System.out.println(Utils.bytesToHex(payload));
|
||||
}
|
||||
public void send(BasePacket packet) {
|
||||
// Test
|
||||
if (packet.getOpcode() <= 0) {
|
||||
@ -146,10 +150,18 @@ public class GameSession implements GameSessionManager.KcpChannel {
|
||||
// Log
|
||||
if (SERVER.debugLevel == ServerDebugMode.ALL) {
|
||||
if (!loopPacket.contains(packet.getOpcode())) {
|
||||
Grasscutter.getLogger().info("SEND: " + PacketOpcodesUtil.getOpcodeName(packet.getOpcode()) + " (" + packet.getOpcode() + ")");
|
||||
System.out.println(Utils.bytesToHex(packet.getData()));
|
||||
logPacket("SEND",packet.getOpcode(), packet.getData());
|
||||
}
|
||||
}
|
||||
|
||||
if (SERVER.debugLevel == ServerDebugMode.WHITELIST && SERVER.DebugWhitelist.contains(packet.getOpcode())) {
|
||||
logPacket("SEND",packet.getOpcode(), packet.getData());
|
||||
}
|
||||
|
||||
if (SERVER.debugLevel == ServerDebugMode.BLACKLIST && !(SERVER.DebugBlacklist.contains(packet.getOpcode()))) {
|
||||
logPacket("SEND",packet.getOpcode(), packet.getData());
|
||||
}
|
||||
|
||||
// Invoke event.
|
||||
SendPacketEvent event = new SendPacketEvent(this, packet); event.call();
|
||||
if(!event.isCanceled()) { // If event is not cancelled, continue.
|
||||
@ -216,10 +228,18 @@ public class GameSession implements GameSessionManager.KcpChannel {
|
||||
// Log packet
|
||||
if (allDebug) {
|
||||
if (!loopPacket.contains(opcode)) {
|
||||
Grasscutter.getLogger().info("RECV: " + PacketOpcodesUtil.getOpcodeName(opcode) + " (" + opcode + ")");
|
||||
System.out.println(Utils.bytesToHex(payload));
|
||||
logPacket("RECV",opcode, payload);
|
||||
}
|
||||
}
|
||||
|
||||
if (SERVER.debugLevel == ServerDebugMode.WHITELIST && SERVER.DebugWhitelist.contains(opcode)) {
|
||||
logPacket("RECV",opcode, payload);
|
||||
}
|
||||
|
||||
if (SERVER.debugLevel == ServerDebugMode.BLACKLIST && !(SERVER.DebugBlacklist.contains(opcode))) {
|
||||
logPacket("RECV",opcode, payload);
|
||||
}
|
||||
|
||||
// Handle
|
||||
getServer().getPacketHandler().handle(this, opcode, header, payload);
|
||||
}
|
||||
|
@ -1,11 +1,15 @@
|
||||
package emu.grasscutter.server.packet.recv;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.net.packet.Opcodes;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.UnionCmdNotifyOuterClass.UnionCmdNotify;
|
||||
import emu.grasscutter.net.proto.UnionCmdOuterClass.UnionCmd;
|
||||
import emu.grasscutter.net.packet.PacketHandler;
|
||||
import emu.grasscutter.server.game.GameSession;
|
||||
import emu.grasscutter.Grasscutter.ServerDebugMode;
|
||||
|
||||
import static emu.grasscutter.Configuration.SERVER;
|
||||
|
||||
@Opcodes(PacketOpcodes.UnionCmdNotify)
|
||||
public class HandlerUnionCmdNotify extends PacketHandler {
|
||||
@ -13,7 +17,15 @@ public class HandlerUnionCmdNotify extends PacketHandler {
|
||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||
UnionCmdNotify req = UnionCmdNotify.parseFrom(payload);
|
||||
for (UnionCmd cmd : req.getCmdListList()) {
|
||||
session.getServer().getPacketHandler().handle(session, cmd.getMessageId(), EMPTY_BYTE_ARRAY, cmd.getBody().toByteArray());
|
||||
int cmdOpcode = cmd.getMessageId();
|
||||
byte[] cmdPayload = cmd.getBody().toByteArray();
|
||||
if(Grasscutter.config.server.debugLevel == ServerDebugMode.WHITELIST && SERVER.DebugWhitelist.contains(cmd.getMessageId())) {
|
||||
session.logPacket("RECV in Union", cmdOpcode, cmdPayload);
|
||||
} else if (Grasscutter.config.server.debugLevel == ServerDebugMode.BLACKLIST && !SERVER.DebugBlacklist.contains(cmd.getMessageId())) {
|
||||
session.logPacket("RECV in Union", cmdOpcode, cmdPayload);
|
||||
}
|
||||
//debugLevel ALL ignores UnionCmdNotify, so we will also ignore the contained opcodes
|
||||
session.getServer().getPacketHandler().handle(session, cmd.getMessageId(), EMPTY_BYTE_ARRAY, cmd.getBody().toByteArray());
|
||||
}
|
||||
|
||||
// Update
|
||||
|
@ -5,6 +5,7 @@ import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.Grasscutter.ServerDebugMode;
|
||||
import emu.grasscutter.Grasscutter.ServerRunMode;
|
||||
|
||||
import java.util.Set;
|
||||
import java.io.FileReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
@ -93,6 +94,8 @@ public class ConfigContainer {
|
||||
|
||||
public static class Server {
|
||||
public ServerDebugMode debugLevel = ServerDebugMode.NONE;
|
||||
public Set<Integer> DebugWhitelist = Set.of();
|
||||
public Set<Integer> DebugBlacklist = Set.of();
|
||||
public ServerRunMode runMode = ServerRunMode.HYBRID;
|
||||
|
||||
public HTTP http = new HTTP();
|
||||
|
Loading…
Reference in New Issue
Block a user