Skip to content

Commit

Permalink
Merge pull request #6 from Arikatsu/development
Browse files Browse the repository at this point in the history
Add config option to disable logging for looping packets
  • Loading branch information
Hiro420 authored Nov 28, 2023
2 parents 55ff4c1 + c713cf0 commit 6f631dd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/emu/lunarcore/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public static class LogOptions {
public boolean commands = true;
public boolean connections = true;
public boolean packets = false;
public boolean filterLoopingPackets = false;
}

@Getter
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/emu/lunarcore/server/game/GameSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public void onMessage(ByteBuf packet) {

// Log packet
if (LunarCore.getConfig().getLogOptions().packets) {
if (LunarCore.getConfig().getLogOptions().filterLoopingPackets && CmdIdUtils.LOOP_PACKETS.contains(opcode)) {
return;
}

logPacket("RECV", opcode, data);
}

Expand All @@ -152,6 +156,10 @@ public void send(BasePacket packet) {

// Log
if (LunarCore.getConfig().getLogOptions().packets) {
if (LunarCore.getConfig().getLogOptions().filterLoopingPackets && CmdIdUtils.LOOP_PACKETS.contains(packet.getOpcode())) {
return;
}

logPacket("SEND", packet.getOpcode(), packet.getData());
}
}
Expand All @@ -167,6 +175,10 @@ public void send(int cmdId) {

// Log
if (LunarCore.getConfig().getLogOptions().packets) {
if (LunarCore.getConfig().getLogOptions().filterLoopingPackets && CmdIdUtils.LOOP_PACKETS.contains(cmdId)) {
return;
}

logPacket("SEND", cmdId, null);
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/emu/lunarcore/server/packet/CmdIdUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;

Expand All @@ -14,6 +15,13 @@
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;

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;

static {
Expand Down

0 comments on commit 6f631dd

Please sign in to comment.