diff options
Diffstat (limited to 'OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs')
-rw-r--r-- | OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs | 90 |
1 files changed, 89 insertions, 1 deletions
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs index c928f16..3cf3416 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs | |||
@@ -28,6 +28,8 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Collections.Specialized; | 30 | using System.Collections.Specialized; |
31 | using System.Drawing; | ||
32 | using System.Drawing.Imaging; | ||
31 | using System.IO; | 33 | using System.IO; |
32 | using System.Net; | 34 | using System.Net; |
33 | using System.Reflection; | 35 | using System.Reflection; |
@@ -100,6 +102,15 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
100 | 102 | ||
101 | public string RegisterRegion(UUID scopeID, GridRegion regionInfo) | 103 | public string RegisterRegion(UUID scopeID, GridRegion regionInfo) |
102 | { | 104 | { |
105 | IPEndPoint ext = regionInfo.ExternalEndPoint; | ||
106 | if (ext == null) return "Region registration for " + regionInfo.RegionName + " failed: Could not resolve EndPoint"; | ||
107 | // Generate and upload our map tile in PNG format to the SimianGrid AddMapTile service | ||
108 | // Scene scene; | ||
109 | // if (m_scenes.TryGetValue(regionInfo.RegionID, out scene)) | ||
110 | // UploadMapTile(scene); | ||
111 | // else | ||
112 | // m_log.Warn("Registering region " + regionInfo.RegionName + " (" + regionInfo.RegionID + ") that we are not tracking"); | ||
113 | |||
103 | Vector3d minPosition = new Vector3d(regionInfo.RegionLocX, regionInfo.RegionLocY, 0.0); | 114 | Vector3d minPosition = new Vector3d(regionInfo.RegionLocX, regionInfo.RegionLocY, 0.0); |
104 | Vector3d maxPosition = minPosition + new Vector3d(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); | 115 | Vector3d maxPosition = minPosition + new Vector3d(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); |
105 | 116 | ||
@@ -108,7 +119,7 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
108 | { "ServerURI", OSD.FromString(regionInfo.ServerURI) }, | 119 | { "ServerURI", OSD.FromString(regionInfo.ServerURI) }, |
109 | { "InternalAddress", OSD.FromString(regionInfo.InternalEndPoint.Address.ToString()) }, | 120 | { "InternalAddress", OSD.FromString(regionInfo.InternalEndPoint.Address.ToString()) }, |
110 | { "InternalPort", OSD.FromInteger(regionInfo.InternalEndPoint.Port) }, | 121 | { "InternalPort", OSD.FromInteger(regionInfo.InternalEndPoint.Port) }, |
111 | { "ExternalAddress", OSD.FromString(regionInfo.ExternalEndPoint.Address.ToString()) }, | 122 | { "ExternalAddress", OSD.FromString(ext.Address.ToString()) }, |
112 | { "ExternalPort", OSD.FromInteger(regionInfo.ExternalEndPoint.Port) }, | 123 | { "ExternalPort", OSD.FromInteger(regionInfo.ExternalEndPoint.Port) }, |
113 | { "MapTexture", OSD.FromUUID(regionInfo.TerrainImage) }, | 124 | { "MapTexture", OSD.FromUUID(regionInfo.TerrainImage) }, |
114 | { "Access", OSD.FromInteger(regionInfo.Access) }, | 125 | { "Access", OSD.FromInteger(regionInfo.Access) }, |
@@ -405,6 +416,83 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
405 | 416 | ||
406 | #endregion IGridService | 417 | #endregion IGridService |
407 | 418 | ||
419 | private void UploadMapTile(IScene scene) | ||
420 | { | ||
421 | string errorMessage = null; | ||
422 | |||
423 | // Create a PNG map tile and upload it to the AddMapTile API | ||
424 | byte[] pngData = Utils.EmptyBytes; | ||
425 | IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>(); | ||
426 | if (tileGenerator == null) | ||
427 | { | ||
428 | m_log.Warn("[SIMIAN GRID CONNECTOR]: Cannot upload PNG map tile without an IMapImageGenerator"); | ||
429 | return; | ||
430 | } | ||
431 | |||
432 | using (Image mapTile = tileGenerator.CreateMapTile()) | ||
433 | { | ||
434 | using (MemoryStream stream = new MemoryStream()) | ||
435 | { | ||
436 | mapTile.Save(stream, ImageFormat.Png); | ||
437 | pngData = stream.ToArray(); | ||
438 | } | ||
439 | } | ||
440 | |||
441 | List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>() | ||
442 | { | ||
443 | new MultipartForm.Parameter("X", scene.RegionInfo.RegionLocX.ToString()), | ||
444 | new MultipartForm.Parameter("Y", scene.RegionInfo.RegionLocY.ToString()), | ||
445 | new MultipartForm.File("Tile", "tile.png", "image/png", pngData) | ||
446 | }; | ||
447 | |||
448 | // Make the remote storage request | ||
449 | try | ||
450 | { | ||
451 | HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_ServerURI); | ||
452 | |||
453 | HttpWebResponse response = MultipartForm.Post(request, postParameters); | ||
454 | using (Stream responseStream = response.GetResponseStream()) | ||
455 | { | ||
456 | string responseStr = null; | ||
457 | |||
458 | try | ||
459 | { | ||
460 | responseStr = responseStream.GetStreamString(); | ||
461 | OSD responseOSD = OSDParser.Deserialize(responseStr); | ||
462 | if (responseOSD.Type == OSDType.Map) | ||
463 | { | ||
464 | OSDMap responseMap = (OSDMap)responseOSD; | ||
465 | if (responseMap["Success"].AsBoolean()) | ||
466 | m_log.Info("[SIMIAN GRID CONNECTOR]: Uploaded " + pngData.Length + " byte PNG map tile to AddMapTile"); | ||
467 | else | ||
468 | errorMessage = "Upload failed: " + responseMap["Message"].AsString(); | ||
469 | } | ||
470 | else | ||
471 | { | ||
472 | errorMessage = "Response format was invalid:\n" + responseStr; | ||
473 | } | ||
474 | } | ||
475 | catch (Exception ex) | ||
476 | { | ||
477 | if (!String.IsNullOrEmpty(responseStr)) | ||
478 | errorMessage = "Failed to parse the response:\n" + responseStr; | ||
479 | else | ||
480 | errorMessage = "Failed to retrieve the response: " + ex.Message; | ||
481 | } | ||
482 | } | ||
483 | } | ||
484 | catch (WebException ex) | ||
485 | { | ||
486 | errorMessage = ex.Message; | ||
487 | } | ||
488 | |||
489 | if (!String.IsNullOrEmpty(errorMessage)) | ||
490 | { | ||
491 | m_log.WarnFormat("[SIMIAN GRID CONNECTOR]: Failed to store {0} byte PNG map tile for {1}: {2}", | ||
492 | pngData.Length, scene.RegionInfo.RegionName, errorMessage.Replace('\n', ' ')); | ||
493 | } | ||
494 | } | ||
495 | |||
408 | private GridRegion GetNearestRegion(Vector3d position, bool onlyEnabled) | 496 | private GridRegion GetNearestRegion(Vector3d position, bool onlyEnabled) |
409 | { | 497 | { |
410 | NameValueCollection requestArgs = new NameValueCollection | 498 | NameValueCollection requestArgs = new NameValueCollection |