public override bool Stop() { if (!base.Stop()) { return(false); } Logger.Log(LogType.Debug, $"Stopping {ComponentName}."); if (PlayerWatcherToken?.IsCancellationRequested == false) { PlayerWatcherToken.Cancel(); PlayerWatcherLock.Wait(); } if (PlayerCorrectionToken?.IsCancellationRequested == false) { PlayerCorrectionToken.Cancel(); PlayerCorrectionLock.Wait(); } ModuleManager.ClientJoined -= ModuleManager_ClientJoined; ModuleManager.ClientLeaved -= ModuleManager_ClientLeaved; Listener?.Stop(); lock (JoiningClients) { foreach (var client in JoiningClients) { client?.Dispose(); } JoiningClients.Clear(); } lock (Clients) { foreach (var client in Clients) { client?.SendKick("Server is closing!"); } Clients.Clear(); } NearPlayers.Clear(); return(true); }
protected override void Dispose(bool disposing) { if (!IsDisposed) { if (disposing) { // TODO if (PlayerWatcherToken?.IsCancellationRequested == false) { PlayerWatcherToken.Cancel(); PlayerWatcherLock.Wait(); } if (PlayerCorrectionToken?.IsCancellationRequested == false) { PlayerCorrectionToken.Cancel(); PlayerCorrectionLock.Wait(); } } IsDisposed = true; } base.Dispose(disposing); }