FriendsSimConnector.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 System.Reflection;
  30. using OpenSim.Services.Interfaces;
  31. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  32. using OpenSim.Server.Base;
  33. using OpenSim.Framework;
  34. using OpenMetaverse;
  35. using log4net;
  36. namespace OpenSim.Services.Connectors.Friends
  37. {
  38. public class FriendsSimConnector
  39. {
  40. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  41. protected virtual string ServicePath()
  42. {
  43. return "friends";
  44. }
  45. public bool FriendshipOffered(GridRegion region, UUID userID, UUID friendID, string message)
  46. {
  47. return FriendshipOffered(region, userID, friendID, message, String.Empty);
  48. }
  49. public virtual bool FriendshipOffered(GridRegion region, UUID userID, UUID friendID, string message, string userName)
  50. {
  51. Dictionary<string, object> sendData = new Dictionary<string, object>();
  52. //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  53. //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  54. sendData["METHOD"] = "friendship_offered";
  55. sendData["FromID"] = userID.ToString();
  56. sendData["ToID"] = friendID.ToString();
  57. sendData["Message"] = message;
  58. if (userName != String.Empty)
  59. sendData["FromName"] = userName;
  60. return Call(region, sendData);
  61. }
  62. public bool FriendshipApproved(GridRegion region, UUID userID, string userName, UUID friendID)
  63. {
  64. Dictionary<string, object> sendData = new Dictionary<string, object>();
  65. //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  66. //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  67. sendData["METHOD"] = "friendship_approved";
  68. sendData["FromID"] = userID.ToString();
  69. sendData["FromName"] = userName;
  70. sendData["ToID"] = friendID.ToString();
  71. return Call(region, sendData);
  72. }
  73. public bool FriendshipDenied(GridRegion region, UUID userID, string userName, UUID friendID)
  74. {
  75. if (region == null)
  76. return false;
  77. Dictionary<string, object> sendData = new Dictionary<string, object>();
  78. //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  79. //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  80. sendData["METHOD"] = "friendship_denied";
  81. sendData["FromID"] = userID.ToString();
  82. sendData["FromName"] = userName;
  83. sendData["ToID"] = friendID.ToString();
  84. return Call(region, sendData);
  85. }
  86. public bool FriendshipTerminated(GridRegion region, UUID userID, UUID friendID)
  87. {
  88. Dictionary<string, object> sendData = new Dictionary<string, object>();
  89. //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  90. //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  91. sendData["METHOD"] = "friendship_terminated";
  92. sendData["FromID"] = userID.ToString();
  93. sendData["ToID"] = friendID.ToString();
  94. return Call(region, sendData);
  95. }
  96. public bool GrantRights(GridRegion region, UUID userID, UUID friendID, int userFlags, int rights)
  97. {
  98. Dictionary<string, object> sendData = new Dictionary<string, object>();
  99. //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  100. //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  101. sendData["METHOD"] = "grant_rights";
  102. sendData["FromID"] = userID.ToString();
  103. sendData["ToID"] = friendID.ToString();
  104. sendData["UserFlags"] = userFlags.ToString();
  105. sendData["Rights"] = rights.ToString();
  106. return Call(region, sendData);
  107. }
  108. public bool StatusNotify(GridRegion region, UUID userID, string friendID, bool online)
  109. {
  110. Dictionary<string, object> sendData = new Dictionary<string, object>();
  111. //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  112. //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  113. sendData["METHOD"] = "status";
  114. sendData["FromID"] = userID.ToString();
  115. sendData["ToID"] = friendID;
  116. sendData["Online"] = online.ToString();
  117. return Call(region, sendData);
  118. }
  119. private bool Call(GridRegion region, Dictionary<string, object> sendData)
  120. {
  121. string reqString = ServerUtils.BuildQueryString(sendData);
  122. //m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: queryString = {0}", reqString);
  123. if (region == null)
  124. return false;
  125. string path = ServicePath();
  126. if (!region.ServerURI.EndsWith("/"))
  127. path = "/" + path;
  128. string uri = region.ServerURI + path;
  129. // m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: calling {0}", uri);
  130. try
  131. {
  132. string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString);
  133. if (reply != string.Empty)
  134. {
  135. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  136. if (replyData.ContainsKey("RESULT"))
  137. {
  138. if (replyData["RESULT"].ToString().ToLower() == "true")
  139. return true;
  140. else
  141. return false;
  142. }
  143. else
  144. m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: reply data does not contain result field");
  145. }
  146. else
  147. m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: received empty reply");
  148. }
  149. catch (Exception e)
  150. {
  151. m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: Exception when contacting remote sim at {0}: {1}", uri, e.Message);
  152. }
  153. return false;
  154. }
  155. }
  156. }