EventQueueGetModule.cs 29 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.Text;
  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.Console;
  42. using OpenSim.Framework.Servers;
  43. using OpenSim.Framework.Servers.HttpServer;
  44. using OpenSim.Region.Framework.Interfaces;
  45. using OpenSim.Region.Framework.Scenes;
  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", Id = "EventQueueGetModule")]
  55. public class EventQueueGetModule : IEventQueue, INonSharedRegionModule
  56. {
  57. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  58. private static string LogHeader = "[EVENT QUEUE GET MODULE]";
  59. /// <value>
  60. /// Debug level.
  61. /// </value>
  62. public int DebugLevel { get; set; }
  63. // Viewer post requests timeout in 60 secs
  64. // https://bitbucket.org/lindenlab/viewer-release/src/421c20423df93d650cc305dc115922bb30040999/indra/llmessage/llhttpclient.cpp?at=default#cl-44
  65. //
  66. private const int VIEWER_TIMEOUT = 60 * 1000;
  67. // Just to be safe, we work on a 10 sec shorter cycle
  68. private const int SERVER_EQ_TIME_NO_EVENTS = VIEWER_TIMEOUT - (10 * 1000);
  69. protected Scene m_scene;
  70. private Dictionary<UUID, int> m_ids = new Dictionary<UUID, int>();
  71. private Dictionary<UUID, Queue<OSD>> queues = new Dictionary<UUID, Queue<OSD>>();
  72. private Dictionary<UUID, UUID> m_AvatarQueueUUIDMapping = new Dictionary<UUID, UUID>();
  73. #region INonSharedRegionModule methods
  74. public virtual void Initialise(IConfigSource config)
  75. {
  76. }
  77. public void AddRegion(Scene scene)
  78. {
  79. m_scene = scene;
  80. scene.RegisterModuleInterface<IEventQueue>(this);
  81. scene.EventManager.OnClientClosed += ClientClosed;
  82. scene.EventManager.OnRegisterCaps += OnRegisterCaps;
  83. MainConsole.Instance.Commands.AddCommand(
  84. "Debug",
  85. false,
  86. "debug eq",
  87. "debug eq [0|1|2]",
  88. "Turn on event queue debugging\n"
  89. + " <= 0 - turns off all event queue logging\n"
  90. + " >= 1 - turns on event queue setup and outgoing event logging\n"
  91. + " >= 2 - turns on poll notification",
  92. HandleDebugEq);
  93. MainConsole.Instance.Commands.AddCommand(
  94. "Debug",
  95. false,
  96. "show eq",
  97. "show eq",
  98. "Show contents of event queues for logged in avatars. Used for debugging.",
  99. HandleShowEq);
  100. }
  101. public void RemoveRegion(Scene scene)
  102. {
  103. if (m_scene != scene)
  104. return;
  105. scene.EventManager.OnClientClosed -= ClientClosed;
  106. scene.EventManager.OnRegisterCaps -= OnRegisterCaps;
  107. scene.UnregisterModuleInterface<IEventQueue>(this);
  108. m_scene = null;
  109. }
  110. public void RegionLoaded(Scene scene)
  111. {
  112. }
  113. public virtual void Close()
  114. {
  115. }
  116. public virtual string Name
  117. {
  118. get { return "EventQueueGetModule"; }
  119. }
  120. public Type ReplaceableInterface
  121. {
  122. get { return null; }
  123. }
  124. #endregion
  125. protected void HandleDebugEq(string module, string[] args)
  126. {
  127. int debugLevel;
  128. if (!(args.Length == 3 && int.TryParse(args[2], out debugLevel)))
  129. {
  130. MainConsole.Instance.OutputFormat("Usage: debug eq [0|1|2]");
  131. }
  132. else
  133. {
  134. DebugLevel = debugLevel;
  135. MainConsole.Instance.OutputFormat(
  136. "Set event queue debug level to {0} in {1}", DebugLevel, m_scene.RegionInfo.RegionName);
  137. }
  138. }
  139. protected void HandleShowEq(string module, string[] args)
  140. {
  141. MainConsole.Instance.OutputFormat("For scene {0}", m_scene.Name);
  142. lock (queues)
  143. {
  144. foreach (KeyValuePair<UUID, Queue<OSD>> kvp in queues)
  145. {
  146. MainConsole.Instance.OutputFormat(
  147. "For agent {0} there are {1} messages queued for send.",
  148. kvp.Key, kvp.Value.Count);
  149. }
  150. }
  151. }
  152. /// <summary>
  153. /// Always returns a valid queue
  154. /// </summary>
  155. /// <param name="agentId"></param>
  156. /// <returns></returns>
  157. private Queue<OSD> TryGetQueue(UUID agentId)
  158. {
  159. lock (queues)
  160. {
  161. if (!queues.ContainsKey(agentId))
  162. {
  163. if (DebugLevel > 0)
  164. m_log.DebugFormat(
  165. "[EVENTQUEUE]: Adding new queue for agent {0} in region {1}",
  166. agentId, m_scene.RegionInfo.RegionName);
  167. queues[agentId] = new Queue<OSD>();
  168. }
  169. return queues[agentId];
  170. }
  171. }
  172. /// <summary>
  173. /// May return a null queue
  174. /// </summary>
  175. /// <param name="agentId"></param>
  176. /// <returns></returns>
  177. private Queue<OSD> GetQueue(UUID agentId)
  178. {
  179. lock (queues)
  180. {
  181. if (queues.ContainsKey(agentId))
  182. {
  183. return queues[agentId];
  184. }
  185. else
  186. return null;
  187. }
  188. }
  189. #region IEventQueue Members
  190. public bool Enqueue(OSD ev, UUID avatarID)
  191. {
  192. //m_log.DebugFormat("[EVENTQUEUE]: Enqueuing event for {0} in region {1}", avatarID, m_scene.RegionInfo.RegionName);
  193. try
  194. {
  195. Queue<OSD> queue = GetQueue(avatarID);
  196. if (queue != null)
  197. {
  198. lock (queue)
  199. queue.Enqueue(ev);
  200. }
  201. else
  202. {
  203. m_log.WarnFormat(
  204. "[EVENTQUEUE]: (Enqueue) No queue found for agent {0} in region {2}",
  205. avatarID, m_scene.Name);
  206. }
  207. }
  208. catch (NullReferenceException e)
  209. {
  210. m_log.Error("[EVENTQUEUE] Caught exception: " + e);
  211. return false;
  212. }
  213. return true;
  214. }
  215. #endregion
  216. private void ClientClosed(UUID agentID, Scene scene)
  217. {
  218. //m_log.DebugFormat("[EVENTQUEUE]: Closed client {0} in region {1}", agentID, m_scene.RegionInfo.RegionName);
  219. lock (queues)
  220. {
  221. queues.Remove(agentID);
  222. lock (m_AvatarQueueUUIDMapping)
  223. m_AvatarQueueUUIDMapping.Remove(agentID);
  224. lock (m_ids)
  225. m_ids.Remove(agentID);
  226. }
  227. // m_log.DebugFormat("[EVENTQUEUE]: Deleted queues for {0} in region {1}", agentID, m_scene.RegionInfo.RegionName);
  228. }
  229. /// <summary>
  230. /// Generate an Event Queue Get handler path for the given eqg uuid.
  231. /// </summary>
  232. /// <param name='eqgUuid'></param>
  233. private string GenerateEqgCapPath(UUID eqgUuid)
  234. {
  235. return string.Format("/CAPS/EQG/{0}/", eqgUuid);
  236. }
  237. public void OnRegisterCaps(UUID agentID, Caps caps)
  238. {
  239. // Register an event queue for the client
  240. if (DebugLevel > 0)
  241. m_log.DebugFormat(
  242. "[EVENTQUEUE]: OnRegisterCaps: agentID {0} caps {1} region {2}",
  243. agentID, caps, m_scene.RegionInfo.RegionName);
  244. UUID eventQueueGetUUID;
  245. Queue<OSD> queue = null;
  246. lock (queues)
  247. {
  248. if (queues.ContainsKey(agentID))
  249. queue = queues[agentID];
  250. if (queue == null)
  251. {
  252. queue = new Queue<OSD>();
  253. queues[agentID] = queue;
  254. lock (m_AvatarQueueUUIDMapping)
  255. {
  256. eventQueueGetUUID = UUID.Random();
  257. m_AvatarQueueUUIDMapping[agentID] = eventQueueGetUUID;
  258. lock (m_ids)
  259. {
  260. if (m_ids.ContainsKey(agentID))
  261. m_ids[agentID]++;
  262. else
  263. {
  264. Random rnd = new Random(Environment.TickCount);
  265. m_ids[agentID] = rnd.Next(30000000);
  266. }
  267. }
  268. }
  269. }
  270. else
  271. {
  272. queue.Enqueue(null);
  273. // reuse or not to reuse
  274. lock (m_AvatarQueueUUIDMapping)
  275. {
  276. // Its reuse caps path not queues those are been reused already
  277. if (m_AvatarQueueUUIDMapping.ContainsKey(agentID))
  278. {
  279. m_log.DebugFormat("[EVENTQUEUE]: Found Existing UUID!");
  280. eventQueueGetUUID = m_AvatarQueueUUIDMapping[agentID];
  281. lock (m_ids)
  282. {
  283. // change to negative numbers so they are changed at end of sending first marker
  284. // old data on a queue may be sent on a response for a new caps
  285. // but at least will be sent with coerent IDs
  286. if (m_ids.ContainsKey(agentID))
  287. m_ids[agentID] = -m_ids[agentID];
  288. else
  289. {
  290. Random rnd = new Random(Environment.TickCount);
  291. m_ids[agentID] = -rnd.Next(30000000);
  292. }
  293. }
  294. }
  295. else
  296. {
  297. eventQueueGetUUID = UUID.Random();
  298. m_AvatarQueueUUIDMapping[agentID] = eventQueueGetUUID;
  299. m_log.DebugFormat("[EVENTQUEUE]: Using random UUID!");
  300. lock (m_ids)
  301. {
  302. if (m_ids.ContainsKey(agentID))
  303. m_ids[agentID]++;
  304. else
  305. {
  306. Random rnd = new Random(Environment.TickCount);
  307. m_ids.Add(agentID, rnd.Next(30000000));
  308. }
  309. }
  310. }
  311. }
  312. }
  313. }
  314. caps.RegisterPollHandler(
  315. "EventQueueGet",
  316. new PollServiceEventArgs(null, GenerateEqgCapPath(eventQueueGetUUID), HasEvents, GetEvents, NoEvents, Drop, agentID, SERVER_EQ_TIME_NO_EVENTS));
  317. }
  318. public bool HasEvents(UUID requestID, UUID agentID)
  319. {
  320. Queue<OSD> queue = GetQueue(agentID);
  321. if (queue != null)
  322. lock (queue)
  323. {
  324. //m_log.WarnFormat("POLLED FOR EVENTS BY {0} in {1} -- {2}", agentID, m_scene.RegionInfo.RegionName, queue.Count);
  325. return queue.Count > 0;
  326. }
  327. //m_log.WarnFormat("POLLED FOR EVENTS BY {0} unknown agent", agentID);
  328. return true;
  329. }
  330. /// <summary>
  331. /// Logs a debug line for an outbound event queue message if appropriate.
  332. /// </summary>
  333. /// <param name='element'>Element containing message</param>
  334. private void LogOutboundDebugMessage(OSD element, UUID agentId)
  335. {
  336. if (element is OSDMap)
  337. {
  338. OSDMap ev = (OSDMap)element;
  339. m_log.DebugFormat(
  340. "Eq OUT {0,-30} to {1,-20} {2,-20}",
  341. ev["message"], m_scene.GetScenePresence(agentId).Name, m_scene.Name);
  342. }
  343. }
  344. public void Drop(UUID requestID, UUID pAgentId)
  345. {
  346. // do nothing for now, hope client close will do it
  347. }
  348. public Hashtable GetEvents(UUID requestID, UUID pAgentId)
  349. {
  350. if (DebugLevel >= 2)
  351. m_log.WarnFormat("POLLED FOR EQ MESSAGES BY {0} in {1}", pAgentId, m_scene.Name);
  352. Queue<OSD> queue = GetQueue(pAgentId);
  353. if (queue == null)
  354. return NoEvents(requestID, pAgentId);
  355. OSD element = null;;
  356. OSDArray array = new OSDArray();
  357. int thisID = 0;
  358. bool negativeID = false;
  359. lock (queue)
  360. {
  361. if (queue.Count == 0)
  362. return NoEvents(requestID, pAgentId);
  363. lock (m_ids)
  364. thisID = m_ids[pAgentId];
  365. if (thisID < 0)
  366. {
  367. negativeID = true;
  368. thisID = -thisID;
  369. }
  370. while (queue.Count > 0)
  371. {
  372. element = queue.Dequeue();
  373. // add elements until a marker is found
  374. // so they get into a response
  375. if (element == null)
  376. break;
  377. if (DebugLevel > 0)
  378. LogOutboundDebugMessage(element, pAgentId);
  379. array.Add(element);
  380. }
  381. }
  382. lock (m_ids)
  383. {
  384. if (element == null && negativeID)
  385. {
  386. Random rnd = new Random(Environment.TickCount);
  387. m_ids[pAgentId] = rnd.Next(30000000);
  388. }
  389. else
  390. m_ids[pAgentId] = thisID + 1;
  391. }
  392. if (array.Count == 0)
  393. return NoEvents(requestID, pAgentId);
  394. OSDMap events = new OSDMap();
  395. events.Add("events", array);
  396. events.Add("id", new OSDInteger(thisID));
  397. Hashtable responsedata = new Hashtable();
  398. responsedata["int_response_code"] = 200;
  399. responsedata["content_type"] = "application/xml";
  400. //string tt = OSDParser.SerializeLLSDXmlString(events);
  401. responsedata["bin_response_data"] = Encoding.UTF8.GetBytes(OSDParser.SerializeLLSDXmlString(events));
  402. //m_log.DebugFormat("[EVENTQUEUE]: sending response for {0} in region {1}: {2}", pAgentId, m_scene.RegionInfo.RegionName, responsedata["str_response_string"]);
  403. return responsedata;
  404. }
  405. public Hashtable NoEvents(UUID requestID, UUID agentID)
  406. {
  407. Hashtable responsedata = new Hashtable();
  408. responsedata["int_response_code"] = 502;
  409. responsedata["content_type"] = "text/plain";
  410. responsedata["str_response_string"] = "<llsd></llsd>";
  411. responsedata["error_status_text"] = "<llsd></llsd>";
  412. responsedata["http_protocol_version"] = "HTTP/1.0";
  413. responsedata["keepalive"] = false;
  414. return responsedata;
  415. }
  416. /* this is not a event message
  417. public void DisableSimulator(ulong handle, UUID avatarID)
  418. {
  419. OSD item = EventQueueHelper.DisableSimulator(handle);
  420. Enqueue(item, avatarID);
  421. }
  422. */
  423. public StringBuilder StartEvent(string eventName)
  424. {
  425. StringBuilder sb = new StringBuilder(256);
  426. LLSDxmlEncode.AddMap(sb);
  427. LLSDxmlEncode.AddElem("message", eventName, sb);
  428. LLSDxmlEncode.AddMap("body", sb);
  429. return sb;
  430. }
  431. public string EndEvent(StringBuilder sb)
  432. {
  433. LLSDxmlEncode.AddEndMap(sb); // close body
  434. LLSDxmlEncode.AddEndMap(sb); // close event
  435. return sb.ToString();
  436. }
  437. public virtual void EnableSimulator(ulong handle, IPEndPoint endPoint, UUID avatarID, int regionSizeX, int regionSizeY)
  438. {
  439. if (DebugLevel > 0)
  440. m_log.DebugFormat("{0} EnableSimulator. handle={1}, endPoint={2}, avatarID={3}",
  441. LogHeader, handle, endPoint, avatarID, regionSizeX, regionSizeY);
  442. StringBuilder sb = StartEvent("EnableSimulator");
  443. LLSDxmlEncode.AddArrayAndMap("SimulatorInfo", sb);
  444. LLSDxmlEncode.AddElem("Handle", handle, sb);
  445. LLSDxmlEncode.AddElem("IP", endPoint.Address.GetAddressBytes(), sb);
  446. LLSDxmlEncode.AddElem("Port", endPoint.Port, sb);
  447. LLSDxmlEncode.AddElem("RegionSizeX", (uint)regionSizeX, sb);
  448. LLSDxmlEncode.AddElem("RegionSizeY", (uint)regionSizeY, sb);
  449. LLSDxmlEncode.AddEndMapAndArray(sb);
  450. OSD item = new OSDllsdxml(EndEvent(sb));
  451. Enqueue(item, avatarID);
  452. }
  453. public virtual void EstablishAgentCommunication(UUID avatarID, IPEndPoint endPoint, string capsPath,
  454. ulong regionHandle, int regionSizeX, int regionSizeY)
  455. {
  456. if (DebugLevel > 0)
  457. m_log.DebugFormat("{0} EstablishAgentCommunication. handle={1}, endPoint={2}, avatarID={3}",
  458. LogHeader, regionHandle, endPoint, avatarID, regionSizeX, regionSizeY);
  459. StringBuilder sb = StartEvent("EstablishAgentCommunication");
  460. LLSDxmlEncode.AddElem("agent-id", avatarID, sb);
  461. LLSDxmlEncode.AddElem("sim-ip-and-port", endPoint.ToString(), sb);
  462. LLSDxmlEncode.AddElem("seed-capability", capsPath, sb);
  463. // current viewers ignore this, also not needed its sent on enablesim
  464. //LLSDxmlEncode.AddElem("region-handle", regionHandle, sb);
  465. //LLSDxmlEncode.AddElem("region-size-x", (uint)regionSizeX, sb);
  466. //LLSDxmlEncode.AddElem("region-size-y", (uint)regionSizeY, sb);
  467. OSD ev = new OSDllsdxml(EndEvent(sb));
  468. Enqueue(ev, avatarID);
  469. }
  470. public virtual void TeleportFinishEvent(ulong regionHandle, byte simAccess,
  471. IPEndPoint regionExternalEndPoint,
  472. uint locationID, uint flags, string capsURL,
  473. UUID avatarID, int regionSizeX, int regionSizeY)
  474. {
  475. if (DebugLevel > 0)
  476. m_log.DebugFormat("{0} TeleportFinishEvent. handle={1}, endPoint={2}, avatarID={3}",
  477. LogHeader, regionHandle, regionExternalEndPoint, avatarID, regionSizeX, regionSizeY);
  478. // not sure why flags get overwritten here
  479. if ((flags & (uint)TeleportFlags.IsFlying) != 0)
  480. flags = (uint)TeleportFlags.ViaLocation | (uint)TeleportFlags.IsFlying;
  481. else
  482. flags = (uint)TeleportFlags.ViaLocation;
  483. StringBuilder sb = StartEvent("TeleportFinish");
  484. LLSDxmlEncode.AddArrayAndMap("Info", sb);
  485. LLSDxmlEncode.AddElem("AgentID", avatarID, sb);
  486. LLSDxmlEncode.AddElem("LocationID", (uint)4, sb); // TODO what is this?
  487. LLSDxmlEncode.AddElem("SimIP", regionExternalEndPoint.Address.GetAddressBytes(), sb);
  488. LLSDxmlEncode.AddElem("SimPort", regionExternalEndPoint.Port, sb);
  489. LLSDxmlEncode.AddElem("RegionHandle", regionHandle, sb);
  490. LLSDxmlEncode.AddElem("SeedCapability", capsURL, sb);
  491. LLSDxmlEncode.AddElem("SimAccess",(int)simAccess, sb);
  492. LLSDxmlEncode.AddElem("TeleportFlags", flags, sb);
  493. LLSDxmlEncode.AddElem("RegionSizeX", (uint)regionSizeX, sb);
  494. LLSDxmlEncode.AddElem("RegionSizeY", (uint)regionSizeY, sb);
  495. LLSDxmlEncode.AddEndMapAndArray(sb);
  496. OSD ev = new OSDllsdxml(EndEvent(sb));
  497. Enqueue(ev, avatarID);
  498. }
  499. public virtual void CrossRegion(ulong handle, Vector3 pos, Vector3 lookAt,
  500. IPEndPoint newRegionExternalEndPoint,
  501. string capsURL, UUID avatarID, UUID sessionID, int regionSizeX, int regionSizeY)
  502. {
  503. if (DebugLevel > 0)
  504. m_log.DebugFormat("{0} CrossRegion. handle={1}, avatarID={2}, regionSize={3},{4}>",
  505. LogHeader, handle, avatarID, regionSizeX, regionSizeY);
  506. StringBuilder sb = StartEvent("CrossedRegion");
  507. LLSDxmlEncode.AddArrayAndMap("AgentData", sb);
  508. LLSDxmlEncode.AddElem("AgentID", avatarID, sb);
  509. LLSDxmlEncode.AddElem("SessionID", sessionID, sb);
  510. LLSDxmlEncode.AddEndMapAndArray(sb);
  511. LLSDxmlEncode.AddArrayAndMap("Info", sb);
  512. LLSDxmlEncode.AddElem("LookAt", lookAt, sb);
  513. LLSDxmlEncode.AddElem("Position", pos, sb);
  514. LLSDxmlEncode.AddEndMapAndArray(sb);
  515. LLSDxmlEncode.AddArrayAndMap("RegionData", sb);
  516. LLSDxmlEncode.AddElem("RegionHandle", handle, sb);
  517. LLSDxmlEncode.AddElem("SeedCapability", capsURL, sb);
  518. LLSDxmlEncode.AddElem("SimIP", newRegionExternalEndPoint.Address.GetAddressBytes(), sb);
  519. LLSDxmlEncode.AddElem("SimPort", newRegionExternalEndPoint.Port, sb);
  520. LLSDxmlEncode.AddElem("RegionSizeX", (uint)regionSizeX, sb);
  521. LLSDxmlEncode.AddElem("RegionSizeY", (uint)regionSizeY, sb);
  522. LLSDxmlEncode.AddEndMapAndArray(sb);
  523. OSD ev = new OSDllsdxml(EndEvent(sb));
  524. Enqueue(ev, avatarID);
  525. }
  526. public void ChatterboxInvitation(UUID sessionID, string sessionName,
  527. UUID fromAgent, string message, UUID toAgent, string fromName, byte dialog,
  528. uint timeStamp, bool offline, int parentEstateID, Vector3 position,
  529. uint ttl, UUID transactionID, bool fromGroup, byte[] binaryBucket)
  530. {
  531. OSD item = EventQueueHelper.ChatterboxInvitation(sessionID, sessionName, fromAgent, message, toAgent, fromName, dialog,
  532. timeStamp, offline, parentEstateID, position, ttl, transactionID,
  533. fromGroup, binaryBucket);
  534. Enqueue(item, toAgent);
  535. //m_log.InfoFormat("########### eq ChatterboxInvitation #############\n{0}", item);
  536. }
  537. public void ChatterBoxSessionAgentListUpdates(UUID sessionID, UUID fromAgent, UUID toAgent, bool canVoiceChat,
  538. bool isModerator, bool textMute, bool isEnterorLeave)
  539. {
  540. OSD item = EventQueueHelper.ChatterBoxSessionAgentListUpdates(sessionID, fromAgent, canVoiceChat,
  541. isModerator, textMute, isEnterorLeave);
  542. Enqueue(item, toAgent);
  543. //m_log.InfoFormat("########### eq ChatterBoxSessionAgentListUpdates #############\n{0}", item);
  544. }
  545. public void ChatterBoxForceClose(UUID toAgent, UUID sessionID, string reason)
  546. {
  547. OSD item = EventQueueHelper.ChatterBoxForceClose(sessionID, reason);
  548. Enqueue(item, toAgent);
  549. }
  550. public void GroupMembershipData(UUID AgentID, GroupMembershipData[] data)
  551. {
  552. StringBuilder sb = StartEvent("AgentGroupDataUpdate");
  553. LLSDxmlEncode.AddArrayAndMap("AgentData", sb);
  554. LLSDxmlEncode.AddElem("AgentID", AgentID, sb);
  555. LLSDxmlEncode.AddEndMapAndArray(sb);
  556. if (data.Length == 0)
  557. {
  558. LLSDxmlEncode.AddEmptyArray("GroupData", sb);
  559. LLSDxmlEncode.AddEmptyArray("NewGroupData", sb);
  560. }
  561. else
  562. {
  563. List<bool> lstInProfiles = new List<bool>(data.Length);
  564. LLSDxmlEncode.AddArray("GroupData", sb);
  565. foreach (GroupMembershipData m in data)
  566. {
  567. LLSDxmlEncode.AddMap(sb);
  568. LLSDxmlEncode.AddElem("GroupID", m.GroupID, sb);
  569. LLSDxmlEncode.AddElem("GroupPowers", m.GroupPowers, sb);
  570. LLSDxmlEncode.AddElem("AcceptNotices", m.AcceptNotices, sb);
  571. LLSDxmlEncode.AddElem("GroupInsigniaID", m.GroupPicture, sb);
  572. LLSDxmlEncode.AddElem("Contribution", m.Contribution, sb);
  573. LLSDxmlEncode.AddElem("GroupName", m.GroupName, sb);
  574. LLSDxmlEncode.AddEndMap(sb);
  575. lstInProfiles.Add(m.ListInProfile);
  576. }
  577. LLSDxmlEncode.AddEndArray(sb);
  578. LLSDxmlEncode.AddArray("NewGroupData", sb);
  579. foreach(bool b in lstInProfiles)
  580. {
  581. LLSDxmlEncode.AddMap(sb);
  582. LLSDxmlEncode.AddElem("ListInProfile", b, sb);
  583. LLSDxmlEncode.AddEndMap(sb);
  584. }
  585. LLSDxmlEncode.AddEndArray(sb);
  586. }
  587. OSD ev = new OSDllsdxml(EndEvent(sb));
  588. Enqueue(ev, AgentID);
  589. }
  590. public void QueryReply(PlacesReplyPacket groupUpdate, UUID avatarID)
  591. {
  592. OSD item = EventQueueHelper.PlacesQuery(groupUpdate);
  593. Enqueue(item, avatarID);
  594. }
  595. public void ScriptRunningEvent(UUID objectID, UUID itemID, bool running, UUID avatarID)
  596. {
  597. StringBuilder sb = StartEvent("ScriptRunningReply");
  598. LLSDxmlEncode.AddArrayAndMap("Script", sb);
  599. LLSDxmlEncode.AddElem("ObjectID", objectID, sb);
  600. LLSDxmlEncode.AddElem("ItemID", itemID, sb);
  601. LLSDxmlEncode.AddElem("Running", running, sb);
  602. LLSDxmlEncode.AddElem("Mono", true, sb);
  603. LLSDxmlEncode.AddEndMapAndArray(sb);
  604. OSDllsdxml item = new OSDllsdxml(EndEvent(sb));
  605. Enqueue(item, avatarID);
  606. }
  607. public void partPhysicsProperties(uint localID, byte physhapetype,
  608. float density, float friction, float bounce, float gravmod,UUID avatarID)
  609. {
  610. StringBuilder sb = StartEvent("ObjectPhysicsProperties");
  611. LLSDxmlEncode.AddArrayAndMap("ObjectData", sb);
  612. LLSDxmlEncode.AddElem("LocalID", (int)localID, sb);
  613. LLSDxmlEncode.AddElem("Density", density, sb);
  614. LLSDxmlEncode.AddElem("Friction", friction, sb);
  615. LLSDxmlEncode.AddElem("GravityMultiplier", gravmod, sb);
  616. LLSDxmlEncode.AddElem("Restitution", bounce, sb);
  617. LLSDxmlEncode.AddElem("PhysicsShapeType", (int)physhapetype, sb);
  618. LLSDxmlEncode.AddEndMapAndArray(sb);
  619. OSDllsdxml item = new OSDllsdxml(EndEvent(sb));
  620. Enqueue(item, avatarID);
  621. }
  622. public OSD BuildEvent(string eventName, OSD eventBody)
  623. {
  624. return EventQueueHelper.BuildEvent(eventName, eventBody);
  625. }
  626. }
  627. }