IOfflineIMService.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.Generic;
  29. using OpenSim.Framework;
  30. using OpenMetaverse;
  31. namespace OpenSim.Services.Interfaces
  32. {
  33. public interface IOfflineIMService
  34. {
  35. List<GridInstantMessage> GetMessages(UUID principalID);
  36. bool StoreMessage(GridInstantMessage im, out string reason);
  37. /// <summary>
  38. /// Delete messages to or from this user (or group).
  39. /// </summary>
  40. /// <param name="userID">A user or group ID</param>
  41. void DeleteMessages(UUID userID);
  42. }
  43. public class OfflineIMDataUtils
  44. {
  45. public static GridInstantMessage GridInstantMessage(Dictionary<string, object> dict)
  46. {
  47. GridInstantMessage im = new GridInstantMessage();
  48. object otmp;
  49. if (dict.TryGetValue("BinaryBucket", out otmp) && otmp is string bbs)
  50. im.binaryBucket = OpenMetaverse.Utils.HexStringToBytes(bbs, true);
  51. if (dict.TryGetValue("Dialog", out otmp) && otmp is string ds)
  52. im.dialog = byte.Parse(ds);
  53. if (dict.TryGetValue("FromAgentID", out otmp) && otmp is string faid)
  54. im.fromAgentID = new Guid(faid);
  55. if (dict.TryGetValue("FromAgentName", out otmp) && otmp is string fan)
  56. im.fromAgentName = fan;
  57. else
  58. im.fromAgentName = string.Empty;
  59. if (dict.TryGetValue("FromGroup", out otmp) && otmp is string fg)
  60. im.fromGroup = bool.Parse(fg);
  61. if (dict.TryGetValue("SessionID", out otmp) && otmp is string sid)
  62. im.imSessionID = new Guid(sid);
  63. if (dict.TryGetValue("Message", out otmp) && otmp is string msg)
  64. im.message = msg;
  65. else
  66. im.message = string.Empty;
  67. if (dict.TryGetValue("Offline", out otmp) && otmp is string off)
  68. im.offline = byte.Parse(off);
  69. if (dict.TryGetValue("EstateID", out otmp) && otmp is string eid)
  70. im.ParentEstateID = UInt32.Parse(eid);
  71. if (dict.TryGetValue("Position", out otmp) && otmp is string vpos)
  72. im.Position = Vector3.Parse(vpos);
  73. if (dict.TryGetValue("RegionID", out otmp) && otmp is string rid)
  74. im.RegionID = new Guid(rid);
  75. if (dict.TryGetValue("Timestamp", out otmp) && otmp is string ts)
  76. im.timestamp = UInt32.Parse(ts);
  77. if (dict.TryGetValue("ToAgentID", out otmp) && otmp is string tid)
  78. im.toAgentID = new Guid(tid);
  79. return im;
  80. }
  81. public static Dictionary<string, object> GridInstantMessage(GridInstantMessage im)
  82. {
  83. Dictionary<string, object> dict = new Dictionary<string, object>();
  84. dict["BinaryBucket"] = OpenMetaverse.Utils.BytesToHexString(im.binaryBucket, im.binaryBucket.Length, null);
  85. dict["Dialog"] = im.dialog.ToString();
  86. dict["FromAgentID"] = im.fromAgentID.ToString();
  87. dict["FromAgentName"] = im.fromAgentName == null ? string.Empty : im.fromAgentName;
  88. dict["FromGroup"] = im.fromGroup.ToString();
  89. dict["SessionID"] = im.imSessionID.ToString();
  90. dict["Message"] = im.message == null ? string.Empty : im.message;
  91. dict["Offline"] = im.offline.ToString();
  92. dict["EstateID"] = im.ParentEstateID.ToString();
  93. dict["Position"] = im.Position.ToString();
  94. dict["RegionID"] = im.RegionID.ToString();
  95. dict["Timestamp"] = im.timestamp.ToString();
  96. dict["ToAgentID"] = im.toAgentID.ToString();
  97. return dict;
  98. }
  99. }
  100. }