Detect packet timeout.
Dieser Commit ist enthalten in:
Ursprung
4f4202185c
Commit
a6db5419c0
@ -43,6 +43,13 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
// Structure compiler
|
// Structure compiler
|
||||||
private BackgroundCompiler backgroundCompiler;
|
private BackgroundCompiler backgroundCompiler;
|
||||||
|
|
||||||
|
// Used to (mostly) clean up packets that have expired
|
||||||
|
private int asyncPacketTask = -1;
|
||||||
|
|
||||||
|
// Number of ticks between each cleanup. We don't need to do this often,
|
||||||
|
// as it's only indeeded to detected timeouts.
|
||||||
|
private static final int ASYNC_PACKET_DELAY = 10;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
logger = getLoggerSafely();
|
logger = getLoggerSafely();
|
||||||
@ -69,6 +76,9 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
// Inject our hook into already existing players
|
// Inject our hook into already existing players
|
||||||
protocolManager.initializePlayers(server.getOnlinePlayers());
|
protocolManager.initializePlayers(server.getOnlinePlayers());
|
||||||
|
|
||||||
|
// Timeout
|
||||||
|
createAsyncTask(server);
|
||||||
|
|
||||||
// Try to enable statistics
|
// Try to enable statistics
|
||||||
try {
|
try {
|
||||||
statistisc = new Statistics(this);
|
statistisc = new Statistics(this);
|
||||||
@ -79,6 +89,26 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createAsyncTask(Server server) {
|
||||||
|
try {
|
||||||
|
if (asyncPacketTask < 0)
|
||||||
|
throw new IllegalStateException("Async task has already been created");
|
||||||
|
|
||||||
|
// Attempt to create task
|
||||||
|
asyncPacketTask = server.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
protocolManager.getAsyncFilterManager().sendProcessedPackets();
|
||||||
|
}
|
||||||
|
}, ASYNC_PACKET_DELAY, ASYNC_PACKET_DELAY);
|
||||||
|
|
||||||
|
} catch (Throwable e) {
|
||||||
|
if (asyncPacketTask == -1) {
|
||||||
|
logger.log(Level.SEVERE, "Unable to create packet timeout task.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void checkForIncompatibility(PluginManager manager) {
|
private void checkForIncompatibility(PluginManager manager) {
|
||||||
// Plugin authors: Notify me to remove these
|
// Plugin authors: Notify me to remove these
|
||||||
String[] incompatiblePlugins = {};
|
String[] incompatiblePlugins = {};
|
||||||
@ -100,6 +130,12 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
BackgroundCompiler.setInstance(null);
|
BackgroundCompiler.setInstance(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
if (asyncPacketTask >= 0) {
|
||||||
|
getServer().getScheduler().cancelTask(asyncPacketTask);
|
||||||
|
asyncPacketTask = -1;
|
||||||
|
}
|
||||||
|
|
||||||
protocolManager.close();
|
protocolManager.close();
|
||||||
protocolManager = null;
|
protocolManager = null;
|
||||||
statistisc = null;
|
statistisc = null;
|
||||||
|
@ -185,4 +185,12 @@ public class AsyncFilterManager {
|
|||||||
private PacketProcessingQueue getProcessingQueue(PacketEvent packet) {
|
private PacketProcessingQueue getProcessingQueue(PacketEvent packet) {
|
||||||
return packet.isServerPacket() ? serverProcessingQueue : clientProcessingQueue;
|
return packet.isServerPacket() ? serverProcessingQueue : clientProcessingQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send any due packets, or clean up packets that have expired.
|
||||||
|
*/
|
||||||
|
public void sendProcessedPackets() {
|
||||||
|
clientQueue.trySendPackets();
|
||||||
|
serverQueue.trySendPackets();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,9 @@ public class AsyncListenerHandler {
|
|||||||
// Cancel the async handler
|
// Cancel the async handler
|
||||||
private volatile boolean cancelled;
|
private volatile boolean cancelled;
|
||||||
|
|
||||||
|
// If we've started the listener loop before
|
||||||
|
private volatile boolean started;
|
||||||
|
|
||||||
// The packet listener
|
// The packet listener
|
||||||
private PacketListener listener;
|
private PacketListener listener;
|
||||||
|
|
||||||
@ -105,6 +108,13 @@ public class AsyncListenerHandler {
|
|||||||
// Danger, danger!
|
// Danger, danger!
|
||||||
if (Thread.currentThread().getId() == mainThread.getId())
|
if (Thread.currentThread().getId() == mainThread.getId())
|
||||||
throw new IllegalStateException("Do not call this method from the main thread.");
|
throw new IllegalStateException("Do not call this method from the main thread.");
|
||||||
|
if (started)
|
||||||
|
throw new IllegalStateException("A listener cannot be run by multiple threads. Create a new listener instead.");
|
||||||
|
if (cancelled)
|
||||||
|
throw new IllegalStateException("Listener has been cancelled. Create a new listener instead.");
|
||||||
|
|
||||||
|
// Proceed
|
||||||
|
started = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mainLoop:
|
mainLoop:
|
||||||
@ -158,6 +168,7 @@ public class AsyncListenerHandler {
|
|||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
filterManager.unregisterAsyncHandlerInternal(this);
|
filterManager.unregisterAsyncHandlerInternal(this);
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
|
started = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren