mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-23 15:20:52 +01:00
Add packet names to logger.
This commit is contained in:
parent
14a1c56877
commit
5fc6bc4002
@ -85,10 +85,13 @@ public class PacketManager {
|
|||||||
public static boolean MULTI_THREADED_PACKET_HANDLING = false;
|
public static boolean MULTI_THREADED_PACKET_HANDLING = false;
|
||||||
private final THashMap<Integer, Class<? extends MessageHandler>> incoming;
|
private final THashMap<Integer, Class<? extends MessageHandler>> incoming;
|
||||||
private final THashMap<Integer, List<ICallable>> callables;
|
private final THashMap<Integer, List<ICallable>> callables;
|
||||||
|
private final PacketNames names;
|
||||||
|
|
||||||
public PacketManager() throws Exception {
|
public PacketManager() throws Exception {
|
||||||
this.incoming = new THashMap<>();
|
this.incoming = new THashMap<>();
|
||||||
this.callables = new THashMap<>();
|
this.callables = new THashMap<>();
|
||||||
|
this.names = new PacketNames();
|
||||||
|
this.names.initialize();
|
||||||
|
|
||||||
this.registerHandshake();
|
this.registerHandshake();
|
||||||
this.registerCatalog();
|
this.registerCatalog();
|
||||||
@ -115,6 +118,10 @@ public class PacketManager {
|
|||||||
this.registerGameCenter();
|
this.registerGameCenter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PacketNames getNames() {
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public static void onConfigurationUpdated(EmulatorConfigUpdatedEvent event) {
|
public static void onConfigurationUpdated(EmulatorConfigUpdatedEvent event) {
|
||||||
logList.clear();
|
logList.clear();
|
||||||
|
58
src/main/java/com/eu/habbo/messages/PacketNames.java
Normal file
58
src/main/java/com/eu/habbo/messages/PacketNames.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package com.eu.habbo.messages;
|
||||||
|
|
||||||
|
import com.eu.habbo.messages.incoming.Incoming;
|
||||||
|
import com.eu.habbo.messages.outgoing.Outgoing;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class PacketNames {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(PacketNames.class);
|
||||||
|
|
||||||
|
private final HashMap<Integer, String> incoming;
|
||||||
|
private final HashMap<Integer, String> outgoing;
|
||||||
|
|
||||||
|
public PacketNames() {
|
||||||
|
this.incoming = new HashMap<>();
|
||||||
|
this.outgoing = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize() {
|
||||||
|
PacketNames.getNames(Incoming.class, this.incoming);
|
||||||
|
PacketNames.getNames(Outgoing.class, this.outgoing);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIncomingName(int key) {
|
||||||
|
return this.incoming.getOrDefault(key, "Unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOutgoingName(int key) {
|
||||||
|
return this.outgoing.getOrDefault(key, "Unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void getNames(Class<?> clazz, HashMap<Integer, String> target) {
|
||||||
|
for (Field field : clazz.getFields()) {
|
||||||
|
int modifiers = field.getModifiers();
|
||||||
|
if (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers) && field.getType() == int.class) {
|
||||||
|
try {
|
||||||
|
int packetId = field.getInt(null);
|
||||||
|
if (packetId > 0) {
|
||||||
|
if (target.containsKey(packetId)) {
|
||||||
|
LOGGER.warn("Duplicate packet id found {} for {}.", packetId, clazz.getSimpleName());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.put(packetId, field.getName());
|
||||||
|
}
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
LOGGER.error("Failed to read field integer.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package com.eu.habbo.networking.gameserver.decoders;
|
package com.eu.habbo.networking.gameserver.decoders;
|
||||||
|
|
||||||
|
import com.eu.habbo.Emulator;
|
||||||
import com.eu.habbo.messages.ClientMessage;
|
import com.eu.habbo.messages.ClientMessage;
|
||||||
|
import com.eu.habbo.messages.PacketNames;
|
||||||
import com.eu.habbo.util.ANSI;
|
import com.eu.habbo.util.ANSI;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||||
@ -12,10 +14,18 @@ import java.util.List;
|
|||||||
public class GameClientMessageLogger extends MessageToMessageDecoder<ClientMessage> {
|
public class GameClientMessageLogger extends MessageToMessageDecoder<ClientMessage> {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(GameClientMessageLogger.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(GameClientMessageLogger.class);
|
||||||
|
private final PacketNames names;
|
||||||
|
|
||||||
|
public GameClientMessageLogger() {
|
||||||
|
this.names = Emulator.getGameServer().getPacketManager().getNames();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void decode(ChannelHandlerContext ctx, ClientMessage message, List<Object> out) {
|
protected void decode(ChannelHandlerContext ctx, ClientMessage message, List<Object> out) {
|
||||||
LOGGER.debug(String.format("[" + ANSI.GREEN + "CLIENT" + ANSI.DEFAULT + "][%-4d] => %s", message.getMessageId(), message.getMessageBody()));
|
LOGGER.debug(String.format("[" + ANSI.GREEN + "CLIENT" + ANSI.DEFAULT + "][%-4d][%-41s] => %s",
|
||||||
|
message.getMessageId(),
|
||||||
|
this.names.getIncomingName(message.getMessageId()),
|
||||||
|
message.getMessageBody()));
|
||||||
|
|
||||||
out.add(message);
|
out.add(message);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.eu.habbo.networking.gameserver.encoders;
|
package com.eu.habbo.networking.gameserver.encoders;
|
||||||
|
|
||||||
|
import com.eu.habbo.Emulator;
|
||||||
|
import com.eu.habbo.messages.PacketNames;
|
||||||
import com.eu.habbo.messages.ServerMessage;
|
import com.eu.habbo.messages.ServerMessage;
|
||||||
import com.eu.habbo.util.ANSI;
|
import com.eu.habbo.util.ANSI;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
@ -12,10 +14,18 @@ import java.util.List;
|
|||||||
public class GameServerMessageLogger extends MessageToMessageEncoder<ServerMessage> {
|
public class GameServerMessageLogger extends MessageToMessageEncoder<ServerMessage> {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(GameServerMessageLogger.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(GameServerMessageLogger.class);
|
||||||
|
private final PacketNames names;
|
||||||
|
|
||||||
|
public GameServerMessageLogger() {
|
||||||
|
this.names = Emulator.getGameServer().getPacketManager().getNames();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void encode(ChannelHandlerContext ctx, ServerMessage message, List<Object> out) {
|
protected void encode(ChannelHandlerContext ctx, ServerMessage message, List<Object> out) {
|
||||||
LOGGER.debug(String.format("[" + ANSI.BLUE + "SERVER" + ANSI.DEFAULT + "][%-4d] => %s", message.getHeader(), message.getBodyString()));
|
LOGGER.debug(String.format("[" + ANSI.BLUE + "SERVER" + ANSI.DEFAULT + "][%-4d][%-41s] => %s",
|
||||||
|
message.getHeader(),
|
||||||
|
this.names.getOutgoingName(message.getHeader()),
|
||||||
|
message.getBodyString()));
|
||||||
|
|
||||||
out.add(message.retain());
|
out.add(message.retain());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user