diff options
author | Melanie | 2010-06-12 00:08:20 +0100 |
---|---|---|
committer | Melanie | 2010-06-12 00:08:20 +0100 |
commit | 836728e5ded245df7553b6a1b6c279d2e11ee370 (patch) | |
tree | d0ff3f9a5cc3747357f36aa09367c5d2eb8a7543 /OpenSim/Services/Connectors | |
parent | Merge branch 'master' into careminster-presence-refactor (diff) | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-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.cs | 84 |
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 @@ | |||
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; | ||
33 | using System.IO; | ||
31 | using System.Net; | 34 | using System.Net; |
32 | using System.Reflection; | 35 | using System.Reflection; |
33 | using log4net; | 36 | using log4net; |
34 | using Mono.Addins; | 37 | using Mono.Addins; |
35 | using Nini.Config; | 38 | using Nini.Config; |
36 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
37 | using OpenSim.Framework.Servers.HttpServer; | ||
38 | using OpenSim.Region.Framework.Interfaces; | 40 | using OpenSim.Region.Framework.Interfaces; |
39 | using OpenSim.Region.Framework.Scenes; | 41 | using OpenSim.Region.Framework.Scenes; |
40 | using OpenSim.Services.Interfaces; | 42 | using OpenSim.Services.Interfaces; |
41 | using OpenSim.Server.Base; | ||
42 | using OpenMetaverse; | 43 | using OpenMetaverse; |
43 | using OpenMetaverse.StructuredData; | 44 | using 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 |