OpenProfileClient.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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.Net.Sockets;
  32. using System.Reflection;
  33. using System.Text;
  34. using System.Xml;
  35. using log4net;
  36. using OpenMetaverse;
  37. using OpenSim.Framework;
  38. namespace OpenSim.Services.UserProfilesService
  39. {
  40. /// <summary>
  41. /// A client for accessing a profile server using the OpenProfile protocol.
  42. /// </summary>
  43. /// <remarks>
  44. /// This class was adapted from the full OpenProfile class. Since it's only a client, and not a server,
  45. /// it's much simpler.
  46. /// </remarks>
  47. public class OpenProfileClient
  48. {
  49. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. private string m_serverURI;
  51. /// <summary>
  52. /// Creates a client for accessing a foreign grid's profile server using the OpenProfile protocol.
  53. /// </summary>
  54. /// <param name="serverURI">The grid's profile server URL</param>
  55. public OpenProfileClient(string serverURI)
  56. {
  57. m_serverURI = serverURI;
  58. }
  59. /// <summary>
  60. /// Gets an avatar's profile using the OpenProfile protocol.
  61. /// </summary>
  62. /// <param name="props">On success, this will contain the avatar's profile</param>
  63. /// <returns>Success/failure</returns>
  64. /// <remarks>
  65. /// There are two profile modules currently in use in OpenSim: the older one is OpenProfile, and the newer
  66. /// one is UserProfileModule (this file). This method attempts to read an avatar's profile from a foreign
  67. /// grid using the OpenProfile protocol.
  68. /// </remarks>
  69. public bool RequestAvatarPropertiesUsingOpenProfile(ref UserProfileProperties props)
  70. {
  71. Hashtable ReqHash = new Hashtable();
  72. ReqHash["avatar_id"] = props.UserId.ToString();
  73. Hashtable profileData = XMLRPCRequester.SendRequest(ReqHash, "avatar_properties_request", m_serverURI);
  74. if (profileData == null)
  75. return false;
  76. if (!profileData.ContainsKey("data"))
  77. return false;
  78. ArrayList dataArray = (ArrayList)profileData["data"];
  79. if (dataArray == null || dataArray[0] == null)
  80. return false;
  81. profileData = (Hashtable)dataArray[0];
  82. props.WebUrl = string.Empty;
  83. props.AboutText = String.Empty;
  84. props.FirstLifeText = String.Empty;
  85. props.ImageId = UUID.Zero;
  86. props.FirstLifeImageId = UUID.Zero;
  87. props.PartnerId = UUID.Zero;
  88. if (profileData["ProfileUrl"] != null)
  89. props.WebUrl = profileData["ProfileUrl"].ToString();
  90. if (profileData["AboutText"] != null)
  91. props.AboutText = profileData["AboutText"].ToString();
  92. if (profileData["FirstLifeAboutText"] != null)
  93. props.FirstLifeText = profileData["FirstLifeAboutText"].ToString();
  94. if (profileData["Image"] != null)
  95. props.ImageId = new UUID(profileData["Image"].ToString());
  96. if (profileData["FirstLifeImage"] != null)
  97. props.FirstLifeImageId = new UUID(profileData["FirstLifeImage"].ToString());
  98. if (profileData["Partner"] != null)
  99. props.PartnerId = new UUID(profileData["Partner"].ToString());
  100. props.WantToMask = 0;
  101. props.WantToText = String.Empty;
  102. props.SkillsMask = 0;
  103. props.SkillsText = String.Empty;
  104. props.Language = String.Empty;
  105. if (profileData["wantmask"] != null)
  106. props.WantToMask = Convert.ToInt32(profileData["wantmask"].ToString());
  107. if (profileData["wanttext"] != null)
  108. props.WantToText = profileData["wanttext"].ToString();
  109. if (profileData["skillsmask"] != null)
  110. props.SkillsMask = Convert.ToInt32(profileData["skillsmask"].ToString());
  111. if (profileData["skillstext"] != null)
  112. props.SkillsText = profileData["skillstext"].ToString();
  113. if (profileData["languages"] != null)
  114. props.Language = profileData["languages"].ToString();
  115. return true;
  116. }
  117. }
  118. }