aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors
diff options
context:
space:
mode:
authorMelanie2010-06-12 00:08:20 +0100
committerMelanie2010-06-12 00:08:20 +0100
commit836728e5ded245df7553b6a1b6c279d2e11ee370 (patch)
treed0ff3f9a5cc3747357f36aa09367c5d2eb8a7543 /OpenSim/Services/Connectors
parentMerge branch 'master' into careminster-presence-refactor (diff)
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-836728e5ded245df7553b6a1b6c279d2e11ee370.zip
opensim-SC_OLD-836728e5ded245df7553b6a1b6c279d2e11ee370.tar.gz
opensim-SC_OLD-836728e5ded245df7553b6a1b6c279d2e11ee370.tar.bz2
opensim-SC_OLD-836728e5ded245df7553b6a1b6c279d2e11ee370.tar.xz
Merge branch 'master' into careminster-presence-refactor
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 57924b7..119868b 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
@@ -358,6 +359,83 @@ namespace OpenSim.Services.Connectors.SimianGrid
358 359
359 #endregion IGridService 360 #endregion IGridService
360 361
362 private void UploadMapTile(IScene scene)
363 {
364 string errorMessage = null;
365
366 // Create a PNG map tile and upload it to the AddMapTile API
367 byte[] pngData = Utils.EmptyBytes;
368 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>();
369 if (tileGenerator == null)
370 {
371 m_log.Warn("[SIMIAN GRID CONNECTOR]: Cannot upload PNG map tile without an IMapImageGenerator");
372 return;
373 }
374
375 using (Image mapTile = tileGenerator.CreateMapTile("defaultstripe.png"))
376 {
377 using (MemoryStream stream = new MemoryStream())
378 {
379 mapTile.Save(stream, ImageFormat.Png);
380 pngData = stream.ToArray();
381 }
382 }
383
384 List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>()
385 {
386 new MultipartForm.Parameter("X", scene.RegionInfo.RegionLocX.ToString()),
387 new MultipartForm.Parameter("Y", scene.RegionInfo.RegionLocY.ToString()),
388 new MultipartForm.File("Tile", "tile.png", "image/png", pngData)
389 };
390
391 // Make the remote storage request
392 try
393 {
394 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl);
395
396 HttpWebResponse response = MultipartForm.Post(request, postParameters);
397 using (Stream responseStream = response.GetResponseStream())
398 {
399 string responseStr = null;
400
401 try
402 {
403 responseStr = responseStream.GetStreamString();
404 OSD responseOSD = OSDParser.Deserialize(responseStr);
405 if (responseOSD.Type == OSDType.Map)
406 {
407 OSDMap responseMap = (OSDMap)responseOSD;
408 if (responseMap["Success"].AsBoolean())
409 m_log.Info("[SIMIAN GRID CONNECTOR]: Uploaded " + pngData.Length + " byte PNG map tile to AddMapTile");
410 else
411 errorMessage = "Upload failed: " + responseMap["Message"].AsString();
412 }
413 else
414 {
415 errorMessage = "Response format was invalid:\n" + responseStr;
416 }
417 }
418 catch (Exception ex)
419 {
420 if (!String.IsNullOrEmpty(responseStr))
421 errorMessage = "Failed to parse the response:\n" + responseStr;
422 else
423 errorMessage = "Failed to retrieve the response: " + ex.Message;
424 }
425 }
426 }
427 catch (WebException ex)
428 {
429 errorMessage = ex.Message;
430 }
431
432 if (!String.IsNullOrEmpty(errorMessage))
433 {
434 m_log.WarnFormat("[SIMIAN GRID CONNECTOR]: Failed to store {0} byte PNG map tile for {1}: {2}",
435 pngData.Length, scene.RegionInfo.RegionName, errorMessage);
436 }
437 }
438
361 private GridRegion GetNearestRegion(Vector3d position, bool onlyEnabled) 439 private GridRegion GetNearestRegion(Vector3d position, bool onlyEnabled)
362 { 440 {
363 NameValueCollection requestArgs = new NameValueCollection 441 NameValueCollection requestArgs = new NameValueCollection