diff --git a/OpenMetaverse/AssetManager.cs b/OpenMetaverse/AssetManager.cs index 8db921c0..39e30cec 100644 --- a/OpenMetaverse/AssetManager.cs +++ b/OpenMetaverse/AssetManager.cs @@ -261,6 +261,9 @@ namespace OpenMetaverse } } + /// + /// + /// public class XferDownload : Transfer { public ulong XferID; @@ -374,7 +377,6 @@ namespace OpenMetaverse /// The filename on the simulator /// The name of the file the viewer requested public delegate void InitiateDownloadCallback(string simFilename, string viewerFilename); - #endregion Delegates #region Events @@ -810,6 +812,24 @@ namespace OpenMetaverse } } + /// + /// Used to force asset data into the PendingUpload property, ie: for raw terrain uploads + /// + /// An AssetUpload object containing the data to upload to the simulator + internal void SetPendingAssetUploadData(AssetUpload assetData) + { + lock(PendingUploadLock) + PendingUpload = assetData; + } + + /// + /// Request an asset be uploaded to the simulator + /// + /// The Object containing the asset data + /// If True, the asset once uploaded will be stored on the simulator + /// in which the client was connected in addition to being stored on the asset server + /// The of the transfer, can be used to correlate the upload with + /// events being fired public UUID RequestUpload(Asset asset, bool storeLocal) { if (asset.AssetData == null) @@ -821,12 +841,30 @@ namespace OpenMetaverse return transferID; } + /// + /// Request an asset be uploaded to the simulator + /// + /// The of the asset being uploaded + /// A byte array containing the encoded asset data + /// If True, the asset once uploaded will be stored on the simulator + /// in which the client was connected in addition to being stored on the asset server + /// The of the transfer, can be used to correlate the upload with + /// events being fired public UUID RequestUpload(AssetType type, byte[] data, bool storeLocal) { UUID assetID; return RequestUpload(out assetID, type, data, storeLocal); } + /// + /// Request an asset be uploaded to the simulator + /// + /// + /// A byte array containing the encoded asset data + /// If True, the asset once uploaded will be stored on the simulator + /// in which the client was connected in addition to being stored on the asset server + /// The of the transfer, can be used to correlate the upload with + /// events being fired public UUID RequestUpload(out UUID assetID, AssetType type, byte[] data, bool storeLocal) { return RequestUpload(out assetID, type, data, storeLocal, UUID.Random()); @@ -1200,6 +1238,8 @@ namespace OpenMetaverse } + + private void RequestXferHandler(Packet packet, Simulator simulator) { if (PendingUpload == null) diff --git a/OpenMetaverse/EstateTools.cs b/OpenMetaverse/EstateTools.cs index de71ac20..db5cadc9 100644 --- a/OpenMetaverse/EstateTools.cs +++ b/OpenMetaverse/EstateTools.cs @@ -574,6 +574,33 @@ namespace OpenMetaverse Client.Network.SendPacket(req); } - } + /// + /// Upload a terrain RAW file + /// + /// A byte array containing the encoded terrain data + /// The name of the file being uploaded + /// The Id of the transfer request + public UUID UploadTerrain(byte[] fileData, string fileName) + { + AssetUpload upload = new AssetUpload(); + upload.AssetData = fileData; + upload.AssetType = AssetType.Unknown; + upload.Size = fileData.Length; + upload.ID = UUID.Random(); + + // Tell the library we have a pending file to upload + Client.Assets.SetPendingAssetUploadData(upload); + + // Create and populate a list with commands specific to uploading a raw terrain file + List paramList = new List(); + paramList.Add("upload filename"); + paramList.Add(fileName); + + // Tell the simulator we have a new raw file to upload + Client.Network.CurrentSim.Estate.EstateOwnerMessage("terrain", paramList); + + return upload.ID; + } + } } diff --git a/Programs/examples/TestClient/Commands/Estate/DownloadTerrainCommand.cs b/Programs/examples/TestClient/Commands/Estate/DownloadTerrainCommand.cs index 0d31e3c8..587a4702 100644 --- a/Programs/examples/TestClient/Commands/Estate/DownloadTerrainCommand.cs +++ b/Programs/examples/TestClient/Commands/Estate/DownloadTerrainCommand.cs @@ -31,7 +31,7 @@ namespace OpenMetaverse.TestClient { Name = "downloadterrain"; Description = "Download the RAW terrain file for this estate. Usage: downloadterrain [timeout]"; - Category = CommandCategory.Movement; + Category = CommandCategory.Simulator; } /// diff --git a/Programs/examples/TestClient/Commands/Estate/UploadRawTerrainCommand.cs b/Programs/examples/TestClient/Commands/Estate/UploadRawTerrainCommand.cs new file mode 100644 index 00000000..8da2969c --- /dev/null +++ b/Programs/examples/TestClient/Commands/Estate/UploadRawTerrainCommand.cs @@ -0,0 +1,83 @@ +using System; +using System.IO; +using System.Collections.Generic; +using OpenMetaverse; +using OpenMetaverse.Packets; +namespace OpenMetaverse.TestClient +{ + public class UploadRawTerrainCommand : Command + { + System.Threading.AutoResetEvent WaitForUploadComplete = new System.Threading.AutoResetEvent(false); + + public UploadRawTerrainCommand(TestClient testClient) + { + Name = "uploadterrain"; + Description = "Upload a raw terrain file to a simulator. usage: uploadterrain filename"; + Category = CommandCategory.Simulator; + } + + public override string Execute(string[] args, UUID fromAgentID) + { + string fileName = String.Empty; + + if (args.Length != 1) + return "Usage: uploadterrain filename"; + + + fileName = args[0]; + + if (!System.IO.File.Exists(fileName)) + { + return String.Format("File {0} Does not exist", fileName); + } + + // Setup callbacks for upload request reply and progress indicator + // so we can detect when the upload is complete + Client.Assets.OnUploadProgress += new AssetManager.UploadProgressCallback(Assets_OnUploadProgress); + + byte[] fileData = File.ReadAllBytes(fileName); + + Client.Network.CurrentSim.Estate.UploadTerrain(fileData, fileName); + + // Wait for upload to complete. Upload request is fired in callback from first request + if (!WaitForUploadComplete.WaitOne(120000, false)) + { + Cleanup(); + return "Timeout waiting for terrain file upload"; + } + else + { + Cleanup(); + return "Terrain raw file uploaded and applied"; + } + } + + /// + /// Unregister previously subscribed event handlers + /// + private void Cleanup() + { + Client.Assets.OnUploadProgress -= new AssetManager.UploadProgressCallback(Assets_OnUploadProgress); + } + + + /// + /// + /// + /// + void Assets_OnUploadProgress(AssetUpload upload) + { + if (upload.Transferred == upload.Size) + { + WaitForUploadComplete.Set(); + } + else + { + //Console.WriteLine("Progress: {0}/{1} {2}/{3} {4}", upload.XferID, upload.ID, upload.Transferred, upload.Size, upload.Success); + Console.Write("."); + } + } + + + } +}