Print caught exceptions in debug mode.
Dieser Commit ist enthalten in:
Ursprung
32758061a9
Commit
58c027f162
@ -356,7 +356,6 @@ class ProtocolConfig {
|
|||||||
* Set whether or not the background compiler for structure modifiers is enabled or not.
|
* Set whether or not the background compiler for structure modifiers is enabled or not.
|
||||||
* <p>
|
* <p>
|
||||||
* This setting will take effect next time ProtocolLib is started.
|
* This setting will take effect next time ProtocolLib is started.
|
||||||
*
|
|
||||||
* @param enabled - TRUE if is enabled/running, FALSE otherwise.
|
* @param enabled - TRUE if is enabled/running, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
public void setBackgroundCompilerEnabled(boolean enabled) {
|
public void setBackgroundCompilerEnabled(boolean enabled) {
|
||||||
|
@ -126,14 +126,15 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
|
|
||||||
// Used to clean up server packets that have expired. But mostly required to simulate
|
// Used to clean up server packets that have expired. But mostly required to simulate
|
||||||
// recieving client packets.
|
// recieving client packets.
|
||||||
private int asyncPacketTask = -1;
|
private int packetTask = -1;
|
||||||
private int tickCounter = 0;
|
private int tickCounter = 0;
|
||||||
private static final int ASYNC_PACKET_DELAY = 1;
|
private static final int ASYNC_MANAGER_DELAY = 1;
|
||||||
|
|
||||||
// Used to unhook players after a delay
|
// Used to unhook players after a delay
|
||||||
private DelayedSingleTask unhookTask;
|
private DelayedSingleTask unhookTask;
|
||||||
|
|
||||||
// Settings/options
|
// Settings/options
|
||||||
|
private int configExpectedMod = -1;
|
||||||
private ProtocolConfig config;
|
private ProtocolConfig config;
|
||||||
|
|
||||||
// Updater
|
// Updater
|
||||||
@ -364,7 +365,7 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
|
|
||||||
// Worker that ensures that async packets are eventually sent
|
// Worker that ensures that async packets are eventually sent
|
||||||
// It also performs the update check.
|
// It also performs the update check.
|
||||||
createAsyncTask(server);
|
createPacketTask(server);
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
reporter.reportDetailed(this, Report.newBuilder(REPORT_PLUGIN_ENABLE_ERROR).error(e));
|
reporter.reportDetailed(this, Report.newBuilder(REPORT_PLUGIN_ENABLE_ERROR).error(e));
|
||||||
@ -483,34 +484,46 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
getServer().getPluginManager().disablePlugin(this);
|
getServer().getPluginManager().disablePlugin(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createAsyncTask(Server server) {
|
private void createPacketTask(Server server) {
|
||||||
try {
|
try {
|
||||||
if (asyncPacketTask >= 0)
|
if (packetTask >= 0)
|
||||||
throw new IllegalStateException("Async task has already been created");
|
throw new IllegalStateException("Packet task has already been created");
|
||||||
|
|
||||||
// Attempt to create task
|
// Attempt to create task
|
||||||
asyncPacketTask = server.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
|
packetTask = server.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
AsyncFilterManager manager = (AsyncFilterManager) protocolManager.getAsynchronousManager();
|
AsyncFilterManager manager = (AsyncFilterManager) protocolManager.getAsynchronousManager();
|
||||||
|
|
||||||
// We KNOW we're on the main thread at the moment
|
// We KNOW we're on the main thread at the moment
|
||||||
manager.sendProcessedPackets(tickCounter++, true);
|
manager.sendProcessedPackets(tickCounter++, true);
|
||||||
|
|
||||||
|
// House keeping
|
||||||
|
updateConfiguration();
|
||||||
|
|
||||||
// Check for updates too
|
// Check for updates too
|
||||||
if (!UPDATES_DISABLED) {
|
if (!UPDATES_DISABLED) {
|
||||||
checkUpdates();
|
checkUpdates();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, ASYNC_PACKET_DELAY, ASYNC_PACKET_DELAY);
|
}, ASYNC_MANAGER_DELAY, ASYNC_MANAGER_DELAY);
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
if (asyncPacketTask == -1) {
|
if (packetTask == -1) {
|
||||||
reporter.reportDetailed(this, Report.newBuilder(REPORT_CANNOT_CREATE_TIMEOUT_TASK).error(e));
|
reporter.reportDetailed(this, Report.newBuilder(REPORT_CANNOT_CREATE_TIMEOUT_TASK).error(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateConfiguration() {
|
||||||
|
if (config != null && config.getModificationCount() != configExpectedMod) {
|
||||||
|
configExpectedMod = config.getModificationCount();
|
||||||
|
|
||||||
|
// Update the debug flag
|
||||||
|
protocolManager.setDebug(config.isDebug());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void checkUpdates() {
|
private void checkUpdates() {
|
||||||
// Ignore milliseconds - it's pointless
|
// Ignore milliseconds - it's pointless
|
||||||
long currentTime = System.currentTimeMillis() / MILLI_PER_SECOND;
|
long currentTime = System.currentTimeMillis() / MILLI_PER_SECOND;
|
||||||
@ -551,9 +564,9 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
if (asyncPacketTask >= 0) {
|
if (packetTask >= 0) {
|
||||||
getServer().getScheduler().cancelTask(asyncPacketTask);
|
getServer().getScheduler().cancelTask(packetTask);
|
||||||
asyncPacketTask = -1;
|
packetTask = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// And redirect handler too
|
// And redirect handler too
|
||||||
|
@ -28,7 +28,6 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.error.ErrorReporter;
|
|
||||||
import com.comphenix.protocol.error.Report;
|
import com.comphenix.protocol.error.Report;
|
||||||
import com.comphenix.protocol.error.ReportType;
|
import com.comphenix.protocol.error.ReportType;
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
|
@ -60,6 +60,7 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
|
|||||||
|
|
||||||
// If we have been closed
|
// If we have been closed
|
||||||
private boolean closed;
|
private boolean closed;
|
||||||
|
private boolean debug;
|
||||||
|
|
||||||
// Queued registration
|
// Queued registration
|
||||||
private PluginManager queuedManager;
|
private PluginManager queuedManager;
|
||||||
@ -110,6 +111,8 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
|
|||||||
if (queuedManager != null && queuedPlugin != null) {
|
if (queuedManager != null && queuedPlugin != null) {
|
||||||
delegate.registerEvents(queuedManager, queuedPlugin);
|
delegate.registerEvents(queuedManager, queuedPlugin);
|
||||||
}
|
}
|
||||||
|
// And update the debug mode
|
||||||
|
delegate.setDebug(debug);
|
||||||
|
|
||||||
// Add any pending listeners
|
// Add any pending listeners
|
||||||
synchronized (queuedListeners) {
|
synchronized (queuedListeners) {
|
||||||
@ -428,6 +431,20 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
|
|||||||
return asyncManager;
|
return asyncManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDebug() {
|
||||||
|
return debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDebug(boolean debug) {
|
||||||
|
this.debug = debug;
|
||||||
|
|
||||||
|
if (delegate != null) {
|
||||||
|
delegate.setDebug(debug);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the asynchronous manager. This must be set.
|
* Update the asynchronous manager. This must be set.
|
||||||
* @param asyncManager - the asynchronous manager.
|
* @param asyncManager - the asynchronous manager.
|
||||||
|
@ -35,4 +35,16 @@ public interface InternalManager extends ProtocolManager {
|
|||||||
* Called when ProtocolLib is closing.
|
* Called when ProtocolLib is closing.
|
||||||
*/
|
*/
|
||||||
public void close();
|
public void close();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if debug mode is enabled.
|
||||||
|
* @return TRUE if it is, FALSE otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isDebug();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether or not debug mode is enabled.
|
||||||
|
* @param debug - TRUE if it is, FALSE otherwise.
|
||||||
|
*/
|
||||||
|
public void setDebug(boolean debug);
|
||||||
}
|
}
|
||||||
|
@ -199,6 +199,9 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
|||||||
// Login packets
|
// Login packets
|
||||||
private LoginPackets loginPackets;
|
private LoginPackets loginPackets;
|
||||||
|
|
||||||
|
// Debug mode
|
||||||
|
private boolean debug;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only create instances of this class if protocol lib is disabled.
|
* Only create instances of this class if protocol lib is disabled.
|
||||||
*/
|
*/
|
||||||
@ -301,6 +304,21 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
|||||||
return asyncFilterManager;
|
return asyncFilterManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDebug() {
|
||||||
|
return debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDebug(boolean debug) {
|
||||||
|
this.debug = debug;
|
||||||
|
|
||||||
|
// Inform components that can handle debug mode
|
||||||
|
if (nettyInjector != null) {
|
||||||
|
nettyInjector.setDebug(debug);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves how the server packets are read.
|
* Retrieves how the server packets are read.
|
||||||
* @return Injection method for reading server packets.
|
* @return Injection method for reading server packets.
|
||||||
|
@ -210,6 +210,13 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
|
|||||||
ENCODER_TYPE_MATCHER.set(encoder, TypeParameterMatcher.get(MinecraftReflection.getPacketClass()));
|
ENCODER_TYPE_MATCHER.set(encoder, TypeParameterMatcher.get(MinecraftReflection.getPacketClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
|
if (channelListener.isDebug())
|
||||||
|
cause.printStackTrace();
|
||||||
|
super.exceptionCaught(ctx, cause);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode a packet to a byte buffer, taking over for the standard Minecraft encoder.
|
* Encode a packet to a byte buffer, taking over for the standard Minecraft encoder.
|
||||||
* @param ctx - the current context.
|
* @param ctx - the current context.
|
||||||
|
@ -57,4 +57,10 @@ interface ChannelListener {
|
|||||||
* @return The error reporter.
|
* @return The error reporter.
|
||||||
*/
|
*/
|
||||||
public ErrorReporter getReporter();
|
public ErrorReporter getReporter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if debug mode is enabled.
|
||||||
|
* @return TRUE if it is, FALSE otherwise.
|
||||||
|
*/
|
||||||
|
boolean isDebug();
|
||||||
}
|
}
|
@ -65,12 +65,26 @@ public class NettyProtocolInjector implements ChannelListener {
|
|||||||
|
|
||||||
// Handle errors
|
// Handle errors
|
||||||
private ErrorReporter reporter;
|
private ErrorReporter reporter;
|
||||||
|
private boolean debug;
|
||||||
|
|
||||||
public NettyProtocolInjector(ListenerInvoker invoker, ErrorReporter reporter) {
|
public NettyProtocolInjector(ListenerInvoker invoker, ErrorReporter reporter) {
|
||||||
this.invoker = invoker;
|
this.invoker = invoker;
|
||||||
this.reporter = reporter;
|
this.reporter = reporter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDebug() {
|
||||||
|
return debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether or not the debug mode is enabled.
|
||||||
|
* @param debug - TRUE if it is, FALSE otherwise.
|
||||||
|
*/
|
||||||
|
public void setDebug(boolean debug) {
|
||||||
|
this.debug = debug;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inject into the spigot connection class.
|
* Inject into the spigot connection class.
|
||||||
*/
|
*/
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren