diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/WorldCommModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/WorldCommModule.cs | 146 |
1 files changed, 66 insertions, 80 deletions
diff --git a/OpenSim/Region/Environment/Modules/WorldCommModule.cs b/OpenSim/Region/Environment/Modules/WorldCommModule.cs index a697162..7a631d7 100644 --- a/OpenSim/Region/Environment/Modules/WorldCommModule.cs +++ b/OpenSim/Region/Environment/Modules/WorldCommModule.cs | |||
@@ -27,20 +27,12 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.IO; | 30 | using System.Collections.Generic; |
31 | using System.Net.Sockets; | ||
32 | using System.Text; | ||
33 | using System.Threading; | ||
34 | using libsecondlife; | 31 | using libsecondlife; |
35 | using OpenSim.Framework.Interfaces; | 32 | using Nini.Config; |
36 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
37 | using OpenSim.Region.Environment.Interfaces; | 34 | using OpenSim.Region.Environment.Interfaces; |
38 | using OpenSim.Region.Environment.Scenes; | 35 | using OpenSim.Region.Environment.Scenes; |
39 | using OpenSim.Framework.Servers; | ||
40 | using Nwc.XmlRpc; | ||
41 | using System.Collections; | ||
42 | using System.Collections.Generic; | ||
43 | using Nini.Config; | ||
44 | 36 | ||
45 | /***************************************************** | 37 | /***************************************************** |
46 | * | 38 | * |
@@ -71,6 +63,7 @@ using Nini.Config; | |||
71 | * thats the way it works. | 63 | * thats the way it works. |
72 | * | 64 | * |
73 | * **************************************************/ | 65 | * **************************************************/ |
66 | |||
74 | namespace OpenSim.Region.Environment.Modules | 67 | namespace OpenSim.Region.Environment.Modules |
75 | { | 68 | { |
76 | public class WorldCommModule : IRegionModule, IWorldComm | 69 | public class WorldCommModule : IRegionModule, IWorldComm |
@@ -120,9 +113,9 @@ namespace OpenSim.Region.Environment.Modules | |||
120 | private void DeliverClientMessage(Object sender, ChatFromViewerArgs e) | 113 | private void DeliverClientMessage(Object sender, ChatFromViewerArgs e) |
121 | { | 114 | { |
122 | DeliverMessage(e.Sender.AgentId.ToString(), | 115 | DeliverMessage(e.Sender.AgentId.ToString(), |
123 | (int)e.Type, e.Channel, | 116 | (int) e.Type, e.Channel, |
124 | e.Sender.FirstName + " " + e.Sender.LastName, | 117 | e.Sender.FirstName + " " + e.Sender.LastName, |
125 | e.Message); | 118 | e.Message); |
126 | } | 119 | } |
127 | 120 | ||
128 | public int Listen(uint localID, LLUUID itemID, LLUUID hostID, int channel, string name, string id, string msg) | 121 | public int Listen(uint localID, LLUUID itemID, LLUUID hostID, int channel, string name, string id, string msg) |
@@ -132,11 +125,10 @@ namespace OpenSim.Region.Environment.Modules | |||
132 | 125 | ||
133 | public void ListenControl(int handle, int active) | 126 | public void ListenControl(int handle, int active) |
134 | { | 127 | { |
135 | if ( active == 1 ) | 128 | if (active == 1) |
136 | m_listenerManager.Activate(handle); | 129 | m_listenerManager.Activate(handle); |
137 | else if ( active == 0 ) | 130 | else if (active == 0) |
138 | m_listenerManager.Dectivate(handle); | 131 | m_listenerManager.Dectivate(handle); |
139 | |||
140 | } | 132 | } |
141 | 133 | ||
142 | public void ListenRemove(int handle) | 134 | public void ListenRemove(int handle) |
@@ -151,7 +143,6 @@ namespace OpenSim.Region.Environment.Modules | |||
151 | // nearby avatards, the SimChat function is used. | 143 | // nearby avatards, the SimChat function is used. |
152 | public void DeliverMessage(string sourceItemID, int type, int channel, string name, string msg) | 144 | public void DeliverMessage(string sourceItemID, int type, int channel, string name, string msg) |
153 | { | 145 | { |
154 | |||
155 | SceneObjectPart source = null; | 146 | SceneObjectPart source = null; |
156 | ScenePresence avatar = null; | 147 | ScenePresence avatar = null; |
157 | 148 | ||
@@ -160,7 +151,7 @@ namespace OpenSim.Region.Environment.Modules | |||
160 | { | 151 | { |
161 | avatar = m_scene.GetScenePresence(new LLUUID(sourceItemID)); | 152 | avatar = m_scene.GetScenePresence(new LLUUID(sourceItemID)); |
162 | } | 153 | } |
163 | if( (avatar != null) || (source != null) ) | 154 | if ((avatar != null) || (source != null)) |
164 | { | 155 | { |
165 | // Loop through the objects in the scene | 156 | // Loop through the objects in the scene |
166 | // If they are in proximity, then if they are | 157 | // If they are in proximity, then if they are |
@@ -169,12 +160,12 @@ namespace OpenSim.Region.Environment.Modules | |||
169 | foreach (LLUUID eb in m_scene.Entities.Keys) | 160 | foreach (LLUUID eb in m_scene.Entities.Keys) |
170 | { | 161 | { |
171 | EntityBase sPart; | 162 | EntityBase sPart; |
172 | 163 | ||
173 | m_scene.Entities.TryGetValue(eb, out sPart); | 164 | m_scene.Entities.TryGetValue(eb, out sPart); |
174 | 165 | ||
175 | // Dont process if this message is from itself! | 166 | // Dont process if this message is from itself! |
176 | if (eb.ToString().Equals(sourceItemID) || | 167 | if (eb.ToString().Equals(sourceItemID) || |
177 | sPart.UUID.ToString().Equals(sourceItemID) ) | 168 | sPart.UUID.ToString().Equals(sourceItemID)) |
178 | continue; | 169 | continue; |
179 | 170 | ||
180 | double dis = 0; | 171 | double dis = 0; |
@@ -192,12 +183,11 @@ namespace OpenSim.Region.Environment.Modules | |||
192 | { | 183 | { |
193 | ListenerInfo isListener = m_listenerManager.IsListenerMatch( | 184 | ListenerInfo isListener = m_listenerManager.IsListenerMatch( |
194 | sourceItemID, sPart.UUID, channel, name, msg | 185 | sourceItemID, sPart.UUID, channel, name, msg |
195 | ); | 186 | ); |
196 | if (isListener != null) | 187 | if (isListener != null) |
197 | { | 188 | { |
198 | m_pending.Enqueue(isListener); | 189 | m_pending.Enqueue(isListener); |
199 | } | 190 | } |
200 | |||
201 | } | 191 | } |
202 | break; | 192 | break; |
203 | 193 | ||
@@ -207,12 +197,11 @@ namespace OpenSim.Region.Environment.Modules | |||
207 | { | 197 | { |
208 | ListenerInfo isListener = m_listenerManager.IsListenerMatch( | 198 | ListenerInfo isListener = m_listenerManager.IsListenerMatch( |
209 | sourceItemID, sPart.UUID, channel, name, msg | 199 | sourceItemID, sPart.UUID, channel, name, msg |
210 | ); | 200 | ); |
211 | if (isListener != null) | 201 | if (isListener != null) |
212 | { | 202 | { |
213 | m_pending.Enqueue(isListener); | 203 | m_pending.Enqueue(isListener); |
214 | } | 204 | } |
215 | |||
216 | } | 205 | } |
217 | break; | 206 | break; |
218 | 207 | ||
@@ -221,22 +210,22 @@ namespace OpenSim.Region.Environment.Modules | |||
221 | { | 210 | { |
222 | ListenerInfo isListener = m_listenerManager.IsListenerMatch( | 211 | ListenerInfo isListener = m_listenerManager.IsListenerMatch( |
223 | sourceItemID, sPart.UUID, channel, name, msg | 212 | sourceItemID, sPart.UUID, channel, name, msg |
224 | ); | 213 | ); |
225 | if (isListener != null) | 214 | if (isListener != null) |
226 | { | 215 | { |
227 | m_pending.Enqueue(isListener); | 216 | m_pending.Enqueue(isListener); |
228 | } | 217 | } |
229 | |||
230 | } | 218 | } |
231 | break; | 219 | break; |
232 | 220 | ||
233 | case 0xff: // Broadcast | 221 | case 0xff: // Broadcast |
234 | ListenerInfo isListen = m_listenerManager.IsListenerMatch(sourceItemID, eb, channel, name, msg); | 222 | ListenerInfo isListen = |
223 | m_listenerManager.IsListenerMatch(sourceItemID, eb, channel, name, msg); | ||
235 | if (isListen != null) | 224 | if (isListen != null) |
236 | { | 225 | { |
237 | ListenerInfo isListener = m_listenerManager.IsListenerMatch( | 226 | ListenerInfo isListener = m_listenerManager.IsListenerMatch( |
238 | sourceItemID, sPart.UUID, channel, name, msg | 227 | sourceItemID, sPart.UUID, channel, name, msg |
239 | ); | 228 | ); |
240 | if (isListener != null) | 229 | if (isListener != null) |
241 | { | 230 | { |
242 | m_pending.Enqueue(isListener); | 231 | m_pending.Enqueue(isListener); |
@@ -244,10 +233,9 @@ namespace OpenSim.Region.Environment.Modules | |||
244 | } | 233 | } |
245 | break; | 234 | break; |
246 | } | 235 | } |
247 | }; | 236 | } |
248 | 237 | ; | |
249 | } | 238 | } |
250 | |||
251 | } | 239 | } |
252 | 240 | ||
253 | public bool HasMessages() | 241 | public bool HasMessages() |
@@ -257,18 +245,15 @@ namespace OpenSim.Region.Environment.Modules | |||
257 | 245 | ||
258 | public ListenerInfo GetNextMessage() | 246 | public ListenerInfo GetNextMessage() |
259 | { | 247 | { |
260 | |||
261 | ListenerInfo li = null; | 248 | ListenerInfo li = null; |
262 | 249 | ||
263 | lock (CommListLock) | 250 | lock (CommListLock) |
264 | { | 251 | { |
265 | li = m_pending.Dequeue(); | 252 | li = m_pending.Dequeue(); |
266 | } | 253 | } |
267 | 254 | ||
268 | return li; | 255 | return li; |
269 | |||
270 | } | 256 | } |
271 | |||
272 | } | 257 | } |
273 | 258 | ||
274 | // hostID: the ID of the ScenePart | 259 | // hostID: the ID of the ScenePart |
@@ -285,20 +270,19 @@ namespace OpenSim.Region.Environment.Modules | |||
285 | m_listeners = new Dictionary<int, ListenerInfo>(); | 270 | m_listeners = new Dictionary<int, ListenerInfo>(); |
286 | } | 271 | } |
287 | 272 | ||
288 | public int AddListener(uint localID, LLUUID itemID, LLUUID hostID, int channel, string name, string id, string msg) | 273 | public int AddListener(uint localID, LLUUID itemID, LLUUID hostID, int channel, string name, string id, |
274 | string msg) | ||
289 | { | 275 | { |
290 | 276 | if (m_listeners.Count < m_MaxListeners) | |
291 | if ( m_listeners.Count < m_MaxListeners ) | ||
292 | { | 277 | { |
293 | ListenerInfo isListener = IsListenerMatch(LLUUID.Zero.ToString(), itemID, channel, name, msg); | 278 | ListenerInfo isListener = IsListenerMatch(LLUUID.Zero.ToString(), itemID, channel, name, msg); |
294 | 279 | ||
295 | if(isListener == null) | 280 | if (isListener == null) |
296 | { | 281 | { |
297 | int newHandle = GetNewHandle(); | 282 | int newHandle = GetNewHandle(); |
298 | 283 | ||
299 | if (newHandle > -1) | 284 | if (newHandle > -1) |
300 | { | 285 | { |
301 | |||
302 | ListenerInfo li = new ListenerInfo(localID, newHandle, itemID, hostID, channel, name, id, msg); | 286 | ListenerInfo li = new ListenerInfo(localID, newHandle, itemID, hostID, channel, name, id, msg); |
303 | 287 | ||
304 | lock (ListenersLock) | 288 | lock (ListenersLock) |
@@ -308,13 +292,10 @@ namespace OpenSim.Region.Environment.Modules | |||
308 | 292 | ||
309 | return newHandle; | 293 | return newHandle; |
310 | } | 294 | } |
311 | |||
312 | } | 295 | } |
313 | |||
314 | } | 296 | } |
315 | 297 | ||
316 | return -1; | 298 | return -1; |
317 | |||
318 | } | 299 | } |
319 | 300 | ||
320 | public void Remove(int handle) | 301 | public void Remove(int handle) |
@@ -324,7 +305,6 @@ namespace OpenSim.Region.Environment.Modules | |||
324 | 305 | ||
325 | private int GetNewHandle() | 306 | private int GetNewHandle() |
326 | { | 307 | { |
327 | |||
328 | for (int i = 0; i < int.MaxValue - 1; i++) | 308 | for (int i = 0; i < int.MaxValue - 1; i++) |
329 | { | 309 | { |
330 | if (!m_listeners.ContainsKey(i)) | 310 | if (!m_listeners.ContainsKey(i)) |
@@ -332,12 +312,10 @@ namespace OpenSim.Region.Environment.Modules | |||
332 | } | 312 | } |
333 | 313 | ||
334 | return -1; | 314 | return -1; |
335 | |||
336 | } | 315 | } |
337 | 316 | ||
338 | public bool IsListener(LLUUID hostID) | 317 | public bool IsListener(LLUUID hostID) |
339 | { | 318 | { |
340 | |||
341 | foreach (ListenerInfo li in m_listeners.Values) | 319 | foreach (ListenerInfo li in m_listeners.Values) |
342 | { | 320 | { |
343 | if (li.GetHostID().Equals(hostID)) | 321 | if (li.GetHostID().Equals(hostID)) |
@@ -345,15 +323,13 @@ namespace OpenSim.Region.Environment.Modules | |||
345 | } | 323 | } |
346 | 324 | ||
347 | return false; | 325 | return false; |
348 | |||
349 | } | 326 | } |
350 | 327 | ||
351 | public void Activate(int handle) | 328 | public void Activate(int handle) |
352 | { | 329 | { |
353 | |||
354 | ListenerInfo li; | 330 | ListenerInfo li; |
355 | 331 | ||
356 | if( m_listeners.TryGetValue(handle, out li) ) | 332 | if (m_listeners.TryGetValue(handle, out li)) |
357 | { | 333 | { |
358 | li.Activate(); | 334 | li.Activate(); |
359 | } | 335 | } |
@@ -361,10 +337,9 @@ namespace OpenSim.Region.Environment.Modules | |||
361 | 337 | ||
362 | public void Dectivate(int handle) | 338 | public void Dectivate(int handle) |
363 | { | 339 | { |
364 | |||
365 | ListenerInfo li; | 340 | ListenerInfo li; |
366 | 341 | ||
367 | if( m_listeners.TryGetValue(handle, out li) ) | 342 | if (m_listeners.TryGetValue(handle, out li)) |
368 | { | 343 | { |
369 | li.Deactivate(); | 344 | li.Deactivate(); |
370 | } | 345 | } |
@@ -372,40 +347,40 @@ namespace OpenSim.Region.Environment.Modules | |||
372 | 347 | ||
373 | // Theres probably a more clever and efficient way to | 348 | // Theres probably a more clever and efficient way to |
374 | // do this, maybe with regex. | 349 | // do this, maybe with regex. |
375 | public ListenerInfo IsListenerMatch(string sourceItemID, LLUUID listenerKey, int channel, string name, string msg) | 350 | public ListenerInfo IsListenerMatch(string sourceItemID, LLUUID listenerKey, int channel, string name, |
351 | string msg) | ||
376 | { | 352 | { |
377 | |||
378 | bool isMatch = true; | 353 | bool isMatch = true; |
379 | 354 | ||
380 | foreach (ListenerInfo li in m_listeners.Values) | 355 | foreach (ListenerInfo li in m_listeners.Values) |
381 | { | 356 | { |
382 | if (li.GetHostID().Equals(listenerKey)) | 357 | if (li.GetHostID().Equals(listenerKey)) |
383 | { | 358 | { |
384 | if ( li.IsActive() ) | 359 | if (li.IsActive()) |
385 | { | 360 | { |
386 | if ( channel == li.GetChannel() ) | 361 | if (channel == li.GetChannel()) |
387 | { | 362 | { |
388 | if ( (li.GetID().ToString().Length > 0) && | 363 | if ((li.GetID().ToString().Length > 0) && |
389 | (!li.GetID().Equals(LLUUID.Zero)) ) | 364 | (!li.GetID().Equals(LLUUID.Zero))) |
390 | { | 365 | { |
391 | if (!li.GetID().ToString().Equals(sourceItemID)) | 366 | if (!li.GetID().ToString().Equals(sourceItemID)) |
392 | { | 367 | { |
393 | isMatch = false; | 368 | isMatch = false; |
394 | } | 369 | } |
395 | } | 370 | } |
396 | if ( isMatch && (li.GetName().Length > 0) ) | 371 | if (isMatch && (li.GetName().Length > 0)) |
397 | { | 372 | { |
398 | if ( li.GetName().Equals(name) ) | 373 | if (li.GetName().Equals(name)) |
399 | { | 374 | { |
400 | isMatch = false; | 375 | isMatch = false; |
401 | } | 376 | } |
402 | } | 377 | } |
403 | if ( isMatch ) | 378 | if (isMatch) |
404 | { | 379 | { |
405 | return new ListenerInfo( | 380 | return new ListenerInfo( |
406 | li.GetLocalID(), li.GetHandle(), li.GetItemID(), li.GetHostID(), | 381 | li.GetLocalID(), li.GetHandle(), li.GetItemID(), li.GetHostID(), |
407 | li.GetChannel(), name, li.GetID(), msg, new LLUUID(sourceItemID) | 382 | li.GetChannel(), name, li.GetID(), msg, new LLUUID(sourceItemID) |
408 | ); | 383 | ); |
409 | } | 384 | } |
410 | } | 385 | } |
411 | } | 386 | } |
@@ -413,35 +388,36 @@ namespace OpenSim.Region.Environment.Modules | |||
413 | } | 388 | } |
414 | return null; | 389 | return null; |
415 | } | 390 | } |
416 | |||
417 | } | 391 | } |
418 | 392 | ||
419 | public class ListenerInfo | 393 | public class ListenerInfo |
420 | { | 394 | { |
421 | 395 | private LLUUID m_itemID; // ID of the host script engine | |
422 | private LLUUID m_itemID; // ID of the host script engine | 396 | private LLUUID m_hostID; // ID of the host/scene part |
423 | private LLUUID m_hostID; // ID of the host/scene part | 397 | private LLUUID m_sourceItemID; // ID of the scenePart or avatar source of the message |
424 | private LLUUID m_sourceItemID; // ID of the scenePart or avatar source of the message | 398 | private int m_channel; // Channel |
425 | private int m_channel; // Channel | 399 | private int m_handle; // Assigned handle of this listener |
426 | private int m_handle; // Assigned handle of this listener | 400 | private uint m_localID; // Local ID from script engine |
427 | private uint m_localID; // Local ID from script engine | 401 | private string m_name; // Object name to filter messages from |
428 | private string m_name; // Object name to filter messages from | 402 | private LLUUID m_id; // ID to filter messages from |
429 | private LLUUID m_id; // ID to filter messages from | 403 | private string m_message; // The message |
430 | private string m_message; // The message | 404 | private bool m_active; // Listener is active or not |
431 | private bool m_active; // Listener is active or not | 405 | |
432 | 406 | public ListenerInfo(uint localID, int handle, LLUUID ItemID, LLUUID hostID, int channel, string name, LLUUID id, | |
433 | public ListenerInfo(uint localID, int handle, LLUUID ItemID, LLUUID hostID, int channel, string name, LLUUID id, string message) | 407 | string message) |
434 | { | 408 | { |
435 | Initialise(localID, handle, ItemID, hostID, channel, name, id, message); | 409 | Initialise(localID, handle, ItemID, hostID, channel, name, id, message); |
436 | } | 410 | } |
437 | 411 | ||
438 | public ListenerInfo(uint localID, int handle, LLUUID ItemID, LLUUID hostID, int channel, string name, LLUUID id, string message, LLUUID sourceItemID) | 412 | public ListenerInfo(uint localID, int handle, LLUUID ItemID, LLUUID hostID, int channel, string name, LLUUID id, |
413 | string message, LLUUID sourceItemID) | ||
439 | { | 414 | { |
440 | Initialise(localID, handle, ItemID, hostID, channel, name, id, message); | 415 | Initialise(localID, handle, ItemID, hostID, channel, name, id, message); |
441 | m_sourceItemID = sourceItemID; | 416 | m_sourceItemID = sourceItemID; |
442 | } | 417 | } |
443 | 418 | ||
444 | private void Initialise(uint localID, int handle, LLUUID ItemID, LLUUID hostID, int channel, string name, LLUUID id, string message) | 419 | private void Initialise(uint localID, int handle, LLUUID ItemID, LLUUID hostID, int channel, string name, |
420 | LLUUID id, string message) | ||
445 | { | 421 | { |
446 | m_handle = handle; | 422 | m_handle = handle; |
447 | m_channel = channel; | 423 | m_channel = channel; |
@@ -453,55 +429,65 @@ namespace OpenSim.Region.Environment.Modules | |||
453 | m_active = true; | 429 | m_active = true; |
454 | m_localID = localID; | 430 | m_localID = localID; |
455 | } | 431 | } |
432 | |||
456 | public LLUUID GetItemID() | 433 | public LLUUID GetItemID() |
457 | { | 434 | { |
458 | return m_itemID; | 435 | return m_itemID; |
459 | } | 436 | } |
437 | |||
460 | public LLUUID GetHostID() | 438 | public LLUUID GetHostID() |
461 | { | 439 | { |
462 | return m_hostID; | 440 | return m_hostID; |
463 | } | 441 | } |
442 | |||
464 | public LLUUID GetSourceItemID() | 443 | public LLUUID GetSourceItemID() |
465 | { | 444 | { |
466 | return m_sourceItemID; | 445 | return m_sourceItemID; |
467 | } | 446 | } |
447 | |||
468 | public int GetChannel() | 448 | public int GetChannel() |
469 | { | 449 | { |
470 | return m_channel; | 450 | return m_channel; |
471 | } | 451 | } |
452 | |||
472 | public uint GetLocalID() | 453 | public uint GetLocalID() |
473 | { | 454 | { |
474 | return m_localID; | 455 | return m_localID; |
475 | } | 456 | } |
457 | |||
476 | public int GetHandle() | 458 | public int GetHandle() |
477 | { | 459 | { |
478 | return m_handle; | 460 | return m_handle; |
479 | } | 461 | } |
462 | |||
480 | public string GetMessage() | 463 | public string GetMessage() |
481 | { | 464 | { |
482 | return m_message; | 465 | return m_message; |
483 | } | 466 | } |
467 | |||
484 | public string GetName() | 468 | public string GetName() |
485 | { | 469 | { |
486 | return m_name; | 470 | return m_name; |
487 | } | 471 | } |
472 | |||
488 | public bool IsActive() | 473 | public bool IsActive() |
489 | { | 474 | { |
490 | return m_active; | 475 | return m_active; |
491 | } | 476 | } |
477 | |||
492 | public void Deactivate() | 478 | public void Deactivate() |
493 | { | 479 | { |
494 | m_active = false; | 480 | m_active = false; |
495 | } | 481 | } |
482 | |||
496 | public void Activate() | 483 | public void Activate() |
497 | { | 484 | { |
498 | m_active = true; | 485 | m_active = true; |
499 | } | 486 | } |
487 | |||
500 | public LLUUID GetID() | 488 | public LLUUID GetID() |
501 | { | 489 | { |
502 | return m_id; | 490 | return m_id; |
503 | } | 491 | } |
504 | |||
505 | } | 492 | } |
506 | 493 | } \ No newline at end of file | |
507 | } | ||