MessageTransferModule.cs 26 KB

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