From 679da63da617d031e5e7ae3f2d2a29db1a23ace3 Mon Sep 17 00:00:00 2001 From: Talun Date: Sun, 22 Apr 2012 23:07:50 +0100 Subject: Mantis 5977 Corrections to llRegionSayTo Signed-off-by: BlueWall --- .../Region/CoreModules/Avatar/Chat/ChatModule.cs | 52 ++++++++++------ .../Scripting/WorldComm/WorldCommModule.cs | 70 +++++++++++----------- 2 files changed, 70 insertions(+), 52 deletions(-) (limited to 'OpenSim/Region/CoreModules') diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs index 10b4c37..e4452fb 100644 --- a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs @@ -186,6 +186,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat { string fromName = c.From; UUID fromID = UUID.Zero; + UUID targetID = c.TargetUUID; string message = c.Message; IScene scene = c.Scene; Vector3 fromPos = c.Position; @@ -221,24 +222,38 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat message = message.Substring(0, 1000); // m_log.DebugFormat( -// "[CHAT]: DCTA: fromID {0} fromName {1}, region{2}, cType {3}, sType {4}", -// fromID, fromName, scene.RegionInfo.RegionName, c.Type, sourceType); +// "[CHAT]: DCTA: fromID {0} fromName {1}, region{2}, cType {3}, sType {4}, targetID {5}", +// fromID, fromName, scene.RegionInfo.RegionName, c.Type, sourceType, targetID); HashSet receiverIDs = new HashSet(); - + foreach (Scene s in m_scenes) { - // This should use ForEachClient, but clients don't have a position. - // If camera is moved into client, then camera position can be used - s.ForEachRootScenePresence( - delegate(ScenePresence presence) + 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.ForEachRootScenePresence( + delegate(ScenePresence presence) + { + if (TrySendChatMessage(presence, fromPos, regionPos, fromID, 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) { - if (TrySendChatMessage(presence, fromPos, regionPos, fromID, fromName, c.Type, message, sourceType)) - receiverIDs.Add(presence.UUID); + if (TrySendChatMessage(presence, fromPos, regionPos, fromID, fromName, ChatTypeEnum.Say, message, sourceType, true)) + receiverIDs.Add(presence.UUID); } - ); + } } - + (scene as Scene).EventManager.TriggerOnChatToClients( fromID, receiverIDs, message, c.Type, fromPos, fromName, sourceType, ChatAudibleLevel.Fully); } @@ -315,7 +330,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat /// precondition protected virtual bool TrySendChatMessage(ScenePresence presence, Vector3 fromPos, Vector3 regionPos, UUID fromAgentID, string fromName, ChatTypeEnum type, - string message, ChatSourceType src) + string message, ChatSourceType src, bool ignoreDistance) { // don't send stuff to child agents if (presence.IsChildAgent) return false; @@ -326,12 +341,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat presence.Scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); int dis = (int)Util.GetDistanceTo(toRegionPos, fromRegionPos); - - if (type == ChatTypeEnum.Whisper && dis > m_whisperdistance || - type == ChatTypeEnum.Say && dis > m_saydistance || - type == ChatTypeEnum.Shout && dis > m_shoutdistance) + + if (!ignoreDistance) { - return false; + if (type == ChatTypeEnum.Whisper && dis > m_whisperdistance || + type == ChatTypeEnum.Say && dis > m_saydistance || + type == ChatTypeEnum.Shout && dis > m_shoutdistance) + { + return false; + } } // TODO: should change so the message is sent through the avatar rather than direct to the ClientView diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs index 176c86d..8358bc0 100644 --- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs @@ -308,56 +308,56 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm /// /// Message. /// - public bool DeliverMessageTo(UUID target, int channel, Vector3 pos, string name, UUID id, string msg, out string error) + public void DeliverMessageTo(UUID target, int channel, Vector3 pos, string name, UUID id, string msg) { - error = null; // Is id an avatar? ScenePresence sp = m_scene.GetScenePresence(target); if (sp != null) { - // Send message to avatar + // ignore if a child agent this is restricted to inside one region + if (sp.IsChildAgent) + return; + + // Send message to the avatar. + // Channel zero only goes to the avatar + // non zero channel messages only go to the attachments if (channel == 0) { - m_scene.SimChatBroadcast(Utils.StringToBytes(msg), ChatTypeEnum.Broadcast, 0, pos, name, id, false); - } - - List attachments = sp.GetAttachments(); - - if (attachments.Count == 0) - return true; - - // Get uuid of attachments - List targets = new List(); - foreach (SceneObjectGroup sog in attachments) + m_scene.SimChatToAgent(target, Utils.StringToBytes(msg), pos, name, id, false); + } + else { - if (!sog.IsDeleted) - targets.Add(sog.UUID); - } + List attachments = sp.GetAttachments(); + if (attachments.Count == 0) + return; - // Need to check each attachment - foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg)) - { - if (li.GetHostID().Equals(id)) - continue; + // Get uuid of attachments + List targets = new List(); + foreach (SceneObjectGroup sog in attachments) + { + if (!sog.IsDeleted) + targets.Add(sog.UUID); + } - if (m_scene.GetSceneObjectPart(li.GetHostID()) == null) - continue; + // Need to check each attachment + foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg)) + { + if (li.GetHostID().Equals(id)) + continue; - if (targets.Contains(li.GetHostID())) - QueueMessage(new ListenerInfo(li, name, id, msg)); - } + if (m_scene.GetSceneObjectPart(li.GetHostID()) == null) + continue; - return true; - } + if (targets.Contains(li.GetHostID())) + QueueMessage(new ListenerInfo(li, name, id, msg)); + } + } - // Need to toss an error here - if (channel == 0) - { - error = "Cannot use llRegionSayTo to message objects on channel 0"; - return false; + return; } + // No avatar found so look for an object foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg)) { // Dont process if this message is from yourself! @@ -375,7 +375,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm } } - return true; + return; } protected void QueueMessage(ListenerInfo li) -- cgit v1.1