EventQueueGetModule.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  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
  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
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Net;
  31. using System.Reflection;
  32. using System.Threading;
  33. using log4net;
  34. using Nini.Config;
  35. using Mono.Addins;
  36. using OpenMetaverse;
  37. using OpenMetaverse.Messages.Linden;
  38. using OpenMetaverse.Packets;
  39. using OpenMetaverse.StructuredData;
  40. using OpenSim.Framework;
  41. using OpenSim.Framework.Servers;
  42. using OpenSim.Framework.Servers.HttpServer;
  43. using OpenSim.Region.Framework.Interfaces;
  44. using OpenSim.Region.Framework.Scenes;
  45. using BlockingLLSDQueue = OpenSim.Framework.BlockingQueue<OpenMetaverse.StructuredData.OSD>;
  46. using Caps=OpenSim.Framework.Capabilities.Caps;
  47. namespace OpenSim.Region.ClientStack.Linden
  48. {
  49. public struct QueueItem
  50. {
  51. public int id;
  52. public OSDMap body;
  53. }
  54. //[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
  55. public class EventQueueGetModule : IEventQueue, IRegionModule
  56. {
  57. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  58. protected Scene m_scene = null;
  59. private IConfigSource m_gConfig;
  60. bool enabledYN = false;
  61. private Dictionary<UUID, int> m_ids = new Dictionary<UUID, int>();
  62. private Dictionary<UUID, Queue<OSD>> queues = new Dictionary<UUID, Queue<OSD>>();
  63. private Dictionary<UUID, UUID> m_QueueUUIDAvatarMapping = new Dictionary<UUID, UUID>();
  64. private Dictionary<UUID, UUID> m_AvatarQueueUUIDMapping = new Dictionary<UUID, UUID>();
  65. #region IRegionModule methods
  66. public virtual void Initialise(Scene scene, IConfigSource config)
  67. {
  68. m_gConfig = config;
  69. IConfig startupConfig = m_gConfig.Configs["Startup"];
  70. ReadConfigAndPopulate(scene, startupConfig, "Startup");
  71. if (enabledYN)
  72. {
  73. m_scene = scene;
  74. scene.RegisterModuleInterface<IEventQueue>(this);
  75. // Register fallback handler
  76. // Why does EQG Fail on region crossings!
  77. //scene.CommsManager.HttpServer.AddLLSDHandler("/CAPS/EQG/", EventQueueFallBack);
  78. scene.EventManager.OnNewClient += OnNewClient;
  79. // TODO: Leaving these open, or closing them when we
  80. // become a child is incorrect. It messes up TP in a big
  81. // way. CAPS/EQ need to be active as long as the UDP
  82. // circuit is there.
  83. scene.EventManager.OnClientClosed += ClientClosed;
  84. scene.EventManager.OnMakeChildAgent += MakeChildAgent;
  85. scene.EventManager.OnRegisterCaps += OnRegisterCaps;
  86. }
  87. else
  88. {
  89. m_gConfig = null;
  90. }
  91. }
  92. private void ReadConfigAndPopulate(Scene scene, IConfig startupConfig, string p)
  93. {
  94. enabledYN = startupConfig.GetBoolean("EventQueue", true);
  95. }
  96. public void PostInitialise()
  97. {
  98. }
  99. public virtual void Close()
  100. {
  101. }
  102. public virtual string Name
  103. {
  104. get { return "EventQueueGetModule"; }
  105. }
  106. public bool IsSharedModule
  107. {
  108. get { return false; }
  109. }
  110. #endregion
  111. /// <summary>
  112. /// Always returns a valid queue
  113. /// </summary>
  114. /// <param name="agentId"></param>
  115. /// <returns></returns>
  116. private Queue<OSD> TryGetQueue(UUID agentId)
  117. {
  118. lock (queues)
  119. {
  120. if (!queues.ContainsKey(agentId))
  121. {
  122. /*
  123. m_log.DebugFormat(
  124. "[EVENTQUEUE]: Adding new queue for agent {0} in region {1}",
  125. agentId, m_scene.RegionInfo.RegionName);
  126. */
  127. queues[agentId] = new Queue<OSD>();
  128. }
  129. return queues[agentId];
  130. }
  131. }
  132. /// <summary>
  133. /// May return a null queue
  134. /// </summary>
  135. /// <param name="agentId"></param>
  136. /// <returns></returns>
  137. private Queue<OSD> GetQueue(UUID agentId)
  138. {
  139. lock (queues)
  140. {
  141. if (queues.ContainsKey(agentId))
  142. {
  143. return queues[agentId];
  144. }
  145. else
  146. return null;
  147. }
  148. }
  149. #region IEventQueue Members
  150. public bool Enqueue(OSD ev, UUID avatarID)
  151. {
  152. //m_log.DebugFormat("[EVENTQUEUE]: Enqueuing event for {0} in region {1}", avatarID, m_scene.RegionInfo.RegionName);
  153. try
  154. {
  155. Queue<OSD> queue = GetQueue(avatarID);
  156. if (queue != null)
  157. queue.Enqueue(ev);
  158. }
  159. catch(NullReferenceException e)
  160. {
  161. m_log.Error("[EVENTQUEUE] Caught exception: " + e);
  162. return false;
  163. }
  164. return true;
  165. }
  166. #endregion
  167. private void OnNewClient(IClientAPI client)
  168. {
  169. //client.OnLogout += ClientClosed;
  170. }
  171. // private void ClientClosed(IClientAPI client)
  172. // {
  173. // ClientClosed(client.AgentId);
  174. // }
  175. private void ClientClosed(UUID AgentID, Scene scene)
  176. {
  177. //m_log.DebugFormat("[EVENTQUEUE]: Closed client {0} in region {1}", AgentID, m_scene.RegionInfo.RegionName);
  178. int count = 0;
  179. while (queues.ContainsKey(AgentID) && queues[AgentID].Count > 0 && count++ < 5)
  180. {
  181. Thread.Sleep(1000);
  182. }
  183. lock (queues)
  184. {
  185. queues.Remove(AgentID);
  186. }
  187. List<UUID> removeitems = new List<UUID>();
  188. lock (m_AvatarQueueUUIDMapping)
  189. {
  190. foreach (UUID ky in m_AvatarQueueUUIDMapping.Keys)
  191. {
  192. if (ky == AgentID)
  193. {
  194. removeitems.Add(ky);
  195. }
  196. }
  197. foreach (UUID ky in removeitems)
  198. {
  199. m_AvatarQueueUUIDMapping.Remove(ky);
  200. MainServer.Instance.RemovePollServiceHTTPHandler("","/CAPS/EQG/" + ky.ToString() + "/");
  201. }
  202. }
  203. UUID searchval = UUID.Zero;
  204. removeitems.Clear();
  205. lock (m_QueueUUIDAvatarMapping)
  206. {
  207. foreach (UUID ky in m_QueueUUIDAvatarMapping.Keys)
  208. {
  209. searchval = m_QueueUUIDAvatarMapping[ky];
  210. if (searchval == AgentID)
  211. {
  212. removeitems.Add(ky);
  213. }
  214. }
  215. foreach (UUID ky in removeitems)
  216. m_QueueUUIDAvatarMapping.Remove(ky);
  217. }
  218. }
  219. private void MakeChildAgent(ScenePresence avatar)
  220. {
  221. //m_log.DebugFormat("[EVENTQUEUE]: Make Child agent {0} in region {1}.", avatar.UUID, m_scene.RegionInfo.RegionName);
  222. //lock (m_ids)
  223. // {
  224. //if (m_ids.ContainsKey(avatar.UUID))
  225. //{
  226. // close the event queue.
  227. //m_ids[avatar.UUID] = -1;
  228. //}
  229. //}
  230. }
  231. public void OnRegisterCaps(UUID agentID, Caps caps)
  232. {
  233. // Register an event queue for the client
  234. //m_log.DebugFormat(
  235. // "[EVENTQUEUE]: OnRegisterCaps: agentID {0} caps {1} region {2}",
  236. // agentID, caps, m_scene.RegionInfo.RegionName);
  237. // Let's instantiate a Queue for this agent right now
  238. TryGetQueue(agentID);
  239. string capsBase = "/CAPS/EQG/";
  240. UUID EventQueueGetUUID = UUID.Zero;
  241. lock (m_AvatarQueueUUIDMapping)
  242. {
  243. // Reuse open queues. The client does!
  244. if (m_AvatarQueueUUIDMapping.ContainsKey(agentID))
  245. {
  246. //m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID!");
  247. EventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID];
  248. }
  249. else
  250. {
  251. EventQueueGetUUID = UUID.Random();
  252. //m_log.DebugFormat("[EVENTQUEUE]: Using random UUID!");
  253. }
  254. }
  255. lock (m_QueueUUIDAvatarMapping)
  256. {
  257. if (!m_QueueUUIDAvatarMapping.ContainsKey(EventQueueGetUUID))
  258. m_QueueUUIDAvatarMapping.Add(EventQueueGetUUID, agentID);
  259. }
  260. lock (m_AvatarQueueUUIDMapping)
  261. {
  262. if (!m_AvatarQueueUUIDMapping.ContainsKey(agentID))
  263. m_AvatarQueueUUIDMapping.Add(agentID, EventQueueGetUUID);
  264. }
  265. // Register this as a caps handler
  266. caps.RegisterHandler("EventQueueGet",
  267. new RestHTTPHandler("POST", capsBase + EventQueueGetUUID.ToString() + "/",
  268. delegate(Hashtable m_dhttpMethod)
  269. {
  270. return ProcessQueue(m_dhttpMethod, agentID, caps);
  271. }));
  272. // This will persist this beyond the expiry of the caps handlers
  273. MainServer.Instance.AddPollServiceHTTPHandler(
  274. capsBase + EventQueueGetUUID.ToString() + "/", EventQueuePoll, new PollServiceEventArgs(null, HasEvents, GetEvents, NoEvents, agentID));
  275. Random rnd = new Random(Environment.TickCount);
  276. lock (m_ids)
  277. {
  278. if (!m_ids.ContainsKey(agentID))
  279. m_ids.Add(agentID, rnd.Next(30000000));
  280. }
  281. }
  282. public bool HasEvents(UUID requestID, UUID agentID)
  283. {
  284. // Don't use this, because of race conditions at agent closing time
  285. //Queue<OSD> queue = TryGetQueue(agentID);
  286. Queue<OSD> queue = GetQueue(agentID);
  287. if (queue != null)
  288. lock (queue)
  289. {
  290. if (queue.Count > 0)
  291. return true;
  292. else
  293. return false;
  294. }
  295. return false;
  296. }
  297. public Hashtable GetEvents(UUID requestID, UUID pAgentId, string request)
  298. {
  299. Queue<OSD> queue = TryGetQueue(pAgentId);
  300. OSD element;
  301. lock (queue)
  302. {
  303. if (queue.Count == 0)
  304. return NoEvents(requestID, pAgentId);
  305. element = queue.Dequeue(); // 15s timeout
  306. }
  307. int thisID = 0;
  308. lock (m_ids)
  309. thisID = m_ids[pAgentId];
  310. OSDArray array = new OSDArray();
  311. if (element == null) // didn't have an event in 15s
  312. {
  313. // Send it a fake event to keep the client polling! It doesn't like 502s like the proxys say!
  314. array.Add(EventQueueHelper.KeepAliveEvent());
  315. //m_log.DebugFormat("[EVENTQUEUE]: adding fake event for {0} in region {1}", pAgentId, m_scene.RegionInfo.RegionName);
  316. }
  317. else
  318. {
  319. array.Add(element);
  320. lock (queue)
  321. {
  322. while (queue.Count > 0)
  323. {
  324. array.Add(queue.Dequeue());
  325. thisID++;
  326. }
  327. }
  328. }
  329. OSDMap events = new OSDMap();
  330. events.Add("events", array);
  331. events.Add("id", new OSDInteger(thisID));
  332. lock (m_ids)
  333. {
  334. m_ids[pAgentId] = thisID + 1;
  335. }
  336. Hashtable responsedata = new Hashtable();
  337. responsedata["int_response_code"] = 200;
  338. responsedata["content_type"] = "application/xml";
  339. responsedata["keepalive"] = false;
  340. responsedata["reusecontext"] = false;
  341. responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(events);
  342. //m_log.DebugFormat("[EVENTQUEUE]: sending response for {0} in region {1}: {2}", pAgentId, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
  343. return responsedata;
  344. }
  345. public Hashtable NoEvents(UUID requestID, UUID agentID)
  346. {
  347. Hashtable responsedata = new Hashtable();
  348. responsedata["int_response_code"] = 502;
  349. responsedata["content_type"] = "text/plain";
  350. responsedata["keepalive"] = false;
  351. responsedata["reusecontext"] = false;
  352. responsedata["str_response_string"] = "Upstream error: ";
  353. responsedata["error_status_text"] = "Upstream error:";
  354. responsedata["http_protocol_version"] = "HTTP/1.0";
  355. return responsedata;
  356. }
  357. public Hashtable ProcessQueue(Hashtable request, UUID agentID, Caps caps)
  358. {
  359. // TODO: this has to be redone to not busy-wait (and block the thread),
  360. // TODO: as soon as we have a non-blocking way to handle HTTP-requests.
  361. // if (m_log.IsDebugEnabled)
  362. // {
  363. // String debug = "[EVENTQUEUE]: Got request for agent {0} in region {1} from thread {2}: [ ";
  364. // foreach (object key in request.Keys)
  365. // {
  366. // debug += key.ToString() + "=" + request[key].ToString() + " ";
  367. // }
  368. // m_log.DebugFormat(debug + " ]", agentID, m_scene.RegionInfo.RegionName, System.Threading.Thread.CurrentThread.Name);
  369. // }
  370. Queue<OSD> queue = TryGetQueue(agentID);
  371. OSD element = queue.Dequeue(); // 15s timeout
  372. Hashtable responsedata = new Hashtable();
  373. int thisID = 0;
  374. lock (m_ids)
  375. thisID = m_ids[agentID];
  376. if (element == null)
  377. {
  378. //m_log.ErrorFormat("[EVENTQUEUE]: Nothing to process in " + m_scene.RegionInfo.RegionName);
  379. if (thisID == -1) // close-request
  380. {
  381. m_log.ErrorFormat("[EVENTQUEUE]: 404 in " + m_scene.RegionInfo.RegionName);
  382. responsedata["int_response_code"] = 404; //501; //410; //404;
  383. responsedata["content_type"] = "text/plain";
  384. responsedata["keepalive"] = false;
  385. responsedata["str_response_string"] = "Closed EQG";
  386. return responsedata;
  387. }
  388. responsedata["int_response_code"] = 502;
  389. responsedata["content_type"] = "text/plain";
  390. responsedata["keepalive"] = false;
  391. responsedata["str_response_string"] = "Upstream error: ";
  392. responsedata["error_status_text"] = "Upstream error:";
  393. responsedata["http_protocol_version"] = "HTTP/1.0";
  394. return responsedata;
  395. }
  396. OSDArray array = new OSDArray();
  397. if (element == null) // didn't have an event in 15s
  398. {
  399. // Send it a fake event to keep the client polling! It doesn't like 502s like the proxys say!
  400. array.Add(EventQueueHelper.KeepAliveEvent());
  401. //m_log.DebugFormat("[EVENTQUEUE]: adding fake event for {0} in region {1}", agentID, m_scene.RegionInfo.RegionName);
  402. }
  403. else
  404. {
  405. array.Add(element);
  406. while (queue.Count > 0)
  407. {
  408. array.Add(queue.Dequeue());
  409. thisID++;
  410. }
  411. }
  412. OSDMap events = new OSDMap();
  413. events.Add("events", array);
  414. events.Add("id", new OSDInteger(thisID));
  415. lock (m_ids)
  416. {
  417. m_ids[agentID] = thisID + 1;
  418. }
  419. responsedata["int_response_code"] = 200;
  420. responsedata["content_type"] = "application/xml";
  421. responsedata["keepalive"] = false;
  422. responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(events);
  423. //m_log.DebugFormat("[EVENTQUEUE]: sending response for {0} in region {1}: {2}", agentID, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
  424. return responsedata;
  425. }
  426. public Hashtable EventQueuePoll(Hashtable request)
  427. {
  428. return new Hashtable();
  429. }
  430. public Hashtable EventQueuePath2(Hashtable request)
  431. {
  432. string capuuid = (string)request["uri"]; //path.Replace("/CAPS/EQG/","");
  433. // pull off the last "/" in the path.
  434. Hashtable responsedata = new Hashtable();
  435. capuuid = capuuid.Substring(0, capuuid.Length - 1);
  436. capuuid = capuuid.Replace("/CAPS/EQG/", "");
  437. UUID AvatarID = UUID.Zero;
  438. UUID capUUID = UUID.Zero;
  439. // parse the path and search for the avatar with it registered
  440. if (UUID.TryParse(capuuid, out capUUID))
  441. {
  442. lock (m_QueueUUIDAvatarMapping)
  443. {
  444. if (m_QueueUUIDAvatarMapping.ContainsKey(capUUID))
  445. {
  446. AvatarID = m_QueueUUIDAvatarMapping[capUUID];
  447. }
  448. }
  449. if (AvatarID != UUID.Zero)
  450. {
  451. return ProcessQueue(request, AvatarID, m_scene.CapsModule.GetCapsForUser(AvatarID));
  452. }
  453. else
  454. {
  455. responsedata["int_response_code"] = 404;
  456. responsedata["content_type"] = "text/plain";
  457. responsedata["keepalive"] = false;
  458. responsedata["str_response_string"] = "Not Found";
  459. responsedata["error_status_text"] = "Not Found";
  460. responsedata["http_protocol_version"] = "HTTP/1.0";
  461. return responsedata;
  462. // return 404
  463. }
  464. }
  465. else
  466. {
  467. responsedata["int_response_code"] = 404;
  468. responsedata["content_type"] = "text/plain";
  469. responsedata["keepalive"] = false;
  470. responsedata["str_response_string"] = "Not Found";
  471. responsedata["error_status_text"] = "Not Found";
  472. responsedata["http_protocol_version"] = "HTTP/1.0";
  473. return responsedata;
  474. // return 404
  475. }
  476. }
  477. public OSD EventQueueFallBack(string path, OSD request, string endpoint)
  478. {
  479. // This is a fallback element to keep the client from loosing EventQueueGet
  480. // Why does CAPS fail sometimes!?
  481. m_log.Warn("[EVENTQUEUE]: In the Fallback handler! We lost the Queue in the rest handler!");
  482. string capuuid = path.Replace("/CAPS/EQG/","");
  483. capuuid = capuuid.Substring(0, capuuid.Length - 1);
  484. // UUID AvatarID = UUID.Zero;
  485. UUID capUUID = UUID.Zero;
  486. if (UUID.TryParse(capuuid, out capUUID))
  487. {
  488. /* Don't remove this yet code cleaners!
  489. * Still testing this!
  490. *
  491. lock (m_QueueUUIDAvatarMapping)
  492. {
  493. if (m_QueueUUIDAvatarMapping.ContainsKey(capUUID))
  494. {
  495. AvatarID = m_QueueUUIDAvatarMapping[capUUID];
  496. }
  497. }
  498. if (AvatarID != UUID.Zero)
  499. {
  500. // Repair the CAP!
  501. //OpenSim.Framework.Capabilities.Caps caps = m_scene.GetCapsHandlerForUser(AvatarID);
  502. //string capsBase = "/CAPS/EQG/";
  503. //caps.RegisterHandler("EventQueueGet",
  504. //new RestHTTPHandler("POST", capsBase + capUUID.ToString() + "/",
  505. //delegate(Hashtable m_dhttpMethod)
  506. //{
  507. // return ProcessQueue(m_dhttpMethod, AvatarID, caps);
  508. //}));
  509. // start new ID sequence.
  510. Random rnd = new Random(System.Environment.TickCount);
  511. lock (m_ids)
  512. {
  513. if (!m_ids.ContainsKey(AvatarID))
  514. m_ids.Add(AvatarID, rnd.Next(30000000));
  515. }
  516. int thisID = 0;
  517. lock (m_ids)
  518. thisID = m_ids[AvatarID];
  519. BlockingLLSDQueue queue = GetQueue(AvatarID);
  520. OSDArray array = new OSDArray();
  521. LLSD element = queue.Dequeue(15000); // 15s timeout
  522. if (element == null)
  523. {
  524. array.Add(EventQueueHelper.KeepAliveEvent());
  525. }
  526. else
  527. {
  528. array.Add(element);
  529. while (queue.Count() > 0)
  530. {
  531. array.Add(queue.Dequeue(1));
  532. thisID++;
  533. }
  534. }
  535. OSDMap events = new OSDMap();
  536. events.Add("events", array);
  537. events.Add("id", new LLSDInteger(thisID));
  538. lock (m_ids)
  539. {
  540. m_ids[AvatarID] = thisID + 1;
  541. }
  542. return events;
  543. }
  544. else
  545. {
  546. return new LLSD();
  547. }
  548. *
  549. */
  550. }
  551. else
  552. {
  553. //return new LLSD();
  554. }
  555. return new OSDString("shutdown404!");
  556. }
  557. public void DisableSimulator(ulong handle, UUID avatarID)
  558. {
  559. OSD item = EventQueueHelper.DisableSimulator(handle);
  560. Enqueue(item, avatarID);
  561. }
  562. public virtual void EnableSimulator(ulong handle, IPEndPoint endPoint, UUID avatarID)
  563. {
  564. OSD item = EventQueueHelper.EnableSimulator(handle, endPoint);
  565. Enqueue(item, avatarID);
  566. }
  567. public virtual void EstablishAgentCommunication(UUID avatarID, IPEndPoint endPoint, string capsPath)
  568. {
  569. OSD item = EventQueueHelper.EstablishAgentCommunication(avatarID, endPoint.ToString(), capsPath);
  570. Enqueue(item, avatarID);
  571. }
  572. public virtual void TeleportFinishEvent(ulong regionHandle, byte simAccess,
  573. IPEndPoint regionExternalEndPoint,
  574. uint locationID, uint flags, string capsURL,
  575. UUID avatarID)
  576. {
  577. OSD item = EventQueueHelper.TeleportFinishEvent(regionHandle, simAccess, regionExternalEndPoint,
  578. locationID, flags, capsURL, avatarID);
  579. Enqueue(item, avatarID);
  580. }
  581. public virtual void CrossRegion(ulong handle, Vector3 pos, Vector3 lookAt,
  582. IPEndPoint newRegionExternalEndPoint,
  583. string capsURL, UUID avatarID, UUID sessionID)
  584. {
  585. OSD item = EventQueueHelper.CrossRegion(handle, pos, lookAt, newRegionExternalEndPoint,
  586. capsURL, avatarID, sessionID);
  587. Enqueue(item, avatarID);
  588. }
  589. public void ChatterboxInvitation(UUID sessionID, string sessionName,
  590. UUID fromAgent, string message, UUID toAgent, string fromName, byte dialog,
  591. uint timeStamp, bool offline, int parentEstateID, Vector3 position,
  592. uint ttl, UUID transactionID, bool fromGroup, byte[] binaryBucket)
  593. {
  594. OSD item = EventQueueHelper.ChatterboxInvitation(sessionID, sessionName, fromAgent, message, toAgent, fromName, dialog,
  595. timeStamp, offline, parentEstateID, position, ttl, transactionID,
  596. fromGroup, binaryBucket);
  597. Enqueue(item, toAgent);
  598. //m_log.InfoFormat("########### eq ChatterboxInvitation #############\n{0}", item);
  599. }
  600. public void ChatterBoxSessionAgentListUpdates(UUID sessionID, UUID fromAgent, UUID toAgent, bool canVoiceChat,
  601. bool isModerator, bool textMute)
  602. {
  603. OSD item = EventQueueHelper.ChatterBoxSessionAgentListUpdates(sessionID, fromAgent, canVoiceChat,
  604. isModerator, textMute);
  605. Enqueue(item, toAgent);
  606. //m_log.InfoFormat("########### eq ChatterBoxSessionAgentListUpdates #############\n{0}", item);
  607. }
  608. public void ParcelProperties(ParcelPropertiesMessage parcelPropertiesMessage, UUID avatarID)
  609. {
  610. OSD item = EventQueueHelper.ParcelProperties(parcelPropertiesMessage);
  611. Enqueue(item, avatarID);
  612. }
  613. public void GroupMembership(AgentGroupDataUpdatePacket groupUpdate, UUID avatarID)
  614. {
  615. OSD item = EventQueueHelper.GroupMembership(groupUpdate);
  616. Enqueue(item, avatarID);
  617. }
  618. public void QueryReply(PlacesReplyPacket groupUpdate, UUID avatarID)
  619. {
  620. OSD item = EventQueueHelper.PlacesQuery(groupUpdate);
  621. Enqueue(item, avatarID);
  622. }
  623. public OSD ScriptRunningEvent(UUID objectID, UUID itemID, bool running, bool mono)
  624. {
  625. return EventQueueHelper.ScriptRunningReplyEvent(objectID, itemID, running, mono);
  626. }
  627. public OSD BuildEvent(string eventName, OSD eventBody)
  628. {
  629. return EventQueueHelper.BuildEvent(eventName, eventBody);
  630. }
  631. }
  632. }