public void Shutdown() { // Stop accepting new connections IgnoreNewConnections = true; Exiting = true; // Unregister events so we dont get a shit ton of calls GPSPClient.OnDisconnected -= ClientDisconnected; // Disconnected all connected clients foreach (GPSPClient client in Clients.Values) { client.Dispose(); } // clear clients Clients.Clear(); // Shutdown the listener socket ShutdownSocket(); DB.Dispose(); // Tell the base to dispose all free objects Dispose(); }
/// <summary> /// Shutsdown the ClientManager server and socket /// </summary> public void Shutdown() { // Stop accepting new connections IgnoreNewConnections = true; Exiting = true; // Unregister events so we dont get a shit ton of calls GPCMClient.OnSuccessfulLogin -= ClientSuccessfulLogin; GPCMClient.OnDisconnect -= ClientDisconnected; // Discard the poll timer PollTimer.Stop(); PollTimer.Dispose(); StatusTimer.Stop(); StatusTimer.Dispose(); // Disconnected all connected clients Console.WriteLine("Disconnecting all users..."); Parallel.ForEach(Clients.Values, client => client.DisconnectByReason(DisconnectReason.ForcedServerShutdown)); Parallel.ForEach(Processing.Values, client => client.DisconnectByReason(DisconnectReason.ForcedServerShutdown)); // Update the database try { // Set everyone's online session to 0 LoginQuery.ResetStatusAndSessionKey(); } catch (Exception e) { LogWriter.Log.WriteException(e); } // Update Connected Clients in the Database Clients.Clear(); DB.Dispose(); // Tell the base to dispose all free objects Dispose(); }