MessageTransferModule.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  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 log4net;
  33. using Mono.Addins;
  34. using Nini.Config;
  35. using Nwc.XmlRpc;
  36. using OpenMetaverse;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Servers;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  42. using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
  43. using OpenSim.Services.Interfaces;
  44. namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
  45. {
  46. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MessageTransferModule")]
  47. public class MessageTransferModule : ISharedRegionModule, IMessageTransferModule
  48. {
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. private bool m_Enabled = false;
  51. protected string m_MessageKey = String.Empty;
  52. protected List<Scene> m_Scenes = new List<Scene>();
  53. protected Dictionary<UUID, UUID> m_UserRegionMap = new Dictionary<UUID, UUID>();
  54. public event UndeliveredMessage OnUndeliveredMessage;
  55. private IPresenceService m_PresenceService;
  56. protected IPresenceService PresenceService
  57. {
  58. get
  59. {
  60. if (m_PresenceService == null)
  61. m_PresenceService = m_Scenes[0].RequestModuleInterface<IPresenceService>();
  62. return m_PresenceService;
  63. }
  64. }
  65. public virtual void Initialise(IConfigSource config)
  66. {
  67. IConfig cnf = config.Configs["Messaging"];
  68. if (cnf != null)
  69. {
  70. if (cnf.GetString("MessageTransferModule",
  71. "MessageTransferModule") != "MessageTransferModule")
  72. {
  73. return;
  74. }
  75. m_MessageKey = cnf.GetString("MessageKey", String.Empty);
  76. }
  77. m_log.Debug("[MESSAGE TRANSFER]: Module enabled");
  78. m_Enabled = true;
  79. }
  80. public virtual void AddRegion(Scene scene)
  81. {
  82. if (!m_Enabled)
  83. return;
  84. lock (m_Scenes)
  85. {
  86. m_log.Debug("[MESSAGE TRANSFER]: Message transfer module active");
  87. scene.RegisterModuleInterface<IMessageTransferModule>(this);
  88. m_Scenes.Add(scene);
  89. }
  90. }
  91. public virtual void PostInitialise()
  92. {
  93. if (!m_Enabled)
  94. return;
  95. MainServer.Instance.AddXmlRPCHandler(
  96. "grid_instant_message", processXMLRPCGridInstantMessage);
  97. }
  98. public virtual void RegionLoaded(Scene scene)
  99. {
  100. }
  101. public virtual void RemoveRegion(Scene scene)
  102. {
  103. if (!m_Enabled)
  104. return;
  105. lock (m_Scenes)
  106. {
  107. m_Scenes.Remove(scene);
  108. }
  109. }
  110. public virtual void Close()
  111. {
  112. }
  113. public virtual string Name
  114. {
  115. get { return "MessageTransferModule"; }
  116. }
  117. public virtual Type ReplaceableInterface
  118. {
  119. get { return null; }
  120. }
  121. public virtual void SendInstantMessage(GridInstantMessage im, MessageResultNotification result)
  122. {
  123. UUID toAgentID = new UUID(im.toAgentID);
  124. if (toAgentID == UUID.Zero)
  125. return;
  126. IClientAPI client = null;
  127. // Try root avatar only first
  128. foreach (Scene scene in m_Scenes)
  129. {
  130. ScenePresence sp = scene.GetScenePresence(toAgentID);
  131. if (sp != null && !sp.IsDeleted && sp.ControllingClient.IsActive)
  132. {
  133. // actualy don't send via child agents
  134. // ims can be complex things, and not sure viewers will not mess up
  135. if(sp.IsChildAgent)
  136. continue;
  137. client = sp.ControllingClient;
  138. if(!sp.IsChildAgent)
  139. break;
  140. }
  141. }
  142. if(client != null)
  143. {
  144. // Local message
  145. // m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to root agent {0} {1}", sp.Name, toAgentID);
  146. client.SendInstantMessage(im);
  147. // Message sent
  148. result(true);
  149. return;
  150. }
  151. // m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to {0} via XMLRPC", im.toAgentID);
  152. SendGridInstantMessageViaXMLRPC(im, result);
  153. }
  154. public virtual void HandleUndeliverableMessage(GridInstantMessage im, MessageResultNotification result)
  155. {
  156. UndeliveredMessage handlerUndeliveredMessage = OnUndeliveredMessage;
  157. // If this event has handlers, then an IM from an agent will be
  158. // considered delivered. This will suppress the error message.
  159. //
  160. if (handlerUndeliveredMessage != null)
  161. {
  162. handlerUndeliveredMessage(im);
  163. if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent)
  164. result(true);
  165. else
  166. result(false);
  167. return;
  168. }
  169. //m_log.DebugFormat("[INSTANT MESSAGE]: Undeliverable");
  170. result(false);
  171. }
  172. /// <summary>
  173. /// Process a XMLRPC Grid Instant Message
  174. /// </summary>
  175. /// <param name="request">XMLRPC parameters
  176. /// </param>
  177. /// <returns>Nothing much</returns>
  178. protected virtual XmlRpcResponse processXMLRPCGridInstantMessage(XmlRpcRequest request, IPEndPoint remoteClient)
  179. {
  180. bool successful = false;
  181. // TODO: For now, as IMs seem to be a bit unreliable on OSGrid, catch all exception that
  182. // happen here and aren't caught and log them.
  183. try
  184. {
  185. // various rational defaults
  186. UUID fromAgentID = UUID.Zero;
  187. UUID toAgentID = UUID.Zero;
  188. UUID imSessionID = UUID.Zero;
  189. uint timestamp = 0;
  190. string fromAgentName = "";
  191. string message = "";
  192. byte dialog = (byte)0;
  193. bool fromGroup = false;
  194. byte offline = (byte)0;
  195. uint ParentEstateID=0;
  196. Vector3 Position = Vector3.Zero;
  197. UUID RegionID = UUID.Zero ;
  198. byte[] binaryBucket = new byte[0];
  199. float pos_x = 0;
  200. float pos_y = 0;
  201. float pos_z = 0;
  202. //m_log.Info("Processing IM");
  203. Hashtable requestData = (Hashtable)request.Params[0];
  204. // Check if it's got all the data
  205. if (requestData.ContainsKey("from_agent_id")
  206. && requestData.ContainsKey("to_agent_id") && requestData.ContainsKey("im_session_id")
  207. && requestData.ContainsKey("timestamp") && requestData.ContainsKey("from_agent_name")
  208. && requestData.ContainsKey("message") && requestData.ContainsKey("dialog")
  209. && requestData.ContainsKey("from_group")
  210. && requestData.ContainsKey("offline") && requestData.ContainsKey("parent_estate_id")
  211. && requestData.ContainsKey("position_x") && requestData.ContainsKey("position_y")
  212. && requestData.ContainsKey("position_z") && requestData.ContainsKey("region_id")
  213. && requestData.ContainsKey("binary_bucket"))
  214. {
  215. if (m_MessageKey != String.Empty)
  216. {
  217. XmlRpcResponse error_resp = new XmlRpcResponse();
  218. Hashtable error_respdata = new Hashtable();
  219. error_respdata["success"] = "FALSE";
  220. error_resp.Value = error_respdata;
  221. if (!requestData.Contains("message_key"))
  222. return error_resp;
  223. if (m_MessageKey != (string)requestData["message_key"])
  224. return error_resp;
  225. }
  226. // Do the easy way of validating the UUIDs
  227. UUID.TryParse((string)requestData["from_agent_id"], out fromAgentID);
  228. UUID.TryParse((string)requestData["to_agent_id"], out toAgentID);
  229. UUID.TryParse((string)requestData["im_session_id"], out imSessionID);
  230. UUID.TryParse((string)requestData["region_id"], out RegionID);
  231. try
  232. {
  233. timestamp = (uint)Convert.ToInt32((string)requestData["timestamp"]);
  234. }
  235. catch (ArgumentException)
  236. {
  237. }
  238. catch (FormatException)
  239. {
  240. }
  241. catch (OverflowException)
  242. {
  243. }
  244. fromAgentName = (string)requestData["from_agent_name"];
  245. message = (string)requestData["message"];
  246. if (message == null)
  247. message = string.Empty;
  248. // Bytes don't transfer well over XMLRPC, so, we Base64 Encode them.
  249. string requestData1 = (string)requestData["dialog"];
  250. if (string.IsNullOrEmpty(requestData1))
  251. {
  252. dialog = 0;
  253. }
  254. else
  255. {
  256. byte[] dialogdata = Convert.FromBase64String(requestData1);
  257. dialog = dialogdata[0];
  258. }
  259. if ((string)requestData["from_group"] == "TRUE")
  260. fromGroup = true;
  261. string requestData2 = (string)requestData["offline"];
  262. if (String.IsNullOrEmpty(requestData2))
  263. {
  264. offline = 0;
  265. }
  266. else
  267. {
  268. byte[] offlinedata = Convert.FromBase64String(requestData2);
  269. offline = offlinedata[0];
  270. }
  271. try
  272. {
  273. ParentEstateID = (uint)Convert.ToInt32((string)requestData["parent_estate_id"]);
  274. }
  275. catch (ArgumentException)
  276. {
  277. }
  278. catch (FormatException)
  279. {
  280. }
  281. catch (OverflowException)
  282. {
  283. }
  284. try
  285. {
  286. pos_x = (uint)Convert.ToInt32((string)requestData["position_x"]);
  287. }
  288. catch (ArgumentException)
  289. {
  290. }
  291. catch (FormatException)
  292. {
  293. }
  294. catch (OverflowException)
  295. {
  296. }
  297. try
  298. {
  299. pos_y = (uint)Convert.ToInt32((string)requestData["position_y"]);
  300. }
  301. catch (ArgumentException)
  302. {
  303. }
  304. catch (FormatException)
  305. {
  306. }
  307. catch (OverflowException)
  308. {
  309. }
  310. try
  311. {
  312. pos_z = (uint)Convert.ToInt32((string)requestData["position_z"]);
  313. }
  314. catch (ArgumentException)
  315. {
  316. }
  317. catch (FormatException)
  318. {
  319. }
  320. catch (OverflowException)
  321. {
  322. }
  323. Position = new Vector3(pos_x, pos_y, pos_z);
  324. string requestData3 = (string)requestData["binary_bucket"];
  325. if (string.IsNullOrEmpty(requestData3))
  326. {
  327. binaryBucket = new byte[0];
  328. }
  329. else
  330. {
  331. binaryBucket = Convert.FromBase64String(requestData3);
  332. }
  333. // Create a New GridInstantMessageObject the the data
  334. GridInstantMessage gim = new GridInstantMessage();
  335. gim.fromAgentID = fromAgentID.Guid;
  336. gim.fromAgentName = fromAgentName;
  337. gim.fromGroup = fromGroup;
  338. gim.imSessionID = imSessionID.Guid;
  339. gim.RegionID = RegionID.Guid;
  340. gim.timestamp = timestamp;
  341. gim.toAgentID = toAgentID.Guid;
  342. gim.message = message;
  343. gim.dialog = dialog;
  344. gim.offline = offline;
  345. gim.ParentEstateID = ParentEstateID;
  346. gim.Position = Position;
  347. gim.binaryBucket = binaryBucket;
  348. // Trigger the Instant message in the scene.
  349. foreach (Scene scene in m_Scenes)
  350. {
  351. ScenePresence sp = scene.GetScenePresence(toAgentID);
  352. if (sp != null && !sp.IsChildAgent)
  353. {
  354. scene.EventManager.TriggerIncomingInstantMessage(gim);
  355. successful = true;
  356. }
  357. }
  358. if (!successful)
  359. {
  360. // If the message can't be delivered to an agent, it
  361. // is likely to be a group IM. On a group IM, the
  362. // imSessionID = toAgentID = group id. Raise the
  363. // unhandled IM event to give the groups module
  364. // a chance to pick it up. We raise that in a random
  365. // scene, since the groups module is shared.
  366. //
  367. m_Scenes[0].EventManager.TriggerUnhandledInstantMessage(gim);
  368. }
  369. }
  370. }
  371. catch (Exception e)
  372. {
  373. m_log.Error("[INSTANT MESSAGE]: Caught unexpected exception:", e);
  374. successful = false;
  375. }
  376. //Send response back to region calling if it was successful
  377. // calling region uses this to know when to look up a user's location again.
  378. XmlRpcResponse resp = new XmlRpcResponse();
  379. Hashtable respdata = new Hashtable();
  380. if (successful)
  381. respdata["success"] = "TRUE";
  382. else
  383. respdata["success"] = "FALSE";
  384. resp.Value = respdata;
  385. return resp;
  386. }
  387. /// <summary>
  388. /// delegate for sending a grid instant message asynchronously
  389. /// </summary>
  390. private delegate void GridInstantMessageDelegate(GridInstantMessage im, MessageResultNotification result);
  391. private class GIM {
  392. public GridInstantMessage im;
  393. public MessageResultNotification result;
  394. };
  395. private Queue<GIM> pendingInstantMessages = new Queue<GIM>();
  396. private int numInstantMessageThreads = 0;
  397. private void SendGridInstantMessageViaXMLRPC(GridInstantMessage im, MessageResultNotification result)
  398. {
  399. lock (pendingInstantMessages) {
  400. if (numInstantMessageThreads >= 4) {
  401. GIM gim = new GIM();
  402. gim.im = im;
  403. gim.result = result;
  404. pendingInstantMessages.Enqueue(gim);
  405. } else {
  406. ++ numInstantMessageThreads;
  407. //m_log.DebugFormat("[SendGridInstantMessageViaXMLRPC]: ++numInstantMessageThreads={0}", numInstantMessageThreads);
  408. GridInstantMessageDelegate d = SendGridInstantMessageViaXMLRPCAsyncMain;
  409. d.BeginInvoke(im, result, GridInstantMessageCompleted, d);
  410. }
  411. }
  412. }
  413. private void GridInstantMessageCompleted(IAsyncResult iar)
  414. {
  415. GridInstantMessageDelegate d = (GridInstantMessageDelegate)iar.AsyncState;
  416. d.EndInvoke(iar);
  417. }
  418. /// <summary>
  419. /// Internal SendGridInstantMessage over XMLRPC method.
  420. /// </summary>
  421. /// <param name="prevRegionHandle">
  422. /// Pass in 0 the first time this method is called. It will be called recursively with the last
  423. /// regionhandle tried
  424. /// </param>
  425. private void SendGridInstantMessageViaXMLRPCAsyncMain(GridInstantMessage im, MessageResultNotification result)
  426. {
  427. GIM gim;
  428. do {
  429. try {
  430. SendGridInstantMessageViaXMLRPCAsync(im, result, UUID.Zero);
  431. } catch (Exception e) {
  432. m_log.Error("[SendGridInstantMessageViaXMLRPC]: exception " + e.Message);
  433. }
  434. lock (pendingInstantMessages) {
  435. if (pendingInstantMessages.Count > 0) {
  436. gim = pendingInstantMessages.Dequeue();
  437. im = gim.im;
  438. result = gim.result;
  439. } else {
  440. gim = null;
  441. -- numInstantMessageThreads;
  442. //m_log.DebugFormat("[SendGridInstantMessageViaXMLRPC]: --numInstantMessageThreads={0}", numInstantMessageThreads);
  443. }
  444. }
  445. } while (gim != null);
  446. }
  447. private void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result, UUID prevRegionID)
  448. {
  449. UUID toAgentID = new UUID(im.toAgentID);
  450. PresenceInfo upd = null;
  451. bool lookupAgent = false;
  452. lock (m_UserRegionMap)
  453. {
  454. if (m_UserRegionMap.ContainsKey(toAgentID))
  455. {
  456. upd = new PresenceInfo();
  457. upd.RegionID = m_UserRegionMap[toAgentID];
  458. // We need to compare the current regionhandle with the previous region handle
  459. // or the recursive loop will never end because it will never try to lookup the agent again
  460. if (prevRegionID == upd.RegionID)
  461. {
  462. lookupAgent = true;
  463. }
  464. }
  465. else
  466. {
  467. lookupAgent = true;
  468. }
  469. }
  470. // Are we needing to look-up an agent?
  471. if (lookupAgent)
  472. {
  473. // Non-cached user agent lookup.
  474. PresenceInfo[] presences = PresenceService.GetAgents(new string[] { toAgentID.ToString() });
  475. if (presences != null && presences.Length > 0)
  476. {
  477. foreach (PresenceInfo p in presences)
  478. {
  479. if (p.RegionID != UUID.Zero)
  480. {
  481. upd = p;
  482. break;
  483. }
  484. }
  485. }
  486. if (upd != null)
  487. {
  488. // check if we've tried this before..
  489. // This is one way to end the recursive loop
  490. //
  491. if (upd.RegionID == prevRegionID)
  492. {
  493. // m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message");
  494. HandleUndeliverableMessage(im, result);
  495. return;
  496. }
  497. }
  498. else
  499. {
  500. // m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message");
  501. HandleUndeliverableMessage(im, result);
  502. return;
  503. }
  504. }
  505. if (upd != null)
  506. {
  507. GridRegion reginfo = m_Scenes[0].GridService.GetRegionByUUID(UUID.Zero,
  508. upd.RegionID);
  509. if (reginfo != null)
  510. {
  511. Hashtable msgdata = ConvertGridInstantMessageToXMLRPC(im);
  512. // Not actually used anymore, left in for compatibility
  513. // Remove at next interface change
  514. //
  515. msgdata["region_handle"] = 0;
  516. bool imresult = doIMSending(reginfo, msgdata);
  517. if (imresult)
  518. {
  519. // IM delivery successful, so store the Agent's location in our local cache.
  520. lock (m_UserRegionMap)
  521. {
  522. if (m_UserRegionMap.ContainsKey(toAgentID))
  523. {
  524. m_UserRegionMap[toAgentID] = upd.RegionID;
  525. }
  526. else
  527. {
  528. m_UserRegionMap.Add(toAgentID, upd.RegionID);
  529. }
  530. }
  531. result(true);
  532. }
  533. else
  534. {
  535. // try again, but lookup user this time.
  536. // Warning, this must call the Async version
  537. // of this method or we'll be making thousands of threads
  538. // The version within the spawned thread is SendGridInstantMessageViaXMLRPCAsync
  539. // The version that spawns the thread is SendGridInstantMessageViaXMLRPC
  540. // This is recursive!!!!!
  541. SendGridInstantMessageViaXMLRPCAsync(im, result,
  542. upd.RegionID);
  543. }
  544. }
  545. else
  546. {
  547. m_log.WarnFormat("[GRID INSTANT MESSAGE]: Unable to find region {0}", upd.RegionID);
  548. HandleUndeliverableMessage(im, result);
  549. }
  550. }
  551. else
  552. {
  553. HandleUndeliverableMessage(im, result);
  554. }
  555. }
  556. /// <summary>
  557. /// This actually does the XMLRPC Request
  558. /// </summary>
  559. /// <param name="reginfo">RegionInfo we pull the data out of to send the request to</param>
  560. /// <param name="xmlrpcdata">The Instant Message data Hashtable</param>
  561. /// <returns>Bool if the message was successfully delivered at the other side.</returns>
  562. protected virtual bool doIMSending(GridRegion reginfo, Hashtable xmlrpcdata)
  563. {
  564. ArrayList SendParams = new ArrayList();
  565. SendParams.Add(xmlrpcdata);
  566. XmlRpcRequest GridReq = new XmlRpcRequest("grid_instant_message", SendParams);
  567. try
  568. {
  569. XmlRpcResponse GridResp = GridReq.Send(reginfo.ServerURI, 3000);
  570. Hashtable responseData = (Hashtable)GridResp.Value;
  571. if (responseData.ContainsKey("success"))
  572. {
  573. if ((string)responseData["success"] == "TRUE")
  574. {
  575. return true;
  576. }
  577. else
  578. {
  579. return false;
  580. }
  581. }
  582. else
  583. {
  584. return false;
  585. }
  586. }
  587. catch (WebException e)
  588. {
  589. m_log.ErrorFormat("[GRID INSTANT MESSAGE]: Error sending message to {0} the host didn't respond " + e.ToString(), reginfo.ServerURI.ToString());
  590. }
  591. return false;
  592. }
  593. /// <summary>
  594. /// Get ulong region handle for region by it's Region UUID.
  595. /// We use region handles over grid comms because there's all sorts of free and cool caching.
  596. /// </summary>
  597. /// <param name="regionID">UUID of region to get the region handle for</param>
  598. /// <returns></returns>
  599. // private virtual ulong getLocalRegionHandleFromUUID(UUID regionID)
  600. // {
  601. // ulong returnhandle = 0;
  602. //
  603. // lock (m_Scenes)
  604. // {
  605. // foreach (Scene sn in m_Scenes)
  606. // {
  607. // if (sn.RegionInfo.RegionID == regionID)
  608. // {
  609. // returnhandle = sn.RegionInfo.RegionHandle;
  610. // break;
  611. // }
  612. // }
  613. // }
  614. // return returnhandle;
  615. // }
  616. /// <summary>
  617. /// Takes a GridInstantMessage and converts it into a Hashtable for XMLRPC
  618. /// </summary>
  619. /// <param name="msg">The GridInstantMessage object</param>
  620. /// <returns>Hashtable containing the XMLRPC request</returns>
  621. protected virtual Hashtable ConvertGridInstantMessageToXMLRPC(GridInstantMessage msg)
  622. {
  623. Hashtable gim = new Hashtable();
  624. gim["from_agent_id"] = msg.fromAgentID.ToString();
  625. // Kept for compatibility
  626. gim["from_agent_session"] = UUID.Zero.ToString();
  627. gim["to_agent_id"] = msg.toAgentID.ToString();
  628. gim["im_session_id"] = msg.imSessionID.ToString();
  629. gim["timestamp"] = msg.timestamp.ToString();
  630. gim["from_agent_name"] = msg.fromAgentName;
  631. gim["message"] = msg.message;
  632. byte[] dialogdata = new byte[1];dialogdata[0] = msg.dialog;
  633. gim["dialog"] = Convert.ToBase64String(dialogdata,Base64FormattingOptions.None);
  634. if (msg.fromGroup)
  635. gim["from_group"] = "TRUE";
  636. else
  637. gim["from_group"] = "FALSE";
  638. byte[] offlinedata = new byte[1]; offlinedata[0] = msg.offline;
  639. gim["offline"] = Convert.ToBase64String(offlinedata, Base64FormattingOptions.None);
  640. gim["parent_estate_id"] = msg.ParentEstateID.ToString();
  641. gim["position_x"] = msg.Position.X.ToString();
  642. gim["position_y"] = msg.Position.Y.ToString();
  643. gim["position_z"] = msg.Position.Z.ToString();
  644. gim["region_id"] = new UUID(msg.RegionID).ToString();
  645. gim["binary_bucket"] = Convert.ToBase64String(msg.binaryBucket,Base64FormattingOptions.None);
  646. if (m_MessageKey != String.Empty)
  647. gim["message_key"] = m_MessageKey;
  648. return gim;
  649. }
  650. }
  651. }