LocalUserServices.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using libsecondlife;
  3. using OpenSim.Framework.Communications;
  4. using OpenSim.Framework.Data;
  5. using OpenSim.Framework.Types;
  6. using OpenSim.Framework.UserManagement;
  7. using OpenSim.Framework.Utilities;
  8. namespace OpenSim.Region.Communications.Local
  9. {
  10. public class LocalUserServices : UserManagerBase, IUserServices
  11. {
  12. private CommunicationsLocal m_Parent;
  13. private NetworkServersInfo serversInfo;
  14. private uint defaultHomeX ;
  15. private uint defaultHomeY;
  16. public LocalUserServices(CommunicationsLocal parent, NetworkServersInfo serversData)
  17. {
  18. m_Parent = parent;
  19. this.serversInfo = serversData;
  20. defaultHomeX = this.serversInfo.DefaultHomeLocX;
  21. defaultHomeY = this.serversInfo.DefaultHomeLocY;
  22. }
  23. public UserProfileData GetUserProfile(string firstName, string lastName)
  24. {
  25. return GetUserProfile(firstName + " " + lastName);
  26. }
  27. public UserProfileData GetUserProfile(string name)
  28. {
  29. return this.getUserProfile(name);
  30. }
  31. public UserProfileData GetUserProfile(LLUUID avatarID)
  32. {
  33. return this.getUserProfile(avatarID);
  34. }
  35. /// <summary>
  36. ///
  37. /// </summary>
  38. /// <returns></returns>
  39. public override string GetMessage()
  40. {
  41. return "Welcome to OpenSim";
  42. }
  43. public override UserProfileData GetTheUser(string firstname, string lastname)
  44. {
  45. UserProfileData profile = getUserProfile(firstname, lastname);
  46. if (profile != null)
  47. {
  48. return profile;
  49. }
  50. //no current user account so make one
  51. Console.WriteLine("No User account found so creating a new one ");
  52. this.AddUserProfile(firstname, lastname, "test", defaultHomeX, defaultHomeY);
  53. profile = getUserProfile(firstname, lastname);
  54. return profile;
  55. }
  56. public override bool AuthenticateUser(UserProfileData profile, string password)
  57. {
  58. //for now we will accept any password in sandbox mode
  59. Console.WriteLine("authorising user");
  60. return true;
  61. }
  62. public override void CustomiseResponse(LoginResponse response, UserProfileData theUser)
  63. {
  64. ulong currentRegion = theUser.currentAgent.currentHandle;
  65. RegionInfo reg = m_Parent.GridServer.RequestNeighbourInfo(currentRegion);
  66. if (reg != null)
  67. {
  68. response.Home = "{'region_handle':[r" + (reg.RegionLocX * 256).ToString() + ",r" + (reg.RegionLocY * 256).ToString() + "], " +
  69. "'position':[r" + theUser.homeLocation.X.ToString() + ",r" + theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "], " +
  70. "'look_at':[r" + theUser.homeLocation.X.ToString() + ",r" + theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "]}";
  71. string capsPath = Util.GetRandomCapsPath();
  72. response.SimAddress = reg.ExternalEndPoint.Address.ToString();
  73. response.SimPort = (Int32)reg.ExternalEndPoint.Port;
  74. response.RegionX = reg.RegionLocX ;
  75. response.RegionY = reg.RegionLocY ;
  76. //following port needs changing as we don't want a http listener for every region (or do we?)
  77. response.SeedCapability = "http://" + reg.ExternalHostName + ":" + this.serversInfo.HttpListenerPort.ToString() + "/CAPS/" + capsPath + "0000/";
  78. theUser.currentAgent.currentRegion = reg.SimUUID;
  79. theUser.currentAgent.currentHandle = reg.RegionHandle;
  80. Login _login = new Login();
  81. //copy data to login object
  82. _login.First = response.Firstname;
  83. _login.Last = response.Lastname;
  84. _login.Agent = response.AgentID;
  85. _login.Session = response.SessionID;
  86. _login.SecureSession = response.SecureSessionID;
  87. _login.CircuitCode = (uint)response.CircuitCode;
  88. _login.CapsPath = capsPath;
  89. m_Parent.InformRegionOfLogin(currentRegion, _login);
  90. }
  91. else
  92. {
  93. Console.WriteLine("not found region " + currentRegion);
  94. }
  95. }
  96. public UserProfileData SetupMasterUser(string firstName, string lastName)
  97. {
  98. return SetupMasterUser(firstName, lastName, "");
  99. }
  100. public UserProfileData SetupMasterUser(string firstName, string lastName, string password)
  101. {
  102. UserProfileData profile = getUserProfile(firstName, lastName);
  103. if (profile != null)
  104. {
  105. return profile;
  106. }
  107. Console.WriteLine("Unknown Master User. Sandbox Mode: Creating Account");
  108. this.AddUserProfile(firstName, lastName, password, defaultHomeX, defaultHomeY);
  109. profile = getUserProfile(firstName, lastName);
  110. if (profile == null)
  111. {
  112. Console.WriteLine("Unknown Master User after creation attempt. No clue what to do here.");
  113. }
  114. return profile;
  115. }
  116. }
  117. }