// Stop the server public void Stop() { // Stop the server and release resources _closed = true; try { _tcp.Server.Close(); _tcp.Stop(); } catch (Exception e) { if (Debugger.IsAttached) { Debugger.Break(); } } try{ _broadcaster.StopBroadcasting(); } catch (Exception) {} // Submit end game report try { var c = new ApiClient(); var dcUsers = State.Instance.DcUsers.ToArray(); var req = new PutGameCompleteReq(State.Instance.Engine.ApiKey, State.Instance.Engine.Game.Id.ToString(), dcUsers); c.CompleteGameHistory(req); } catch (Exception e) { Log.Error("Disconnect Error reporting disconnect", e); } // Close all open connections foreach (var c in State.Instance.Clients) { try { c.Disconnect(false); } catch {} } State.Instance.RemoveAllClients(); try { if (OnStop != null) { OnStop.Invoke(this, null); } } catch {} }
private void Shutdown() { try { if (_calledShutdown) { return; } _calledShutdown = true; Log.Info(nameof(Shutdown)); _tcp.Stop(); _broadcaster.StopBroadcasting(); _listenTask.Wait(); OnStop?.Invoke(this, null); } catch (Exception ex) { Log.Error($"{nameof(Shutdown)}", ex); } }
// Stop the server public void Stop() { // Stop the server and release resources _closed = true; try { _tcp.Server.Close(); _tcp.Stop(); } catch (Exception e) { if (Debugger.IsAttached) { Debugger.Break(); } } try{ _broadcaster.StopBroadcasting(); } catch (Exception) {} // Close all open connections foreach (var c in State.Instance.Clients) { try { c.Disconnect(); } catch {} } State.Instance.RemoveAllClients(); try { if (OnStop != null) { OnStop.Invoke(this, null); } } catch {} }