29 using System.Collections.Generic;
30 using System.Collections.Specialized;
32 using System.Drawing.Imaging;
35 using System.Reflection;
39 using OpenSim.Framework;
40 using OpenSim.Region.Framework.Interfaces;
41 using OpenSim.Region.Framework.Scenes;
42 using OpenSim.Services.Interfaces;
44 using OpenMetaverse.StructuredData;
48 namespace OpenSim.Services.Connectors.SimianGrid
56 private static readonly ILog m_log =
58 MethodBase.GetCurrentMethod().DeclaringType);
60 private string m_ServerURI = String.Empty;
66 m_ServerURI = serverURI.TrimEnd(
'/');
79 private void CommonInit(IConfigSource source)
81 IConfig gridConfig = source.Configs[
"GridService"];
82 if (gridConfig == null)
84 m_log.Error(
"[SIMIAN GRID CONNECTOR]: GridService missing from OpenSim.ini");
85 throw new Exception(
"Grid connector init error");
88 string serviceUrl = gridConfig.GetString(
"GridServerURI");
89 if (
String.IsNullOrEmpty(serviceUrl))
91 m_log.Error(
"[SIMIAN GRID CONNECTOR]: No Server URI named in section GridService");
92 throw new Exception(
"Grid connector init error");
95 if (!serviceUrl.EndsWith(
"/") && !serviceUrl.EndsWith(
"="))
96 serviceUrl = serviceUrl +
'/';
97 m_ServerURI = serviceUrl;
105 IPEndPoint ext = regionInfo.ExternalEndPoint;
106 if (ext == null)
return "Region registration for " + regionInfo.RegionName +
" failed: Could not resolve EndPoint";
119 {
"ServerURI", OSD.FromString(regionInfo.ServerURI) },
120 {
"InternalAddress", OSD.FromString(regionInfo.InternalEndPoint.Address.ToString()) },
121 {
"InternalPort", OSD.FromInteger(regionInfo.InternalEndPoint.Port) },
122 {
"ExternalAddress", OSD.FromString(ext.Address.ToString()) },
123 {
"ExternalPort", OSD.FromInteger(regionInfo.ExternalEndPoint.Port) },
124 {
"MapTexture", OSD.FromUUID(regionInfo.TerrainImage) },
125 {
"Access", OSD.FromInteger(regionInfo.Access) },
126 {
"RegionSecret", OSD.FromString(regionInfo.RegionSecret) },
127 {
"EstateOwner", OSD.FromUUID(regionInfo.EstateOwner) },
128 {
"Token", OSD.FromString(regionInfo.Token) }
131 NameValueCollection requestArgs =
new NameValueCollection
133 {
"RequestMethod",
"AddScene" },
134 {
"SceneID", regionInfo.RegionID.ToString() },
135 {
"Name", regionInfo.RegionName },
136 {
"MinPosition", minPosition.ToString() },
137 {
"MaxPosition", maxPosition.ToString() },
138 {
"Address", regionInfo.ServerURI },
140 {
"ExtraData", OSDParser.SerializeJsonString(extraData) }
143 OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
144 if (response[
"Success"].AsBoolean())
147 return "Region registration for " + regionInfo.
RegionName +
" failed: " + response[
"Message"].AsString();
152 NameValueCollection requestArgs =
new NameValueCollection
154 {
"RequestMethod",
"AddScene" },
155 {
"SceneID", regionID.ToString() },
159 OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
160 bool success = response[
"Success"].AsBoolean();
163 m_log.Warn(
"[SIMIAN GRID CONNECTOR]: Region deregistration for " + regionID +
" failed: " + response[
"Message"].AsString());
170 GridRegion region = GetRegionByUUID(scopeID, regionID);
172 int NEIGHBOR_RADIUS = Math.Max(region.RegionSizeX, region.RegionSizeY) / 2;
176 List<GridRegion> regions = GetRegionRange(scopeID,
180 for (
int i = 0; i < regions.Count; i++)
182 if (regions[i].RegionID == regionID)
193 return new List<GridRegion>(0);
198 NameValueCollection requestArgs =
new NameValueCollection
200 {
"RequestMethod",
"GetScene" },
201 {
"SceneID", regionID.ToString() }
206 OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
207 if (response[
"Success"].AsBoolean())
210 return ResponseToGridRegion(response);
214 m_log.Warn(
"[SIMIAN GRID CONNECTOR]: Grid service did not find a match for region " + regionID);
223 Vector3d position =
new Vector3d(x + 1, y + 1, 0.0);
225 NameValueCollection requestArgs =
new NameValueCollection
227 {
"RequestMethod",
"GetScene" },
228 {
"Position", position.ToString() },
234 OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
235 if (response[
"Success"].AsBoolean())
238 return ResponseToGridRegion(response);
250 List<GridRegion> regions = GetRegionsByName(scopeID, regionName, 1);
252 m_log.Debug(
"[SIMIAN GRID CONNECTOR]: Got " + regions.Count +
" matches for region name " + regionName);
254 if (regions.Count > 0)
262 List<GridRegion> foundRegions =
new List<GridRegion>();
264 NameValueCollection requestArgs =
new NameValueCollection
266 {
"RequestMethod",
"GetScenes" },
267 {
"NameQuery", name },
271 requestArgs[
"MaxNumber"] = maxNumber.ToString();
275 OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
276 if (response[
"Success"].AsBoolean())
283 for (
int i = 0; i < array.Count; i++)
287 foundRegions.Add(region);
295 public List<GridRegion>
GetRegionRange(UUID scopeID,
int xmin,
int xmax,
int ymin,
int ymax)
297 List<GridRegion> foundRegions =
new List<GridRegion>();
299 Vector3d minPosition =
new Vector3d(xmin, ymin, 0.0);
302 NameValueCollection requestArgs =
new NameValueCollection
304 {
"RequestMethod",
"GetScenes" },
305 {
"MinPosition", minPosition.ToString() },
306 {
"MaxPosition", maxPosition.ToString() },
313 OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
314 if (response[
"Success"].AsBoolean())
319 for (
int i = 0; i < array.Count; i++)
323 foundRegions.Add(region);
334 const int DEFAULT_X = 1000 * 256;
335 const int DEFAULT_Y = 1000 * 256;
337 GridRegion defRegion = GetNearestRegion(
new Vector3d(DEFAULT_X, DEFAULT_Y, 0.0),
true);
338 if (defRegion != null)
339 return new List<GridRegion>(1) { defRegion };
341 return new List<GridRegion>(0);
347 return GetDefaultRegions(scopeID);
352 GridRegion defRegion = GetNearestRegion(
new Vector3d(x, y, 0.0),
true);
353 if (defRegion != null)
354 return new List<GridRegion>(1) { defRegion };
356 return new List<GridRegion>(0);
361 List<GridRegion> foundRegions =
new List<GridRegion>();
363 NameValueCollection requestArgs =
new NameValueCollection
365 {
"RequestMethod",
"GetScenes" },
366 {
"HyperGrid",
"true" },
370 OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
371 if (response[
"Success"].AsBoolean())
378 for (
int i = 0; i < array.Count; i++)
382 foundRegions.Add(region);
392 NameValueCollection requestArgs =
new NameValueCollection
394 {
"RequestMethod",
"GetScene" },
395 {
"SceneID", regionID.ToString() }
398 m_log.DebugFormat(
"[SIMIAN GRID CONNECTOR] request region flags for {0}",regionID.ToString());
400 OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
401 if (response[
"Success"].AsBoolean())
404 int enabled = response[
"Enabled"].AsBoolean() ? (
int)OpenSim.Framework.RegionFlags.RegionOnline : 0;
405 int hypergrid = extraData[
"HyperGrid"].AsBoolean() ? (
int)OpenSim.Framework.RegionFlags.Hyperlink : 0;
406 int flags = enabled | hypergrid;
407 m_log.DebugFormat(
"[SGGC] enabled - {0} hg - {1} flags - {2}", enabled, hypergrid, flags);
412 m_log.Warn(
"[SIMIAN GRID CONNECTOR]: Grid service did not find a match for region " + regionID +
" during region flags check");
420 Dictionary<string, object> extraFeatures =
new Dictionary<string, object>();
421 return extraFeatures;
424 #endregion IGridService
426 private GridRegion GetNearestRegion(Vector3d position,
bool onlyEnabled)
428 NameValueCollection requestArgs =
new NameValueCollection
430 {
"RequestMethod",
"GetScene" },
431 {
"Position", position.ToString() },
432 {
"FindClosest",
"1" }
435 requestArgs[
"Enabled"] =
"1";
437 OSDMap response = SimianGrid.PostToService(m_ServerURI, requestArgs);
438 if (response[
"Success"].AsBoolean())
440 return ResponseToGridRegion(response);
444 m_log.Warn(
"[SIMIAN GRID CONNECTOR]: Grid service did not find a match for region at " + position);
451 if (response == null)
455 if (extraData == null)
460 region.RegionID = response[
"SceneID"].AsUUID();
461 region.RegionName = response[
"Name"].AsString();
463 Vector3d minPosition = response[
"MinPosition"].AsVector3d();
464 Vector3d maxPosition = response[
"MaxPosition"].AsVector3d();
465 region.RegionLocX = (int)minPosition.X;
468 region.RegionSizeX = (int)maxPosition.X - (
int)minPosition.X;
469 region.RegionSizeY = (int)maxPosition.Y - (
int)minPosition.Y;
471 if ( ! extraData[
"HyperGrid"] ) {
472 Uri httpAddress = response[
"Address"].AsUri();
473 region.ExternalHostName = httpAddress.Host;
474 region.HttpPort = (uint)httpAddress.Port;
476 IPAddress internalAddress;
477 IPAddress.TryParse(extraData[
"InternalAddress"].AsString(), out internalAddress);
478 if (internalAddress == null)
479 internalAddress = IPAddress.Any;
481 region.InternalEndPoint =
new IPEndPoint(internalAddress, extraData[
"InternalPort"].AsInteger());
482 region.TerrainImage = extraData[
"MapTexture"].AsUUID();
483 region.Access = (byte)extraData[
"Access"].AsInteger();
484 region.RegionSecret = extraData[
"RegionSecret"].AsString();
485 region.EstateOwner = extraData[
"EstateOwner"].AsUUID();
486 region.Token = extraData[
"Token"].AsString();
487 region.ServerURI = extraData[
"ServerURI"].AsString();
489 region.ServerURI = response[
"Address"];
List< GridRegion > GetFallbackRegions(UUID scopeID, int x, int y)
OpenMetaverse.StructuredData.OSDArray OSDArray
SimianGridServiceConnector(string serverURI)
Connects region registration and neighbor lookups to the SimianGrid backend
bool DeregisterRegion(UUID regionID)
Deregister a region with the grid service.
OpenMetaverse.StructuredData.OSDMap OSDMap
List< GridRegion > GetHyperlinks(UUID scopeID)
string RegisterRegion(UUID scopeID, GridRegion regionInfo)
Register a region with the grid service.
GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
int RegionLocX
The location of this region in meters. DANGER DANGER! Note that this name means something different i...
SimianGridServiceConnector()
int RegionLocY
The location of this region in meters. DANGER DANGER! Note that this name means something different i...
Dictionary< string, object > GetExtraFeatures()
void Initialise(IConfigSource source)
OpenSim.Services.Interfaces.GridRegion GridRegion
SimianGridServiceConnector(IConfigSource source)
List< GridRegion > GetNeighbours(UUID scopeID, UUID regionID)
Get information about the regions neighbouring the given co-ordinates (in meters).
List< GridRegion > GetDefaultRegions(UUID scopeID)
List< GridRegion > GetRegionsByName(UUID scopeID, string name, int maxNumber)
Get information about regions starting with the provided name.
List< GridRegion > GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
List< GridRegion > GetDefaultHypergridRegions(UUID scopeID)
int GetRegionFlags(UUID scopeID, UUID regionID)
Get internal OpenSimulator region flags.
GridRegion GetRegionByName(UUID scopeID, string regionName)
Get information about a region which exactly matches the name given.
GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
Get the region at the given position (in meters)