Пример #1
0
        static void RestartHandler(Player player, CommandReader cmd)
        {
            string   delayString = cmd.Next();
            TimeSpan delayTime   = DefaultShutdownTime;
            string   reason      = "";

            if (delayString != null)
            {
                if (delayString.Equals("abort", StringComparison.OrdinalIgnoreCase))
                {
                    if (Server.CancelShutdown())
                    {
                        Logger.Log(LogType.UserActivity,
                                   "Restart aborted by {0}.", player.Name);
                        Server.Message("&WRestart aborted by {0}", player.ClassyName);
                    }
                    else
                    {
                        player.MessageNow("Cannot abort restart - too late.");
                    }
                    return;
                }
                else if (!delayString.TryParseMiniTimespan(out delayTime))
                {
                    CdShutdown.PrintUsage(player);
                    return;
                }
                if (delayTime > DateTimeUtil.MaxTimeSpan)
                {
                    player.MessageMaxTimeSpan();
                    return;
                }
                reason = cmd.NextAll();
            }

            if (delayTime.TotalMilliseconds > Int32.MaxValue - 1)
            {
                player.Message("Restart: Delay is too long, maximum is {0}",
                               TimeSpan.FromMilliseconds(Int32.MaxValue - 1).ToMiniString());
                return;
            }

            Server.Message("&WServer restarting in {0}", delayTime.ToMiniString());

            if (String.IsNullOrEmpty(reason))
            {
                Logger.Log(LogType.UserActivity,
                           "{0} scheduled a restart ({1} delay).",
                           player.Name, delayTime.ToCompactString());
                ShutdownParams sp = new ShutdownParams(ShutdownReason.Restarting, delayTime, true, true);
                Server.Shutdown(sp, false);
            }
            else
            {
                Server.Message("&WRestart reason: {0}", reason);
                Logger.Log(LogType.UserActivity,
                           "{0} scheduled a restart ({1} delay). Reason: {2}",
                           player.Name, delayTime.ToCompactString(), reason);
                ShutdownParams sp = new ShutdownParams(ShutdownReason.Restarting, delayTime, true, true, reason, player);
                Server.Shutdown(sp, false);
            }
        }