UserManager.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 OpenSim 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. */
  28. using System;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Text.RegularExpressions;
  32. using libsecondlife;
  33. using Nwc.XmlRpc;
  34. using OpenSim.Framework;
  35. using OpenSim.Framework.UserManagement;
  36. namespace OpenSim.Grid.UserServer
  37. {
  38. public class UserManager : UserManagerBase
  39. {
  40. public UserManager()
  41. {
  42. }
  43. /// <summary>
  44. /// Deletes an active agent session
  45. /// </summary>
  46. /// <param name="request">The request</param>
  47. /// <param name="path">The path (eg /bork/narf/test)</param>
  48. /// <param name="param">Parameters sent</param>
  49. /// <returns>Success "OK" else error</returns>
  50. public string RestDeleteUserSessionMethod(string request, string path, string param)
  51. {
  52. // TODO! Important!
  53. return "OK";
  54. }
  55. /// <summary>
  56. /// Returns an error message that the user could not be found in the database
  57. /// </summary>
  58. /// <returns>XML string consisting of a error element containing individual error(s)</returns>
  59. public XmlRpcResponse CreateUnknownUserErrorResponse()
  60. {
  61. XmlRpcResponse response = new XmlRpcResponse();
  62. Hashtable responseData = new Hashtable();
  63. responseData["error_type"] = "unknown_user";
  64. responseData["error_desc"] = "The user requested is not in the database";
  65. response.Value = responseData;
  66. return response;
  67. }
  68. public XmlRpcResponse AvatarPickerListtoXmlRPCResponse(LLUUID queryID, List<AvatarPickerAvatar> returnUsers)
  69. {
  70. XmlRpcResponse response = new XmlRpcResponse();
  71. Hashtable responseData = new Hashtable();
  72. // Query Result Information
  73. responseData["queryid"] = (string) queryID.ToString();
  74. responseData["avcount"] = (string) returnUsers.Count.ToString();
  75. for (int i = 0; i < returnUsers.Count; i++)
  76. {
  77. responseData["avatarid" + i.ToString()] = returnUsers[i].AvatarID.ToString();
  78. responseData["firstname" + i.ToString()] = returnUsers[i].firstName;
  79. responseData["lastname" + i.ToString()] = returnUsers[i].lastName;
  80. }
  81. response.Value = responseData;
  82. return response;
  83. }
  84. public XmlRpcResponse FriendListItemListtoXmlRPCResponse(List<FriendListItem> returnUsers)
  85. {
  86. XmlRpcResponse response = new XmlRpcResponse();
  87. Hashtable responseData = new Hashtable();
  88. // Query Result Information
  89. responseData["avcount"] = (string)returnUsers.Count.ToString();
  90. for (int i = 0; i < returnUsers.Count; i++)
  91. {
  92. responseData["ownerID" + i.ToString()] = returnUsers[i].FriendListOwner.UUID.ToString();
  93. responseData["friendID" + i.ToString()] = returnUsers[i].Friend.UUID.ToString();
  94. responseData["ownerPerms" + i.ToString()] = returnUsers[i].FriendListOwnerPerms.ToString();
  95. responseData["friendPerms" + i.ToString()] = returnUsers[i].FriendPerms.ToString();
  96. }
  97. response.Value = responseData;
  98. return response;
  99. }
  100. /// <summary>
  101. /// Converts a user profile to an XML element which can be returned
  102. /// </summary>
  103. /// <param name="profile">The user profile</param>
  104. /// <returns>A string containing an XML Document of the user profile</returns>
  105. public XmlRpcResponse ProfileToXmlRPCResponse(UserProfileData profile)
  106. {
  107. XmlRpcResponse response = new XmlRpcResponse();
  108. Hashtable responseData = new Hashtable();
  109. // Account information
  110. responseData["firstname"] = profile.username;
  111. responseData["lastname"] = profile.surname;
  112. responseData["uuid"] = profile.UUID.ToString();
  113. // Server Information
  114. responseData["server_inventory"] = profile.userInventoryURI;
  115. responseData["server_asset"] = profile.userAssetURI;
  116. // Profile Information
  117. responseData["profile_about"] = profile.profileAboutText;
  118. responseData["profile_firstlife_about"] = profile.profileFirstText;
  119. responseData["profile_firstlife_image"] = profile.profileFirstImage.ToString();
  120. responseData["profile_can_do"] = profile.profileCanDoMask.ToString();
  121. responseData["profile_want_do"] = profile.profileWantDoMask.ToString();
  122. responseData["profile_image"] = profile.profileImage.ToString();
  123. responseData["profile_created"] = profile.created.ToString();
  124. responseData["profile_lastlogin"] = profile.lastLogin.ToString();
  125. // Home region information
  126. responseData["home_coordinates_x"] = profile.homeLocation.X.ToString();
  127. responseData["home_coordinates_y"] = profile.homeLocation.Y.ToString();
  128. responseData["home_coordinates_z"] = profile.homeLocation.Z.ToString();
  129. responseData["home_region"] = profile.homeRegion.ToString();
  130. responseData["home_look_x"] = profile.homeLookAt.X.ToString();
  131. responseData["home_look_y"] = profile.homeLookAt.Y.ToString();
  132. responseData["home_look_z"] = profile.homeLookAt.Z.ToString();
  133. response.Value = responseData;
  134. return response;
  135. }
  136. #region XMLRPC User Methods
  137. public XmlRpcResponse XmlRPCGetAvatarPickerAvatar(XmlRpcRequest request)
  138. {
  139. XmlRpcResponse response = new XmlRpcResponse();
  140. Hashtable requestData = (Hashtable) request.Params[0];
  141. List<AvatarPickerAvatar> returnAvatar = new List<AvatarPickerAvatar>();
  142. LLUUID queryID = new LLUUID(LLUUID.Zero.ToString());
  143. if (requestData.Contains("avquery") && requestData.Contains("queryid"))
  144. {
  145. queryID = new LLUUID((string) requestData["queryid"]);
  146. returnAvatar = GenerateAgentPickerRequestResponse(queryID, (string) requestData["avquery"]);
  147. }
  148. Console.WriteLine("[AVATARINFO]: Servicing Avatar Query: " + (string) requestData["avquery"]);
  149. return AvatarPickerListtoXmlRPCResponse(queryID, returnAvatar);
  150. }
  151. public XmlRpcResponse XmlRpcResponseXmlRPCAddUserFriend(XmlRpcRequest request)
  152. {
  153. XmlRpcResponse response = new XmlRpcResponse();
  154. Hashtable requestData = (Hashtable)request.Params[0];
  155. Hashtable responseData = new Hashtable();
  156. string returnString = "FALSE";
  157. // Query Result Information
  158. if (requestData.Contains("ownerID") && requestData.Contains("friendID") && requestData.Contains("friendPerms"))
  159. {
  160. // UserManagerBase.AddNewuserFriend
  161. AddNewUserFriend(new LLUUID((string)requestData["ownerID"]), new LLUUID((string)requestData["friendID"]), (uint)Convert.ToInt32((string)requestData["friendPerms"]));
  162. returnString = "TRUE";
  163. }
  164. responseData["returnString"] = returnString;
  165. response.Value = responseData;
  166. return response;
  167. }
  168. public XmlRpcResponse XmlRpcResponseXmlRPCRemoveUserFriend(XmlRpcRequest request)
  169. {
  170. XmlRpcResponse response = new XmlRpcResponse();
  171. Hashtable requestData = (Hashtable)request.Params[0];
  172. Hashtable responseData = new Hashtable();
  173. string returnString = "FALSE";
  174. // Query Result Information
  175. if (requestData.Contains("ownerID") && requestData.Contains("friendID"))
  176. {
  177. // UserManagerBase.AddNewuserFriend
  178. RemoveUserFriend(new LLUUID((string)requestData["ownerID"]), new LLUUID((string)requestData["friendID"]));
  179. returnString = "TRUE";
  180. }
  181. responseData["returnString"] = returnString;
  182. response.Value = responseData;
  183. return response;
  184. }
  185. public XmlRpcResponse XmlRpcResponseXmlRPCUpdateUserFriendPerms(XmlRpcRequest request)
  186. {
  187. XmlRpcResponse response = new XmlRpcResponse();
  188. Hashtable requestData = (Hashtable)request.Params[0];
  189. Hashtable responseData = new Hashtable();
  190. string returnString = "FALSE";
  191. if (requestData.Contains("ownerID") && requestData.Contains("friendID") && requestData.Contains("friendPerms"))
  192. {
  193. UpdateUserFriendPerms(new LLUUID((string)requestData["ownerID"]), new LLUUID((string)requestData["friendID"]), (uint)Convert.ToInt32((string)requestData["friendPerms"]));
  194. // UserManagerBase.
  195. returnString = "TRUE";
  196. }
  197. responseData["returnString"] = returnString;
  198. response.Value = responseData;
  199. return response;
  200. }
  201. public XmlRpcResponse XmlRpcResponseXmlRPCGetUserFriendList(XmlRpcRequest request)
  202. {
  203. XmlRpcResponse response = new XmlRpcResponse();
  204. Hashtable requestData = (Hashtable)request.Params[0];
  205. Hashtable responseData = new Hashtable();
  206. List<FriendListItem> returndata = new List<FriendListItem>();
  207. if (requestData.Contains("ownerID"))
  208. {
  209. returndata = this.GetUserFriendList(new LLUUID((string)requestData["ownerID"]));
  210. }
  211. return FriendListItemListtoXmlRPCResponse(returndata);
  212. }
  213. public XmlRpcResponse XmlRPCGetUserMethodName(XmlRpcRequest request)
  214. {
  215. XmlRpcResponse response = new XmlRpcResponse();
  216. Hashtable requestData = (Hashtable) request.Params[0];
  217. UserProfileData userProfile;
  218. if (requestData.Contains("avatar_name"))
  219. {
  220. string query = (string) requestData["avatar_name"];
  221. Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9]");
  222. string[] querysplit;
  223. querysplit = query.Split(' ');
  224. if (querysplit.Length == 2)
  225. {
  226. userProfile = GetUserProfile(querysplit[0], querysplit[1], "");
  227. if (userProfile == null)
  228. {
  229. return CreateUnknownUserErrorResponse();
  230. }
  231. }
  232. else
  233. {
  234. return CreateUnknownUserErrorResponse();
  235. }
  236. }
  237. else
  238. {
  239. return CreateUnknownUserErrorResponse();
  240. }
  241. return ProfileToXmlRPCResponse(userProfile);
  242. }
  243. public XmlRpcResponse XmlRPCGetUserMethodUUID(XmlRpcRequest request)
  244. {
  245. XmlRpcResponse response = new XmlRpcResponse();
  246. Hashtable requestData = (Hashtable) request.Params[0];
  247. UserProfileData userProfile;
  248. //CFK: this clogs the UserServer log and is not necessary at this time.
  249. //CFK: Console.WriteLine("METHOD BY UUID CALLED");
  250. if (requestData.Contains("avatar_uuid"))
  251. {
  252. LLUUID guess = new LLUUID();
  253. try
  254. {
  255. guess = new LLUUID((string)requestData["avatar_uuid"]);
  256. //userProfile = GetUserProfile(guess);
  257. string authAddr;
  258. if (requestData["AuthenticationAddress"] == null)
  259. authAddr = "";
  260. else
  261. authAddr = requestData["AuthenticationAddress"].ToString();
  262. userProfile = GetUserProfile(guess, authAddr);
  263. }
  264. catch (FormatException)
  265. {
  266. return CreateUnknownUserErrorResponse();
  267. }
  268. catch (NullReferenceException)
  269. {
  270. Console.WriteLine("NullReferenceException occured");
  271. return CreateUnknownUserErrorResponse();
  272. }
  273. if (userProfile == null)
  274. {
  275. return CreateUnknownUserErrorResponse();
  276. }
  277. }
  278. else
  279. {
  280. return CreateUnknownUserErrorResponse();
  281. }
  282. return ProfileToXmlRPCResponse(userProfile);
  283. }
  284. #endregion
  285. public override UserProfileData SetupMasterUser(string firstName, string lastName)
  286. {
  287. throw new Exception("The method or operation is not implemented.");
  288. }
  289. public override UserProfileData SetupMasterUser(string firstName, string lastName, string password)
  290. {
  291. throw new Exception("The method or operation is not implemented.");
  292. }
  293. public override UserProfileData SetupMasterUser(LLUUID uuid)
  294. {
  295. throw new Exception("The method or operation is not implemented.");
  296. }
  297. }
  298. }