Merge pull request #6 from Arikatsu/development

Add config option to disable logging for looping packets
This commit is contained in:
Hiro
2023-11-28 20:18:15 +02:00
committed by GitHub
3 changed files with 21 additions and 0 deletions

View File

@@ -130,6 +130,7 @@ public class Config {
public boolean commands = true; public boolean commands = true;
public boolean connections = true; public boolean connections = true;
public boolean packets = false; public boolean packets = false;
public boolean filterLoopingPackets = false;
} }
@Getter @Getter

View File

@@ -127,6 +127,10 @@ public class GameSession {
// Log packet // Log packet
if (LunarCore.getConfig().getLogOptions().packets) { if (LunarCore.getConfig().getLogOptions().packets) {
if (LunarCore.getConfig().getLogOptions().filterLoopingPackets && CmdIdUtils.LOOP_PACKETS.contains(opcode)) {
return;
}
logPacket("RECV", opcode, data); logPacket("RECV", opcode, data);
} }
@@ -152,6 +156,10 @@ public class GameSession {
// Log // Log
if (LunarCore.getConfig().getLogOptions().packets) { if (LunarCore.getConfig().getLogOptions().packets) {
if (LunarCore.getConfig().getLogOptions().filterLoopingPackets && CmdIdUtils.LOOP_PACKETS.contains(packet.getOpcode())) {
return;
}
logPacket("SEND", packet.getOpcode(), packet.getData()); logPacket("SEND", packet.getOpcode(), packet.getData());
} }
} }
@@ -167,6 +175,10 @@ public class GameSession {
// Log // Log
if (LunarCore.getConfig().getLogOptions().packets) { if (LunarCore.getConfig().getLogOptions().packets) {
if (LunarCore.getConfig().getLogOptions().filterLoopingPackets && CmdIdUtils.LOOP_PACKETS.contains(cmdId)) {
return;
}
logPacket("SEND", cmdId, null); logPacket("SEND", cmdId, null);
} }
} }

View File

@@ -4,6 +4,7 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -14,6 +15,13 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class CmdIdUtils { public class CmdIdUtils {
public static final Set<Integer> LOOP_PACKETS = Set.of(
CmdId.PlayerHeartBeatCsReq,
CmdId.PlayerHeartBeatScRsp,
CmdId.SceneEntityMoveCsReq,
CmdId.SceneEntityMoveScRsp
);
private static Int2ObjectMap<String> opcodeMap; private static Int2ObjectMap<String> opcodeMap;
static { static {