Archiviert
13
0

Make it possible to intercept and expand upon the unknown origin error.

We add another configuration option that enables stack traces of 
warnings.
Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-07-19 02:26:07 +02:00
Ursprung 92781be618
Commit 62094492a9
5 geänderte Dateien mit 76 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -48,6 +48,7 @@ class ProtocolConfig {
private static final String BACKGROUND_COMPILER_ENABLED = "background compiler";
private static final String DEBUG_MODE_ENABLED = "debug";
private static final String DETAILED_ERROR = "detailed error";
private static final String INJECTION_METHOD = "injection method";
private static final String SCRIPT_ENGINE_NAME = "script engine";
@ -193,6 +194,22 @@ class ProtocolConfig {
return new File(plugin.getDataFolder(), "config.yml");
}
/**
* Determine if detailed error reporting is enabled. Default FALSE.
* @return TRUE if it is enabled, FALSE otherwise.
*/
public boolean isDetailedErrorReporting() {
return global.getBoolean(DETAILED_ERROR, false);
}
/**
* Set whether or not detailed error reporting is enabled.
* @param value - TRUE if it is enabled, FALSE otherwise.
*/
public void setDetailedErrorReporting(boolean value) {
global.set(DETAILED_ERROR, value);
}
/**
* Retrieve whether or not ProtocolLib should determine if a new version has been released.
* @return TRUE if it should do this automatically, FALSE otherwise.

Datei anzeigen

@ -161,6 +161,11 @@ public class ProtocolLibrary extends JavaPlugin {
if (config.isDebug()) {
logger.warning("Debug mode is enabled!");
}
// And the state of the error reporter
if (config.isDetailedErrorReporting()) {
detailedReporter.setDetailedReporting(true);
logger.warning("Detailed error reporting enabled!");
}
try {
// Check for other versions

Datei anzeigen

@ -77,6 +77,9 @@ public class DetailedErrorReporter implements ErrorReporter {
// Whether or not Apache Commons is not present
protected boolean apacheCommonsMissing;
// Whether or not detailed errror reporting is enabled
protected boolean detailedReporting;
// Map of global objects
protected Map<String, Object> globalParameters = new HashMap<String, Object>();
@ -125,6 +128,22 @@ public class DetailedErrorReporter implements ErrorReporter {
return Logger.getLogger("Minecraft");
}
}
/**
* Determine if we're using detailed error reporting.
* @return TRUE if we are, FALSE otherwise.
*/
public boolean isDetailedReporting() {
return detailedReporting;
}
/**
* Set whether or not to use detailed error reporting.
* @param detailedReporting - TRUE to enable it, FALSE otherwise.
*/
public void setDetailedReporting(boolean detailedReporting) {
this.detailedReporting = detailedReporting;
}
@Override
public void reportMinimal(Plugin sender, String methodName, Throwable error, Object... parameters) {
@ -206,8 +225,13 @@ public class DetailedErrorReporter implements ErrorReporter {
// Print the main warning
if (report.getException() != null) {
logger.log(Level.WARNING, message, report.getException());
} else {
} else {
logger.log(Level.WARNING, message);
// Remember the call stack
if (detailedReporting) {
printCallStack(Level.WARNING, logger);
}
}
// Parameters?
@ -264,6 +288,9 @@ public class DetailedErrorReporter implements ErrorReporter {
if (report.getException() != null) {
report.getException().printStackTrace(writer);
} else if (detailedReporting) {
printCallStack(writer);
}
// Data dump!
@ -309,6 +336,27 @@ public class DetailedErrorReporter implements ErrorReporter {
logger.severe(addPrefix(text.toString(), prefix));
}
/**
* Print the call stack to the given logger.
* @param logger - the logger.
*/
private void printCallStack(Level level, Logger logger) {
StringWriter text = new StringWriter();
printCallStack(new PrintWriter(text));
// Print the exception
logger.log(level, text.toString());
}
/**
* Print the current call stack.
* @param writer - the writer.
*/
private void printCallStack(PrintWriter writer) {
Exception current = new Exception("Not an error! This is the call stack.");
current.printStackTrace(writer);
}
private String printParameters(Object... parameters) {
StringWriter writer = new StringWriter();

Datei anzeigen

@ -56,6 +56,7 @@ import com.comphenix.protocol.utility.MinecraftReflection;
*/
class ProxyPacketInjector implements PacketInjector {
public static final ReportType REPORT_CANNOT_FIND_READ_PACKET_METHOD = new ReportType("Cannot find read packet method for ID %s.");
public static final ReportType REPORT_UNKNOWN_ORIGIN_FOR_PACKET = new ReportType("Unknown origin %s for packet %s.");
/**
* Represents a way to update the packet ID to class lookup table.
@ -339,7 +340,7 @@ class ProxyPacketInjector implements PacketInjector {
} else {
// Hack #2 - Caused by our server socket injector
if (packet.getID() != Packets.Client.GET_INFO)
System.out.println("[ProtocolLib] Unknown origin " + input + " for packet " + packet.getID());
reporter.reportWarning(this, Report.newBuilder(REPORT_UNKNOWN_ORIGIN_FOR_PACKET).messageParam(input, packet.getID()));
return null;
}

Datei anzeigen

@ -21,6 +21,9 @@ global:
# Whether or not to enable the filter command
debug: false
# Whether or not to print a stack trace for every warning
detailed error: false
# The engine used by the filter command
script engine: JavaScript