IOfflineIMService.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. if (dict.ContainsKey("BinaryBucket") && dict["BinaryBucket"] != null)
  49. im.binaryBucket = OpenMetaverse.Utils.HexStringToBytes(dict["BinaryBucket"].ToString(), true);
  50. if (dict.ContainsKey("Dialog") && dict["Dialog"] != null)
  51. im.dialog = byte.Parse(dict["Dialog"].ToString());
  52. if (dict.ContainsKey("FromAgentID") && dict["FromAgentID"] != null)
  53. im.fromAgentID = new Guid(dict["FromAgentID"].ToString());
  54. if (dict.ContainsKey("FromAgentName") && dict["FromAgentName"] != null)
  55. im.fromAgentName = dict["FromAgentName"].ToString();
  56. else
  57. im.fromAgentName = string.Empty;
  58. if (dict.ContainsKey("FromGroup") && dict["FromGroup"] != null)
  59. im.fromGroup = bool.Parse(dict["FromGroup"].ToString());
  60. if (dict.ContainsKey("SessionID") && dict["SessionID"] != null)
  61. im.imSessionID = new Guid(dict["SessionID"].ToString());
  62. if (dict.ContainsKey("Message") && dict["Message"] != null)
  63. im.message = dict["Message"].ToString();
  64. else
  65. im.message = string.Empty;
  66. if (dict.ContainsKey("Offline") && dict["Offline"] != null)
  67. im.offline = byte.Parse(dict["Offline"].ToString());
  68. if (dict.ContainsKey("EstateID") && dict["EstateID"] != null)
  69. im.ParentEstateID = UInt32.Parse(dict["EstateID"].ToString());
  70. if (dict.ContainsKey("Position") && dict["Position"] != null)
  71. im.Position = Vector3.Parse(dict["Position"].ToString());
  72. if (dict.ContainsKey("RegionID") && dict["RegionID"] != null)
  73. im.RegionID = new Guid(dict["RegionID"].ToString());
  74. if (dict.ContainsKey("Timestamp") && dict["Timestamp"] != null)
  75. im.timestamp = UInt32.Parse(dict["Timestamp"].ToString());
  76. if (dict.ContainsKey("ToAgentID") && dict["ToAgentID"] != null)
  77. im.toAgentID = new Guid(dict["ToAgentID"].ToString());
  78. return im;
  79. }
  80. public static Dictionary<string, object> GridInstantMessage(GridInstantMessage im)
  81. {
  82. Dictionary<string, object> dict = new Dictionary<string, object>();
  83. dict["BinaryBucket"] = OpenMetaverse.Utils.BytesToHexString(im.binaryBucket, im.binaryBucket.Length, null);
  84. dict["Dialog"] = im.dialog.ToString();
  85. dict["FromAgentID"] = im.fromAgentID.ToString();
  86. dict["FromAgentName"] = im.fromAgentName == null ? string.Empty : im.fromAgentName;
  87. dict["FromGroup"] = im.fromGroup.ToString();
  88. dict["SessionID"] = im.imSessionID.ToString();
  89. dict["Message"] = im.message == null ? string.Empty : im.message;
  90. dict["Offline"] = im.offline.ToString();
  91. dict["EstateID"] = im.ParentEstateID.ToString();
  92. dict["Position"] = im.Position.ToString();
  93. dict["RegionID"] = im.RegionID.ToString();
  94. dict["Timestamp"] = im.timestamp.ToString();
  95. dict["ToAgentID"] = im.toAgentID.ToString();
  96. return dict;
  97. }
  98. }
  99. }