MessageTransferModule.cs 27 KB

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