From 52a4c4d82f9c5b808e6c61fd51c1c70e42865565 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 12 Sep 2008 20:12:03 +0000 Subject: * Check in first part of http://opensimulator.org/mantis/view.php?id=2073 * This patch aims to introduce look at direction persistence between logins. It won't be active until the second part of the patch is committed in about two weeks time. At this point, region servers that haven't upgraded past this revision may run into problems * This checkin upgrades the user database. As always, we recommend you have backups in case something goes wrong. * Many thanks to tyre for this patch. --- .../Communications/Local/LocalLoginService.cs | 257 ++++++++++----------- .../Region/Communications/OGS1/OGS1UserServices.cs | 35 ++- .../Modules/InterGrid/OpenGridProtocolModule.cs | 3 - .../Scenes/SceneCommunicationService.cs | 12 +- OpenSim/Region/Environment/Scenes/ScenePresence.cs | 5 + 5 files changed, 168 insertions(+), 144 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Communications/Local/LocalLoginService.cs b/OpenSim/Region/Communications/Local/LocalLoginService.cs index 93a1e46..2f7fdb7 100644 --- a/OpenSim/Region/Communications/Local/LocalLoginService.cs +++ b/OpenSim/Region/Communications/Local/LocalLoginService.cs @@ -41,8 +41,7 @@ namespace OpenSim.Region.Communications.Local public class LocalLoginService : LoginService { - private static readonly ILog m_log - = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private CommunicationsLocal m_Parent; @@ -120,167 +119,167 @@ namespace OpenSim.Region.Communications.Local } } - private Regex reURI = new Regex(@"^uri:(?[^&]+)&(?\d+)&(?\d+)&(?\d+)$"); - + /// + /// Customises the login response and fills in missing values. + /// + /// The existing response + /// The user profile + /// The requested start location public override bool CustomiseResponse(LoginResponse response, UserProfileData theUser, string startLocationRequest) { - ulong currentRegion = 0; - - uint locX = 0; - uint locY = 0; - uint locZ = 0; - bool specificStartLocation = false; + // HomeLocation + RegionInfo homeInfo = null; + // use the homeRegionID if it is stored already. If not, use the regionHandle as before + if (theUser.HomeRegionID != UUID.Zero) + homeInfo = m_Parent.GridService.RequestNeighbourInfo(theUser.HomeRegionID); + else + homeInfo = m_Parent.GridService.RequestNeighbourInfo(theUser.HomeRegion); + if (homeInfo != null) + { + response.Home = + string.Format( + "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}", + (homeInfo.RegionLocX*Constants.RegionSize), + (homeInfo.RegionLocY*Constants.RegionSize), + theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z, + theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z); + } + else + { + // Emergency mode: Home-region isn't available, so we can't request the region info. + // Use the stored home regionHandle instead. + // NOTE: If the home-region moves, this will be wrong until the users update their user-profile again + ulong regionX = theUser.HomeRegion >> 32; + ulong regionY = theUser.HomeRegion & 0xffffffff; + response.Home = + string.Format( + "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}", + regionX, regionY, + theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z, + theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z); + m_log.InfoFormat("[LOGIN] Home region of user {0} {1} is not available; using computed region position {2} {3}", + theUser.FirstName, theUser.SurName, + regionX, regionY); + } - // get start location - if (startLocationRequest == "last") + // StartLocation + RegionInfo regionInfo = null; + if (startLocationRequest == "home") { - currentRegion = theUser.CurrentAgent.Handle; - locX = (UInt32)theUser.CurrentAgent.Position.X; - locY = (UInt32)theUser.CurrentAgent.Position.Y; - locZ = (UInt32)theUser.CurrentAgent.Position.Z; - response.StartLocation = "last"; - specificStartLocation = true; + regionInfo = homeInfo; + theUser.CurrentAgent.Position = theUser.HomeLocation; + response.LookAt = "[r" + theUser.HomeLookAt.X.ToString() + ",r" + theUser.HomeLookAt.Y.ToString() + ",r" + theUser.HomeLookAt.Z.ToString() + "]"; } - else if (startLocationRequest == "home") + else if (startLocationRequest == "last") { - currentRegion = theUser.HomeRegion; - response.StartLocation = "home"; + regionInfo = m_Parent.GridService.RequestNeighbourInfo(theUser.CurrentAgent.Region); + response.LookAt = "[r" + theUser.CurrentAgent.LookAt.X.ToString() + ",r" + theUser.CurrentAgent.LookAt.Y.ToString() + ",r" + theUser.CurrentAgent.LookAt.Z.ToString() + "]"; } else { - // use last location as default - currentRegion = theUser.CurrentAgent.Handle; - + Regex reURI = new Regex(@"^uri:(?[^&]+)&(?\d+)&(?\d+)&(?\d+)$"); Match uriMatch = reURI.Match(startLocationRequest); - if (null == uriMatch) + if (uriMatch == null) { m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, but can't process it", startLocationRequest); } else { string region = uriMatch.Groups["region"].ToString(); - - RegionInfo r = m_Parent.GridService.RequestClosestRegion(region); - if (null == r) + regionInfo = m_Parent.GridService.RequestClosestRegion(region); + if (regionInfo == null) { - m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, can't locate region {1}", - startLocationRequest, region); + m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, can't locate region {1}", startLocationRequest, region); } else { - currentRegion = r.RegionHandle; - locX = UInt32.Parse(uriMatch.Groups["x"].ToString()); - locY = UInt32.Parse(uriMatch.Groups["y"].ToString()); - locZ = UInt32.Parse(uriMatch.Groups["z"].ToString()); - // can be: last, home, safe, url - response.StartLocation = "url"; - specificStartLocation = true; + theUser.CurrentAgent.Position = new Vector3(float.Parse(uriMatch.Groups["x"].Value), + float.Parse(uriMatch.Groups["y"].Value), float.Parse(uriMatch.Groups["x"].Value)); } } + response.LookAt = "[r0,r1,r0]"; + // can be: last, home, safe, url + response.StartLocation = "url"; } - RegionInfo homeReg = m_Parent.GridService.RequestNeighbourInfo(theUser.HomeRegion); - RegionInfo reg = m_Parent.GridService.RequestNeighbourInfo(currentRegion); - - if ((homeReg != null) || (reg != null)) + if ((regionInfo != null) && (PrepareLoginToRegion(regionInfo, theUser, response))) { - if (homeReg != null) - { - response.Home = "{'region_handle':[r" + - (homeReg.RegionLocX * Constants.RegionSize).ToString() + ",r" + - (homeReg.RegionLocY * Constants.RegionSize).ToString() + "], " + - "'position':[r" + - theUser.HomeLocation.X.ToString() + ",r" + - theUser.HomeLocation.Y.ToString() + ",r" + - theUser.HomeLocation.Z.ToString() + "], " + - "'look_at':[r" + - theUser.HomeLocation.X.ToString() + ",r" + - theUser.HomeLocation.Y.ToString() + ",r" + - theUser.HomeLocation.Z.ToString() + "]}"; - } - else - { - m_log.Warn("[LOGIN]: Your home region doesn't exist"); - response.Home = "{'region_handle':[r" + - (reg.RegionLocX * Constants.RegionSize).ToString() + ",r" + - (reg.RegionLocY * Constants.RegionSize).ToString() + "], " + - "'position':[r" + - theUser.HomeLocation.X.ToString() + ",r" + - theUser.HomeLocation.Y.ToString() + ",r" + - theUser.HomeLocation.Z.ToString() + "], " + - "'look_at':[r" + - theUser.HomeLocation.X.ToString() + ",r" + - theUser.HomeLocation.Y.ToString() + ",r" + - theUser.HomeLocation.Z.ToString() + "]}"; - } - string capsPath = Util.GetRandomCapsPath(); - response.SimAddress = reg.ExternalEndPoint.Address.ToString(); - response.SimPort = (uint) reg.ExternalEndPoint.Port; - response.RegionX = reg.RegionLocX; - response.RegionY = reg.RegionLocY; - - m_log.DebugFormat( - "[CAPS][LOGIN]: RegionX {0} RegionY {0}", response.RegionX, response.RegionY); - - response.SeedCapability = "http://" + reg.ExternalHostName + ":" + - serversInfo.HttpListenerPort.ToString() + "/CAPS/" + capsPath + "0000/"; - - m_log.DebugFormat( - "[CAPS]: Sending new CAPS seed url {0} to client {1}", - response.SeedCapability, response.AgentID); - - theUser.CurrentAgent.Region = reg.RegionID; - theUser.CurrentAgent.Handle = reg.RegionHandle; - - // LoginResponse.BuddyList buddyList = new LoginResponse.BuddyList(); - - response.BuddList = ConvertFriendListItem(m_userManager.GetUserFriendList(theUser.ID)); - - Login _login = new Login(); - //copy data to login object - _login.First = response.Firstname; - _login.Last = response.Lastname; - _login.Agent = response.AgentID; - _login.Session = response.SessionID; - _login.SecureSession = response.SecureSessionID; - _login.CircuitCode = (uint) response.CircuitCode; - if (specificStartLocation) - _login.StartPos = new Vector3(locX, locY, locZ); - else - _login.StartPos = new Vector3(128, 128, 128); - _login.CapsPath = capsPath; + return true; + } - m_log.InfoFormat( - "[LOGIN]: Telling region {0} @ {1},{2} ({3}:{4}) to expect user connection", - reg.RegionName, response.RegionX, response.RegionY, response.SimAddress, response.SimPort); + // StartLocation not available, send him to a nearby region instead + // regionInfo = m_Parent.GridService.RequestClosestRegion(""); + //m_log.InfoFormat("[LOGIN]: StartLocation not available sending to region {0}", regionInfo.regionName); - handlerLoginToRegion = OnLoginToRegion; - if (handlerLoginToRegion != null) - { - handlerLoginToRegion(currentRegion, _login); - } - } - else + // Send him to default region instead + ulong defaultHandle = (((ulong)defaultHomeX * Constants.RegionSize) << 32) | + ((ulong)defaultHomeY * Constants.RegionSize); + + if ((regionInfo != null) && (defaultHandle == regionInfo.RegionHandle)) { - m_log.Warn("[LOGIN]: Not found region " + currentRegion); + m_log.ErrorFormat("[LOGIN]: Not trying the default region since this is the same as the selected region"); return false; } - return true; + m_log.Error("[LOGIN]: Sending user to default region " + defaultHandle + " instead"); + regionInfo = m_Parent.GridService.RequestNeighbourInfo(defaultHandle); + + // Customise the response + //response.Home = + // string.Format( + // "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}", + // (SimInfo.regionLocX * Constants.RegionSize), + // (SimInfo.regionLocY*Constants.RegionSize), + // theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z, + // theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z); + theUser.CurrentAgent.Position = new Vector3(128,128,0); + response.StartLocation = "safe"; + + return PrepareLoginToRegion(regionInfo, theUser, response); } - private LoginResponse.BuddyList ConvertFriendListItem(List LFL) + /// + /// Prepare a login to the given region. This involves both telling the region to expect a connection + /// and appropriately customising the response to the user. + /// + /// + /// + /// + /// true if the region was successfully contacted, false otherwise + private bool PrepareLoginToRegion(RegionInfo regionInfo, UserProfileData user, LoginResponse response) { - LoginResponse.BuddyList buddylistreturn = new LoginResponse.BuddyList(); - foreach (FriendListItem fl in LFL) - { - LoginResponse.BuddyList.BuddyInfo buddyitem = new LoginResponse.BuddyList.BuddyInfo(fl.Friend); - buddyitem.BuddyID = fl.Friend; - buddyitem.BuddyRightsHave = (int)fl.FriendListOwnerPerms; - buddyitem.BuddyRightsGiven = (int)fl.FriendPerms; - buddylistreturn.AddNewBuddy(buddyitem); - } - return buddylistreturn; + response.SimAddress = regionInfo.ExternalEndPoint.Address.ToString(); + response.SimPort = (uint)regionInfo.ExternalEndPoint.Port; + response.RegionX = regionInfo.RegionLocX; + response.RegionY = regionInfo.RegionLocY; + + string capsPath = Util.GetRandomCapsPath(); + response.SeedCapability = regionInfo.ServerURI + "/CAPS/" + capsPath + "0000/"; + + // Notify the target of an incoming user + m_log.InfoFormat( + "[LOGIN]: Telling {0} @ {1},{2} ({3}) to prepare for client connection", + regionInfo.RegionName, response.RegionX, response.RegionY, regionInfo.ServerURI); + // Update agent with target sim + user.CurrentAgent.Region = regionInfo.RegionID; + user.CurrentAgent.Handle = regionInfo.RegionHandle; + // Prepare notification + Login loginParams = new Login(); + loginParams.Session = user.CurrentAgent.SessionID.ToString(); + loginParams.SecureSession = user.CurrentAgent.SecureSessionID.ToString(); + loginParams.First = user.FirstName; + loginParams.Last = user.SurName; + loginParams.Agent = user.ID.ToString(); + loginParams.CircuitCode = Convert.ToUInt32(response.CircuitCode); + loginParams.StartPos = user.CurrentAgent.Position; + loginParams.CapsPath = capsPath; + + handlerLoginToRegion = OnLoginToRegion; + if (handlerLoginToRegion == null) + return false; + + handlerLoginToRegion(user.CurrentAgent.Handle, loginParams); + return true; } // See LoginService diff --git a/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs b/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs index 36a82a8..b8268eb 100644 --- a/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs +++ b/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs @@ -235,19 +235,22 @@ namespace OpenSim.Region.Communications.OGS1 /// Logs off a user on the user server /// /// UUID of the user - /// UUID of the Region - /// final position x - /// final position y - /// final position z - public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz) + /// UUID of the Region + /// regionhandle + /// final position + /// final lookat + public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat) { Hashtable param = new Hashtable(); param["avatar_uuid"] = userid.Guid.ToString(); param["region_uuid"] = regionid.Guid.ToString(); param["region_handle"] = regionhandle.ToString(); - param["region_pos_x"] = posx.ToString(); - param["region_pos_y"] = posy.ToString(); - param["region_pos_z"] = posz.ToString(); + param["region_pos_x"] = position.X.ToString(); + param["region_pos_y"] = position.Y.ToString(); + param["region_pos_z"] = position.Z.ToString(); + param["lookat_x"] = lookat.X.ToString(); + param["lookat_y"] = lookat.Y.ToString(); + param["lookat_z"] = lookat.Z.ToString(); IList parameters = new ArrayList(); parameters.Add(param); @@ -263,6 +266,20 @@ namespace OpenSim.Region.Communications.OGS1 } } + /// + /// Logs off a user on the user server (deprecated as of 2008-08-27) + /// + /// UUID of the user + /// UUID of the Region + /// regionhandle + /// final position x + /// final position y + /// final position z + public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz) + { + LogOffUser(userid, regionid, regionhandle, new Vector3(posx, posy, posz), new Vector3()); + } + public UserProfileData GetUserProfile(string firstName, string lastName) { return GetUserProfile(firstName + " " + lastName); @@ -672,7 +689,7 @@ namespace OpenSim.Region.Communications.OGS1 } } /// - /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for LLUUID friendslistowner + /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for UUID friendslistowner /// /// The agent that we're retreiving the friends Data. public List GetUserFriendList(UUID friendlistowner) diff --git a/OpenSim/Region/Environment/Modules/InterGrid/OpenGridProtocolModule.cs b/OpenSim/Region/Environment/Modules/InterGrid/OpenGridProtocolModule.cs index 6d06bb5..2604b3f 100644 --- a/OpenSim/Region/Environment/Modules/InterGrid/OpenGridProtocolModule.cs +++ b/OpenSim/Region/Environment/Modules/InterGrid/OpenGridProtocolModule.cs @@ -322,9 +322,6 @@ namespace OpenSim.Region.Environment.Modules.InterGrid useragent.LoginTime=Util.UnixTimeSinceEpoch(); useragent.LogoutTime = 0; useragent.Position=agentData.startpos; - useragent.PositionX=agentData.startpos.X; - useragent.PositionY=agentData.startpos.Y; - useragent.PositionZ=agentData.startpos.Z; useragent.Region=reg.originRegionID; useragent.SecureSessionID=agentData.SecureSessionID; useragent.SessionID = agentData.SessionID; diff --git a/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs index 9ff35c0..887a8da 100644 --- a/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs +++ b/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs @@ -579,7 +579,7 @@ namespace OpenSim.Region.Environment.Scenes /// /// public virtual void RequestTeleportToLocation(ScenePresence avatar, ulong regionHandle, Vector3 position, - Vector3 lookAt, uint flags) + Vector3 lookAt, uint teleportFlags) { bool destRegionUp = false; @@ -604,7 +604,7 @@ namespace OpenSim.Region.Environment.Scenes position.Z = newPosZ; } avatar.ControllingClient.SendTeleportLocationStart(); - avatar.ControllingClient.SendLocalTeleport(position, lookAt, flags); + avatar.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags); avatar.Teleport(position); } else @@ -662,7 +662,7 @@ namespace OpenSim.Region.Environment.Scenes m_log.DebugFormat( "[CAPS]: Sending new CAPS seed url {0} to client {1}", capsPath, avatar.UUID); - avatar.ControllingClient.SendRegionTeleport(reg.RegionHandle, 13, reg.ExternalEndPoint, 4, (1 << 4), + avatar.ControllingClient.SendRegionTeleport(reg.RegionHandle, 13, reg.ExternalEndPoint, 4, teleportFlags, capsPath); avatar.MakeChildAgent(); Thread.Sleep(5000); @@ -716,6 +716,12 @@ namespace OpenSim.Region.Environment.Scenes return m_commsProvider.GridService.GetGridSettings(); } + public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat) + { + m_commsProvider.LogOffUser(userid, regionid, regionhandle, position, lookat); + } + + // deprecated as of 2008-08-27 public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz) { m_commsProvider.LogOffUser(userid, regionid, regionhandle, posx, posy, posz); diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index 1a4b0c9..abda63e 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs @@ -241,6 +241,11 @@ namespace OpenSim.Region.Environment.Scenes get { return m_CameraCenter; } } + public Vector3 Lookat + { + get { return Util.GetNormalizedVector(new Vector3(m_CameraAtAxis.X, m_CameraAtAxis.Y, 0)); } + } + private readonly string m_firstname; public string Firstname -- cgit v1.1