UserManager.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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. m_httpServer.AddXmlRPCHandler("update_user_current_region", XmlRPCAtRegion);
  93. m_httpServer.AddXmlRPCHandler("logout_of_simulator", XmlRPCLogOffUserMethodUUID);
  94. m_httpServer.AddXmlRPCHandler("get_agent_by_uuid", XmlRPCGetAgentMethodUUID);
  95. m_httpServer.AddXmlRPCHandler("update_user_profile", XmlRpcResponseXmlRPCUpdateUserProfile);
  96. m_httpServer.AddStreamHandler(new RestStreamHandler("DELETE", "/usersessions/", RestDeleteUserSessionMethod));
  97. }
  98. /// <summary>
  99. /// Deletes an active agent session
  100. /// </summary>
  101. /// <param name="request">The request</param>
  102. /// <param name="path">The path (eg /bork/narf/test)</param>
  103. /// <param name="param">Parameters sent</param>
  104. /// <param name="httpRequest">HTTP request header object</param>
  105. /// <param name="httpResponse">HTTP response header object</param>
  106. /// <returns>Success "OK" else error</returns>
  107. public string RestDeleteUserSessionMethod(string request, string path, string param,
  108. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  109. {
  110. // TODO! Important!
  111. return "OK";
  112. }
  113. public XmlRpcResponse AvatarPickerListtoXmlRPCResponse(UUID queryID, List<AvatarPickerAvatar> returnUsers)
  114. {
  115. XmlRpcResponse response = new XmlRpcResponse();
  116. Hashtable responseData = new Hashtable();
  117. // Query Result Information
  118. responseData["queryid"] = queryID.ToString();
  119. responseData["avcount"] = returnUsers.Count.ToString();
  120. for (int i = 0; i < returnUsers.Count; i++)
  121. {
  122. responseData["avatarid" + i] = returnUsers[i].AvatarID.ToString();
  123. responseData["firstname" + i] = returnUsers[i].firstName;
  124. responseData["lastname" + i] = returnUsers[i].lastName;
  125. }
  126. response.Value = responseData;
  127. return response;
  128. }
  129. /// <summary>
  130. /// Converts a user profile to an XML element which can be returned
  131. /// </summary>
  132. /// <param name="profile">The user profile</param>
  133. /// <returns>A string containing an XML Document of the user profile</returns>
  134. public XmlRpcResponse ProfileToXmlRPCResponse(UserProfileData profile)
  135. {
  136. XmlRpcResponse response = new XmlRpcResponse();
  137. Hashtable responseData = new Hashtable();
  138. // Account information
  139. responseData["firstname"] = profile.FirstName;
  140. responseData["lastname"] = profile.SurName;
  141. responseData["uuid"] = profile.ID.ToString();
  142. // Server Information
  143. responseData["server_inventory"] = profile.UserInventoryURI;
  144. responseData["server_asset"] = profile.UserAssetURI;
  145. // Profile Information
  146. responseData["profile_about"] = profile.AboutText;
  147. responseData["profile_firstlife_about"] = profile.FirstLifeAboutText;
  148. responseData["profile_firstlife_image"] = profile.FirstLifeImage.ToString();
  149. responseData["profile_can_do"] = profile.CanDoMask.ToString();
  150. responseData["profile_want_do"] = profile.WantDoMask.ToString();
  151. responseData["profile_image"] = profile.Image.ToString();
  152. responseData["profile_created"] = profile.Created.ToString();
  153. responseData["profile_lastlogin"] = profile.LastLogin.ToString();
  154. // Home region information
  155. responseData["home_coordinates_x"] = profile.HomeLocation.X.ToString();
  156. responseData["home_coordinates_y"] = profile.HomeLocation.Y.ToString();
  157. responseData["home_coordinates_z"] = profile.HomeLocation.Z.ToString();
  158. responseData["home_region"] = profile.HomeRegion.ToString();
  159. responseData["home_region_id"] = profile.HomeRegionID.ToString();
  160. responseData["home_look_x"] = profile.HomeLookAt.X.ToString();
  161. responseData["home_look_y"] = profile.HomeLookAt.Y.ToString();
  162. responseData["home_look_z"] = profile.HomeLookAt.Z.ToString();
  163. responseData["user_flags"] = profile.UserFlags.ToString();
  164. responseData["god_level"] = profile.GodLevel.ToString();
  165. responseData["custom_type"] = profile.CustomType;
  166. responseData["partner"] = profile.Partner.ToString();
  167. response.Value = responseData;
  168. return response;
  169. }
  170. #region XMLRPC User Methods
  171. public XmlRpcResponse XmlRPCGetAvatarPickerAvatar(XmlRpcRequest request, IPEndPoint remoteClient)
  172. {
  173. // XmlRpcResponse response = new XmlRpcResponse();
  174. Hashtable requestData = (Hashtable)request.Params[0];
  175. List<AvatarPickerAvatar> returnAvatar = new List<AvatarPickerAvatar>();
  176. UUID queryID = new UUID(UUID.Zero.ToString());
  177. if (requestData.Contains("avquery") && requestData.Contains("queryid"))
  178. {
  179. queryID = new UUID((string)requestData["queryid"]);
  180. returnAvatar = m_userDataBaseService.GenerateAgentPickerRequestResponse(queryID, (string)requestData["avquery"]);
  181. }
  182. m_log.InfoFormat("[AVATARINFO]: Servicing Avatar Query: " + (string)requestData["avquery"]);
  183. return AvatarPickerListtoXmlRPCResponse(queryID, returnAvatar);
  184. }
  185. public XmlRpcResponse XmlRPCAtRegion(XmlRpcRequest request, IPEndPoint remoteClient)
  186. {
  187. XmlRpcResponse response = new XmlRpcResponse();
  188. Hashtable requestData = (Hashtable)request.Params[0];
  189. Hashtable responseData = new Hashtable();
  190. string returnstring = "FALSE";
  191. if (requestData.Contains("avatar_id") && requestData.Contains("region_handle") &&
  192. requestData.Contains("region_uuid"))
  193. {
  194. // ulong cregionhandle = 0;
  195. UUID regionUUID;
  196. UUID avatarUUID;
  197. UUID.TryParse((string)requestData["avatar_id"], out avatarUUID);
  198. UUID.TryParse((string)requestData["region_uuid"], out regionUUID);
  199. if (avatarUUID != UUID.Zero)
  200. {
  201. UserProfileData userProfile = m_userDataBaseService.GetUserProfile(avatarUUID);
  202. userProfile.CurrentAgent.Region = regionUUID;
  203. userProfile.CurrentAgent.Handle = (ulong)Convert.ToInt64((string)requestData["region_handle"]);
  204. //userProfile.CurrentAgent.
  205. m_userDataBaseService.CommitAgent(ref userProfile);
  206. //setUserProfile(userProfile);
  207. returnstring = "TRUE";
  208. }
  209. }
  210. responseData.Add("returnString", returnstring);
  211. response.Value = responseData;
  212. return response;
  213. }
  214. public XmlRpcResponse XmlRPCGetUserMethodName(XmlRpcRequest request, IPEndPoint remoteClient)
  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. if (null == query)
  223. return Util.CreateUnknownUserErrorResponse();
  224. // Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9]");
  225. string[] querysplit = query.Split(' ');
  226. if (querysplit.Length == 2)
  227. {
  228. userProfile = m_userDataBaseService.GetUserProfile(querysplit[0], querysplit[1]);
  229. if (userProfile == null)
  230. {
  231. return Util.CreateUnknownUserErrorResponse();
  232. }
  233. }
  234. else
  235. {
  236. return Util.CreateUnknownUserErrorResponse();
  237. }
  238. }
  239. else
  240. {
  241. return Util.CreateUnknownUserErrorResponse();
  242. }
  243. return ProfileToXmlRPCResponse(userProfile);
  244. }
  245. public XmlRpcResponse XmlRPCGetUserMethodUUID(XmlRpcRequest request, IPEndPoint remoteClient)
  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: m_log.Debug("METHOD BY UUID CALLED");
  252. if (requestData.Contains("avatar_uuid"))
  253. {
  254. try
  255. {
  256. UUID guess = new UUID((string)requestData["avatar_uuid"]);
  257. userProfile = m_userDataBaseService.GetUserProfile(guess);
  258. }
  259. catch (FormatException)
  260. {
  261. return Util.CreateUnknownUserErrorResponse();
  262. }
  263. if (userProfile == null)
  264. {
  265. return Util.CreateUnknownUserErrorResponse();
  266. }
  267. }
  268. else
  269. {
  270. return Util.CreateUnknownUserErrorResponse();
  271. }
  272. return ProfileToXmlRPCResponse(userProfile);
  273. }
  274. public XmlRpcResponse XmlRPCGetAgentMethodUUID(XmlRpcRequest request, IPEndPoint remoteClient)
  275. {
  276. XmlRpcResponse response = new XmlRpcResponse();
  277. Hashtable requestData = (Hashtable)request.Params[0];
  278. UserProfileData userProfile;
  279. //CFK: this clogs the UserServer log and is not necessary at this time.
  280. //CFK: m_log.Debug("METHOD BY UUID CALLED");
  281. if (requestData.Contains("avatar_uuid"))
  282. {
  283. UUID guess;
  284. UUID.TryParse((string)requestData["avatar_uuid"], out guess);
  285. if (guess == UUID.Zero)
  286. {
  287. return Util.CreateUnknownUserErrorResponse();
  288. }
  289. userProfile = m_userDataBaseService.GetUserProfile(guess);
  290. if (userProfile == null)
  291. {
  292. return Util.CreateUnknownUserErrorResponse();
  293. }
  294. // no agent???
  295. if (userProfile.CurrentAgent == null)
  296. {
  297. return Util.CreateUnknownUserErrorResponse();
  298. }
  299. Hashtable responseData = new Hashtable();
  300. responseData["handle"] = userProfile.CurrentAgent.Handle.ToString();
  301. responseData["session"] = userProfile.CurrentAgent.SessionID.ToString();
  302. if (userProfile.CurrentAgent.AgentOnline)
  303. responseData["agent_online"] = "TRUE";
  304. else
  305. responseData["agent_online"] = "FALSE";
  306. response.Value = responseData;
  307. }
  308. else
  309. {
  310. return Util.CreateUnknownUserErrorResponse();
  311. }
  312. return response;
  313. }
  314. public XmlRpcResponse XmlRpcResponseXmlRPCUpdateUserProfile(XmlRpcRequest request, IPEndPoint remoteClient)
  315. {
  316. m_log.Debug("[UserManager]: Got request to update user profile");
  317. XmlRpcResponse response = new XmlRpcResponse();
  318. Hashtable requestData = (Hashtable)request.Params[0];
  319. Hashtable responseData = new Hashtable();
  320. if (!requestData.Contains("avatar_uuid"))
  321. {
  322. return Util.CreateUnknownUserErrorResponse();
  323. }
  324. UUID UserUUID = new UUID((string)requestData["avatar_uuid"]);
  325. UserProfileData userProfile = m_userDataBaseService.GetUserProfile(UserUUID);
  326. if (null == userProfile)
  327. {
  328. return Util.CreateUnknownUserErrorResponse();
  329. }
  330. // don't know how yet.
  331. if (requestData.Contains("AllowPublish"))
  332. {
  333. }
  334. if (requestData.Contains("FLImageID"))
  335. {
  336. userProfile.FirstLifeImage = new UUID((string)requestData["FLImageID"]);
  337. }
  338. if (requestData.Contains("ImageID"))
  339. {
  340. userProfile.Image = new UUID((string)requestData["ImageID"]);
  341. }
  342. // dont' know how yet
  343. if (requestData.Contains("MaturePublish"))
  344. {
  345. }
  346. if (requestData.Contains("AboutText"))
  347. {
  348. userProfile.AboutText = (string)requestData["AboutText"];
  349. }
  350. if (requestData.Contains("FLAboutText"))
  351. {
  352. userProfile.FirstLifeAboutText = (string)requestData["FLAboutText"];
  353. }
  354. // not in DB yet.
  355. if (requestData.Contains("ProfileURL"))
  356. {
  357. }
  358. if (requestData.Contains("home_region"))
  359. {
  360. try
  361. {
  362. userProfile.HomeRegion = Convert.ToUInt64((string)requestData["home_region"]);
  363. }
  364. catch (ArgumentException)
  365. {
  366. m_log.Error("[PROFILE]:Failed to set home region, Invalid Argument");
  367. }
  368. catch (FormatException)
  369. {
  370. m_log.Error("[PROFILE]:Failed to set home region, Invalid Format");
  371. }
  372. catch (OverflowException)
  373. {
  374. m_log.Error("[PROFILE]:Failed to set home region, Value was too large");
  375. }
  376. }
  377. if (requestData.Contains("home_region_id"))
  378. {
  379. UUID regionID;
  380. UUID.TryParse((string)requestData["home_region_id"], out regionID);
  381. userProfile.HomeRegionID = regionID;
  382. }
  383. if (requestData.Contains("home_pos_x"))
  384. {
  385. try
  386. {
  387. userProfile.HomeLocationX = (float)Convert.ToDecimal((string)requestData["home_pos_x"]);
  388. }
  389. catch (InvalidCastException)
  390. {
  391. m_log.Error("[PROFILE]:Failed to set home postion x");
  392. }
  393. }
  394. if (requestData.Contains("home_pos_y"))
  395. {
  396. try
  397. {
  398. userProfile.HomeLocationY = (float)Convert.ToDecimal((string)requestData["home_pos_y"]);
  399. }
  400. catch (InvalidCastException)
  401. {
  402. m_log.Error("[PROFILE]:Failed to set home postion y");
  403. }
  404. }
  405. if (requestData.Contains("home_pos_z"))
  406. {
  407. try
  408. {
  409. userProfile.HomeLocationZ = (float)Convert.ToDecimal((string)requestData["home_pos_z"]);
  410. }
  411. catch (InvalidCastException)
  412. {
  413. m_log.Error("[PROFILE]:Failed to set home postion z");
  414. }
  415. }
  416. if (requestData.Contains("home_look_x"))
  417. {
  418. try
  419. {
  420. userProfile.HomeLookAtX = (float)Convert.ToDecimal((string)requestData["home_look_x"]);
  421. }
  422. catch (InvalidCastException)
  423. {
  424. m_log.Error("[PROFILE]:Failed to set home lookat x");
  425. }
  426. }
  427. if (requestData.Contains("home_look_y"))
  428. {
  429. try
  430. {
  431. userProfile.HomeLookAtY = (float)Convert.ToDecimal((string)requestData["home_look_y"]);
  432. }
  433. catch (InvalidCastException)
  434. {
  435. m_log.Error("[PROFILE]:Failed to set home lookat y");
  436. }
  437. }
  438. if (requestData.Contains("home_look_z"))
  439. {
  440. try
  441. {
  442. userProfile.HomeLookAtZ = (float)Convert.ToDecimal((string)requestData["home_look_z"]);
  443. }
  444. catch (InvalidCastException)
  445. {
  446. m_log.Error("[PROFILE]:Failed to set home lookat z");
  447. }
  448. }
  449. if (requestData.Contains("user_flags"))
  450. {
  451. try
  452. {
  453. userProfile.UserFlags = Convert.ToInt32((string)requestData["user_flags"]);
  454. }
  455. catch (InvalidCastException)
  456. {
  457. m_log.Error("[PROFILE]:Failed to set user flags");
  458. }
  459. }
  460. if (requestData.Contains("god_level"))
  461. {
  462. try
  463. {
  464. userProfile.GodLevel = Convert.ToInt32((string)requestData["god_level"]);
  465. }
  466. catch (InvalidCastException)
  467. {
  468. m_log.Error("[PROFILE]:Failed to set god level");
  469. }
  470. }
  471. if (requestData.Contains("custom_type"))
  472. {
  473. try
  474. {
  475. userProfile.CustomType = (string)requestData["custom_type"];
  476. }
  477. catch (InvalidCastException)
  478. {
  479. m_log.Error("[PROFILE]:Failed to set custom type");
  480. }
  481. }
  482. if (requestData.Contains("partner"))
  483. {
  484. try
  485. {
  486. userProfile.Partner = new UUID((string)requestData["partner"]);
  487. }
  488. catch (InvalidCastException)
  489. {
  490. m_log.Error("[PROFILE]:Failed to set partner");
  491. }
  492. }
  493. else
  494. {
  495. userProfile.Partner = UUID.Zero;
  496. }
  497. // call plugin!
  498. bool ret = m_userDataBaseService.UpdateUserProfile(userProfile);
  499. responseData["returnString"] = ret.ToString();
  500. response.Value = responseData;
  501. return response;
  502. }
  503. public XmlRpcResponse XmlRPCLogOffUserMethodUUID(XmlRpcRequest request, IPEndPoint remoteClient)
  504. {
  505. XmlRpcResponse response = new XmlRpcResponse();
  506. Hashtable requestData = (Hashtable)request.Params[0];
  507. if (requestData.Contains("avatar_uuid"))
  508. {
  509. try
  510. {
  511. UUID userUUID = new UUID((string)requestData["avatar_uuid"]);
  512. UUID RegionID = new UUID((string)requestData["region_uuid"]);
  513. ulong regionhandle = (ulong)Convert.ToInt64((string)requestData["region_handle"]);
  514. Vector3 position = new Vector3(
  515. (float)Convert.ToDecimal((string)requestData["region_pos_x"]),
  516. (float)Convert.ToDecimal((string)requestData["region_pos_y"]),
  517. (float)Convert.ToDecimal((string)requestData["region_pos_z"]));
  518. Vector3 lookat = new Vector3(
  519. (float)Convert.ToDecimal((string)requestData["lookat_x"]),
  520. (float)Convert.ToDecimal((string)requestData["lookat_y"]),
  521. (float)Convert.ToDecimal((string)requestData["lookat_z"]));
  522. handlerLogOffUser = OnLogOffUser;
  523. if (handlerLogOffUser != null)
  524. handlerLogOffUser(userUUID);
  525. m_userDataBaseService.LogOffUser(userUUID, RegionID, regionhandle, position, lookat);
  526. }
  527. catch (FormatException)
  528. {
  529. m_log.Warn("[LOGOUT]: Error in Logout XMLRPC Params");
  530. return response;
  531. }
  532. }
  533. else
  534. {
  535. return Util.CreateUnknownUserErrorResponse();
  536. }
  537. return response;
  538. }
  539. #endregion
  540. public void HandleAgentLocation(UUID agentID, UUID regionID, ulong regionHandle)
  541. {
  542. UserProfileData userProfile = m_userDataBaseService.GetUserProfile(agentID);
  543. if (userProfile != null)
  544. {
  545. userProfile.CurrentAgent.Region = regionID;
  546. userProfile.CurrentAgent.Handle = regionHandle;
  547. m_userDataBaseService.CommitAgent(ref userProfile);
  548. }
  549. }
  550. public void HandleAgentLeaving(UUID agentID, UUID regionID, ulong regionHandle)
  551. {
  552. UserProfileData userProfile = m_userDataBaseService.GetUserProfile(agentID);
  553. if (userProfile != null)
  554. {
  555. if (userProfile.CurrentAgent.Region == regionID)
  556. {
  557. UserAgentData userAgent = userProfile.CurrentAgent;
  558. if (userAgent != null && userAgent.AgentOnline)
  559. {
  560. userAgent.AgentOnline = false;
  561. userAgent.LogoutTime = Util.UnixTimeSinceEpoch();
  562. if (regionID != UUID.Zero)
  563. {
  564. userAgent.Region = regionID;
  565. }
  566. userAgent.Handle = regionHandle;
  567. userProfile.LastLogin = userAgent.LogoutTime;
  568. m_userDataBaseService.CommitAgent(ref userProfile);
  569. handlerLogOffUser = OnLogOffUser;
  570. if (handlerLogOffUser != null)
  571. handlerLogOffUser(agentID);
  572. }
  573. }
  574. }
  575. }
  576. public void HandleRegionStartup(UUID regionID)
  577. {
  578. m_userDataBaseService.LogoutUsers(regionID);
  579. }
  580. public void HandleRegionShutdown(UUID regionID)
  581. {
  582. m_userDataBaseService.LogoutUsers(regionID);
  583. }
  584. }
  585. }