UserManager.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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 OpenSimulator 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.Net;
  31. using System.Reflection;
  32. using log4net;
  33. using Nwc.XmlRpc;
  34. using OpenMetaverse;
  35. using OpenSim.Framework;
  36. using OpenSim.Framework.Communications;
  37. using OpenSim.Framework.Servers;
  38. using OpenSim.Framework.Servers.HttpServer;
  39. using OpenSim.Grid.Framework;
  40. namespace OpenSim.Grid.UserServer.Modules
  41. {
  42. public delegate void logOffUser(UUID AgentID);
  43. public class UserManager
  44. {
  45. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  46. public event logOffUser OnLogOffUser;
  47. private logOffUser handlerLogOffUser;
  48. private UserDataBaseService m_userDataBaseService;
  49. private BaseHttpServer m_httpServer;
  50. /// <summary>
  51. ///
  52. /// </summary>
  53. /// <param name="userDataBaseService"></param>
  54. public UserManager(UserDataBaseService userDataBaseService)
  55. {
  56. m_userDataBaseService = userDataBaseService;
  57. }
  58. public void Initialise(IGridServiceCore core)
  59. {
  60. }
  61. public void PostInitialise()
  62. {
  63. }
  64. private string RESTGetUserProfile(string request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  65. {
  66. UUID id;
  67. UserProfileData userProfile;
  68. try
  69. {
  70. id = new UUID(param);
  71. }
  72. catch (Exception)
  73. {
  74. httpResponse.StatusCode = 500;
  75. return "Malformed Param [" + param + "]";
  76. }
  77. userProfile = m_userDataBaseService.GetUserProfile(id);
  78. if (userProfile == null)
  79. {
  80. httpResponse.StatusCode = 404;
  81. return "Not Found.";
  82. }
  83. return ProfileToXmlRPCResponse(userProfile).ToString();
  84. }
  85. public void RegisterHandlers(BaseHttpServer httpServer)
  86. {
  87. m_httpServer = httpServer;
  88. m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/users/", RESTGetUserProfile));
  89. m_httpServer.AddXmlRPCHandler("get_user_by_name", XmlRPCGetUserMethodName);
  90. m_httpServer.AddXmlRPCHandler("get_user_by_uuid", XmlRPCGetUserMethodUUID);
  91. m_httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", XmlRPCGetAvatarPickerAvatar);
  92. // Used by IAR module to do password checks
  93. m_httpServer.AddXmlRPCHandler("authenticate_user_by_password", XmlRPCAuthenticateUserMethodPassword);
  94. m_httpServer.AddXmlRPCHandler("update_user_current_region", XmlRPCAtRegion);
  95. m_httpServer.AddXmlRPCHandler("logout_of_simulator", XmlRPCLogOffUserMethodUUID);
  96. m_httpServer.AddXmlRPCHandler("get_agent_by_uuid", XmlRPCGetAgentMethodUUID);
  97. m_httpServer.AddXmlRPCHandler("update_user_profile", XmlRpcResponseXmlRPCUpdateUserProfile);
  98. m_httpServer.AddStreamHandler(new RestStreamHandler("DELETE", "/usersessions/", RestDeleteUserSessionMethod));
  99. }
  100. /// <summary>
  101. /// Deletes an active agent session
  102. /// </summary>
  103. /// <param name="request">The request</param>
  104. /// <param name="path">The path (eg /bork/narf/test)</param>
  105. /// <param name="param">Parameters sent</param>
  106. /// <param name="httpRequest">HTTP request header object</param>
  107. /// <param name="httpResponse">HTTP response header object</param>
  108. /// <returns>Success "OK" else error</returns>
  109. public string RestDeleteUserSessionMethod(string request, string path, string param,
  110. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  111. {
  112. // TODO! Important!
  113. return "OK";
  114. }
  115. public XmlRpcResponse AvatarPickerListtoXmlRPCResponse(UUID queryID, List<AvatarPickerAvatar> returnUsers)
  116. {
  117. XmlRpcResponse response = new XmlRpcResponse();
  118. Hashtable responseData = new Hashtable();
  119. // Query Result Information
  120. responseData["queryid"] = queryID.ToString();
  121. responseData["avcount"] = returnUsers.Count.ToString();
  122. for (int i = 0; i < returnUsers.Count; i++)
  123. {
  124. responseData["avatarid" + i] = returnUsers[i].AvatarID.ToString();
  125. responseData["firstname" + i] = returnUsers[i].firstName;
  126. responseData["lastname" + i] = returnUsers[i].lastName;
  127. }
  128. response.Value = responseData;
  129. return response;
  130. }
  131. /// <summary>
  132. /// Converts a user profile to an XML element which can be returned
  133. /// </summary>
  134. /// <param name="profile">The user profile</param>
  135. /// <returns>A string containing an XML Document of the user profile</returns>
  136. public XmlRpcResponse ProfileToXmlRPCResponse(UserProfileData profile)
  137. {
  138. XmlRpcResponse response = new XmlRpcResponse();
  139. Hashtable responseData = new Hashtable();
  140. // Account information
  141. responseData["firstname"] = profile.FirstName;
  142. responseData["lastname"] = profile.SurName;
  143. responseData["email"] = profile.Email;
  144. responseData["uuid"] = profile.ID.ToString();
  145. // Server Information
  146. responseData["server_inventory"] = profile.UserInventoryURI;
  147. responseData["server_asset"] = profile.UserAssetURI;
  148. // Profile Information
  149. responseData["profile_about"] = profile.AboutText;
  150. responseData["profile_firstlife_about"] = profile.FirstLifeAboutText;
  151. responseData["profile_firstlife_image"] = profile.FirstLifeImage.ToString();
  152. responseData["profile_can_do"] = profile.CanDoMask.ToString();
  153. responseData["profile_want_do"] = profile.WantDoMask.ToString();
  154. responseData["profile_image"] = profile.Image.ToString();
  155. responseData["profile_created"] = profile.Created.ToString();
  156. responseData["profile_lastlogin"] = profile.LastLogin.ToString();
  157. // Home region information
  158. responseData["home_coordinates_x"] = profile.HomeLocation.X.ToString();
  159. responseData["home_coordinates_y"] = profile.HomeLocation.Y.ToString();
  160. responseData["home_coordinates_z"] = profile.HomeLocation.Z.ToString();
  161. responseData["home_region"] = profile.HomeRegion.ToString();
  162. responseData["home_region_id"] = profile.HomeRegionID.ToString();
  163. responseData["home_look_x"] = profile.HomeLookAt.X.ToString();
  164. responseData["home_look_y"] = profile.HomeLookAt.Y.ToString();
  165. responseData["home_look_z"] = profile.HomeLookAt.Z.ToString();
  166. responseData["user_flags"] = profile.UserFlags.ToString();
  167. responseData["god_level"] = profile.GodLevel.ToString();
  168. responseData["custom_type"] = profile.CustomType;
  169. responseData["partner"] = profile.Partner.ToString();
  170. response.Value = responseData;
  171. return response;
  172. }
  173. #region XMLRPC User Methods
  174. /// <summary>
  175. /// Authenticate a user using their password
  176. /// </summary>
  177. /// <param name="request">Must contain values for "user_uuid" and "password" keys</param>
  178. /// <param name="remoteClient"></param>
  179. /// <returns></returns>
  180. public XmlRpcResponse XmlRPCAuthenticateUserMethodPassword(XmlRpcRequest request, IPEndPoint remoteClient)
  181. {
  182. // m_log.DebugFormat("[USER MANAGER]: Received authenticated user by password request from {0}", remoteClient);
  183. Hashtable requestData = (Hashtable)request.Params[0];
  184. string userUuidRaw = (string)requestData["user_uuid"];
  185. string password = (string)requestData["password"];
  186. if (null == userUuidRaw)
  187. return Util.CreateUnknownUserErrorResponse();
  188. UUID userUuid;
  189. if (!UUID.TryParse(userUuidRaw, out userUuid))
  190. return Util.CreateUnknownUserErrorResponse();
  191. UserProfileData userProfile = m_userDataBaseService.GetUserProfile(userUuid);
  192. if (null == userProfile)
  193. return Util.CreateUnknownUserErrorResponse();
  194. string authed;
  195. if (null == password)
  196. {
  197. authed = "FALSE";
  198. }
  199. else
  200. {
  201. if (m_userDataBaseService.AuthenticateUserByPassword(userUuid, password))
  202. authed = "TRUE";
  203. else
  204. authed = "FALSE";
  205. }
  206. // m_log.DebugFormat(
  207. // "[USER MANAGER]: Authentication by password result from {0} for {1} is {2}",
  208. // remoteClient, userUuid, authed);
  209. XmlRpcResponse response = new XmlRpcResponse();
  210. Hashtable responseData = new Hashtable();
  211. responseData["auth_user"] = authed;
  212. response.Value = responseData;
  213. return response;
  214. }
  215. public XmlRpcResponse XmlRPCGetAvatarPickerAvatar(XmlRpcRequest request, IPEndPoint remoteClient)
  216. {
  217. // XmlRpcResponse response = new XmlRpcResponse();
  218. Hashtable requestData = (Hashtable)request.Params[0];
  219. List<AvatarPickerAvatar> returnAvatar = new List<AvatarPickerAvatar>();
  220. UUID queryID = new UUID(UUID.Zero.ToString());
  221. if (requestData.Contains("avquery") && requestData.Contains("queryid"))
  222. {
  223. queryID = new UUID((string)requestData["queryid"]);
  224. returnAvatar = m_userDataBaseService.GenerateAgentPickerRequestResponse(queryID, (string)requestData["avquery"]);
  225. }
  226. m_log.InfoFormat("[AVATARINFO]: Servicing Avatar Query: " + (string)requestData["avquery"]);
  227. return AvatarPickerListtoXmlRPCResponse(queryID, returnAvatar);
  228. }
  229. public XmlRpcResponse XmlRPCAtRegion(XmlRpcRequest request, IPEndPoint remoteClient)
  230. {
  231. XmlRpcResponse response = new XmlRpcResponse();
  232. Hashtable requestData = (Hashtable)request.Params[0];
  233. Hashtable responseData = new Hashtable();
  234. string returnstring = "FALSE";
  235. if (requestData.Contains("avatar_id") && requestData.Contains("region_handle") &&
  236. requestData.Contains("region_uuid"))
  237. {
  238. // ulong cregionhandle = 0;
  239. UUID regionUUID;
  240. UUID avatarUUID;
  241. UUID.TryParse((string)requestData["avatar_id"], out avatarUUID);
  242. UUID.TryParse((string)requestData["region_uuid"], out regionUUID);
  243. if (avatarUUID != UUID.Zero)
  244. {
  245. UserProfileData userProfile = m_userDataBaseService.GetUserProfile(avatarUUID);
  246. userProfile.CurrentAgent.Region = regionUUID;
  247. userProfile.CurrentAgent.Handle = (ulong)Convert.ToInt64((string)requestData["region_handle"]);
  248. //userProfile.CurrentAgent.
  249. m_userDataBaseService.CommitAgent(ref userProfile);
  250. //setUserProfile(userProfile);
  251. returnstring = "TRUE";
  252. }
  253. }
  254. responseData.Add("returnString", returnstring);
  255. response.Value = responseData;
  256. return response;
  257. }
  258. public XmlRpcResponse XmlRPCGetUserMethodName(XmlRpcRequest request, IPEndPoint remoteClient)
  259. {
  260. // XmlRpcResponse response = new XmlRpcResponse();
  261. Hashtable requestData = (Hashtable)request.Params[0];
  262. UserProfileData userProfile;
  263. if (requestData.Contains("avatar_name"))
  264. {
  265. string query = (string)requestData["avatar_name"];
  266. if (null == query)
  267. return Util.CreateUnknownUserErrorResponse();
  268. // Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9]");
  269. string[] querysplit = query.Split(' ');
  270. if (querysplit.Length == 2)
  271. {
  272. userProfile = m_userDataBaseService.GetUserProfile(querysplit[0], querysplit[1]);
  273. if (userProfile == null)
  274. {
  275. return Util.CreateUnknownUserErrorResponse();
  276. }
  277. }
  278. else
  279. {
  280. return Util.CreateUnknownUserErrorResponse();
  281. }
  282. }
  283. else
  284. {
  285. return Util.CreateUnknownUserErrorResponse();
  286. }
  287. return ProfileToXmlRPCResponse(userProfile);
  288. }
  289. public XmlRpcResponse XmlRPCGetUserMethodUUID(XmlRpcRequest request, IPEndPoint remoteClient)
  290. {
  291. // XmlRpcResponse response = new XmlRpcResponse();
  292. Hashtable requestData = (Hashtable)request.Params[0];
  293. UserProfileData userProfile;
  294. //CFK: this clogs the UserServer log and is not necessary at this time.
  295. //CFK: m_log.Debug("METHOD BY UUID CALLED");
  296. if (requestData.Contains("avatar_uuid"))
  297. {
  298. try
  299. {
  300. UUID guess = new UUID((string)requestData["avatar_uuid"]);
  301. userProfile = m_userDataBaseService.GetUserProfile(guess);
  302. }
  303. catch (FormatException)
  304. {
  305. return Util.CreateUnknownUserErrorResponse();
  306. }
  307. if (userProfile == null)
  308. {
  309. return Util.CreateUnknownUserErrorResponse();
  310. }
  311. }
  312. else
  313. {
  314. return Util.CreateUnknownUserErrorResponse();
  315. }
  316. return ProfileToXmlRPCResponse(userProfile);
  317. }
  318. public XmlRpcResponse XmlRPCGetAgentMethodUUID(XmlRpcRequest request, IPEndPoint remoteClient)
  319. {
  320. XmlRpcResponse response = new XmlRpcResponse();
  321. Hashtable requestData = (Hashtable)request.Params[0];
  322. UserProfileData userProfile;
  323. //CFK: this clogs the UserServer log and is not necessary at this time.
  324. //CFK: m_log.Debug("METHOD BY UUID CALLED");
  325. if (requestData.Contains("avatar_uuid"))
  326. {
  327. UUID guess;
  328. UUID.TryParse((string)requestData["avatar_uuid"], out guess);
  329. if (guess == UUID.Zero)
  330. {
  331. return Util.CreateUnknownUserErrorResponse();
  332. }
  333. userProfile = m_userDataBaseService.GetUserProfile(guess);
  334. if (userProfile == null)
  335. {
  336. return Util.CreateUnknownUserErrorResponse();
  337. }
  338. // no agent???
  339. if (userProfile.CurrentAgent == null)
  340. {
  341. return Util.CreateUnknownUserErrorResponse();
  342. }
  343. Hashtable responseData = new Hashtable();
  344. responseData["handle"] = userProfile.CurrentAgent.Handle.ToString();
  345. responseData["session"] = userProfile.CurrentAgent.SessionID.ToString();
  346. if (userProfile.CurrentAgent.AgentOnline)
  347. responseData["agent_online"] = "TRUE";
  348. else
  349. responseData["agent_online"] = "FALSE";
  350. response.Value = responseData;
  351. }
  352. else
  353. {
  354. return Util.CreateUnknownUserErrorResponse();
  355. }
  356. return response;
  357. }
  358. public XmlRpcResponse XmlRpcResponseXmlRPCUpdateUserProfile(XmlRpcRequest request, IPEndPoint remoteClient)
  359. {
  360. m_log.Debug("[UserManager]: Got request to update user profile");
  361. XmlRpcResponse response = new XmlRpcResponse();
  362. Hashtable requestData = (Hashtable)request.Params[0];
  363. Hashtable responseData = new Hashtable();
  364. if (!requestData.Contains("avatar_uuid"))
  365. {
  366. return Util.CreateUnknownUserErrorResponse();
  367. }
  368. UUID UserUUID = new UUID((string)requestData["avatar_uuid"]);
  369. UserProfileData userProfile = m_userDataBaseService.GetUserProfile(UserUUID);
  370. if (null == userProfile)
  371. {
  372. return Util.CreateUnknownUserErrorResponse();
  373. }
  374. // don't know how yet.
  375. if (requestData.Contains("AllowPublish"))
  376. {
  377. }
  378. if (requestData.Contains("FLImageID"))
  379. {
  380. userProfile.FirstLifeImage = new UUID((string)requestData["FLImageID"]);
  381. }
  382. if (requestData.Contains("ImageID"))
  383. {
  384. userProfile.Image = new UUID((string)requestData["ImageID"]);
  385. }
  386. // dont' know how yet
  387. if (requestData.Contains("MaturePublish"))
  388. {
  389. }
  390. if (requestData.Contains("AboutText"))
  391. {
  392. userProfile.AboutText = (string)requestData["AboutText"];
  393. }
  394. if (requestData.Contains("FLAboutText"))
  395. {
  396. userProfile.FirstLifeAboutText = (string)requestData["FLAboutText"];
  397. }
  398. // not in DB yet.
  399. if (requestData.Contains("ProfileURL"))
  400. {
  401. }
  402. if (requestData.Contains("home_region"))
  403. {
  404. try
  405. {
  406. userProfile.HomeRegion = Convert.ToUInt64((string)requestData["home_region"]);
  407. }
  408. catch (ArgumentException)
  409. {
  410. m_log.Error("[PROFILE]:Failed to set home region, Invalid Argument");
  411. }
  412. catch (FormatException)
  413. {
  414. m_log.Error("[PROFILE]:Failed to set home region, Invalid Format");
  415. }
  416. catch (OverflowException)
  417. {
  418. m_log.Error("[PROFILE]:Failed to set home region, Value was too large");
  419. }
  420. }
  421. if (requestData.Contains("home_region_id"))
  422. {
  423. UUID regionID;
  424. UUID.TryParse((string)requestData["home_region_id"], out regionID);
  425. userProfile.HomeRegionID = regionID;
  426. }
  427. if (requestData.Contains("home_pos_x"))
  428. {
  429. try
  430. {
  431. userProfile.HomeLocationX = (float)Convert.ToDecimal((string)requestData["home_pos_x"], Culture.NumberFormatInfo);
  432. }
  433. catch (InvalidCastException)
  434. {
  435. m_log.Error("[PROFILE]:Failed to set home postion x");
  436. }
  437. }
  438. if (requestData.Contains("home_pos_y"))
  439. {
  440. try
  441. {
  442. userProfile.HomeLocationY = (float)Convert.ToDecimal((string)requestData["home_pos_y"], Culture.NumberFormatInfo);
  443. }
  444. catch (InvalidCastException)
  445. {
  446. m_log.Error("[PROFILE]:Failed to set home postion y");
  447. }
  448. }
  449. if (requestData.Contains("home_pos_z"))
  450. {
  451. try
  452. {
  453. userProfile.HomeLocationZ = (float)Convert.ToDecimal((string)requestData["home_pos_z"], Culture.NumberFormatInfo);
  454. }
  455. catch (InvalidCastException)
  456. {
  457. m_log.Error("[PROFILE]:Failed to set home postion z");
  458. }
  459. }
  460. if (requestData.Contains("home_look_x"))
  461. {
  462. try
  463. {
  464. userProfile.HomeLookAtX = (float)Convert.ToDecimal((string)requestData["home_look_x"], Culture.NumberFormatInfo);
  465. }
  466. catch (InvalidCastException)
  467. {
  468. m_log.Error("[PROFILE]:Failed to set home lookat x");
  469. }
  470. }
  471. if (requestData.Contains("home_look_y"))
  472. {
  473. try
  474. {
  475. userProfile.HomeLookAtY = (float)Convert.ToDecimal((string)requestData["home_look_y"], Culture.NumberFormatInfo);
  476. }
  477. catch (InvalidCastException)
  478. {
  479. m_log.Error("[PROFILE]:Failed to set home lookat y");
  480. }
  481. }
  482. if (requestData.Contains("home_look_z"))
  483. {
  484. try
  485. {
  486. userProfile.HomeLookAtZ = (float)Convert.ToDecimal((string)requestData["home_look_z"], Culture.NumberFormatInfo);
  487. }
  488. catch (InvalidCastException)
  489. {
  490. m_log.Error("[PROFILE]:Failed to set home lookat z");
  491. }
  492. }
  493. if (requestData.Contains("user_flags"))
  494. {
  495. try
  496. {
  497. userProfile.UserFlags = Convert.ToInt32((string)requestData["user_flags"]);
  498. }
  499. catch (InvalidCastException)
  500. {
  501. m_log.Error("[PROFILE]:Failed to set user flags");
  502. }
  503. }
  504. if (requestData.Contains("god_level"))
  505. {
  506. try
  507. {
  508. userProfile.GodLevel = Convert.ToInt32((string)requestData["god_level"]);
  509. }
  510. catch (InvalidCastException)
  511. {
  512. m_log.Error("[PROFILE]:Failed to set god level");
  513. }
  514. }
  515. if (requestData.Contains("custom_type"))
  516. {
  517. try
  518. {
  519. userProfile.CustomType = (string)requestData["custom_type"];
  520. }
  521. catch (InvalidCastException)
  522. {
  523. m_log.Error("[PROFILE]:Failed to set custom type");
  524. }
  525. }
  526. if (requestData.Contains("partner"))
  527. {
  528. try
  529. {
  530. userProfile.Partner = new UUID((string)requestData["partner"]);
  531. }
  532. catch (InvalidCastException)
  533. {
  534. m_log.Error("[PROFILE]:Failed to set partner");
  535. }
  536. }
  537. else
  538. {
  539. userProfile.Partner = UUID.Zero;
  540. }
  541. // call plugin!
  542. bool ret = m_userDataBaseService.UpdateUserProfile(userProfile);
  543. responseData["returnString"] = ret.ToString();
  544. response.Value = responseData;
  545. return response;
  546. }
  547. public XmlRpcResponse XmlRPCLogOffUserMethodUUID(XmlRpcRequest request, IPEndPoint remoteClient)
  548. {
  549. XmlRpcResponse response = new XmlRpcResponse();
  550. Hashtable requestData = (Hashtable)request.Params[0];
  551. if (requestData.Contains("avatar_uuid"))
  552. {
  553. try
  554. {
  555. UUID userUUID = new UUID((string)requestData["avatar_uuid"]);
  556. UUID RegionID = new UUID((string)requestData["region_uuid"]);
  557. ulong regionhandle = (ulong)Convert.ToInt64((string)requestData["region_handle"]);
  558. Vector3 position = new Vector3(
  559. (float)Convert.ToDecimal((string)requestData["region_pos_x"], Culture.NumberFormatInfo),
  560. (float)Convert.ToDecimal((string)requestData["region_pos_y"], Culture.NumberFormatInfo),
  561. (float)Convert.ToDecimal((string)requestData["region_pos_z"], Culture.NumberFormatInfo));
  562. Vector3 lookat = new Vector3(
  563. (float)Convert.ToDecimal((string)requestData["lookat_x"], Culture.NumberFormatInfo),
  564. (float)Convert.ToDecimal((string)requestData["lookat_y"], Culture.NumberFormatInfo),
  565. (float)Convert.ToDecimal((string)requestData["lookat_z"], Culture.NumberFormatInfo));
  566. handlerLogOffUser = OnLogOffUser;
  567. if (handlerLogOffUser != null)
  568. handlerLogOffUser(userUUID);
  569. m_userDataBaseService.LogOffUser(userUUID, RegionID, regionhandle, position, lookat);
  570. }
  571. catch (FormatException)
  572. {
  573. m_log.Warn("[LOGOUT]: Error in Logout XMLRPC Params");
  574. return response;
  575. }
  576. }
  577. else
  578. {
  579. return Util.CreateUnknownUserErrorResponse();
  580. }
  581. return response;
  582. }
  583. #endregion
  584. public void HandleAgentLocation(UUID agentID, UUID regionID, ulong regionHandle)
  585. {
  586. UserProfileData userProfile = m_userDataBaseService.GetUserProfile(agentID);
  587. if (userProfile != null)
  588. {
  589. userProfile.CurrentAgent.Region = regionID;
  590. userProfile.CurrentAgent.Handle = regionHandle;
  591. m_userDataBaseService.CommitAgent(ref userProfile);
  592. }
  593. }
  594. public void HandleAgentLeaving(UUID agentID, UUID regionID, ulong regionHandle)
  595. {
  596. UserProfileData userProfile = m_userDataBaseService.GetUserProfile(agentID);
  597. if (userProfile != null)
  598. {
  599. if (userProfile.CurrentAgent.Region == regionID)
  600. {
  601. UserAgentData userAgent = userProfile.CurrentAgent;
  602. if (userAgent != null && userAgent.AgentOnline)
  603. {
  604. userAgent.AgentOnline = false;
  605. userAgent.LogoutTime = Util.UnixTimeSinceEpoch();
  606. if (regionID != UUID.Zero)
  607. {
  608. userAgent.Region = regionID;
  609. }
  610. userAgent.Handle = regionHandle;
  611. userProfile.LastLogin = userAgent.LogoutTime;
  612. m_userDataBaseService.CommitAgent(ref userProfile);
  613. handlerLogOffUser = OnLogOffUser;
  614. if (handlerLogOffUser != null)
  615. handlerLogOffUser(agentID);
  616. }
  617. }
  618. }
  619. }
  620. public void HandleRegionStartup(UUID regionID)
  621. {
  622. m_userDataBaseService.LogoutUsers(regionID);
  623. }
  624. public void HandleRegionShutdown(UUID regionID)
  625. {
  626. m_userDataBaseService.LogoutUsers(regionID);
  627. }
  628. }
  629. }