FriendsSimConnector.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. Dictionary<string, object> sendData = new Dictionary<string, object>();
  66. //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  67. //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  68. sendData["METHOD"] = "friendship_denied";
  69. sendData["FromID"] = userID.ToString();
  70. sendData["FromName"] = userName;
  71. sendData["ToID"] = friendID.ToString();
  72. return Call(region, sendData);
  73. }
  74. public bool FriendshipTerminated(GridRegion region, UUID userID, UUID friendID)
  75. {
  76. Dictionary<string, object> sendData = new Dictionary<string, object>();
  77. //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  78. //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  79. sendData["METHOD"] = "friendship_terminated";
  80. sendData["FromID"] = userID.ToString();
  81. sendData["ToID"] = friendID.ToString();
  82. return Call(region, sendData);
  83. }
  84. public bool GrantRights(GridRegion region, UUID userID, UUID friendID, int userFlags, int rights)
  85. {
  86. Dictionary<string, object> sendData = new Dictionary<string, object>();
  87. //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
  88. //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
  89. sendData["METHOD"] = "grant_rights";
  90. sendData["FromID"] = userID.ToString();
  91. sendData["ToID"] = friendID.ToString();
  92. sendData["UserFlags"] = userFlags.ToString();
  93. sendData["Rights"] = rights.ToString();
  94. return Call(region, sendData);
  95. }
  96. public bool StatusNotify(GridRegion region, UUID userID, UUID friendID, bool online)
  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"] = "status";
  102. sendData["FromID"] = userID.ToString();
  103. sendData["ToID"] = friendID.ToString();
  104. sendData["Online"] = online.ToString();
  105. return Call(region, sendData);
  106. }
  107. private bool Call(GridRegion region, Dictionary<string, object> sendData)
  108. {
  109. string reqString = ServerUtils.BuildQueryString(sendData);
  110. // m_log.DebugFormat("[FRIENDS CONNECTOR]: queryString = {0}", reqString);
  111. try
  112. {
  113. string url = "http://" + region.ExternalHostName + ":" + region.HttpPort;
  114. string reply = SynchronousRestFormsRequester.MakeRequest("POST",
  115. url + "/friends",
  116. reqString);
  117. if (reply != string.Empty)
  118. {
  119. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  120. if (replyData.ContainsKey("RESULT"))
  121. {
  122. if (replyData["RESULT"].ToString().ToLower() == "true")
  123. return true;
  124. else
  125. return false;
  126. }
  127. else
  128. m_log.DebugFormat("[FRIENDS CONNECTOR]: reply data does not contain result field");
  129. }
  130. else
  131. m_log.DebugFormat("[FRIENDS CONNECTOR]: received empty reply");
  132. }
  133. catch (Exception e)
  134. {
  135. m_log.DebugFormat("[FRIENDS CONNECTOR]: Exception when contacting remote sim: {0}", e.Message);
  136. }
  137. return false;
  138. }
  139. }
  140. }