3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 00:00:28 +01:00

Add debug mode so we can analyse packets

Dieser Commit ist enthalten in:
Myles 2016-03-04 23:10:07 +00:00
Ursprung 24fa8aec35
Commit ac2178a247
5 geänderte Dateien mit 47 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit;
public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
private final Map<UUID, ConnectionInfo> portedPlayers = new ConcurrentHashMap<UUID, ConnectionInfo>(); private final Map<UUID, ConnectionInfo> portedPlayers = new ConcurrentHashMap<UUID, ConnectionInfo>();
private boolean debug = false;
@Override @Override
public void onEnable() { public void onEnable() {
@ -58,7 +59,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
Bukkit.getPluginManager().registerEvents(new ArmorListener(this), this); Bukkit.getPluginManager().registerEvents(new ArmorListener(this), this);
getCommand("viaversion").setExecutor(new ViaVersionCommand()); getCommand("viaversion").setExecutor(new ViaVersionCommand(this));
} }
public void injectPacketHandler() throws Exception { public void injectPacketHandler() throws Exception {
@ -107,6 +108,15 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
ci.sendRawPacket(packet); ci.sendRawPacket(packet);
} }
@Override
public boolean isDebug() {
return this.debug;
}
public void setDebug(boolean value) {
this.debug = value;
}
public void addPortedClient(ConnectionInfo info) { public void addPortedClient(ConnectionInfo info) {
portedPlayers.put(info.getUUID(), info); portedPlayers.put(info.getUUID(), info);
} }

Datei anzeigen

@ -24,4 +24,10 @@ public interface ViaVersionAPI {
* @throws IllegalArgumentException If not on 1.9 throws IllegalArg * @throws IllegalArgumentException If not on 1.9 throws IllegalArg
*/ */
void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException; void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException;
/**
* Obtain if global debug is enabled
* @return true if debug is enabled
*/
boolean isDebug();
} }

Datei anzeigen

@ -5,6 +5,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.ViaVersion; import us.myles.ViaVersion.api.ViaVersion;
import java.util.ArrayList; import java.util.ArrayList;
@ -14,6 +15,11 @@ import java.util.List;
* Created by fillefilip8 on 2016-03-03. * Created by fillefilip8 on 2016-03-03.
*/ */
public class ViaVersionCommand implements CommandExecutor { public class ViaVersionCommand implements CommandExecutor {
private final ViaVersionPlugin plugin;
public ViaVersionCommand(ViaVersionPlugin plugin) {
this.plugin = plugin;
}
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
@ -37,12 +43,17 @@ public class ViaVersionCommand implements CommandExecutor {
sender.sendMessage(color("&8[&61.9&8]: &b" + portedPlayers.toString())); sender.sendMessage(color("&8[&61.9&8]: &b" + portedPlayers.toString()));
sender.sendMessage(color("&8[&61.8&8]: &b" + normalPlayers.toString())); sender.sendMessage(color("&8[&61.8&8]: &b" + normalPlayers.toString()));
} }
if (args[0].equalsIgnoreCase("debug")) {
plugin.setDebug(!plugin.isDebug());
sender.sendMessage(color("&6Debug mode is now " + (plugin.isDebug() ? "&aenabled" : "&cdisabled")));
}
} }
} }
return false; return false;
} }
public String color(String string){
public String color(String string) {
return string.replace("&", "§"); return string.replace("&", "§");
} }
} }

Datei anzeigen

@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack;
import us.myles.ViaVersion.CancelException; import us.myles.ViaVersion.CancelException;
import us.myles.ViaVersion.ConnectionInfo; import us.myles.ViaVersion.ConnectionInfo;
import us.myles.ViaVersion.ViaVersionPlugin; import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.packets.PacketType; import us.myles.ViaVersion.packets.PacketType;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.slot.ItemSlotRewriter; import us.myles.ViaVersion.slot.ItemSlotRewriter;
@ -35,9 +36,11 @@ public class IncomingTransformer {
if (packet.getPacketID() != -1) { if (packet.getPacketID() != -1) {
packetID = packet.getPacketID(); packetID = packet.getPacketID();
} }
// if (packet != PacketType.PLAY_PLAYER_POSITION_LOOK_REQUEST && packet != PacketType.PLAY_KEEP_ALIVE_REQUEST && packet != PacketType.PLAY_PLAYER_POSITION_REQUEST && packet != PacketType.PLAY_PLAYER_LOOK_REQUEST) { if (ViaVersion.getInstance().isDebug()) {
// System.out.println("Packet Type: " + packet + " New ID: " + packetID + " Original: " + original); if (packet != PacketType.PLAY_PLAYER_POSITION_LOOK_REQUEST && packet != PacketType.PLAY_KEEP_ALIVE_REQUEST && packet != PacketType.PLAY_PLAYER_POSITION_REQUEST && packet != PacketType.PLAY_PLAYER_LOOK_REQUEST) {
// } System.out.println("Direction " + packet.getDirection().name() + " Packet Type: " + packet + " New ID: " + packetID + " Original: " + original + " Size: " + input.readableBytes());
}
}
if (packet == PacketType.PLAY_TP_CONFIRM || packet == PacketType.PLAY_VEHICLE_MOVE_REQUEST) { //TODO handle client-sided horse riding if (packet == PacketType.PLAY_TP_CONFIRM || packet == PacketType.PLAY_VEHICLE_MOVE_REQUEST) { //TODO handle client-sided horse riding
throw new CancelException(); throw new CancelException();
} }
@ -175,13 +178,13 @@ public class IncomingTransformer {
} }
return; return;
} }
if(packet == PacketType.PLAY_PLUGIN_MESSAGE_REQUEST) { if (packet == PacketType.PLAY_PLUGIN_MESSAGE_REQUEST) {
String name = PacketUtil.readString(input); String name = PacketUtil.readString(input);
PacketUtil.writeString(name, output); PacketUtil.writeString(name, output);
byte[] b = new byte[input.readableBytes()]; byte[] b = new byte[input.readableBytes()];
input.readBytes(b); input.readBytes(b);
// patch books // patch books
if(name.equals("MC|BSign")){ if (name.equals("MC|BSign")) {
ByteBuf in = Unpooled.wrappedBuffer(b); ByteBuf in = Unpooled.wrappedBuffer(b);
try { try {
ItemSlotRewriter.ItemStack stack = ItemSlotRewriter.readItemStack(in); ItemSlotRewriter.ItemStack stack = ItemSlotRewriter.readItemStack(in);

Datei anzeigen

@ -44,14 +44,17 @@ public class OutgoingTransformer {
} }
PacketType packet = PacketType.getOutgoingPacket(info.getState(), packetID); PacketType packet = PacketType.getOutgoingPacket(info.getState(), packetID);
int original = packetID;
if (packet.getPacketID() != -1) {
packetID = packet.getNewPacketID();
}
if (packet == null) { if (packet == null) {
throw new RuntimeException("Outgoing Packet not found? " + packetID + " State: " + info.getState() + " Version: " + info.getProtocol()); throw new RuntimeException("Outgoing Packet not found? " + packetID + " State: " + info.getState() + " Version: " + info.getProtocol());
} }
// if (packet != PacketType.PLAY_CHUNK_DATA && packet != PacketType.PLAY_KEEP_ALIVE && packet != PacketType.PLAY_TIME_UPDATE && (!packet.name().toLowerCase().contains("move") && !packet.name().toLowerCase().contains("look"))) if (ViaVersion.getInstance().isDebug()) {
// System.out.println("Packet Type: " + packet + " Original ID: " + packetID + " State:" + info.getState()); if (packet != PacketType.PLAY_CHUNK_DATA && packet != PacketType.PLAY_KEEP_ALIVE && packet != PacketType.PLAY_TIME_UPDATE && (!packet.name().toLowerCase().contains("move") && !packet.name().toLowerCase().contains("look"))) {
if (packet.getPacketID() != -1) { System.out.println("Direction " + packet.getDirection().name() + " Packet Type: " + packet + " New ID: " + packetID + " Original: " + original + " Size: " + input.readableBytes());
packetID = packet.getNewPacketID(); }
} }
// By default no transform // By default no transform
@ -254,9 +257,9 @@ public class OutgoingTransformer {
} }
if (packet == PacketType.STATUS_RESPONSE) { if (packet == PacketType.STATUS_RESPONSE) {
String original = PacketUtil.readString(input); String originalStatus = PacketUtil.readString(input);
try { try {
JSONObject json = (JSONObject) new JSONParser().parse(original); JSONObject json = (JSONObject) new JSONParser().parse(originalStatus);
JSONObject version = (JSONObject) json.get("version"); JSONObject version = (JSONObject) json.get("version");
version.put("protocol", info.getProtocol()); version.put("protocol", info.getProtocol());
PacketUtil.writeString(json.toJSONString(), output); PacketUtil.writeString(json.toJSONString(), output);