diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs index 8eb2b1eb37..efd4ca6bad 100644 --- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs @@ -71,6 +71,8 @@ namespace OpenSim.Region.CoreModules.World.Estate public event ChangeDelegate OnRegionInfoChange; public event ChangeDelegate OnEstateInfoChange; public event MessageDelegate OnEstateMessage; + public event EstateTeleportOneUserHomeRequest OnEstateTeleportOneUserHomeRequest; + public event EstateTeleportAllUsersHomeRequest OnEstateTeleportAllUsersHomeRequest; private int m_delayCount = 0; @@ -1193,13 +1195,20 @@ namespace OpenSim.Region.CoreModules.World.Estate private void handleEstateTeleportOneUserHomeRequest(IClientAPI remover_client, UUID invoice, UUID senderID, UUID prey) { + EstateTeleportOneUserHomeRequest evOverride = OnEstateTeleportOneUserHomeRequest; + if(evOverride != null) + { + evOverride(remover_client, invoice, senderID, prey); + return; + } + if (!Scene.Permissions.CanIssueEstateCommand(remover_client.AgentId, false)) return; if (prey != UUID.Zero) { ScenePresence s = Scene.GetScenePresence(prey); - if (s != null) + if (s != null && !s.IsDeleted && !s.IsInTransit) { if (!Scene.TeleportClientHome(prey, s.ControllingClient)) { @@ -1212,6 +1221,13 @@ namespace OpenSim.Region.CoreModules.World.Estate private void handleEstateTeleportAllUsersHomeRequest(IClientAPI remover_client, UUID invoice, UUID senderID) { + EstateTeleportAllUsersHomeRequest evOverride = OnEstateTeleportAllUsersHomeRequest; + if(evOverride != null) + { + evOverride(remover_client, invoice, senderID); + return; + } + if (!Scene.Permissions.CanIssueEstateCommand(remover_client.AgentId, false)) return; diff --git a/OpenSim/Region/CoreModules/World/Estate/XEstateConnector.cs b/OpenSim/Region/CoreModules/World/Estate/XEstateConnector.cs index 73e706c339..2c0c882b60 100644 --- a/OpenSim/Region/CoreModules/World/Estate/XEstateConnector.cs +++ b/OpenSim/Region/CoreModules/World/Estate/XEstateConnector.cs @@ -46,16 +46,19 @@ namespace OpenSim.Region.CoreModules.World.Estate private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); protected XEstateModule m_EstateModule; + private string token; - public EstateConnector(XEstateModule module) + public EstateConnector(XEstateModule module, string _token) { m_EstateModule = module; + token = _token; } public void SendTeleportHomeOneUser(uint EstateID, UUID PreyID) { Dictionary sendData = new Dictionary(); sendData["METHOD"] = "teleport_home_one_user"; + sendData["TOKEN"] = token; sendData["EstateID"] = EstateID.ToString(); sendData["PreyID"] = PreyID.ToString(); @@ -67,6 +70,7 @@ namespace OpenSim.Region.CoreModules.World.Estate { Dictionary sendData = new Dictionary(); sendData["METHOD"] = "teleport_home_all_users"; + sendData["TOKEN"] = token; sendData["EstateID"] = EstateID.ToString(); @@ -77,6 +81,7 @@ namespace OpenSim.Region.CoreModules.World.Estate { Dictionary sendData = new Dictionary(); sendData["METHOD"] = "update_covenant"; + sendData["TOKEN"] = token; sendData["CovenantID"] = CovenantID.ToString(); sendData["EstateID"] = EstateID.ToString(); @@ -99,6 +104,7 @@ namespace OpenSim.Region.CoreModules.World.Estate { Dictionary sendData = new Dictionary(); sendData["METHOD"] = "update_estate"; + sendData["TOKEN"] = token; sendData["EstateID"] = EstateID.ToString(); @@ -119,6 +125,7 @@ namespace OpenSim.Region.CoreModules.World.Estate { Dictionary sendData = new Dictionary(); sendData["METHOD"] = "estate_message"; + sendData["TOKEN"] = token; sendData["EstateID"] = EstateID.ToString(); sendData["FromID"] = FromID.ToString(); @@ -132,47 +139,43 @@ namespace OpenSim.Region.CoreModules.World.Estate { List regions = m_EstateModule.Scenes[0].GetEstateRegions((int)EstateID); - UUID ScopeID = UUID.Zero; + // Don't send to the same instance twice + List done = new List(); // Handle local regions locally - // lock (m_EstateModule.Scenes) { foreach (Scene s in m_EstateModule.Scenes) { - if (regions.Contains(s.RegionInfo.RegionID)) + RegionInfo sreg = s.RegionInfo; + if (regions.Contains(sreg.RegionID)) { - // All regions in one estate are in the same scope. - // Use that scope. - // - ScopeID = s.RegionInfo.ScopeID; - regions.Remove(s.RegionInfo.RegionID); + string url = sreg.ExternalHostName + ":" + sreg.HttpPort; + regions.Remove(sreg.RegionID); + if(!done.Contains(url)) // we may have older regs with same url lost in dbs + done.Add(url); } } } - // Our own region should always be in the above list. - // In a standalone this would not be true. But then, - // Scope ID is not relevat there. Use first scope. - // - if (ScopeID == UUID.Zero) - ScopeID = m_EstateModule.Scenes[0].RegionInfo.ScopeID; + if(regions.Count == 0) + return; - // Don't send to the same instance twice - // - List done = new List(); + Scene baseScene = m_EstateModule.Scenes[0]; + UUID ScopeID = baseScene.RegionInfo.ScopeID; + IGridService gridService = baseScene.GridService; + if(gridService == null) + return; // Send to remote regions - // foreach (UUID regionID in regions) { - GridRegion region = m_EstateModule.Scenes[0].GridService.GetRegionByUUID(ScopeID, regionID); + GridRegion region = gridService.GetRegionByUUID(ScopeID, regionID); if (region != null) { - string url = "http://" + region.ExternalHostName + ":" + region.HttpPort; - if (done.Contains(url)) + string url = region.ExternalHostName + ":" + region.HttpPort; + if(done.Contains(url)) continue; - Call(region, sendData); done.Add(url); } @@ -185,7 +188,12 @@ namespace OpenSim.Region.CoreModules.World.Estate // m_log.DebugFormat("[XESTATE CONNECTOR]: queryString = {0}", reqString); try { - string url = "http://" + region.ExternalHostName + ":" + region.HttpPort; + string url = ""; + if(string.IsNullOrEmpty(region.ServerURI)) + url = "http://" + region.ExternalHostName + ":" + region.HttpPort; + else + url = region.ServerURI; + string reply = SynchronousRestFormsRequester.MakeRequest("POST", url + "/estate", reqString); diff --git a/OpenSim/Region/CoreModules/World/Estate/XEstateModule.cs b/OpenSim/Region/CoreModules/World/Estate/XEstateModule.cs index 4bb3799dc9..a7195af2a5 100644 --- a/OpenSim/Region/CoreModules/World/Estate/XEstateModule.cs +++ b/OpenSim/Region/CoreModules/World/Estate/XEstateModule.cs @@ -51,6 +51,7 @@ namespace OpenSim.Region.CoreModules.World.Estate protected List m_Scenes = new List(); protected bool m_InInfoUpdate = false; + private string token = "7db8eh2gvgg45jj"; public bool InInfoUpdate { @@ -69,17 +70,19 @@ namespace OpenSim.Region.CoreModules.World.Estate { int port = 0; - IConfig estateConfig = config.Configs["Estate"]; + IConfig estateConfig = config.Configs["Estates"]; if (estateConfig != null) { port = estateConfig.GetInt("Port", 0); + // this will need to came from somewhere else + token = estateConfig.GetString("Token", token); } - m_EstateConnector = new EstateConnector(this); + m_EstateConnector = new EstateConnector(this, token); // Instantiate the request handler IHttpServer server = MainServer.GetHttpServer((uint)port); - server.AddStreamHandler(new EstateRequestHandler(this)); + server.AddStreamHandler(new EstateRequestHandler(this, token)); } public void PostInitialise() @@ -94,8 +97,6 @@ namespace OpenSim.Region.CoreModules.World.Estate { lock (m_Scenes) m_Scenes.Add(scene); - - scene.EventManager.OnNewClient += OnNewClient; } public void RegionLoaded(Scene scene) @@ -105,12 +106,12 @@ namespace OpenSim.Region.CoreModules.World.Estate em.OnRegionInfoChange += OnRegionInfoChange; em.OnEstateInfoChange += OnEstateInfoChange; em.OnEstateMessage += OnEstateMessage; + em.OnEstateTeleportOneUserHomeRequest += OnEstateTeleportOneUserHomeRequest; + em.OnEstateTeleportAllUsersHomeRequest += OnEstateTeleportAllUsersHomeRequest; } public void RemoveRegion(Scene scene) { - scene.EventManager.OnNewClient -= OnNewClient; - lock (m_Scenes) m_Scenes.Remove(scene); } @@ -181,13 +182,6 @@ namespace OpenSim.Region.CoreModules.World.Estate m_EstateConnector.SendEstateMessage(estateID, FromID, FromName, Message); } - private void OnNewClient(IClientAPI client) - { - client.OnEstateTeleportOneUserHomeRequest += OnEstateTeleportOneUserHomeRequest; - client.OnEstateTeleportAllUsersHomeRequest += OnEstateTeleportAllUsersHomeRequest; - - } - private void OnEstateTeleportOneUserHomeRequest(IClientAPI client, UUID invoice, UUID senderID, UUID prey) { if (prey == UUID.Zero) @@ -205,16 +199,18 @@ namespace OpenSim.Region.CoreModules.World.Estate foreach (Scene s in Scenes) { - if (s == scene) - continue; // Already handles by estate module if (s.RegionInfo.EstateSettings.EstateID != estateID) continue; ScenePresence p = scene.GetScenePresence(prey); - if (p != null && !p.IsChildAgent) + if (p != null && !p.IsChildAgent ) { - p.ControllingClient.SendTeleportStart(16); - scene.TeleportClientHome(prey, p.ControllingClient); + if(!p.IsDeleted && !p.IsInTransit) + { + p.ControllingClient.SendTeleportStart(16); + scene.TeleportClientHome(prey, p.ControllingClient); + } + return; } } @@ -235,8 +231,6 @@ namespace OpenSim.Region.CoreModules.World.Estate foreach (Scene s in Scenes) { - if (s == scene) - continue; // Already handles by estate module if (s.RegionInfo.EstateSettings.EstateID != estateID) continue; diff --git a/OpenSim/Region/CoreModules/World/Estate/XEstateRequestHandler.cs b/OpenSim/Region/CoreModules/World/Estate/XEstateRequestHandler.cs index 1dcaed333f..756b54dcb1 100644 --- a/OpenSim/Region/CoreModules/World/Estate/XEstateRequestHandler.cs +++ b/OpenSim/Region/CoreModules/World/Estate/XEstateRequestHandler.cs @@ -48,11 +48,13 @@ namespace OpenSim.Region.CoreModules.World.Estate protected XEstateModule m_EstateModule; protected Object m_RequestLock = new Object(); + private string token; - public EstateRequestHandler(XEstateModule fmodule) + public EstateRequestHandler(XEstateModule fmodule, string _token) : base("POST", "/estate") { m_EstateModule = fmodule; + token = _token; } protected override byte[] ProcessRequest(string path, Stream requestData, @@ -75,6 +77,15 @@ namespace OpenSim.Region.CoreModules.World.Estate if (!request.ContainsKey("METHOD")) return FailureResult(); + if (!request.ContainsKey("TOKEN")) + return FailureResult(); + + string reqToken = request["TOKEN"].ToString(); + request.Remove("TOKEN"); + + if(token != reqToken) + return FailureResult(); + string method = request["METHOD"].ToString(); request.Remove("METHOD"); diff --git a/OpenSim/Region/Framework/Interfaces/IEstateModule.cs b/OpenSim/Region/Framework/Interfaces/IEstateModule.cs index 461c880fe0..6b8b999ae2 100644 --- a/OpenSim/Region/Framework/Interfaces/IEstateModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IEstateModule.cs @@ -39,6 +39,8 @@ namespace OpenSim.Region.Framework.Interfaces event ChangeDelegate OnRegionInfoChange; event ChangeDelegate OnEstateInfoChange; event MessageDelegate OnEstateMessage; + event EstateTeleportOneUserHomeRequest OnEstateTeleportOneUserHomeRequest; + event EstateTeleportAllUsersHomeRequest OnEstateTeleportAllUsersHomeRequest; uint GetRegionFlags(); bool IsManager(UUID avatarID);