From 04e29c1bacbc1e2df980ae15896a847ce7535da2 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 16 Jan 2010 21:42:44 -0800 Subject: Beginning of rewriting HG. Compiles, and runs, but HG functions not restored yet. --- .../EntityTransfer/EntityTransferModule.cs | 2 +- .../Grid/HypergridServiceInConnectorModule.cs | 14 +- .../ServiceConnectorsOut/Grid/HGCommands.cs | 303 ---------- .../ServiceConnectorsOut/Grid/HGGridConnector.cs | 650 ++------------------- 4 files changed, 48 insertions(+), 921 deletions(-) delete mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs (limited to 'OpenSim/Region/CoreModules') diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index 25415af..827dafe 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -1154,7 +1154,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer #endregion - #region Object Crossings + #region Object Transfers /// /// Move the given scene object into a new region depending on which region its absolute position has moved /// into. diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs index b12d778..6ec0fcf 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs @@ -36,7 +36,7 @@ using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Interfaces; using OpenSim.Server.Base; using OpenSim.Server.Handlers.Base; -using OpenSim.Server.Handlers.Grid; +using OpenSim.Server.Handlers.Hypergrid; using OpenSim.Services.Interfaces; using GridRegion = OpenSim.Services.Interfaces.GridRegion; @@ -49,7 +49,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid private IConfigSource m_Config; bool m_Registered = false; - HypergridServiceInConnector m_HypergridHandler; + GatekeeperServiceInConnector m_HypergridHandler; #region IRegionModule interface @@ -102,9 +102,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid { if (!m_Enabled) return; - - GridRegion rinfo = new GridRegion(scene.RegionInfo); - m_HypergridHandler.RemoveRegion(rinfo); } public void RegionLoaded(Scene scene) @@ -119,13 +116,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid m_log.Info("[HypergridService]: Starting..."); // Object[] args = new Object[] { m_Config, MainServer.Instance }; - - m_HypergridHandler = new HypergridServiceInConnector(m_Config, MainServer.Instance, scene.RequestModuleInterface()); + ISimulationService simService = scene.RequestModuleInterface(); + m_HypergridHandler = new GatekeeperServiceInConnector(m_Config, MainServer.Instance, simService); //ServerUtils.LoadPlugin("OpenSim.Server.Handlers.dll:HypergridServiceInConnector", args); } - - GridRegion rinfo = new GridRegion(scene.RegionInfo); - m_HypergridHandler.AddRegion(rinfo); } #endregion diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs deleted file mode 100644 index 0974372..0000000 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs +++ /dev/null @@ -1,303 +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.Collections.Generic; -using System.Reflection; -using System.Xml; -using log4net; -using Nini.Config; -using OpenSim.Framework; -//using OpenSim.Framework.Communications; -using OpenSim.Framework.Console; -using OpenSim.Region.Framework; -using OpenSim.Region.Framework.Scenes; -using OpenSim.Region.Framework.Scenes.Hypergrid; -using GridRegion = OpenSim.Services.Interfaces.GridRegion; - -namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid -{ - public class HGCommands - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private HGGridConnector m_HGGridConnector; - private Scene m_scene; - - private static uint m_autoMappingX = 0; - private static uint m_autoMappingY = 0; - private static bool m_enableAutoMapping = false; - - public HGCommands(HGGridConnector hgConnector, Scene scene) - { - m_HGGridConnector = hgConnector; - m_scene = scene; - } - - //public static Scene CreateScene(RegionInfo regionInfo, AgentCircuitManager circuitManager, CommunicationsManager m_commsManager, - // StorageManager storageManager, ModuleLoader m_moduleLoader, ConfigSettings m_configSettings, OpenSimConfigSource m_config, string m_version) - //{ - // HGSceneCommunicationService sceneGridService = new HGSceneCommunicationService(m_commsManager, HGServices); - - // return - // new HGScene( - // regionInfo, circuitManager, m_commsManager, sceneGridService, storageManager, - // m_moduleLoader, false, m_configSettings.PhysicalPrim, - // m_configSettings.See_into_region_from_neighbor, m_config.Source, m_version); - //} - - public void RunCommand(string module, string[] cmdparams) - { - List args = new List(cmdparams); - if (args.Count < 1) - return; - - string command = args[0]; - args.RemoveAt(0); - - cmdparams = args.ToArray(); - - RunHGCommand(command, cmdparams); - - } - - private void RunHGCommand(string command, string[] cmdparams) - { - if (command.Equals("link-mapping")) - { - if (cmdparams.Length == 2) - { - try - { - m_autoMappingX = Convert.ToUInt32(cmdparams[0]); - m_autoMappingY = Convert.ToUInt32(cmdparams[1]); - m_enableAutoMapping = true; - } - catch (Exception) - { - m_autoMappingX = 0; - m_autoMappingY = 0; - m_enableAutoMapping = false; - } - } - } - else if (command.Equals("link-region")) - { - if (cmdparams.Length < 3) - { - if ((cmdparams.Length == 1) || (cmdparams.Length == 2)) - { - LoadXmlLinkFile(cmdparams); - } - else - { - LinkRegionCmdUsage(); - } - return; - } - - if (cmdparams[2].Contains(":")) - { - // New format - int xloc, yloc; - string mapName; - try - { - xloc = Convert.ToInt32(cmdparams[0]); - yloc = Convert.ToInt32(cmdparams[1]); - mapName = cmdparams[2]; - if (cmdparams.Length > 3) - for (int i = 3; i < cmdparams.Length; i++) - mapName += " " + cmdparams[i]; - - m_log.Info(">> MapName: " + mapName); - //internalPort = Convert.ToUInt32(cmdparams[4]); - //remotingPort = Convert.ToUInt32(cmdparams[5]); - } - catch (Exception e) - { - m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message); - LinkRegionCmdUsage(); - return; - } - - // Convert cell coordinates given by the user to meters - xloc = xloc * (int)Constants.RegionSize; - yloc = yloc * (int)Constants.RegionSize; - m_HGGridConnector.TryLinkRegionToCoords(m_scene, null, mapName, xloc, yloc); - } - else - { - // old format - GridRegion regInfo; - int xloc, yloc; - uint externalPort; - string externalHostName; - try - { - xloc = Convert.ToInt32(cmdparams[0]); - yloc = Convert.ToInt32(cmdparams[1]); - externalPort = Convert.ToUInt32(cmdparams[3]); - externalHostName = cmdparams[2]; - //internalPort = Convert.ToUInt32(cmdparams[4]); - //remotingPort = Convert.ToUInt32(cmdparams[5]); - } - catch (Exception e) - { - m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message); - LinkRegionCmdUsage(); - return; - } - - // Convert cell coordinates given by the user to meters - xloc = xloc * (int)Constants.RegionSize; - yloc = yloc * (int)Constants.RegionSize; - if (m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort, externalHostName, out regInfo)) - { - if (cmdparams.Length >= 5) - { - regInfo.RegionName = ""; - for (int i = 4; i < cmdparams.Length; i++) - regInfo.RegionName += cmdparams[i] + " "; - } - } - } - return; - } - else if (command.Equals("unlink-region")) - { - if (cmdparams.Length < 1) - { - UnlinkRegionCmdUsage(); - return; - } - if (m_HGGridConnector.TryUnlinkRegion(m_scene, cmdparams[0])) - m_log.InfoFormat("[HGrid]: Successfully unlinked {0}", cmdparams[0]); - else - m_log.InfoFormat("[HGrid]: Unable to unlink {0}, region not found", cmdparams[0]); - } - } - - private void LoadXmlLinkFile(string[] cmdparams) - { - //use http://www.hgurl.com/hypergrid.xml for test - try - { - XmlReader r = XmlReader.Create(cmdparams[0]); - XmlConfigSource cs = new XmlConfigSource(r); - string[] excludeSections = null; - - if (cmdparams.Length == 2) - { - if (cmdparams[1].ToLower().StartsWith("excludelist:")) - { - string excludeString = cmdparams[1].ToLower(); - excludeString = excludeString.Remove(0, 12); - char[] splitter = { ';' }; - - excludeSections = excludeString.Split(splitter); - } - } - - for (int i = 0; i < cs.Configs.Count; i++) - { - bool skip = false; - if ((excludeSections != null) && (excludeSections.Length > 0)) - { - for (int n = 0; n < excludeSections.Length; n++) - { - if (excludeSections[n] == cs.Configs[i].Name.ToLower()) - { - skip = true; - break; - } - } - } - if (!skip) - { - ReadLinkFromConfig(cs.Configs[i]); - } - } - } - catch (Exception e) - { - m_log.Error(e.ToString()); - } - } - - - private void ReadLinkFromConfig(IConfig config) - { - GridRegion regInfo; - int xloc, yloc; - uint externalPort; - string externalHostName; - uint realXLoc, realYLoc; - - xloc = Convert.ToInt32(config.GetString("xloc", "0")); - yloc = Convert.ToInt32(config.GetString("yloc", "0")); - externalPort = Convert.ToUInt32(config.GetString("externalPort", "0")); - externalHostName = config.GetString("externalHostName", ""); - realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0")); - realYLoc = Convert.ToUInt32(config.GetString("real-yloc", "0")); - - if (m_enableAutoMapping) - { - xloc = (int)((xloc % 100) + m_autoMappingX); - yloc = (int)((yloc % 100) + m_autoMappingY); - } - - if (((realXLoc == 0) && (realYLoc == 0)) || - (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) && - ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896)))) - { - xloc = xloc * (int)Constants.RegionSize; - yloc = yloc * (int)Constants.RegionSize; - if ( - m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort, - externalHostName, out regInfo)) - { - regInfo.RegionName = config.GetString("localName", ""); - } - } - } - - - private void LinkRegionCmdUsage() - { - m_log.Info("Usage: link-region :[:]"); - m_log.Info("Usage: link-region []"); - m_log.Info("Usage: link-region []"); - } - - private void UnlinkRegionCmdUsage() - { - m_log.Info("Usage: unlink-region :"); - m_log.Info("Usage: unlink-region "); - } - - } -} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs index de71b56..75eb889 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs @@ -49,12 +49,11 @@ using Nini.Config; namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid { - public class HGGridConnector : ISharedRegionModule, IGridService, IHyperlinkService + public class HGGridConnector : ISharedRegionModule, IGridService { private static readonly ILog m_log = LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType); - private static string LocalAssetServerURI, LocalInventoryServerURI, LocalUserServerURI; private bool m_Enabled = false; private bool m_Initialized = false; @@ -63,18 +62,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid private Dictionary m_LocalScenes = new Dictionary(); private IGridService m_GridServiceConnector; - private HypergridServiceConnector m_HypergridServiceConnector; + private IHypergridService m_HypergridService; - // Hyperlink regions are hyperlinks on the map - protected Dictionary m_HyperlinkRegions = new Dictionary(); - - // Known regions are home regions of visiting foreign users. - // They are not on the map as static hyperlinks. They are dynamic hyperlinks, they go away when - // the visitor goes away. They are mapped to X=0 on the map. - // This is key-ed on agent ID - protected Dictionary m_knownRegions = new Dictionary(); - - protected Dictionary m_HyperlinkHandles = new Dictionary(); #region ISharedRegionModule @@ -125,13 +114,22 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (module == String.Empty) { m_log.Error("[HGGRID CONNECTOR]: No GridServiceConnectorModule named in section GridService"); - //return; throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's"); } Object[] args = new Object[] { source }; m_GridServiceConnector = ServerUtils.LoadPlugin(module, args); + string hypergrid = gridConfig.GetString("HypergridService", string.Empty); + if (hypergrid == String.Empty) + { + m_log.Error("[HGGRID CONNECTOR]: No HypergridService named in section GridService"); + throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's"); + } + m_HypergridService = ServerUtils.LoadPlugin(hypergrid, args); + + if (m_GridServiceConnector == null || m_HypergridService == null) + throw new Exception("Unable to proceed. HGGrid services could not be loaded."); } public void PostInitialise() @@ -151,7 +149,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid m_LocalScenes[scene.RegionInfo.RegionHandle] = scene; scene.RegisterModuleInterface(this); - scene.RegisterModuleInterface(this); ((ISharedRegionModule)m_GridServiceConnector).AddRegion(scene); @@ -175,18 +172,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid { m_aScene = scene; - m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService); - - HGCommands hgCommands = new HGCommands(this, scene); - MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-region", - "link-region :[:] ", - "Link a hypergrid region", hgCommands.RunCommand); - MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "unlink-region", - "unlink-region or : ", - "Unlink a hypergrid region", hgCommands.RunCommand); - MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-mapping", "link-mapping [ ] ", - "Set local coordinate to map HG regions to", hgCommands.RunCommand); - m_Initialized = true; } } @@ -197,50 +182,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public string RegisterRegion(UUID scopeID, GridRegion regionInfo) { - // Region doesn't exist here. Trying to link remote region - if (regionInfo.RegionID.Equals(UUID.Zero)) - { - m_log.Info("[HGrid]: Linking remote region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort); - ulong regionHandle = 0; - regionInfo.RegionID = m_HypergridServiceConnector.LinkRegion(regionInfo, out regionHandle); - if (!regionInfo.RegionID.Equals(UUID.Zero)) - { - AddHyperlinkRegion(regionInfo, regionHandle); - m_log.Info("[HGrid]: Successfully linked to region_uuid " + regionInfo.RegionID); - - // Try get the map image - m_HypergridServiceConnector.GetMapImage(regionInfo); - return String.Empty; - } - else - { - m_log.Info("[HGrid]: No such region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort + "(" + regionInfo.InternalEndPoint.Port + ")"); - return "No such region"; - } - // Note that these remote regions aren't registered in localBackend, so return null, no local listeners - } - else // normal grid - return m_GridServiceConnector.RegisterRegion(scopeID, regionInfo); + return m_GridServiceConnector.RegisterRegion(scopeID, regionInfo); } public bool DeregisterRegion(UUID regionID) { - // Try the hyperlink collection - if (m_HyperlinkRegions.ContainsKey(regionID)) - { - RemoveHyperlinkRegion(regionID); - return true; - } - // Try the foreign users home collection - - foreach (GridRegion r in m_knownRegions.Values) - if (r.RegionID == regionID) - { - RemoveHyperlinkHomeRegion(regionID); - return true; - } - - // Finally, try the normal route return m_GridServiceConnector.DeregisterRegion(regionID); } @@ -253,41 +199,27 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) { - // Try the hyperlink collection - if (m_HyperlinkRegions.ContainsKey(regionID)) - return m_HyperlinkRegions[regionID]; - - // Try the foreign users home collection - foreach (GridRegion r in m_knownRegions.Values) - if (r.RegionID == regionID) - return r; - - // Finally, try the normal route - return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID); + GridRegion region = m_GridServiceConnector.GetRegionByUUID(scopeID, regionID); + if (region != null) + return region; + + region = m_HypergridService.GetRegionByUUID(regionID); + + return region; } public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) { int snapX = (int) (x / Constants.RegionSize) * (int)Constants.RegionSize; int snapY = (int) (y / Constants.RegionSize) * (int)Constants.RegionSize; - // Try the hyperlink collection - foreach (GridRegion r in m_HyperlinkRegions.Values) - { - if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY)) - return r; - } - // Try the foreign users home collection - foreach (GridRegion r in m_knownRegions.Values) - { - if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY)) - { - return r; - } - } + GridRegion region = m_GridServiceConnector.GetRegionByPosition(scopeID, x, y); + if (region != null) + return region; + + region = m_HypergridService.GetRegionByPosition(snapX, snapY); - // Finally, try the normal route - return m_GridServiceConnector.GetRegionByPosition(scopeID, x, y); + return region; } public GridRegion GetRegionByName(UUID scopeID, string regionName) @@ -297,551 +229,55 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid if (region != null) return region; - // Try the hyperlink collection - foreach (GridRegion r in m_HyperlinkRegions.Values) - { - if (r.RegionName == regionName) - return r; - } + region = m_HypergridService.GetRegionByName(regionName); - // Try the foreign users home collection - foreach (GridRegion r in m_knownRegions.Values) - { - if (r.RegionName == regionName) - return r; - } - return null; + return region; } public List GetRegionsByName(UUID scopeID, string name, int maxNumber) { - List rinfos = new List(); - if (name == string.Empty) - return rinfos; - - foreach (GridRegion r in m_HyperlinkRegions.Values) - if ((r.RegionName != null) && r.RegionName.ToLower().StartsWith(name.ToLower())) - rinfos.Add(r); + return new List(); + + List rinfos = m_GridServiceConnector.GetRegionsByName(scopeID, name, maxNumber); + + rinfos.AddRange(m_HypergridService.GetRegionsByName(name)); + if (rinfos.Count > maxNumber) + rinfos.RemoveRange(maxNumber - 1, rinfos.Count - maxNumber); - rinfos.AddRange(m_GridServiceConnector.GetRegionsByName(scopeID, name, maxNumber)); return rinfos; } public List GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) { int snapXmin = (int)(xmin / Constants.RegionSize) * (int)Constants.RegionSize; -// int snapXmax = (int)(xmax / Constants.RegionSize) * (int)Constants.RegionSize; + int snapXmax = (int)(xmax / Constants.RegionSize) * (int)Constants.RegionSize; int snapYmin = (int)(ymin / Constants.RegionSize) * (int)Constants.RegionSize; int snapYmax = (int)(ymax / Constants.RegionSize) * (int)Constants.RegionSize; - List rinfos = new List(); - foreach (GridRegion r in m_HyperlinkRegions.Values) - if ((r.RegionLocX > snapXmin) && (r.RegionLocX < snapYmax) && - (r.RegionLocY > snapYmin) && (r.RegionLocY < snapYmax)) - rinfos.Add(r); + List rinfos = m_GridServiceConnector.GetRegionRange(scopeID, xmin, xmax, ymin, ymax); - rinfos.AddRange(m_GridServiceConnector.GetRegionRange(scopeID, xmin, xmax, ymin, ymax)); + rinfos.AddRange(m_HypergridService.GetRegionRange(snapXmin, snapXmax, snapYmin, snapYmax)); return rinfos; } - #endregion - - #region Auxiliary - - private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle) - { - m_HyperlinkRegions[regionInfo.RegionID] = regionInfo; - m_HyperlinkHandles[regionInfo.RegionID] = regionHandle; - } - - private void RemoveHyperlinkRegion(UUID regionID) - { - m_HyperlinkRegions.Remove(regionID); - m_HyperlinkHandles.Remove(regionID); - } - - private void AddHyperlinkHomeRegion(UUID userID, GridRegion regionInfo, ulong regionHandle) - { - m_knownRegions[userID] = regionInfo; - m_HyperlinkHandles[regionInfo.RegionID] = regionHandle; - } - - private void RemoveHyperlinkHomeRegion(UUID regionID) - { - foreach (KeyValuePair kvp in m_knownRegions) - { - if (kvp.Value.RegionID == regionID) - { - m_knownRegions.Remove(kvp.Key); - } - } - m_HyperlinkHandles.Remove(regionID); - } - #endregion - - #region IHyperlinkService - - private static Random random = new Random(); - - // From the command line link-region - public GridRegion TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, int xloc, int yloc) - { - string host = "127.0.0.1"; - string portstr; - string regionName = ""; - uint port = 9000; - string[] parts = mapName.Split(new char[] { ':' }); - if (parts.Length >= 1) - { - host = parts[0]; - } - if (parts.Length >= 2) - { - portstr = parts[1]; - //m_log.Debug("-- port = " + portstr); - if (!UInt32.TryParse(portstr, out port)) - regionName = parts[1]; - } - // always take the last one - if (parts.Length >= 3) - { - regionName = parts[2]; - } - - // Sanity check. Don't ever link to this sim. - IPAddress ipaddr = null; - try - { - ipaddr = Util.GetHostFromDNS(host); - } - catch { } - - if ((ipaddr != null) && - !((m_scene.RegionInfo.ExternalEndPoint.Address.Equals(ipaddr)) && (m_scene.RegionInfo.HttpPort == port))) - { - GridRegion regInfo; - bool success = TryCreateLink(m_scene, client, xloc, yloc, regionName, port, host, out regInfo); - if (success) - { - regInfo.RegionName = mapName; - return regInfo; - } - } - - return null; - } - - - // From the map search and secondlife://blah - public GridRegion TryLinkRegion(Scene m_scene, IClientAPI client, string mapName) - { - int xloc = random.Next(0, Int16.MaxValue) * (int) Constants.RegionSize; - return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0); - } - - // From the command line and the 2 above - public bool TryCreateLink(Scene m_scene, IClientAPI client, int xloc, int yloc, - string externalRegionName, uint externalPort, string externalHostName, out GridRegion regInfo) - { - m_log.DebugFormat("[HGrid]: Link to {0}:{1}, in {2}-{3}", externalHostName, externalPort, xloc, yloc); - - regInfo = new GridRegion(); - regInfo.RegionName = externalRegionName; - regInfo.HttpPort = externalPort; - regInfo.ExternalHostName = externalHostName; - regInfo.RegionLocX = xloc; - regInfo.RegionLocY = yloc; - - try - { - regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0); - } - catch (Exception e) - { - m_log.Warn("[HGrid]: Wrong format for link-region: " + e.Message); - return false; - } - - // Finally, link it - if (RegisterRegion(UUID.Zero, regInfo) != String.Empty) - { - m_log.Warn("[HGrid]: Unable to link region"); - return false; - } - - int x, y; - if (!Check4096(m_scene, regInfo, out x, out y)) - { - DeregisterRegion(regInfo.RegionID); - if (client != null) - client.SendAlertMessage("Region is too far (" + x + ", " + y + ")"); - m_log.Info("[HGrid]: Unable to link, region is too far (" + x + ", " + y + ")"); - return false; - } - - if (!CheckCoords(m_scene.RegionInfo.RegionLocX, m_scene.RegionInfo.RegionLocY, x, y)) - { - DeregisterRegion(regInfo.RegionID); - if (client != null) - client.SendAlertMessage("Region has incompatible coordinates (" + x + ", " + y + ")"); - m_log.Info("[HGrid]: Unable to link, region has incompatible coordinates (" + x + ", " + y + ")"); - return false; - } - - m_log.Debug("[HGrid]: link region succeeded"); - return true; - } - - public bool TryUnlinkRegion(Scene m_scene, string mapName) - { - GridRegion regInfo = null; - if (mapName.Contains(":")) - { - string host = "127.0.0.1"; - //string portstr; - //string regionName = ""; - uint port = 9000; - string[] parts = mapName.Split(new char[] { ':' }); - if (parts.Length >= 1) - { - host = parts[0]; - } - // if (parts.Length >= 2) - // { - // portstr = parts[1]; - // if (!UInt32.TryParse(portstr, out port)) - // regionName = parts[1]; - // } - // always take the last one - // if (parts.Length >= 3) - // { - // regionName = parts[2]; - // } - foreach (GridRegion r in m_HyperlinkRegions.Values) - if (host.Equals(r.ExternalHostName) && (port == r.HttpPort)) - regInfo = r; - } - else - { - foreach (GridRegion r in m_HyperlinkRegions.Values) - if (r.RegionName.Equals(mapName)) - regInfo = r; - } - if (regInfo != null) - { - return DeregisterRegion(regInfo.RegionID); - } - else - { - m_log.InfoFormat("[HGrid]: Region {0} not found", mapName); - return false; - } - } - - /// - /// Cope with this viewer limitation. - /// - /// - /// - public bool Check4096(Scene m_scene, GridRegion regInfo, out int x, out int y) - { - ulong realHandle = m_HyperlinkHandles[regInfo.RegionID]; - uint ux = 0, uy = 0; - Utils.LongToUInts(realHandle, out ux, out uy); - x = (int)(ux / Constants.RegionSize); - y = (int)(uy / Constants.RegionSize); - - if ((Math.Abs((int)m_scene.RegionInfo.RegionLocX - x) >= 4096) || - (Math.Abs((int)m_scene.RegionInfo.RegionLocY - y) >= 4096)) - { - return false; - } - return true; - } - - public bool CheckCoords(uint thisx, uint thisy, int x, int y) - { - if ((thisx == x) && (thisy == y)) - return false; - return true; - } - - // From the map search - public GridRegion TryLinkRegion(IClientAPI client, string regionDescriptor) - { - return TryLinkRegion((Scene)client.Scene, client, regionDescriptor); - } - - // From the map and secondlife://blah - public GridRegion GetHyperlinkRegion(ulong handle) - { - foreach (GridRegion r in m_HyperlinkRegions.Values) - if (r.RegionHandle == handle) - return r; - foreach (GridRegion r in m_knownRegions.Values) - if (r.RegionHandle == handle) - return r; - return null; - } - - public ulong FindRegionHandle(ulong handle) - { - foreach (GridRegion r in m_HyperlinkRegions.Values) - if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID))) - return m_HyperlinkHandles[r.RegionID]; - - foreach (GridRegion r in m_knownRegions.Values) - if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID))) - return m_HyperlinkHandles[r.RegionID]; - - return handle; - } - - public bool SendUserInformation(GridRegion regInfo, AgentCircuitData agentData) - { - // REFACTORING PROBLEM. This needs to change. Some of this info should go with the agent circuit data. - - //UserAccount account = m_aScene.UserAccountService.GetUserAccount(m_aScene.RegionInfo.ScopeID, agentData.AgentID); - //if (account == null) - // return false; - - //if ((IsLocalUser(account) && (GetHyperlinkRegion(regInfo.RegionHandle) != null)) || - // (!IsLocalUser(account) && !IsGoingHome(uinfo, regInfo))) - //{ - // m_log.Info("[HGrid]: Local user is going to foreign region or foreign user is going elsewhere"); - - // PresenceInfo pinfo = m_aScene.PresenceService.GetAgent(agentData.SessionID); - // if (pinfo != null) - // { - // // Set the position of the region on the remote grid - // // ulong realHandle = FindRegionHandle(regInfo.RegionHandle); - // uint x = 0, y = 0; - // Utils.LongToUInts(regInfo.RegionHandle, out x, out y); - // GridRegion clonedRegion = new GridRegion(regInfo); - // clonedRegion.RegionLocX = (int)x; - // clonedRegion.RegionLocY = (int)y; - - // // Get the user's home region information and adapt the region handle - // GridRegion home = GetRegionByUUID(m_aScene.RegionInfo.ScopeID, pinfo.HomeRegionID); - // if (m_HyperlinkHandles.ContainsKey(pinfo.HomeRegionID)) - // { - // ulong realHandle = m_HyperlinkHandles[pinfo.HomeRegionID]; - // Utils.LongToUInts(realHandle, out x, out y); - // m_log.DebugFormat("[HGrid]: Foreign user is going elsewhere. Adjusting home handle from {0}-{1} to {2}-{3}", home.RegionLocX, home.RegionLocY, x, y); - // home.RegionLocX = (int)x; - // home.RegionLocY = (int)y; - // } - - // // Get the user's service URLs - // string serverURI = ""; - // if (uinfo.UserProfile is ForeignUserProfileData) - // serverURI = Util.ServerURI(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI); - // string userServer = (serverURI == "") || (serverURI == null) ? LocalUserServerURI : serverURI; - - // string assetServer = Util.ServerURI(uinfo.UserProfile.UserAssetURI); - // if ((assetServer == null) || (assetServer == "")) - // assetServer = LocalAssetServerURI; - - // string inventoryServer = Util.ServerURI(uinfo.UserProfile.UserInventoryURI); - // if ((inventoryServer == null) || (inventoryServer == "")) - // inventoryServer = LocalInventoryServerURI; - - // if (!m_HypergridServiceConnector.InformRegionOfUser(clonedRegion, agentData, home, userServer, assetServer, inventoryServer)) - // { - // m_log.Warn("[HGrid]: Could not inform remote region of transferring user."); - // return false; - // } - // } - // else - // { - // m_log.Warn("[HGrid]: Unable to find local presence of transferring user."); - // return false; - // } - //} - ////if ((uinfo == null) || !IsGoingHome(uinfo, regInfo)) - ////{ - //// m_log.Info("[HGrid]: User seems to be going to foreign region."); - //// if (!InformRegionOfUser(regInfo, agentData)) - //// { - //// m_log.Warn("[HGrid]: Could not inform remote region of transferring user."); - //// return false; - //// } - ////} - ////else - //// m_log.Info("[HGrid]: User seems to be going home " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName); - - //// May need to change agent's name - //if (IsLocalUser(uinfo) && (GetHyperlinkRegion(regInfo.RegionHandle) != null)) - //{ - // agentData.firstname = agentData.firstname + "." + agentData.lastname; - // agentData.lastname = "@" + LocalUserServerURI.Replace("http://", ""); ; //HGNetworkServersInfo.Singleton.LocalUserServerURI; - //} - - return true; - } - - public void AdjustUserInformation(AgentCircuitData agentData) - { - // REFACTORING PROBLEM!!! This needs to change - - //CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID); - //if ((uinfo != null) && (uinfo.UserProfile != null) && - // (IsLocalUser(uinfo) || !(uinfo.UserProfile is ForeignUserProfileData))) - //{ - // //m_log.Debug("---------------> Local User!"); - // string[] parts = agentData.firstname.Split(new char[] { '.' }); - // if (parts.Length == 2) - // { - // agentData.firstname = parts[0]; - // agentData.lastname = parts[1]; - // } - //} - ////else - //// m_log.Debug("---------------> Foreign User!"); - } - - // Check if a local user exists with the same UUID as the incoming foreign user - public bool CheckUserAtEntry(UUID userID, UUID sessionID, out bool comingHome) - { - comingHome = false; - - UserAccount account = m_aScene.UserAccountService.GetUserAccount(m_aScene.RegionInfo.ScopeID, userID); - if (account != null) - { - if (m_aScene.AuthenticationService.Verify(userID, sessionID.ToString(), 30)) - { - // oh, so it's you! welcome back - comingHome = true; - } - else - // can't have a foreigner with a local UUID - return false; - } - - // OK, user can come in - return true; - } - - public void AcceptUser(ForeignUserProfileData user, GridRegion home) - { - // REFACTORING PROBLEM. uh-oh, commenting this breaks HG completely - // Needs to be rewritten - //m_aScene.CommsManager.UserProfileCacheService.PreloadUserCache(user); - - ulong realHandle = home.RegionHandle; - // Change the local coordinates - // X=0 on the map - home.RegionLocX = 0; - home.RegionLocY = random.Next(0, 10000) * (int)Constants.RegionSize; - - AddHyperlinkHomeRegion(user.ID, home, realHandle); - - DumpUserData(user); - DumpRegionData(home); - - } - - public bool IsLocalUser(UUID userID) - { - UserAccount account = m_aScene.UserAccountService.GetUserAccount(m_aScene.RegionInfo.ScopeID, userID); - return IsLocalUser(account); - } - - #endregion - - #region IHyperlink Misc - - protected bool IsComingHome(ForeignUserProfileData userData) - { - return false; - // REFACTORING PROBLEM - //return (userData.UserServerURI == LocalUserServerURI); - } - - // REFACTORING PROBLEM - //// Is the user going back to the home region or the home grid? - //protected bool IsGoingHome(CachedUserInfo uinfo, GridRegion rinfo) - //{ - // if (uinfo == null) - // return false; - - // if (uinfo.UserProfile == null) - // return false; - - // if (!(uinfo.UserProfile is ForeignUserProfileData)) - // // it's a home user, can't be outside to return home - // return false; - - // // OK, it's a foreign user with a ForeignUserProfileData - // // and is going back to exactly the home region. - // // We can't check if it's going back to a non-home region - // // of the home grid. That will be dealt with in the - // // receiving end - // return (uinfo.UserProfile.HomeRegionID == rinfo.RegionID); - //} - - protected bool IsLocalUser(UserAccount account) - { - return true; - - // REFACTORING PROBLEM - //if (account != null && - // account.ServiceURLs.ContainsKey("HomeURI") && - // account.ServiceURLs["HomeURI"] != null) - - // return (account.ServiceURLs["HomeURI"].ToString() == LocalUserServerURI); - - //return false; - } - - - protected bool IsLocalRegion(ulong handle) - { - return m_LocalScenes.ContainsKey(handle); - } - - private void DumpUserData(ForeignUserProfileData userData) - { - m_log.Info(" ------------ User Data Dump ----------"); - m_log.Info(" >> Name: " + userData.FirstName + " " + userData.SurName); - m_log.Info(" >> HomeID: " + userData.HomeRegionID); - m_log.Info(" >> UserServer: " + userData.UserServerURI); - m_log.Info(" >> InvServer: " + userData.UserInventoryURI); - m_log.Info(" >> AssetServer: " + userData.UserAssetURI); - m_log.Info(" ------------ -------------- ----------"); - } - - private void DumpRegionData(GridRegion rinfo) - { - m_log.Info(" ------------ Region Data Dump ----------"); - m_log.Info(" >> handle: " + rinfo.RegionHandle); - m_log.Info(" >> coords: " + rinfo.RegionLocX + ", " + rinfo.RegionLocY); - m_log.Info(" >> external host name: " + rinfo.ExternalHostName); - m_log.Info(" >> http port: " + rinfo.HttpPort); - m_log.Info(" >> external EP address: " + rinfo.ExternalEndPoint.Address); - m_log.Info(" >> external EP port: " + rinfo.ExternalEndPoint.Port); - m_log.Info(" ------------ -------------- ----------"); - } - - - #endregion - public List GetDefaultRegions(UUID scopeID) { - return null; + return m_GridServiceConnector.GetDefaultRegions(scopeID); } public List GetFallbackRegions(UUID scopeID, int x, int y) { - return null; + return m_GridServiceConnector.GetFallbackRegions(scopeID, x, y); } public int GetRegionFlags(UUID scopeID, UUID regionID) { - return 0; + return m_GridServiceConnector.GetRegionFlags(scopeID, regionID); } + + #endregion } } -- cgit v1.1