diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs index 69ad3cd9af..7e6e6f470c 100644 --- a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs @@ -48,7 +48,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat private int m_saydistance = 20; private int m_shoutdistance = 100; private int m_whisperdistance = 10; - private List m_scenes = new List(); internal object m_syncy = new object(); @@ -80,18 +79,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat public virtual void AddRegion(Scene scene) { - if (!m_enabled) return; + if (!m_enabled) + return; - lock (m_syncy) - { - if (!m_scenes.Contains(scene)) - { - m_scenes.Add(scene); - scene.EventManager.OnNewClient += OnNewClient; - scene.EventManager.OnChatFromWorld += OnChatFromWorld; - scene.EventManager.OnChatBroadcast += OnChatBroadcast; - } - } + scene.EventManager.OnNewClient += OnNewClient; + scene.EventManager.OnChatFromWorld += OnChatFromWorld; + scene.EventManager.OnChatBroadcast += OnChatBroadcast; m_log.InfoFormat("[CHAT]: Initialized for {0} w:{1} s:{2} S:{3}", scene.RegionInfo.RegionName, m_whisperdistance, m_saydistance, m_shoutdistance); @@ -103,18 +96,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat public virtual void RemoveRegion(Scene scene) { - if (!m_enabled) return; + 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); - } - } + scene.EventManager.OnNewClient -= OnNewClient; + scene.EventManager.OnChatFromWorld -= OnChatFromWorld; + scene.EventManager.OnChatBroadcast -= OnChatBroadcast; } public virtual void Close() @@ -189,7 +176,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat UUID ownerID = UUID.Zero; UUID targetID = c.TargetUUID; string message = c.Message; - IScene scene = c.Scene; + Scene scene = (Scene)c.Scene; Vector3 fromPos = c.Position; Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); @@ -199,13 +186,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat switch (sourceType) { case ChatSourceType.Agent: - if (!(scene is Scene)) - { - m_log.WarnFormat("[CHAT]: scene {0} is not a Scene object, cannot obtain scene presence for {1}", - scene.RegionInfo.RegionName, c.Sender.AgentId); - return; - } - ScenePresence avatar = (scene as Scene).GetScenePresence(c.Sender.AgentId); + ScenePresence avatar = scene.GetScenePresence(c.Sender.AgentId); fromPos = avatar.AbsolutePosition; fromName = avatar.Name; fromID = c.Sender.AgentId; @@ -232,36 +213,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat HashSet receiverIDs = new HashSet(); - foreach (Scene s in m_scenes) + if (targetID == UUID.Zero) { - if (targetID == UUID.Zero) - { - // This should use ForEachClient, but clients don't have a position. - // If camera is moved into client, then camera position can be used - s.ForEachScenePresence( - delegate(ScenePresence presence) - { - if (TrySendChatMessage( - presence, fromPos, regionPos, fromID, ownerID, fromName, c.Type, message, sourceType, false)) - receiverIDs.Add(presence.UUID); - } - ); - } - else - { - // This is a send to a specific client eg from llRegionSayTo - // no need to check distance etc, jand send is as say - ScenePresence presence = s.GetScenePresence(targetID); - if (presence != null && !presence.IsChildAgent) + // This should use ForEachClient, but clients don't have a position. + // If camera is moved into client, then camera position can be used + scene.ForEachScenePresence( + delegate(ScenePresence presence) { if (TrySendChatMessage( - presence, fromPos, regionPos, fromID, ownerID, fromName, ChatTypeEnum.Say, message, sourceType, true)) + presence, fromPos, regionPos, fromID, ownerID, fromName, c.Type, message, sourceType, false)) receiverIDs.Add(presence.UUID); } + ); + } + else + { + // This is a send to a specific client eg from llRegionSayTo + // no need to check distance etc, jand send is as say + ScenePresence presence = scene.GetScenePresence(targetID); + if (presence != null && !presence.IsChildAgent) + { + if (TrySendChatMessage( + presence, fromPos, regionPos, fromID, ownerID, fromName, ChatTypeEnum.Say, message, sourceType, true)) + receiverIDs.Add(presence.UUID); } } - (scene as Scene).EventManager.TriggerOnChatToClients( + scene.EventManager.TriggerOnChatToClients( fromID, receiverIDs, message, c.Type, fromPos, fromName, sourceType, ChatAudibleLevel.Fully); } @@ -346,9 +324,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat UUID fromAgentID, UUID ownerID, string fromName, ChatTypeEnum type, string message, ChatSourceType src, bool ignoreDistance) { - // don't send stuff to child agents - if (presence.IsChildAgent) return false; - Vector3 fromRegionPos = fromPos + regionPos; Vector3 toRegionPos = presence.AbsolutePosition + new Vector3(presence.Scene.RegionInfo.RegionLocX * Constants.RegionSize,