aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Scripting/WorldComm
diff options
context:
space:
mode:
authorJeff Ames2008-05-01 14:31:30 +0000
committerJeff Ames2008-05-01 14:31:30 +0000
commitd51ce47b2d7635b17f3dd429158e8f59b78b83aa (patch)
treed3595bd5194199184059aa398b91a51dc6c799cf /OpenSim/Region/Environment/Modules/Scripting/WorldComm
parent* Looks like I had the bamboo build right in the first place - it was just th... (diff)
downloadopensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.zip
opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.gz
opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.bz2
opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.xz
Update svn properties. Minor formatting cleanup.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Scripting/WorldComm')
-rw-r--r--OpenSim/Region/Environment/Modules/Scripting/WorldComm/WorldCommModule.cs1168
1 files changed, 584 insertions, 584 deletions
diff --git a/OpenSim/Region/Environment/Modules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/Environment/Modules/Scripting/WorldComm/WorldCommModule.cs
index ff3b31e..e79b2bd 100644
--- a/OpenSim/Region/Environment/Modules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/Environment/Modules/Scripting/WorldComm/WorldCommModule.cs
@@ -1,585 +1,585 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the 12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using libsecondlife; 30using libsecondlife;
31using Nini.Config; 31using Nini.Config;
32using OpenSim.Framework; 32using OpenSim.Framework;
33using OpenSim.Region.Environment.Interfaces; 33using OpenSim.Region.Environment.Interfaces;
34using OpenSim.Region.Environment.Scenes; 34using OpenSim.Region.Environment.Scenes;
35 35
36/***************************************************** 36/*****************************************************
37 * 37 *
38 * WorldCommModule 38 * WorldCommModule
39 * 39 *
40 * 40 *
41 * Holding place for world comms - basically llListen 41 * Holding place for world comms - basically llListen
42 * function implementation. 42 * function implementation.
43 * 43 *
44 * lLListen(integer channel, string name, key id, string msg) 44 * lLListen(integer channel, string name, key id, string msg)
45 * The name, id, and msg arguments specify the filtering 45 * The name, id, and msg arguments specify the filtering
46 * criteria. You can pass the empty string 46 * criteria. You can pass the empty string
47 * (or NULL_KEY for id) for these to set a completely 47 * (or NULL_KEY for id) for these to set a completely
48 * open filter; this causes the listen() event handler to be 48 * open filter; this causes the listen() event handler to be
49 * invoked for all chat on the channel. To listen only 49 * invoked for all chat on the channel. To listen only
50 * for chat spoken by a specific object or avatar, 50 * for chat spoken by a specific object or avatar,
51 * specify the name and/or id arguments. To listen 51 * specify the name and/or id arguments. To listen
52 * only for a specific command, specify the 52 * only for a specific command, specify the
53 * (case-sensitive) msg argument. If msg is not empty, 53 * (case-sensitive) msg argument. If msg is not empty,
54 * listener will only hear strings which are exactly equal 54 * listener will only hear strings which are exactly equal
55 * to msg. You can also use all the arguments to establish 55 * to msg. You can also use all the arguments to establish
56 * the most restrictive filtering criteria. 56 * the most restrictive filtering criteria.
57 * 57 *
58 * It might be useful for each listener to maintain a message 58 * It might be useful for each listener to maintain a message
59 * digest, with a list of recent messages by UUID. This can 59 * digest, with a list of recent messages by UUID. This can
60 * be used to prevent in-world repeater loops. However, the 60 * be used to prevent in-world repeater loops. However, the
61 * linden functions do not have this capability, so for now 61 * linden functions do not have this capability, so for now
62 * thats the way it works. 62 * thats the way it works.
63 * 63 *
64 * **************************************************/ 64 * **************************************************/
65 65
66namespace OpenSim.Region.Environment.Modules.Scripting.WorldComm 66namespace OpenSim.Region.Environment.Modules.Scripting.WorldComm
67{ 67{
68 public class WorldCommModule : IRegionModule, IWorldComm 68 public class WorldCommModule : IRegionModule, IWorldComm
69 { 69 {
70 private object CommListLock = new object(); 70 private object CommListLock = new object();
71 private object ListLock = new object(); 71 private object ListLock = new object();
72 private ListenerManager m_listenerManager; 72 private ListenerManager m_listenerManager;
73 private string m_name = "WorldCommModule"; 73 private string m_name = "WorldCommModule";
74 private Queue m_pending; 74 private Queue m_pending;
75 private Queue m_pendingQ; 75 private Queue m_pendingQ;
76 private Scene m_scene; 76 private Scene m_scene;
77 77
78 public WorldCommModule() 78 public WorldCommModule()
79 { 79 {
80 } 80 }
81 81
82 #region IRegionModule Members 82 #region IRegionModule Members
83 83
84 public void Initialise(Scene scene, IConfigSource config) 84 public void Initialise(Scene scene, IConfigSource config)
85 { 85 {
86 m_scene = scene; 86 m_scene = scene;
87 m_scene.RegisterModuleInterface<IWorldComm>(this); 87 m_scene.RegisterModuleInterface<IWorldComm>(this);
88 m_listenerManager = new ListenerManager(); 88 m_listenerManager = new ListenerManager();
89 m_scene.EventManager.OnNewClient += NewClient; 89 m_scene.EventManager.OnNewClient += NewClient;
90 m_pendingQ = new Queue(); 90 m_pendingQ = new Queue();
91 m_pending = Queue.Synchronized(m_pendingQ); 91 m_pending = Queue.Synchronized(m_pendingQ);
92 } 92 }
93 93
94 public void PostInitialise() 94 public void PostInitialise()
95 { 95 {
96 } 96 }
97 97
98 public void Close() 98 public void Close()
99 { 99 {
100 } 100 }
101 101
102 public string Name 102 public string Name
103 { 103 {
104 get { return m_name; } 104 get { return m_name; }
105 } 105 }
106 106
107 public bool IsSharedModule 107 public bool IsSharedModule
108 { 108 {
109 get { return false; } 109 get { return false; }
110 } 110 }
111 111
112 #endregion 112 #endregion
113 113
114 #region IWorldComm Members 114 #region IWorldComm Members
115 115
116 public int Listen(uint localID, LLUUID itemID, LLUUID hostID, int channel, string name, string id, string msg) 116 public int Listen(uint localID, LLUUID itemID, LLUUID hostID, int channel, string name, string id, string msg)
117 { 117 {
118 return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg); 118 return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg);
119 } 119 }
120 120
121 public void ListenControl(int handle, int active) 121 public void ListenControl(int handle, int active)
122 { 122 {
123 if (m_listenerManager != null) 123 if (m_listenerManager != null)
124 { 124 {
125 if (active == 1) 125 if (active == 1)
126 m_listenerManager.Activate(handle); 126 m_listenerManager.Activate(handle);
127 else if (active == 0) 127 else if (active == 0)
128 m_listenerManager.Dectivate(handle); 128 m_listenerManager.Dectivate(handle);
129 } 129 }
130 } 130 }
131 131
132 public void ListenRemove(int handle) 132 public void ListenRemove(int handle)
133 { 133 {
134 if (m_listenerManager != null) 134 if (m_listenerManager != null)
135 { 135 {
136 m_listenerManager.Remove(handle); 136 m_listenerManager.Remove(handle);
137 } 137 }
138 } 138 }
139 139
140 public void DeleteListener(LLUUID itemID) 140 public void DeleteListener(LLUUID itemID)
141 { 141 {
142 if (m_listenerManager != null) 142 if (m_listenerManager != null)
143 { 143 {
144 m_listenerManager.DeleteListener(itemID); 144 m_listenerManager.DeleteListener(itemID);
145 } 145 }
146 } 146 }
147 147
148 // This method scans nearby objects and determines if they are listeners, 148 // This method scans nearby objects and determines if they are listeners,
149 // and if so if this message fits the filter. If it does, then 149 // and if so if this message fits the filter. If it does, then
150 // enqueue the message for delivery to the objects listen event handler. 150 // enqueue the message for delivery to the objects listen event handler.
151 // Objects that do an llSay have their messages delivered here, and for 151 // Objects that do an llSay have their messages delivered here, and for
152 // nearby avatars, the SimChat function is used. 152 // nearby avatars, the SimChat function is used.
153 public void DeliverMessage(string sourceItemID, ChatTypeEnum type, int channel, string name, string msg) 153 public void DeliverMessage(string sourceItemID, ChatTypeEnum type, int channel, string name, string msg)
154 { 154 {
155 SceneObjectPart source = null; 155 SceneObjectPart source = null;
156 ScenePresence avatar = null; 156 ScenePresence avatar = null;
157 157
158 source = m_scene.GetSceneObjectPart(new LLUUID(sourceItemID)); 158 source = m_scene.GetSceneObjectPart(new LLUUID(sourceItemID));
159 if (source == null) 159 if (source == null)
160 { 160 {
161 avatar = m_scene.GetScenePresence(new LLUUID(sourceItemID)); 161 avatar = m_scene.GetScenePresence(new LLUUID(sourceItemID));
162 } 162 }
163 if ((avatar != null) || (source != null)) 163 if ((avatar != null) || (source != null))
164 { 164 {
165 // Loop through the objects in the scene 165 // Loop through the objects in the scene
166 // If they are in proximity, then if they are 166 // If they are in proximity, then if they are
167 // listeners, if so add them to the pending queue 167 // listeners, if so add them to the pending queue
168 168
169 foreach (ListenerInfo li in m_listenerManager.GetListeners()) 169 foreach (ListenerInfo li in m_listenerManager.GetListeners())
170 { 170 {
171 EntityBase sPart; 171 EntityBase sPart;
172 172
173 m_scene.Entities.TryGetValue(li.GetHostID(), out sPart); 173 m_scene.Entities.TryGetValue(li.GetHostID(), out sPart);
174 174
175 if (sPart != null) 175 if (sPart != null)
176 { 176 {
177 double dis = 0; 177 double dis = 0;
178 178
179 if (source != null) 179 if (source != null)
180 dis = Util.GetDistanceTo(sPart.AbsolutePosition, source.AbsolutePosition); 180 dis = Util.GetDistanceTo(sPart.AbsolutePosition, source.AbsolutePosition);
181 else 181 else
182 dis = Util.GetDistanceTo(sPart.AbsolutePosition, avatar.AbsolutePosition); 182 dis = Util.GetDistanceTo(sPart.AbsolutePosition, avatar.AbsolutePosition);
183 183
184 switch (type) 184 switch (type)
185 { 185 {
186 case ChatTypeEnum.Whisper: 186 case ChatTypeEnum.Whisper:
187 187
188 if ((dis < 10) && (dis > -10)) 188 if ((dis < 10) && (dis > -10))
189 { 189 {
190 if (li.GetChannel() == channel) 190 if (li.GetChannel() == channel)
191 { 191 {
192 ListenerInfo isListener = m_listenerManager.IsListenerMatch( 192 ListenerInfo isListener = m_listenerManager.IsListenerMatch(
193 sourceItemID, sPart.UUID, channel, name, msg 193 sourceItemID, sPart.UUID, channel, name, msg
194 ); 194 );
195 if (isListener != null) 195 if (isListener != null)
196 { 196 {
197 lock (m_pending.SyncRoot) 197 lock (m_pending.SyncRoot)
198 { 198 {
199 m_pending.Enqueue(isListener); 199 m_pending.Enqueue(isListener);
200 } 200 }
201 } 201 }
202 } 202 }
203 } 203 }
204 break; 204 break;
205 205
206 case ChatTypeEnum.Say: 206 case ChatTypeEnum.Say:
207 207
208 if ((dis < 30) && (dis > -30)) 208 if ((dis < 30) && (dis > -30))
209 { 209 {
210 if (li.GetChannel() == channel) 210 if (li.GetChannel() == channel)
211 { 211 {
212 ListenerInfo isListener = m_listenerManager.IsListenerMatch( 212 ListenerInfo isListener = m_listenerManager.IsListenerMatch(
213 sourceItemID, sPart.UUID, channel, name, msg 213 sourceItemID, sPart.UUID, channel, name, msg
214 ); 214 );
215 if (isListener != null) 215 if (isListener != null)
216 { 216 {
217 lock (m_pending.SyncRoot) 217 lock (m_pending.SyncRoot)
218 { 218 {
219 m_pending.Enqueue(isListener); 219 m_pending.Enqueue(isListener);
220 } 220 }
221 } 221 }
222 } 222 }
223 } 223 }
224 break; 224 break;
225 225
226 case ChatTypeEnum.Shout: 226 case ChatTypeEnum.Shout:
227 if ((dis < 100) && (dis > -100)) 227 if ((dis < 100) && (dis > -100))
228 { 228 {
229 if (li.GetChannel() == channel) 229 if (li.GetChannel() == channel)
230 { 230 {
231 ListenerInfo isListener = m_listenerManager.IsListenerMatch( 231 ListenerInfo isListener = m_listenerManager.IsListenerMatch(
232 sourceItemID, sPart.UUID, channel, name, msg 232 sourceItemID, sPart.UUID, channel, name, msg
233 ); 233 );
234 if (isListener != null) 234 if (isListener != null)
235 { 235 {
236 lock (m_pending.SyncRoot) 236 lock (m_pending.SyncRoot)
237 { 237 {
238 m_pending.Enqueue(isListener); 238 m_pending.Enqueue(isListener);
239 } 239 }
240 } 240 }
241 } 241 }
242 } 242 }
243 break; 243 break;
244 244
245 case ChatTypeEnum.Broadcast: 245 case ChatTypeEnum.Broadcast:
246 // Dont process if this message is from itself! 246 // Dont process if this message is from itself!
247 if (li.GetHostID().ToString().Equals(sourceItemID) || 247 if (li.GetHostID().ToString().Equals(sourceItemID) ||
248 sPart.UUID.ToString().Equals(sourceItemID)) 248 sPart.UUID.ToString().Equals(sourceItemID))
249 continue; 249 continue;
250 250
251 if (li.GetChannel() == channel) 251 if (li.GetChannel() == channel)
252 { 252 {
253 ListenerInfo isListener = m_listenerManager.IsListenerMatch( 253 ListenerInfo isListener = m_listenerManager.IsListenerMatch(
254 sourceItemID, sPart.UUID, channel, name, msg 254 sourceItemID, sPart.UUID, channel, name, msg
255 ); 255 );
256 if (isListener != null) 256 if (isListener != null)
257 { 257 {
258 lock (m_pending.SyncRoot) 258 lock (m_pending.SyncRoot)
259 { 259 {
260 m_pending.Enqueue(isListener); 260 m_pending.Enqueue(isListener);
261 } 261 }
262 } 262 }
263 } 263 }
264 264
265 break; 265 break;
266 } 266 }
267 } 267 }
268 } 268 }
269 } 269 }
270 } 270 }
271 271
272 public bool HasMessages() 272 public bool HasMessages()
273 { 273 {
274 if (m_pending != null) 274 if (m_pending != null)
275 return (m_pending.Count > 0); 275 return (m_pending.Count > 0);
276 else 276 else
277 return false; 277 return false;
278 } 278 }
279 279
280 public ListenerInfo GetNextMessage() 280 public ListenerInfo GetNextMessage()
281 { 281 {
282 ListenerInfo li = null; 282 ListenerInfo li = null;
283 283
284 lock (m_pending.SyncRoot) 284 lock (m_pending.SyncRoot)
285 { 285 {
286 li = (ListenerInfo) m_pending.Dequeue(); 286 li = (ListenerInfo) m_pending.Dequeue();
287 } 287 }
288 288
289 return li; 289 return li;
290 } 290 }
291 291
292 public uint PeekNextMessageLocalID() 292 public uint PeekNextMessageLocalID()
293 { 293 {
294 return ((ListenerInfo) m_pending.Peek()).GetLocalID(); 294 return ((ListenerInfo) m_pending.Peek()).GetLocalID();
295 } 295 }
296 296
297 public LLUUID PeekNextMessageItemID() 297 public LLUUID PeekNextMessageItemID()
298 { 298 {
299 return ((ListenerInfo) m_pending.Peek()).GetItemID(); 299 return ((ListenerInfo) m_pending.Peek()).GetItemID();
300 } 300 }
301 301
302 #endregion 302 #endregion
303 303
304 public void NewClient(IClientAPI client) 304 public void NewClient(IClientAPI client)
305 { 305 {
306 client.OnChatFromViewer += DeliverClientMessage; 306 client.OnChatFromViewer += DeliverClientMessage;
307 } 307 }
308 308
309 /******************************************************************** 309 /********************************************************************
310 * 310 *
311 * Listener Stuff 311 * Listener Stuff
312 * 312 *
313 * *****************************************************************/ 313 * *****************************************************************/
314 314
315 private void DeliverClientMessage(Object sender, ChatFromViewerArgs e) 315 private void DeliverClientMessage(Object sender, ChatFromViewerArgs e)
316 { 316 {
317 DeliverMessage(e.Sender.AgentId.ToString(), 317 DeliverMessage(e.Sender.AgentId.ToString(),
318 e.Type, e.Channel, 318 e.Type, e.Channel,
319 e.Sender.FirstName + " " + e.Sender.LastName, 319 e.Sender.FirstName + " " + e.Sender.LastName,
320 e.Message); 320 e.Message);
321 } 321 }
322 } 322 }
323 323
324 public class ListenerManager 324 public class ListenerManager
325 { 325 {
326 //private Dictionary<int, ListenerInfo> m_listeners; 326 //private Dictionary<int, ListenerInfo> m_listeners;
327 private object ListenersLock = new object(); 327 private object ListenersLock = new object();
328 private Hashtable m_listeners = Hashtable.Synchronized(new Hashtable()); 328 private Hashtable m_listeners = Hashtable.Synchronized(new Hashtable());
329 private int m_MaxListeners = 100; 329 private int m_MaxListeners = 100;
330 330
331 public int AddListener(uint localID, LLUUID itemID, LLUUID hostID, int channel, string name, string id, string msg) 331 public int AddListener(uint localID, LLUUID itemID, LLUUID hostID, int channel, string name, string id, string msg)
332 { 332 {
333 if (m_listeners.Count < m_MaxListeners) 333 if (m_listeners.Count < m_MaxListeners)
334 { 334 {
335 ListenerInfo isListener = IsListenerMatch(LLUUID.Zero.ToString(), itemID, channel, name, msg); 335 ListenerInfo isListener = IsListenerMatch(LLUUID.Zero.ToString(), itemID, channel, name, msg);
336 336
337 if (isListener == null) 337 if (isListener == null)
338 { 338 {
339 int newHandle = GetNewHandle(); 339 int newHandle = GetNewHandle();
340 340
341 if (newHandle > -1) 341 if (newHandle > -1)
342 { 342 {
343 ListenerInfo li = new ListenerInfo(localID, newHandle, itemID, hostID, channel, name, id, msg); 343 ListenerInfo li = new ListenerInfo(localID, newHandle, itemID, hostID, channel, name, id, msg);
344 344
345 lock (m_listeners.SyncRoot) 345 lock (m_listeners.SyncRoot)
346 { 346 {
347 m_listeners.Add(newHandle, li); 347 m_listeners.Add(newHandle, li);
348 } 348 }
349 349
350 return newHandle; 350 return newHandle;
351 } 351 }
352 } 352 }
353 } 353 }
354 354
355 return -1; 355 return -1;
356 } 356 }
357 357
358 public void Remove(int handle) 358 public void Remove(int handle)
359 { 359 {
360 lock (m_listeners.SyncRoot) 360 lock (m_listeners.SyncRoot)
361 { 361 {
362 m_listeners.Remove(handle); 362 m_listeners.Remove(handle);
363 } 363 }
364 } 364 }
365 365
366 public void DeleteListener(LLUUID itemID) 366 public void DeleteListener(LLUUID itemID)
367 { 367 {
368 ArrayList removedListeners = new ArrayList(); 368 ArrayList removedListeners = new ArrayList();
369 369
370 lock (m_listeners.SyncRoot) 370 lock (m_listeners.SyncRoot)
371 { 371 {
372 IDictionaryEnumerator en = m_listeners.GetEnumerator(); 372 IDictionaryEnumerator en = m_listeners.GetEnumerator();
373 while (en.MoveNext()) 373 while (en.MoveNext())
374 { 374 {
375 ListenerInfo li = (ListenerInfo) en.Value; 375 ListenerInfo li = (ListenerInfo) en.Value;
376 if (li.GetItemID().Equals(itemID)) 376 if (li.GetItemID().Equals(itemID))
377 { 377 {
378 removedListeners.Add(li.GetHandle()); 378 removedListeners.Add(li.GetHandle());
379 } 379 }
380 } 380 }
381 foreach (int handle in removedListeners) 381 foreach (int handle in removedListeners)
382 { 382 {
383 m_listeners.Remove(handle); 383 m_listeners.Remove(handle);
384 } 384 }
385 } 385 }
386 } 386 }
387 387
388 private int GetNewHandle() 388 private int GetNewHandle()
389 { 389 {
390 for (int i = 0; i < int.MaxValue - 1; i++) 390 for (int i = 0; i < int.MaxValue - 1; i++)
391 { 391 {
392 if (!m_listeners.ContainsKey(i)) 392 if (!m_listeners.ContainsKey(i))
393 return i; 393 return i;
394 } 394 }
395 395
396 return -1; 396 return -1;
397 } 397 }
398 398
399 public bool IsListener(LLUUID hostID) 399 public bool IsListener(LLUUID hostID)
400 { 400 {
401 foreach (ListenerInfo li in m_listeners.Values) 401 foreach (ListenerInfo li in m_listeners.Values)
402 { 402 {
403 if (li.GetHostID().Equals(hostID)) 403 if (li.GetHostID().Equals(hostID))
404 return true; 404 return true;
405 } 405 }
406 406
407 return false; 407 return false;
408 } 408 }
409 409
410 public void Activate(int handle) 410 public void Activate(int handle)
411 { 411 {
412 if (m_listeners.ContainsKey(handle)) 412 if (m_listeners.ContainsKey(handle))
413 { 413 {
414 lock (m_listeners.SyncRoot) 414 lock (m_listeners.SyncRoot)
415 { 415 {
416 ListenerInfo li = (ListenerInfo) m_listeners[handle]; 416 ListenerInfo li = (ListenerInfo) m_listeners[handle];
417 li.Activate(); 417 li.Activate();
418 } 418 }
419 } 419 }
420 } 420 }
421 421
422 public void Dectivate(int handle) 422 public void Dectivate(int handle)
423 { 423 {
424 if (m_listeners.ContainsKey(handle)) 424 if (m_listeners.ContainsKey(handle))
425 { 425 {
426 ListenerInfo li = (ListenerInfo) m_listeners[handle]; 426 ListenerInfo li = (ListenerInfo) m_listeners[handle];
427 li.Deactivate(); 427 li.Deactivate();
428 } 428 }
429 } 429 }
430 430
431 // Theres probably a more clever and efficient way to 431 // Theres probably a more clever and efficient way to
432 // do this, maybe with regex. 432 // do this, maybe with regex.
433 public ListenerInfo IsListenerMatch(string sourceItemID, LLUUID listenerKey, int channel, string name, 433 public ListenerInfo IsListenerMatch(string sourceItemID, LLUUID listenerKey, int channel, string name,
434 string msg) 434 string msg)
435 { 435 {
436 bool isMatch = true; 436 bool isMatch = true;
437 lock (m_listeners.SyncRoot) 437 lock (m_listeners.SyncRoot)
438 { 438 {
439 IDictionaryEnumerator en = m_listeners.GetEnumerator(); 439 IDictionaryEnumerator en = m_listeners.GetEnumerator();
440 while (en.MoveNext()) 440 while (en.MoveNext())
441 { 441 {
442 ListenerInfo li = (ListenerInfo) en.Value; 442 ListenerInfo li = (ListenerInfo) en.Value;
443 443
444 if (li.IsActive()) 444 if (li.IsActive())
445 { 445 {
446 if (li.GetHostID().Equals(listenerKey)) 446 if (li.GetHostID().Equals(listenerKey))
447 { 447 {
448 if (channel == li.GetChannel()) 448 if (channel == li.GetChannel())
449 { 449 {
450 if ((li.GetID().ToString().Length > 0) && 450 if ((li.GetID().ToString().Length > 0) &&
451 (!li.GetID().Equals(LLUUID.Zero))) 451 (!li.GetID().Equals(LLUUID.Zero)))
452 { 452 {
453 if (!li.GetID().ToString().Equals(sourceItemID)) 453 if (!li.GetID().ToString().Equals(sourceItemID))
454 { 454 {
455 isMatch = false; 455 isMatch = false;
456 } 456 }
457 } 457 }
458 if (isMatch && (li.GetName().Length > 0)) 458 if (isMatch && (li.GetName().Length > 0))
459 { 459 {
460 if (li.GetName().Equals(name)) 460 if (li.GetName().Equals(name))
461 { 461 {
462 isMatch = false; 462 isMatch = false;
463 } 463 }
464 } 464 }
465 if (isMatch) 465 if (isMatch)
466 { 466 {
467 return new ListenerInfo( 467 return new ListenerInfo(
468 li.GetLocalID(), li.GetHandle(), li.GetItemID(), li.GetHostID(), 468 li.GetLocalID(), li.GetHandle(), li.GetItemID(), li.GetHostID(),
469 li.GetChannel(), name, li.GetID(), msg, new LLUUID(sourceItemID) 469 li.GetChannel(), name, li.GetID(), msg, new LLUUID(sourceItemID)
470 ); 470 );
471 } 471 }
472 } 472 }
473 } 473 }
474 } 474 }
475 } 475 }
476 } 476 }
477 return null; 477 return null;
478 } 478 }
479 479
480 public ICollection GetListeners() 480 public ICollection GetListeners()
481 { 481 {
482 return m_listeners.Values; 482 return m_listeners.Values;
483 } 483 }
484 } 484 }
485 485
486 public class ListenerInfo 486 public class ListenerInfo
487 { 487 {
488 private bool m_active; // Listener is active or not 488 private bool m_active; // Listener is active or not
489 private int m_channel; // Channel 489 private int m_channel; // Channel
490 private int m_handle; // Assigned handle of this listener 490 private int m_handle; // Assigned handle of this listener
491 private LLUUID m_hostID; // ID of the host/scene part 491 private LLUUID m_hostID; // ID of the host/scene part
492 private LLUUID m_id; // ID to filter messages from 492 private LLUUID m_id; // ID to filter messages from
493 private LLUUID m_itemID; // ID of the host script engine 493 private LLUUID m_itemID; // ID of the host script engine
494 private uint m_localID; // Local ID from script engine 494 private uint m_localID; // Local ID from script engine
495 private string m_message; // The message 495 private string m_message; // The message
496 private string m_name; // Object name to filter messages from 496 private string m_name; // Object name to filter messages from
497 private LLUUID m_sourceItemID; // ID of the scenePart or avatar source of the message 497 private LLUUID m_sourceItemID; // ID of the scenePart or avatar source of the message
498 498
499 public ListenerInfo(uint localID, int handle, LLUUID ItemID, LLUUID hostID, int channel, string name, LLUUID id, string message) 499 public ListenerInfo(uint localID, int handle, LLUUID ItemID, LLUUID hostID, int channel, string name, LLUUID id, string message)
500 { 500 {
501 Initialise(localID, handle, ItemID, hostID, channel, name, id, message); 501 Initialise(localID, handle, ItemID, hostID, channel, name, id, message);
502 } 502 }
503 503
504 public ListenerInfo(uint localID, int handle, LLUUID ItemID, LLUUID hostID, int channel, string name, LLUUID id, 504 public ListenerInfo(uint localID, int handle, LLUUID ItemID, LLUUID hostID, int channel, string name, LLUUID id,
505 string message, LLUUID sourceItemID) 505 string message, LLUUID sourceItemID)
506 { 506 {
507 Initialise(localID, handle, ItemID, hostID, channel, name, id, message); 507 Initialise(localID, handle, ItemID, hostID, channel, name, id, message);
508 m_sourceItemID = sourceItemID; 508 m_sourceItemID = sourceItemID;
509 } 509 }
510 510
511 private void Initialise(uint localID, int handle, LLUUID ItemID, LLUUID hostID, int channel, string name, 511 private void Initialise(uint localID, int handle, LLUUID ItemID, LLUUID hostID, int channel, string name,
512 LLUUID id, string message) 512 LLUUID id, string message)
513 { 513 {
514 m_handle = handle; 514 m_handle = handle;
515 m_channel = channel; 515 m_channel = channel;
516 m_itemID = ItemID; 516 m_itemID = ItemID;
517 m_hostID = hostID; 517 m_hostID = hostID;
518 m_name = name; 518 m_name = name;
519 m_id = id; 519 m_id = id;
520 m_message = message; 520 m_message = message;
521 m_active = true; 521 m_active = true;
522 m_localID = localID; 522 m_localID = localID;
523 } 523 }
524 524
525 public LLUUID GetItemID() 525 public LLUUID GetItemID()
526 { 526 {
527 return m_itemID; 527 return m_itemID;
528 } 528 }
529 529
530 public LLUUID GetHostID() 530 public LLUUID GetHostID()
531 { 531 {
532 return m_hostID; 532 return m_hostID;
533 } 533 }
534 534
535 public LLUUID GetSourceItemID() 535 public LLUUID GetSourceItemID()
536 { 536 {
537 return m_sourceItemID; 537 return m_sourceItemID;
538 } 538 }
539 539
540 public int GetChannel() 540 public int GetChannel()
541 { 541 {
542 return m_channel; 542 return m_channel;
543 } 543 }
544 544
545 public uint GetLocalID() 545 public uint GetLocalID()
546 { 546 {
547 return m_localID; 547 return m_localID;
548 } 548 }
549 549
550 public int GetHandle() 550 public int GetHandle()
551 { 551 {
552 return m_handle; 552 return m_handle;
553 } 553 }
554 554
555 public string GetMessage() 555 public string GetMessage()
556 { 556 {
557 return m_message; 557 return m_message;
558 } 558 }
559 559
560 public string GetName() 560 public string GetName()
561 { 561 {
562 return m_name; 562 return m_name;
563 } 563 }
564 564
565 public bool IsActive() 565 public bool IsActive()
566 { 566 {
567 return m_active; 567 return m_active;
568 } 568 }
569 569
570 public void Deactivate() 570 public void Deactivate()
571 { 571 {
572 m_active = false; 572 m_active = false;
573 } 573 }
574 574
575 public void Activate() 575 public void Activate()
576 { 576 {
577 m_active = true; 577 m_active = true;
578 } 578 }
579 579
580 public LLUUID GetID() 580 public LLUUID GetID()
581 { 581 {
582 return m_id; 582 return m_id;
583 } 583 }
584 } 584 }
585} \ No newline at end of file 585} \ No newline at end of file