FriendsSimConnector.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.Servers.HttpServer;
  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. public bool FriendshipOffered(GridRegion region, UUID userID, UUID friendID, string message)
  42. {
  43. Dictionary<string, object> sendData = new Dictionary<string, object>();
  44. //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  45. //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  46. sendData["METHOD"] = "friendship_offered";
  47. sendData["FromID"] = userID.ToString();
  48. sendData["ToID"] = friendID.ToString();
  49. sendData["Message"] = message;
  50. return Call(region, sendData);
  51. }
  52. public bool FriendshipApproved(GridRegion region, UUID userID, string userName, UUID friendID)
  53. {
  54. Dictionary<string, object> sendData = new Dictionary<string, object>();
  55. //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  56. //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  57. sendData["METHOD"] = "friendship_approved";
  58. sendData["FromID"] = userID.ToString();
  59. sendData["FromName"] = userName;
  60. sendData["ToID"] = friendID.ToString();
  61. return Call(region, sendData);
  62. }
  63. public bool FriendshipDenied(GridRegion region, UUID userID, string userName, UUID friendID)
  64. {
  65. if (region == null)
  66. return false;
  67. Dictionary<string, object> sendData = new Dictionary<string, object>();
  68. //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  69. //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  70. sendData["METHOD"] = "friendship_denied";
  71. sendData["FromID"] = userID.ToString();
  72. sendData["FromName"] = userName;
  73. sendData["ToID"] = friendID.ToString();
  74. return Call(region, sendData);
  75. }
  76. public bool FriendshipTerminated(GridRegion region, UUID userID, UUID friendID)
  77. {
  78. Dictionary<string, object> sendData = new Dictionary<string, object>();
  79. //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  80. //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  81. sendData["METHOD"] = "friendship_terminated";
  82. sendData["FromID"] = userID.ToString();
  83. sendData["ToID"] = friendID.ToString();
  84. return Call(region, sendData);
  85. }
  86. public bool GrantRights(GridRegion region, UUID userID, UUID friendID, int userFlags, int rights)
  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"] = "grant_rights";
  92. sendData["FromID"] = userID.ToString();
  93. sendData["ToID"] = friendID.ToString();
  94. sendData["UserFlags"] = userFlags.ToString();
  95. sendData["Rights"] = rights.ToString();
  96. return Call(region, sendData);
  97. }
  98. public bool StatusNotify(GridRegion region, UUID userID, UUID friendID, bool online)
  99. {
  100. Dictionary<string, object> sendData = new Dictionary<string, object>();
  101. //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  102. //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  103. sendData["METHOD"] = "status";
  104. sendData["FromID"] = userID.ToString();
  105. sendData["ToID"] = friendID.ToString();
  106. sendData["Online"] = online.ToString();
  107. return Call(region, sendData);
  108. }
  109. private bool Call(GridRegion region, Dictionary<string, object> sendData)
  110. {
  111. string reqString = ServerUtils.BuildQueryString(sendData);
  112. //m_log.DebugFormat("[FRIENDS CONNECTOR]: queryString = {0}", reqString);
  113. if (region == null)
  114. return false;
  115. m_log.DebugFormat("[FRIENDS CONNECTOR]: region: {0}", region.ExternalHostName + ":" + region.HttpPort);
  116. try
  117. {
  118. string url = "http://" + region.ExternalHostName + ":" + region.HttpPort;
  119. string reply = SynchronousRestFormsRequester.MakeRequest("POST",
  120. url + "/friends",
  121. reqString);
  122. if (reply != string.Empty)
  123. {
  124. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  125. if (replyData.ContainsKey("RESULT"))
  126. {
  127. if (replyData["RESULT"].ToString().ToLower() == "true")
  128. return true;
  129. else
  130. return false;
  131. }
  132. else
  133. m_log.DebugFormat("[FRIENDS CONNECTOR]: reply data does not contain result field");
  134. }
  135. else
  136. m_log.DebugFormat("[FRIENDS CONNECTOR]: received empty reply");
  137. }
  138. catch (Exception e)
  139. {
  140. m_log.DebugFormat("[FRIENDS CONNECTOR]: Exception when contacting remote sim: {0}", e.ToString());
  141. }
  142. return false;
  143. }
  144. }
  145. }