OGS1UserServices.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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 OpenMetaverse;
  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, IAvatarService, IMessagingService
  41. {
  42. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  43. private CommunicationsManager m_commsManager;
  44. public OGS1UserServices(CommunicationsManager commsManager)
  45. {
  46. m_commsManager = commsManager;
  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 UUID((string) data["uuid"]);
  62. userData.Created = Convert.ToInt32(data["profile_created"]);
  63. userData.UserInventoryURI = (string) data["server_inventory"];
  64. userData.UserAssetURI = (string) data["server_asset"];
  65. userData.FirstLifeAboutText = (string) data["profile_firstlife_about"];
  66. userData.FirstLifeImage = new UUID((string) data["profile_firstlife_image"]);
  67. userData.CanDoMask = Convert.ToUInt32((string) data["profile_can_do"]);
  68. userData.WantDoMask = Convert.ToUInt32(data["profile_want_do"]);
  69. userData.AboutText = (string)data["profile_about"];
  70. userData.Image = new UUID((string) data["profile_image"]);
  71. userData.LastLogin = Convert.ToInt32((string) data["profile_lastlogin"]);
  72. userData.HomeRegion = Convert.ToUInt64((string) data["home_region"]);
  73. if (data.Contains("home_region_id"))
  74. userData.HomeRegionID = new UUID((string)data["home_region_id"]);
  75. else
  76. userData.HomeRegionID = UUID.Zero;
  77. userData.HomeLocation =
  78. new Vector3((float) Convert.ToDecimal((string) data["home_coordinates_x"]),
  79. (float) Convert.ToDecimal((string) data["home_coordinates_y"]),
  80. (float) Convert.ToDecimal((string) data["home_coordinates_z"]));
  81. userData.HomeLookAt =
  82. new Vector3((float) Convert.ToDecimal((string) data["home_look_x"]),
  83. (float) Convert.ToDecimal((string) data["home_look_y"]),
  84. (float) Convert.ToDecimal((string) data["home_look_z"]));
  85. if (data.Contains("user_flags"))
  86. userData.UserFlags = Convert.ToInt32((string) data["user_flags"]);
  87. if (data.Contains("god_level"))
  88. userData.GodLevel = Convert.ToInt32((string) data["god_level"]);
  89. if (data.Contains("custom_type"))
  90. userData.CustomType = (string) data["custom_type"];
  91. else
  92. userData.CustomType = "";
  93. if (userData.CustomType == null)
  94. userData.CustomType = "";
  95. if (data.Contains("partner"))
  96. userData.Partner = new UUID((string) data["partner"]);
  97. else
  98. userData.Partner = UUID.Zero;
  99. return userData;
  100. }
  101. /// <summary>
  102. /// Get a user agent from the user server
  103. /// </summary>
  104. /// <param name="avatarID"></param>
  105. /// <returns>null if the request fails</returns>
  106. public UserAgentData GetAgentByUUID(UUID userId)
  107. {
  108. try
  109. {
  110. Hashtable param = new Hashtable();
  111. param["avatar_uuid"] = userId.ToString();
  112. IList parameters = new ArrayList();
  113. parameters.Add(param);
  114. XmlRpcRequest req = new XmlRpcRequest("get_agent_by_uuid", parameters);
  115. XmlRpcResponse resp = req.Send(m_commsManager.NetworkServersInfo.UserURL, 6000);
  116. Hashtable respData = (Hashtable) resp.Value;
  117. if (respData.Contains("error_type"))
  118. {
  119. m_log.Warn("[GRID]: " +
  120. "Error sent by user server when trying to get agent: (" +
  121. (string) respData["error_type"] +
  122. "): " + (string)respData["error_desc"]);
  123. return null;
  124. }
  125. UUID sessionid = UUID.Zero;
  126. UserAgentData userAgent = new UserAgentData();
  127. userAgent.Handle = Convert.ToUInt64((string)respData["handle"]);
  128. UUID.TryParse((string)respData["sessionid"], out sessionid);
  129. userAgent.SessionID = sessionid;
  130. if ((string)respData["agent_online"] == "TRUE")
  131. {
  132. userAgent.AgentOnline = true;
  133. }
  134. else
  135. {
  136. userAgent.AgentOnline = false;
  137. }
  138. return userAgent;
  139. }
  140. catch (Exception e)
  141. {
  142. m_log.ErrorFormat(
  143. "[OGS1 USER SERVICES]: Error when trying to fetch agent data by uuid from remote user server: {0}",
  144. e);
  145. }
  146. return null;
  147. }
  148. public AvatarAppearance ConvertXMLRPCDataToAvatarAppearance(Hashtable data)
  149. {
  150. if (data != null)
  151. {
  152. if (data.Contains("error_type"))
  153. {
  154. m_log.Warn("[GRID]: " +
  155. "Error sent by user server when trying to get user appearance: (" +
  156. data["error_type"] +
  157. "): " + data["error_desc"]);
  158. return null;
  159. }
  160. else
  161. {
  162. return new AvatarAppearance(data);
  163. }
  164. }
  165. else
  166. {
  167. m_log.Error("[GRID]: The avatar appearance is null, something bad happenend");
  168. return null;
  169. }
  170. }
  171. public List<AvatarPickerAvatar> ConvertXMLRPCDataToAvatarPickerList(UUID queryID, Hashtable data)
  172. {
  173. List<AvatarPickerAvatar> pickerlist = new List<AvatarPickerAvatar>();
  174. int pickercount = Convert.ToInt32((string) data["avcount"]);
  175. UUID respqueryID = new UUID((string) data["queryid"]);
  176. if (queryID == respqueryID)
  177. {
  178. for (int i = 0; i < pickercount; i++)
  179. {
  180. AvatarPickerAvatar apicker = new AvatarPickerAvatar();
  181. UUID avatarID = new UUID((string) data["avatarid" + i.ToString()]);
  182. string firstname = (string) data["firstname" + i.ToString()];
  183. string lastname = (string) data["lastname" + i.ToString()];
  184. apicker.AvatarID = avatarID;
  185. apicker.firstName = firstname;
  186. apicker.lastName = lastname;
  187. pickerlist.Add(apicker);
  188. }
  189. }
  190. else
  191. {
  192. m_log.Warn("[OGS1 USER SERVICES]: Got invalid queryID from userServer");
  193. }
  194. return pickerlist;
  195. }
  196. public List<FriendListItem> ConvertXMLRPCDataToFriendListItemList(Hashtable data)
  197. {
  198. List<FriendListItem> buddylist = new List<FriendListItem>();
  199. int buddycount = Convert.ToInt32((string)data["avcount"]);
  200. for (int i = 0; i < buddycount; i++)
  201. {
  202. FriendListItem buddylistitem = new FriendListItem();
  203. buddylistitem.FriendListOwner = new UUID((string)data["ownerID" + i.ToString()]);
  204. buddylistitem.Friend = new UUID((string)data["friendID" + i.ToString()]);
  205. buddylistitem.FriendListOwnerPerms = (uint)Convert.ToInt32((string)data["ownerPerms" + i.ToString()]);
  206. buddylistitem.FriendPerms = (uint)Convert.ToInt32((string)data["friendPerms" + i.ToString()]);
  207. buddylist.Add(buddylistitem);
  208. }
  209. return buddylist;
  210. }
  211. /// <summary>
  212. /// Logs off a user on the user server
  213. /// </summary>
  214. /// <param name="UserID">UUID of the user</param>
  215. /// <param name="regionID">UUID of the Region</param>
  216. /// <param name="regionhandle">regionhandle</param>
  217. /// <param name="position">final position</param>
  218. /// <param name="lookat">final lookat</param>
  219. public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat)
  220. {
  221. Hashtable param = new Hashtable();
  222. param["avatar_uuid"] = userid.Guid.ToString();
  223. param["region_uuid"] = regionid.Guid.ToString();
  224. param["region_handle"] = regionhandle.ToString();
  225. param["region_pos_x"] = position.X.ToString();
  226. param["region_pos_y"] = position.Y.ToString();
  227. param["region_pos_z"] = position.Z.ToString();
  228. param["lookat_x"] = lookat.X.ToString();
  229. param["lookat_y"] = lookat.Y.ToString();
  230. param["lookat_z"] = lookat.Z.ToString();
  231. IList parameters = new ArrayList();
  232. parameters.Add(param);
  233. XmlRpcRequest req = new XmlRpcRequest("logout_of_simulator", parameters);
  234. try
  235. {
  236. req.Send(m_commsManager.NetworkServersInfo.UserURL, 3000);
  237. }
  238. catch (WebException)
  239. {
  240. m_log.Warn("[LOGOFF]: Unable to notify grid server of user logoff");
  241. }
  242. }
  243. /// <summary>
  244. /// Logs off a user on the user server (deprecated as of 2008-08-27)
  245. /// </summary>
  246. /// <param name="UserID">UUID of the user</param>
  247. /// <param name="regionID">UUID of the Region</param>
  248. /// <param name="regionhandle">regionhandle</param>
  249. /// <param name="posx">final position x</param>
  250. /// <param name="posy">final position y</param>
  251. /// <param name="posz">final position z</param>
  252. public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz)
  253. {
  254. LogOffUser(userid, regionid, regionhandle, new Vector3(posx, posy, posz), new Vector3());
  255. }
  256. public UserProfileData GetUserProfile(string firstName, string lastName)
  257. {
  258. return GetUserProfile(firstName + " " + lastName);
  259. }
  260. public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(UUID queryID, string query)
  261. {
  262. List<AvatarPickerAvatar> pickerlist = new List<AvatarPickerAvatar>();
  263. Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9 ]");
  264. try
  265. {
  266. Hashtable param = new Hashtable();
  267. param["queryid"] = (string) queryID.ToString();
  268. param["avquery"] = objAlphaNumericPattern.Replace(query, String.Empty);
  269. IList parameters = new ArrayList();
  270. parameters.Add(param);
  271. XmlRpcRequest req = new XmlRpcRequest("get_avatar_picker_avatar", parameters);
  272. XmlRpcResponse resp = req.Send(m_commsManager.NetworkServersInfo.UserURL, 3000);
  273. Hashtable respData = (Hashtable) resp.Value;
  274. pickerlist = ConvertXMLRPCDataToAvatarPickerList(queryID, respData);
  275. }
  276. catch (WebException e)
  277. {
  278. m_log.Warn("[OGS1 USER SERVICES]: Error when trying to fetch Avatar Picker Response: " +
  279. e.Message);
  280. // Return Empty picker list (no results)
  281. }
  282. return pickerlist;
  283. }
  284. /// <summary>
  285. /// Get a user profile from the user server
  286. /// </summary>
  287. /// <param name="avatarID"></param>
  288. /// <returns>null if the request fails</returns>
  289. public UserProfileData GetUserProfile(string name)
  290. {
  291. try
  292. {
  293. Hashtable param = new Hashtable();
  294. param["avatar_name"] = name;
  295. IList parameters = new ArrayList();
  296. parameters.Add(param);
  297. XmlRpcRequest req = new XmlRpcRequest("get_user_by_name", parameters);
  298. XmlRpcResponse resp = req.Send(m_commsManager.NetworkServersInfo.UserURL, 30000);
  299. Hashtable respData = (Hashtable) resp.Value;
  300. return ConvertXMLRPCDataToUserProfile(respData);
  301. }
  302. catch (WebException e)
  303. {
  304. m_log.ErrorFormat(
  305. "[OGS1 USER SERVICES]: Error when trying to fetch profile data by name from remote user server: {0}",
  306. e);
  307. }
  308. return null;
  309. }
  310. /// <summary>
  311. /// Get a user profile from the user server
  312. /// </summary>
  313. /// <param name="avatarID"></param>
  314. /// <returns>null if the request fails</returns>
  315. public UserProfileData GetUserProfile(UUID avatarID)
  316. {
  317. try
  318. {
  319. Hashtable param = new Hashtable();
  320. param["avatar_uuid"] = avatarID.ToString();
  321. IList parameters = new ArrayList();
  322. parameters.Add(param);
  323. XmlRpcRequest req = new XmlRpcRequest("get_user_by_uuid", parameters);
  324. XmlRpcResponse resp = req.Send(m_commsManager.NetworkServersInfo.UserURL, 30000);
  325. Hashtable respData = (Hashtable) resp.Value;
  326. return ConvertXMLRPCDataToUserProfile(respData);
  327. }
  328. catch (Exception e)
  329. {
  330. m_log.ErrorFormat(
  331. "[OGS1 USER SERVICES]: Error when trying to fetch profile data by uuid from remote user server: {0}",
  332. e);
  333. }
  334. return null;
  335. }
  336. public void ClearUserAgent(UUID avatarID)
  337. {
  338. // TODO: implement
  339. }
  340. /// <summary>
  341. /// Retrieve the user information for the given master uuid.
  342. /// </summary>
  343. /// <param name="uuid"></param>
  344. /// <returns></returns>
  345. public UserProfileData SetupMasterUser(string firstName, string lastName)
  346. {
  347. return SetupMasterUser(firstName, lastName, String.Empty);
  348. }
  349. /// <summary>
  350. /// Retrieve the user information for the given master uuid.
  351. /// </summary>
  352. /// <param name="uuid"></param>
  353. /// <returns></returns>
  354. public UserProfileData SetupMasterUser(string firstName, string lastName, string password)
  355. {
  356. UserProfileData profile = GetUserProfile(firstName, lastName);
  357. return profile;
  358. }
  359. /// <summary>
  360. /// Retrieve the user information for the given master uuid.
  361. /// </summary>
  362. /// <param name="uuid"></param>
  363. /// <returns></returns>
  364. public UserProfileData SetupMasterUser(UUID uuid)
  365. {
  366. UserProfileData data = GetUserProfile(uuid);
  367. if (data == null)
  368. {
  369. throw new Exception(
  370. "Could not retrieve profile for master user " + uuid + ". User server did not respond to the request.");
  371. }
  372. return data;
  373. }
  374. public UUID AddUserProfile(string firstName, string lastName, string pass, uint regX, uint regY)
  375. {
  376. throw new Exception("The method or operation is not implemented.");
  377. }
  378. public bool ResetUserPassword(string firstName, string lastName, string newPassword)
  379. {
  380. throw new Exception("The method or operation is not implemented.");
  381. }
  382. public bool UpdateUserProfile(UserProfileData userProfile)
  383. {
  384. m_log.Debug("[OGS1 USER SERVICES]: Asking UserServer to update profile.");
  385. Hashtable param = new Hashtable();
  386. param["avatar_uuid"] = userProfile.ID.ToString();
  387. //param["AllowPublish"] = userProfile.ToString();
  388. param["FLImageID"] = userProfile.FirstLifeImage.ToString();
  389. param["ImageID"] = userProfile.Image.ToString();
  390. //param["MaturePublish"] = MaturePublish.ToString();
  391. param["AboutText"] = userProfile.AboutText;
  392. param["FLAboutText"] = userProfile.FirstLifeAboutText;
  393. //param["ProfileURL"] = userProfile.ProfileURL.ToString();
  394. param["home_region"] = userProfile.HomeRegion.ToString();
  395. param["home_region_id"] = userProfile.HomeRegionID.ToString();
  396. param["home_pos_x"] = userProfile.HomeLocationX.ToString();
  397. param["home_pos_y"] = userProfile.HomeLocationY.ToString();
  398. param["home_pos_z"] = userProfile.HomeLocationZ.ToString();
  399. param["home_look_x"] = userProfile.HomeLookAtX.ToString();
  400. param["home_look_y"] = userProfile.HomeLookAtY.ToString();
  401. param["home_look_z"] = userProfile.HomeLookAtZ.ToString();
  402. param["user_flags"] = userProfile.UserFlags.ToString();
  403. param["god_level"] = userProfile.GodLevel.ToString();
  404. param["custom_type"] = userProfile.CustomType.ToString();
  405. param["partner"] = userProfile.Partner.ToString();
  406. IList parameters = new ArrayList();
  407. parameters.Add(param);
  408. XmlRpcRequest req = new XmlRpcRequest("update_user_profile", parameters);
  409. XmlRpcResponse resp = req.Send(m_commsManager.NetworkServersInfo.UserURL, 3000);
  410. Hashtable respData = (Hashtable)resp.Value;
  411. if (respData != null)
  412. {
  413. if (respData.Contains("returnString"))
  414. {
  415. if (((string)respData["returnString"]).ToUpper() != "TRUE")
  416. {
  417. m_log.Warn("[GRID]: Unable to update user profile, User Server Reported an issue");
  418. return false;
  419. }
  420. }
  421. else
  422. {
  423. m_log.Warn("[GRID]: Unable to update user profile, UserServer didn't understand me!");
  424. return false;
  425. }
  426. }
  427. else
  428. {
  429. m_log.Warn("[GRID]: Unable to update user profile, UserServer didn't understand me!");
  430. return false;
  431. }
  432. return true;
  433. }
  434. #region IUserServices Friend Methods
  435. /// <summary>
  436. /// Adds a new friend to the database for XUser
  437. /// </summary>
  438. /// <param name="friendlistowner">The agent that who's friends list is being added to</param>
  439. /// <param name="friend">The agent that being added to the friends list of the friends list owner</param>
  440. /// <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>
  441. public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
  442. {
  443. try
  444. {
  445. Hashtable param = new Hashtable();
  446. param["ownerID"] = friendlistowner.Guid.ToString();
  447. param["friendID"] = friend.Guid.ToString();
  448. param["friendPerms"] = perms.ToString();
  449. IList parameters = new ArrayList();
  450. parameters.Add(param);
  451. XmlRpcRequest req = new XmlRpcRequest("add_new_user_friend", parameters);
  452. XmlRpcResponse resp = req.Send(m_commsManager.NetworkServersInfo.UserURL, 3000);
  453. Hashtable respData = (Hashtable)resp.Value;
  454. if (respData != null)
  455. {
  456. if (respData.Contains("returnString"))
  457. {
  458. if ((string)respData["returnString"] == "TRUE")
  459. {
  460. }
  461. else
  462. {
  463. m_log.Warn("[GRID]: Unable to add new friend, User Server Reported an issue");
  464. }
  465. }
  466. else
  467. {
  468. m_log.Warn("[GRID]: Unable to add new friend, UserServer didn't understand me!");
  469. }
  470. }
  471. else
  472. {
  473. m_log.Warn("[GRID]: Unable to add new friend, UserServer didn't understand me!");
  474. }
  475. }
  476. catch (WebException e)
  477. {
  478. m_log.Warn("[GRID]: Error when trying to AddNewUserFriend: " +
  479. e.Message);
  480. }
  481. }
  482. /// <summary>
  483. /// Delete friend on friendlistowner's friendlist.
  484. /// </summary>
  485. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  486. /// <param name="friend">The Ex-friend agent</param>
  487. public void RemoveUserFriend(UUID friendlistowner, UUID friend)
  488. {
  489. try
  490. {
  491. Hashtable param = new Hashtable();
  492. param["ownerID"] = friendlistowner.Guid.ToString();
  493. param["friendID"] = friend.Guid.ToString();
  494. IList parameters = new ArrayList();
  495. parameters.Add(param);
  496. XmlRpcRequest req = new XmlRpcRequest("remove_user_friend", parameters);
  497. XmlRpcResponse resp = req.Send(m_commsManager.NetworkServersInfo.UserURL, 3000);
  498. Hashtable respData = (Hashtable)resp.Value;
  499. if (respData != null)
  500. {
  501. if (respData.Contains("returnString"))
  502. {
  503. if ((string)respData["returnString"] == "TRUE")
  504. {
  505. }
  506. else
  507. {
  508. m_log.Warn("[GRID]: Unable to remove friend, User Server Reported an issue");
  509. }
  510. }
  511. else
  512. {
  513. m_log.Warn("[GRID]: Unable to remove friend, UserServer didn't understand me!");
  514. }
  515. }
  516. else
  517. {
  518. m_log.Warn("[GRID]: Unable to remove friend, UserServer didn't understand me!");
  519. }
  520. }
  521. catch (WebException e)
  522. {
  523. m_log.Warn("[GRID]: Error when trying to RemoveUserFriend: " +
  524. e.Message);
  525. }
  526. }
  527. /// <summary>
  528. /// Update permissions for friend on friendlistowner's friendlist.
  529. /// </summary>
  530. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  531. /// <param name="friend">The agent that is getting or loosing permissions</param>
  532. /// <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>
  533. public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
  534. {
  535. try
  536. {
  537. Hashtable param = new Hashtable();
  538. param["ownerID"] = friendlistowner.Guid.ToString();
  539. param["friendID"] = friend.Guid.ToString();
  540. param["friendPerms"] = perms.ToString();
  541. IList parameters = new ArrayList();
  542. parameters.Add(param);
  543. XmlRpcRequest req = new XmlRpcRequest("update_user_friend_perms", parameters);
  544. XmlRpcResponse resp = req.Send(m_commsManager.NetworkServersInfo.UserURL, 3000);
  545. Hashtable respData = (Hashtable)resp.Value;
  546. if (respData != null)
  547. {
  548. if (respData.Contains("returnString"))
  549. {
  550. if ((string)respData["returnString"] == "TRUE")
  551. {
  552. }
  553. else
  554. {
  555. m_log.Warn("[GRID]: Unable to update_user_friend_perms, User Server Reported an issue");
  556. }
  557. }
  558. else
  559. {
  560. m_log.Warn("[GRID]: Unable to update_user_friend_perms, UserServer didn't understand me!");
  561. }
  562. }
  563. else
  564. {
  565. m_log.Warn("[GRID]: Unable to update_user_friend_perms, UserServer didn't understand me!");
  566. }
  567. }
  568. catch (WebException e)
  569. {
  570. m_log.Warn("[GRID]: Error when trying to update_user_friend_perms: " +
  571. e.Message);
  572. }
  573. }
  574. /// <summary>
  575. /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for UUID friendslistowner
  576. /// </summary>
  577. /// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param>
  578. public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
  579. {
  580. List<FriendListItem> buddylist = new List<FriendListItem>();
  581. try
  582. {
  583. Hashtable param = new Hashtable();
  584. param["ownerID"] = friendlistowner.Guid.ToString();
  585. IList parameters = new ArrayList();
  586. parameters.Add(param);
  587. XmlRpcRequest req = new XmlRpcRequest("get_user_friend_list", parameters);
  588. XmlRpcResponse resp = req.Send(m_commsManager.NetworkServersInfo.UserURL, 8000);
  589. Hashtable respData = (Hashtable) resp.Value;
  590. if (respData != null && respData.Contains("avcount"))
  591. {
  592. buddylist = ConvertXMLRPCDataToFriendListItemList(respData);
  593. }
  594. }
  595. catch (WebException e)
  596. {
  597. m_log.Warn("[OGS1 USER SERVICES]: Error when trying to fetch Avatar's friends list: " +
  598. e.Message);
  599. // Return Empty list (no friends)
  600. }
  601. return buddylist;
  602. }
  603. public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos (List<UUID> uuids)
  604. {
  605. Dictionary<UUID, FriendRegionInfo> result = new Dictionary<UUID, FriendRegionInfo>();
  606. // ask MessageServer about the current on-/offline status and regions the friends are in
  607. ArrayList parameters = new ArrayList();
  608. Hashtable map = new Hashtable();
  609. ArrayList list = new ArrayList();
  610. foreach (UUID uuid in uuids)
  611. {
  612. list.Add(uuid.ToString());
  613. list.Add(uuid.ToString());
  614. }
  615. map["uuids"] = list;
  616. map["recv_key"] = m_commsManager.NetworkServersInfo.UserRecvKey;
  617. map["send_key"] = m_commsManager.NetworkServersInfo.UserSendKey;
  618. parameters.Add(map);
  619. try {
  620. XmlRpcRequest req = new XmlRpcRequest("get_presence_info_bulk", parameters);
  621. XmlRpcResponse resp = req.Send(m_commsManager.NetworkServersInfo.MessagingURL, 8000);
  622. Hashtable respData = resp != null ? (Hashtable) resp.Value : null;
  623. if (respData == null || respData.ContainsKey("faultMessage"))
  624. {
  625. m_log.WarnFormat("[OGS1 USER SERVICES]: Contacting MessagingServer about user-regions resulted in error: {0}",
  626. respData == null ? "<unknown error>" : respData["faultMessage"]);
  627. }
  628. else if (!respData.ContainsKey("count"))
  629. {
  630. m_log.WarnFormat("[OGS1 USER SERVICES]: Wrong format in response for MessagingServer request get_presence_info_bulk: missing 'count' field");
  631. }
  632. else
  633. {
  634. int count = (int)respData["count"];
  635. m_log.DebugFormat("[OGS1 USER SERVICES]: Request returned {0} results.", count);
  636. for (int i = 0; i < count; ++i)
  637. {
  638. if (respData.ContainsKey("uuid_" + i) && respData.ContainsKey("isOnline_" + i) && respData.ContainsKey("regionHandle_" + i))
  639. {
  640. UUID uuid;
  641. if (UUID.TryParse((string)respData["uuid_" + i], out uuid))
  642. {
  643. FriendRegionInfo info = new FriendRegionInfo();
  644. info.isOnline = (bool)respData["isOnline_" + i];
  645. if (info.isOnline)
  646. {
  647. // TODO remove this after the next protocol update (say, r7800?)
  648. info.regionHandle = Convert.ToUInt64(respData["regionHandle_" + i]);
  649. // accept missing id
  650. if (respData.ContainsKey("regionID_" + i))
  651. UUID.TryParse((string)respData["regionID_" + i], out info.regionID);
  652. }
  653. result.Add(uuid, info);
  654. }
  655. }
  656. else
  657. {
  658. m_log.WarnFormat("[OGS1 USER SERVICES]: Response to get_presence_info_bulk contained an error in entry {0}", i);
  659. }
  660. }
  661. }
  662. }
  663. catch (WebException e)
  664. {
  665. m_log.ErrorFormat("[OGS1 USER SERVICES]: Network problems when trying to fetch friend infos: {0}", e.Message);
  666. }
  667. m_log.DebugFormat("[OGS1 USER SERVICES]: Returning {0} entries", result.Count);
  668. return result;
  669. }
  670. #endregion
  671. /// Appearance
  672. public AvatarAppearance GetUserAppearance(UUID user)
  673. {
  674. AvatarAppearance appearance = null;
  675. try
  676. {
  677. Hashtable param = new Hashtable();
  678. param["owner"] = user.ToString();
  679. IList parameters = new ArrayList();
  680. parameters.Add(param);
  681. XmlRpcRequest req = new XmlRpcRequest("get_avatar_appearance", parameters);
  682. XmlRpcResponse resp = req.Send(m_commsManager.NetworkServersInfo.UserURL, 8000);
  683. Hashtable respData = (Hashtable) resp.Value;
  684. return ConvertXMLRPCDataToAvatarAppearance(respData);
  685. }
  686. catch (WebException e)
  687. {
  688. m_log.ErrorFormat("[OGS1 USER SERVICES]: Network problems when trying to fetch appearance for avatar {0}, {1}", user, e.Message);
  689. }
  690. return appearance;
  691. }
  692. public void UpdateUserAppearance(UUID user, AvatarAppearance appearance)
  693. {
  694. try
  695. {
  696. Hashtable param = appearance.ToHashTable();
  697. param["owner"] = user.ToString();
  698. IList parameters = new ArrayList();
  699. parameters.Add(param);
  700. XmlRpcRequest req = new XmlRpcRequest("update_avatar_appearance", parameters);
  701. XmlRpcResponse resp = req.Send(m_commsManager.NetworkServersInfo.UserURL, 8000);
  702. Hashtable respData = (Hashtable) resp.Value;
  703. if (respData != null)
  704. {
  705. if (respData.Contains("returnString"))
  706. {
  707. if ((string)respData["returnString"] == "TRUE")
  708. {
  709. }
  710. else
  711. {
  712. m_log.Warn("[GRID]: Unable to update_user_appearance, User Server Reported an issue");
  713. }
  714. }
  715. else
  716. {
  717. m_log.Warn("[GRID]: Unable to update_user_appearance, UserServer didn't understand me!");
  718. }
  719. }
  720. else
  721. {
  722. m_log.Warn("[GRID]: Unable to update_user_appearance, UserServer didn't understand me!");
  723. }
  724. }
  725. catch (WebException e)
  726. {
  727. m_log.Warn("[OGS1 USER SERVICES]: Error when trying to update Avatar's appearance: " +
  728. e.Message);
  729. // Return Empty list (no friends)
  730. }
  731. }
  732. }
  733. }