Use log4j for monitored chr logger. Log all monitored to a dedicated file.

This commit is contained in:
P0nk
2021-12-21 21:07:18 +01:00
parent 507ab06721
commit 6c1a9465c0
10 changed files with 49 additions and 24 deletions

View File

@@ -1,11 +1,20 @@
package net.packet.logging;
import io.netty.buffer.Unpooled;
import net.opcodes.RecvOpcode;
import java.util.Set;
public class LoggingUtil {
private static final Set<Short> ignoredDebugRecvPackets = Set.of((short) 167, (short) 197, (short) 89, (short) 91, (short) 41, (short) 188, (short) 107);
private static final Set<Short> ignoredDebugRecvPackets = Set.of(
(short) RecvOpcode.MOVE_PLAYER.getValue(), // 41
(short) RecvOpcode.HEAL_OVER_TIME.getValue(), // 89
(short) RecvOpcode.SPECIAL_MOVE.getValue(), // 91
(short) RecvOpcode.QUEST_ACTION.getValue(), // 107
(short) RecvOpcode.MOVE_PET.getValue(), // 167
(short) RecvOpcode.MOVE_LIFE.getValue(), // 188
(short) RecvOpcode.NPC_ACTION.getValue() // 197
);
public static short readFirstShort(byte[] bytes) {
return Unpooled.wrappedBuffer(bytes).readShortLE();

View File

@@ -23,7 +23,8 @@ package net.packet.logging;
import client.Character;
import client.Client;
import net.opcodes.RecvOpcode;
import tools.FilePrinter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.HexTool;
import java.util.Arrays;
@@ -31,16 +32,17 @@ import java.util.HashSet;
import java.util.Set;
/**
* Logs packets to console and file.
* Logs packets from monitored characters to a file.
*
* @author Alan (SharpAceX)
*/
public class MapleLogger {
public class MonitoredChrLogger {
private static final Logger log = LoggerFactory.getLogger(MonitoredChrLogger.class);
public static final Set<Integer> monitored = new HashSet<>();
public static final Set<Integer> ignored = new HashSet<>();
public static void logRecv(Client c, short packetId, byte[] packetContent) {
public static void logPacketIfMonitored(Client c, short packetId, byte[] packetContent) {
Character chr = c.getPlayer();
if (chr == null) {
return;
@@ -52,8 +54,9 @@ public class MapleLogger {
if (isRecvBlocked(op)) {
return;
}
String packet = op + "\r\n" + HexTool.toString(packetContent);
FilePrinter.printError(FilePrinter.PACKET_LOGS + c.getAccountName() + "-" + chr.getName() + ".txt", packet);
String packet = packetContent.length > 0 ? HexTool.toString(packetContent) : "<empty>";
log.info("{}-{} {}-{}", c.getAccountName(), chr.getName(), packetId, packet);
}
private static boolean isRecvBlocked(RecvOpcode op) {