Encapsulate "monitored" collection
This commit is contained in:
@@ -22,12 +22,14 @@ package net.packet.logging;
|
||||
|
||||
import client.Character;
|
||||
import client.Client;
|
||||
import net.jcip.annotations.NotThreadSafe;
|
||||
import net.opcodes.RecvOpcode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import tools.HexTool;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -36,18 +38,37 @@ import java.util.Set;
|
||||
*
|
||||
* @author Alan (SharpAceX)
|
||||
*/
|
||||
|
||||
@NotThreadSafe
|
||||
public class MonitoredChrLogger {
|
||||
private static final Logger log = LoggerFactory.getLogger(MonitoredChrLogger.class);
|
||||
public static final Set<Integer> monitored = new HashSet<>();
|
||||
private static final Set<Integer> monitoredChrIds = new HashSet<>();
|
||||
public static final Set<Integer> ignored = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Toggle monitored status for a character id
|
||||
*
|
||||
* @return new status. true if the chrId is now monitored, otherwise false.
|
||||
*/
|
||||
public static boolean toggleMonitored(int chrId) {
|
||||
if (monitoredChrIds.contains(chrId)) {
|
||||
monitoredChrIds.remove(chrId);
|
||||
return false;
|
||||
} else {
|
||||
monitoredChrIds.add(chrId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static Collection<Integer> getMonitoredChrIds() {
|
||||
return monitoredChrIds;
|
||||
}
|
||||
|
||||
public static void logPacketIfMonitored(Client c, short packetId, byte[] packetContent) {
|
||||
Character chr = c.getPlayer();
|
||||
if (chr == null) {
|
||||
return;
|
||||
}
|
||||
if (!monitored.contains(chr.getId())) {
|
||||
if (!monitoredChrIds.contains(chr.getId())) {
|
||||
return;
|
||||
}
|
||||
RecvOpcode op = getOpcodeFromValue(packetId);
|
||||
|
||||
Reference in New Issue
Block a user