Exemplo n.º 1
0
        /// <summary>
        /// Handles the region restart command
        /// </summary>
        /// <param name="scene">Scene.</param>
        /// <param name="args">Arguments.</param>
        void HandleRegionRestart(IScene scene, string [] args)
        {
            bool   allRegions = false;
            int    seconds    = 0;
            string message    = " will restart in {0}";
            string scnName    = "";

            if (scene != null)
            {
                scnName = scene.RegionInfo.RegionName;
            }

            // check if this for all scenes
            if ((args.Length > 1) && (args [1].ToLower() == "all"))
            {
                allRegions = true;
                var newargs = new List <string> (args);
                newargs.RemoveAt(1);
                args    = newargs.ToArray();
                scnName = "all regions";
            }

            if (args.Length < 3)
            {
                if (MainConsole.Instance.Prompt("[Restart]: Do you wish to restart " + scnName +
                                                " immediately? (yes/no)", "no") != "yes")
                {
                    MainConsole.Instance.Info("usage: region restart <time> [message]");
                    return;
                }
            }

            // do we have a time?
            if (args.Length > 2)
            {
                if (!int.TryParse(args [2], out seconds))
                {
                    MainConsole.Instance.Error("[Restart]: Unable to determine restart delay!");
                    return;
                }
            }

            // build message interval list
            List <int> times = new List <int> ();

            while (seconds > 0)
            {
                times.Add(seconds);
                if (seconds > 300)
                {
                    seconds -= 120;
                }
                else if (seconds > 30)
                {
                    seconds -= 30;
                }
                else
                {
                    seconds -= 15;
                }
            }
            times.Add(0);               // we should always have a 'zero' for the immediate request

            // have a message?
            if (args.Length > 3)
            {
                message = Util.CombineParams(args, 4);    // assume everything else is the message
            }
            if (!allRegions)
            {
                // we have a specified region
                IRestartModule restartModule = scene.RequestModuleInterface <IRestartModule> ();
                if (restartModule == null)
                {
                    MainConsole.Instance.Error("[Restart]: Unable to locate restart module for " + scnName);
                    return;
                }
                restartModule.ScheduleRestart(UUID.Zero, scnName + message, times.ToArray(), true);
            }
            else
            {
                int offset = 0;
                // check for immediate restart
                if ((times.Count == 1) && (times [0] == 0))
                {
                    times [0] = 2;                              // delay initial restart by 2 seconds
                }
                foreach (IScene scn in MainConsole.Instance.ConsoleScenes)
                {
                    for (int i = 0; i < times.Count; i++)
                    {
                        times [i] = times [i] + 5;               // stagger each alert/restart by 5 seconds
                    }

                    scnName = scn.RegionInfo.RegionName;

                    IRestartModule sceneRestart = scn.RequestModuleInterface <IRestartModule> ();
                    if (sceneRestart == null)
                    {
                        MainConsole.Instance.Error("[Restart]: Unable to locate restart module for " + scnName);
                    }
                    else
                    {
                        sceneRestart.ScheduleRestart(UUID.Zero, scnName + message, times.ToArray(), true);
                        offset++;
                    }
                }
            }
        }