diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs | 168 |
1 files changed, 90 insertions, 78 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs index 6d62ff0..f0b1e67 100644 --- a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs | |||
@@ -32,6 +32,7 @@ using log4net; | |||
32 | using Nini.Config; | 32 | using Nini.Config; |
33 | using Mono.Addins; | 33 | using Mono.Addins; |
34 | using OpenMetaverse; | 34 | using OpenMetaverse; |
35 | using OpenMetaverse.StructuredData; | ||
35 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
36 | using OpenSim.Region.Framework.Interfaces; | 37 | using OpenSim.Region.Framework.Interfaces; |
37 | using OpenSim.Region.Framework.Scenes; | 38 | using OpenSim.Region.Framework.Scenes; |
@@ -50,7 +51,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat | |||
50 | private int m_saydistance = 20; | 51 | private int m_saydistance = 20; |
51 | private int m_shoutdistance = 100; | 52 | private int m_shoutdistance = 100; |
52 | private int m_whisperdistance = 10; | 53 | private int m_whisperdistance = 10; |
53 | private List<Scene> m_scenes = new List<Scene>(); | ||
54 | 54 | ||
55 | internal object m_syncy = new object(); | 55 | internal object m_syncy = new object(); |
56 | 56 | ||
@@ -61,18 +61,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat | |||
61 | { | 61 | { |
62 | m_config = config.Configs["Chat"]; | 62 | m_config = config.Configs["Chat"]; |
63 | 63 | ||
64 | if (null == m_config) | 64 | if (m_config != null) |
65 | { | 65 | { |
66 | m_log.Info("[CHAT]: no config found, plugin disabled"); | 66 | if (!m_config.GetBoolean("enabled", true)) |
67 | m_enabled = false; | 67 | { |
68 | return; | 68 | m_log.Info("[CHAT]: plugin disabled by configuration"); |
69 | } | 69 | m_enabled = false; |
70 | 70 | return; | |
71 | if (!m_config.GetBoolean("enabled", true)) | 71 | } |
72 | { | ||
73 | m_log.Info("[CHAT]: plugin disabled by configuration"); | ||
74 | m_enabled = false; | ||
75 | return; | ||
76 | } | 72 | } |
77 | 73 | ||
78 | m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance", m_whisperdistance); | 74 | m_whisperdistance = config.Configs["Chat"].GetInt("whisper_distance", m_whisperdistance); |
@@ -82,18 +78,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat | |||
82 | 78 | ||
83 | public virtual void AddRegion(Scene scene) | 79 | public virtual void AddRegion(Scene scene) |
84 | { | 80 | { |
85 | if (!m_enabled) return; | 81 | if (!m_enabled) |
82 | return; | ||
86 | 83 | ||
87 | lock (m_syncy) | 84 | scene.EventManager.OnNewClient += OnNewClient; |
88 | { | 85 | scene.EventManager.OnChatFromWorld += OnChatFromWorld; |
89 | if (!m_scenes.Contains(scene)) | 86 | scene.EventManager.OnChatBroadcast += OnChatBroadcast; |
90 | { | ||
91 | m_scenes.Add(scene); | ||
92 | scene.EventManager.OnNewClient += OnNewClient; | ||
93 | scene.EventManager.OnChatFromWorld += OnChatFromWorld; | ||
94 | scene.EventManager.OnChatBroadcast += OnChatBroadcast; | ||
95 | } | ||
96 | } | ||
97 | 87 | ||
98 | m_log.InfoFormat("[CHAT]: Initialized for {0} w:{1} s:{2} S:{3}", scene.RegionInfo.RegionName, | 88 | m_log.InfoFormat("[CHAT]: Initialized for {0} w:{1} s:{2} S:{3}", scene.RegionInfo.RegionName, |
99 | m_whisperdistance, m_saydistance, m_shoutdistance); | 89 | m_whisperdistance, m_saydistance, m_shoutdistance); |
@@ -101,22 +91,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat | |||
101 | 91 | ||
102 | public virtual void RegionLoaded(Scene scene) | 92 | public virtual void RegionLoaded(Scene scene) |
103 | { | 93 | { |
94 | if (!m_enabled) | ||
95 | return; | ||
96 | |||
97 | ISimulatorFeaturesModule featuresModule = scene.RequestModuleInterface<ISimulatorFeaturesModule>(); | ||
98 | |||
99 | if (featuresModule != null) | ||
100 | featuresModule.OnSimulatorFeaturesRequest += OnSimulatorFeaturesRequest; | ||
101 | |||
104 | } | 102 | } |
105 | 103 | ||
106 | public virtual void RemoveRegion(Scene scene) | 104 | public virtual void RemoveRegion(Scene scene) |
107 | { | 105 | { |
108 | if (!m_enabled) return; | 106 | if (!m_enabled) |
107 | return; | ||
109 | 108 | ||
110 | lock (m_syncy) | 109 | scene.EventManager.OnNewClient -= OnNewClient; |
111 | { | 110 | scene.EventManager.OnChatFromWorld -= OnChatFromWorld; |
112 | if (m_scenes.Contains(scene)) | 111 | scene.EventManager.OnChatBroadcast -= OnChatBroadcast; |
113 | { | ||
114 | scene.EventManager.OnNewClient -= OnNewClient; | ||
115 | scene.EventManager.OnChatFromWorld -= OnChatFromWorld; | ||
116 | scene.EventManager.OnChatBroadcast -= OnChatBroadcast; | ||
117 | m_scenes.Remove(scene); | ||
118 | } | ||
119 | } | ||
120 | } | 112 | } |
121 | 113 | ||
122 | public virtual void Close() | 114 | public virtual void Close() |
@@ -191,23 +183,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat | |||
191 | UUID ownerID = UUID.Zero; | 183 | UUID ownerID = UUID.Zero; |
192 | UUID targetID = c.TargetUUID; | 184 | UUID targetID = c.TargetUUID; |
193 | string message = c.Message; | 185 | string message = c.Message; |
194 | IScene scene = c.Scene; | 186 | Scene scene = (Scene)c.Scene; |
195 | Vector3 fromPos = c.Position; | 187 | Vector3 fromPos = c.Position; |
196 | Vector3 regionPos = new Vector3(scene.RegionInfo.RegionLocX * Constants.RegionSize, | 188 | Vector3 regionPos = new Vector3(scene.RegionInfo.WorldLocX, scene.RegionInfo.WorldLocY, 0); |
197 | scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); | ||
198 | 189 | ||
199 | if (c.Channel == DEBUG_CHANNEL) c.Type = ChatTypeEnum.DebugChannel; | 190 | if (c.Channel == DEBUG_CHANNEL) c.Type = ChatTypeEnum.DebugChannel; |
200 | 191 | ||
201 | switch (sourceType) | 192 | switch (sourceType) |
202 | { | 193 | { |
203 | case ChatSourceType.Agent: | 194 | case ChatSourceType.Agent: |
204 | if (!(scene is Scene)) | 195 | ScenePresence avatar = scene.GetScenePresence(c.Sender.AgentId); |
205 | { | ||
206 | m_log.WarnFormat("[CHAT]: scene {0} is not a Scene object, cannot obtain scene presence for {1}", | ||
207 | scene.RegionInfo.RegionName, c.Sender.AgentId); | ||
208 | return; | ||
209 | } | ||
210 | ScenePresence avatar = (scene as Scene).GetScenePresence(c.Sender.AgentId); | ||
211 | fromPos = avatar.AbsolutePosition; | 196 | fromPos = avatar.AbsolutePosition; |
212 | fromName = avatar.Name; | 197 | fromName = avatar.Name; |
213 | fromID = c.Sender.AgentId; | 198 | fromID = c.Sender.AgentId; |
@@ -234,36 +219,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat | |||
234 | 219 | ||
235 | HashSet<UUID> receiverIDs = new HashSet<UUID>(); | 220 | HashSet<UUID> receiverIDs = new HashSet<UUID>(); |
236 | 221 | ||
237 | foreach (Scene s in m_scenes) | 222 | if (targetID == UUID.Zero) |
238 | { | 223 | { |
239 | if (targetID == UUID.Zero) | 224 | // This should use ForEachClient, but clients don't have a position. |
240 | { | 225 | // If camera is moved into client, then camera position can be used |
241 | // This should use ForEachClient, but clients don't have a position. | 226 | scene.ForEachScenePresence( |
242 | // If camera is moved into client, then camera position can be used | 227 | delegate(ScenePresence presence) |
243 | s.ForEachRootScenePresence( | ||
244 | delegate(ScenePresence presence) | ||
245 | { | ||
246 | if (TrySendChatMessage( | ||
247 | presence, fromPos, regionPos, fromID, ownerID, fromName, c.Type, message, sourceType, false)) | ||
248 | receiverIDs.Add(presence.UUID); | ||
249 | } | ||
250 | ); | ||
251 | } | ||
252 | else | ||
253 | { | ||
254 | // This is a send to a specific client eg from llRegionSayTo | ||
255 | // no need to check distance etc, jand send is as say | ||
256 | ScenePresence presence = s.GetScenePresence(targetID); | ||
257 | if (presence != null && !presence.IsChildAgent) | ||
258 | { | 228 | { |
259 | if (TrySendChatMessage( | 229 | if (TrySendChatMessage( |
260 | presence, fromPos, regionPos, fromID, ownerID, fromName, ChatTypeEnum.Say, message, sourceType, true)) | 230 | presence, fromPos, regionPos, fromID, ownerID, fromName, c.Type, message, sourceType, false)) |
261 | receiverIDs.Add(presence.UUID); | 231 | receiverIDs.Add(presence.UUID); |
262 | } | 232 | } |
233 | ); | ||
234 | } | ||
235 | else | ||
236 | { | ||
237 | // This is a send to a specific client eg from llRegionSayTo | ||
238 | // no need to check distance etc, jand send is as say | ||
239 | ScenePresence presence = scene.GetScenePresence(targetID); | ||
240 | if (presence != null && !presence.IsChildAgent) | ||
241 | { | ||
242 | if (TrySendChatMessage( | ||
243 | presence, fromPos, regionPos, fromID, ownerID, fromName, ChatTypeEnum.Say, message, sourceType, true)) | ||
244 | receiverIDs.Add(presence.UUID); | ||
263 | } | 245 | } |
264 | } | 246 | } |
265 | 247 | ||
266 | (scene as Scene).EventManager.TriggerOnChatToClients( | 248 | scene.EventManager.TriggerOnChatToClients( |
267 | fromID, receiverIDs, message, c.Type, fromPos, fromName, sourceType, ChatAudibleLevel.Fully); | 249 | fromID, receiverIDs, message, c.Type, fromPos, fromName, sourceType, ChatAudibleLevel.Fully); |
268 | } | 250 | } |
269 | 251 | ||
@@ -288,17 +270,20 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat | |||
288 | string fromName = c.From; | 270 | string fromName = c.From; |
289 | 271 | ||
290 | UUID fromID = UUID.Zero; | 272 | UUID fromID = UUID.Zero; |
273 | UUID ownerID = UUID.Zero; | ||
291 | ChatSourceType sourceType = ChatSourceType.Object; | 274 | ChatSourceType sourceType = ChatSourceType.Object; |
292 | if (null != c.Sender) | 275 | if (null != c.Sender) |
293 | { | 276 | { |
294 | ScenePresence avatar = (c.Scene as Scene).GetScenePresence(c.Sender.AgentId); | 277 | ScenePresence avatar = (c.Scene as Scene).GetScenePresence(c.Sender.AgentId); |
295 | fromID = c.Sender.AgentId; | 278 | fromID = c.Sender.AgentId; |
296 | fromName = avatar.Name; | 279 | fromName = avatar.Name; |
280 | ownerID = c.Sender.AgentId; | ||
297 | sourceType = ChatSourceType.Agent; | 281 | sourceType = ChatSourceType.Agent; |
298 | } | 282 | } |
299 | else if (c.SenderUUID != UUID.Zero) | 283 | else if (c.SenderUUID != UUID.Zero) |
300 | { | 284 | { |
301 | fromID = c.SenderUUID; | 285 | fromID = c.SenderUUID; |
286 | ownerID = ((SceneObjectPart)c.SenderObject).OwnerID; | ||
302 | } | 287 | } |
303 | 288 | ||
304 | // m_log.DebugFormat("[CHAT] Broadcast: fromID {0} fromName {1}, cType {2}, sType {3}", fromID, fromName, cType, sourceType); | 289 | // m_log.DebugFormat("[CHAT] Broadcast: fromID {0} fromName {1}, cType {2}, sType {3}", fromID, fromName, cType, sourceType); |
@@ -316,7 +301,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat | |||
316 | return; | 301 | return; |
317 | 302 | ||
318 | client.SendChatMessage( | 303 | client.SendChatMessage( |
319 | c.Message, (byte)cType, CenterOfRegion, fromName, fromID, fromID, | 304 | c.Message, (byte)cType, CenterOfRegion, fromName, fromID, ownerID, |
320 | (byte)sourceType, (byte)ChatAudibleLevel.Fully); | 305 | (byte)sourceType, (byte)ChatAudibleLevel.Fully); |
321 | 306 | ||
322 | receiverIDs.Add(client.AgentId); | 307 | receiverIDs.Add(client.AgentId); |
@@ -348,18 +333,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat | |||
348 | UUID fromAgentID, UUID ownerID, string fromName, ChatTypeEnum type, | 333 | UUID fromAgentID, UUID ownerID, string fromName, ChatTypeEnum type, |
349 | string message, ChatSourceType src, bool ignoreDistance) | 334 | string message, ChatSourceType src, bool ignoreDistance) |
350 | { | 335 | { |
351 | // don't send stuff to child agents | 336 | if (presence.LifecycleState != ScenePresenceState.Running) |
352 | if (presence.IsChildAgent) return false; | 337 | return false; |
353 | |||
354 | Vector3 fromRegionPos = fromPos + regionPos; | ||
355 | Vector3 toRegionPos = presence.AbsolutePosition + | ||
356 | new Vector3(presence.Scene.RegionInfo.RegionLocX * Constants.RegionSize, | ||
357 | presence.Scene.RegionInfo.RegionLocY * Constants.RegionSize, 0); | ||
358 | |||
359 | int dis = (int)Util.GetDistanceTo(toRegionPos, fromRegionPos); | ||
360 | 338 | ||
361 | if (!ignoreDistance) | 339 | if (!ignoreDistance) |
362 | { | 340 | { |
341 | Vector3 fromRegionPos = fromPos + regionPos; | ||
342 | Vector3 toRegionPos = presence.AbsolutePosition + | ||
343 | new Vector3(presence.Scene.RegionInfo.WorldLocX, presence.Scene.RegionInfo.WorldLocY, 0); | ||
344 | |||
345 | int dis = (int)Util.GetDistanceTo(toRegionPos, fromRegionPos); | ||
346 | |||
363 | if (type == ChatTypeEnum.Whisper && dis > m_whisperdistance || | 347 | if (type == ChatTypeEnum.Whisper && dis > m_whisperdistance || |
364 | type == ChatTypeEnum.Say && dis > m_saydistance || | 348 | type == ChatTypeEnum.Say && dis > m_saydistance || |
365 | type == ChatTypeEnum.Shout && dis > m_shoutdistance) | 349 | type == ChatTypeEnum.Shout && dis > m_shoutdistance) |
@@ -375,5 +359,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat | |||
375 | 359 | ||
376 | return true; | 360 | return true; |
377 | } | 361 | } |
362 | |||
363 | #region SimulatorFeaturesRequest | ||
364 | |||
365 | static OSDInteger m_SayRange, m_WhisperRange, m_ShoutRange; | ||
366 | |||
367 | private void OnSimulatorFeaturesRequest(UUID agentID, ref OSDMap features) | ||
368 | { | ||
369 | OSD extras = new OSDMap(); | ||
370 | if (features.ContainsKey("OpenSimExtras")) | ||
371 | extras = features["OpenSimExtras"]; | ||
372 | else | ||
373 | features["OpenSimExtras"] = extras; | ||
374 | |||
375 | if (m_SayRange == null) | ||
376 | { | ||
377 | // Do this only once | ||
378 | m_SayRange = new OSDInteger(m_saydistance); | ||
379 | m_WhisperRange = new OSDInteger(m_whisperdistance); | ||
380 | m_ShoutRange = new OSDInteger(m_shoutdistance); | ||
381 | } | ||
382 | |||
383 | ((OSDMap)extras)["say-range"] = m_SayRange; | ||
384 | ((OSDMap)extras)["whisper-range"] = m_WhisperRange; | ||
385 | ((OSDMap)extras)["shout-range"] = m_ShoutRange; | ||
386 | |||
387 | } | ||
388 | |||
389 | #endregion | ||
378 | } | 390 | } |
379 | } \ No newline at end of file | 391 | } |