mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2025-01-29 03:31:31 +01:00
Make packet logging more robust
This commit is contained in:
parent
b30628f6db
commit
73ce01bbde
@ -73,6 +73,7 @@ public class PacketLogging implements CommandExecutor, PacketListener {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
PacketType type = null;
|
||||
|
||||
try {
|
||||
if (args.length > 2) {
|
||||
Protocol protocol;
|
||||
|
||||
@ -99,8 +100,7 @@ public class PacketLogging implements CommandExecutor, PacketListener {
|
||||
} catch (NumberFormatException ex) {
|
||||
String name = args[2];
|
||||
outer: for (PacketType packet : PacketType.values()) {
|
||||
if (packet.getProtocol() == protocol &&
|
||||
packet.getSender() == pSender) {
|
||||
if (packet.getProtocol() == protocol && packet.getSender() == pSender) {
|
||||
if (packet.name().equalsIgnoreCase(name)) {
|
||||
type = packet;
|
||||
break outer;
|
||||
@ -115,7 +115,11 @@ public class PacketLogging implements CommandExecutor, PacketListener {
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException ex) {
|
||||
sender.sendMessage(ChatColor.RED + "Unknown packet: " + PacketType.format(protocol, pSender, args[2]));
|
||||
type = null;
|
||||
}
|
||||
|
||||
if (type == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Unknown packet: " + args[2]);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -148,6 +152,10 @@ public class PacketLogging implements CommandExecutor, PacketListener {
|
||||
|
||||
sender.sendMessage(ChatColor.RED + "Invalid syntax: /packetlog <protocol> <sender> <packet> [location]");
|
||||
return true;
|
||||
} catch (Throwable ex) {
|
||||
sender.sendMessage(ChatColor.RED + "Failed to parse command: " + ex.toString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void startLogging() {
|
||||
@ -199,15 +207,9 @@ public class PacketLogging implements CommandExecutor, PacketListener {
|
||||
}
|
||||
|
||||
private void log(PacketEvent event) {
|
||||
String hexDump;
|
||||
|
||||
try {
|
||||
WirePacket packet = WirePacket.fromPacket(event.getPacket());
|
||||
hexDump = hexDump(packet.getBytes());
|
||||
} catch (Throwable ex) {
|
||||
fileLogger.log(Level.WARNING, "Failed to dump packet: " + ex.toString());
|
||||
return;
|
||||
}
|
||||
String hexDump = hexDump(packet.getBytes());
|
||||
|
||||
if (location == LogLocation.FILE) {
|
||||
fileLogger.log(Level.INFO, event.getPacketType() + ":");
|
||||
@ -218,6 +220,14 @@ public class PacketLogging implements CommandExecutor, PacketListener {
|
||||
System.out.println(hexDump);
|
||||
System.out.println();
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
plugin.getLogger().log(Level.WARNING, "Failed to log packet " + event.getPacketType() + ":", ex);
|
||||
plugin.getLogger().log(Level.WARNING, "Clearing packet logger...");
|
||||
|
||||
sendingTypes.clear();
|
||||
receivingTypes.clear();
|
||||
startLogging();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user