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 67a65ff..0e4d794 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, 4096.0); | 115 | Vector3d maxPosition = minPosition + new Vector3d(Constants.RegionSize, Constants.RegionSize, 4096.0); |
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) }, |
@@ -399,6 +410,83 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
399 | 410 | ||
400 | #endregion IGridService | 411 | #endregion IGridService |
401 | 412 | ||
413 | private void UploadMapTile(IScene scene) | ||
414 | { | ||
415 | string errorMessage = null; | ||
416 | |||
417 | // Create a PNG map tile and upload it to the AddMapTile API | ||
418 | byte[] pngData = Utils.EmptyBytes; | ||
419 | IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>(); | ||
420 | if (tileGenerator == null) | ||
421 | { | ||
422 | m_log.Warn("[SIMIAN GRID CONNECTOR]: Cannot upload PNG map tile without an IMapImageGenerator"); | ||
423 | return; | ||
424 | } | ||
425 | |||
426 | using (Image mapTile = tileGenerator.CreateMapTile()) | ||
427 | { | ||
428 | using (MemoryStream stream = new MemoryStream()) | ||
429 | { | ||
430 | mapTile.Save(stream, ImageFormat.Png); | ||
431 | pngData = stream.ToArray(); | ||
432 | } | ||
433 | } | ||
434 | |||
435 | List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>() | ||
436 | { | ||
437 | new MultipartForm.Parameter("X", scene.RegionInfo.RegionLocX.ToString()), | ||
438 | new MultipartForm.Parameter("Y", scene.RegionInfo.RegionLocY.ToString()), | ||
439 | new MultipartForm.File("Tile", "tile.png", "image/png", pngData) | ||
440 | }; | ||
441 | |||
442 | // Make the remote storage request | ||
443 | try | ||
444 | { | ||
445 | HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_ServerURI); | ||
446 | |||
447 | HttpWebResponse response = MultipartForm.Post(request, postParameters); | ||
448 | using (Stream responseStream = response.GetResponseStream()) | ||
449 | { | ||
450 | string responseStr = null; | ||
451 | |||
452 | try | ||
453 | { | ||
454 | responseStr = responseStream.GetStreamString(); | ||
455 | OSD responseOSD = OSDParser.Deserialize(responseStr); | ||
456 | if (responseOSD.Type == OSDType.Map) | ||
457 | { | ||
458 | OSDMap responseMap = (OSDMap)responseOSD; | ||
459 | if (responseMap["Success"].AsBoolean()) | ||
460 | m_log.Info("[SIMIAN GRID CONNECTOR]: Uploaded " + pngData.Length + " byte PNG map tile to AddMapTile"); | ||
461 | else | ||
462 | errorMessage = "Upload failed: " + responseMap["Message"].AsString(); | ||
463 | } | ||
464 | else | ||
465 | { | ||
466 | errorMessage = "Response format was invalid:\n" + responseStr; | ||
467 | } | ||
468 | } | ||
469 | catch (Exception ex) | ||
470 | { | ||
471 | if (!String.IsNullOrEmpty(responseStr)) | ||
472 | errorMessage = "Failed to parse the response:\n" + responseStr; | ||
473 | else | ||
474 | errorMessage = "Failed to retrieve the response: " + ex.Message; | ||
475 | } | ||
476 | } | ||
477 | } | ||
478 | catch (WebException ex) | ||
479 | { | ||
480 | errorMessage = ex.Message; | ||
481 | } | ||
482 | |||
483 | if (!String.IsNullOrEmpty(errorMessage)) | ||
484 | { | ||
485 | m_log.WarnFormat("[SIMIAN GRID CONNECTOR]: Failed to store {0} byte PNG map tile for {1}: {2}", | ||
486 | pngData.Length, scene.RegionInfo.RegionName, errorMessage.Replace('\n', ' ')); | ||
487 | } | ||
488 | } | ||
489 | |||
402 | private GridRegion GetNearestRegion(Vector3d position, bool onlyEnabled) | 490 | private GridRegion GetNearestRegion(Vector3d position, bool onlyEnabled) |
403 | { | 491 | { |
404 | NameValueCollection requestArgs = new NameValueCollection | 492 | NameValueCollection requestArgs = new NameValueCollection |