UserServerFriendsModule.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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;
  29. using System.Collections.Generic;
  30. using System.Net;
  31. using System.Reflection;
  32. using log4net;
  33. using Nwc.XmlRpc;
  34. using OpenMetaverse;
  35. using OpenSim.Framework;
  36. using OpenSim.Framework.Communications;
  37. using OpenSim.Framework.Servers;
  38. using OpenSim.Framework.Servers.HttpServer;
  39. using OpenSim.Grid.Framework;
  40. namespace OpenSim.Grid.UserServer.Modules
  41. {
  42. public class UserServerFriendsModule
  43. {
  44. //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. private UserDataBaseService m_userDataBaseService;
  46. private BaseHttpServer m_httpServer;
  47. public UserServerFriendsModule(UserDataBaseService userDataBaseService)
  48. {
  49. m_userDataBaseService = userDataBaseService;
  50. }
  51. public void Initialise(IGridServiceCore core)
  52. {
  53. }
  54. public void PostInitialise()
  55. {
  56. }
  57. public void RegisterHandlers(BaseHttpServer httpServer)
  58. {
  59. m_httpServer = httpServer;
  60. m_httpServer.AddXmlRPCHandler("add_new_user_friend", XmlRpcResponseXmlRPCAddUserFriend);
  61. m_httpServer.AddXmlRPCHandler("remove_user_friend", XmlRpcResponseXmlRPCRemoveUserFriend);
  62. m_httpServer.AddXmlRPCHandler("update_user_friend_perms", XmlRpcResponseXmlRPCUpdateUserFriendPerms);
  63. m_httpServer.AddXmlRPCHandler("get_user_friend_list", XmlRpcResponseXmlRPCGetUserFriendList);
  64. }
  65. public XmlRpcResponse FriendListItemListtoXmlRPCResponse(List<FriendListItem> returnUsers)
  66. {
  67. XmlRpcResponse response = new XmlRpcResponse();
  68. Hashtable responseData = new Hashtable();
  69. // Query Result Information
  70. responseData["avcount"] = returnUsers.Count.ToString();
  71. for (int i = 0; i < returnUsers.Count; i++)
  72. {
  73. responseData["ownerID" + i] = returnUsers[i].FriendListOwner.ToString();
  74. responseData["friendID" + i] = returnUsers[i].Friend.ToString();
  75. responseData["ownerPerms" + i] = returnUsers[i].FriendListOwnerPerms.ToString();
  76. responseData["friendPerms" + i] = returnUsers[i].FriendPerms.ToString();
  77. }
  78. response.Value = responseData;
  79. return response;
  80. }
  81. public XmlRpcResponse XmlRpcResponseXmlRPCAddUserFriend(XmlRpcRequest request, IPEndPoint remoteClient)
  82. {
  83. XmlRpcResponse response = new XmlRpcResponse();
  84. Hashtable requestData = (Hashtable)request.Params[0];
  85. Hashtable responseData = new Hashtable();
  86. string returnString = "FALSE";
  87. // Query Result Information
  88. if (requestData.Contains("ownerID") && requestData.Contains("friendID") &&
  89. requestData.Contains("friendPerms"))
  90. {
  91. // UserManagerBase.AddNewuserFriend
  92. m_userDataBaseService.AddNewUserFriend(new UUID((string)requestData["ownerID"]),
  93. new UUID((string)requestData["friendID"]),
  94. (uint)Convert.ToInt32((string)requestData["friendPerms"]));
  95. returnString = "TRUE";
  96. }
  97. responseData["returnString"] = returnString;
  98. response.Value = responseData;
  99. return response;
  100. }
  101. public XmlRpcResponse XmlRpcResponseXmlRPCRemoveUserFriend(XmlRpcRequest request, IPEndPoint remoteClient)
  102. {
  103. XmlRpcResponse response = new XmlRpcResponse();
  104. Hashtable requestData = (Hashtable)request.Params[0];
  105. Hashtable responseData = new Hashtable();
  106. string returnString = "FALSE";
  107. // Query Result Information
  108. if (requestData.Contains("ownerID") && requestData.Contains("friendID"))
  109. {
  110. // UserManagerBase.AddNewuserFriend
  111. m_userDataBaseService.RemoveUserFriend(new UUID((string)requestData["ownerID"]),
  112. new UUID((string)requestData["friendID"]));
  113. returnString = "TRUE";
  114. }
  115. responseData["returnString"] = returnString;
  116. response.Value = responseData;
  117. return response;
  118. }
  119. public XmlRpcResponse XmlRpcResponseXmlRPCUpdateUserFriendPerms(XmlRpcRequest request, IPEndPoint remoteClient)
  120. {
  121. XmlRpcResponse response = new XmlRpcResponse();
  122. Hashtable requestData = (Hashtable)request.Params[0];
  123. Hashtable responseData = new Hashtable();
  124. string returnString = "FALSE";
  125. if (requestData.Contains("ownerID") && requestData.Contains("friendID") &&
  126. requestData.Contains("friendPerms"))
  127. {
  128. m_userDataBaseService.UpdateUserFriendPerms(new UUID((string)requestData["ownerID"]),
  129. new UUID((string)requestData["friendID"]),
  130. (uint)Convert.ToInt32((string)requestData["friendPerms"]));
  131. // UserManagerBase.
  132. returnString = "TRUE";
  133. }
  134. responseData["returnString"] = returnString;
  135. response.Value = responseData;
  136. return response;
  137. }
  138. public XmlRpcResponse XmlRpcResponseXmlRPCGetUserFriendList(XmlRpcRequest request, IPEndPoint remoteClient)
  139. {
  140. // XmlRpcResponse response = new XmlRpcResponse();
  141. Hashtable requestData = (Hashtable)request.Params[0];
  142. // Hashtable responseData = new Hashtable();
  143. List<FriendListItem> returndata = new List<FriendListItem>();
  144. if (requestData.Contains("ownerID"))
  145. {
  146. returndata = m_userDataBaseService.GetUserFriendList(new UUID((string)requestData["ownerID"]));
  147. }
  148. return FriendListItemListtoXmlRPCResponse(returndata);
  149. }
  150. }
  151. }