diff options
author | Tom Grimshaw | 2010-06-12 04:36:14 -0700 |
---|---|---|
committer | Tom Grimshaw | 2010-06-12 04:36:14 -0700 |
commit | 63531b1df5463d43821c91a26bd0f6414716d0d0 (patch) | |
tree | 381fddf86dbe4880b6e5114f3db8737fc9ecb53a /OpenSim/Services | |
parent | Get rid of spamming SOG debug message (diff) | |
parent | Preserving the link numbers is a serializer's highest duty. (diff) | |
download | opensim-SC-63531b1df5463d43821c91a26bd0f6414716d0d0.zip opensim-SC-63531b1df5463d43821c91a26bd0f6414716d0d0.tar.gz opensim-SC-63531b1df5463d43821c91a26bd0f6414716d0d0.tar.bz2 opensim-SC-63531b1df5463d43821c91a26bd0f6414716d0d0.tar.xz |
Merge branch 'careminster-presence-refactor' of ssh://3dhosting.de/var/git/careminster into careminster-presence-refactor
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 57924b7..6a61da6 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) { if (!String.IsNullOrEmpty(m_serverUrl)) { 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 |