OGS1UserServices.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Collections;
  3. using libsecondlife;
  4. using Nwc.XmlRpc;
  5. using OpenSim.Framework.Communications;
  6. using OpenSim.Framework.Data;
  7. namespace OpenSim.Region.Communications.OGS1
  8. {
  9. public class OGS1UserServices :IUserServices
  10. {
  11. CommunicationsOGS1 m_parent;
  12. public OGS1UserServices(CommunicationsOGS1 parent)
  13. {
  14. m_parent = parent;
  15. }
  16. public UserProfileData ConvertXMLRPCDataToUserProfile(Hashtable data)
  17. {
  18. if (data.Contains("error_type"))
  19. {
  20. Console.WriteLine("Error sent by user server when trying to get user profile: (" + data["error_type"] + "): " + data["error_desc"]);
  21. return null;
  22. }
  23. UserProfileData userData = new UserProfileData();
  24. userData.username = (string)data["firstname"];
  25. userData.surname = (string)data["lastname"];
  26. userData.UUID = new LLUUID((string)data["uuid"]);
  27. userData.userInventoryURI = (string)data["server_inventory"];
  28. userData.userAssetURI = (string)data["server_asset"];
  29. userData.profileFirstText = (string)data["profile_firstlife_about"];
  30. userData.profileFirstImage = new LLUUID((string)data["profile_firstlife_image"]);
  31. userData.profileCanDoMask = Convert.ToUInt32((string)data["profile_can_do"]);
  32. userData.profileWantDoMask = Convert.ToUInt32(data["profile_want_do"]);
  33. userData.profileImage = new LLUUID((string)data["profile_image"]);
  34. userData.lastLogin = Convert.ToInt32((string)data["profile_lastlogin"]);
  35. userData.homeRegion = Convert.ToUInt64((string)data["home_region"]);
  36. userData.homeLocation = new LLVector3((float)Convert.ToDecimal((string)data["home_coordinates_x"]), (float)Convert.ToDecimal((string)data["home_coordinates_y"]), (float)Convert.ToDecimal((string)data["home_coordinates_z"]));
  37. userData.homeLookAt = new LLVector3((float)Convert.ToDecimal((string)data["home_look_x"]), (float)Convert.ToDecimal((string)data["home_look_y"]), (float)Convert.ToDecimal((string)data["home_look_z"]));
  38. return userData;
  39. }
  40. public UserProfileData GetUserProfile(string firstName, string lastName)
  41. {
  42. return GetUserProfile(firstName + " " + lastName);
  43. }
  44. public UserProfileData GetUserProfile(string name)
  45. {
  46. //try
  47. //{
  48. Hashtable param = new Hashtable();
  49. param["avatar_name"] = name;
  50. IList parameters = new ArrayList();
  51. parameters.Add(param);
  52. XmlRpcRequest req = new XmlRpcRequest("get_user_by_name", parameters);
  53. XmlRpcResponse resp = req.Send(m_parent.ServersInfo.UserURL, 3000);
  54. Hashtable respData = (Hashtable)resp.Value;
  55. return ConvertXMLRPCDataToUserProfile(respData);
  56. //}
  57. //catch (Exception e)
  58. //{
  59. // Console.WriteLine("Error when trying to fetch profile data by name from remote user server: " + e.Message);
  60. //}
  61. //return null;
  62. }
  63. public UserProfileData GetUserProfile(LLUUID avatarID)
  64. {
  65. try
  66. {
  67. Hashtable param = new Hashtable();
  68. param["avatar_uuid"] = avatarID.ToString();
  69. IList parameters = new ArrayList();
  70. parameters.Add(param);
  71. XmlRpcRequest req = new XmlRpcRequest("get_user_by_uuid", parameters);
  72. XmlRpcResponse resp = req.Send(m_parent.ServersInfo.UserURL, 3000);
  73. Hashtable respData = (Hashtable)resp.Value;
  74. return ConvertXMLRPCDataToUserProfile(respData);
  75. }
  76. catch (Exception e)
  77. {
  78. Console.WriteLine("Error when trying to fetch profile data by uuid from remote user server: " + e.Message);
  79. }
  80. return null;
  81. }
  82. public UserProfileData SetupMasterUser(string firstName, string lastName)
  83. {
  84. return SetupMasterUser(firstName, lastName, "");
  85. }
  86. public UserProfileData SetupMasterUser(string firstName, string lastName, string password)
  87. {
  88. UserProfileData profile = GetUserProfile(firstName, lastName);
  89. if (profile == null)
  90. {
  91. Console.WriteLine("Unknown Master User. Grid Mode: No clue what I should do. Probably would choose the grid owner UUID when that is implemented");
  92. }
  93. return null;
  94. }
  95. }
  96. }