From 912be7a2acee6f49eeee2f06879d9fff7ca183ab Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Fri, 22 May 2009 14:25:50 +0000 Subject: converting Chat module and Concierge module to new style region modules --- .../Region/CoreModules/Avatar/Chat/ChatModule.cs | 69 +++++++++++++------ .../Resources/CoreModulePlugin.addin.xml | 1 + .../Avatar/Concierge/ConciergeModule.cs | 78 +++++++++++++++------- .../Resources/OptionalModules.addin.xml | 1 + 4 files changed, 105 insertions(+), 44 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs index 337644d..47c9db5 100644 --- a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs @@ -37,7 +37,7 @@ using OpenSim.Region.Framework.Scenes; namespace OpenSim.Region.CoreModules.Avatar.Chat { - public class ChatModule : IRegionModule + public class ChatModule : ISharedRegionModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -50,27 +50,39 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat private int m_whisperdistance = 10; private List m_scenes = new List(); - internal object m_syncInit = new object(); + internal object m_syncy = new object(); - #region IRegionModule Members - public virtual void Initialise(Scene scene, IConfigSource config) + internal IConfig m_config; + + #region ISharedRegionModule Members + public virtual void Initialise(IConfigSource config) { - // wrap this in a try block so that defaults will work if - // the config file doesn't specify otherwise. - try - { - m_enabled = config.Configs["Chat"].GetBoolean("enabled", m_enabled); - if (!m_enabled) return; - m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance", m_whisperdistance); - m_saydistance = config.Configs["Chat"].GetInt("say_distance", m_saydistance); - m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance", m_shoutdistance); + m_config = config.Configs["Chat"]; + + if (null == m_config) + { + m_log.Info("[CHAT]: no config found, plugin disabled"); + return; } - catch (Exception) + + if (!m_config.GetBoolean("enabled", false)) { + m_log.Info("[CHAT]: plugin disabled by configuration"); + return; } + m_enabled = true; - lock (m_syncInit) + m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance", m_whisperdistance); + m_saydistance = config.Configs["Chat"].GetInt("say_distance", m_saydistance); + m_shoutdistance = config.Configs["Chat"].GetInt("shout_distance", m_shoutdistance); + } + + public virtual void AddRegion(Scene scene) + { + if (!m_enabled) return; + + lock (m_syncy) { if (!m_scenes.Contains(scene)) { @@ -84,23 +96,38 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat m_log.InfoFormat("[CHAT]: Initialized for {0} w:{1} s:{2} S:{3}", scene.RegionInfo.RegionName, m_whisperdistance, m_saydistance, m_shoutdistance); } - - public virtual void PostInitialise() + + public virtual void RegionLoaded(Scene scene) { } + public virtual void RemoveRegion(Scene scene) + { + if (!m_enabled) return; + + lock (m_syncy) + { + if (m_scenes.Contains(scene)) + { + scene.EventManager.OnNewClient -= OnNewClient; + scene.EventManager.OnChatFromWorld -= OnChatFromWorld; + scene.EventManager.OnChatBroadcast -= OnChatBroadcast; + m_scenes.Remove(scene); + } + } + } + public virtual void Close() { } - public virtual string Name + public virtual void PostInitialise() { - get { return "ChatModule"; } } - public virtual bool IsSharedModule + public virtual string Name { - get { return true; } + get { return "ChatModule"; } } #endregion diff --git a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml index 3b6c1dc..6c80598 100644 --- a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml +++ b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml @@ -18,6 +18,7 @@ + diff --git a/OpenSim/Region/OptionalModules/Avatar/Concierge/ConciergeModule.cs b/OpenSim/Region/OptionalModules/Avatar/Concierge/ConciergeModule.cs index 604b21d..687b2da 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Concierge/ConciergeModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Concierge/ConciergeModule.cs @@ -47,7 +47,7 @@ using OpenSim.Region.CoreModules.Avatar.Chat; namespace OpenSim.Region.OptionalModules.Avatar.Concierge { - public class ConciergeModule : ChatModule, IRegionModule + public class ConciergeModule : ChatModule, ISharedRegionModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -76,28 +76,26 @@ namespace OpenSim.Region.OptionalModules.Avatar.Concierge internal object m_syncy = new object(); - #region IRegionModule Members - public override void Initialise(Scene scene, IConfigSource config) + internal bool m_enabled = false; + + #region ISharedRegionModule Members + public override void Initialise(IConfigSource config) { - try - { - if ((m_config = config.Configs["Concierge"]) == null) - { - //_log.InfoFormat("[Concierge]: no configuration section [Concierge] in OpenSim.ini: module not configured"); - return; - } + m_config = config.Configs["Concierge"]; - if (!m_config.GetBoolean("enabled", false)) - { - //_log.InfoFormat("[Concierge]: module disabled by OpenSim.ini configuration"); - return; - } + if (null == m_config) + { + m_log.Info("[Concierge]: no config found, plugin disabled"); + return; } - catch (Exception) + + if (!m_config.GetBoolean("enabled", false)) { - m_log.Info("[Concierge]: module not configured"); + m_log.Info("[Concierge]: plugin disabled by configuration"); return; } + m_enabled = true; + // check whether ChatModule has been disabled: if yes, // then we'll "stand in" @@ -140,6 +138,12 @@ namespace OpenSim.Region.OptionalModules.Avatar.Concierge m_regions = new Regex(@regions, RegexOptions.Compiled | RegexOptions.IgnoreCase); } } + } + + + public override void AddRegion(Scene scene) + { + if (!m_enabled) return; scene.CommsManager.HttpServer.AddXmlRPCHandler("concierge_update_welcome", XmlRpcUpdateWelcomeMethod, false); @@ -169,6 +173,40 @@ namespace OpenSim.Region.OptionalModules.Avatar.Concierge m_log.InfoFormat("[Concierge]: initialized for {0}", scene.RegionInfo.RegionName); } + public override void RemoveRegion(Scene scene) + { + if (!m_enabled) return; + + scene.CommsManager.HttpServer.RemoveXmlRPCHandler("concierge_update_welcome"); + + lock (m_syncy) + { + // unsubscribe from NewClient events + scene.EventManager.OnNewClient -= OnNewClient; + + // unsubscribe from *Chat events + scene.EventManager.OnChatFromWorld -= OnChatFromWorld; + if (!m_replacingChatModule) + scene.EventManager.OnChatFromClient -= OnChatFromClient; + scene.EventManager.OnChatBroadcast -= OnChatBroadcast; + + // unsubscribe from agent change events + scene.EventManager.OnMakeRootAgent -= OnMakeRootAgent; + scene.EventManager.OnMakeChildAgent -= OnMakeChildAgent; + + if (m_scenes.Contains(scene)) + { + m_scenes.Remove(scene); + } + + if (m_conciergedScenes.Contains(scene)) + { + m_conciergedScenes.Remove(scene); + } + } + m_log.InfoFormat("[Concierge]: removed {0}", scene.RegionInfo.RegionName); + } + public override void PostInitialise() { } @@ -181,12 +219,6 @@ namespace OpenSim.Region.OptionalModules.Avatar.Concierge { get { return "ConciergeModule"; } } - - public override bool IsSharedModule - { - get { return true; } - } - #endregion #region ISimChat Members diff --git a/OpenSim/Region/OptionalModules/Resources/OptionalModules.addin.xml b/OpenSim/Region/OptionalModules/Resources/OptionalModules.addin.xml index 69d3e57..01a5d8b 100644 --- a/OpenSim/Region/OptionalModules/Resources/OptionalModules.addin.xml +++ b/OpenSim/Region/OptionalModules/Resources/OptionalModules.addin.xml @@ -9,6 +9,7 @@ + -- cgit v1.1