From a6928a479eb84b14e949c5f589b9ce753edf457a Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 11 Sep 2012 17:50:55 +0200 Subject: Add cost calculation suppor tto the VariablePrice one as well --- .../Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 1 - .../NewFileAgentInventoryVariablePriceModule.cs | 52 ++++++++++++++++++---- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 097e224..328dc75 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -417,7 +417,6 @@ namespace OpenSim.Region.ClientStack.Linden } } - /// /// /// diff --git a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs index 52c4f44..6e2b52d 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs @@ -127,6 +127,37 @@ namespace OpenSim.Region.ClientStack.Linden #endregion + private delegate void UploadWithCostCompleteDelegate(string assetName, + string assetDescription, UUID assetID, UUID inventoryItem, + UUID parentFolder, byte[] data, string inventoryType, + string assetType, uint cost); + + private class AssetUploaderWithCost : AssetUploader + { + private uint m_cost; + + public event UploadWithCostCompleteDelegate OnUpLoad; + + public AssetUploaderWithCost(string assetName, string description, UUID assetID, + UUID inventoryItem, UUID parentFolderID, string invType, string assetType, + string path, IHttpServer httpServer, bool dumpAssetsToFile, uint cost) : + base(assetName, description, assetID, inventoryItem, parentFolderID, + invType, assetType, path, httpServer, dumpAssetsToFile) + { + m_cost = cost; + + base.OnUpLoad += UploadCompleteHandler; + } + + private void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, + UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, + string assetType) + { + OnUpLoad(assetName, assetDescription, assetID, inventoryItem, parentFolder, + data, inventoryType, assetType, m_cost); + } + } + public LLSDNewFileAngentInventoryVariablePriceReplyResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest, UUID agentID) { //TODO: The Mesh uploader uploads many types of content. If you're going to implement a Money based limit @@ -138,6 +169,8 @@ namespace OpenSim.Region.ClientStack.Linden // { // check user level + uint cost = 0; + ScenePresence avatar = null; IClientAPI client = null; m_scene.TryGetScenePresence(agentID, out avatar); @@ -163,7 +196,10 @@ namespace OpenSim.Region.ClientStack.Linden if (mm != null) { - if (!mm.UploadCovered(agentID, mm.UploadCharge)) + // XPTO: Calculate cost here + cost = (uint)mm.UploadCharge; + + if (!mm.UploadCovered(agentID, (int)cost)) { if (client != null) client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); @@ -185,9 +221,9 @@ namespace OpenSim.Region.ClientStack.Linden UUID parentFolder = llsdRequest.folder_id; string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000") + "/"; - AssetUploader uploader = - new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, - llsdRequest.asset_type, capsBase + uploaderPath, MainServer.Instance, m_dumpAssetsToFile); + AssetUploaderWithCost uploader = + new AssetUploaderWithCost(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, + llsdRequest.asset_type, capsBase + uploaderPath, MainServer.Instance, m_dumpAssetsToFile, cost); MainServer.Instance.AddStreamHandler( new BinaryStreamHandler( @@ -218,11 +254,11 @@ namespace OpenSim.Region.ClientStack.Linden delegate( string passetName, string passetDescription, UUID passetID, UUID pinventoryItem, UUID pparentFolder, byte[] pdata, string pinventoryType, - string passetType) + string passetType, uint cost) { UploadCompleteHandler(passetName, passetDescription, passetID, pinventoryItem, pparentFolder, pdata, pinventoryType, - passetType,agentID); + passetType,agentID, cost); }; return uploadResponse; @@ -230,7 +266,7 @@ namespace OpenSim.Region.ClientStack.Linden public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, - string assetType,UUID AgentID) + string assetType,UUID AgentID, uint cost) { // m_log.DebugFormat( // "[NEW FILE AGENT INVENTORY VARIABLE PRICE MODULE]: Upload complete for {0}", inventoryItem); @@ -290,7 +326,7 @@ namespace OpenSim.Region.ClientStack.Linden item.EveryOnePermissions = 0; item.NextPermissions = (uint)PermissionMask.All; item.CreationDate = Util.UnixTimeSinceEpoch(); - m_scene.AddInventoryItem(item); + m_scene.AddUploadedInventoryItem(AgentID, item, cost); } } } -- cgit v1.1