OGS1UserServices.cs 23 KB

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