Added API.OnStop(). Added ConsoleCancelEvent

This commit is contained in:
EntenKoeniq
2021-12-08 13:45:00 +01:00
parent 250ea7d3f3
commit 652733c715
3 changed files with 32 additions and 4 deletions

View File

@ -17,8 +17,9 @@ namespace CoopServer
internal class Resource
{
public bool ReadyToStop = false;
private static Thread _mainThread;
private static bool _hasToStop = false;
private static Queue _actionQueue;
private static ServerScript _script;
@ -40,7 +41,7 @@ namespace CoopServer
private void ThreadLoop()
{
while (!_hasToStop)
while (!Program.ReadyToStop)
{
Queue localQueue;
lock (_actionQueue.SyncRoot)
@ -57,6 +58,9 @@ namespace CoopServer
// 16 milliseconds to sleep to reduce CPU usage
Thread.Sleep(1000 / 60);
}
_script.API.InvokeStop();
ReadyToStop = true;
}
public bool InvokeModPacketReceived(long from, long target, string mod, byte customID, byte[] bytes)
@ -137,6 +141,7 @@ namespace CoopServer
#region EVENTS
public event EmptyEvent OnStart;
public event EmptyEvent OnStop;
public event ChatEvent OnChatMessage;
public event PlayerEvent OnPlayerHandshake;
public event PlayerEvent OnPlayerConnected;
@ -151,6 +156,11 @@ namespace CoopServer
OnStart?.Invoke();
}
internal void InvokeStop()
{
OnStop?.Invoke();
}
internal void InvokePlayerHandshake(Client client)
{
OnPlayerHandshake?.Invoke(client);