Merge branch 'master' of ssh://justincc@opensimulator.org/var/git/opensim

remotes/origin/0.6.7-post-fixes
Justin Clark-Casey (justincc) 2009-09-24 17:35:03 +01:00
commit ad753d784c
24 changed files with 2290 additions and 346 deletions

View File

@ -40,6 +40,7 @@ namespace OpenSim.Data.Null
public NullRegionData(string connectionString, string realm)
{
//Console.WriteLine("[XXX] NullRegionData constructor");
}
public List<RegionData> Get(string regionName, UUID scopeID)

View File

@ -64,6 +64,13 @@ namespace OpenSim.Framework
}
protected string m_serverURI;
public string RegionName
{
get { return m_regionName; }
set { m_regionName = value; }
}
protected string m_regionName = String.Empty;
protected bool Allow_Alternate_Ports;
public bool m_allow_alternate_ports;
protected string m_externalHostName;
@ -101,6 +108,7 @@ namespace OpenSim.Framework
public SimpleRegionInfo(RegionInfo ConvertFrom)
{
m_regionName = ConvertFrom.RegionName;
m_regionLocX = ConvertFrom.RegionLocX;
m_regionLocY = ConvertFrom.RegionLocY;
m_internalEndPoint = ConvertFrom.InternalEndPoint;
@ -284,7 +292,6 @@ namespace OpenSim.Framework
public UUID originRegionID = UUID.Zero;
public string proxyUrl = "";
public int ProxyOffset = 0;
public string RegionName = String.Empty;
public string regionSecret = UUID.Random().ToString();
public string osSecret;

View File

@ -70,6 +70,39 @@ namespace OpenSim.Framework
public static readonly Regex UUIDPattern
= new Regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
/// <summary>
/// Linear interpolates B<->C using percent A
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
/// <returns></returns>
public static double lerp(double a, double b, double c)
{
return (b*a) + (c*(1 - a));
}
/// <summary>
/// Bilinear Interpolate, see Lerp but for 2D using 'percents' X & Y.
/// Layout:
/// A B
/// C D
/// A<->C = Y
/// C<->D = X
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
/// <param name="d"></param>
/// <returns></returns>
public static double lerp2D(double x, double y, double a, double b, double c, double d)
{
return lerp(y, lerp(x, a, b), lerp(x, c, d));
}
/// <value>
/// Well known UUID for the blank texture used in the Linden SL viewer version 1.20 (and hopefully onwards)
/// </value>

View File

@ -38,11 +38,15 @@
<RegionModule id="RemoteLandServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Land.RemoteLandServicesConnector" />
<RegionModule id="LocalInterregionComms" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion.LocalInterregionComms" />
<RegionModule id="RESTInterregionComms" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion.RESTInterregionComms" />
<RegionModule id="LocalGridServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.LocalGridServicesConnector" />
<RegionModule id="RemoteGridServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.RemoteGridServicesConnector" />
<RegionModule id="HGGridConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.HGGridConnector" />
<!-- Service connectors IN modules -->
<RegionModule id="AssetServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Asset.AssetServiceInConnectorModule" />
<RegionModule id="InventoryServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Inventory.InventoryServiceInConnectorModule" />
<RegionModule id="LandServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Land.LandServiceInConnectorModule" />
<RegionModule id="NeighbourServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Neighbour.NeighbourServiceInConnectorModule" /> \
<RegionModule id="HypergridServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid.HypergridServiceInConnectorModule" /> \
</Extension>

View File

@ -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.Grid;
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;
HypergridServiceInConnector 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;
if (!m_Registered)
{
m_Registered = true;
m_log.Info("[HypergridService]: Starting...");
Object[] args = new Object[] { m_Config, MainServer.Instance };
m_HypergridHandler = new HypergridServiceInConnector(m_Config, MainServer.Instance);
//ServerUtils.LoadPlugin<HypergridServiceInConnector>("OpenSim.Server.Handlers.dll:HypergridServiceInConnector", args);
}
SimpleRegionInfo rinfo = new SimpleRegionInfo(scene.RegionInfo);
m_HypergridHandler.AddRegion(rinfo);
}
public void RemoveRegion(Scene scene)
{
if (!m_Enabled)
return;
SimpleRegionInfo rinfo = new SimpleRegionInfo(scene.RegionInfo);
m_HypergridHandler.RemoveRegion(rinfo);
}
public void RegionLoaded(Scene scene)
{
}
#endregion
}
}

View File

@ -0,0 +1,303 @@
/*
* 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<string> args = new List<string>(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("linkk-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("linkk-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("unlinkk-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 <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]");
m_log.Info("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]");
m_log.Info("Usage: link-region <URI_of_xml> [<exclude>]");
}
private void UnlinkRegionCmdUsage()
{
m_log.Info("Usage: unlink-region <HostName>:<HttpPort>");
m_log.Info("Usage: unlink-region <LocalName>");
}
}
}

View File

@ -0,0 +1,560 @@
/*
* 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.Net;
using System.Reflection;
using System.Xml;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.Framework.Scenes.Hypergrid;
using OpenSim.Services.Interfaces;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
using OpenSim.Server.Base;
using OpenSim.Services.Connectors.Grid;
using OpenSim.Framework.Console;
using OpenMetaverse;
using log4net;
using Nini.Config;
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
{
public class HGGridConnector : ISharedRegionModule, IGridService
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private bool m_Enabled = false;
private bool m_Initialized = false;
private IGridService m_GridServiceConnector;
private HypergridServiceConnector m_HypergridServiceConnector;
// Hyperlink regions are hyperlinks on the map
protected Dictionary<UUID, GridRegion> m_HyperlinkRegions = new Dictionary<UUID, GridRegion>();
// 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<UUID, GridRegion> m_knownRegions = new Dictionary<UUID, GridRegion>();
protected Dictionary<UUID, ulong> m_HyperlinkHandles = new Dictionary<UUID, ulong>();
#region ISharedRegionModule
public Type ReplaceableInterface
{
get { return null; }
}
public string Name
{
get { return "HGGridServicesConnector"; }
}
public void Initialise(IConfigSource source)
{
IConfig moduleConfig = source.Configs["Modules"];
if (moduleConfig != null)
{
string name = moduleConfig.GetString("GridServices", "");
if (name == Name)
{
IConfig gridConfig = source.Configs["GridService"];
if (gridConfig == null)
{
m_log.Error("[HGGRID CONNECTOR]: GridService missing from OpenSim.ini");
return;
}
InitialiseConnectorModule(source);
m_Enabled = true;
m_log.Info("[HGGRID CONNECTOR]: HG grid enabled");
}
}
}
private void InitialiseConnectorModule(IConfigSource source)
{
IConfig gridConfig = source.Configs["GridService"];
if (gridConfig == null)
{
m_log.Error("[HGGRID CONNECTOR]: GridService missing from OpenSim.ini");
throw new Exception("Grid connector init error");
}
string module = gridConfig.GetString("GridServiceConnectorModule", String.Empty);
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<IGridService>(module, args);
}
public void PostInitialise()
{
}
public void Close()
{
}
public void AddRegion(Scene scene)
{
if (!m_Enabled)
return;
scene.RegisterModuleInterface<IGridService>(this);
}
public void RemoveRegion(Scene scene)
{
}
public void RegionLoaded(Scene scene)
{
if (!m_Enabled)
return;
if (!m_Initialized)
{
m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService);
HGCommands hgCommands = new HGCommands(this, scene);
MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "linkk-region",
"link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>",
"Link a hypergrid region", hgCommands.RunCommand);
MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "unlinkk-region",
"unlink-region <local name> or <HostName>:<HttpPort> <cr>",
"Unlink a hypergrid region", hgCommands.RunCommand);
MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "linkk-mapping", "link-mapping [<x> <y>] <cr>",
"Set local coordinate to map HG regions to", hgCommands.RunCommand);
m_Initialized = true;
}
//scene.AddCommand("HGGridServicesConnector", "linkk-region",
// "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>",
// "Link a hypergrid region", hgCommands.RunCommand);
//scene.AddCommand("HGGridServicesConnector", "unlinkk-region",
// "unlink-region <local name> or <HostName>:<HttpPort> <cr>",
// "Unlink a hypergrid region", hgCommands.RunCommand);
//scene.AddCommand("HGGridServicesConnector", "linkk-mapping", "link-mapping [<x> <y>] <cr>",
// "Set local coordinate to map HG regions to", hgCommands.RunCommand);
}
#endregion
#region IGridService
public bool 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 true;
}
else
{
m_log.Info("[HGrid]: No such region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort + "(" + regionInfo.InternalEndPoint.Port + ")");
return false;
}
// 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);
}
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);
}
public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
{
// No serving neighbours on hyperliked regions.
// Just the regular regions.
return m_GridServiceConnector.GetNeighbours(scopeID, regionID);
}
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 m_knownRegions[regionID];
// Finally, try the normal route
return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID);
}
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;
}
// Finally, try the normal route
return m_GridServiceConnector.GetRegionByPosition(scopeID, x, y);
}
public GridRegion GetRegionByName(UUID scopeID, string regionName)
{
// Try normal grid first
GridRegion region = m_GridServiceConnector.GetRegionByName(scopeID, regionName);
if (region != null)
return region;
// Try the hyperlink collection
foreach (GridRegion r in m_HyperlinkRegions.Values)
{
if (r.RegionName == regionName)
return r;
}
// Try the foreign users home collection
foreach (GridRegion r in m_knownRegions.Values)
{
if (r.RegionName == regionName)
return r;
}
return null;
}
public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
{
List<GridRegion> rinfos = new List<GridRegion>();
// Commenting until regionname exists
//foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values)
// if ((r.RegionName != null) && r.RegionName.StartsWith(name))
// rinfos.Add(r);
rinfos.AddRange(m_GridServiceConnector.GetRegionsByName(scopeID, name, maxNumber));
return rinfos;
}
public List<GridRegion> 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 snapYmin = (int)(ymin / Constants.RegionSize) * (int)Constants.RegionSize;
int snapYmax = (int)(ymax / Constants.RegionSize) * (int)Constants.RegionSize;
List<GridRegion> rinfos = new List<GridRegion>();
foreach (GridRegion r in m_HyperlinkRegions.Values)
if ((r.RegionLocX > snapXmin) && (r.RegionLocX < snapYmax) &&
(r.RegionLocY > snapYmin) && (r.RegionLocY < snapYmax))
rinfos.Add(r);
rinfos.AddRange(m_GridServiceConnector.GetRegionRange(scopeID, xmin, xmax, ymin, ymax));
return rinfos;
}
#endregion
#region Auxiliary
private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle)
{
m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo);
m_HyperlinkHandles.Add(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.Add(userID, regionInfo);
m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle);
}
private void RemoveHyperlinkHomeRegion(UUID regionID)
{
foreach (KeyValuePair<UUID, GridRegion> kvp in m_knownRegions)
{
if (kvp.Value.RegionID == regionID)
{
m_knownRegions.Remove(kvp.Key);
}
}
m_HyperlinkHandles.Remove(regionID);
}
#endregion
#region Hyperlinks
private static Random random = new Random();
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];
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);
return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0);
}
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
try
{
RegisterRegion(UUID.Zero, regInfo);
}
catch (Exception e)
{
m_log.Warn("[HGrid]: Unable to link region: " + e.Message);
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;
}
}
/// <summary>
/// Cope with this viewer limitation.
/// </summary>
/// <param name="regInfo"></param>
/// <returns></returns>
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 / Constants.RegionSize) - x) >= 4096) ||
(Math.Abs((int)(m_scene.RegionInfo.RegionLocY / Constants.RegionSize) - 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;
}
#endregion
}
}

View File

@ -35,6 +35,7 @@ using OpenSim.Server.Base;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
using OpenMetaverse;
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
@ -50,6 +51,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
private bool m_Enabled = false;
public LocalGridServicesConnector()
{
}
public LocalGridServicesConnector(IConfigSource source)
{
m_log.Debug("[LOCAL GRID CONNECTOR]: LocalGridServicesConnector instantiated");
InitialiseService(source);
}
#region ISharedRegionModule
public Type ReplaceableInterface
@ -70,38 +81,43 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
string name = moduleConfig.GetString("GridServices", "");
if (name == Name)
{
IConfig assetConfig = source.Configs["GridService"];
if (assetConfig == null)
{
m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini");
return;
}
string serviceDll = assetConfig.GetString("LocalServiceModule",
String.Empty);
if (serviceDll == String.Empty)
{
m_log.Error("[GRID CONNECTOR]: No LocalServiceModule named in section GridService");
return;
}
Object[] args = new Object[] { source };
m_GridService =
ServerUtils.LoadPlugin<IGridService>(serviceDll,
args);
if (m_GridService == null)
{
m_log.Error("[GRID CONNECTOR]: Can't load asset service");
return;
}
InitialiseService(source);
m_Enabled = true;
m_log.Info("[GRID CONNECTOR]: Local grid connector enabled");
m_log.Info("[LOCAL GRID CONNECTOR]: Local grid connector enabled");
}
}
}
private void InitialiseService(IConfigSource source)
{
IConfig assetConfig = source.Configs["GridService"];
if (assetConfig == null)
{
m_log.Error("[LOCAL GRID CONNECTOR]: GridService missing from OpenSim.ini");
return;
}
string serviceDll = assetConfig.GetString("LocalServiceModule",
String.Empty);
if (serviceDll == String.Empty)
{
m_log.Error("[LOCAL GRID CONNECTOR]: No LocalServiceModule named in section GridService");
return;
}
Object[] args = new Object[] { source };
m_GridService =
ServerUtils.LoadPlugin<IGridService>(serviceDll,
args);
if (m_GridService == null)
{
m_log.Error("[LOCAL GRID CONNECTOR]: Can't load grid service");
return;
}
}
public void PostInitialise()
{
}
@ -130,7 +146,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
#region IGridService
public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo)
public bool RegisterRegion(UUID scopeID, GridRegion regionInfo)
{
return m_GridService.RegisterRegion(scopeID, regionInfo);
}
@ -140,32 +156,32 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
return m_GridService.DeregisterRegion(regionID);
}
public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID)
public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
{
return m_GridService.GetNeighbours(scopeID, regionID);
}
public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID)
public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
{
return m_GridService.GetRegionByUUID(scopeID, regionID);
}
public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y)
public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
{
return m_GridService.GetRegionByPosition(scopeID, x, y);
}
public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName)
public GridRegion GetRegionByName(UUID scopeID, string regionName)
{
return m_GridService.GetRegionByName(scopeID, regionName);
}
public List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber)
public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
{
return m_GridService.GetRegionsByName(scopeID, name, maxNumber);
}
public List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
{
return m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
}

View File

@ -0,0 +1,183 @@
/*
* 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 log4net;
using System;
using System.Collections.Generic;
using System.Reflection;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Services.Connectors;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
{
public class RemoteGridServicesConnector :
GridServicesConnector, ISharedRegionModule, IGridService
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private bool m_Enabled = false;
private IGridService m_LocalGridService;
public RemoteGridServicesConnector()
{
}
public RemoteGridServicesConnector(IConfigSource source)
{
InitialiseServices(source);
}
#region ISharedRegionmodule
public Type ReplaceableInterface
{
get { return null; }
}
public string Name
{
get { return "RemoteGridServicesConnector"; }
}
public override void Initialise(IConfigSource source)
{
IConfig moduleConfig = source.Configs["Modules"];
if (moduleConfig != null)
{
string name = moduleConfig.GetString("GridServices", "");
if (name == Name)
{
InitialiseServices(source);
m_Enabled = true;
m_log.Info("[REMOTE GRID CONNECTOR]: Remote grid enabled");
}
}
}
private void InitialiseServices(IConfigSource source)
{
IConfig gridConfig = source.Configs["GridService"];
if (gridConfig == null)
{
m_log.Error("[REMOTE GRID CONNECTOR]: GridService missing from OpenSim.ini");
return;
}
base.Initialise(source);
m_LocalGridService = new LocalGridServicesConnector(source);
}
public void PostInitialise()
{
}
public void Close()
{
}
public void AddRegion(Scene scene)
{
if (!m_Enabled)
return;
scene.RegisterModuleInterface<IGridService>(this);
}
public void RemoveRegion(Scene scene)
{
}
public void RegionLoaded(Scene scene)
{
}
#endregion
#region IGridService
public override bool RegisterRegion(UUID scopeID, GridRegion regionInfo)
{
if (m_LocalGridService.RegisterRegion(scopeID, regionInfo))
return base.RegisterRegion(scopeID, regionInfo);
return false;
}
public override bool DeregisterRegion(UUID regionID)
{
if (m_LocalGridService.DeregisterRegion(regionID))
return base.DeregisterRegion(regionID);
return false;
}
// Let's not override GetNeighbours -- let's get them all from the grid server
public override GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
{
GridRegion rinfo = m_LocalGridService.GetRegionByUUID(scopeID, regionID);
if (rinfo == null)
rinfo = base.GetRegionByUUID(scopeID, regionID);
return rinfo;
}
public override GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
{
GridRegion rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y);
if (rinfo == null)
rinfo = base.GetRegionByPosition(scopeID, x, y);
return rinfo;
}
public override GridRegion GetRegionByName(UUID scopeID, string regionName)
{
GridRegion rinfo = m_LocalGridService.GetRegionByName(scopeID, regionName);
if (rinfo == null)
rinfo = base.GetRegionByName(scopeID, regionName);
return rinfo;
}
// Let's not override GetRegionsByName -- let's get them all from the grid server
// Let's not override GetRegionRange -- let's get them all from the grid server
#endregion
}
}

View File

@ -0,0 +1,131 @@
/*
* 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.IO;
using System.Reflection;
using System.Threading;
using log4net.Config;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using OpenMetaverse;
using OpenSim.Framework;
using Nini.Config;
using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
using OpenSim.Region.Framework.Scenes;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
using OpenSim.Tests.Common;
using OpenSim.Tests.Common.Setup;
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests
{
[TestFixture]
public class GridConnectorsTests
{
LocalGridServicesConnector m_LocalConnector;
private void SetUp()
{
IConfigSource config = new IniConfigSource();
config.AddConfig("Modules");
config.AddConfig("GridService");
config.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector");
config.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService");
config.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData");
m_LocalConnector = new LocalGridServicesConnector(config);
}
/// <summary>
/// Test saving a V0.2 OpenSim Region Archive.
/// </summary>
[Test]
public void TestRegisterRegionV0_2()
{
SetUp();
// Create 3 regions
GridRegion r1 = new GridRegion();
r1.RegionName = "Test Region 1";
r1.RegionID = new UUID(1);
r1.RegionLocX = 1000 * (int)Constants.RegionSize;
r1.RegionLocY = 1000 * (int)Constants.RegionSize;
r1.ExternalHostName = "127.0.0.1";
r1.HttpPort = 9001;
r1.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
GridRegion r2 = new GridRegion();
r2.RegionName = "Test Region 2";
r2.RegionID = new UUID(2);
r2.RegionLocX = 1001 * (int)Constants.RegionSize;
r2.RegionLocY = 1000 * (int)Constants.RegionSize;
r2.ExternalHostName = "127.0.0.1";
r2.HttpPort = 9002;
r2.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
GridRegion r3 = new GridRegion();
r3.RegionName = "Test Region 3";
r3.RegionID = new UUID(3);
r3.RegionLocX = 1005 * (int)Constants.RegionSize;
r3.RegionLocY = 1000 * (int)Constants.RegionSize;
r3.ExternalHostName = "127.0.0.1";
r3.HttpPort = 9003;
r3.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
m_LocalConnector.RegisterRegion(UUID.Zero, r1);
GridRegion result = m_LocalConnector.GetRegionByName(UUID.Zero, "Test");
Assert.IsNotNull(result, "Retrieved GetRegionByName is null");
Assert.That(result.RegionName, Is.EqualTo("Test Region 1"), "Retrieved region's name does not match");
result = m_LocalConnector.GetRegionByUUID(UUID.Zero, new UUID(1));
Assert.IsNotNull(result, "Retrieved GetRegionByUUID is null");
Assert.That(result.RegionID, Is.EqualTo(new UUID(1)), "Retrieved region's UUID does not match");
result = m_LocalConnector.GetRegionByPosition(UUID.Zero, 1000 * (int)Constants.RegionSize, 1000 * (int)Constants.RegionSize);
Assert.IsNotNull(result, "Retrieved GetRegionByPosition is null");
Assert.That(result.RegionLocX, Is.EqualTo(1000 * (int)Constants.RegionSize), "Retrieved region's position does not match");
m_LocalConnector.RegisterRegion(UUID.Zero, r2);
m_LocalConnector.RegisterRegion(UUID.Zero, r3);
List<GridRegion> results = m_LocalConnector.GetNeighbours(UUID.Zero, new UUID(1));
Assert.IsNotNull(results, "Retrieved neighbours list is null");
Assert.That(results.Count, Is.EqualTo(1), "Retrieved neighbour collection is greater than expected");
Assert.That(results[0].RegionID, Is.EqualTo(new UUID(2)), "Retrieved region's UUID does not match");
results = m_LocalConnector.GetRegionsByName(UUID.Zero, "Test", 10);
Assert.IsNotNull(results, "Retrieved GetRegionsByName list is null");
Assert.That(results.Count, Is.EqualTo(3), "Retrieved neighbour collection is less than expected");
results = m_LocalConnector.GetRegionRange(UUID.Zero, 900 * (int)Constants.RegionSize, 1002 * (int)Constants.RegionSize,
900 * (int)Constants.RegionSize, 1100 * (int)Constants.RegionSize);
Assert.IsNotNull(results, "Retrieved GetRegionRange list is null");
Assert.That(results.Count, Is.EqualTo(2), "Retrieved neighbour collection is not the number expected");
}
}
}

View File

@ -33,7 +33,6 @@ using log4net;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Region.CoreModules.World.Terrain;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
@ -47,7 +46,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
private Scene m_scene;
private EstateTerrainXferHandler TerrainUploader = null;
private EstateTerrainXferHandler TerrainUploader;
#region Packet Data Responders
@ -155,6 +154,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
break;
}
m_scene.RegionInfo.RegionSettings.Save();
sendRegionInfoPacketToAll();
}
public void setEstateTerrainTextureHeights(IClientAPI client, int corner, float lowValue, float highValue)
@ -179,6 +179,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
break;
}
m_scene.RegionInfo.RegionSettings.Save();
sendRegionInfoPacketToAll();
}
private void handleCommitEstateTerrainTextureRequest(IClientAPI remoteClient)
@ -668,7 +669,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
LookupUUID(uuidNameLookupList);
}
private void LookupUUIDSCompleted(IAsyncResult iar)
private static void LookupUUIDSCompleted(IAsyncResult iar)
{
LookupUUIDS icon = (LookupUUIDS)iar.AsyncState;
icon.EndInvoke(iar);
@ -683,7 +684,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
}
private void LookupUUIDsAsync(List<UUID> uuidLst)
{
UUID[] uuidarr = new UUID[0];
UUID[] uuidarr;
lock (uuidLst)
{
@ -707,7 +708,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
for (int i = 0; i < avatars.Count; i++)
{
HandleRegionInfoRequest(avatars[i].ControllingClient); ;
HandleRegionInfoRequest(avatars[i].ControllingClient);
}
}
@ -768,7 +769,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
else
{
m_scene.RegionInfo.EstateSettings.UseGlobalTime = false;
m_scene.RegionInfo.EstateSettings.SunPosition = (double)(parms2 - 0x1800)/1024.0;
m_scene.RegionInfo.EstateSettings.SunPosition = (parms2 - 0x1800)/1024.0;
}
if ((parms1 & 0x00000010) != 0)
@ -828,8 +829,60 @@ namespace OpenSim.Region.CoreModules.World.Estate
m_scene.RegisterModuleInterface<IEstateModule>(this);
m_scene.EventManager.OnNewClient += EventManager_OnNewClient;
m_scene.EventManager.OnRequestChangeWaterHeight += changeWaterHeight;
m_scene.AddCommand(this, "set terrain texture",
"set terrain texture <number> <uuid> [<x>] [<y>]",
"Sets the terrain <number> to <uuid>, if <x> or <y> are specified, it will only " +
"set it on regions with a matching coordinate. Specify -1 in <x> or <y> to wildcard" +
" that coordinate.",
consoleSetTerrainTexture);
m_scene.AddCommand(this, "set terrain heights",
"set terrain heights <corner> <min> <max> [<x>] [<y>]",
"Sets the terrain texture heights on corner #<corner> to <min>/<max>, if <x> or <y> are specified, it will only " +
"set it on regions with a matching coordinate. Specify -1 in <x> or <y> to wildcard" +
" that coordinate. Corner # SW = 0, NW = 1, SE = 2, NE = 3.",
consoleSetTerrainHeights);
}
#region Console Commands
public void consoleSetTerrainTexture(string module, string[] args)
{
string num = args[3];
string uuid = args[4];
int x = (args.Length > 5 ? int.Parse(args[5]) : -1);
int y = (args.Length > 6 ? int.Parse(args[6]) : -1);
if (x == -1 || m_scene.RegionInfo.RegionLocX == x)
{
if (y == -1 || m_scene.RegionInfo.RegionLocY == y)
{
m_log.Debug("[ESTATEMODULE] Setting terrain textures for " + m_scene.RegionInfo.RegionName);
setEstateTerrainBaseTexture(null, int.Parse(num), UUID.Parse(uuid));
}
}
}
public void consoleSetTerrainHeights(string module, string[] args)
{
string num = args[3];
string min = args[4];
string max = args[5];
int x = (args.Length > 6 ? int.Parse(args[6]) : -1);
int y = (args.Length > 7 ? int.Parse(args[7]) : -1);
if (x == -1 || m_scene.RegionInfo.RegionLocX == x)
{
if (y == -1 || m_scene.RegionInfo.RegionLocY == y)
{
m_log.Debug("[ESTATEMODULE] Setting terrain heights " + m_scene.RegionInfo.RegionName);
setEstateTerrainTextureHeights(null, int.Parse(num), float.Parse(min), float.Parse(max));
}
}
}
#endregion
public void PostInitialise()
{

View File

@ -49,7 +49,7 @@ namespace OpenSim.Server.Handlers.Grid
String.Empty);
if (gridService == String.Empty)
throw new Exception("No AuthenticationService in config file");
throw new Exception("No GridService in config file");
Object[] args = new Object[] { config };
m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);

View File

@ -38,6 +38,7 @@ using System.Xml.Serialization;
using System.Collections.Generic;
using OpenSim.Server.Base;
using OpenSim.Services.Interfaces;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
using OpenSim.Framework;
using OpenSim.Framework.Servers.HttpServer;
using OpenMetaverse;
@ -117,7 +118,7 @@ namespace OpenSim.Server.Handlers.Grid
Dictionary<string, object> rinfoData = new Dictionary<string, object>();
foreach (KeyValuePair<string, string> kvp in request)
rinfoData[kvp.Key] = kvp.Value;
SimpleRegionInfo rinfo = new SimpleRegionInfo(rinfoData);
GridRegion rinfo = new GridRegion(rinfoData);
bool result = m_GridService.RegisterRegion(scopeID, rinfo);
@ -158,11 +159,11 @@ namespace OpenSim.Server.Handlers.Grid
else
m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
List<SimpleRegionInfo> rinfos = m_GridService.GetNeighbours(scopeID, regionID);
List<GridRegion> rinfos = m_GridService.GetNeighbours(scopeID, regionID);
Dictionary<string, object> result = new Dictionary<string, object>();
int i = 0;
foreach (SimpleRegionInfo rinfo in rinfos)
foreach (GridRegion rinfo in rinfos)
{
Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
result["region" + i] = rinfoDict;

View File

@ -0,0 +1,112 @@
/*
* 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;
using System.Collections.Generic;
using System.Reflection;
using System.Net;
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;
namespace OpenSim.Server.Handlers.Grid
{
public class HypergridServiceInConnector : ServiceConnector
{
private static readonly ILog m_log =
LogManager.GetLogger(
MethodBase.GetCurrentMethod().DeclaringType);
private List<SimpleRegionInfo> m_RegionsOnSim = new List<SimpleRegionInfo>();
public HypergridServiceInConnector(IConfigSource config, IHttpServer server) :
base(config, server)
{
server.AddXmlRPCHandler("linkk_region", LinkRegionRequest, false);
}
/// <summary>
/// Someone wants to link to us
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public XmlRpcResponse LinkRegionRequest(XmlRpcRequest request, IPEndPoint remoteClient)
{
Hashtable requestData = (Hashtable)request.Params[0];
//string host = (string)requestData["host"];
//string portstr = (string)requestData["port"];
string name = (string)requestData["region_name"];
m_log.DebugFormat("[HGrid]: Hyperlink request");
SimpleRegionInfo regInfo = null;
foreach (SimpleRegionInfo r in m_RegionsOnSim)
{
if ((r.RegionName != null) && (name != null) && (r.RegionName.ToLower() == name.ToLower()))
{
regInfo = r;
break;
}
}
if (regInfo == null)
regInfo = m_RegionsOnSim[0]; // Send out the first region
Hashtable hash = new Hashtable();
hash["uuid"] = regInfo.RegionID.ToString();
hash["handle"] = regInfo.RegionHandle.ToString();
//m_log.Debug(">> Here " + regInfo.RegionHandle);
//hash["region_image"] = regInfo.RegionSettings.TerrainImageID.ToString();
hash["region_name"] = regInfo.RegionName;
hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString();
//m_log.Debug(">> Here: " + regInfo.InternalEndPoint.Port);
XmlRpcResponse response = new XmlRpcResponse();
response.Value = hash;
return response;
}
public void AddRegion(SimpleRegionInfo rinfo)
{
m_RegionsOnSim.Add(rinfo);
}
public void RemoveRegion(SimpleRegionInfo rinfo)
{
if (m_RegionsOnSim.Contains(rinfo))
m_RegionsOnSim.Remove(rinfo);
}
}
}

View File

@ -35,6 +35,7 @@ using OpenSim.Framework;
using OpenSim.Framework.Communications;
using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Services.Interfaces;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
using OpenSim.Server.Base;
using OpenMetaverse;
@ -85,7 +86,7 @@ namespace OpenSim.Services.Connectors
#region IGridService
public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo)
public virtual bool RegisterRegion(UUID scopeID, GridRegion regionInfo)
{
Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs();
Dictionary<string, string> sendData = new Dictionary<string,string>();
@ -108,7 +109,7 @@ namespace OpenSim.Services.Connectors
return false;
}
public bool DeregisterRegion(UUID regionID)
public virtual bool DeregisterRegion(UUID regionID)
{
Dictionary<string, string> sendData = new Dictionary<string, string>();
@ -128,7 +129,7 @@ namespace OpenSim.Services.Connectors
return false;
}
public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID)
public virtual List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
{
Dictionary<string, string> sendData = new Dictionary<string, string>();
@ -143,7 +144,7 @@ namespace OpenSim.Services.Connectors
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
List<GridRegion> rinfos = new List<GridRegion>();
if (replyData != null)
{
Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
@ -151,7 +152,7 @@ namespace OpenSim.Services.Connectors
{
if (r is Dictionary<string, object>)
{
SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r);
GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
rinfos.Add(rinfo);
}
else
@ -166,7 +167,7 @@ namespace OpenSim.Services.Connectors
return rinfos;
}
public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID)
public virtual GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
{
Dictionary<string, string> sendData = new Dictionary<string, string>();
@ -181,11 +182,11 @@ namespace OpenSim.Services.Connectors
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
SimpleRegionInfo rinfo = null;
GridRegion rinfo = null;
if ((replyData != null) && (replyData["result"] != null))
{
if (replyData["result"] is Dictionary<string, object>)
rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]);
rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
else
m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received invalid response",
scopeID, regionID);
@ -197,7 +198,7 @@ namespace OpenSim.Services.Connectors
return rinfo;
}
public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y)
public virtual GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
{
Dictionary<string, string> sendData = new Dictionary<string, string>();
@ -213,11 +214,11 @@ namespace OpenSim.Services.Connectors
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
SimpleRegionInfo rinfo = null;
GridRegion rinfo = null;
if ((replyData != null) && (replyData["result"] != null))
{
if (replyData["result"] is Dictionary<string, object>)
rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]);
rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
else
m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received invalid response",
scopeID, x, y);
@ -229,7 +230,7 @@ namespace OpenSim.Services.Connectors
return rinfo;
}
public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName)
public virtual GridRegion GetRegionByName(UUID scopeID, string regionName)
{
Dictionary<string, string> sendData = new Dictionary<string, string>();
@ -244,11 +245,11 @@ namespace OpenSim.Services.Connectors
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
SimpleRegionInfo rinfo = null;
GridRegion rinfo = null;
if ((replyData != null) && (replyData["result"] != null))
{
if (replyData["result"] is Dictionary<string, object>)
rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]);
rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
else
m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received invalid response",
scopeID, regionName);
@ -260,7 +261,7 @@ namespace OpenSim.Services.Connectors
return rinfo;
}
public List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber)
public virtual List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
{
Dictionary<string, string> sendData = new Dictionary<string, string>();
@ -276,7 +277,7 @@ namespace OpenSim.Services.Connectors
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
List<GridRegion> rinfos = new List<GridRegion>();
if (replyData != null)
{
Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
@ -284,7 +285,7 @@ namespace OpenSim.Services.Connectors
{
if (r is Dictionary<string, object>)
{
SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r);
GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
rinfos.Add(rinfo);
}
else
@ -299,7 +300,7 @@ namespace OpenSim.Services.Connectors
return rinfos;
}
public List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
public virtual List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
{
Dictionary<string, string> sendData = new Dictionary<string, string>();
@ -317,7 +318,7 @@ namespace OpenSim.Services.Connectors
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
List<GridRegion> rinfos = new List<GridRegion>();
if (replyData != null)
{
Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
@ -325,7 +326,7 @@ namespace OpenSim.Services.Connectors
{
if (r is Dictionary<string, object>)
{
SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r);
GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
rinfos.Add(rinfo);
}
else

View File

@ -0,0 +1,152 @@
/*
* 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;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Net;
using System.Reflection;
using OpenSim.Services.Interfaces;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
using OpenSim.Framework;
using OpenMetaverse;
using OpenMetaverse.Imaging;
using log4net;
using Nwc.XmlRpc;
namespace OpenSim.Services.Connectors.Grid
{
public class HypergridServiceConnector
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IAssetService m_AssetService;
public HypergridServiceConnector(IAssetService assService)
{
m_AssetService = assService;
}
public UUID LinkRegion(GridRegion info, out ulong realHandle)
{
UUID uuid = UUID.Zero;
realHandle = 0;
Hashtable hash = new Hashtable();
hash["region_name"] = info.RegionName;
IList paramList = new ArrayList();
paramList.Add(hash);
XmlRpcRequest request = new XmlRpcRequest("linkk_region", paramList);
string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
m_log.Debug("[HGrid]: Linking to " + uri);
XmlRpcResponse response = request.Send(uri, 10000);
if (response.IsFault)
{
m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
}
else
{
hash = (Hashtable)response.Value;
//foreach (Object o in hash)
// m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
try
{
UUID.TryParse((string)hash["uuid"], out uuid);
info.RegionID = uuid;
if ((string)hash["handle"] != null)
{
realHandle = Convert.ToUInt64((string)hash["handle"]);
m_log.Debug(">> HERE, realHandle: " + realHandle);
}
//if (hash["region_image"] != null)
//{
// UUID img = UUID.Zero;
// UUID.TryParse((string)hash["region_image"], out img);
// info.RegionSettings.TerrainImageID = img;
//}
if (hash["region_name"] != null)
{
info.RegionName = (string)hash["region_name"];
//m_log.Debug(">> " + info.RegionName);
}
if (hash["internal_port"] != null)
{
int port = Convert.ToInt32((string)hash["internal_port"]);
info.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port);
//m_log.Debug(">> " + info.InternalEndPoint.ToString());
}
}
catch (Exception e)
{
m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace);
}
}
return uuid;
}
public void GetMapImage(GridRegion info)
{
try
{
string regionimage = "regionImage" + info.RegionID.ToString();
regionimage = regionimage.Replace("-", "");
WebClient c = new WebClient();
string uri = "http://" + info.ExternalHostName + ":" + info.HttpPort + "/index.php?method=" + regionimage;
//m_log.Debug("JPEG: " + uri);
c.DownloadFile(uri, info.RegionID.ToString() + ".jpg");
Bitmap m = new Bitmap(info.RegionID.ToString() + ".jpg");
//m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width);
byte[] imageData = OpenJPEG.EncodeFromImage(m, true);
AssetBase ass = new AssetBase(UUID.Random(), "region " + info.RegionID.ToString());
// !!! for now
//info.RegionSettings.TerrainImageID = ass.FullID;
ass.Type = (int)AssetType.Texture;
ass.Temporary = true;
ass.Local = true;
ass.Data = imageData;
m_AssetService.Store(ass);
}
catch // LEGIT: Catching problems caused by OpenJPEG p/invoke
{
m_log.Warn("[HGrid]: Failed getting/storing map image, because it is probably already in the cache");
}
}
}
}

View File

@ -35,6 +35,7 @@ using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Data;
using OpenSim.Services.Interfaces;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
using OpenMetaverse;
namespace OpenSim.Services.GridService
@ -48,6 +49,7 @@ namespace OpenSim.Services.GridService
public GridService(IConfigSource config)
: base(config)
{
m_log.DebugFormat("[GRID SERVICE]: Starting...");
MainConsole.Instance.Commands.AddCommand("kfs", false,
"show digest",
"show digest <ID>",
@ -62,14 +64,16 @@ namespace OpenSim.Services.GridService
#region IGridService
public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfos)
public bool RegisterRegion(UUID scopeID, GridRegion regionInfos)
{
if (m_Database.Get(regionInfos.RegionID, scopeID) != null)
{
m_log.WarnFormat("[GRID SERVICE]: Region {0} already registered in scope {1}.", regionInfos.RegionID, scopeID);
return false;
}
if (m_Database.Get((int)regionInfos.RegionLocX, (int)regionInfos.RegionLocY, scopeID) != null)
// This needs better sanity testing. What if regionInfo is registering in
// overlapping coords?
if (m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID) != null)
{
m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.",
regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID);
@ -88,22 +92,25 @@ namespace OpenSim.Services.GridService
return m_Database.Delete(regionID);
}
public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID)
public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
{
List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
List<GridRegion> rinfos = new List<GridRegion>();
RegionData region = m_Database.Get(regionID, scopeID);
if (region != null)
{
// Not really? Maybe?
List<RegionData> rdatas = m_Database.Get(region.posX - 1, region.posY - 1, region.posX + 1, region.posY + 1, scopeID);
List<RegionData> rdatas = m_Database.Get(region.posX - (int)Constants.RegionSize, region.posY - (int)Constants.RegionSize,
region.posX + (int)Constants.RegionSize, region.posY + (int)Constants.RegionSize, scopeID);
foreach (RegionData rdata in rdatas)
rinfos.Add(RegionData2RegionInfo(rdata));
if (rdata.RegionID != regionID)
rinfos.Add(RegionData2RegionInfo(rdata));
}
return rinfos;
}
public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID)
public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
{
RegionData rdata = m_Database.Get(regionID, scopeID);
if (rdata != null)
@ -112,16 +119,18 @@ namespace OpenSim.Services.GridService
return null;
}
public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y)
public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
{
RegionData rdata = m_Database.Get(x, y, scopeID);
int snapX = (int)(x / Constants.RegionSize) * (int)Constants.RegionSize;
int snapY = (int)(y / Constants.RegionSize) * (int)Constants.RegionSize;
RegionData rdata = m_Database.Get(snapX, snapY, scopeID);
if (rdata != null)
return RegionData2RegionInfo(rdata);
return null;
}
public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName)
public GridRegion GetRegionByName(UUID scopeID, string regionName)
{
List<RegionData> rdatas = m_Database.Get(regionName + "%", scopeID);
if ((rdatas != null) && (rdatas.Count > 0))
@ -130,12 +139,12 @@ namespace OpenSim.Services.GridService
return null;
}
public List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber)
public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
{
List<RegionData> rdatas = m_Database.Get("%" + name + "%", scopeID);
int count = 0;
List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
List<GridRegion> rinfos = new List<GridRegion>();
if (rdatas != null)
{
@ -149,10 +158,15 @@ namespace OpenSim.Services.GridService
return rinfos;
}
public List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
{
List<RegionData> rdatas = m_Database.Get(xmin, ymin, xmax, ymax, scopeID);
List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
int xminSnap = (int)(xmin / Constants.RegionSize) * (int)Constants.RegionSize;
int xmaxSnap = (int)(xmax / Constants.RegionSize) * (int)Constants.RegionSize;
int yminSnap = (int)(ymin / Constants.RegionSize) * (int)Constants.RegionSize;
int ymaxSnap = (int)(ymax / Constants.RegionSize) * (int)Constants.RegionSize;
List<RegionData> rdatas = m_Database.Get(xminSnap, yminSnap, xmaxSnap, ymaxSnap, scopeID);
List<GridRegion> rinfos = new List<GridRegion>();
foreach (RegionData rdata in rdatas)
rinfos.Add(RegionData2RegionInfo(rdata));
@ -163,25 +177,25 @@ namespace OpenSim.Services.GridService
#region Data structure conversions
protected RegionData RegionInfo2RegionData(SimpleRegionInfo rinfo)
protected RegionData RegionInfo2RegionData(GridRegion rinfo)
{
RegionData rdata = new RegionData();
rdata.posX = (int)rinfo.RegionLocX;
rdata.posY = (int)rinfo.RegionLocY;
rdata.RegionID = rinfo.RegionID;
rdata.Data = rinfo.ToKeyValuePairs();
//rdata.RegionName = rinfo.RegionName;
rdata.RegionName = rinfo.RegionName;
return rdata;
}
protected SimpleRegionInfo RegionData2RegionInfo(RegionData rdata)
protected GridRegion RegionData2RegionInfo(RegionData rdata)
{
SimpleRegionInfo rinfo = new SimpleRegionInfo(rdata.Data);
rinfo.RegionLocX = (uint)rdata.posX;
rinfo.RegionLocY = (uint)rdata.posY;
GridRegion rinfo = new GridRegion(rdata.Data);
rinfo.RegionLocX = rdata.posX;
rinfo.RegionLocY = rdata.posY;
rinfo.RegionID = rdata.RegionID;
//rinfo.RegionName = rdata.RegionName;
rinfo.RegionName = rdata.RegionName;
return rinfo;
}

View File

@ -25,8 +25,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using OpenSim.Framework;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using OpenSim.Framework;
using OpenMetaverse;
namespace OpenSim.Services.Interfaces
@ -39,7 +42,7 @@ namespace OpenSim.Services.Interfaces
/// <param name="regionInfos"> </param>
/// <returns></returns>
/// <exception cref="System.Exception">Thrown if region registration failed</exception>
bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfos);
bool RegisterRegion(UUID scopeID, GridRegion regionInfos);
/// <summary>
/// Deregister a region with the grid service.
@ -55,9 +58,9 @@ namespace OpenSim.Services.Interfaces
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID);
List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID);
SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID);
GridRegion GetRegionByUUID(UUID scopeID, UUID regionID);
/// <summary>
/// Get the region at the given position (in meters)
@ -66,9 +69,9 @@ namespace OpenSim.Services.Interfaces
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y);
GridRegion GetRegionByPosition(UUID scopeID, int x, int y);
SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName);
GridRegion GetRegionByName(UUID scopeID, string regionName);
/// <summary>
/// Get information about regions starting with the provided name.
@ -83,9 +86,237 @@ namespace OpenSim.Services.Interfaces
/// A list of <see cref="RegionInfo"/>s of regions with matching name. If the
/// grid-server couldn't be contacted or returned an error, return null.
/// </returns>
List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber);
List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber);
List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax);
List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax);
}
public class GridRegion
{
/// <summary>
/// The port by which http communication occurs with the region
/// </summary>
public uint HttpPort
{
get { return m_httpPort; }
set { m_httpPort = value; }
}
protected uint m_httpPort;
/// <summary>
/// A well-formed URI for the host region server (namely "http://" + ExternalHostName)
/// </summary>
public string ServerURI
{
get { return m_serverURI; }
set { m_serverURI = value; }
}
protected string m_serverURI;
public string RegionName
{
get { return m_regionName; }
set { m_regionName = value; }
}
protected string m_regionName = String.Empty;
protected bool Allow_Alternate_Ports;
public bool m_allow_alternate_ports;
protected string m_externalHostName;
protected IPEndPoint m_internalEndPoint;
public int RegionLocX
{
get { return m_regionLocX; }
set { m_regionLocX = value; }
}
protected int m_regionLocX;
public int RegionLocY
{
get { return m_regionLocY; }
set { m_regionLocY = value; }
}
protected int m_regionLocY;
public UUID RegionID = UUID.Zero;
public UUID ScopeID = UUID.Zero;
public GridRegion()
{
}
public GridRegion(int regionLocX, int regionLocY, IPEndPoint internalEndPoint, string externalUri)
{
m_regionLocX = regionLocX;
m_regionLocY = regionLocY;
m_internalEndPoint = internalEndPoint;
m_externalHostName = externalUri;
}
public GridRegion(int regionLocX, int regionLocY, string externalUri, uint port)
{
m_regionLocX = regionLocX;
m_regionLocY = regionLocY;
m_externalHostName = externalUri;
m_internalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)port);
}
public GridRegion(uint xcell, uint ycell)
{
m_regionLocX = (int)(xcell * Constants.RegionSize);
m_regionLocY = (int)(ycell * Constants.RegionSize);
}
public GridRegion(RegionInfo ConvertFrom)
{
m_regionName = ConvertFrom.RegionName;
m_regionLocX = (int)(ConvertFrom.RegionLocX * Constants.RegionSize);
m_regionLocY = (int)(ConvertFrom.RegionLocY * Constants.RegionSize);
m_internalEndPoint = ConvertFrom.InternalEndPoint;
m_externalHostName = ConvertFrom.ExternalHostName;
m_httpPort = ConvertFrom.HttpPort;
m_allow_alternate_ports = ConvertFrom.m_allow_alternate_ports;
RegionID = UUID.Zero;
ServerURI = ConvertFrom.ServerURI;
}
/// <value>
/// This accessor can throw all the exceptions that Dns.GetHostAddresses can throw.
///
/// XXX Isn't this really doing too much to be a simple getter, rather than an explict method?
/// </value>
public IPEndPoint ExternalEndPoint
{
get
{
// Old one defaults to IPv6
//return new IPEndPoint(Dns.GetHostAddresses(m_externalHostName)[0], m_internalEndPoint.Port);
IPAddress ia = null;
// If it is already an IP, don't resolve it - just return directly
if (IPAddress.TryParse(m_externalHostName, out ia))
return new IPEndPoint(ia, m_internalEndPoint.Port);
// Reset for next check
ia = null;
try
{
foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
{
if (ia == null)
ia = Adr;
if (Adr.AddressFamily == AddressFamily.InterNetwork)
{
ia = Adr;
break;
}
}
}
catch (SocketException e)
{
throw new Exception(
"Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
e + "' attached to this exception", e);
}
return new IPEndPoint(ia, m_internalEndPoint.Port);
}
set { m_externalHostName = value.ToString(); }
}
public string ExternalHostName
{
get { return m_externalHostName; }
set { m_externalHostName = value; }
}
public IPEndPoint InternalEndPoint
{
get { return m_internalEndPoint; }
set { m_internalEndPoint = value; }
}
public ulong RegionHandle
{
get { return Util.UIntsToLong((uint)RegionLocX, (uint)RegionLocY); }
}
public int getInternalEndPointPort()
{
return m_internalEndPoint.Port;
}
public Dictionary<string, object> ToKeyValuePairs()
{
Dictionary<string, object> kvp = new Dictionary<string, object>();
kvp["uuid"] = RegionID.ToString();
kvp["locX"] = RegionLocX.ToString();
kvp["locY"] = RegionLocY.ToString();
kvp["external_ip_address"] = ExternalEndPoint.Address.ToString();
kvp["external_port"] = ExternalEndPoint.Port.ToString();
kvp["external_host_name"] = ExternalHostName;
kvp["http_port"] = HttpPort.ToString();
kvp["internal_ip_address"] = InternalEndPoint.Address.ToString();
kvp["internal_port"] = InternalEndPoint.Port.ToString();
kvp["alternate_ports"] = m_allow_alternate_ports.ToString();
kvp["server_uri"] = ServerURI;
return kvp;
}
public GridRegion(Dictionary<string, object> kvp)
{
if ((kvp["external_ip_address"] != null) && (kvp["external_port"] != null))
{
int port = 0;
Int32.TryParse((string)kvp["external_port"], out port);
IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)kvp["external_ip_address"]), port);
ExternalEndPoint = ep;
}
else
ExternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
if (kvp["external_host_name"] != null)
ExternalHostName = (string)kvp["external_host_name"];
if (kvp["http_port"] != null)
{
UInt32 port = 0;
UInt32.TryParse((string)kvp["http_port"], out port);
HttpPort = port;
}
if ((kvp["internal_ip_address"] != null) && (kvp["internal_port"] != null))
{
int port = 0;
Int32.TryParse((string)kvp["internal_port"], out port);
IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)kvp["internal_ip_address"]), port);
InternalEndPoint = ep;
}
else
InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
if (kvp["alternate_ports"] != null)
{
bool alts = false;
Boolean.TryParse((string)kvp["alternate_ports"], out alts);
m_allow_alternate_ports = alts;
}
if (kvp["server_uri"] != null)
ServerURI = (string)kvp["server_uri"];
}
}
}

View File

@ -12,6 +12,7 @@
InventoryServices = "LocalInventoryServicesConnector"
NeighbourServices = "LocalNeighbourServicesConnector"
AuthorizationServices = "LocalAuthorizationServicesConnector"
GridServices = "LocalGridServicesConnector"
[AssetService]
LocalServiceModule = "OpenSim.Services.AssetService.dll:AssetService"
@ -21,3 +22,8 @@
[AuthorizationService]
LocalServiceModule = "OpenSim.Services.AuthorizationService.dll:AuthorizationService"
[GridService]
LocalServiceModule = "OpenSim.Services.GridService.dll:GridService"
StorageProvider = "OpenSim.Data.Null.dll:NullRegionData"

View File

@ -12,9 +12,11 @@
InventoryServices = "HGInventoryBroker"
NeighbourServices = "LocalNeighbourServicesConnector"
AuthorizationServices = "LocalAuthorizationServicesConnector"
GridServices = "HGGridServicesConnector"
InventoryServiceInConnector = true
AssetServiceInConnector = true
HGAuthServiceInConnector = true
HypergridServiceInConnector = true
[AssetService]
; For the AssetServiceInConnector
@ -39,4 +41,7 @@
; For the HGAuthServiceInConnector
LocalServiceModule = "OpenSim.Services.AuthenticationService.dll:HGAuthenticationService"
[GridService]
LocalServiceModule = "OpenSim.Services.GridService.dll:GridService"
GridServiceConnectorModule = "OpenSim.Region.CoreModules.dll:LocalGridServicesConnector"
StorageProvider = "OpenSim.Data.Null.dll:NullRegionData"

View File

@ -1205,6 +1205,7 @@
<ReferencePath>../../../bin/</ReferencePath>
<Reference name="System"/>
<Reference name="System.Xml"/>
<Reference name="System.Drawing"/>
<Reference name="OpenMetaverseTypes.dll"/>
<Reference name="OpenMetaverse.dll"/>
<Reference name="OpenMetaverse.StructuredData.dll"/>
@ -3591,6 +3592,7 @@
<Match path="World/Archiver/Tests" pattern="*.cs" recurse="true" />
<Match path="World/Serialiser/Tests" pattern="*.cs" recurse="true" />
<Match path="World/Terrain/Tests" pattern="*.cs" recurse="true" />
<Match path="ServiceConnectorsOut/Grid/Tests" pattern="*.cs" recurse="true" />
</Files>
</Project>