From ac2fcbe224d4877dccc4d73e9c58771e40a4ae1c Mon Sep 17 00:00:00 2001 From: CasperW Date: Thu, 26 Nov 2009 15:17:44 +0100 Subject: [PATCH] Improvements to rAdmin admin_shutdown and admin_restart. Both methods can now accept a parameter of noticetype = dialog in order to display a blue persistant dropdown instead of a short notice. Added an optional and configurable delay to the restart method, defaulting at 30 seconds as before. Both methods can also accept a noticetype = none dialog in order to act silently. --- .../RemoteController/RemoteAdminPlugin.cs | 74 ++++++++++++++++++- OpenSim/Region/Framework/Scenes/Scene.cs | 16 +++- 2 files changed, 86 insertions(+), 4 deletions(-) diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs index 3bc557da94..325816da7d 100644 --- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs +++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs @@ -213,9 +213,59 @@ namespace OpenSim.ApplicationPlugins.RemoteController if (!m_app.SceneManager.TryGetScene(regionID, out rebootedScene)) throw new Exception("region not found"); + int timeout = 30000; + string message; + + if (requestData.ContainsKey("restart") + && ((string)requestData["restart"] == "delayed") + && requestData.ContainsKey("milliseconds")) + { + timeout = Int32.Parse(requestData["milliseconds"].ToString()); + + if (timeout < 15000) + { + //It must be at least 15 seconds or we'll cancel the reboot request + timeout = 15000; + } + + message + = "Region is restarting in " + ((int)(timeout / 1000)).ToString() + + " second(s). Please save what you are doing and log out."; + } + else + { + message = "Region is restarting in 30 second(s). Please save what you are doing and log out."; + } + + if (requestData.ContainsKey("noticetype") + && ((string)requestData["noticetype"] == "dialog")) + { + m_app.SceneManager.ForEachScene( + delegate(Scene scene) + { + IDialogModule dialogModule = scene.RequestModuleInterface(); + if (dialogModule != null) + dialogModule.SendNotificationToUsersInRegion(UUID.Zero, "System", message); + }); + } + else + { + if (!requestData.ContainsKey("noticetype") + || ((string)requestData["noticetype"] != "none")) + { + m_app.SceneManager.ForEachScene( + delegate(Scene scene) + { + IDialogModule dialogModule = scene.RequestModuleInterface(); + if (dialogModule != null) + dialogModule.SendGeneralAlert(message); + }); + } + } + responseData["rebooting"] = true; response.Value = responseData; - rebootedScene.Restart(30); + rebootedScene.Restart(timeout / 1000,false); } catch (Exception e) { @@ -419,13 +469,33 @@ namespace OpenSim.ApplicationPlugins.RemoteController message = "Region is going down now."; } - m_app.SceneManager.ForEachScene( + if (requestData.ContainsKey("noticetype") + && ((string) requestData["noticetype"] == "dialog")) + { + m_app.SceneManager.ForEachScene( delegate(Scene scene) + { + IDialogModule dialogModule = scene.RequestModuleInterface(); + if (dialogModule != null) + dialogModule.SendNotificationToUsersInRegion(UUID.Zero, "System", message); + }); + } + else + { + if (!requestData.ContainsKey("noticetype") + || ((string)requestData["noticetype"] != "none")) + { + m_app.SceneManager.ForEachScene( + delegate(Scene scene) { IDialogModule dialogModule = scene.RequestModuleInterface(); if (dialogModule != null) dialogModule.SendGeneralAlert(message); }); + } + } + + // Perform shutdown System.Timers.Timer shutdownTimer = new System.Timers.Timer(timeout); // Wait before firing diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 4ffa1a2ed4..be1d4bfbf4 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -872,6 +872,15 @@ namespace OpenSim.Region.Framework.Scenes /// /// float indicating duration before restart. public virtual void Restart(float seconds) + { + Restart(seconds, true); + } + + /// + /// Given float seconds, this will restart the region. showDialog will optionally alert the users. + /// + /// float indicating duration before restart. + public virtual void Restart(float seconds, bool showDialog) { // notifications are done in 15 second increments // so .. if the number of seconds is less then 15 seconds, it's not really a restart request @@ -893,8 +902,11 @@ namespace OpenSim.Region.Framework.Scenes m_restartTimer.Elapsed += new ElapsedEventHandler(RestartTimer_Elapsed); m_log.Info("[REGION]: Restarting Region in " + (seconds / 60) + " minutes"); m_restartTimer.Start(); - m_dialogModule.SendNotificationToUsersInRegion( - UUID.Random(), String.Empty, RegionInfo.RegionName + ": Restarting in 2 Minutes"); + if (showDialog) + { + m_dialogModule.SendNotificationToUsersInRegion( + UUID.Random(), String.Empty, RegionInfo.RegionName + ": Restarting in " + (seconds / 60).ToString() + " Minutes"); + } } }