OGS1UserServices.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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.Net;
  31. using System.Reflection;
  32. using System.Text.RegularExpressions;
  33. using libsecondlife;
  34. using log4net;
  35. using Nwc.XmlRpc;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Communications;
  38. namespace OpenSim.Region.Communications.OGS1
  39. {
  40. public class OGS1UserServices : IUserService
  41. {
  42. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  43. private CommunicationsOGS1 m_parent;
  44. public OGS1UserServices(CommunicationsOGS1 parent)
  45. {
  46. m_parent = parent;
  47. }
  48. public UserProfileData ConvertXMLRPCDataToUserProfile(Hashtable data)
  49. {
  50. if (data.Contains("error_type"))
  51. {
  52. m_log.Warn("[GRID]: " +
  53. "Error sent by user server when trying to get user profile: (" +
  54. data["error_type"] +
  55. "): " + data["error_desc"]);
  56. return null;
  57. }
  58. UserProfileData userData = new UserProfileData();
  59. userData.FirstName = (string) data["firstname"];
  60. userData.SurName = (string) data["lastname"];
  61. userData.ID = new LLUUID((string) data["uuid"]);
  62. userData.UserInventoryURI = (string) data["server_inventory"];
  63. userData.UserAssetURI = (string) data["server_asset"];
  64. userData.FirstLifeAboutText = (string) data["profile_firstlife_about"];
  65. userData.FirstLifeImage = new LLUUID((string) data["profile_firstlife_image"]);
  66. userData.CanDoMask = Convert.ToUInt32((string) data["profile_can_do"]);
  67. userData.WantDoMask = Convert.ToUInt32(data["profile_want_do"]);
  68. userData.AboutText = (string)data["profile_about"];
  69. userData.Image = new LLUUID((string) data["profile_image"]);
  70. userData.LastLogin = Convert.ToInt32((string) data["profile_lastlogin"]);
  71. userData.HomeRegion = Convert.ToUInt64((string) data["home_region"]);
  72. userData.HomeLocation =
  73. new LLVector3((float) Convert.ToDecimal((string) data["home_coordinates_x"]),
  74. (float) Convert.ToDecimal((string) data["home_coordinates_y"]),
  75. (float) Convert.ToDecimal((string) data["home_coordinates_z"]));
  76. userData.HomeLookAt =
  77. new LLVector3((float) Convert.ToDecimal((string) data["home_look_x"]),
  78. (float) Convert.ToDecimal((string) data["home_look_y"]),
  79. (float) Convert.ToDecimal((string) data["home_look_z"]));
  80. return userData;
  81. }
  82. public List<AvatarPickerAvatar> ConvertXMLRPCDataToAvatarPickerList(LLUUID queryID, Hashtable data)
  83. {
  84. List<AvatarPickerAvatar> pickerlist = new List<AvatarPickerAvatar>();
  85. int pickercount = Convert.ToInt32((string) data["avcount"]);
  86. LLUUID respqueryID = new LLUUID((string) data["queryid"]);
  87. if (queryID == respqueryID)
  88. {
  89. for (int i = 0; i < pickercount; i++)
  90. {
  91. AvatarPickerAvatar apicker = new AvatarPickerAvatar();
  92. LLUUID avatarID = new LLUUID((string) data["avatarid" + i.ToString()]);
  93. string firstname = (string) data["firstname" + i.ToString()];
  94. string lastname = (string) data["lastname" + i.ToString()];
  95. apicker.AvatarID = avatarID;
  96. apicker.firstName = firstname;
  97. apicker.lastName = lastname;
  98. pickerlist.Add(apicker);
  99. }
  100. }
  101. else
  102. {
  103. m_log.Warn("[OGS1 USER SERVICES]: Got invalid queryID from userServer");
  104. }
  105. return pickerlist;
  106. }
  107. public List<FriendListItem> ConvertXMLRPCDataToFriendListItemList(Hashtable data)
  108. {
  109. List<FriendListItem> buddylist = new List<FriendListItem>();
  110. int buddycount = Convert.ToInt32((string)data["avcount"]);
  111. for (int i = 0; i < buddycount; i++)
  112. {
  113. FriendListItem buddylistitem = new FriendListItem();
  114. buddylistitem.FriendListOwner = new LLUUID((string)data["ownerID" + i.ToString()]);
  115. buddylistitem.Friend = new LLUUID((string)data["friendID" + i.ToString()]);
  116. buddylistitem.FriendListOwnerPerms = (uint)Convert.ToInt32((string)data["ownerPerms" + i.ToString()]);
  117. buddylistitem.FriendPerms = (uint)Convert.ToInt32((string)data["friendPerms" + i.ToString()]);
  118. buddylist.Add(buddylistitem);
  119. }
  120. return buddylist;
  121. }
  122. /// <summary>
  123. /// Logs off a user on the user server
  124. /// </summary>
  125. /// <param name="UserID">UUID of the user</param>
  126. /// <param name="regionData">UUID of the Region</param>
  127. /// <param name="posx">final position x</param>
  128. /// <param name="posy">final position y</param>
  129. /// <param name="posz">final position z</param>
  130. public void LogOffUser(LLUUID userid, LLUUID regionid, ulong regionhandle, float posx, float posy, float posz)
  131. {
  132. Hashtable param = new Hashtable();
  133. param["avatar_uuid"] = userid.UUID.ToString();
  134. param["region_uuid"] = regionid.UUID.ToString();
  135. param["region_handle"] = regionhandle.ToString();
  136. param["region_pos_x"] = posx.ToString();
  137. param["region_pos_y"] = posy.ToString();
  138. param["region_pos_z"] = posz.ToString();
  139. IList parameters = new ArrayList();
  140. parameters.Add(param);
  141. XmlRpcRequest req = new XmlRpcRequest("logout_of_simulator", parameters);
  142. try
  143. {
  144. XmlRpcResponse resp = req.Send(m_parent.NetworkServersInfo.UserURL, 3000);
  145. }
  146. catch (WebException)
  147. {
  148. m_log.Warn("[LOGOFF]: Unable to notify grid server of user logoff");
  149. }
  150. }
  151. public UserProfileData GetUserProfile(string firstName, string lastName)
  152. {
  153. return GetUserProfile(firstName + " " + lastName);
  154. }
  155. public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(LLUUID queryID, string query)
  156. {
  157. List<AvatarPickerAvatar> pickerlist = new List<AvatarPickerAvatar>();
  158. Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9 ]");
  159. try
  160. {
  161. Hashtable param = new Hashtable();
  162. param["queryid"] = (string) queryID.ToString();
  163. param["avquery"] = objAlphaNumericPattern.Replace(query, String.Empty);
  164. IList parameters = new ArrayList();
  165. parameters.Add(param);
  166. XmlRpcRequest req = new XmlRpcRequest("get_avatar_picker_avatar", parameters);
  167. XmlRpcResponse resp = req.Send(m_parent.NetworkServersInfo.UserURL, 3000);
  168. Hashtable respData = (Hashtable) resp.Value;
  169. pickerlist = ConvertXMLRPCDataToAvatarPickerList(queryID, respData);
  170. }
  171. catch (WebException e)
  172. {
  173. m_log.Warn("[OGS1 USER SERVICES]: Error when trying to fetch Avatar Picker Response: " +
  174. e.Message);
  175. // Return Empty picker list (no results)
  176. }
  177. return pickerlist;
  178. }
  179. /// <summary>
  180. /// Get a user profile from the user server
  181. /// </summary>
  182. /// <param name="avatarID"></param>
  183. /// <returns>null if the request fails</returns>
  184. public UserProfileData GetUserProfile(string name)
  185. {
  186. try
  187. {
  188. Hashtable param = new Hashtable();
  189. param["avatar_name"] = name;
  190. IList parameters = new ArrayList();
  191. parameters.Add(param);
  192. XmlRpcRequest req = new XmlRpcRequest("get_user_by_name", parameters);
  193. XmlRpcResponse resp = req.Send(m_parent.NetworkServersInfo.UserURL, 6000);
  194. Hashtable respData = (Hashtable) resp.Value;
  195. return ConvertXMLRPCDataToUserProfile(respData);
  196. }
  197. catch (WebException e)
  198. {
  199. m_log.ErrorFormat(
  200. "[OGS1 USER SERVICES]: Error when trying to fetch profile data by name from remote user server: {0}",
  201. e);
  202. }
  203. return null;
  204. }
  205. /// <summary>
  206. /// Get a user profile from the user server
  207. /// </summary>
  208. /// <param name="avatarID"></param>
  209. /// <returns>null if the request fails</returns>
  210. public UserProfileData GetUserProfile(LLUUID avatarID)
  211. {
  212. try
  213. {
  214. Hashtable param = new Hashtable();
  215. param["avatar_uuid"] = avatarID.ToString();
  216. IList parameters = new ArrayList();
  217. parameters.Add(param);
  218. XmlRpcRequest req = new XmlRpcRequest("get_user_by_uuid", parameters);
  219. XmlRpcResponse resp = req.Send(m_parent.NetworkServersInfo.UserURL, 6000);
  220. Hashtable respData = (Hashtable) resp.Value;
  221. return ConvertXMLRPCDataToUserProfile(respData);
  222. }
  223. catch (Exception e)
  224. {
  225. m_log.ErrorFormat(
  226. "[OGS1 USER SERVICES]: Error when trying to fetch profile data by uuid from remote user server: {0}",
  227. e);
  228. }
  229. return null;
  230. }
  231. public void clearUserAgent(LLUUID avatarID)
  232. {
  233. // TODO: implement
  234. }
  235. /// <summary>
  236. /// Retrieve the user information for the given master uuid.
  237. /// </summary>
  238. /// <param name="uuid"></param>
  239. /// <returns></returns>
  240. public UserProfileData SetupMasterUser(string firstName, string lastName)
  241. {
  242. return SetupMasterUser(firstName, lastName, String.Empty);
  243. }
  244. /// <summary>
  245. /// Retrieve the user information for the given master uuid.
  246. /// </summary>
  247. /// <param name="uuid"></param>
  248. /// <returns></returns>
  249. public UserProfileData SetupMasterUser(string firstName, string lastName, string password)
  250. {
  251. UserProfileData profile = GetUserProfile(firstName, lastName);
  252. return profile;
  253. }
  254. /// <summary>
  255. /// Retrieve the user information for the given master uuid.
  256. /// </summary>
  257. /// <param name="uuid"></param>
  258. /// <returns></returns>
  259. public UserProfileData SetupMasterUser(LLUUID uuid)
  260. {
  261. UserProfileData data = GetUserProfile(uuid);
  262. if (data == null)
  263. {
  264. throw new Exception(
  265. "Could not retrieve profile for master user " + uuid + ". User server did not respond to the request.");
  266. }
  267. return data;
  268. }
  269. public LLUUID AddUserProfile(string firstName, string lastName, string pass, uint regX, uint regY)
  270. {
  271. throw new Exception("The method or operation is not implemented.");
  272. }
  273. public bool UpdateUserProfileProperties(UserProfileData UserProfile)
  274. {
  275. m_log.Debug("[OGS1 USER SERVICES]: Asking UserServer to update profile.");
  276. Hashtable param = new Hashtable();
  277. param["avatar_uuid"] = UserProfile.ID.ToString();
  278. //param["AllowPublish"] = UserProfile.ToString();
  279. param["FLImageID"] = UserProfile.FirstLifeImage.ToString();
  280. param["ImageID"] = UserProfile.Image.ToString();
  281. //param["MaturePublish"] = MaturePublish.ToString();
  282. param["AboutText"] = UserProfile.AboutText;
  283. param["FLAboutText"] = UserProfile.FirstLifeAboutText;
  284. //param["ProfileURL"] = UserProfile.ProfileURL.ToString();
  285. param["home_region"] = UserProfile.HomeRegion.ToString();
  286. param["home_pos_x"] = UserProfile.HomeLocationX.ToString();
  287. param["home_pos_y"] = UserProfile.HomeLocationY.ToString();
  288. param["home_pos_z"] = UserProfile.HomeLocationZ.ToString();
  289. param["home_look_x"] = UserProfile.HomeLookAtX.ToString();
  290. param["home_look_y"] = UserProfile.HomeLookAtY.ToString();
  291. param["home_look_z"] = UserProfile.HomeLookAtZ.ToString();
  292. IList parameters = new ArrayList();
  293. parameters.Add(param);
  294. XmlRpcRequest req = new XmlRpcRequest("update_user_profile", parameters);
  295. XmlRpcResponse resp = req.Send(m_parent.NetworkServersInfo.UserURL, 3000);
  296. Hashtable respData = (Hashtable)resp.Value;
  297. if (respData != null)
  298. {
  299. if (respData.Contains("returnString"))
  300. {
  301. if (((string)respData["returnString"]).ToUpper() != "TRUE")
  302. {
  303. m_log.Warn("[GRID]: Unable to update user profile, User Server Reported an issue");
  304. return false;
  305. }
  306. }
  307. else
  308. {
  309. m_log.Warn("[GRID]: Unable to update user profile, UserServer didn't understand me!");
  310. return false;
  311. }
  312. }
  313. else
  314. {
  315. m_log.Warn("[GRID]: Unable to update user profile, UserServer didn't understand me!");
  316. return false;
  317. }
  318. return true;
  319. }
  320. #region IUserServices Friend Methods
  321. /// <summary>
  322. /// Adds a new friend to the database for XUser
  323. /// </summary>
  324. /// <param name="friendlistowner">The agent that who's friends list is being added to</param>
  325. /// <param name="friend">The agent that being added to the friends list of the friends list owner</param>
  326. /// <param name="perms">A uint bit vector for set perms that the friend being added has; 0 = none, 1=This friend can see when they sign on, 2 = map, 4 edit objects </param>
  327. public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms)
  328. {
  329. try
  330. {
  331. Hashtable param = new Hashtable();
  332. param["ownerID"] = friendlistowner.UUID.ToString();
  333. param["friendID"] = friend.UUID.ToString();
  334. param["friendPerms"] = perms.ToString();
  335. IList parameters = new ArrayList();
  336. parameters.Add(param);
  337. XmlRpcRequest req = new XmlRpcRequest("add_new_user_friend", parameters);
  338. XmlRpcResponse resp = req.Send(m_parent.NetworkServersInfo.UserURL, 3000);
  339. Hashtable respData = (Hashtable)resp.Value;
  340. if (respData != null)
  341. {
  342. if (respData.Contains("returnString"))
  343. {
  344. if ((string)respData["returnString"] == "TRUE")
  345. {
  346. }
  347. else
  348. {
  349. m_log.Warn("[GRID]: Unable to add new friend, User Server Reported an issue");
  350. }
  351. }
  352. else
  353. {
  354. m_log.Warn("[GRID]: Unable to add new friend, UserServer didn't understand me!");
  355. }
  356. }
  357. else
  358. {
  359. m_log.Warn("[GRID]: Unable to add new friend, UserServer didn't understand me!");
  360. }
  361. }
  362. catch (WebException e)
  363. {
  364. m_log.Warn("[GRID]: Error when trying to AddNewUserFriend: " +
  365. e.Message);
  366. }
  367. }
  368. /// <summary>
  369. /// Delete friend on friendlistowner's friendlist.
  370. /// </summary>
  371. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  372. /// <param name="friend">The Ex-friend agent</param>
  373. public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend)
  374. {
  375. try
  376. {
  377. Hashtable param = new Hashtable();
  378. param["ownerID"] = friendlistowner.UUID.ToString();
  379. param["friendID"] = friend.UUID.ToString();
  380. IList parameters = new ArrayList();
  381. parameters.Add(param);
  382. XmlRpcRequest req = new XmlRpcRequest("remove_user_friend", parameters);
  383. XmlRpcResponse resp = req.Send(m_parent.NetworkServersInfo.UserURL, 3000);
  384. Hashtable respData = (Hashtable)resp.Value;
  385. if (respData != null)
  386. {
  387. if (respData.Contains("returnString"))
  388. {
  389. if ((string)respData["returnString"] == "TRUE")
  390. {
  391. }
  392. else
  393. {
  394. m_log.Warn("[GRID]: Unable to remove friend, User Server Reported an issue");
  395. }
  396. }
  397. else
  398. {
  399. m_log.Warn("[GRID]: Unable to remove friend, UserServer didn't understand me!");
  400. }
  401. }
  402. else
  403. {
  404. m_log.Warn("[GRID]: Unable to remove friend, UserServer didn't understand me!");
  405. }
  406. }
  407. catch (WebException e)
  408. {
  409. m_log.Warn("[GRID]: Error when trying to RemoveUserFriend: " +
  410. e.Message);
  411. }
  412. }
  413. /// <summary>
  414. /// Update permissions for friend on friendlistowner's friendlist.
  415. /// </summary>
  416. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  417. /// <param name="friend">The agent that is getting or loosing permissions</param>
  418. /// <param name="perms">A uint bit vector for set perms that the friend being added has; 0 = none, 1=This friend can see when they sign on, 2 = map, 4 edit objects </param>
  419. public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms)
  420. {
  421. try
  422. {
  423. Hashtable param = new Hashtable();
  424. param["ownerID"] = friendlistowner.UUID.ToString();
  425. param["friendID"] = friend.UUID.ToString();
  426. param["friendPerms"] = perms.ToString();
  427. IList parameters = new ArrayList();
  428. parameters.Add(param);
  429. XmlRpcRequest req = new XmlRpcRequest("update_user_friend_perms", parameters);
  430. XmlRpcResponse resp = req.Send(m_parent.NetworkServersInfo.UserURL, 3000);
  431. Hashtable respData = (Hashtable)resp.Value;
  432. if (respData != null)
  433. {
  434. if (respData.Contains("returnString"))
  435. {
  436. if ((string)respData["returnString"] == "TRUE")
  437. {
  438. }
  439. else
  440. {
  441. m_log.Warn("[GRID]: Unable to update_user_friend_perms, User Server Reported an issue");
  442. }
  443. }
  444. else
  445. {
  446. m_log.Warn("[GRID]: Unable to update_user_friend_perms, UserServer didn't understand me!");
  447. }
  448. }
  449. else
  450. {
  451. m_log.Warn("[GRID]: Unable to update_user_friend_perms, UserServer didn't understand me!");
  452. }
  453. }
  454. catch (WebException e)
  455. {
  456. m_log.Warn("[GRID]: Error when trying to update_user_friend_perms: " +
  457. e.Message);
  458. }
  459. }
  460. /// <summary>
  461. /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for LLUUID friendslistowner
  462. /// </summary>
  463. /// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param>
  464. public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner)
  465. {
  466. List<FriendListItem> buddylist = new List<FriendListItem>();
  467. try
  468. {
  469. Hashtable param = new Hashtable();
  470. param["ownerID"] = friendlistowner.UUID.ToString();
  471. IList parameters = new ArrayList();
  472. parameters.Add(param);
  473. XmlRpcRequest req = new XmlRpcRequest("get_user_friend_list", parameters);
  474. XmlRpcResponse resp = req.Send(m_parent.NetworkServersInfo.UserURL, 8000);
  475. Hashtable respData = (Hashtable) resp.Value;
  476. if (respData.Contains("avcount"))
  477. {
  478. buddylist = ConvertXMLRPCDataToFriendListItemList(respData);
  479. }
  480. }
  481. catch (WebException e)
  482. {
  483. m_log.Warn("[OGS1 USER SERVICES]: Error when trying to fetch Avatar's friends list: " +
  484. e.Message);
  485. // Return Empty list (no friends)
  486. }
  487. return buddylist;
  488. }
  489. #endregion
  490. }
  491. }