UserManager.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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.Reflection;
  31. using System.Text.RegularExpressions;
  32. using libsecondlife;
  33. using log4net;
  34. using Nwc.XmlRpc;
  35. using OpenSim.Framework;
  36. using OpenSim.Framework.Communications;
  37. using OpenSim.Framework.Servers;
  38. namespace OpenSim.Grid.UserServer
  39. {
  40. public delegate void logOffUser(LLUUID AgentID);
  41. public class UserManager : UserManagerBase
  42. {
  43. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. public event logOffUser OnLogOffUser;
  45. private logOffUser handlerLogOffUser = null;
  46. /// <summary>
  47. /// Deletes an active agent session
  48. /// </summary>
  49. /// <param name="request">The request</param>
  50. /// <param name="path">The path (eg /bork/narf/test)</param>
  51. /// <param name="param">Parameters sent</param>
  52. /// <param name="httpRequest">HTTP request header object</param>
  53. /// <param name="httpResponse">HTTP response header object</param>
  54. /// <returns>Success "OK" else error</returns>
  55. public string RestDeleteUserSessionMethod(string request, string path, string param,
  56. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  57. {
  58. // TODO! Important!
  59. return "OK";
  60. }
  61. /// <summary>
  62. /// Returns an error message that the user could not be found in the database
  63. /// </summary>
  64. /// <returns>XML string consisting of a error element containing individual error(s)</returns>
  65. public XmlRpcResponse CreateUnknownUserErrorResponse()
  66. {
  67. XmlRpcResponse response = new XmlRpcResponse();
  68. Hashtable responseData = new Hashtable();
  69. responseData["error_type"] = "unknown_user";
  70. responseData["error_desc"] = "The user requested is not in the database";
  71. response.Value = responseData;
  72. return response;
  73. }
  74. public XmlRpcResponse AvatarPickerListtoXmlRPCResponse(LLUUID queryID, List<AvatarPickerAvatar> returnUsers)
  75. {
  76. XmlRpcResponse response = new XmlRpcResponse();
  77. Hashtable responseData = new Hashtable();
  78. // Query Result Information
  79. responseData["queryid"] = (string) queryID.ToString();
  80. responseData["avcount"] = (string) returnUsers.Count.ToString();
  81. for (int i = 0; i < returnUsers.Count; i++)
  82. {
  83. responseData["avatarid" + i.ToString()] = returnUsers[i].AvatarID.ToString();
  84. responseData["firstname" + i.ToString()] = returnUsers[i].firstName;
  85. responseData["lastname" + i.ToString()] = returnUsers[i].lastName;
  86. }
  87. response.Value = responseData;
  88. return response;
  89. }
  90. public XmlRpcResponse FriendListItemListtoXmlRPCResponse(List<FriendListItem> returnUsers)
  91. {
  92. XmlRpcResponse response = new XmlRpcResponse();
  93. Hashtable responseData = new Hashtable();
  94. // Query Result Information
  95. responseData["avcount"] = (string)returnUsers.Count.ToString();
  96. for (int i = 0; i < returnUsers.Count; i++)
  97. {
  98. responseData["ownerID" + i.ToString()] = returnUsers[i].FriendListOwner.UUID.ToString();
  99. responseData["friendID" + i.ToString()] = returnUsers[i].Friend.UUID.ToString();
  100. responseData["ownerPerms" + i.ToString()] = returnUsers[i].FriendListOwnerPerms.ToString();
  101. responseData["friendPerms" + i.ToString()] = returnUsers[i].FriendPerms.ToString();
  102. }
  103. response.Value = responseData;
  104. return response;
  105. }
  106. /// <summary>
  107. /// Converts a user profile to an XML element which can be returned
  108. /// </summary>
  109. /// <param name="profile">The user profile</param>
  110. /// <returns>A string containing an XML Document of the user profile</returns>
  111. public XmlRpcResponse ProfileToXmlRPCResponse(UserProfileData profile)
  112. {
  113. XmlRpcResponse response = new XmlRpcResponse();
  114. Hashtable responseData = new Hashtable();
  115. // Account information
  116. responseData["firstname"] = profile.FirstName;
  117. responseData["lastname"] = profile.SurName;
  118. responseData["uuid"] = profile.ID.ToString();
  119. // Server Information
  120. responseData["server_inventory"] = profile.UserInventoryURI;
  121. responseData["server_asset"] = profile.UserAssetURI;
  122. // Profile Information
  123. responseData["profile_about"] = profile.AboutText;
  124. responseData["profile_firstlife_about"] = profile.FirstLifeAboutText;
  125. responseData["profile_firstlife_image"] = profile.FirstLifeImage.ToString();
  126. responseData["profile_can_do"] = profile.CanDoMask.ToString();
  127. responseData["profile_want_do"] = profile.WantDoMask.ToString();
  128. responseData["profile_image"] = profile.Image.ToString();
  129. responseData["profile_created"] = profile.Created.ToString();
  130. responseData["profile_lastlogin"] = profile.LastLogin.ToString();
  131. // Home region information
  132. responseData["home_coordinates_x"] = profile.HomeLocation.X.ToString();
  133. responseData["home_coordinates_y"] = profile.HomeLocation.Y.ToString();
  134. responseData["home_coordinates_z"] = profile.HomeLocation.Z.ToString();
  135. responseData["home_region"] = profile.HomeRegion.ToString();
  136. responseData["home_look_x"] = profile.HomeLookAt.X.ToString();
  137. responseData["home_look_y"] = profile.HomeLookAt.Y.ToString();
  138. responseData["home_look_z"] = profile.HomeLookAt.Z.ToString();
  139. response.Value = responseData;
  140. return response;
  141. }
  142. #region XMLRPC User Methods
  143. public XmlRpcResponse XmlRPCGetAvatarPickerAvatar(XmlRpcRequest request)
  144. {
  145. XmlRpcResponse response = new XmlRpcResponse();
  146. Hashtable requestData = (Hashtable) request.Params[0];
  147. List<AvatarPickerAvatar> returnAvatar = new List<AvatarPickerAvatar>();
  148. LLUUID queryID = new LLUUID(LLUUID.Zero.ToString());
  149. if (requestData.Contains("avquery") && requestData.Contains("queryid"))
  150. {
  151. queryID = new LLUUID((string) requestData["queryid"]);
  152. returnAvatar = GenerateAgentPickerRequestResponse(queryID, (string) requestData["avquery"]);
  153. }
  154. m_log.InfoFormat("[AVATARINFO]: Servicing Avatar Query: " + (string) requestData["avquery"]);
  155. return AvatarPickerListtoXmlRPCResponse(queryID, returnAvatar);
  156. }
  157. public XmlRpcResponse XmlRpcResponseXmlRPCAddUserFriend(XmlRpcRequest request)
  158. {
  159. XmlRpcResponse response = new XmlRpcResponse();
  160. Hashtable requestData = (Hashtable)request.Params[0];
  161. Hashtable responseData = new Hashtable();
  162. string returnString = "FALSE";
  163. // Query Result Information
  164. if (requestData.Contains("ownerID") && requestData.Contains("friendID") && requestData.Contains("friendPerms"))
  165. {
  166. // UserManagerBase.AddNewuserFriend
  167. AddNewUserFriend(new LLUUID((string)requestData["ownerID"]), new LLUUID((string)requestData["friendID"]), (uint)Convert.ToInt32((string)requestData["friendPerms"]));
  168. returnString = "TRUE";
  169. }
  170. responseData["returnString"] = returnString;
  171. response.Value = responseData;
  172. return response;
  173. }
  174. public XmlRpcResponse XmlRpcResponseXmlRPCRemoveUserFriend(XmlRpcRequest request)
  175. {
  176. XmlRpcResponse response = new XmlRpcResponse();
  177. Hashtable requestData = (Hashtable)request.Params[0];
  178. Hashtable responseData = new Hashtable();
  179. string returnString = "FALSE";
  180. // Query Result Information
  181. if (requestData.Contains("ownerID") && requestData.Contains("friendID"))
  182. {
  183. // UserManagerBase.AddNewuserFriend
  184. RemoveUserFriend(new LLUUID((string)requestData["ownerID"]), new LLUUID((string)requestData["friendID"]));
  185. returnString = "TRUE";
  186. }
  187. responseData["returnString"] = returnString;
  188. response.Value = responseData;
  189. return response;
  190. }
  191. public XmlRpcResponse XmlRpcResponseXmlRPCUpdateUserFriendPerms(XmlRpcRequest request)
  192. {
  193. XmlRpcResponse response = new XmlRpcResponse();
  194. Hashtable requestData = (Hashtable)request.Params[0];
  195. Hashtable responseData = new Hashtable();
  196. string returnString = "FALSE";
  197. if (requestData.Contains("ownerID") && requestData.Contains("friendID") && requestData.Contains("friendPerms"))
  198. {
  199. UpdateUserFriendPerms(new LLUUID((string)requestData["ownerID"]), new LLUUID((string)requestData["friendID"]), (uint)Convert.ToInt32((string)requestData["friendPerms"]));
  200. // UserManagerBase.
  201. returnString = "TRUE";
  202. }
  203. responseData["returnString"] = returnString;
  204. response.Value = responseData;
  205. return response;
  206. }
  207. public XmlRpcResponse XmlRpcResponseXmlRPCGetUserFriendList(XmlRpcRequest request)
  208. {
  209. XmlRpcResponse response = new XmlRpcResponse();
  210. Hashtable requestData = (Hashtable)request.Params[0];
  211. Hashtable responseData = new Hashtable();
  212. List<FriendListItem> returndata = new List<FriendListItem>();
  213. if (requestData.Contains("ownerID"))
  214. {
  215. returndata = this.GetUserFriendList(new LLUUID((string)requestData["ownerID"]));
  216. }
  217. return FriendListItemListtoXmlRPCResponse(returndata);
  218. }
  219. public XmlRpcResponse XmlRPCGetAvatarAppearance(XmlRpcRequest request)
  220. {
  221. XmlRpcResponse response = new XmlRpcResponse();
  222. Hashtable requestData = (Hashtable)request.Params[0];
  223. AvatarAppearance appearance = null;
  224. Hashtable responseData = null;
  225. if (requestData.Contains("owner"))
  226. {
  227. appearance = GetUserAppearance(new LLUUID((string)requestData["owner"]));
  228. if (appearance == null)
  229. {
  230. responseData = new Hashtable();
  231. responseData["error_type"] = "no appearance";
  232. responseData["error_desc"] = "There was no appearance found for this avatar";
  233. }
  234. else
  235. {
  236. responseData = appearance.ToHashTable();
  237. }
  238. }
  239. else
  240. {
  241. responseData = new Hashtable();
  242. responseData["error_type"] = "unknown_avatar";
  243. responseData["error_desc"] = "The avatar appearance requested is not in the database";
  244. }
  245. response.Value = responseData;
  246. return response;
  247. }
  248. public XmlRpcResponse XmlRPCUpdateAvatarAppearance(XmlRpcRequest request)
  249. {
  250. XmlRpcResponse response = new XmlRpcResponse();
  251. Hashtable requestData = (Hashtable)request.Params[0];
  252. Hashtable responseData = null;
  253. if (requestData.Contains("owner"))
  254. {
  255. AvatarAppearance appearance = new AvatarAppearance(requestData);
  256. UpdateUserAppearance(new LLUUID((string)requestData["owner"]), appearance);
  257. responseData = new Hashtable();
  258. responseData["returnString"] = "TRUE";
  259. }
  260. else
  261. {
  262. responseData = new Hashtable();
  263. responseData["error_type"] = "unknown_avatar";
  264. responseData["error_desc"] = "The avatar appearance requested is not in the database";
  265. }
  266. response.Value = responseData;
  267. return response;
  268. }
  269. public XmlRpcResponse XmlRPCGetUserMethodName(XmlRpcRequest request)
  270. {
  271. XmlRpcResponse response = new XmlRpcResponse();
  272. Hashtable requestData = (Hashtable) request.Params[0];
  273. UserProfileData userProfile;
  274. if (requestData.Contains("avatar_name"))
  275. {
  276. string query = (string) requestData["avatar_name"];
  277. Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9]");
  278. string[] querysplit;
  279. querysplit = query.Split(' ');
  280. if (querysplit.Length == 2)
  281. {
  282. userProfile = GetUserProfile(querysplit[0], querysplit[1]);
  283. if (userProfile == null)
  284. {
  285. return CreateUnknownUserErrorResponse();
  286. }
  287. }
  288. else
  289. {
  290. return CreateUnknownUserErrorResponse();
  291. }
  292. }
  293. else
  294. {
  295. return CreateUnknownUserErrorResponse();
  296. }
  297. return ProfileToXmlRPCResponse(userProfile);
  298. }
  299. public XmlRpcResponse XmlRPCGetUserMethodUUID(XmlRpcRequest request)
  300. {
  301. XmlRpcResponse response = new XmlRpcResponse();
  302. Hashtable requestData = (Hashtable) request.Params[0];
  303. UserProfileData userProfile;
  304. //CFK: this clogs the UserServer log and is not necessary at this time.
  305. //CFK: Console.WriteLine("METHOD BY UUID CALLED");
  306. if (requestData.Contains("avatar_uuid"))
  307. {
  308. LLUUID guess = new LLUUID();
  309. try
  310. {
  311. guess = new LLUUID((string) requestData["avatar_uuid"]);
  312. userProfile = GetUserProfile(guess);
  313. }
  314. catch (FormatException)
  315. {
  316. return CreateUnknownUserErrorResponse();
  317. }
  318. if (userProfile == null)
  319. {
  320. return CreateUnknownUserErrorResponse();
  321. }
  322. }
  323. else
  324. {
  325. return CreateUnknownUserErrorResponse();
  326. }
  327. return ProfileToXmlRPCResponse(userProfile);
  328. }
  329. public XmlRpcResponse XmlRpcResponseXmlRPCUpdateUserProfile(XmlRpcRequest request)
  330. {
  331. m_log.Debug("[UserManager]: Got request to update user profile");
  332. XmlRpcResponse response = new XmlRpcResponse();
  333. Hashtable requestData = (Hashtable)request.Params[0];
  334. Hashtable responseData = new Hashtable();
  335. UserProfileData userProfile;
  336. if (!requestData.Contains("avatar_uuid"))
  337. {
  338. return CreateUnknownUserErrorResponse();
  339. }
  340. LLUUID UserUUID = new LLUUID((string)requestData["avatar_uuid"]);
  341. userProfile = GetUserProfile(UserUUID);
  342. if (null == userProfile)
  343. {
  344. return CreateUnknownUserErrorResponse();
  345. }
  346. // don't know how yet.
  347. if (requestData.Contains("AllowPublish"))
  348. {
  349. }
  350. if (requestData.Contains("FLImageID"))
  351. {
  352. userProfile.FirstLifeImage = new LLUUID((string)requestData["FLImageID"]);
  353. }
  354. if (requestData.Contains("ImageID"))
  355. {
  356. userProfile.Image = new LLUUID((string)requestData["ImageID"]);
  357. }
  358. // dont' know how yet
  359. if (requestData.Contains("MaturePublish"))
  360. {
  361. }
  362. if (requestData.Contains("AboutText"))
  363. {
  364. userProfile.AboutText = (string)requestData["AboutText"];
  365. }
  366. if (requestData.Contains("FLAboutText"))
  367. {
  368. userProfile.FirstLifeAboutText = (string)requestData["FLAboutText"];
  369. }
  370. // not in DB yet.
  371. if (requestData.Contains("ProfileURL"))
  372. {
  373. }
  374. if (requestData.Contains("home_region"))
  375. {
  376. try
  377. {
  378. userProfile.HomeRegion = Convert.ToUInt64((string)requestData["home_region"]);
  379. }
  380. catch (ArgumentException)
  381. {
  382. m_log.Error("[PROFILE]:Failed to set home region, Invalid Argument");
  383. }
  384. catch (FormatException)
  385. {
  386. m_log.Error("[PROFILE]:Failed to set home region, Invalid Format");
  387. }
  388. catch (OverflowException)
  389. {
  390. m_log.Error("[PROFILE]:Failed to set home region, Value was too large");
  391. }
  392. }
  393. if (requestData.Contains("home_pos_x"))
  394. {
  395. try
  396. {
  397. userProfile.HomeLocationX = (float)Convert.ToDecimal((string)requestData["home_pos_x"]);
  398. }
  399. catch (InvalidCastException)
  400. {
  401. m_log.Error("[PROFILE]:Failed to set home postion x");
  402. }
  403. }
  404. if (requestData.Contains("home_pos_y"))
  405. {
  406. try
  407. {
  408. userProfile.HomeLocationY = (float)Convert.ToDecimal((string)requestData["home_pos_y"]);
  409. }
  410. catch (InvalidCastException)
  411. {
  412. m_log.Error("[PROFILE]:Failed to set home postion y");
  413. }
  414. }
  415. if (requestData.Contains("home_pos_z"))
  416. {
  417. try
  418. {
  419. userProfile.HomeLocationZ = (float)Convert.ToDecimal((string)requestData["home_pos_z"]);
  420. }
  421. catch (InvalidCastException)
  422. {
  423. m_log.Error("[PROFILE]:Failed to set home postion z");
  424. }
  425. }
  426. if (requestData.Contains("home_look_x"))
  427. {
  428. try
  429. {
  430. userProfile.HomeLookAtX = (float)Convert.ToDecimal((string)requestData["home_look_x"]);
  431. }
  432. catch (InvalidCastException)
  433. {
  434. m_log.Error("[PROFILE]:Failed to set home lookat x");
  435. }
  436. }
  437. if (requestData.Contains("home_look_y"))
  438. {
  439. try
  440. {
  441. userProfile.HomeLookAtY = (float)Convert.ToDecimal((string)requestData["home_look_y"]);
  442. }
  443. catch (InvalidCastException)
  444. {
  445. m_log.Error("[PROFILE]:Failed to set home lookat y");
  446. }
  447. }
  448. if (requestData.Contains("home_look_z"))
  449. {
  450. try
  451. {
  452. userProfile.HomeLookAtZ = (float)Convert.ToDecimal((string)requestData["home_look_z"]);
  453. }
  454. catch (InvalidCastException)
  455. {
  456. m_log.Error("[PROFILE]:Failed to set home lookat z");
  457. }
  458. }
  459. // call plugin!
  460. bool ret = UpdateUserProfileProperties(userProfile);
  461. responseData["returnString"] = ret.ToString();
  462. response.Value = responseData;
  463. return response;
  464. }
  465. public XmlRpcResponse XmlRPCLogOffUserMethodUUID(XmlRpcRequest request)
  466. {
  467. XmlRpcResponse response = new XmlRpcResponse();
  468. Hashtable requestData = (Hashtable)request.Params[0];
  469. if (requestData.Contains("avatar_uuid"))
  470. {
  471. try
  472. {
  473. LLUUID userUUID = new LLUUID((string)requestData["avatar_uuid"]);
  474. LLUUID RegionID = new LLUUID((string)requestData["region_uuid"]);
  475. ulong regionhandle = (ulong)Convert.ToInt64((string)requestData["region_handle"]);
  476. float posx = (float)Convert.ToDecimal((string)requestData["region_pos_x"]);
  477. float posy = (float)Convert.ToDecimal((string)requestData["region_pos_y"]);
  478. float posz = (float)Convert.ToDecimal((string)requestData["region_pos_z"]);
  479. handlerLogOffUser = OnLogOffUser;
  480. if (handlerLogOffUser != null)
  481. handlerLogOffUser(userUUID);
  482. LogOffUser(userUUID, RegionID, regionhandle, posx, posy, posz);
  483. }
  484. catch (FormatException)
  485. {
  486. m_log.Warn("[LOGOUT]: Error in Logout XMLRPC Params");
  487. return response;
  488. }
  489. }
  490. else
  491. {
  492. return CreateUnknownUserErrorResponse();
  493. }
  494. return response;
  495. }
  496. #endregion
  497. public override UserProfileData SetupMasterUser(string firstName, string lastName)
  498. {
  499. throw new Exception("The method or operation is not implemented.");
  500. }
  501. public override UserProfileData SetupMasterUser(string firstName, string lastName, string password)
  502. {
  503. throw new Exception("The method or operation is not implemented.");
  504. }
  505. public override UserProfileData SetupMasterUser(LLUUID uuid)
  506. {
  507. throw new Exception("The method or operation is not implemented.");
  508. }
  509. }
  510. }