UserManager.cs 15 KB

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