Merge branch 'master' of git+ssh://git@github.com/dmulloy2/ProtocolLib
Dieser Commit ist enthalten in:
Commit
a6810ea874
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.comphenix.protocol;
|
package com.comphenix.protocol;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
@ -29,6 +30,7 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.apache.commons.io.HexDump;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
@ -41,9 +43,7 @@ import com.comphenix.protocol.events.ListeningWhitelist;
|
|||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
import com.comphenix.protocol.events.PacketListener;
|
import com.comphenix.protocol.events.PacketListener;
|
||||||
import com.comphenix.protocol.injector.netty.WirePacket;
|
import com.comphenix.protocol.injector.netty.WirePacket;
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.buffer.ByteBufUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs packets to a given stream
|
* Logs packets to a given stream
|
||||||
@ -73,6 +73,7 @@ public class PacketLogging implements CommandExecutor, PacketListener {
|
|||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
PacketType type = null;
|
PacketType type = null;
|
||||||
|
|
||||||
|
try {
|
||||||
if (args.length > 2) {
|
if (args.length > 2) {
|
||||||
Protocol protocol;
|
Protocol protocol;
|
||||||
|
|
||||||
@ -97,10 +98,28 @@ public class PacketLogging implements CommandExecutor, PacketListener {
|
|||||||
int id = Integer.parseInt(args[2]);
|
int id = Integer.parseInt(args[2]);
|
||||||
type = PacketType.findCurrent(protocol, pSender, id);
|
type = PacketType.findCurrent(protocol, pSender, id);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
type = PacketType.findCurrent(protocol, pSender, args[2]);
|
String name = args[2];
|
||||||
|
outer: for (PacketType packet : PacketType.values()) {
|
||||||
|
if (packet.getProtocol() == protocol && packet.getSender() == pSender) {
|
||||||
|
if (packet.name().equalsIgnoreCase(name)) {
|
||||||
|
type = packet;
|
||||||
|
break outer;
|
||||||
|
}
|
||||||
|
for (String className : packet.getClassNames()) {
|
||||||
|
if (className.equalsIgnoreCase(name)) {
|
||||||
|
type = packet;
|
||||||
|
break outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ex) {
|
} 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +152,10 @@ public class PacketLogging implements CommandExecutor, PacketListener {
|
|||||||
|
|
||||||
sender.sendMessage(ChatColor.RED + "Invalid syntax: /packetlog <protocol> <sender> <packet> [location]");
|
sender.sendMessage(ChatColor.RED + "Invalid syntax: /packetlog <protocol> <sender> <packet> [location]");
|
||||||
return true;
|
return true;
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Failed to parse command: " + ex.toString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startLogging() {
|
private void startLogging() {
|
||||||
@ -176,9 +199,17 @@ public class PacketLogging implements CommandExecutor, PacketListener {
|
|||||||
log(event);
|
log(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String hexDump(byte[] bytes) throws IOException {
|
||||||
|
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
||||||
|
HexDump.dump(bytes, 0, output, 0);
|
||||||
|
return new String(output.toByteArray(), Charsets.UTF_8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void log(PacketEvent event) {
|
private void log(PacketEvent event) {
|
||||||
ByteBuf buffer = WirePacket.bufferFromPacket(event.getPacket());
|
try {
|
||||||
String hexDump = ByteBufUtil.hexDump(buffer);
|
WirePacket packet = WirePacket.fromPacket(event.getPacket());
|
||||||
|
String hexDump = hexDump(packet.getBytes());
|
||||||
|
|
||||||
if (location == LogLocation.FILE) {
|
if (location == LogLocation.FILE) {
|
||||||
fileLogger.log(Level.INFO, event.getPacketType() + ":");
|
fileLogger.log(Level.INFO, event.getPacketType() + ":");
|
||||||
@ -189,6 +220,14 @@ public class PacketLogging implements CommandExecutor, PacketListener {
|
|||||||
System.out.println(hexDump);
|
System.out.println(hexDump);
|
||||||
System.out.println();
|
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
|
@Override
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren