From 796a8efe25e74253b25d3c8a265635e8517d5f05 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 18 Jan 2019 22:18:49 +0000 Subject: [PATCH] a few changes to tp home --- .../EntityTransfer/EntityTransferModule.cs | 97 ++++++++++++------- .../EntityTransfer/HGEntityTransferModule.cs | 90 +++++++++++------ .../CoreModules/World/Estate/EstateModule.cs | 22 ++--- 3 files changed, 134 insertions(+), 75 deletions(-) diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index 53061a4e51..ce88e6b768 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -391,7 +391,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer try { - if (regionHandle == sp.Scene.RegionInfo.RegionHandle) { if(!sp.AllowMovement) @@ -486,7 +485,13 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer { position.Z = posZLimit; } - +/* + if(!sp.CheckLocalTPLandingPoint(ref position)) + { + sp.ControllingClient.SendTeleportFailed("Not allowed at destination"); + return; + } +*/ if (sp.Flying) teleportFlags |= (uint)TeleportFlags.IsFlying; @@ -1389,45 +1394,67 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer public virtual bool TeleportHome(UUID id, IClientAPI client) { - m_log.DebugFormat( - "[ENTITY TRANSFER MODULE]: Request to teleport {0} {1} home", client.Name, client.AgentId); - - //OpenSim.Services.Interfaces.PresenceInfo pinfo = Scene.PresenceService.GetAgent(client.SessionId); - GridUserInfo uinfo = Scene.GridUserService.GetGridUserInfo(client.AgentId.ToString()); - - if (uinfo != null) + bool isSame = false; + if (client != null && id == client.AgentId) { - if (uinfo.HomeRegionID == UUID.Zero) - { - // can't find the Home region: Tell viewer and abort - m_log.ErrorFormat("{0} No grid user info found for {1} {2}. Cannot send home.", - LogHeader, client.Name, client.AgentId); - client.SendTeleportFailed("You don't have a home position set."); - return false; - } - GridRegion regionInfo = Scene.GridService.GetRegionByUUID(UUID.Zero, uinfo.HomeRegionID); - if (regionInfo == null) - { - // can't find the Home region: Tell viewer and abort - client.SendTeleportFailed("Your home region could not be found."); - return false; - } - - m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Home region of {0} is {1} ({2}-{3})", - client.Name, regionInfo.RegionName, regionInfo.RegionCoordX, regionInfo.RegionCoordY); - - // a little eekie that this goes back to Scene and with a forced cast, will fix that at some point... - ((Scene)(client.Scene)).RequestTeleportLocation( - client, regionInfo.RegionHandle, uinfo.HomePosition, uinfo.HomeLookAt, - (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome)); - return true; + isSame = true; + m_log.DebugFormat( + "[ENTITY TRANSFER MODULE]: Request to teleport {0} {1} home", client.Name, id); } else + m_log.DebugFormat( + "[ENTITY TRANSFER MODULE]: Request to teleport {0} home by {1} {2}", id, client.Name, client.AgentId); + + ScenePresence sp = ((Scene)(client.Scene)).GetScenePresence(id); + if (sp == null || sp.IsDeleted || sp.IsChildAgent || sp.ControllingClient == null || !sp.ControllingClient.IsActive) + { + if (isSame) + client.SendTeleportFailed("Internal error, agent presence not found"); + m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Agent not found in the scene where it is supposed to be"); + return false; + } + + if (sp.IsInTransit) + { + if (isSame) + client.SendTeleportFailed("Already processing a teleport"); + m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Agent still in teleport"); + return false; + } + + //OpenSim.Services.Interfaces.PresenceInfo pinfo = Scene.PresenceService.GetAgent(client.SessionId); + GridUserInfo uinfo = Scene.GridUserService.GetGridUserInfo(id.ToString()); + if(uinfo == null) + { + m_log.ErrorFormat("[ENTITY TRANSFER MODULE] Griduser info not found for {1}. Cannot send home.", id); + if (isSame) + client.SendTeleportFailed("Your home region could not be found."); + return false; + } + + if (uinfo.HomeRegionID == UUID.Zero) { // can't find the Home region: Tell viewer and abort - client.SendTeleportFailed("Your home region could not be found."); + m_log.ErrorFormat("[ENTITY TRANSFER MODULE] no home set {0}", id); + if (isSame) + client.SendTeleportFailed("home position set not"); + return false; } - return false; + + GridRegion regionInfo = Scene.GridService.GetRegionByUUID(UUID.Zero, uinfo.HomeRegionID); + if (regionInfo == null) + { + // can't find the Home region: Tell viewer and abort + m_log.ErrorFormat("[ENTITY TRANSFER MODULE] {0} home region {1} not found", id, uinfo.HomeRegionID); + if (isSame) + client.SendTeleportFailed("Your home region could not be found."); + return false; + } + + Teleport(sp, regionInfo.RegionHandle, uinfo.HomePosition, uinfo.HomeLookAt, + (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome)); + + return true; } #endregion diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs index 56c654f224..c82d93a95f 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs @@ -38,13 +38,14 @@ using OpenSim.Services.Connectors.Hypergrid; using OpenSim.Services.Interfaces; using OpenSim.Server.Base; -using GridRegion = OpenSim.Services.Interfaces.GridRegion; - using OpenMetaverse; using log4net; using Nini.Config; using Mono.Addins; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; + + namespace OpenSim.Region.CoreModules.Framework.EntityTransfer { [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HGEntityTransferModule")] @@ -436,9 +437,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer public override bool TeleportHome(UUID id, IClientAPI client) { - m_log.DebugFormat( - "[ENTITY TRANSFER MODULE]: Request to teleport {0} {1} home", client.Name, client.AgentId); - // Let's find out if this is a foreign user or a local user IUserManagement uMan = Scene.RequestModuleInterface(); if (uMan != null && uMan.IsLocalGridUser(id)) @@ -448,23 +446,53 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer return base.TeleportHome(id, client); } - // Foreign user wants to go home - // - AgentCircuitData aCircuit = ((Scene)(client.Scene)).AuthenticateHandler.GetAgentCircuitData(client.CircuitCode); - if (aCircuit == null || (aCircuit != null && !aCircuit.ServiceURLs.ContainsKey("HomeURI"))) + bool issame = false; + if (client != null && id == client.AgentId) { - client.SendTeleportFailed("Your information has been lost"); - m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Unable to locate agent's gateway information"); + issame = true; + m_log.DebugFormat( + "[HG ENTITY TRANSFER MODULE]: Request to teleport {0} {1} home", client.Name, id); + } + else + m_log.DebugFormat( + "[HG ENTITY TRANSFER MODULE]: Request to teleport {0} home by {1} {2}", id, client.Name, client.AgentId); + + ScenePresence sp = ((Scene)(client.Scene)).GetScenePresence(id); + if (sp == null || sp.IsDeleted || sp.IsChildAgent || sp.ControllingClient == null || !sp.ControllingClient.IsActive) + { + if (issame) + client.SendTeleportFailed("Internal error, agent presence not found"); + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent not found in the scene"); return false; } - IUserAgentService userAgentService = new UserAgentServiceConnector(aCircuit.ServiceURLs["HomeURI"].ToString()); + if (sp.IsInTransit) + { + if (issame) + client.SendTeleportFailed("Already processing a teleport"); + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent still in teleport"); + return false; + } + + // Foreign user wants to go home + // + AgentCircuitData aCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); + if (aCircuit == null || !aCircuit.ServiceURLs.ContainsKey("HomeURI")) + { + if (issame) + client.SendTeleportFailed("Agent Home information has been lost"); + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Unable to locate agent's gateway information"); + return false; + } + string homeURI = aCircuit.ServiceURLs["HomeURI"].ToString(); + + IUserAgentService userAgentService = new UserAgentServiceConnector(homeURI); Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY; GridRegion finalDestination = null; try { - finalDestination = userAgentService.GetHomeRegion(aCircuit.AgentID, out position, out lookAt); + finalDestination = userAgentService.GetHomeRegion(id, out position, out lookAt); } catch (Exception e) { @@ -473,20 +501,21 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer if (finalDestination == null) { - client.SendTeleportFailed("Your home region could not be found"); + if (issame) + client.SendTeleportFailed("Home region could not be found"); m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent's home region not found"); return false; } - ScenePresence sp = ((Scene)(client.Scene)).GetScenePresence(client.AgentId); - if (sp == null) + if (sp.IsDeleted || sp.IsChildAgent || sp.IsInTransit) { - client.SendTeleportFailed("Internal error"); - m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent not found in the scene where it is supposed to be"); + if (issame) + client.SendTeleportFailed("Agent lost or started other tp"); + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent lost or started other tp"); return false; } - GridRegion homeGatekeeper = MakeRegion(aCircuit); + GridRegion homeGatekeeper = MakeGateKeeperRegion(homeURI); m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: teleporting user {0} {1} home to {2} via {3}:{4}", aCircuit.firstname, aCircuit.lastname, finalDestination.RegionName, homeGatekeeper.ServerURI, homeGatekeeper.RegionName); @@ -525,8 +554,13 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer { // Foreign region GatekeeperServiceConnector gConn = new GatekeeperServiceConnector(); - GridRegion gatekeeper = new GridRegion(); - gatekeeper.ServerURI = lm.Gatekeeper; + GridRegion gatekeeper = MakeGateKeeperRegion(lm.Gatekeeper); + if (gatekeeper == null) + { + remoteClient.SendTeleportFailed("Could not parse landmark destiny URI"); + return; + } + string homeURI = Scene.GetAgentHomeURI(remoteClient.AgentId); string message; @@ -741,20 +775,20 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer #endregion - private GridRegion MakeRegion(AgentCircuitData aCircuit) + private GridRegion MakeGateKeeperRegion(string wantedURI) { - GridRegion region = new GridRegion(); - - Uri uri = null; - if (!aCircuit.ServiceURLs.ContainsKey("HomeURI") || - (aCircuit.ServiceURLs.ContainsKey("HomeURI") && !Uri.TryCreate(aCircuit.ServiceURLs["HomeURI"].ToString(), UriKind.Absolute, out uri))) + Uri uri; + if(!Uri.TryCreate(wantedURI, UriKind.Absolute, out uri)) return null; + GridRegion region = new GridRegion(); + region.ExternalHostName = uri.Host; region.HttpPort = (uint)uri.Port; - region.ServerURI = aCircuit.ServiceURLs["HomeURI"].ToString(); + region.ServerURI = wantedURI; //uri.AbsoluteUri for some reason default ports are needed region.RegionName = string.Empty; region.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), (int)0); + region.RegionFlags = OpenSim.Framework.RegionFlags.Hyperlink; return region; } } diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateModule.cs index f3c8aa8f1a..f4a174a7a7 100644 --- a/OpenSim/Region/CoreModules/World/Estate/EstateModule.cs +++ b/OpenSim/Region/CoreModules/World/Estate/EstateModule.cs @@ -225,13 +225,10 @@ namespace OpenSim.Region.CoreModules.World.Estate continue; ScenePresence p = scene.GetScenePresence(prey); - if (p != null && !p.IsChildAgent ) + if (p != null && !p.IsChildAgent && !p.IsDeleted && !p.IsInTransit) { - if(!p.IsDeleted && !p.IsInTransit) - { - p.ControllingClient.SendTeleportStart(16); - scene.TeleportClientHome(prey, p.ControllingClient); - } + p.ControllingClient.SendTeleportStart(16); + scene.TeleportClientHome(prey, client); return; } } @@ -256,13 +253,14 @@ namespace OpenSim.Region.CoreModules.World.Estate if (s.RegionInfo.EstateSettings.EstateID != estateID) continue; - scene.ForEachScenePresence(delegate(ScenePresence p) { - if (p != null && !p.IsChildAgent) + scene.ForEachScenePresence(delegate(ScenePresence p) { - p.ControllingClient.SendTeleportStart(16); - scene.TeleportClientHome(p.ControllingClient.AgentId, p.ControllingClient); - } - }); + if (p != null && !p.IsChildAgent && !p.IsDeleted && !p.IsInTransit) + { + p.ControllingClient.SendTeleportStart(16); + scene.TeleportClientHome(p.ControllingClient.AgentId, client); + } + }); } m_EstateConnector.SendTeleportHomeAllUsers(estateID);