aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Connectors')
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs84
1 files changed, 81 insertions, 3 deletions
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
index 3a61226..cc8080f 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
@@ -28,17 +28,18 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Collections.Specialized; 30using System.Collections.Specialized;
31using System.Drawing;
32using System.Drawing.Imaging;
33using System.IO;
31using System.Net; 34using System.Net;
32using System.Reflection; 35using System.Reflection;
33using log4net; 36using log4net;
34using Mono.Addins; 37using Mono.Addins;
35using Nini.Config; 38using Nini.Config;
36using OpenSim.Framework; 39using OpenSim.Framework;
37using OpenSim.Framework.Servers.HttpServer;
38using OpenSim.Region.Framework.Interfaces; 40using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Framework.Scenes; 41using OpenSim.Region.Framework.Scenes;
40using OpenSim.Services.Interfaces; 42using OpenSim.Services.Interfaces;
41using OpenSim.Server.Base;
42using OpenMetaverse; 43using OpenMetaverse;
43using OpenMetaverse.StructuredData; 44using OpenMetaverse.StructuredData;
44 45
@@ -62,7 +63,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
62 #region ISharedRegionModule 63 #region ISharedRegionModule
63 64
64 public Type ReplaceableInterface { get { return null; } } 65 public Type ReplaceableInterface { get { return null; } }
65 public void RegionLoaded(Scene scene) { } 66 public void RegionLoaded(Scene scene) { UploadMapTile(scene); }
66 public void PostInitialise() { } 67 public void PostInitialise() { }
67 public void Close() { } 68 public void Close() { }
68 69
@@ -356,6 +357,83 @@ namespace OpenSim.Services.Connectors.SimianGrid
356 357
357 #endregion IGridService 358 #endregion IGridService
358 359
360 private void UploadMapTile(IScene scene)
361 {
362 string errorMessage = null;
363
364 // Create a PNG map tile and upload it to the AddMapTile API
365 byte[] pngData = Utils.EmptyBytes;
366 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>();
367 if (tileGenerator == null)
368 {
369 m_log.Warn("[SIMIAN GRID CONNECTOR]: Cannot upload PNG map tile without an IMapImageGenerator");
370 return;
371 }
372
373 using (Image mapTile = tileGenerator.CreateMapTile("defaultstripe.png"))
374 {
375 using (MemoryStream stream = new MemoryStream())
376 {
377 mapTile.Save(stream, ImageFormat.Png);
378 pngData = stream.ToArray();
379 }
380 }
381
382 List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>()
383 {
384 new MultipartForm.Parameter("X", scene.RegionInfo.RegionLocX.ToString()),
385 new MultipartForm.Parameter("Y", scene.RegionInfo.RegionLocY.ToString()),
386 new MultipartForm.File("Tile", "tile.png", "image/png", pngData)
387 };
388
389 // Make the remote storage request
390 try
391 {
392 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl);
393
394 HttpWebResponse response = MultipartForm.Post(request, postParameters);
395 using (Stream responseStream = response.GetResponseStream())
396 {
397 string responseStr = null;
398
399 try
400 {
401 responseStr = responseStream.GetStreamString();
402 OSD responseOSD = OSDParser.Deserialize(responseStr);
403 if (responseOSD.Type == OSDType.Map)
404 {
405 OSDMap responseMap = (OSDMap)responseOSD;
406 if (responseMap["Success"].AsBoolean())
407 m_log.Info("[SIMIAN GRID CONNECTOR]: Uploaded " + pngData.Length + " byte PNG map tile to AddMapTile");
408 else
409 errorMessage = "Upload failed: " + responseMap["Message"].AsString();
410 }
411 else
412 {
413 errorMessage = "Response format was invalid:\n" + responseStr;
414 }
415 }
416 catch (Exception ex)
417 {
418 if (!String.IsNullOrEmpty(responseStr))
419 errorMessage = "Failed to parse the response:\n" + responseStr;
420 else
421 errorMessage = "Failed to retrieve the response: " + ex.Message;
422 }
423 }
424 }
425 catch (WebException ex)
426 {
427 errorMessage = ex.Message;
428 }
429
430 if (!String.IsNullOrEmpty(errorMessage))
431 {
432 m_log.WarnFormat("[SIMIAN GRID CONNECTOR]: Failed to store {0} byte PNG map tile for {1}: {2}",
433 pngData.Length, scene.RegionInfo.RegionName, errorMessage);
434 }
435 }
436
359 private GridRegion GetNearestRegion(Vector3d position, bool onlyEnabled) 437 private GridRegion GetNearestRegion(Vector3d position, bool onlyEnabled)
360 { 438 {
361 NameValueCollection requestArgs = new NameValueCollection 439 NameValueCollection requestArgs = new NameValueCollection