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.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. m_log.DebugFormat("[INSTANT MESSAGE]: Attempting delivery of IM from {0} to {1}", im.fromAgentName, toAgentID.ToString());
  118. // Try root avatar only first
  119. foreach (Scene scene in m_Scenes)
  120. {
  121. if (scene.Entities.ContainsKey(toAgentID) &&
  122. scene.Entities[toAgentID] is ScenePresence)
  123. {
  124. m_log.DebugFormat("[INSTANT MESSAGE]: Looking for {0} in {1}", toAgentID.ToString(), scene.RegionInfo.RegionName);
  125. // Local message
  126. ScenePresence user = (ScenePresence) scene.Entities[toAgentID];
  127. if (!user.IsChildAgent)
  128. {
  129. m_log.DebugFormat("[INSTANT MESSAGE]: Delivering to client");
  130. user.ControllingClient.SendInstantMessage(im);
  131. // Message sent
  132. result(true);
  133. return;
  134. }
  135. }
  136. }
  137. // try child avatar second
  138. foreach (Scene scene in m_Scenes)
  139. {
  140. // m_log.DebugFormat(
  141. // "[INSTANT MESSAGE]: Looking for child of {0} in {1}", toAgentID, scene.RegionInfo.RegionName);
  142. if (scene.Entities.ContainsKey(toAgentID) &&
  143. scene.Entities[toAgentID] is ScenePresence)
  144. {
  145. // Local message
  146. ScenePresence user = (ScenePresence) scene.Entities[toAgentID];
  147. m_log.DebugFormat("[INSTANT MESSAGE]: Delivering to client");
  148. user.ControllingClient.SendInstantMessage(im);
  149. // Message sent
  150. result(true);
  151. return;
  152. }
  153. }
  154. SendGridInstantMessageViaXMLRPC(im, result);
  155. return;
  156. }
  157. private void HandleUndeliveredMessage(GridInstantMessage im, MessageResultNotification result)
  158. {
  159. UndeliveredMessage handlerUndeliveredMessage = OnUndeliveredMessage;
  160. // If this event has handlers, then the IM will be considered
  161. // delivered. This will suppress the error message.
  162. //
  163. if (handlerUndeliveredMessage != null)
  164. {
  165. handlerUndeliveredMessage(im);
  166. result(true);
  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. // Do the easy way of validating the UUIDs
  216. UUID.TryParse((string)requestData["from_agent_id"], out fromAgentID);
  217. UUID.TryParse((string)requestData["to_agent_id"], out toAgentID);
  218. UUID.TryParse((string)requestData["im_session_id"], out imSessionID);
  219. UUID.TryParse((string)requestData["region_id"], out RegionID);
  220. try
  221. {
  222. timestamp = (uint)Convert.ToInt32((string)requestData["timestamp"]);
  223. }
  224. catch (ArgumentException)
  225. {
  226. }
  227. catch (FormatException)
  228. {
  229. }
  230. catch (OverflowException)
  231. {
  232. }
  233. fromAgentName = (string)requestData["from_agent_name"];
  234. message = (string)requestData["message"];
  235. if (message == null)
  236. message = string.Empty;
  237. // Bytes don't transfer well over XMLRPC, so, we Base64 Encode them.
  238. string requestData1 = (string)requestData["dialog"];
  239. if (string.IsNullOrEmpty(requestData1))
  240. {
  241. dialog = 0;
  242. }
  243. else
  244. {
  245. byte[] dialogdata = Convert.FromBase64String(requestData1);
  246. dialog = dialogdata[0];
  247. }
  248. if ((string)requestData["from_group"] == "TRUE")
  249. fromGroup = true;
  250. string requestData2 = (string)requestData["offline"];
  251. if (String.IsNullOrEmpty(requestData2))
  252. {
  253. offline = 0;
  254. }
  255. else
  256. {
  257. byte[] offlinedata = Convert.FromBase64String(requestData2);
  258. offline = offlinedata[0];
  259. }
  260. try
  261. {
  262. ParentEstateID = (uint)Convert.ToInt32((string)requestData["parent_estate_id"]);
  263. }
  264. catch (ArgumentException)
  265. {
  266. }
  267. catch (FormatException)
  268. {
  269. }
  270. catch (OverflowException)
  271. {
  272. }
  273. try
  274. {
  275. pos_x = (uint)Convert.ToInt32((string)requestData["position_x"]);
  276. }
  277. catch (ArgumentException)
  278. {
  279. }
  280. catch (FormatException)
  281. {
  282. }
  283. catch (OverflowException)
  284. {
  285. }
  286. try
  287. {
  288. pos_y = (uint)Convert.ToInt32((string)requestData["position_y"]);
  289. }
  290. catch (ArgumentException)
  291. {
  292. }
  293. catch (FormatException)
  294. {
  295. }
  296. catch (OverflowException)
  297. {
  298. }
  299. try
  300. {
  301. pos_z = (uint)Convert.ToInt32((string)requestData["position_z"]);
  302. }
  303. catch (ArgumentException)
  304. {
  305. }
  306. catch (FormatException)
  307. {
  308. }
  309. catch (OverflowException)
  310. {
  311. }
  312. Position = new Vector3(pos_x, pos_y, pos_z);
  313. string requestData3 = (string)requestData["binary_bucket"];
  314. if (string.IsNullOrEmpty(requestData3))
  315. {
  316. binaryBucket = new byte[0];
  317. }
  318. else
  319. {
  320. binaryBucket = Convert.FromBase64String(requestData3);
  321. }
  322. // Create a New GridInstantMessageObject the the data
  323. GridInstantMessage gim = new GridInstantMessage();
  324. gim.fromAgentID = fromAgentID.Guid;
  325. gim.fromAgentName = fromAgentName;
  326. gim.fromGroup = fromGroup;
  327. gim.imSessionID = imSessionID.Guid;
  328. gim.RegionID = RegionID.Guid;
  329. gim.timestamp = timestamp;
  330. gim.toAgentID = toAgentID.Guid;
  331. gim.message = message;
  332. gim.dialog = dialog;
  333. gim.offline = offline;
  334. gim.ParentEstateID = ParentEstateID;
  335. gim.Position = Position;
  336. gim.binaryBucket = binaryBucket;
  337. // Trigger the Instant message in the scene.
  338. foreach (Scene scene in m_Scenes)
  339. {
  340. if (scene.Entities.ContainsKey(toAgentID) &&
  341. scene.Entities[toAgentID] is ScenePresence)
  342. {
  343. ScenePresence user =
  344. (ScenePresence)scene.Entities[toAgentID];
  345. if (!user.IsChildAgent)
  346. {
  347. scene.EventManager.TriggerIncomingInstantMessage(gim);
  348. successful = true;
  349. }
  350. }
  351. }
  352. if (!successful)
  353. {
  354. // If the message can't be delivered to an agent, it
  355. // is likely to be a group IM. On a group IM, the
  356. // imSessionID = toAgentID = group id. Raise the
  357. // unhandled IM event to give the groups module
  358. // a chance to pick it up. We raise that in a random
  359. // scene, since the groups module is shared.
  360. //
  361. m_Scenes[0].EventManager.TriggerUnhandledInstantMessage(gim);
  362. }
  363. }
  364. }
  365. catch (Exception e)
  366. {
  367. m_log.Error("[INSTANT MESSAGE]: Caught unexpected exception:", e);
  368. successful = false;
  369. }
  370. //Send response back to region calling if it was successful
  371. // calling region uses this to know when to look up a user's location again.
  372. XmlRpcResponse resp = new XmlRpcResponse();
  373. Hashtable respdata = new Hashtable();
  374. if (successful)
  375. respdata["success"] = "TRUE";
  376. else
  377. respdata["success"] = "FALSE";
  378. resp.Value = respdata;
  379. return resp;
  380. }
  381. /// <summary>
  382. /// delegate for sending a grid instant message asynchronously
  383. /// </summary>
  384. public delegate void GridInstantMessageDelegate(GridInstantMessage im, MessageResultNotification result, UUID prevRegionID);
  385. protected virtual void GridInstantMessageCompleted(IAsyncResult iar)
  386. {
  387. GridInstantMessageDelegate icon =
  388. (GridInstantMessageDelegate)iar.AsyncState;
  389. icon.EndInvoke(iar);
  390. }
  391. protected virtual void SendGridInstantMessageViaXMLRPC(GridInstantMessage im, MessageResultNotification result)
  392. {
  393. GridInstantMessageDelegate d = SendGridInstantMessageViaXMLRPCAsync;
  394. d.BeginInvoke(im, result, UUID.Zero, GridInstantMessageCompleted, d);
  395. }
  396. /// <summary>
  397. /// Recursive SendGridInstantMessage over XMLRPC method.
  398. /// This is called from within a dedicated thread.
  399. /// The first time this is called, prevRegionHandle will be 0 Subsequent times this is called from
  400. /// itself, prevRegionHandle will be the last region handle that we tried to send.
  401. /// If the handles are the same, we look up the user's location using the grid.
  402. /// If the handles are still the same, we end. The send failed.
  403. /// </summary>
  404. /// <param name="prevRegionHandle">
  405. /// Pass in 0 the first time this method is called. It will be called recursively with the last
  406. /// regionhandle tried
  407. /// </param>
  408. protected virtual void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result, UUID prevRegionID)
  409. {
  410. UUID toAgentID = new UUID(im.toAgentID);
  411. PresenceInfo upd = null;
  412. bool lookupAgent = false;
  413. lock (m_UserRegionMap)
  414. {
  415. if (m_UserRegionMap.ContainsKey(toAgentID))
  416. {
  417. upd = new PresenceInfo();
  418. upd.RegionID = m_UserRegionMap[toAgentID];
  419. // We need to compare the current regionhandle with the previous region handle
  420. // or the recursive loop will never end because it will never try to lookup the agent again
  421. if (prevRegionID == upd.RegionID)
  422. {
  423. lookupAgent = true;
  424. }
  425. }
  426. else
  427. {
  428. lookupAgent = true;
  429. }
  430. }
  431. // Are we needing to look-up an agent?
  432. if (lookupAgent)
  433. {
  434. // Non-cached user agent lookup.
  435. PresenceInfo[] presences = PresenceService.GetAgents(new string[] { toAgentID.ToString() });
  436. if (presences != null && presences.Length > 0)
  437. upd = presences[0];
  438. if (upd != null)
  439. {
  440. // check if we've tried this before..
  441. // This is one way to end the recursive loop
  442. //
  443. if (upd.RegionID == prevRegionID)
  444. {
  445. m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message");
  446. HandleUndeliveredMessage(im, result);
  447. return;
  448. }
  449. }
  450. else
  451. {
  452. m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message");
  453. HandleUndeliveredMessage(im, result);
  454. return;
  455. }
  456. }
  457. if (upd != null)
  458. {
  459. GridRegion reginfo = m_Scenes[0].GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID,
  460. upd.RegionID);
  461. if (reginfo != null)
  462. {
  463. Hashtable msgdata = ConvertGridInstantMessageToXMLRPC(im);
  464. // Not actually used anymore, left in for compatibility
  465. // Remove at next interface change
  466. //
  467. msgdata["region_handle"] = 0;
  468. bool imresult = doIMSending(reginfo, msgdata);
  469. if (imresult)
  470. {
  471. // IM delivery successful, so store the Agent's location in our local cache.
  472. lock (m_UserRegionMap)
  473. {
  474. if (m_UserRegionMap.ContainsKey(toAgentID))
  475. {
  476. m_UserRegionMap[toAgentID] = upd.RegionID;
  477. }
  478. else
  479. {
  480. m_UserRegionMap.Add(toAgentID, upd.RegionID);
  481. }
  482. }
  483. result(true);
  484. }
  485. else
  486. {
  487. // try again, but lookup user this time.
  488. // Warning, this must call the Async version
  489. // of this method or we'll be making thousands of threads
  490. // The version within the spawned thread is SendGridInstantMessageViaXMLRPCAsync
  491. // The version that spawns the thread is SendGridInstantMessageViaXMLRPC
  492. // This is recursive!!!!!
  493. SendGridInstantMessageViaXMLRPCAsync(im, result,
  494. upd.RegionID);
  495. }
  496. }
  497. else
  498. {
  499. m_log.WarnFormat("[GRID INSTANT MESSAGE]: Unable to find region {0}", upd.RegionID);
  500. HandleUndeliveredMessage(im, result);
  501. }
  502. }
  503. else
  504. {
  505. HandleUndeliveredMessage(im, result);
  506. }
  507. }
  508. /// <summary>
  509. /// This actually does the XMLRPC Request
  510. /// </summary>
  511. /// <param name="reginfo">RegionInfo we pull the data out of to send the request to</param>
  512. /// <param name="xmlrpcdata">The Instant Message data Hashtable</param>
  513. /// <returns>Bool if the message was successfully delivered at the other side.</returns>
  514. protected virtual bool doIMSending(GridRegion reginfo, Hashtable xmlrpcdata)
  515. {
  516. ArrayList SendParams = new ArrayList();
  517. SendParams.Add(xmlrpcdata);
  518. XmlRpcRequest GridReq = new XmlRpcRequest("grid_instant_message", SendParams);
  519. try
  520. {
  521. XmlRpcResponse GridResp = GridReq.Send("http://" + reginfo.ExternalHostName + ":" + reginfo.HttpPort, 3000);
  522. Hashtable responseData = (Hashtable)GridResp.Value;
  523. if (responseData.ContainsKey("success"))
  524. {
  525. if ((string)responseData["success"] == "TRUE")
  526. {
  527. return true;
  528. }
  529. else
  530. {
  531. return false;
  532. }
  533. }
  534. else
  535. {
  536. return false;
  537. }
  538. }
  539. catch (WebException e)
  540. {
  541. m_log.ErrorFormat("[GRID INSTANT MESSAGE]: Error sending message to http://{0}:{1} the host didn't respond ({2})",
  542. reginfo.ExternalHostName, reginfo.HttpPort, e.Message);
  543. }
  544. return false;
  545. }
  546. /// <summary>
  547. /// Get ulong region handle for region by it's Region UUID.
  548. /// We use region handles over grid comms because there's all sorts of free and cool caching.
  549. /// </summary>
  550. /// <param name="regionID">UUID of region to get the region handle for</param>
  551. /// <returns></returns>
  552. // private virtual ulong getLocalRegionHandleFromUUID(UUID regionID)
  553. // {
  554. // ulong returnhandle = 0;
  555. //
  556. // lock (m_Scenes)
  557. // {
  558. // foreach (Scene sn in m_Scenes)
  559. // {
  560. // if (sn.RegionInfo.RegionID == regionID)
  561. // {
  562. // returnhandle = sn.RegionInfo.RegionHandle;
  563. // break;
  564. // }
  565. // }
  566. // }
  567. // return returnhandle;
  568. // }
  569. /// <summary>
  570. /// Takes a GridInstantMessage and converts it into a Hashtable for XMLRPC
  571. /// </summary>
  572. /// <param name="msg">The GridInstantMessage object</param>
  573. /// <returns>Hashtable containing the XMLRPC request</returns>
  574. protected virtual Hashtable ConvertGridInstantMessageToXMLRPC(GridInstantMessage msg)
  575. {
  576. Hashtable gim = new Hashtable();
  577. gim["from_agent_id"] = msg.fromAgentID.ToString();
  578. // Kept for compatibility
  579. gim["from_agent_session"] = UUID.Zero.ToString();
  580. gim["to_agent_id"] = msg.toAgentID.ToString();
  581. gim["im_session_id"] = msg.imSessionID.ToString();
  582. gim["timestamp"] = msg.timestamp.ToString();
  583. gim["from_agent_name"] = msg.fromAgentName;
  584. gim["message"] = msg.message;
  585. byte[] dialogdata = new byte[1];dialogdata[0] = msg.dialog;
  586. gim["dialog"] = Convert.ToBase64String(dialogdata,Base64FormattingOptions.None);
  587. if (msg.fromGroup)
  588. gim["from_group"] = "TRUE";
  589. else
  590. gim["from_group"] = "FALSE";
  591. byte[] offlinedata = new byte[1]; offlinedata[0] = msg.offline;
  592. gim["offline"] = Convert.ToBase64String(offlinedata, Base64FormattingOptions.None);
  593. gim["parent_estate_id"] = msg.ParentEstateID.ToString();
  594. gim["position_x"] = msg.Position.X.ToString();
  595. gim["position_y"] = msg.Position.Y.ToString();
  596. gim["position_z"] = msg.Position.Z.ToString();
  597. gim["region_id"] = msg.RegionID.ToString();
  598. gim["binary_bucket"] = Convert.ToBase64String(msg.binaryBucket,Base64FormattingOptions.None);
  599. return gim;
  600. }
  601. }
  602. }