3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Add more debugging options

Dieser Commit ist enthalten in:
Nassim Jahnke 2021-11-21 11:12:13 +01:00
Ursprung 3a529d00ce
Commit d159047dc0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
10 geänderte Dateien mit 226 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -64,7 +64,7 @@ public interface ViaAPI<T> {
* @return API version incremented with meaningful API changes * @return API version incremented with meaningful API changes
*/ */
default int apiVersion() { default int apiVersion() {
return 9; return 10;
} }
/** /**

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api;
import com.viaversion.viaversion.api.command.ViaVersionCommand; import com.viaversion.viaversion.api.command.ViaVersionCommand;
import com.viaversion.viaversion.api.connection.ConnectionManager; import com.viaversion.viaversion.api.connection.ConnectionManager;
import com.viaversion.viaversion.api.debug.DebugHandler;
import com.viaversion.viaversion.api.platform.ViaInjector; import com.viaversion.viaversion.api.platform.ViaInjector;
import com.viaversion.viaversion.api.platform.ViaPlatform; import com.viaversion.viaversion.api.platform.ViaPlatform;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader; import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
@ -88,14 +89,27 @@ public interface ViaManager {
* *
* @return true if enabled * @return true if enabled
*/ */
boolean isDebug(); @Deprecated
default boolean isDebug() {
return debugHandler().enabled();
}
/** /**
* Sets the debug mode. If enabled, packets and other otherwise suppressed warnings will be logged. * Sets the debug mode. If enabled, packets and other otherwise suppressed warnings will be logged.
* *
* @param debug whether debug should be enabled * @param debug whether debug should be enabled
*/ */
void setDebug(boolean debug); @Deprecated
default void setDebug(boolean debug) {
debugHandler().setEnabled(debug);
}
/**
* Returns the debug handler.
*
* @return debug handler
*/
DebugHandler debugHandler();
/** /**
* Returns a mutable set of self-added subplatform version strings. * Returns a mutable set of self-added subplatform version strings.

Datei anzeigen

@ -0,0 +1,85 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.debug;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
public interface DebugHandler {
/**
* Returns whether debug mode is enabled.
*
* @return whether debug mode is enabled
*/
boolean enabled();
/**
* Sets debug mode.
*
* @param enabled whether debug should be enabled
*/
void setEnabled(boolean enabled);
/**
* Adds a packet type name to the list of packet types to log.
*
* @param packetTypeName packet type name
*/
void addPacketTypeNameToLog(String packetTypeName);
/**
* Removes a packet type name from the list of packet types to log.
*
* @param packetTypeName packet type name
*/
boolean removePacketTypeNameToLog(String packetTypeName);
/**
* Resets packet type filters.
*/
void clearPacketTypesToLog();
/**
* Returns whether packets should be logged after being transformed.
* Set to true by default.
*
* @return whether packets should be logged after being transformed
*/
boolean logPostPacketTransform();
/**
* Sets whether packets should be logged after being transformed.
*
* @param logPostPacketTransform whether packets should be logged after being transformed
*/
void setLogPostPacketTransform(boolean logPostPacketTransform);
/**
* Returns whether the given packet should be logged.
* If no specific packet type has been added, all packet types will be logged.
*
* @param wrapper packet wrapper
* @return whether the packet should be logged
*/
boolean shouldLog(PacketWrapper wrapper);
}

Datei anzeigen

@ -20,6 +20,7 @@ package com.viaversion.viaversion;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.ViaManager; import com.viaversion.viaversion.api.ViaManager;
import com.viaversion.viaversion.api.connection.ConnectionManager; import com.viaversion.viaversion.api.connection.ConnectionManager;
import com.viaversion.viaversion.api.debug.DebugHandler;
import com.viaversion.viaversion.api.platform.PlatformTask; import com.viaversion.viaversion.api.platform.PlatformTask;
import com.viaversion.viaversion.api.platform.UnsupportedSoftware; import com.viaversion.viaversion.api.platform.UnsupportedSoftware;
import com.viaversion.viaversion.api.platform.ViaInjector; import com.viaversion.viaversion.api.platform.ViaInjector;
@ -31,6 +32,7 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion; import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion;
import com.viaversion.viaversion.commands.ViaCommandHandler; import com.viaversion.viaversion.commands.ViaCommandHandler;
import com.viaversion.viaversion.connection.ConnectionManagerImpl; import com.viaversion.viaversion.connection.ConnectionManagerImpl;
import com.viaversion.viaversion.debug.DebugHandlerImpl;
import com.viaversion.viaversion.protocol.ProtocolManagerImpl; import com.viaversion.viaversion.protocol.ProtocolManagerImpl;
import com.viaversion.viaversion.protocol.ServerProtocolVersionRange; import com.viaversion.viaversion.protocol.ServerProtocolVersionRange;
import com.viaversion.viaversion.protocol.ServerProtocolVersionSingleton; import com.viaversion.viaversion.protocol.ServerProtocolVersionSingleton;
@ -50,6 +52,7 @@ import java.util.regex.Pattern;
public class ViaManagerImpl implements ViaManager { public class ViaManagerImpl implements ViaManager {
private final ProtocolManagerImpl protocolManager = new ProtocolManagerImpl(); private final ProtocolManagerImpl protocolManager = new ProtocolManagerImpl();
private final ConnectionManager connectionManager = new ConnectionManagerImpl(); private final ConnectionManager connectionManager = new ConnectionManagerImpl();
private final DebugHandler debugHandler = new DebugHandlerImpl();
private final ViaProviders providers = new ViaProviders(); private final ViaProviders providers = new ViaProviders();
private final ViaPlatform<?> platform; private final ViaPlatform<?> platform;
private final ViaInjector injector; private final ViaInjector injector;
@ -279,13 +282,8 @@ public class ViaManagerImpl implements ViaManager {
} }
@Override @Override
public boolean isDebug() { public DebugHandler debugHandler() {
return debug; return debugHandler;
}
@Override
public void setDebug(boolean debug) {
this.debug = debug;
} }
@Override @Override

Datei anzeigen

@ -20,6 +20,12 @@ package com.viaversion.viaversion.commands.defaultsubs;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.api.command.ViaSubCommand; import com.viaversion.viaversion.api.command.ViaSubCommand;
import com.viaversion.viaversion.api.debug.DebugHandler;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
public class DebugSubCmd extends ViaSubCommand { public class DebugSubCmd extends ViaSubCommand {
@Override @Override
@ -34,8 +40,41 @@ public class DebugSubCmd extends ViaSubCommand {
@Override @Override
public boolean execute(ViaCommandSender sender, String[] args) { public boolean execute(ViaCommandSender sender, String[] args) {
Via.getManager().setDebug(!Via.getManager().isDebug()); final DebugHandler debug = Via.getManager().debugHandler();
sendMessage(sender, "&6Debug mode is now %s", (Via.getManager().isDebug() ? "&aenabled" : "&cdisabled")); if (args.length == 0) {
Via.getManager().debugHandler().setEnabled(!Via.getManager().debugHandler().enabled());
sendMessage(sender, "&6Debug mode is now %s", (Via.getManager().debugHandler().enabled() ? "&aenabled" : "&cdisabled"));
return true;
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("clear")) {
debug.clearPacketTypesToLog();
sendMessage(sender, "&6Cleared packet types to log");
return true;
} else if (args[0].equalsIgnoreCase("logposttransform")) {
debug.setLogPostPacketTransform(!debug.logPostPacketTransform());
sendMessage(sender, "&6Post transform packet logging is now %s", (debug.logPostPacketTransform() ? "&aenabled" : "&cdisabled"));
return true;
}
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("add")) {
debug.addPacketTypeNameToLog(args[1].toUpperCase(Locale.ROOT));
sendMessage(sender, "&6Added packet type %s to debug logging", args[1]);
return true;
} else if (args[0].equalsIgnoreCase("remove")) {
debug.removePacketTypeNameToLog(args[1].toUpperCase(Locale.ROOT));
sendMessage(sender, "&6Removed packet type %s from debug logging", args[1]);
return true; return true;
} }
} }
return false;
}
@Override
public List<String> onTabComplete(final ViaCommandSender sender, final String[] args) {
if (args.length == 1) {
//TODO match current input
return Arrays.asList("clear", "logposttransform", "add", "remove");
}
return Collections.emptyList();
}
}

Datei anzeigen

@ -0,0 +1,71 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.debug;
import com.viaversion.viaversion.api.debug.DebugHandler;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import java.util.HashSet;
import java.util.Set;
public final class DebugHandlerImpl implements DebugHandler {
private final Set<String> packetTypesToLog = new HashSet<>();
private boolean logPostPacketTransform = true;
private boolean enabled;
@Override
public boolean enabled() {
return enabled;
}
@Override
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
@Override
public void addPacketTypeNameToLog(final String packetTypeName) {
packetTypesToLog.add(packetTypeName);
}
@Override
public boolean removePacketTypeNameToLog(final String packetTypeName) {
return packetTypesToLog.remove(packetTypeName);
}
@Override
public void clearPacketTypesToLog() {
packetTypesToLog.clear();
}
@Override
public boolean logPostPacketTransform() {
return logPostPacketTransform;
}
@Override
public void setLogPostPacketTransform(final boolean logPostPacketTransform) {
this.logPostPacketTransform = logPostPacketTransform;
}
@Override
public boolean shouldLog(final PacketWrapper wrapper) {
return packetTypesToLog.isEmpty() || (wrapper.getPacketType() != null && packetTypesToLog.contains(wrapper.getPacketType().getName()));
}
}

Datei anzeigen

@ -20,6 +20,7 @@ package com.viaversion.viaversion.protocol;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.debug.DebugHandler;
import com.viaversion.viaversion.api.platform.ViaPlatform; import com.viaversion.viaversion.api.platform.ViaPlatform;
import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol; import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol;
import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.protocol.Protocol;
@ -117,7 +118,8 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
packetWrapper.apply(direction, state, 0, protocolList, direction == Direction.CLIENTBOUND); packetWrapper.apply(direction, state, 0, protocolList, direction == Direction.CLIENTBOUND);
super.transform(direction, state, packetWrapper); super.transform(direction, state, packetWrapper);
if (Via.getManager().isDebug()) { DebugHandler debugHandler = Via.getManager().debugHandler();
if (debugHandler.enabled() && debugHandler.logPostPacketTransform() && debugHandler.shouldLog(packetWrapper)) {
logPacket(direction, state, packetWrapper, originalID); logPacket(direction, state, packetWrapper, originalID);
} }
} }

Datei anzeigen

@ -491,7 +491,7 @@ public class PacketWrapperImpl implements PacketWrapper {
"packetValues=" + packetValues + "packetValues=" + packetValues +
", readableObjects=" + readableObjects + ", readableObjects=" + readableObjects +
", id=" + id + ", id=" + id +
", packetType" + packetType + ", packetType=" + packetType +
'}'; '}';
} }
} }

Datei anzeigen

@ -67,7 +67,7 @@ public class Protocol1_14To1_13_2 extends AbstractProtocol<ClientboundPackets1_1
new StatisticsRewriter(this).register(ClientboundPackets1_13.STATISTICS); new StatisticsRewriter(this).register(ClientboundPackets1_13.STATISTICS);
ComponentRewriter componentRewriter = new ComponentRewriter1_14(this); ComponentRewriter componentRewriter = new ComponentRewriter1_14(this);
componentRewriter.registerChatMessage(ClientboundPackets1_13.CHAT_MESSAGE); componentRewriter.registerComponentPacket(ClientboundPackets1_13.CHAT_MESSAGE);
CommandRewriter1_14 commandRewriter = new CommandRewriter1_14(this); CommandRewriter1_14 commandRewriter = new CommandRewriter1_14(this);
commandRewriter.registerDeclareCommands(ClientboundPackets1_13.DECLARE_COMMANDS); commandRewriter.registerDeclareCommands(ClientboundPackets1_13.DECLARE_COMMANDS);

Datei anzeigen

@ -61,6 +61,7 @@ public class ComponentRewriter {
}); });
} }
@Deprecated/*(forRemoval = true)**/
public void registerChatMessage(ClientboundPacketType packetType) { public void registerChatMessage(ClientboundPacketType packetType) {
registerComponentPacket(packetType); registerComponentPacket(packetType);
} }