UserManager.cs 21 KB

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