aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2010-10-21 22:04:31 +0100
committerJustin Clark-Casey (justincc)2010-10-22 01:01:56 +0100
commit62a09103552cc87083f9107324dc4d6e4256b3d3 (patch)
treeafb74106363941341160458afae0585449749ee3 /OpenSim
parentThis fixes a delay in llSetLinkPrimitiveParamsFast (diff)
downloadopensim-SC-62a09103552cc87083f9107324dc4d6e4256b3d3.zip
opensim-SC-62a09103552cc87083f9107324dc4d6e4256b3d3.tar.gz
opensim-SC-62a09103552cc87083f9107324dc4d6e4256b3d3.tar.bz2
opensim-SC-62a09103552cc87083f9107324dc4d6e4256b3d3.tar.xz
Allow region modules to know which agents actually receive chat
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs44
-rw-r--r--OpenSim/Region/Framework/Scenes/EventManager.cs35
2 files changed, 71 insertions, 8 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
index ef5efdd..d76ff47 100644
--- a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs
@@ -167,7 +167,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
167 // sanity check: 167 // sanity check:
168 if (c.Sender == null) 168 if (c.Sender == null)
169 { 169 {
170 m_log.ErrorFormat("[CHAT] OnChatFromClient from {0} has empty Sender field!", sender); 170 m_log.ErrorFormat("[CHAT]: OnChatFromClient from {0} has empty Sender field!", sender);
171 return; 171 return;
172 } 172 }
173 173
@@ -220,17 +220,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
220 if (message.Length >= 1000) // libomv limit 220 if (message.Length >= 1000) // libomv limit
221 message = message.Substring(0, 1000); 221 message = message.Substring(0, 1000);
222 222
223 // m_log.DebugFormat("[CHAT]: DCTA: fromID {0} fromName {1}, cType {2}, sType {3}", fromID, fromName, c.Type, sourceType); 223// m_log.DebugFormat(
224// "[CHAT]: DCTA: fromID {0} fromName {1}, region{2}, cType {3}, sType {4}",
225// fromID, fromName, scene.RegionInfo.RegionName, c.Type, sourceType);
224 226
227 HashSet<UUID> receiverIDs = new HashSet<UUID>();
228
225 foreach (Scene s in m_scenes) 229 foreach (Scene s in m_scenes)
226 { 230 {
227 s.ForEachScenePresence( 231 s.ForEachScenePresence(
228 delegate(ScenePresence presence) 232 delegate(ScenePresence presence)
229 { 233 {
230 TrySendChatMessage(presence, fromPos, regionPos, fromID, fromName, c.Type, message, sourceType); 234 if (TrySendChatMessage(presence, fromPos, regionPos, fromID, fromName, c.Type, message, sourceType))
235 receiverIDs.Add(presence.UUID);
231 } 236 }
232 ); 237 );
233 } 238 }
239
240 (scene as Scene).EventManager.TriggerOnChatToClients(
241 fromID, receiverIDs, message, c.Type, fromPos, fromName, sourceType, ChatAudibleLevel.Fully);
234 } 242 }
235 243
236 static private Vector3 CenterOfRegion = new Vector3(128, 128, 30); 244 static private Vector3 CenterOfRegion = new Vector3(128, 128, 30);
@@ -269,6 +277,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
269 277
270 // m_log.DebugFormat("[CHAT] Broadcast: fromID {0} fromName {1}, cType {2}, sType {3}", fromID, fromName, cType, sourceType); 278 // m_log.DebugFormat("[CHAT] Broadcast: fromID {0} fromName {1}, cType {2}, sType {3}", fromID, fromName, cType, sourceType);
271 279
280 HashSet<UUID> receiverIDs = new HashSet<UUID>();
281
272 ((Scene)c.Scene).ForEachScenePresence( 282 ((Scene)c.Scene).ForEachScenePresence(
273 delegate(ScenePresence presence) 283 delegate(ScenePresence presence)
274 { 284 {
@@ -286,16 +296,32 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
286 296
287 client.SendChatMessage(c.Message, (byte)cType, CenterOfRegion, fromName, fromID, 297 client.SendChatMessage(c.Message, (byte)cType, CenterOfRegion, fromName, fromID,
288 (byte)sourceType, (byte)ChatAudibleLevel.Fully); 298 (byte)sourceType, (byte)ChatAudibleLevel.Fully);
299 receiverIDs.Add(presence.UUID);
289 }); 300 });
301
302 (c.Scene as Scene).EventManager.TriggerOnChatToClients(
303 fromID, receiverIDs, c.Message, cType, CenterOfRegion, fromName, sourceType, ChatAudibleLevel.Fully);
290 } 304 }
291 305
292 306 /// <summary>
293 protected virtual void TrySendChatMessage(ScenePresence presence, Vector3 fromPos, Vector3 regionPos, 307 /// Try to send a message to the given presence
308 /// </summary>
309 /// <param name="presence">The receiver</param>
310 /// <param name="fromPos"></param>
311 /// <param name="regionPos">/param>
312 /// <param name="fromAgentID"></param>
313 /// <param name="fromName"></param>
314 /// <param name="type"></param>
315 /// <param name="message"></param>
316 /// <param name="src"></param>
317 /// <returns>true if the message was sent to the receiver, false if it was not sent due to failing a
318 /// precondition</returns>
319 protected virtual bool TrySendChatMessage(ScenePresence presence, Vector3 fromPos, Vector3 regionPos,
294 UUID fromAgentID, string fromName, ChatTypeEnum type, 320 UUID fromAgentID, string fromName, ChatTypeEnum type,
295 string message, ChatSourceType src) 321 string message, ChatSourceType src)
296 { 322 {
297 // don't send stuff to child agents 323 // don't send stuff to child agents
298 if (presence.IsChildAgent) return; 324 if (presence.IsChildAgent) return false;
299 325
300 Vector3 fromRegionPos = fromPos + regionPos; 326 Vector3 fromRegionPos = fromPos + regionPos;
301 Vector3 toRegionPos = presence.AbsolutePosition + 327 Vector3 toRegionPos = presence.AbsolutePosition +
@@ -308,12 +334,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
308 type == ChatTypeEnum.Say && dis > m_saydistance || 334 type == ChatTypeEnum.Say && dis > m_saydistance ||
309 type == ChatTypeEnum.Shout && dis > m_shoutdistance) 335 type == ChatTypeEnum.Shout && dis > m_shoutdistance)
310 { 336 {
311 return; 337 return false;
312 } 338 }
313 339
314 // TODO: should change so the message is sent through the avatar rather than direct to the ClientView 340 // TODO: should change so the message is sent through the avatar rather than direct to the ClientView
315 presence.ControllingClient.SendChatMessage(message, (byte) type, fromPos, fromName, 341 presence.ControllingClient.SendChatMessage(message, (byte) type, fromPos, fromName,
316 fromAgentID,(byte)src,(byte)ChatAudibleLevel.Fully); 342 fromAgentID, (byte)src, (byte)ChatAudibleLevel.Fully);
343
344 return true;
317 } 345 }
318 } 346 }
319} 347}
diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs
index 437b91a..4feb3fc 100644
--- a/OpenSim/Region/Framework/Scenes/EventManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EventManager.cs
@@ -293,6 +293,17 @@ namespace OpenSim.Region.Framework.Scenes
293 public event ChatFromClientEvent OnChatFromClient; 293 public event ChatFromClientEvent OnChatFromClient;
294 294
295 /// <summary> 295 /// <summary>
296 /// ChatToClientsEvent is triggered via ChatModule (or
297 /// substitutes thereof) when a chat message is actually sent to clients. Clients will only be sent a
298 /// received chat message if they satisfy various conditions (within audible range, etc.)
299 /// </summary>
300 public delegate void ChatToClientsEvent(
301 UUID senderID, HashSet<UUID> receiverIDs,
302 string message, ChatTypeEnum type, Vector3 fromPos, string fromName,
303 ChatSourceType src, ChatAudibleLevel level);
304 public event ChatToClientsEvent OnChatToClients;
305
306 /// <summary>
296 /// ChatBroadcastEvent is called via Scene when a broadcast chat message 307 /// ChatBroadcastEvent is called via Scene when a broadcast chat message
297 /// from world comes in 308 /// from world comes in
298 /// </summary> 309 /// </summary>
@@ -1603,6 +1614,30 @@ namespace OpenSim.Region.Framework.Scenes
1603 } 1614 }
1604 } 1615 }
1605 } 1616 }
1617
1618 public void TriggerOnChatToClients(
1619 UUID senderID, HashSet<UUID> receiverIDs,
1620 string message, ChatTypeEnum type, Vector3 fromPos, string fromName,
1621 ChatSourceType src, ChatAudibleLevel level)
1622 {
1623 ChatToClientsEvent handler = OnChatToClients;
1624 if (handler != null)
1625 {
1626 foreach (ChatToClientsEvent d in handler.GetInvocationList())
1627 {
1628 try
1629 {
1630 d(senderID, receiverIDs, message, type, fromPos, fromName, src, level);
1631 }
1632 catch (Exception e)
1633 {
1634 m_log.ErrorFormat(
1635 "[EVENT MANAGER]: Delegate for TriggerOnChatToClients failed - continuing. {0} {1}",
1636 e.Message, e.StackTrace);
1637 }
1638 }
1639 }
1640 }
1606 1641
1607 public void TriggerOnChatBroadcast(Object sender, OSChatMessage chat) 1642 public void TriggerOnChatBroadcast(Object sender, OSChatMessage chat)
1608 { 1643 {