From a87c4c7d8924138896ab93828cd8e7d8442fbaf7 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sun, 11 Nov 2012 00:21:10 +0000 Subject: Converting WorldCommModule to INonSharedRegionModule Signed-off-by: Diva Canto --- .../Scripting/WorldComm/WorldCommModule.cs | 36 +++++++++++++++------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'OpenSim/Region/CoreModules/Scripting') diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs index 401ff6c..2c26e63 100644 --- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs @@ -30,6 +30,7 @@ using System.Collections; using System.Collections.Generic; using System.Text.RegularExpressions; using Nini.Config; +using Mono.Addins; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Region.Framework.Interfaces; @@ -86,7 +87,8 @@ using OpenSim.Region.Framework.Scenes; namespace OpenSim.Region.CoreModules.Scripting.WorldComm { - public class WorldCommModule : IRegionModule, IWorldComm + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] + public class WorldCommModule : IWorldComm, INonSharedRegionModule { // private static readonly ILog m_log = // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -99,9 +101,9 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm private int m_saydistance = 20; private int m_shoutdistance = 100; - #region IRegionModule Members + #region INonSharedRegionModule Members - public void Initialise(Scene scene, IConfigSource config) + public void Initialise(IConfigSource config) { // wrap this in a try block so that defaults will work if // the config file doesn't specify otherwise. @@ -120,18 +122,33 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm } if (maxlisteners < 1) maxlisteners = int.MaxValue; if (maxhandles < 1) maxhandles = int.MaxValue; + m_listenerManager = new ListenerManager(maxlisteners, maxhandles); + m_pendingQ = new Queue(); + m_pending = Queue.Synchronized(m_pendingQ); + } + public void PostInitialise() + { + } + + public void AddRegion(Scene scene) + { m_scene = scene; m_scene.RegisterModuleInterface(this); - m_listenerManager = new ListenerManager(maxlisteners, maxhandles); m_scene.EventManager.OnChatFromClient += DeliverClientMessage; m_scene.EventManager.OnChatBroadcast += DeliverClientMessage; - m_pendingQ = new Queue(); - m_pending = Queue.Synchronized(m_pendingQ); } - public void PostInitialise() + public void RegionLoaded(Scene scene) { } + + public void RemoveRegion(Scene scene) { + if (scene != m_scene) + return; + + m_scene.UnregisterModuleInterface(this); + m_scene.EventManager.OnChatBroadcast -= DeliverClientMessage; + m_scene.EventManager.OnChatBroadcast -= DeliverClientMessage; } public void Close() @@ -143,10 +160,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm get { return "WorldCommModule"; } } - public bool IsSharedModule - { - get { return false; } - } + public Type ReplaceableInterface { get { return null; } } #endregion -- cgit v1.1 From b3dddd7447c42a60f1e4a2452e6a6c6dbe9d5618 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sun, 11 Nov 2012 00:38:27 +0000 Subject: document & 80-character width terminal formatting Signed-off-by: Diva Canto --- .../Scripting/WorldComm/WorldCommModule.cs | 170 ++++++++++++++------- 1 file changed, 114 insertions(+), 56 deletions(-) (limited to 'OpenSim/Region/CoreModules/Scripting') diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs index 2c26e63..c88be82 100644 --- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs @@ -29,9 +29,12 @@ using System; using System.Collections; using System.Collections.Generic; using System.Text.RegularExpressions; + using Nini.Config; using Mono.Addins; + using OpenMetaverse; + using OpenSim.Framework; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; @@ -111,11 +114,16 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm int maxhandles = 64; try { - 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); - maxlisteners = config.Configs["LL-Functions"].GetInt("max_listens_per_region", maxlisteners); - maxhandles = config.Configs["LL-Functions"].GetInt("max_listens_per_script", maxhandles); + 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); + maxlisteners = config.Configs["LL-Functions"].GetInt( + "max_listens_per_region", maxlisteners); + maxhandles = config.Configs["LL-Functions"].GetInt( + "max_listens_per_script", maxhandles); } catch (Exception) { @@ -269,7 +277,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm if ((source = m_scene.GetSceneObjectPart(id)) != null) position = source.AbsolutePosition; - else if ((avatar = m_scene.GetScenePresence(id)) != null) + else if ((avatar = m_scene.GetScenePresence(id)) != null) position = avatar.AbsolutePosition; else if (ChatTypeEnum.Region == type) position = CenterOfRegion; @@ -292,7 +300,8 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm /// name of sender (object or avatar) /// key of sender (object or avatar) /// msg to sent - public void DeliverMessage(ChatTypeEnum type, int channel, string name, UUID id, string msg, Vector3 position) + public void DeliverMessage(ChatTypeEnum type, int channel, + string name, UUID id, string msg, Vector3 position) { // m_log.DebugFormat("[WorldComm] got[2] type {0}, channel {1}, name {2}, id {3}, msg {4}", // type, channel, name, id, msg); @@ -300,17 +309,21 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm // Determine which listen event filters match the given set of arguments, this results // in a limited set of listeners, each belonging a host. If the host is in range, add them // to the pending queue. - foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg)) + foreach (ListenerInfo li + in m_listenerManager.GetListeners(UUID.Zero, channel, + name, id, msg)) { // Dont process if this message is from yourself! if (li.GetHostID().Equals(id)) continue; - SceneObjectPart sPart = m_scene.GetSceneObjectPart(li.GetHostID()); + SceneObjectPart sPart = m_scene.GetSceneObjectPart( + li.GetHostID()); if (sPart == null) continue; - double dis = Util.GetDistanceTo(sPart.AbsolutePosition, position); + double dis = Util.GetDistanceTo(sPart.AbsolutePosition, + position); switch (type) { case ChatTypeEnum.Whisper: @@ -353,14 +366,16 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm /// /// Message. /// - public void DeliverMessageTo(UUID target, int channel, Vector3 pos, string name, UUID id, string msg) + public void DeliverMessageTo(UUID target, int channel, Vector3 pos, + string name, UUID id, string msg) { // Is id an avatar? ScenePresence sp = m_scene.GetScenePresence(target); if (sp != null) { - // ignore if a child agent this is restricted to inside one region + // ignore if a child agent this is restricted to inside one + // region if (sp.IsChildAgent) return; @@ -369,8 +384,9 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm // non zero channel messages only go to the attachments if (channel == 0) { - m_scene.SimChatToAgent(target, Utils.StringToBytes(msg), pos, name, id, false); - } + m_scene.SimChatToAgent(target, Utils.StringToBytes(msg), + pos, name, id, false); + } else { List attachments = sp.GetAttachments(); @@ -386,13 +402,18 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm } // Need to check each attachment - foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg)) + foreach (ListenerInfo li + in m_listenerManager.GetListeners(UUID.Zero, + channel, name, id, msg)) { if (li.GetHostID().Equals(id)) continue; - if (m_scene.GetSceneObjectPart(li.GetHostID()) == null) + if (m_scene.GetSceneObjectPart( + li.GetHostID()) == null) + { continue; + } if (targets.Contains(li.GetHostID())) QueueMessage(new ListenerInfo(li, name, id, msg)); @@ -403,17 +424,20 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm } // No avatar found so look for an object - foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg)) + foreach (ListenerInfo li + in m_listenerManager.GetListeners(UUID.Zero, channel, + name, id, msg)) { // Dont process if this message is from yourself! if (li.GetHostID().Equals(id)) continue; - SceneObjectPart sPart = m_scene.GetSceneObjectPart(li.GetHostID()); + SceneObjectPart sPart = m_scene.GetSceneObjectPart( + li.GetHostID()); if (sPart == null) continue; - if ( li.GetHostID().Equals(target)) + if (li.GetHostID().Equals(target)) { QueueMessage(new ListenerInfo(li, name, id, msg)); break; @@ -467,9 +491,15 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm private void DeliverClientMessage(Object sender, OSChatMessage e) { if (null != e.Sender) - DeliverMessage(e.Type, e.Channel, e.Sender.Name, e.Sender.AgentId, e.Message, e.Position); + { + DeliverMessage(e.Type, e.Channel, e.Sender.Name, + e.Sender.AgentId, e.Message, e.Position); + } else - DeliverMessage(e.Type, e.Channel, e.From, UUID.Zero, e.Message, e.Position); + { + DeliverMessage(e.Type, e.Channel, e.From, UUID.Zero, + e.Message, e.Position); + } } public Object[] GetSerializationData(UUID itemID) @@ -486,7 +516,8 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm public class ListenerManager { - private Dictionary> m_listeners = new Dictionary>(); + private Dictionary> m_listeners = + new Dictionary>(); private int m_maxlisteners; private int m_maxhandles; private int m_curlisteners; @@ -544,14 +575,15 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm itemID, hostID, channel, name, id, msg, regexBitfield); - List listeners; - if (!m_listeners.TryGetValue(channel,out listeners)) - { - listeners = new List(); - m_listeners.Add(channel, listeners); - } - listeners.Add(li); - m_curlisteners++; + List listeners; + if (!m_listeners.TryGetValue( + channel, out listeners)) + { + listeners = new List(); + m_listeners.Add(channel, listeners); + } + listeners.Add(li); + m_curlisteners++; return newHandle; } @@ -564,11 +596,13 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm { lock (m_listeners) { - foreach (KeyValuePair> lis in m_listeners) + foreach (KeyValuePair> lis + in m_listeners) { foreach (ListenerInfo li in lis.Value) { - if (li.GetItemID().Equals(itemID) && li.GetHandle().Equals(handle)) + if (li.GetItemID().Equals(itemID) && + li.GetHandle().Equals(handle)) { lis.Value.Remove(li); if (lis.Value.Count == 0) @@ -591,13 +625,15 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm lock (m_listeners) { - foreach (KeyValuePair> lis in m_listeners) + foreach (KeyValuePair> lis + in m_listeners) { foreach (ListenerInfo li in lis.Value) { if (li.GetItemID().Equals(itemID)) { - // store them first, else the enumerated bails on us + // store them first, else the enumerated bails on + // us removedListeners.Add(li); } } @@ -624,11 +660,13 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm { lock (m_listeners) { - foreach (KeyValuePair> lis in m_listeners) + foreach (KeyValuePair> lis + in m_listeners) { foreach (ListenerInfo li in lis.Value) { - if (li.GetItemID().Equals(itemID) && li.GetHandle() == handle) + if (li.GetItemID().Equals(itemID) && + li.GetHandle() == handle) { li.Activate(); // only one, bail out @@ -643,11 +681,13 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm { lock (m_listeners) { - foreach (KeyValuePair> lis in m_listeners) + foreach (KeyValuePair> lis + in m_listeners) { foreach (ListenerInfo li in lis.Value) { - if (li.GetItemID().Equals(itemID) && li.GetHandle() == handle) + if (li.GetItemID().Equals(itemID) && + li.GetHandle() == handle) { li.Deactivate(); // only one, bail out @@ -658,19 +698,24 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm } } - // non-locked access, since its always called in the context of the lock + /// + /// non-locked access, since its always called in the context of the + /// lock + /// + /// + /// private int GetNewHandle(UUID itemID) { List handles = new List(); // build a list of used keys for this specific itemID... - foreach (KeyValuePair> lis in m_listeners) + foreach (KeyValuePair> lis in m_listeners) { - foreach (ListenerInfo li in lis.Value) - { - if (li.GetItemID().Equals(itemID)) - handles.Add(li.GetHandle()); - } + foreach (ListenerInfo li in lis.Value) + { + if (li.GetItemID().Equals(itemID)) + handles.Add(li.GetHandle()); + } } // Note: 0 is NOT a valid handle for llListen() to return @@ -709,7 +754,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm lock (m_listeners) { List listeners; - if (!m_listeners.TryGetValue(channel,out listeners)) + if (!m_listeners.TryGetValue(channel, out listeners)) { return collection; } @@ -720,7 +765,8 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm { continue; } - if (!itemID.Equals(UUID.Zero) && !li.GetItemID().Equals(itemID)) + if (!itemID.Equals(UUID.Zero) && + !li.GetItemID().Equals(itemID)) { continue; } @@ -785,11 +831,14 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm lock (m_listeners) { if (!m_listeners.ContainsKey((int)item[2])) - m_listeners.Add((int)item[2], new List()); + { + m_listeners.Add((int)item[2], + new List()); + } m_listeners[(int)item[2]].Add(info); } - idx+=dataItemLength; + idx += dataItemLength; } } } @@ -820,17 +869,23 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm message, regexBitfield); } - public ListenerInfo(ListenerInfo li, string name, UUID id, string message) + public ListenerInfo(ListenerInfo li, string name, UUID id, + string message) { - Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, 0); + Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, + li.m_channel, name, id, message, 0); } - public ListenerInfo(ListenerInfo li, string name, UUID id, string message, int regexBitfield) + public ListenerInfo(ListenerInfo li, string name, UUID id, + string message, int regexBitfield) { - Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, regexBitfield); + Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, + li.m_channel, name, id, message, regexBitfield); } - private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, int regexBitfield) + private void Initialise(int handle, uint localID, UUID ItemID, + UUID hostID, int channel, string name, UUID id, + string message, int regexBitfield) { m_active = true; m_handle = handle; @@ -859,9 +914,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm return data; } - public static ListenerInfo FromData(uint localID, UUID ItemID, UUID hostID, Object[] data) + public static ListenerInfo FromData(uint localID, UUID ItemID, + UUID hostID, Object[] data) { - ListenerInfo linfo = new ListenerInfo((int)data[1], localID, ItemID, hostID, (int)data[2], (string)data[3], (UUID)data[4], (string)data[5]); + ListenerInfo linfo = new ListenerInfo((int)data[1], localID, + ItemID, hostID, (int)data[2], (string)data[3], + (UUID)data[4], (string)data[5]); linfo.m_active = (bool)data[0]; if (data.Length >= 7) { -- cgit v1.1 From d5f9f5c9c347f6d858bf91de87a5ba71ba06082a Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sun, 11 Nov 2012 00:39:10 +0000 Subject: document, 80-character width terminal formatting converting comments to documentation for IDE & doxygen goodness Signed-off-by: Diva Canto --- .../Scripting/WorldComm/WorldCommModule.cs | 80 ++++++++++++++++++---- 1 file changed, 65 insertions(+), 15 deletions(-) (limited to 'OpenSim/Region/CoreModules/Scripting') diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs index c88be82..2d2ea2f 100644 --- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs @@ -744,10 +744,23 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm #endregion - // Theres probably a more clever and efficient way to - // do this, maybe with regex. - // PM2008: Ha, one could even be smart and define a specialized Enumerator. - public List GetListeners(UUID itemID, int channel, string name, UUID id, string msg) + /// + /// Get listeners matching the input parameters. + /// + /// + /// Theres probably a more clever and efficient way to do this, maybe + /// with regex. + /// PM2008: Ha, one could even be smart and define a specialized + /// Enumerator. + /// + /// + /// + /// + /// + /// + /// + public List GetListeners(UUID itemID, int channel, + string name, UUID id, string msg) { List collection = new List(); @@ -845,17 +858,54 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm public class ListenerInfo : IWorldCommListenerInfo { - private bool m_active; // Listener is active or not - private int m_handle; // Assigned handle of this listener - private uint m_localID; // Local ID from script engine - private UUID m_itemID; // ID of the host script engine - private UUID m_hostID; // ID of the host/scene part - private int m_channel; // Channel - private UUID m_id; // ID to filter messages from - private string m_name; // Object name to filter messages from - private string m_message; // The message - - public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message) + /// + /// Listener is active or not + /// + private bool m_active; + + /// + /// Assigned handle of this listener + /// + private int m_handle; + + /// + /// Local ID from script engine + /// + private uint m_localID; + + /// + /// ID of the host script engine + /// + private UUID m_itemID; + + /// + /// ID of the host/scene part + /// + private UUID m_hostID; + + /// + /// Channel + /// + private int m_channel; + + /// + /// ID to filter messages from + /// + private UUID m_id; + + /// + /// Object name to filter messages from + /// + private string m_name; + + /// + /// The message + /// + private string m_message; + + public ListenerInfo(int handle, uint localID, UUID ItemID, + UUID hostID, int channel, string name, UUID id, + string message) { Initialise(handle, localID, ItemID, hostID, channel, name, id, message, 0); -- cgit v1.1