UserManager.cs 18 KB

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