ShutDown() public method

public ShutDown ( ) : void
return void
Example #1
0
        // Disconnect all players
        public void ShutDown()
        {
            try {
                log.Log("Server shutting down.", LogType.SystemActivity);
                keepGoing = false;
                if (mainThread != null && mainThread.IsAlive)
                {
                    mainThread.Join();
                }

                if (heartbeat != null)
                {
                    heartbeat.ShutDown();
                }
                if (tasks != null)
                {
                    tasks.ShutDown();
                }

                lock ( playerListLock ) {
                    for (int i = 1; i < players.Length; i++)
                    {
                        if (players[i] != null)
                        {
                            players[i].session.Kick("Server shutting down.");
                        }
                        players[i] = null;
                    }
                    playerCount = 0;
                }

                if (config.GetBool("SaveOnShutdown") && map != null)
                {
                    map.Save();
                }

                if (db != null)
                {
                    db.Save();
                }
                if (bans != null)
                {
                    bans.Save();
                }
                if (server != null)
                {
                    server.ShutDown();
                }
            } catch (Exception ex) {
                log.Log("Error occured while trying to shut down: {0}", LogType.FatalError, ex.Message);
            }
        }