EventQueueGetModule.cs 29 KB

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