From fd64823466ee667d0d827f95d3001ec8675512b2 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 18 Jan 2010 10:37:11 -0800 Subject: * Added missing GatekeeperServiceConnector * Added basic machinery for teleporting users home. Untested. --- .../EntityTransfer/EntityTransferModule.cs | 456 +++++++++++---------- .../EntityTransfer/HGEntityTransferModule.cs | 49 +++ .../Hypergrid/GatekeeperServerConnector.cs | 1 + .../Server/Handlers/Hypergrid/HypergridHandlers.cs | 33 ++ .../Hypergrid/GatekeeperServiceConnector.cs | 119 ++++++ .../Services/HypergridService/GatekeeperService.cs | 38 +- .../Services/HypergridService/HypergridService.cs | 8 +- OpenSim/Services/Interfaces/IGatekeeperService.cs | 3 + 8 files changed, 478 insertions(+), 229 deletions(-) create mode 100644 OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index fcc7a85..e85f270 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -183,7 +183,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer sp.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags); sp.Teleport(position); } - else + else // Another region possibly in another simulator { uint x = 0, y = 0; Utils.LongToUInts(regionHandle, out x, out y); @@ -191,15 +191,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer if (reg != null) { - m_log.DebugFormat( - "[ENTITY TRANSFER MODULE]: RequestTeleportToLocation to {0} in {1}", - position, reg.RegionName); - - uint newRegionX = (uint)(reg.RegionHandle >> 40); - uint newRegionY = (((uint)(reg.RegionHandle)) >> 8); - uint oldRegionX = (uint)(sp.Scene.RegionInfo.RegionHandle >> 40); - uint oldRegionY = (((uint)(sp.Scene.RegionInfo.RegionHandle)) >> 8); - GridRegion finalDestination = GetFinalDestination(reg); if (finalDestination == null) { @@ -207,220 +198,16 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer sp.ControllingClient.SendTeleportFailed("Problem at destination"); return; } - m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Final destination is x={0} y={1} uuid={2}", finalDestination.RegionLocX, finalDestination.RegionLocY, finalDestination.RegionID); - ulong destinationHandle = finalDestination.RegionHandle; - - if (eq == null) - sp.ControllingClient.SendTeleportLocationStart(); - - // Let's do DNS resolution only once in this process, please! - // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field, - // it's actually doing a lot of work. - IPEndPoint endPoint = finalDestination.ExternalEndPoint; - if (endPoint.Address == null) - { - // Couldn't resolve the name. Can't TP, because the viewer wants IP addresses. - destRegionUp = false; - } - - if (destRegionUp) - { - // Fixing a bug where teleporting while sitting results in the avatar ending up removed from - // both regions - if (sp.ParentID != (uint)0) - sp.StandUp(); - - if (!sp.ValidateAttachments()) - { - sp.ControllingClient.SendTeleportFailed("Inconsistent attachment state"); - return; - } - - // the avatar.Close below will clear the child region list. We need this below for (possibly) - // closing the child agents, so save it here (we need a copy as it is Clear()-ed). - //List childRegions = new List(avatar.GetKnownRegionList()); - // Compared to ScenePresence.CrossToNewRegion(), there's no obvious code to handle a teleport - // failure at this point (unlike a border crossing failure). So perhaps this can never fail - // once we reach here... - //avatar.Scene.RemoveCapsHandler(avatar.UUID); - - string capsPath = String.Empty; - - AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); - AgentCircuitData agentCircuit = sp.ControllingClient.RequestClientInfo(); - agentCircuit.startpos = position; - agentCircuit.child = true; - agentCircuit.Appearance = sp.Appearance; - if (currentAgentCircuit != null) - agentCircuit.ServiceURLs = currentAgentCircuit.ServiceURLs; - - if (NeedsNewAgent(oldRegionX, newRegionX, oldRegionY, newRegionY)) - { - // brand new agent, let's create a new caps seed - agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath(); - } - - string reason = String.Empty; - - // Let's create an agent there if one doesn't exist yet. - if (!CreateAgent(reg, finalDestination, agentCircuit, teleportFlags, out reason)) - { - sp.ControllingClient.SendTeleportFailed(String.Format("Destination refused: {0}", - reason)); - return; - } - - // OK, it got this agent. Let's close some child agents - sp.CloseChildAgents(newRegionX, newRegionY); - - if (NeedsNewAgent(oldRegionX, newRegionX, oldRegionY, newRegionY)) - { - #region IP Translation for NAT - IClientIPEndpoint ipepClient; - if (sp.ClientView.TryGet(out ipepClient)) - { - capsPath - = "http://" - + NetworkUtil.GetHostFor(ipepClient.EndPoint, finalDestination.ExternalHostName) - + ":" - + finalDestination.HttpPort - + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath); - } - else - { - capsPath - = "http://" - + finalDestination.ExternalHostName - + ":" - + finalDestination.HttpPort - + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath); - } - #endregion - - if (eq != null) - { - #region IP Translation for NAT - // Uses ipepClient above - if (sp.ClientView.TryGet(out ipepClient)) - { - endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address); - } - #endregion - - eq.EnableSimulator(destinationHandle, endPoint, sp.UUID); - - // ES makes the client send a UseCircuitCode message to the destination, - // which triggers a bunch of things there. - // So let's wait - Thread.Sleep(2000); - - eq.EstablishAgentCommunication(sp.UUID, endPoint, capsPath); - - } - else - { - sp.ControllingClient.InformClientOfNeighbour(destinationHandle, endPoint); - } - } - else - { - agentCircuit.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, reg.RegionHandle); - capsPath = "http://" + finalDestination.ExternalHostName + ":" + finalDestination.HttpPort - + "/CAPS/" + agentCircuit.CapsPath + "0000/"; - } - - // Expect avatar crossing is a heavy-duty function at the destination. - // That is where MakeRoot is called, which fetches appearance and inventory. - // Plus triggers OnMakeRoot, which spawns a series of asynchronous updates. - //m_commsProvider.InterRegion.ExpectAvatarCrossing(reg.RegionHandle, avatar.ControllingClient.AgentId, - // position, false); - - //{ - // avatar.ControllingClient.SendTeleportFailed("Problem with destination."); - // // We should close that agent we just created over at destination... - // List lst = new List(); - // lst.Add(reg.RegionHandle); - // SendCloseChildAgentAsync(avatar.UUID, lst); - // return; - //} - - SetInTransit(sp.UUID); - - // Let's send a full update of the agent. This is a synchronous call. - AgentData agent = new AgentData(); - sp.CopyTo(agent); - agent.Position = position; - SetCallbackURL(agent, sp.Scene.RegionInfo); - - UpdateAgent(reg, finalDestination, agent); - - m_log.DebugFormat( - "[ENTITY TRANSFER MODULE]: Sending new CAPS seed url {0} to client {1}", capsPath, sp.UUID); - - - if (eq != null) - { - eq.TeleportFinishEvent(destinationHandle, 13, endPoint, - 0, teleportFlags, capsPath, sp.UUID); - } - else - { - sp.ControllingClient.SendRegionTeleport(destinationHandle, 13, endPoint, 4, - teleportFlags, capsPath); - } - - // TeleportFinish makes the client send CompleteMovementIntoRegion (at the destination), which - // trigers a whole shebang of things there, including MakeRoot. So let's wait for confirmation - // that the client contacted the destination before we send the attachments and close things here. - if (!WaitForCallback(sp.UUID)) - { - // Client never contacted destination. Let's restore everything back - sp.ControllingClient.SendTeleportFailed("Problems connecting to destination."); - - ResetFromTransit(sp.UUID); - - // Yikes! We should just have a ref to scene here. - //sp.Scene.InformClientOfNeighbours(sp); - EnableChildAgents(sp); - - // Finally, kill the agent we just created at the destination. - m_aScene.SimulationService.CloseAgent(finalDestination, sp.UUID); - - return; - } - - KillEntity(sp.Scene, sp.LocalId); - - sp.MakeChildAgent(); - - // CrossAttachmentsIntoNewRegion is a synchronous call. We shouldn't need to wait after it - CrossAttachmentsIntoNewRegion(finalDestination, sp, true); - - // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone - - if (NeedsClosing(oldRegionX, newRegionX, oldRegionY, newRegionY, reg)) - { - Thread.Sleep(5000); - sp.Close(); - sp.Scene.IncomingCloseAgent(sp.UUID); - } - else - // now we have a child agent in this region. - sp.Reset(); - - - // REFACTORING PROBLEM. Well, not a problem, but this method is HORRIBLE! - if (sp.Scene.NeedSceneCacheClear(sp.UUID)) - { - m_log.DebugFormat( - "[ENTITY TRANSFER MODULE]: User {0} is going to another region, profile cache removed", - sp.UUID); - } - } - else - { - sp.ControllingClient.SendTeleportFailed("Remote Region appears to be down"); - } + m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Final destination is x={0} y={1} uuid={2}", + finalDestination.RegionLocX / Constants.RegionSize, finalDestination.RegionLocY / Constants.RegionSize, finalDestination.RegionID); + + // + // This is it + // + DoTeleport(sp, reg, finalDestination, position, lookAt, teleportFlags, eq); + // + // + // } else { @@ -450,6 +237,227 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer } } + protected void DoTeleport(ScenePresence sp, GridRegion reg, GridRegion finalDestination, Vector3 position, Vector3 lookAt, uint teleportFlags, IEventQueue eq) + { + m_log.DebugFormat( + "[ENTITY TRANSFER MODULE]: RequestTeleportToLocation to {0} in {1}", + position, reg.RegionName); + + uint newRegionX = (uint)(reg.RegionHandle >> 40); + uint newRegionY = (((uint)(reg.RegionHandle)) >> 8); + uint oldRegionX = (uint)(sp.Scene.RegionInfo.RegionHandle >> 40); + uint oldRegionY = (((uint)(sp.Scene.RegionInfo.RegionHandle)) >> 8); + + ulong destinationHandle = finalDestination.RegionHandle; + + if (eq == null) + sp.ControllingClient.SendTeleportLocationStart(); + + // Let's do DNS resolution only once in this process, please! + // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field, + // it's actually doing a lot of work. + IPEndPoint endPoint = finalDestination.ExternalEndPoint; + if (endPoint.Address != null) + { + // Fixing a bug where teleporting while sitting results in the avatar ending up removed from + // both regions + if (sp.ParentID != (uint)0) + sp.StandUp(); + + if (!sp.ValidateAttachments()) + { + sp.ControllingClient.SendTeleportFailed("Inconsistent attachment state"); + return; + } + + // the avatar.Close below will clear the child region list. We need this below for (possibly) + // closing the child agents, so save it here (we need a copy as it is Clear()-ed). + //List childRegions = new List(avatar.GetKnownRegionList()); + // Compared to ScenePresence.CrossToNewRegion(), there's no obvious code to handle a teleport + // failure at this point (unlike a border crossing failure). So perhaps this can never fail + // once we reach here... + //avatar.Scene.RemoveCapsHandler(avatar.UUID); + + string capsPath = String.Empty; + + AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); + AgentCircuitData agentCircuit = sp.ControllingClient.RequestClientInfo(); + agentCircuit.startpos = position; + agentCircuit.child = true; + agentCircuit.Appearance = sp.Appearance; + if (currentAgentCircuit != null) + agentCircuit.ServiceURLs = currentAgentCircuit.ServiceURLs; + + if (NeedsNewAgent(oldRegionX, newRegionX, oldRegionY, newRegionY)) + { + // brand new agent, let's create a new caps seed + agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath(); + } + + string reason = String.Empty; + + // Let's create an agent there if one doesn't exist yet. + if (!CreateAgent(reg, finalDestination, agentCircuit, teleportFlags, out reason)) + { + sp.ControllingClient.SendTeleportFailed(String.Format("Destination refused: {0}", + reason)); + return; + } + + // OK, it got this agent. Let's close some child agents + sp.CloseChildAgents(newRegionX, newRegionY); + + if (NeedsNewAgent(oldRegionX, newRegionX, oldRegionY, newRegionY)) + { + #region IP Translation for NAT + IClientIPEndpoint ipepClient; + if (sp.ClientView.TryGet(out ipepClient)) + { + capsPath + = "http://" + + NetworkUtil.GetHostFor(ipepClient.EndPoint, finalDestination.ExternalHostName) + + ":" + + finalDestination.HttpPort + + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath); + } + else + { + capsPath + = "http://" + + finalDestination.ExternalHostName + + ":" + + finalDestination.HttpPort + + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath); + } + #endregion + + if (eq != null) + { + #region IP Translation for NAT + // Uses ipepClient above + if (sp.ClientView.TryGet(out ipepClient)) + { + endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address); + } + #endregion + + eq.EnableSimulator(destinationHandle, endPoint, sp.UUID); + + // ES makes the client send a UseCircuitCode message to the destination, + // which triggers a bunch of things there. + // So let's wait + Thread.Sleep(2000); + + eq.EstablishAgentCommunication(sp.UUID, endPoint, capsPath); + + } + else + { + sp.ControllingClient.InformClientOfNeighbour(destinationHandle, endPoint); + } + } + else + { + agentCircuit.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, reg.RegionHandle); + capsPath = "http://" + finalDestination.ExternalHostName + ":" + finalDestination.HttpPort + + "/CAPS/" + agentCircuit.CapsPath + "0000/"; + } + + // Expect avatar crossing is a heavy-duty function at the destination. + // That is where MakeRoot is called, which fetches appearance and inventory. + // Plus triggers OnMakeRoot, which spawns a series of asynchronous updates. + //m_commsProvider.InterRegion.ExpectAvatarCrossing(reg.RegionHandle, avatar.ControllingClient.AgentId, + // position, false); + + //{ + // avatar.ControllingClient.SendTeleportFailed("Problem with destination."); + // // We should close that agent we just created over at destination... + // List lst = new List(); + // lst.Add(reg.RegionHandle); + // SendCloseChildAgentAsync(avatar.UUID, lst); + // return; + //} + + SetInTransit(sp.UUID); + + // Let's send a full update of the agent. This is a synchronous call. + AgentData agent = new AgentData(); + sp.CopyTo(agent); + agent.Position = position; + SetCallbackURL(agent, sp.Scene.RegionInfo); + + UpdateAgent(reg, finalDestination, agent); + + m_log.DebugFormat( + "[ENTITY TRANSFER MODULE]: Sending new CAPS seed url {0} to client {1}", capsPath, sp.UUID); + + + if (eq != null) + { + eq.TeleportFinishEvent(destinationHandle, 13, endPoint, + 0, teleportFlags, capsPath, sp.UUID); + } + else + { + sp.ControllingClient.SendRegionTeleport(destinationHandle, 13, endPoint, 4, + teleportFlags, capsPath); + } + + // TeleportFinish makes the client send CompleteMovementIntoRegion (at the destination), which + // trigers a whole shebang of things there, including MakeRoot. So let's wait for confirmation + // that the client contacted the destination before we send the attachments and close things here. + if (!WaitForCallback(sp.UUID)) + { + // Client never contacted destination. Let's restore everything back + sp.ControllingClient.SendTeleportFailed("Problems connecting to destination."); + + ResetFromTransit(sp.UUID); + + // Yikes! We should just have a ref to scene here. + //sp.Scene.InformClientOfNeighbours(sp); + EnableChildAgents(sp); + + // Finally, kill the agent we just created at the destination. + m_aScene.SimulationService.CloseAgent(finalDestination, sp.UUID); + + return; + } + + KillEntity(sp.Scene, sp.LocalId); + + sp.MakeChildAgent(); + + // CrossAttachmentsIntoNewRegion is a synchronous call. We shouldn't need to wait after it + CrossAttachmentsIntoNewRegion(finalDestination, sp, true); + + // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone + + if (NeedsClosing(oldRegionX, newRegionX, oldRegionY, newRegionY, reg)) + { + Thread.Sleep(5000); + sp.Close(); + sp.Scene.IncomingCloseAgent(sp.UUID); + } + else + // now we have a child agent in this region. + sp.Reset(); + + + // REFACTORING PROBLEM. Well, not a problem, but this method is HORRIBLE! + if (sp.Scene.NeedSceneCacheClear(sp.UUID)) + { + m_log.DebugFormat( + "[ENTITY TRANSFER MODULE]: User {0} is going to another region, profile cache removed", + sp.UUID); + } + } + else + { + sp.ControllingClient.SendTeleportFailed("Remote Region appears to be down"); + } + } + + protected virtual bool CreateAgent(GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason) { return m_aScene.SimulationService.CreateAgent(finalDestination, agentCircuit, teleportFlags, out reason); diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs index 101aea0..0e6323b 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs @@ -111,6 +111,55 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer return m_aScene.SimulationService.CreateAgent(reg, agentCircuit, teleportFlags, out reason); } + public override void TeleportHome(UUID id, IClientAPI client) + { + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Request to teleport {0} {1} home", client.FirstName, client.LastName); + + // Let's find out if this is a foreign user or a local user + UserAccount account = m_aScene.UserAccountService.GetUserAccount(m_aScene.RegionInfo.ScopeID, id); + if (account != null) + { + // local grid user + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is local"); + base.TeleportHome(id, client); + return; + } + + // Foreign user wants to go home + // + AgentCircuitData aCircuit = ((Scene)(client.Scene)).AuthenticateHandler.GetAgentCircuitData(client.CircuitCode); + if (aCircuit == null || (aCircuit != null && !aCircuit.ServiceURLs.ContainsKey("GatewayURI"))) + { + client.SendTeleportFailed("Your information has been lost"); + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Unable to locate agent's gateway information"); + return; + } + + GridRegion homeGatekeeper = MakeRegion(aCircuit); + if (homeGatekeeper == null) + { + client.SendTeleportFailed("Your information has been lost"); + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent's gateway information is malformed"); + return; + } + + Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY; + GridRegion finalDestination = m_GatekeeperConnector.GetHomeRegion(homeGatekeeper, aCircuit.AgentID, out position, out lookAt); + } #endregion + + private GridRegion MakeRegion(AgentCircuitData aCircuit) + { + GridRegion region = new GridRegion(); + + Uri uri = null; + if (!Uri.TryCreate(aCircuit.ServiceURLs["GatewayURI"].ToString(), UriKind.Absolute, out uri)) + return null; + + region.ExternalHostName = uri.Host; + region.HttpPort = (uint)uri.Port; + region.RegionName = string.Empty; + return region; + } } } diff --git a/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs index c56ea3f..f03d33a 100644 --- a/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs +++ b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs @@ -63,6 +63,7 @@ namespace OpenSim.Server.Handlers.Hypergrid HypergridHandlers hghandlers = new HypergridHandlers(m_GatekeeperService); server.AddXmlRPCHandler("link_region", hghandlers.LinkRegionRequest, false); server.AddXmlRPCHandler("get_region", hghandlers.GetRegion, false); + server.AddXmlRPCHandler("get_home_region", hghandlers.GetHomeRegion, false); server.AddHTTPHandler("/foreignagent/", new AgentHandler(m_GatekeeperService).Handler); diff --git a/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs index baafd7d..846d1c2 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs @@ -111,5 +111,38 @@ namespace OpenSim.Server.Handlers.Hypergrid } + public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient) + { + Hashtable requestData = (Hashtable)request.Params[0]; + //string host = (string)requestData["host"]; + //string portstr = (string)requestData["port"]; + string userID_str = (string)requestData["userID"]; + UUID userID = UUID.Zero; + UUID.TryParse(userID_str, out userID); + + Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY; + GridRegion regInfo = m_GatekeeperService.GetHomeRegion(userID, out position, out lookAt); + + Hashtable hash = new Hashtable(); + if (regInfo == null) + hash["result"] = "false"; + else + { + hash["result"] = "true"; + hash["uuid"] = regInfo.RegionID.ToString(); + hash["x"] = regInfo.RegionLocX.ToString(); + hash["y"] = regInfo.RegionLocY.ToString(); + hash["region_name"] = regInfo.RegionName; + hash["hostname"] = regInfo.ExternalHostName; + hash["http_port"] = regInfo.HttpPort.ToString(); + hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString(); + hash["position"] = position.ToString(); + hash["lookAt"] = lookAt.ToString(); + } + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = hash; + return response; + + } } } diff --git a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs new file mode 100644 index 0000000..a8d9292 --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Net; + +using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; + +using OpenMetaverse; +using Nwc.XmlRpc; + +using OpenSim.Services.Connectors.Simulation; + +namespace OpenSim.Services.Connectors.Hypergrid +{ + public class GatekeeperServiceConnector : SimulationServiceConnector + { + protected override string AgentPath() + { + return "/foreignagent/"; + } + + protected override string ObjectPath() + { + return "/foreignobject/"; + } + + public GridRegion GetHomeRegion(GridRegion gatekeeper, UUID userID, out Vector3 position, out Vector3 lookAt) + { + position = Vector3.UnitY; lookAt = Vector3.UnitY; + + Hashtable hash = new Hashtable(); + hash["userID"] = userID.ToString(); + + IList paramList = new ArrayList(); + paramList.Add(hash); + + XmlRpcRequest request = new XmlRpcRequest("get_home_region", paramList); + string uri = "http://" + gatekeeper.ExternalHostName + ":" + gatekeeper.HttpPort + "/"; + XmlRpcResponse response = null; + try + { + response = request.Send(uri, 10000); + } + catch (Exception e) + { + return null; + } + + if (response.IsFault) + { + return null; + } + + hash = (Hashtable)response.Value; + //foreach (Object o in hash) + // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); + try + { + bool success = false; + Boolean.TryParse((string)hash["result"], out success); + if (success) + { + GridRegion region = new GridRegion(); + + UUID.TryParse((string)hash["uuid"], out region.RegionID); + //m_log.Debug(">> HERE, uuid: " + region.RegionID); + int n = 0; + if (hash["x"] != null) + { + Int32.TryParse((string)hash["x"], out n); + region.RegionLocX = n; + //m_log.Debug(">> HERE, x: " + region.RegionLocX); + } + if (hash["y"] != null) + { + Int32.TryParse((string)hash["y"], out n); + region.RegionLocY = n; + //m_log.Debug(">> HERE, y: " + region.RegionLocY); + } + if (hash["region_name"] != null) + { + region.RegionName = (string)hash["region_name"]; + //m_log.Debug(">> HERE, name: " + region.RegionName); + } + if (hash["hostname"] != null) + region.ExternalHostName = (string)hash["hostname"]; + if (hash["http_port"] != null) + { + uint p = 0; + UInt32.TryParse((string)hash["http_port"], out p); + region.HttpPort = p; + } + if (hash["internal_port"] != null) + { + int p = 0; + Int32.TryParse((string)hash["internal_port"], out p); + region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p); + } + if (hash["position"] != null) + Vector3.TryParse((string)hash["position"], out position); + if (hash["lookAt"] != null) + Vector3.TryParse((string)hash["lookAt"], out lookAt); + + // Successful return + return region; + } + + } + catch (Exception e) + { + return null; + } + + return null; + + } + } +} diff --git a/OpenSim/Services/HypergridService/GatekeeperService.cs b/OpenSim/Services/HypergridService/GatekeeperService.cs index 72db93f..55d9ce1 100644 --- a/OpenSim/Services/HypergridService/GatekeeperService.cs +++ b/OpenSim/Services/HypergridService/GatekeeperService.cs @@ -164,6 +164,7 @@ namespace OpenSim.Services.HypergridService return region; } + #region Login Agent public bool LoginAgent(AgentCircuitData aCircuit, GridRegion destination, out string reason) { reason = string.Empty; @@ -221,7 +222,7 @@ namespace OpenSim.Services.HypergridService return m_SimulationService.CreateAgent(destination, aCircuit, 0, out reason); } - protected bool Authenticate(AgentCircuitData aCircuit) + protected bool Authenticate(AgentCircuitData aCircuit) { string authURL = string.Empty; if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) @@ -250,5 +251,40 @@ namespace OpenSim.Services.HypergridService return false; } + + #endregion + + public GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt) + { + position = new Vector3(128, 128, 0); lookAt = Vector3.UnitY; + + m_log.DebugFormat("[GATEKEEPER SERVICE]: Request to get home region of user {0}", userID); + + GridRegion home = null; + PresenceInfo[] presences = m_PresenceService.GetAgents(new string[] { userID.ToString() }); + if (presences != null && presences.Length > 0) + { + UUID homeID = presences[0].HomeRegionID; + if (homeID != UUID.Zero) + { + home = m_GridService.GetRegionByUUID(m_ScopeID, homeID); + position = presences[0].HomePosition; + lookAt = presences[0].HomeLookAt; + } + if (home == null) + { + List defs = m_GridService.GetDefaultRegions(m_ScopeID); + if (defs != null && defs.Count > 0) + home = defs[0]; + } + } + + return home; + } + + #region Misc + + + #endregion } } diff --git a/OpenSim/Services/HypergridService/HypergridService.cs b/OpenSim/Services/HypergridService/HypergridService.cs index 734931d..ac0f5ac 100644 --- a/OpenSim/Services/HypergridService/HypergridService.cs +++ b/OpenSim/Services/HypergridService/HypergridService.cs @@ -51,7 +51,7 @@ namespace OpenSim.Services.HypergridService private static HypergridService m_RootInstance = null; protected IConfigSource m_config; - protected IAuthenticationService m_AuthenticationService = null; + protected IPresenceService m_PresenceService = null; protected IGridService m_GridService; protected IAssetService m_AssetService; protected HypergridServiceConnector m_HypergridConnector; @@ -94,7 +94,7 @@ namespace OpenSim.Services.HypergridService if (gridConfig != null) { string gridService = gridConfig.GetString("GridService", string.Empty); - string authService = gridConfig.GetString("AuthenticationService", String.Empty); + string presenceService = gridConfig.GetString("PresenceService", String.Empty); string assetService = gridConfig.GetString("AssetService", string.Empty); Object[] args = new Object[] { config }; @@ -104,8 +104,8 @@ namespace OpenSim.Services.HypergridService if (m_GridService == null) throw new Exception("HypergridService cannot function without a GridService"); - if (authService != String.Empty) - m_AuthenticationService = ServerUtils.LoadPlugin(authService, args); + if (presenceService != String.Empty) + m_PresenceService = ServerUtils.LoadPlugin(presenceService, args); if (assetService != string.Empty) m_AssetService = ServerUtils.LoadPlugin(assetService, args); diff --git a/OpenSim/Services/Interfaces/IGatekeeperService.cs b/OpenSim/Services/Interfaces/IGatekeeperService.cs index d41df75..59e0f82 100644 --- a/OpenSim/Services/Interfaces/IGatekeeperService.cs +++ b/OpenSim/Services/Interfaces/IGatekeeperService.cs @@ -39,5 +39,8 @@ namespace OpenSim.Services.Interfaces GridRegion GetHyperlinkRegion(UUID regionID); bool LoginAgent(AgentCircuitData aCircuit, GridRegion destination, out string reason); + + GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt); + } } -- cgit v1.1 From 3d536944153d4931cf891d6a788a47484f3e6f4d Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 18 Jan 2010 16:34:23 -0800 Subject: Go Home works. With security!! --- .../Region/ClientStack/LindenUDP/LLUDPServer.cs | 20 ++++ .../EntityTransfer/EntityTransferModule.cs | 10 +- .../EntityTransfer/HGEntityTransferModule.cs | 69 ++++++++++- .../Resources/CoreModulePlugin.addin.xml | 2 +- .../Grid/HypergridServiceInConnectorModule.cs | 128 -------------------- .../Hypergrid/HypergridServiceInConnectorModule.cs | 129 ++++++++++++++++++++ .../Hypergrid/GatekeeperServerConnector.cs | 4 + .../Hypergrid/HomeUsersSecurityServerConnector.cs | 122 +++++++++++++++++++ .../Hypergrid/HomeUsersSecurityServiceConnector.cs | 132 +++++++++++++++++++++ .../Services/HypergridService/GatekeeperService.cs | 53 ++++++--- .../HypergridService/HomeUsersSecurityService.cs | 67 +++++++++++ OpenSim/Services/Interfaces/IGatekeeperService.cs | 11 ++ OpenSim/Services/Interfaces/IHypergridService.cs | 1 + bin/config-include/StandaloneHypergrid.ini | 3 + 14 files changed, 598 insertions(+), 153 deletions(-) delete mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs create mode 100644 OpenSim/Server/Handlers/Hypergrid/HomeUsersSecurityServerConnector.cs create mode 100644 OpenSim/Services/Connectors/Hypergrid/HomeUsersSecurityServiceConnector.cs create mode 100644 OpenSim/Services/HypergridService/HomeUsersSecurityService.cs diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 3c4fa72..ffd2546 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -38,6 +38,7 @@ using OpenMetaverse.Packets; using OpenSim.Framework; using OpenSim.Framework.Statistics; using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; using OpenMetaverse; using TokenBucket = OpenSim.Region.ClientStack.LindenUDP.TokenBucket; @@ -900,6 +901,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (!m_scene.TryGetClient(agentID, out existingClient)) { + IHomeUsersSecurityService security = m_scene.RequestModuleInterface(); + if (security != null) + { + IPEndPoint ep = security.GetEndPoint(sessionID); + if (ep != null && ep.ToString() != remoteEndPoint.ToString()) + { + // uh-oh, this is fishy + m_log.WarnFormat("[LLUDPSERVER]: Agent {0} with session {1} connecting with unidentified end point. Refusing service.", agentID, sessionID); + m_log.WarnFormat("[LLUDPSERVER]: EP was {0}, now is {1}", ep.ToString(), remoteEndPoint.ToString()); + return; + } + else if (ep != null) + { + // ok, you're home, welcome back + m_log.InfoFormat("LLUDPSERVER]: Agent {0} is coming back to this grid", agentID); + security.RemoveEndPoint(sessionID); + } + } + // Create the LLClientView LLClientView client = new LLClientView(remoteEndPoint, m_scene, this, udpClient, sessionInfo, agentID, sessionID, circuitCode); client.OnLogout += LogoutHandler; diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index e85f270..ed8c0fd 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -134,8 +134,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer if (!sp.Scene.Permissions.CanTeleport(sp.UUID)) return; - bool destRegionUp = true; - IEventQueue eq = sp.Scene.RequestModuleInterface(); // Reset animations; the viewer does that in teleports. @@ -240,8 +238,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer protected void DoTeleport(ScenePresence sp, GridRegion reg, GridRegion finalDestination, Vector3 position, Vector3 lookAt, uint teleportFlags, IEventQueue eq) { m_log.DebugFormat( - "[ENTITY TRANSFER MODULE]: RequestTeleportToLocation to {0} in {1}", - position, reg.RegionName); + "[ENTITY TRANSFER MODULE]: Request Teleport to {0}:{1}:{2}/{3} final destination {4}", + reg.ExternalHostName, reg.HttpPort, reg.RegionName, position, finalDestination.RegionName); uint newRegionX = (uint)(reg.RegionHandle >> 40); uint newRegionY = (((uint)(reg.RegionHandle)) >> 8); @@ -297,7 +295,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer string reason = String.Empty; // Let's create an agent there if one doesn't exist yet. - if (!CreateAgent(reg, finalDestination, agentCircuit, teleportFlags, out reason)) + if (!CreateAgent(sp, reg, finalDestination, agentCircuit, teleportFlags, out reason)) { sp.ControllingClient.SendTeleportFailed(String.Format("Destination refused: {0}", reason)); @@ -458,7 +456,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer } - protected virtual bool CreateAgent(GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason) + protected virtual bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason) { return m_aScene.SimulationService.CreateAgent(finalDestination, agentCircuit, teleportFlags, out reason); } diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs index 0e6323b..d39537d 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs @@ -34,6 +34,7 @@ using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Services.Connectors.Hypergrid; using OpenSim.Services.Interfaces; +using OpenSim.Server.Base; using GridRegion = OpenSim.Services.Interfaces.GridRegion; @@ -59,6 +60,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer } private GatekeeperServiceConnector m_GatekeeperConnector; + private IHomeUsersSecurityService m_Security; #region ISharedRegionModule @@ -77,12 +79,42 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer { m_agentsInTransit = new List(); m_GatekeeperConnector = new GatekeeperServiceConnector(); + + IConfig config = source.Configs["HGEntityTransferModule"]; + if (config != null) + { + string dll = config.GetString("HomeUsersSecurityService", string.Empty); + if (dll != string.Empty) + { + Object[] args = new Object[] { source }; + m_Security = ServerUtils.LoadPlugin(dll, args); + if (m_Security == null) + m_log.Debug("[HG ENTITY TRANSFER MODULE]: Unable to load Home Users Security service"); + else + m_log.Debug("[HG ENTITY TRANSFER MODULE]: Home Users Security service loaded"); + } + } + m_Enabled = true; m_log.InfoFormat("[HG ENTITY TRANSFER MODULE]: {0} enabled.", Name); } } } + public override void AddRegion(Scene scene) + { + base.AddRegion(scene); + if (m_Enabled) + scene.RegisterModuleInterface(m_Security); + } + + public override void RemoveRegion(Scene scene) + { + base.AddRegion(scene); + if (m_Enabled) + scene.UnregisterModuleInterface(m_Security); + } + #endregion @@ -98,13 +130,25 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer return true; } - protected override bool CreateAgent(GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason) + protected override bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason) { reason = string.Empty; - if (reg.RegionLocX != finalDestination.RegionLocX && reg.RegionLocY != finalDestination.RegionLocY) + if (reg.RegionLocX != finalDestination.RegionLocX || reg.RegionLocY != finalDestination.RegionLocY) { // this user is going to another grid reg.RegionName = finalDestination.RegionName; + reg.RegionID = finalDestination.RegionID; + reg.RegionLocX = finalDestination.RegionLocX; + reg.RegionLocY = finalDestination.RegionLocY; + + // Log their session and remote endpoint in the home users security service + IHomeUsersSecurityService security = sp.Scene.RequestModuleInterface(); + if (security != null) + security.SetEndPoint(sp.ControllingClient.SessionId, sp.ControllingClient.RemoteEndPoint); + + // Log them out of this grid + sp.Scene.PresenceService.LogoutAgent(agentCircuit.SessionID, sp.AbsolutePosition, sp.Lookat); + return m_GatekeeperConnector.CreateAgent(reg, agentCircuit, teleportFlags, out reason); } @@ -145,6 +189,26 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY; GridRegion finalDestination = m_GatekeeperConnector.GetHomeRegion(homeGatekeeper, aCircuit.AgentID, out position, out lookAt); + if (finalDestination == null) + { + client.SendTeleportFailed("Your home region could not be found"); + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent's home region not found"); + return; + } + + ScenePresence sp = ((Scene)(client.Scene)).GetScenePresence(client.AgentId); + if (sp == null) + { + client.SendTeleportFailed("Internal error"); + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent not found in the scene where it is supposed to be"); + return; + } + + m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: teleporting user {0} {1} home to {2} via {3}:{4}:{5}", + aCircuit.firstname, aCircuit.lastname, finalDestination.RegionName, homeGatekeeper.ExternalHostName, homeGatekeeper.HttpPort, homeGatekeeper.RegionName); + + IEventQueue eq = sp.Scene.RequestModuleInterface(); + DoTeleport(sp, homeGatekeeper, finalDestination, position, lookAt, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome), eq); } #endregion @@ -159,6 +223,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer region.ExternalHostName = uri.Host; region.HttpPort = (uint)uri.Port; region.RegionName = string.Empty; + region.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), (int)0); return region; } } diff --git a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml index c61198d..0e3739a 100644 --- a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml +++ b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml @@ -62,7 +62,7 @@ \ - \ + \ \ \ \ diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs deleted file mode 100644 index 6ec0fcf..0000000 --- a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Reflection; -using System.Collections.Generic; -using log4net; -using Nini.Config; -using OpenSim.Framework; -using OpenSim.Framework.Servers.HttpServer; -using OpenSim.Region.Framework.Scenes; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Server.Base; -using OpenSim.Server.Handlers.Base; -using OpenSim.Server.Handlers.Hypergrid; -using OpenSim.Services.Interfaces; -using GridRegion = OpenSim.Services.Interfaces.GridRegion; - -namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid -{ - public class HypergridServiceInConnectorModule : ISharedRegionModule - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private static bool m_Enabled = false; - - private IConfigSource m_Config; - bool m_Registered = false; - GatekeeperServiceInConnector m_HypergridHandler; - - #region IRegionModule interface - - public void Initialise(IConfigSource config) - { - //// This module is only on for standalones in hypergrid mode - //enabled = (!config.Configs["Startup"].GetBoolean("gridmode", true)) && - // config.Configs["Startup"].GetBoolean("hypergrid", true); - //m_log.DebugFormat("[RegionInventoryService]: enabled? {0}", enabled); - m_Config = config; - IConfig moduleConfig = config.Configs["Modules"]; - if (moduleConfig != null) - { - m_Enabled = moduleConfig.GetBoolean("HypergridServiceInConnector", false); - if (m_Enabled) - { - m_log.Info("[HGGRID IN CONNECTOR]: Hypergrid Service In Connector enabled"); - } - - } - - } - - public void PostInitialise() - { - } - - public void Close() - { - } - - public Type ReplaceableInterface - { - get { return null; } - } - - public string Name - { - get { return "HypergridService"; } - } - - public void AddRegion(Scene scene) - { - if (!m_Enabled) - return; - - } - - public void RemoveRegion(Scene scene) - { - if (!m_Enabled) - return; - } - - public void RegionLoaded(Scene scene) - { - if (!m_Enabled) - return; - - if (!m_Registered) - { - m_Registered = true; - - m_log.Info("[HypergridService]: Starting..."); - -// Object[] args = new Object[] { m_Config, MainServer.Instance }; - ISimulationService simService = scene.RequestModuleInterface(); - m_HypergridHandler = new GatekeeperServiceInConnector(m_Config, MainServer.Instance, simService); - //ServerUtils.LoadPlugin("OpenSim.Server.Handlers.dll:HypergridServiceInConnector", args); - } - } - - #endregion - - } -} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs new file mode 100644 index 0000000..6e6946c --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs @@ -0,0 +1,129 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Reflection; +using System.Collections.Generic; +using log4net; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Framework.Servers.HttpServer; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Server.Base; +using OpenSim.Server.Handlers.Base; +using OpenSim.Server.Handlers.Hypergrid; +using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Hypergrid +{ + public class HypergridServiceInConnectorModule : ISharedRegionModule + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static bool m_Enabled = false; + + private IConfigSource m_Config; + bool m_Registered = false; + GatekeeperServiceInConnector m_HypergridHandler; + + #region IRegionModule interface + + public void Initialise(IConfigSource config) + { + //// This module is only on for standalones in hypergrid mode + //enabled = (!config.Configs["Startup"].GetBoolean("gridmode", true)) && + // config.Configs["Startup"].GetBoolean("hypergrid", true); + //m_log.DebugFormat("[RegionInventoryService]: enabled? {0}", enabled); + m_Config = config; + IConfig moduleConfig = config.Configs["Modules"]; + if (moduleConfig != null) + { + m_Enabled = moduleConfig.GetBoolean("HypergridServiceInConnector", false); + if (m_Enabled) + { + m_log.Info("[HGGRID IN CONNECTOR]: Hypergrid Service In Connector enabled"); + } + + } + + } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public Type ReplaceableInterface + { + get { return null; } + } + + public string Name + { + get { return "HypergridService"; } + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + } + + public void RemoveRegion(Scene scene) + { + if (!m_Enabled) + return; + } + + public void RegionLoaded(Scene scene) + { + if (!m_Enabled) + return; + + if (!m_Registered) + { + m_Registered = true; + + m_log.Info("[HypergridService]: Starting..."); + +// Object[] args = new Object[] { m_Config, MainServer.Instance }; + ISimulationService simService = scene.RequestModuleInterface(); + m_HypergridHandler = new GatekeeperServiceInConnector(m_Config, MainServer.Instance, simService); + //ServerUtils.LoadPlugin("OpenSim.Server.Handlers.dll:HypergridServiceInConnector", args); + scene.RegisterModuleInterface(m_HypergridHandler.GateKeeper); + } + } + + #endregion + + } +} diff --git a/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs index f03d33a..15b29d2 100644 --- a/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs +++ b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs @@ -46,6 +46,10 @@ namespace OpenSim.Server.Handlers.Hypergrid MethodBase.GetCurrentMethod().DeclaringType); private IGatekeeperService m_GatekeeperService; + public IGatekeeperService GateKeeper + { + get { return m_GatekeeperService; } + } public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server, ISimulationService simService) : base(config, server, String.Empty) diff --git a/OpenSim/Server/Handlers/Hypergrid/HomeUsersSecurityServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/HomeUsersSecurityServerConnector.cs new file mode 100644 index 0000000..5379784 --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/HomeUsersSecurityServerConnector.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Net; +using System.Reflection; + +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; +using OpenSim.Framework.Servers.HttpServer; +using OpenSim.Server.Handlers.Base; + +using log4net; +using Nwc.XmlRpc; +using OpenMetaverse; + +namespace OpenSim.Server.Handlers.Hypergrid +{ + public class HomeUsersSecurityServerConnector : ServiceConnector + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private IHomeUsersSecurityService m_HomeUsersService; + + public HomeUsersSecurityServerConnector(IConfigSource config, IHttpServer server) : + base(config, server, String.Empty) + { + IConfig gridConfig = config.Configs["HomeUsersSecurityService"]; + if (gridConfig != null) + { + string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty); + Object[] args = new Object[] { config }; + m_HomeUsersService = ServerUtils.LoadPlugin(serviceDll, args); + } + if (m_HomeUsersService == null) + throw new Exception("HomeUsersSecurity server connector cannot proceed because of missing service"); + + server.AddXmlRPCHandler("ep_get", GetEndPoint, false); + server.AddXmlRPCHandler("ep_set", SetEndPoint, false); + server.AddXmlRPCHandler("ep_remove", RemoveEndPoint, false); + + } + + public XmlRpcResponse GetEndPoint(XmlRpcRequest request, IPEndPoint remoteClient) + { + Hashtable requestData = (Hashtable)request.Params[0]; + //string host = (string)requestData["host"]; + //string portstr = (string)requestData["port"]; + string sessionID_str = (string)requestData["sessionID"]; + UUID sessionID = UUID.Zero; + UUID.TryParse(sessionID_str, out sessionID); + + IPEndPoint ep = m_HomeUsersService.GetEndPoint(sessionID); + + Hashtable hash = new Hashtable(); + if (ep == null) + hash["result"] = "false"; + else + { + hash["result"] = "true"; + hash["ep_addr"] = ep.Address.ToString(); + hash["ep_port"] = ep.Port.ToString(); + } + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = hash; + return response; + + } + + public XmlRpcResponse SetEndPoint(XmlRpcRequest request, IPEndPoint remoteClient) + { + Hashtable requestData = (Hashtable)request.Params[0]; + string host = (string)requestData["ep_addr"]; + string portstr = (string)requestData["ep_port"]; + string sessionID_str = (string)requestData["sessionID"]; + UUID sessionID = UUID.Zero; + UUID.TryParse(sessionID_str, out sessionID); + int port = 0; + Int32.TryParse(portstr, out port); + + IPEndPoint ep = null; + try + { + ep = new IPEndPoint(IPAddress.Parse(host), port); + } + catch + { + m_log.Debug("[HOME USERS SECURITY]: Exception in creating EndPoint"); + } + + m_HomeUsersService.SetEndPoint(sessionID, ep); + + Hashtable hash = new Hashtable(); + hash["result"] = "true"; + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = hash; + return response; + + } + + public XmlRpcResponse RemoveEndPoint(XmlRpcRequest request, IPEndPoint remoteClient) + { + Hashtable requestData = (Hashtable)request.Params[0]; + string sessionID_str = (string)requestData["sessionID"]; + UUID sessionID = UUID.Zero; + UUID.TryParse(sessionID_str, out sessionID); + + m_HomeUsersService.RemoveEndPoint(sessionID); + + Hashtable hash = new Hashtable(); + hash["result"] = "true"; + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = hash; + return response; + + } + + } +} diff --git a/OpenSim/Services/Connectors/Hypergrid/HomeUsersSecurityServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HomeUsersSecurityServiceConnector.cs new file mode 100644 index 0000000..150690b --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/HomeUsersSecurityServiceConnector.cs @@ -0,0 +1,132 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Net; +using System.Reflection; + +using OpenSim.Services.Interfaces; + +using OpenMetaverse; +using log4net; +using Nwc.XmlRpc; +using Nini.Config; + +namespace OpenSim.Services.Connectors.Hypergrid +{ + public class HomeUsersSecurityServiceConnector : IHomeUsersSecurityService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + string m_ServerURL; + public HomeUsersSecurityServiceConnector(string url) + { + m_ServerURL = url; + } + + public HomeUsersSecurityServiceConnector(IConfigSource config) + { + } + + public void SetEndPoint(UUID sessionID, IPEndPoint ep) + { + Hashtable hash = new Hashtable(); + hash["sessionID"] = sessionID.ToString(); + hash["ep_addr"] = ep.Address.ToString(); + hash["ep_port"] = ep.Port.ToString(); + + Call("ep_set", hash); + } + + public void RemoveEndPoint(UUID sessionID) + { + Hashtable hash = new Hashtable(); + hash["sessionID"] = sessionID.ToString(); + + Call("ep_remove", hash); + } + + public IPEndPoint GetEndPoint(UUID sessionID) + { + Hashtable hash = new Hashtable(); + hash["sessionID"] = sessionID.ToString(); + + IList paramList = new ArrayList(); + paramList.Add(hash); + + XmlRpcRequest request = new XmlRpcRequest("ep_get", paramList); + //m_log.Debug("[HGrid]: Linking to " + uri); + XmlRpcResponse response = null; + try + { + response = request.Send(m_ServerURL, 10000); + } + catch (Exception e) + { + m_log.Debug("[HGrid]: Exception " + e.Message); + return null; + } + + if (response.IsFault) + { + m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString); + return null; + } + + hash = (Hashtable)response.Value; + //foreach (Object o in hash) + // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); + try + { + bool success = false; + Boolean.TryParse((string)hash["result"], out success); + if (success) + { + IPEndPoint ep = null; + int port = 0; + if (hash["ep_port"] != null) + Int32.TryParse((string)hash["ep_port"], out port); + if (hash["ep_addr"] != null) + ep = new IPEndPoint(IPAddress.Parse((string)hash["ep_addr"]), port); + + return ep; + } + + } + catch (Exception e) + { + m_log.Error("[HGrid]: Got exception while parsing GetEndPoint response " + e.StackTrace); + return null; + } + + return null; + } + + private void Call(string method, Hashtable hash) + { + IList paramList = new ArrayList(); + paramList.Add(hash); + + XmlRpcRequest request = new XmlRpcRequest(method, paramList); + XmlRpcResponse response = null; + try + { + response = request.Send(m_ServerURL, 10000); + } + catch (Exception e) + { + m_log.Debug("[HGrid]: Exception " + e.Message); + return ; + } + + if (response.IsFault) + { + m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString); + return ; + } + + } + + } +} diff --git a/OpenSim/Services/HypergridService/GatekeeperService.cs b/OpenSim/Services/HypergridService/GatekeeperService.cs index 55d9ce1..169cfa3 100644 --- a/OpenSim/Services/HypergridService/GatekeeperService.cs +++ b/OpenSim/Services/HypergridService/GatekeeperService.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.Net; using System.Reflection; using OpenSim.Framework; @@ -51,6 +52,7 @@ namespace OpenSim.Services.HypergridService IPresenceService m_PresenceService; IAuthenticationService m_AuthenticationService; IUserAccountService m_UserAccountService; + IHomeUsersSecurityService m_HomeUsersSecurityService; ISimulationService m_SimulationService; string m_AuthDll; @@ -66,14 +68,15 @@ namespace OpenSim.Services.HypergridService throw new Exception(String.Format("No section GatekeeperService in config file")); string accountService = serverConfig.GetString("UserAccountService", String.Empty); + string homeUsersSecurityService = serverConfig.GetString("HomeUsersSecurityService", string.Empty); string gridService = serverConfig.GetString("GridService", String.Empty); string presenceService = serverConfig.GetString("PresenceService", String.Empty); string simulationService = serverConfig.GetString("SimulationService", String.Empty); m_AuthDll = serverConfig.GetString("AuthenticationService", String.Empty); - if (accountService == string.Empty || gridService == string.Empty || - presenceService == string.Empty || m_AuthDll == string.Empty) + // These 3 are mandatory, the others aren't + if (gridService == string.Empty || presenceService == string.Empty || m_AuthDll == string.Empty) throw new Exception("Incomplete specifications, Gatekeeper Service cannot function."); string scope = serverConfig.GetString("ScopeID", UUID.Zero.ToString()); @@ -82,16 +85,20 @@ namespace OpenSim.Services.HypergridService m_AllowTeleportsToAnyRegion = serverConfig.GetBoolean("AllowTeleportsToAnyRegion", true); Object[] args = new Object[] { config }; - m_UserAccountService = ServerUtils.LoadPlugin(accountService, args); m_GridService = ServerUtils.LoadPlugin(gridService, args); m_PresenceService = ServerUtils.LoadPlugin(presenceService, args); + + if (accountService != string.Empty) + m_UserAccountService = ServerUtils.LoadPlugin(accountService, args); + if (homeUsersSecurityService != string.Empty) + m_HomeUsersSecurityService = ServerUtils.LoadPlugin(homeUsersSecurityService, args); + if (simService != null) m_SimulationService = simService; else if (simulationService != string.Empty) m_SimulationService = ServerUtils.LoadPlugin(simulationService, args); - if (m_UserAccountService == null || m_GridService == null || - m_PresenceService == null || m_SimulationService == null) + if (m_GridService == null || m_PresenceService == null || m_SimulationService == null) throw new Exception("Unable to load a required plugin, Gatekeeper Service cannot function."); m_log.Debug("[GATEKEEPER SERVICE]: Starting..."); @@ -183,17 +190,31 @@ namespace OpenSim.Services.HypergridService } m_log.DebugFormat("[GATEKEEPER SERVICE]: Identity verified for {0} {1} @ {2}", aCircuit.firstname, aCircuit.lastname, authURL); - // Check to see if we have a local user with that UUID - UserAccount account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID); - if (account != null) - { - // No, sorry; go away - reason = "User identifier not allowed on this grid"; - m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has UUID of local user {3}. Refusing service.", - aCircuit.firstname, aCircuit.lastname, aCircuit.AgentID); - return false; - } - m_log.DebugFormat("[GATEKEEPER SERVICE]: User ID ok"); + //if (m_UserAccountService != null && m_HomeUsersSecurityService != null) + //{ + // // Check to see if we have a local user with that UUID + // UserAccount account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID); + + // // See if that user went out of this home grid + // IPEndPoint ep = m_HomeUsersSecurityService.GetEndPoint(aCircuit.AgentID); + + // if (account != null) + // { + // if ((ep == null) || // there's no memory of this agent going out + // (ep != null && (ep.Address != aCircuit.ClientEndPoint.Address || ep.Port != aCircuit.ClientEndPoint.Port))) // fake agent + // { + // // No, sorry; go away + // reason = "User identifier not allowed on this grid"; + // m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has UUID of local user {2}. Refusing service.", + // aCircuit.firstname, aCircuit.lastname, aCircuit.AgentID); + // return false; + // } + // else + // { + // } + // } + // m_log.DebugFormat("[GATEKEEPER SERVICE]: User ID ok"); + //} // May want to authorize diff --git a/OpenSim/Services/HypergridService/HomeUsersSecurityService.cs b/OpenSim/Services/HypergridService/HomeUsersSecurityService.cs new file mode 100644 index 0000000..a7adfc1 --- /dev/null +++ b/OpenSim/Services/HypergridService/HomeUsersSecurityService.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Reflection; + +using OpenSim.Services.Interfaces; + +using OpenMetaverse; +using log4net; +using Nini.Config; + +namespace OpenSim.Services.HypergridService +{ + /// + /// This service is for HG1.5 only, to make up for the fact that clients don't + /// keep any private information in themselves, and that their 'home service' + /// needs to do it for them. + /// Once we have better clients, this shouldn't be needed. + /// + public class HomeUsersSecurityService : IHomeUsersSecurityService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + // + // This is a persistent storage wannabe for dealing with the + // quirks of HG1.5. We don't really want to store this in a table. + // But this is the necessary information for securing clients + // coming home. + // + protected static Dictionary m_ClientEndPoints = new Dictionary(); + + public HomeUsersSecurityService(IConfigSource config) + { + m_log.DebugFormat("[HOME USERS SECURITY]: Starting..."); + } + + public void SetEndPoint(UUID sessionID, IPEndPoint ep) + { + m_log.DebugFormat("[HOME USERS SECURITY]: Set EndPoint {0} for session {1}", ep.ToString(), sessionID); + + lock (m_ClientEndPoints) + m_ClientEndPoints[sessionID] = ep; + } + + public IPEndPoint GetEndPoint(UUID sessionID) + { + lock (m_ClientEndPoints) + if (m_ClientEndPoints.ContainsKey(sessionID)) + { + m_log.DebugFormat("[HOME USERS SECURITY]: Get EndPoint {0} for session {1}", m_ClientEndPoints[sessionID].ToString(), sessionID); + return m_ClientEndPoints[sessionID]; + } + + return null; + } + + public void RemoveEndPoint(UUID sessionID) + { + m_log.DebugFormat("[HOME USERS SECURITY]: Remove EndPoint for session {0}", sessionID); + lock (m_ClientEndPoints) + if (m_ClientEndPoints.ContainsKey(sessionID)) + m_ClientEndPoints.Remove(sessionID); + } + } +} diff --git a/OpenSim/Services/Interfaces/IGatekeeperService.cs b/OpenSim/Services/Interfaces/IGatekeeperService.cs index 59e0f82..5b5c9d1 100644 --- a/OpenSim/Services/Interfaces/IGatekeeperService.cs +++ b/OpenSim/Services/Interfaces/IGatekeeperService.cs @@ -26,6 +26,7 @@ */ using System; +using System.Net; using System.Collections.Generic; using OpenSim.Framework; @@ -43,4 +44,14 @@ namespace OpenSim.Services.Interfaces GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt); } + + /// + /// HG1.5 only + /// + public interface IHomeUsersSecurityService + { + void SetEndPoint(UUID sessionID, IPEndPoint ep); + IPEndPoint GetEndPoint(UUID sessionID); + void RemoveEndPoint(UUID sessionID); + } } diff --git a/OpenSim/Services/Interfaces/IHypergridService.cs b/OpenSim/Services/Interfaces/IHypergridService.cs index dd3c053..86ef1b4 100644 --- a/OpenSim/Services/Interfaces/IHypergridService.cs +++ b/OpenSim/Services/Interfaces/IHypergridService.cs @@ -43,6 +43,7 @@ namespace OpenSim.Services.Interfaces GridRegion GetRegionByName(string name); List GetRegionsByName(string name); List GetRegionRange(int xmin, int xmax, int ymin, int ymax); + } } diff --git a/bin/config-include/StandaloneHypergrid.ini b/bin/config-include/StandaloneHypergrid.ini index eb887a6..28b9d47 100644 --- a/bin/config-include/StandaloneHypergrid.ini +++ b/bin/config-include/StandaloneHypergrid.ini @@ -82,6 +82,9 @@ GridService = "OpenSim.Services.GridService.dll:GridService" AuthenticationService = "OpenSim.Services.Connectors.dll:AuthenticationServicesConnector" +[HGEntityTransferModule] + HomeUsersSecurityService = "OpenSim.Services.HypergridService.dll:HomeUsersSecurityService" + [PresenceService] LocalServiceModule = "OpenSim.Services.PresenceService.dll:PresenceService" -- cgit v1.1 From 5feeea00aeef6ff635442aedd44fa176541d6278 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 18 Jan 2010 17:00:06 -0800 Subject: Check for impersonations at the Gatekeeper. --- .../Services/HypergridService/GatekeeperService.cs | 81 ++++++++++++++-------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/OpenSim/Services/HypergridService/GatekeeperService.cs b/OpenSim/Services/HypergridService/GatekeeperService.cs index 169cfa3..283ab3e 100644 --- a/OpenSim/Services/HypergridService/GatekeeperService.cs +++ b/OpenSim/Services/HypergridService/GatekeeperService.cs @@ -182,6 +182,9 @@ namespace OpenSim.Services.HypergridService m_log.DebugFormat("[GATEKEEPER SERVICE]: Request to login foreign agent {0} {1} @ {2} ({3}) at destination {4}", aCircuit.firstname, aCircuit.lastname, authURL, aCircuit.AgentID, destination.RegionName); + // + // Authenticate the user + // if (!Authenticate(aCircuit)) { reason = "Unable to verify identity"; @@ -189,36 +192,40 @@ namespace OpenSim.Services.HypergridService return false; } m_log.DebugFormat("[GATEKEEPER SERVICE]: Identity verified for {0} {1} @ {2}", aCircuit.firstname, aCircuit.lastname, authURL); - - //if (m_UserAccountService != null && m_HomeUsersSecurityService != null) - //{ - // // Check to see if we have a local user with that UUID - // UserAccount account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID); - - // // See if that user went out of this home grid - // IPEndPoint ep = m_HomeUsersSecurityService.GetEndPoint(aCircuit.AgentID); - - // if (account != null) - // { - // if ((ep == null) || // there's no memory of this agent going out - // (ep != null && (ep.Address != aCircuit.ClientEndPoint.Address || ep.Port != aCircuit.ClientEndPoint.Port))) // fake agent - // { - // // No, sorry; go away - // reason = "User identifier not allowed on this grid"; - // m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has UUID of local user {2}. Refusing service.", - // aCircuit.firstname, aCircuit.lastname, aCircuit.AgentID); - // return false; - // } - // else - // { - // } - // } - // m_log.DebugFormat("[GATEKEEPER SERVICE]: User ID ok"); - //} + + // + // Check for impersonations + // + UserAccount account = null; + if (m_UserAccountService != null) + { + // Check to see if we have a local user with that UUID + account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID); + if (account != null) + { + // Make sure this is the user coming home, and not a fake + if (m_HomeUsersSecurityService != null) + { + Object ep = m_HomeUsersSecurityService.GetEndPoint(aCircuit.SessionID); + if (ep == null) + { + // This is a fake, this session never left this grid + reason = "Unauthorized"; + m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has same ID as local user. Refusing service.", + aCircuit.firstname, aCircuit.lastname); + return false; + + } + } + } + } + m_log.DebugFormat("[GATEKEEPER SERVICE]: User is ok"); // May want to authorize + // // Login the presence + // if (!m_PresenceService.LoginAgent(aCircuit.AgentID.ToString(), aCircuit.SessionID, aCircuit.SecureSessionID)) { reason = "Unable to login presence"; @@ -228,18 +235,34 @@ namespace OpenSim.Services.HypergridService } m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence ok"); + // // Get the region + // destination = m_GridService.GetRegionByUUID(m_ScopeID, destination.RegionID); if (destination == null) { reason = "Destination region not found"; return false; } - m_log.DebugFormat("[GATEKEEPER SERVICE]: destination ok : {0}", destination.RegionName); + m_log.DebugFormat("[GATEKEEPER SERVICE]: destination ok: {0}", destination.RegionName); + + // + // Adjust the visible name + // + if (account != null) + { + aCircuit.firstname = account.FirstName; + aCircuit.lastname = account.LastName; + } + if (account == null && !aCircuit.lastname.StartsWith("@")) + { + aCircuit.firstname = aCircuit.firstname + "." + aCircuit.lastname; + aCircuit.lastname = "@" + aCircuit.ServiceURLs["HomeURI"].ToString(); + } + // // Finally launch the agent at the destination - aCircuit.firstname = aCircuit.firstname + "." + aCircuit.lastname; - aCircuit.lastname = "@" + aCircuit.ServiceURLs["HomeURI"].ToString(); + // return m_SimulationService.CreateAgent(destination, aCircuit, 0, out reason); } -- cgit v1.1 From 9fbcceb1db84e62eedb75b2bd43f5e59142ec6c8 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 18 Jan 2010 20:35:59 -0800 Subject: * Towards enabling hyperlinks at grid-level. * Updated grid configs --- .../Hypergrid/GatekeeperServerConnector.cs | 11 ++- .../Server/Handlers/Hypergrid/HypergridHandlers.cs | 34 ++++++- .../Hypergrid/HypergridServiceConnector.cs | 110 ++++++++++++++++++++- bin/OpenSim.Server.ini.example | 5 +- bin/config-include/GridHypergrid.ini | 13 ++- 5 files changed, 158 insertions(+), 15 deletions(-) diff --git a/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs index 15b29d2..940ec7a 100644 --- a/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs +++ b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs @@ -51,6 +51,8 @@ namespace OpenSim.Server.Handlers.Hypergrid get { return m_GatekeeperService; } } + private IHypergridService m_HypergridService; + public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server, ISimulationService simService) : base(config, server, String.Empty) { @@ -60,12 +62,17 @@ namespace OpenSim.Server.Handlers.Hypergrid string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty); Object[] args = new Object[] { config, simService }; m_GatekeeperService = ServerUtils.LoadPlugin(serviceDll, args); + + serviceDll = gridConfig.GetString("HypergridService", string.Empty); + m_HypergridService = ServerUtils.LoadPlugin(serviceDll, args); + } - if (m_GatekeeperService == null) + if (m_GatekeeperService == null || m_HypergridService == null) throw new Exception("Gatekeeper server connector cannot proceed because of missing service"); - HypergridHandlers hghandlers = new HypergridHandlers(m_GatekeeperService); + HypergridHandlers hghandlers = new HypergridHandlers(m_GatekeeperService, m_HypergridService); server.AddXmlRPCHandler("link_region", hghandlers.LinkRegionRequest, false); + server.AddXmlRPCHandler("link_region_by_desc", hghandlers.LinkRegionByDescRequest, false); server.AddXmlRPCHandler("get_region", hghandlers.GetRegion, false); server.AddXmlRPCHandler("get_home_region", hghandlers.GetHomeRegion, false); diff --git a/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs index 846d1c2..1d711a8 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs @@ -44,10 +44,12 @@ namespace OpenSim.Server.Handlers.Hypergrid private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IGatekeeperService m_GatekeeperService; + private IHypergridService m_HypergridService; - public HypergridHandlers(IGatekeeperService gatekeeper) + public HypergridHandlers(IGatekeeperService gatekeeper, IHypergridService hyper) { m_GatekeeperService = gatekeeper; + m_HypergridService = hyper; } /// @@ -80,6 +82,36 @@ namespace OpenSim.Server.Handlers.Hypergrid return response; } + /// + /// A local region wants to establish a grid-wide hyperlink to another region + /// + /// + /// + public XmlRpcResponse LinkRegionByDescRequest(XmlRpcRequest request, IPEndPoint remoteClient) + { + Hashtable requestData = (Hashtable)request.Params[0]; + //string host = (string)requestData["host"]; + //string portstr = (string)requestData["port"]; + string descriptor = (string)requestData["region_desc"]; + + UUID regionID = UUID.Zero; + string imageURL = string.Empty; + ulong regionHandle = 0; + string reason = string.Empty; + + bool success = m_HypergridService.LinkRegion(descriptor, out regionID, out regionHandle, out imageURL, out reason); + + Hashtable hash = new Hashtable(); + hash["result"] = success.ToString(); + hash["uuid"] = regionID.ToString(); + hash["handle"] = regionHandle.ToString(); + hash["region_image"] = imageURL; + + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = hash; + return response; + } + public XmlRpcResponse GetRegion(XmlRpcRequest request, IPEndPoint remoteClient) { Hashtable requestData = (Hashtable)request.Params[0]; diff --git a/OpenSim/Services/Connectors/Hypergrid/HypergridServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HypergridServiceConnector.cs index 953c7bd..1786d38 100644 --- a/OpenSim/Services/Connectors/Hypergrid/HypergridServiceConnector.cs +++ b/OpenSim/Services/Connectors/Hypergrid/HypergridServiceConnector.cs @@ -41,22 +41,49 @@ using OpenMetaverse; using OpenMetaverse.Imaging; using log4net; using Nwc.XmlRpc; +using Nini.Config; namespace OpenSim.Services.Connectors.Hypergrid { - public class HypergridServiceConnector + public class HypergridServiceConnector : IHypergridService { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAssetService m_AssetService; + private string m_ServerURL; - public HypergridServiceConnector() : this(null) { } + public HypergridServiceConnector() { } - public HypergridServiceConnector(IAssetService assService) + public HypergridServiceConnector(IAssetService assService) { m_AssetService = assService; } + public HypergridServiceConnector(IConfigSource source) + { + Initialise(source); + } + + public virtual void Initialise(IConfigSource source) + { + IConfig hgConfig = source.Configs["HypergridService"]; + if (hgConfig == null) + { + m_log.Error("[HYPERGRID CONNECTOR]: HypergridService missing from OpenSim.ini"); + throw new Exception("Hypergrid connector init error"); + } + + string serviceURI = hgConfig.GetString("HypergridServerURI", + String.Empty); + + if (serviceURI == String.Empty) + { + m_log.Error("[HYPERGRID CONNECTOR]: No Server URI named in section HypergridService"); + throw new Exception("Hypergrid connector init error"); + } + m_ServerURL = serviceURI; + } + public bool LinkRegion(GridRegion info, out UUID regionID, out ulong realHandle, out string imageURL, out string reason) { regionID = UUID.Zero; @@ -246,5 +273,82 @@ namespace OpenSim.Services.Connectors.Hypergrid return null; } + + #region From local regions to grid-wide hypergrid service + + public bool LinkRegion(string regionDescriptor, out UUID regionID, out ulong realHandle, out string imageURL, out string reason) + { + regionID = UUID.Zero; + imageURL = string.Empty; + realHandle = 0; + reason = string.Empty; + + Hashtable hash = new Hashtable(); + hash["region_desc"] = regionDescriptor; + + IList paramList = new ArrayList(); + paramList.Add(hash); + + XmlRpcRequest request = new XmlRpcRequest("link_region_by_desc", paramList); + XmlRpcResponse response = null; + try + { + response = request.Send(m_ServerURL, 10000); + } + catch (Exception e) + { + m_log.Debug("[HGrid]: Exception " + e.Message); + reason = "Error contacting remote server"; + return false; + } + + if (response.IsFault) + { + reason = response.FaultString; + m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString); + return false; + } + + hash = (Hashtable)response.Value; + //foreach (Object o in hash) + // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); + try + { + bool success = false; + Boolean.TryParse((string)hash["result"], out success); + if (success) + { + UUID.TryParse((string)hash["uuid"], out regionID); + //m_log.Debug(">> HERE, uuid: " + uuid); + if ((string)hash["handle"] != null) + { + realHandle = Convert.ToUInt64((string)hash["handle"]); + //m_log.Debug(">> HERE, realHandle: " + realHandle); + } + if (hash["region_image"] != null) + { + imageURL = (string)hash["region_image"]; + } + } + + } + catch (Exception e) + { + reason = "Error parsing return arguments"; + m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace); + return false; + } + + return true; + } + + // TODO !!! + public GridRegion GetRegionByUUID(UUID regionID) { return null; } + public GridRegion GetRegionByPosition(int x, int y) { return null; } + public GridRegion GetRegionByName(string name) { return null; } + public List GetRegionsByName(string name) { return null; } + public List GetRegionRange(int xmin, int xmax, int ymin, int ymax) { return null; } + + #endregion } } diff --git a/bin/OpenSim.Server.ini.example b/bin/OpenSim.Server.ini.example index 3d2a5ba..0c6046f 100644 --- a/bin/OpenSim.Server.ini.example +++ b/bin/OpenSim.Server.ini.example @@ -42,7 +42,6 @@ ServiceConnectors = "OpenSim.Server.Handlers.dll:AssetServiceConnector,OpenSim.S ; * [InventoryService] LocalServiceModule = "OpenSim.Services.InventoryService.dll:InventoryService" - UserServerURI = "http://127.0.0.1:8002" SessionAuthentication = "false" StorageProvider = "OpenSim.Data.MySQL.dll" ConnectionString = "Data Source=localhost;Database=opensim;User ID=opensim;Password=opensim123;" @@ -58,10 +57,12 @@ ServiceConnectors = "OpenSim.Server.Handlers.dll:AssetServiceConnector,OpenSim.S Realm = "regions" ; AllowDuplicateNames = "True" ;; Next, we can specify properties of regions, including default and fallback regions - ;; The syntax is: Region_ = "" + ;; The syntax is: Region_ = "" + ;; or: Region_ = "" ;; where can be DefaultRegion, FallbackRegion, NoDirectLogin, Persistent, LockedOut,Reservation,NoMove,Authenticate ;; For example: ; Region_Welcome_Area = "DefaultRegion, FallbackRegion" + ; (replace spaces with underscore) ; * This is the configuration for the freeswitch server in grid mode [FreeswitchService] diff --git a/bin/config-include/GridHypergrid.ini b/bin/config-include/GridHypergrid.ini index 4b6bc17..4885a41 100644 --- a/bin/config-include/GridHypergrid.ini +++ b/bin/config-include/GridHypergrid.ini @@ -17,18 +17,17 @@ AvatarServices = "RemoteAvatarServicesConnector" NeighbourServices = "RemoteNeighbourServicesConnector" AuthenticationServices = "RemoteAuthenticationServicesConnector" + AuthorizationServices = "LocalAuthorizationServicesConnector" PresenceServices = "RemotePresenceServicesConnector" UserAccountServices = "RemoteUserAccountServicesConnector" SimulationServices = "RemoteSimulationConnectorModule" - EntityTransferModule = "BasicEntityTransferModule" + EntityTransferModule = "HGEntityTransferModule" LandServiceInConnector = true NeighbourServiceInConnector = true - HypergridServiceInConnector = true SimulationServiceInConnector = true LibraryModule = true InventoryServiceInConnector = false AssetServiceInConnector = false - LLLoginServiceInConnector = false [AssetService] LocalGridAssetService = "OpenSim.Services.Connectors.dll:AssetServicesConnector" @@ -41,12 +40,12 @@ [GridService] ; for the HGGridServicesConnector to instantiate GridServiceConnectorModule = "OpenSim.Region.CoreModules.dll:RemoteGridServicesConnector" + HypergridService = "OpenSim.Services.HypergridService.dll:HypergridService" ; RemoteGridServicesConnector instantiates a LocalGridServicesConnector, ; which in turn uses this LocalServiceModule = "OpenSim.Services.GridService.dll:GridService" StorageProvider = "OpenSim.Data.Null.dll:NullRegionData" -[LibraryService] - LocalServiceModule = "OpenSim.Services.InventoryService.dll:LibraryService" - LibraryName = "OpenSim Library" - DefaultLibrary = "./inventory/Libraries.xml" +[HypergridService] + GridService = "OpenSim.Services.GridService.dll:GridService" + AssetService = "OpenSim.Services.AssetService.dll:AssetService" -- cgit v1.1