OGS1UserDataPlugin.cs 32 KB

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