diff options
author | John Hurliman | 2010-06-11 15:37:25 -0700 |
---|---|---|
committer | John Hurliman | 2010-06-11 15:37:25 -0700 |
commit | d1a324888be2a0db247999928dff12d0bb62cddd (patch) | |
tree | d5038ea284401fd2f4661f3a00ad60ede069bd7a /OpenSim/Services | |
parent | Allow IInventoryService.GetFolder(folderId, userId) as well as GetFolder(Inve... (diff) | |
download | opensim-SC-d1a324888be2a0db247999928dff12d0bb62cddd.zip opensim-SC-d1a324888be2a0db247999928dff12d0bb62cddd.tar.gz opensim-SC-d1a324888be2a0db247999928dff12d0bb62cddd.tar.bz2 opensim-SC-d1a324888be2a0db247999928dff12d0bb62cddd.tar.xz |
* Added a new method to IMapImageGenerator for getting the map tile before it is JPEG2000 compressed
* Aesthetically improved map tile water
* SimianGrid connector now uploads a PNG tile to the AddMapTile API
Diffstat (limited to 'OpenSim/Services')
-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 3a61226..cc8080f 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 | ||
@@ -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 |