Exemple #1
0
        static void ShutdownThread(bool restarting, string msg)
        {
            try {
                Logger.Log(LogType.SystemActivity, "Server shutting down ({0})", msg);
            } catch { }

            // Stop accepting new connections and disconnect existing sessions
            try {
                if (Listener != null)
                {
                    Listener.Close();
                }
            } catch (Exception ex) { Logger.LogError(ex); }

            try {
                Player[] players = PlayerInfo.Online.Items;
                foreach (Player p in players)
                {
                    p.Leave(msg);
                }
            } catch (Exception ex) { Logger.LogError(ex); }

            byte[] kick = Packet.Kick(msg, false);
            try {
                INetSocket[] pending = INetSocket.pending.Items;
                foreach (INetSocket p in pending)
                {
                    p.Send(kick, SendFlags.None);
                }
            } catch (Exception ex) { Logger.LogError(ex); }

            OnShuttingDownEvent.Call(restarting, msg);
            Plugin.UnloadAll();

            try {
                string  autoload = null;
                Level[] loaded   = LevelInfo.Loaded.Items;
                foreach (Level lvl in loaded)
                {
                    if (!lvl.SaveChanges)
                    {
                        continue;
                    }

                    autoload = autoload + lvl.name + "=" + lvl.physics + Environment.NewLine;
                    lvl.Save();
                    lvl.SaveBlockDBChanges();
                }

                if (Server.SetupFinished && !Server.Config.AutoLoadMaps)
                {
                    File.WriteAllText("text/autoload.txt", autoload);
                }
            } catch (Exception ex) { Logger.LogError(ex); }

            try {
                Logger.Log(LogType.SystemActivity, "Server shutdown completed");
            } catch { }

            try { FileLogger.Flush(null); } catch { }

            if (restarting)
            {
                // first try to use excevp to restart in CLI mode under mono
                // - see detailed comment in HACK_Execvp for why this is required
                if (HACK_TryExecvp())
                {
                    HACK_Execvp();
                }
                Process.Start(GetRestartPath());
            }
            Environment.Exit(0);
        }
Exemple #2
0
        static void ShutdownThread(bool restarting, string msg)
        {
            try {
                Logger.Log(LogType.SystemActivity, "Server shutting down ({0})", msg);
            } catch { }

            // Stop accepting new connections and disconnect existing sessions
            try {
                if (Listener != null)
                {
                    Listener.Close();
                }
            } catch (Exception ex) { Logger.LogError(ex); }

            try {
                Player[] players = PlayerInfo.Online.Items;

                SaveRestoreTokens(players);

                foreach (Player p in players)
                {
                    p.Leave(msg);
                }
            } catch (Exception ex) { Logger.LogError(ex); }

            byte[] kick = Packet.Kick(msg, false);
            try {
                INetSocket[] pending = INetSocket.pending.Items;
                foreach (INetSocket p in pending)
                {
                    p.Send(kick, false);
                }
            } catch (Exception ex) { Logger.LogError(ex); }

            Plugin.UnloadAll();
            OnShuttingDownEvent.Call(restarting, msg);

            try {
                string  autoload = null;
                Level[] loaded   = LevelInfo.Loaded.Items;
                foreach (Level lvl in loaded)
                {
                    if (!lvl.SaveChanges)
                    {
                        continue;
                    }

                    autoload = autoload + lvl.name + "=" + lvl.physics + Environment.NewLine;
                    lvl.Save(false, true);
                    lvl.SaveBlockDBChanges();
                }

                if (Server.SetupFinished && !Server.Config.AutoLoadMaps)
                {
                    File.WriteAllText("text/autoload.txt", autoload);
                }
            } catch (Exception ex) { Logger.LogError(ex); }

            try {
                Logger.Log(LogType.SystemActivity, "Server shutdown completed");
            } catch { }

            try { FileLogger.Flush(null); } catch { }
            if (restarting)
            {
                Process.Start(RestartPath);
            }
            Environment.Exit(0);
        }