MessageTransferModule.cs 27 KB

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