OGS1UserDataPlugin.cs 33 KB

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