From d307109e1af20c5b1b27743853236d7842d871f0 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 13 Feb 2009 19:03:18 +0000 Subject: * refactor: move alert commands from Scene to DialogModule --- .../RemoteController/RemoteAdminPlugin.cs | 36 +++++++++++---- OpenSim/Region/Application/OpenSim.cs | 13 ------ .../CoreModules/Avatar/Dialog/DialogModule.cs | 52 +++++++++++++++++++++- OpenSim/Region/Framework/Scenes/Scene.cs | 30 ------------- OpenSim/Region/Framework/Scenes/SceneManager.cs | 10 ----- 5 files changed, 78 insertions(+), 63 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs index d457d2b..a0f1eea 100644 --- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs +++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs @@ -182,7 +182,8 @@ namespace OpenSim.ApplicationPlugins.RemoteController XmlRpcResponse response = new XmlRpcResponse(); Hashtable responseData = new Hashtable(); - try { + try + { Hashtable requestData = (Hashtable) request.Params[0]; checkStringParameters(request, new string[] { "password", "message" }); @@ -197,8 +198,14 @@ namespace OpenSim.ApplicationPlugins.RemoteController responseData["accepted"] = "true"; responseData["success"] = "true"; response.Value = responseData; - - m_app.SceneManager.SendGeneralMessage(message); + + m_app.SceneManager.ForEachScene( + delegate(Scene scene) + { + IDialogModule dialogModule = scene.RequestModuleInterface(); + if (dialogModule != null) + dialogModule.SendGeneralAlert(message); + }); } catch(Exception e) { @@ -283,19 +290,30 @@ namespace OpenSim.ApplicationPlugins.RemoteController response.Value = responseData; int timeout = 2000; + string message; - if (requestData.ContainsKey("shutdown") && - ((string) requestData["shutdown"] == "delayed") && - requestData.ContainsKey("milliseconds")) + if (requestData.ContainsKey("shutdown") + && ((string) requestData["shutdown"] == "delayed") + && requestData.ContainsKey("milliseconds")) { timeout = (Int32) requestData["milliseconds"]; - m_app.SceneManager.SendGeneralMessage("Region is going down in " + ((int) (timeout/1000)).ToString() + - " second(s). Please save what you are doing and log out."); + + message + = "Region is going down in " + ((int) (timeout/1000)).ToString() + + " second(s). Please save what you are doing and log out."; } else { - m_app.SceneManager.SendGeneralMessage("Region is going down now."); + message = "Region is going down now."; } + + m_app.SceneManager.ForEachScene( + delegate(Scene scene) + { + IDialogModule dialogModule = scene.RequestModuleInterface(); + if (dialogModule != null) + dialogModule.SendGeneralAlert(message); + }); // Perform shutdown Timer shutdownTimer = new Timer(timeout); // Wait before firing diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 17ced08..a0d5bd8 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -177,14 +177,6 @@ namespace OpenSim "show queues", "Show queue data", HandleShow); - m_console.Commands.AddCommand("region", false, "alert", - "alert ", - "Send an alert to a user", RunCommand); - - m_console.Commands.AddCommand("region", false, "alert general", - "alert general ", - "Send an alert everyone", RunCommand); - m_console.Commands.AddCommand("region", false, "backup", "backup", "Persist objects to the database now", RunCommand); @@ -547,7 +539,6 @@ namespace OpenSim } } - /// /// Runs commands issued by the server console from the operator /// @@ -577,10 +568,6 @@ namespace OpenSim m_sceneManager.BackupCurrentScene(); break; - case "alert": - m_sceneManager.HandleAlertCommandOnCurrentScene(cmdparams); - break; - case "remove-region": string regRemoveName = CombineParams(cmdparams, 0); diff --git a/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs b/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs index 3fe57bc..6dd020a 100644 --- a/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs @@ -26,6 +26,8 @@ */ using System.Collections.Generic; +using System.Reflection; +using log4net; using Nini.Config; using OpenMetaverse; using OpenSim.Framework; @@ -36,7 +38,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Dialog { public class DialogModule : IRegionModule, IDialogModule { - //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); protected Scene m_scene; @@ -44,6 +46,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Dialog { m_scene = scene; m_scene.RegisterModuleInterface(this); + + m_scene.AddCommand( + this, "alert", "alert ", "Send an alert to a user", HandleAlertConsoleCommand); + + m_scene.AddCommand( + this, "alert general", "alert general ", "Send an alert to everyone", HandleAlertConsoleCommand); } public void PostInitialise() {} @@ -137,5 +145,47 @@ namespace OpenSim.Region.CoreModules.Avatar.Dialog presence.ControllingClient.SendBlueBoxMessage(fromAvatarID, fromAvatarName, message); } } + + /// + /// Handle an alert command from the console. + /// + /// + /// + public void HandleAlertConsoleCommand(string module, string[] cmdparams) + { + if (m_scene.ConsoleScene() != null && m_scene.ConsoleScene() != m_scene) + return; + + if (cmdparams[1] == "general") + { + string message = CombineParams(cmdparams, 2); + + m_log.InfoFormat( + "[DIALOG]: Sending general alert in region {0} with message {1}", m_scene.RegionInfo.RegionName, message); + SendGeneralAlert(message); + } + else + { + string firstName = cmdparams[1]; + string lastName = cmdparams[2]; + string message = CombineParams(cmdparams, 3); + + m_log.InfoFormat( + "[DIALOG]: Sending alert in region {0} to {1} {2} with message {3}", + m_scene.RegionInfo.RegionName, firstName, lastName, message); + SendAlertToUser(firstName, lastName, message, false); + } + } + + private string CombineParams(string[] commandParams, int pos) + { + string result = string.Empty; + for (int i = pos; i < commandParams.Length; i++) + { + result += commandParams[i] + " "; + } + + return result; + } } } diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 18e729f..611b9db 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2213,7 +2213,6 @@ namespace OpenSim.Region.Framework.Scenes { lock (av) { - for (int i = 0; i < regionslst.Count; i++) { av.KnownChildRegionHandles.Remove(regionslst[i]); @@ -2902,35 +2901,6 @@ namespace OpenSim.Region.Framework.Scenes } } - /// - /// Handle an alert command from the console. - /// FIXME: Command parsing code really shouldn't be in this core Scene class. - /// - /// - public void HandleAlertCommand(string[] commandParams) - { - if (commandParams[0] == "general") - { - string message = CombineParams(commandParams, 1); - m_dialogModule.SendGeneralAlert(message); - } - else - { - string message = CombineParams(commandParams, 2); - m_dialogModule.SendAlertToUser(commandParams[0], commandParams[1], message, false); - } - } - - private string CombineParams(string[] commandParams, int pos) - { - string result = String.Empty; - for (int i = pos; i < commandParams.Length; i++) - { - result += commandParams[i] + " "; - } - return result; - } - #endregion /// diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs index 180f8a1..fe37dae 100644 --- a/OpenSim/Region/Framework/Scenes/SceneManager.cs +++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs @@ -296,16 +296,6 @@ namespace OpenSim.Region.Framework.Scenes ForEachCurrentScene(delegate(Scene scene) { scene.Backup(); }); } - public void HandleAlertCommandOnCurrentScene(string[] cmdparams) - { - ForEachCurrentScene(delegate(Scene scene) { scene.HandleAlertCommand(cmdparams); }); - } - - public void SendGeneralMessage(string msg) - { - ForEachCurrentScene(delegate(Scene scene) { scene.HandleAlertCommand(new string[] { "general", msg }); }); - } - public bool TrySetCurrentScene(string regionName) { if ((String.Compare(regionName, "root") == 0) -- cgit v1.1