Allow terrain heightmaps to be loaded directly from URIs via the remote admin plugin

See http://opensimulator.org/mantis/view.php?id=4418
Thanks StrawberryFride
See
mysql-performance
Justin Clark-Casey (justincc) 2009-12-04 18:26:58 +00:00
parent 07786786fc
commit c0f3a4c833
4 changed files with 53 additions and 4 deletions

View File

@ -315,8 +315,21 @@ namespace OpenSim.ApplicationPlugins.RemoteController
ITerrainModule terrainModule = region.RequestModuleInterface<ITerrainModule>(); ITerrainModule terrainModule = region.RequestModuleInterface<ITerrainModule>();
if (null == terrainModule) throw new Exception("terrain module not available"); if (null == terrainModule) throw new Exception("terrain module not available");
terrainModule.LoadFromFile(file); if (Uri.IsWellFormedUriString(file, UriKind.Absolute))
{
m_log.Info("[RADMIN]: Terrain path is URL");
Uri result;
if (Uri.TryCreate(file, UriKind.RelativeOrAbsolute, out result))
{
// the url is valid
string fileType = file.Substring(file.LastIndexOf('/') + 1);
terrainModule.LoadFromStream(fileType, result);
}
}
else
{
terrainModule.LoadFromFile(file);
}
responseData["success"] = false; responseData["success"] = false;
response.Value = responseData; response.Value = responseData;

View File

@ -29,6 +29,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Net;
using log4net; using log4net;
using Nini.Config; using Nini.Config;
using OpenMetaverse; using OpenMetaverse;
@ -258,6 +259,16 @@ namespace OpenSim.Region.CoreModules.World.Terrain
} }
} }
/// <summary>
/// Loads a terrain file from the specified URI
/// </summary>
/// <param name="filename">The name of the terrain to load</param>
/// <param name="pathToTerrainHeightmap">The URI to the terrain height map</param>
public void LoadFromStream(string filename, Uri pathToTerrainHeightmap)
{
LoadFromStream(filename, URIFetch(pathToTerrainHeightmap));
}
/// <summary> /// <summary>
/// Loads a terrain file from a stream and installs it in the scene. /// Loads a terrain file from a stream and installs it in the scene.
/// </summary> /// </summary>
@ -267,7 +278,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
{ {
foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
{ {
if (@filename.EndsWith(loader.Key)) if (filename.EndsWith(loader.Key))
{ {
lock (m_scene) lock (m_scene)
{ {
@ -295,6 +306,25 @@ namespace OpenSim.Region.CoreModules.World.Terrain
throw new TerrainException(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename)); throw new TerrainException(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename));
} }
private static Stream URIFetch(Uri uri)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
// request.Credentials = credentials;
request.ContentLength = 0;
request.KeepAlive = false;
WebResponse response = request.GetResponse();
Stream file = response.GetResponseStream();
if (response.ContentLength == 0)
throw new Exception(String.Format("{0} returned an empty file", uri.ToString()));
// return new BufferedStream(file, (int) response.ContentLength);
return new BufferedStream(file, 1000000);
}
/// <summary> /// <summary>
/// Modify Land /// Modify Land
/// </summary> /// </summary>

View File

@ -51,7 +51,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// </param> /// </param>
/// <param name="stream"></param> /// <param name="stream"></param>
void LoadFromStream(string filename, Stream stream); void LoadFromStream(string filename, Stream stream);
void LoadFromStream(string filename, System.Uri pathToTerrainHeightmap);
/// <summary> /// <summary>
/// Save a terrain to a stream. /// Save a terrain to a stream.
/// </summary> /// </summary>

View File

@ -2393,6 +2393,12 @@ namespace OpenSim.Region.Framework.Scenes
InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId); InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
item = InventoryService.GetItem(item); item = InventoryService.GetItem(item);
presence.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID /*att.UUID*/); presence.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID /*att.UUID*/);
if (m_AvatarFactory != null)
{
m_AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
}
} }
} }