From a6753c14a509e11f65829b87070b440ac3b87c4a Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 11 Sep 2012 10:39:43 +0200 Subject: Revamp the v3 inventory sending. Uses threads and some nifty mechanics to leverage the Poll Service without blocking it's workers. --- .../Linden/Caps/WebFetchInvDescModule.cs | 198 ++++++++++++--------- 1 file changed, 117 insertions(+), 81 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs index e996fe8..4908c2c 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs @@ -42,6 +42,7 @@ using OpenSim.Region.Framework.Scenes; using OpenSim.Services.Interfaces; using Caps = OpenSim.Framework.Capabilities.Caps; using OpenSim.Capabilities.Handlers; +using OpenSim.Framework.Monitoring; namespace OpenSim.Region.ClientStack.Linden { @@ -58,13 +59,13 @@ namespace OpenSim.Region.ClientStack.Linden private IInventoryService m_InventoryService; private ILibraryService m_LibraryService; - private WebFetchInvDescHandler m_webFetchHandler; - - private object m_lock = new object(); + private static WebFetchInvDescHandler m_webFetchHandler; private Dictionary m_capsDict = new Dictionary(); - private Dictionary m_requests = new Dictionary(); - bool m_busy = false; + private static Thread[] m_workerThreads = null; + + private static OpenMetaverse.BlockingQueue m_queue = + new OpenMetaverse.BlockingQueue(); #region ISharedRegionModule Members @@ -94,6 +95,22 @@ namespace OpenSim.Region.ClientStack.Linden m_scene.EventManager.OnRegisterCaps += RegisterCaps; m_scene.EventManager.OnDeregisterCaps += DeregisterCaps; + + if (m_workerThreads == null) + { + m_workerThreads = new Thread[2]; + + for (uint i = 0; i < 2; i++) + { + m_workerThreads[i] = Watchdog.StartThread(DoInventoryRequests, + String.Format("InventoryWorkerThread{0}", i), + ThreadPriority.Normal, + false, + true, + null, + int.MaxValue); + } + } } public void PostInitialise() @@ -111,13 +128,103 @@ namespace OpenSim.Region.ClientStack.Linden #endregion + ~WebFetchInvDescModule() + { + foreach (Thread t in m_workerThreads) + t.Abort(); + } + + private class PollServiceInventoryEventArgs : PollServiceEventArgs + { + private List requests = + new List(); + private Dictionary responses = + new Dictionary(); + + public PollServiceInventoryEventArgs(UUID pId) : + base(null, null, null, null, pId, 30000) + { + HasEvents = (x, y) => { return this.responses.ContainsKey(x); }; + GetEvents = (x, y, s) => + { + try + { + return this.responses[x]; + } + finally + { + responses.Remove(x); + } + }; + + Request = (x, y) => + { + y["RequestID"] = x.ToString(); + lock (this.requests) + this.requests.Add(y); + + m_queue.Enqueue(this); + }; + + NoEvents = (x, y) => + { + lock (this.requests) + { + Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString()); + requests.Remove(request); + } + + Hashtable response = new Hashtable(); + + response["int_response_code"] = 500; + response["str_response_string"] = "Script timeout"; + response["content_type"] = "text/plain"; + response["keepalive"] = false; + response["reusecontext"] = false; + + return response; + }; + } + + public void Process() + { + Hashtable request = null; + + try + { + lock (this.requests) + { + request = requests[0]; + requests.RemoveAt(0); + } + } + catch + { + return; + } + + UUID requestID = new UUID(request["RequestID"].ToString()); + + Hashtable response = new Hashtable(); + + response["int_response_code"] = 200; + response["content_type"] = "text/plain"; + response["keepalive"] = false; + response["reusecontext"] = false; + + response["str_response_string"] = m_webFetchHandler.FetchInventoryDescendentsRequest(request["body"].ToString(), String.Empty, String.Empty, null, null); + + responses[requestID] = response; + } + } + private void RegisterCaps(UUID agentID, Caps caps) { string capUrl = "/CAPS/" + UUID.Random() + "/"; // Register this as a poll service // absurd large timeout to tune later to make a bit less than viewer - PollServiceEventArgs args = new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, agentID, 300000); + PollServiceInventoryEventArgs args = new PollServiceInventoryEventArgs(agentID); args.Type = PollServiceEventArgs.EventType.Inventory; MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args); @@ -135,8 +242,6 @@ namespace OpenSim.Region.ClientStack.Linden caps.RegisterHandler("FetchInventoryDescendents2", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl)); m_capsDict[agentID] = capUrl; - - m_busy = false; } private void DeregisterCaps(UUID agentID, Caps caps) @@ -150,83 +255,14 @@ namespace OpenSim.Region.ClientStack.Linden } } - public void HttpRequestHandler(UUID requestID, Hashtable request) + private void DoInventoryRequests() { -// m_log.DebugFormat("[FETCH2]: Received request {0}", requestID); - lock(m_lock) - m_requests[requestID] = request; - } - - private bool HasEvents(UUID requestID, UUID sessionID) - { - lock (m_lock) + while (true) { - return !m_busy; - } - } - - private Hashtable NoEvents(UUID requestID, UUID sessionID) - { - lock(m_lock) - m_requests.Remove(requestID); - - Hashtable response = new Hashtable(); - - response["int_response_code"] = 500; - response["str_response_string"] = "Script timeout"; - response["content_type"] = "text/plain"; - response["keepalive"] = false; - response["reusecontext"] = false; - - lock (m_lock) - m_busy = false; + PollServiceInventoryEventArgs args = m_queue.Dequeue(); - return response; - } - - private Hashtable GetEvents(UUID requestID, UUID sessionID, string request) - { - lock (m_lock) - m_busy = true; - - Hashtable response = new Hashtable(); - - response["int_response_code"] = 500; - response["str_response_string"] = "Internal error"; - response["content_type"] = "text/plain"; - response["keepalive"] = false; - response["reusecontext"] = false; - - try - { - - Hashtable requestHash; - lock (m_lock) - { - if (!m_requests.TryGetValue(requestID, out requestHash)) - { - m_busy = false; - response["str_response_string"] = "Invalid request"; - return response; - } - m_requests.Remove(requestID); - } - -// m_log.DebugFormat("[FETCH2]: Processed request {0}", requestID); - - string reply = m_webFetchHandler.FetchInventoryDescendentsRequest(requestHash["body"].ToString(), String.Empty, String.Empty, null, null); - - - response["int_response_code"] = 200; - response["str_response_string"] = reply; - } - finally - { - lock (m_lock) - m_busy = false; + args.Process(); } - - return response; } } } -- cgit v1.1 From 94a8e5572b1529190a174f29f866b65e7b2ccc0e Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 11 Sep 2012 15:07:32 +0200 Subject: Remove the unused NewFileAgentInventoryVariablePrice module. --- .../NewFileAgentInventoryVariablePriceModule.cs | 296 --------------------- 1 file changed, 296 deletions(-) delete mode 100644 OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs deleted file mode 100644 index 52c4f44..0000000 --- a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections; -using System.Collections.Specialized; -using System.Reflection; -using System.IO; -using System.Web; -using Mono.Addins; -using log4net; -using Nini.Config; -using OpenMetaverse; -using OpenMetaverse.StructuredData; -using OpenSim.Framework; -using OpenSim.Framework.Servers; -using OpenSim.Framework.Servers.HttpServer; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes; -using OpenSim.Services.Interfaces; -using Caps = OpenSim.Framework.Capabilities.Caps; -using OpenSim.Framework.Capabilities; - -namespace OpenSim.Region.ClientStack.Linden -{ - [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] - public class NewFileAgentInventoryVariablePriceModule : INonSharedRegionModule - { -// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private Scene m_scene; -// private IAssetService m_assetService; - private bool m_dumpAssetsToFile = false; - private bool m_enabled = true; - private int m_levelUpload = 0; - - #region IRegionModuleBase Members - - - public Type ReplaceableInterface - { - get { return null; } - } - - public void Initialise(IConfigSource source) - { - IConfig meshConfig = source.Configs["Mesh"]; - if (meshConfig == null) - return; - - m_enabled = meshConfig.GetBoolean("AllowMeshUpload", true); - m_levelUpload = meshConfig.GetInt("LevelUpload", 0); - } - - public void AddRegion(Scene pScene) - { - m_scene = pScene; - } - - public void RemoveRegion(Scene scene) - { - - m_scene.EventManager.OnRegisterCaps -= RegisterCaps; - m_scene = null; - } - - public void RegionLoaded(Scene scene) - { - -// m_assetService = m_scene.RequestModuleInterface(); - m_scene.EventManager.OnRegisterCaps += RegisterCaps; - } - - #endregion - - - #region IRegionModule Members - - - - public void Close() { } - - public string Name { get { return "NewFileAgentInventoryVariablePriceModule"; } } - - - public void RegisterCaps(UUID agentID, Caps caps) - { - if(!m_enabled) - return; - - UUID capID = UUID.Random(); - -// m_log.Debug("[NEW FILE AGENT INVENTORY VARIABLE PRICE]: /CAPS/" + capID); - caps.RegisterHandler( - "NewFileAgentInventoryVariablePrice", - new LLSDStreamhandler( - "POST", - "/CAPS/" + capID.ToString(), - req => NewAgentInventoryRequest(req, agentID), - "NewFileAgentInventoryVariablePrice", - agentID.ToString())); - } - - #endregion - - 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 - // you need to be aware of this - - //if (llsdRequest.asset_type == "texture" || - // llsdRequest.asset_type == "animation" || - // llsdRequest.asset_type == "sound") - // { - // check user level - - ScenePresence avatar = null; - IClientAPI client = null; - m_scene.TryGetScenePresence(agentID, out avatar); - - if (avatar != null) - { - client = avatar.ControllingClient; - - if (avatar.UserLevel < m_levelUpload) - { - if (client != null) - client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false); - - LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); - errorResponse.rsvp = ""; - errorResponse.state = "error"; - return errorResponse; - } - } - - // check funds - IMoneyModule mm = m_scene.RequestModuleInterface(); - - if (mm != null) - { - if (!mm.UploadCovered(agentID, mm.UploadCharge)) - { - if (client != null) - client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); - - LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); - errorResponse.rsvp = ""; - errorResponse.state = "error"; - return errorResponse; - } - } - - // } - - string assetName = llsdRequest.name; - string assetDes = llsdRequest.description; - string capsBase = "/CAPS/NewFileAgentInventoryVariablePrice/"; - UUID newAsset = UUID.Random(); - UUID newInvItem = UUID.Random(); - 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); - - MainServer.Instance.AddStreamHandler( - new BinaryStreamHandler( - "POST", - capsBase + uploaderPath, - uploader.uploaderCaps, - "NewFileAgentInventoryVariablePrice", - agentID.ToString())); - - string protocol = "http://"; - - if (MainServer.Instance.UseSSL) - protocol = "https://"; - - string uploaderURL = protocol + m_scene.RegionInfo.ExternalHostName + ":" + MainServer.Instance.Port.ToString() + capsBase + - uploaderPath; - - - LLSDNewFileAngentInventoryVariablePriceReplyResponse uploadResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); - - uploadResponse.rsvp = uploaderURL; - uploadResponse.state = "upload"; - uploadResponse.resource_cost = 0; - uploadResponse.upload_price = 0; - - uploader.OnUpLoad += //UploadCompleteHandler; - - delegate( - string passetName, string passetDescription, UUID passetID, - UUID pinventoryItem, UUID pparentFolder, byte[] pdata, string pinventoryType, - string passetType) - { - UploadCompleteHandler(passetName, passetDescription, passetID, - pinventoryItem, pparentFolder, pdata, pinventoryType, - passetType,agentID); - }; - - return uploadResponse; - } - - public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, - UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, - string assetType,UUID AgentID) - { -// m_log.DebugFormat( -// "[NEW FILE AGENT INVENTORY VARIABLE PRICE MODULE]: Upload complete for {0}", inventoryItem); - - sbyte assType = 0; - sbyte inType = 0; - - if (inventoryType == "sound") - { - inType = 1; - assType = 1; - } - else if (inventoryType == "animation") - { - inType = 19; - assType = 20; - } - else if (inventoryType == "wearable") - { - inType = 18; - switch (assetType) - { - case "bodypart": - assType = 13; - break; - case "clothing": - assType = 5; - break; - } - } - else if (inventoryType == "mesh") - { - inType = (sbyte)InventoryType.Mesh; - assType = (sbyte)AssetType.Mesh; - } - - AssetBase asset; - asset = new AssetBase(assetID, assetName, assType, AgentID.ToString()); - asset.Data = data; - - if (m_scene.AssetService != null) - m_scene.AssetService.Store(asset); - - InventoryItemBase item = new InventoryItemBase(); - item.Owner = AgentID; - item.CreatorId = AgentID.ToString(); - item.ID = inventoryItem; - item.AssetID = asset.FullID; - item.Description = assetDescription; - item.Name = assetName; - item.AssetType = assType; - item.InvType = inType; - item.Folder = parentFolder; - item.CurrentPermissions - = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer); - item.BasePermissions = (uint)PermissionMask.All; - item.EveryOnePermissions = 0; - item.NextPermissions = (uint)PermissionMask.All; - item.CreationDate = Util.UnixTimeSinceEpoch(); - m_scene.AddInventoryItem(item); - } - } -} -- cgit v1.1 From bd1d9a214b7f8750427d670566c8f99ff62f33c4 Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 11 Sep 2012 17:28:13 +0200 Subject: Add the option to have variable costing for uploads --- .../Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 51 +++++++++++++++++++--- OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 4 +- 2 files changed, 46 insertions(+), 9 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 88c4d7f..097e224 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -60,7 +60,7 @@ namespace OpenSim.Region.ClientStack.Linden public delegate void UpdateTaskScript(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors); - public delegate void NewInventoryItem(UUID userID, InventoryItemBase item); + public delegate void NewInventoryItem(UUID userID, InventoryItemBase item, uint cost); public delegate void NewAsset(AssetBase asset); @@ -386,6 +386,38 @@ namespace OpenSim.Region.ClientStack.Linden return UUID.Zero; } + 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); + } + } + + /// /// /// @@ -396,6 +428,8 @@ namespace OpenSim.Region.ClientStack.Linden //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString()); //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type); + uint cost = 0; + if (llsdRequest.asset_type == "texture" || llsdRequest.asset_type == "animation" || llsdRequest.asset_type == "sound") @@ -428,7 +462,10 @@ namespace OpenSim.Region.ClientStack.Linden if (mm != null) { - if (!mm.UploadCovered(client.AgentId, mm.UploadCharge)) + // XPTO: The cost should be calculated about here + cost = (uint)mm.UploadCharge; + + if (!mm.UploadCovered(client.AgentId, (int)cost)) { client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); @@ -449,9 +486,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, m_HostCapsObj.HttpListener, m_dumpAssetsToFile); + AssetUploaderWithCost uploader = + new AssetUploaderWithCost(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, + llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile, cost); m_HostCapsObj.HttpListener.AddStreamHandler( new BinaryStreamHandler( @@ -484,7 +521,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) + string assetType, uint cost) { m_log.DebugFormat( "[BUNCH OF CAPS]: Uploaded asset {0} for inventory item {1}, inv type {2}, asset type {3}", @@ -703,7 +740,7 @@ namespace OpenSim.Region.ClientStack.Linden if (AddNewInventoryItem != null) { - AddNewInventoryItem(m_HostCapsObj.AgentID, item); + AddNewInventoryItem(m_HostCapsObj.AgentID, item, cost); } } diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 1309623..2d9a035 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -101,12 +101,12 @@ namespace OpenSim.Region.Framework.Scenes engine.StartProcessing(); } - public void AddUploadedInventoryItem(UUID agentID, InventoryItemBase item) + public void AddUploadedInventoryItem(UUID agentID, InventoryItemBase item, uint cost) { IMoneyModule money = RequestModuleInterface(); if (money != null) { - money.ApplyUploadCharge(agentID, money.UploadCharge, "Asset upload"); + money.ApplyUploadCharge(agentID, (int)cost, "Asset upload"); } AddInventoryItem(item); -- cgit v1.1 From ead4b8998c07c4c5445b56fab955dfbdf0bf212f Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 11 Sep 2012 17:28:37 +0200 Subject: Revert "Remove the unused NewFileAgentInventoryVariablePrice module." It's actually used. This reverts commit 94a8e5572b1529190a174f29f866b65e7b2ccc0e. --- .../NewFileAgentInventoryVariablePriceModule.cs | 296 +++++++++++++++++++++ 1 file changed, 296 insertions(+) create mode 100644 OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs new file mode 100644 index 0000000..52c4f44 --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs @@ -0,0 +1,296 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Specialized; +using System.Reflection; +using System.IO; +using System.Web; +using Mono.Addins; +using log4net; +using Nini.Config; +using OpenMetaverse; +using OpenMetaverse.StructuredData; +using OpenSim.Framework; +using OpenSim.Framework.Servers; +using OpenSim.Framework.Servers.HttpServer; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; +using Caps = OpenSim.Framework.Capabilities.Caps; +using OpenSim.Framework.Capabilities; + +namespace OpenSim.Region.ClientStack.Linden +{ + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] + public class NewFileAgentInventoryVariablePriceModule : INonSharedRegionModule + { +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private Scene m_scene; +// private IAssetService m_assetService; + private bool m_dumpAssetsToFile = false; + private bool m_enabled = true; + private int m_levelUpload = 0; + + #region IRegionModuleBase Members + + + public Type ReplaceableInterface + { + get { return null; } + } + + public void Initialise(IConfigSource source) + { + IConfig meshConfig = source.Configs["Mesh"]; + if (meshConfig == null) + return; + + m_enabled = meshConfig.GetBoolean("AllowMeshUpload", true); + m_levelUpload = meshConfig.GetInt("LevelUpload", 0); + } + + public void AddRegion(Scene pScene) + { + m_scene = pScene; + } + + public void RemoveRegion(Scene scene) + { + + m_scene.EventManager.OnRegisterCaps -= RegisterCaps; + m_scene = null; + } + + public void RegionLoaded(Scene scene) + { + +// m_assetService = m_scene.RequestModuleInterface(); + m_scene.EventManager.OnRegisterCaps += RegisterCaps; + } + + #endregion + + + #region IRegionModule Members + + + + public void Close() { } + + public string Name { get { return "NewFileAgentInventoryVariablePriceModule"; } } + + + public void RegisterCaps(UUID agentID, Caps caps) + { + if(!m_enabled) + return; + + UUID capID = UUID.Random(); + +// m_log.Debug("[NEW FILE AGENT INVENTORY VARIABLE PRICE]: /CAPS/" + capID); + caps.RegisterHandler( + "NewFileAgentInventoryVariablePrice", + new LLSDStreamhandler( + "POST", + "/CAPS/" + capID.ToString(), + req => NewAgentInventoryRequest(req, agentID), + "NewFileAgentInventoryVariablePrice", + agentID.ToString())); + } + + #endregion + + 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 + // you need to be aware of this + + //if (llsdRequest.asset_type == "texture" || + // llsdRequest.asset_type == "animation" || + // llsdRequest.asset_type == "sound") + // { + // check user level + + ScenePresence avatar = null; + IClientAPI client = null; + m_scene.TryGetScenePresence(agentID, out avatar); + + if (avatar != null) + { + client = avatar.ControllingClient; + + if (avatar.UserLevel < m_levelUpload) + { + if (client != null) + client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false); + + LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); + errorResponse.rsvp = ""; + errorResponse.state = "error"; + return errorResponse; + } + } + + // check funds + IMoneyModule mm = m_scene.RequestModuleInterface(); + + if (mm != null) + { + if (!mm.UploadCovered(agentID, mm.UploadCharge)) + { + if (client != null) + client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); + + LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); + errorResponse.rsvp = ""; + errorResponse.state = "error"; + return errorResponse; + } + } + + // } + + string assetName = llsdRequest.name; + string assetDes = llsdRequest.description; + string capsBase = "/CAPS/NewFileAgentInventoryVariablePrice/"; + UUID newAsset = UUID.Random(); + UUID newInvItem = UUID.Random(); + 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); + + MainServer.Instance.AddStreamHandler( + new BinaryStreamHandler( + "POST", + capsBase + uploaderPath, + uploader.uploaderCaps, + "NewFileAgentInventoryVariablePrice", + agentID.ToString())); + + string protocol = "http://"; + + if (MainServer.Instance.UseSSL) + protocol = "https://"; + + string uploaderURL = protocol + m_scene.RegionInfo.ExternalHostName + ":" + MainServer.Instance.Port.ToString() + capsBase + + uploaderPath; + + + LLSDNewFileAngentInventoryVariablePriceReplyResponse uploadResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); + + uploadResponse.rsvp = uploaderURL; + uploadResponse.state = "upload"; + uploadResponse.resource_cost = 0; + uploadResponse.upload_price = 0; + + uploader.OnUpLoad += //UploadCompleteHandler; + + delegate( + string passetName, string passetDescription, UUID passetID, + UUID pinventoryItem, UUID pparentFolder, byte[] pdata, string pinventoryType, + string passetType) + { + UploadCompleteHandler(passetName, passetDescription, passetID, + pinventoryItem, pparentFolder, pdata, pinventoryType, + passetType,agentID); + }; + + return uploadResponse; + } + + public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, + UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, + string assetType,UUID AgentID) + { +// m_log.DebugFormat( +// "[NEW FILE AGENT INVENTORY VARIABLE PRICE MODULE]: Upload complete for {0}", inventoryItem); + + sbyte assType = 0; + sbyte inType = 0; + + if (inventoryType == "sound") + { + inType = 1; + assType = 1; + } + else if (inventoryType == "animation") + { + inType = 19; + assType = 20; + } + else if (inventoryType == "wearable") + { + inType = 18; + switch (assetType) + { + case "bodypart": + assType = 13; + break; + case "clothing": + assType = 5; + break; + } + } + else if (inventoryType == "mesh") + { + inType = (sbyte)InventoryType.Mesh; + assType = (sbyte)AssetType.Mesh; + } + + AssetBase asset; + asset = new AssetBase(assetID, assetName, assType, AgentID.ToString()); + asset.Data = data; + + if (m_scene.AssetService != null) + m_scene.AssetService.Store(asset); + + InventoryItemBase item = new InventoryItemBase(); + item.Owner = AgentID; + item.CreatorId = AgentID.ToString(); + item.ID = inventoryItem; + item.AssetID = asset.FullID; + item.Description = assetDescription; + item.Name = assetName; + item.AssetType = assType; + item.InvType = inType; + item.Folder = parentFolder; + item.CurrentPermissions + = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer); + item.BasePermissions = (uint)PermissionMask.All; + item.EveryOnePermissions = 0; + item.NextPermissions = (uint)PermissionMask.All; + item.CreationDate = Util.UnixTimeSinceEpoch(); + m_scene.AddInventoryItem(item); + } + } +} -- cgit v1.1 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(-) (limited to 'OpenSim') 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 From 375ca478dd7bebd6825e6305ba7c8a44fe119c7e Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 11 Sep 2012 17:52:24 +0200 Subject: Rename NewFileAgentInventoryVariablePrice to NewAgentInventoryVariablePrice which is the name actually used in viewer code. --- .../NewFileAgentInventoryVariablePriceModule.cs | 332 --------------------- 1 file changed, 332 deletions(-) delete mode 100644 OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs deleted file mode 100644 index 6e2b52d..0000000 --- a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs +++ /dev/null @@ -1,332 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections; -using System.Collections.Specialized; -using System.Reflection; -using System.IO; -using System.Web; -using Mono.Addins; -using log4net; -using Nini.Config; -using OpenMetaverse; -using OpenMetaverse.StructuredData; -using OpenSim.Framework; -using OpenSim.Framework.Servers; -using OpenSim.Framework.Servers.HttpServer; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes; -using OpenSim.Services.Interfaces; -using Caps = OpenSim.Framework.Capabilities.Caps; -using OpenSim.Framework.Capabilities; - -namespace OpenSim.Region.ClientStack.Linden -{ - [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] - public class NewFileAgentInventoryVariablePriceModule : INonSharedRegionModule - { -// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private Scene m_scene; -// private IAssetService m_assetService; - private bool m_dumpAssetsToFile = false; - private bool m_enabled = true; - private int m_levelUpload = 0; - - #region IRegionModuleBase Members - - - public Type ReplaceableInterface - { - get { return null; } - } - - public void Initialise(IConfigSource source) - { - IConfig meshConfig = source.Configs["Mesh"]; - if (meshConfig == null) - return; - - m_enabled = meshConfig.GetBoolean("AllowMeshUpload", true); - m_levelUpload = meshConfig.GetInt("LevelUpload", 0); - } - - public void AddRegion(Scene pScene) - { - m_scene = pScene; - } - - public void RemoveRegion(Scene scene) - { - - m_scene.EventManager.OnRegisterCaps -= RegisterCaps; - m_scene = null; - } - - public void RegionLoaded(Scene scene) - { - -// m_assetService = m_scene.RequestModuleInterface(); - m_scene.EventManager.OnRegisterCaps += RegisterCaps; - } - - #endregion - - - #region IRegionModule Members - - - - public void Close() { } - - public string Name { get { return "NewFileAgentInventoryVariablePriceModule"; } } - - - public void RegisterCaps(UUID agentID, Caps caps) - { - if(!m_enabled) - return; - - UUID capID = UUID.Random(); - -// m_log.Debug("[NEW FILE AGENT INVENTORY VARIABLE PRICE]: /CAPS/" + capID); - caps.RegisterHandler( - "NewFileAgentInventoryVariablePrice", - new LLSDStreamhandler( - "POST", - "/CAPS/" + capID.ToString(), - req => NewAgentInventoryRequest(req, agentID), - "NewFileAgentInventoryVariablePrice", - agentID.ToString())); - } - - #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 - // you need to be aware of this - - //if (llsdRequest.asset_type == "texture" || - // llsdRequest.asset_type == "animation" || - // llsdRequest.asset_type == "sound") - // { - // check user level - - uint cost = 0; - - ScenePresence avatar = null; - IClientAPI client = null; - m_scene.TryGetScenePresence(agentID, out avatar); - - if (avatar != null) - { - client = avatar.ControllingClient; - - if (avatar.UserLevel < m_levelUpload) - { - if (client != null) - client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false); - - LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); - errorResponse.rsvp = ""; - errorResponse.state = "error"; - return errorResponse; - } - } - - // check funds - IMoneyModule mm = m_scene.RequestModuleInterface(); - - if (mm != null) - { - // 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); - - LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); - errorResponse.rsvp = ""; - errorResponse.state = "error"; - return errorResponse; - } - } - - // } - - string assetName = llsdRequest.name; - string assetDes = llsdRequest.description; - string capsBase = "/CAPS/NewFileAgentInventoryVariablePrice/"; - UUID newAsset = UUID.Random(); - UUID newInvItem = UUID.Random(); - UUID parentFolder = llsdRequest.folder_id; - string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000") + "/"; - - 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( - "POST", - capsBase + uploaderPath, - uploader.uploaderCaps, - "NewFileAgentInventoryVariablePrice", - agentID.ToString())); - - string protocol = "http://"; - - if (MainServer.Instance.UseSSL) - protocol = "https://"; - - string uploaderURL = protocol + m_scene.RegionInfo.ExternalHostName + ":" + MainServer.Instance.Port.ToString() + capsBase + - uploaderPath; - - - LLSDNewFileAngentInventoryVariablePriceReplyResponse uploadResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); - - uploadResponse.rsvp = uploaderURL; - uploadResponse.state = "upload"; - uploadResponse.resource_cost = 0; - uploadResponse.upload_price = 0; - - uploader.OnUpLoad += //UploadCompleteHandler; - - delegate( - string passetName, string passetDescription, UUID passetID, - UUID pinventoryItem, UUID pparentFolder, byte[] pdata, string pinventoryType, - string passetType, uint cost) - { - UploadCompleteHandler(passetName, passetDescription, passetID, - pinventoryItem, pparentFolder, pdata, pinventoryType, - passetType,agentID, cost); - }; - - return uploadResponse; - } - - public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, - UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, - string assetType,UUID AgentID, uint cost) - { -// m_log.DebugFormat( -// "[NEW FILE AGENT INVENTORY VARIABLE PRICE MODULE]: Upload complete for {0}", inventoryItem); - - sbyte assType = 0; - sbyte inType = 0; - - if (inventoryType == "sound") - { - inType = 1; - assType = 1; - } - else if (inventoryType == "animation") - { - inType = 19; - assType = 20; - } - else if (inventoryType == "wearable") - { - inType = 18; - switch (assetType) - { - case "bodypart": - assType = 13; - break; - case "clothing": - assType = 5; - break; - } - } - else if (inventoryType == "mesh") - { - inType = (sbyte)InventoryType.Mesh; - assType = (sbyte)AssetType.Mesh; - } - - AssetBase asset; - asset = new AssetBase(assetID, assetName, assType, AgentID.ToString()); - asset.Data = data; - - if (m_scene.AssetService != null) - m_scene.AssetService.Store(asset); - - InventoryItemBase item = new InventoryItemBase(); - item.Owner = AgentID; - item.CreatorId = AgentID.ToString(); - item.ID = inventoryItem; - item.AssetID = asset.FullID; - item.Description = assetDescription; - item.Name = assetName; - item.AssetType = assType; - item.InvType = inType; - item.Folder = parentFolder; - item.CurrentPermissions - = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer); - item.BasePermissions = (uint)PermissionMask.All; - item.EveryOnePermissions = 0; - item.NextPermissions = (uint)PermissionMask.All; - item.CreationDate = Util.UnixTimeSinceEpoch(); - m_scene.AddUploadedInventoryItem(AgentID, item, cost); - } - } -} -- cgit v1.1 From 757a669924db1a68ed75640816c8b9d32a6146e1 Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 11 Sep 2012 17:55:33 +0200 Subject: Re-add the module and fix a typo --- .../Caps/NewAgentInventoryVariablePriceModule.cs | 332 +++++++++++++++++++++ 1 file changed, 332 insertions(+) create mode 100644 OpenSim/Region/ClientStack/Linden/Caps/NewAgentInventoryVariablePriceModule.cs (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/NewAgentInventoryVariablePriceModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/NewAgentInventoryVariablePriceModule.cs new file mode 100644 index 0000000..423ad58 --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/Caps/NewAgentInventoryVariablePriceModule.cs @@ -0,0 +1,332 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Specialized; +using System.Reflection; +using System.IO; +using System.Web; +using Mono.Addins; +using log4net; +using Nini.Config; +using OpenMetaverse; +using OpenMetaverse.StructuredData; +using OpenSim.Framework; +using OpenSim.Framework.Servers; +using OpenSim.Framework.Servers.HttpServer; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; +using Caps = OpenSim.Framework.Capabilities.Caps; +using OpenSim.Framework.Capabilities; + +namespace OpenSim.Region.ClientStack.Linden +{ + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] + public class NewAgentInventoryVariablePriceModule : INonSharedRegionModule + { +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private Scene m_scene; +// private IAssetService m_assetService; + private bool m_dumpAssetsToFile = false; + private bool m_enabled = true; + private int m_levelUpload = 0; + + #region IRegionModuleBase Members + + + public Type ReplaceableInterface + { + get { return null; } + } + + public void Initialise(IConfigSource source) + { + IConfig meshConfig = source.Configs["Mesh"]; + if (meshConfig == null) + return; + + m_enabled = meshConfig.GetBoolean("AllowMeshUpload", true); + m_levelUpload = meshConfig.GetInt("LevelUpload", 0); + } + + public void AddRegion(Scene pScene) + { + m_scene = pScene; + } + + public void RemoveRegion(Scene scene) + { + + m_scene.EventManager.OnRegisterCaps -= RegisterCaps; + m_scene = null; + } + + public void RegionLoaded(Scene scene) + { + +// m_assetService = m_scene.RequestModuleInterface(); + m_scene.EventManager.OnRegisterCaps += RegisterCaps; + } + + #endregion + + + #region IRegionModule Members + + + + public void Close() { } + + public string Name { get { return "NewAgentInventoryVariablePriceModule"; } } + + + public void RegisterCaps(UUID agentID, Caps caps) + { + if(!m_enabled) + return; + + UUID capID = UUID.Random(); + +// m_log.Debug("[NEW FILE AGENT INVENTORY VARIABLE PRICE]: /CAPS/" + capID); + caps.RegisterHandler( + "NewAgentInventoryVariablePrice", + new LLSDStreamhandler( + "POST", + "/CAPS/" + capID.ToString(), + req => NewAgentInventoryRequest(req, agentID), + "NewAgentInventoryVariablePrice", + agentID.ToString())); + } + + #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 + // you need to be aware of this + + //if (llsdRequest.asset_type == "texture" || + // llsdRequest.asset_type == "animation" || + // llsdRequest.asset_type == "sound") + // { + // check user level + + uint cost = 0; + + ScenePresence avatar = null; + IClientAPI client = null; + m_scene.TryGetScenePresence(agentID, out avatar); + + if (avatar != null) + { + client = avatar.ControllingClient; + + if (avatar.UserLevel < m_levelUpload) + { + if (client != null) + client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false); + + LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); + errorResponse.rsvp = ""; + errorResponse.state = "error"; + return errorResponse; + } + } + + // check funds + IMoneyModule mm = m_scene.RequestModuleInterface(); + + if (mm != null) + { + // 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); + + LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); + errorResponse.rsvp = ""; + errorResponse.state = "error"; + return errorResponse; + } + } + + // } + + string assetName = llsdRequest.name; + string assetDes = llsdRequest.description; + string capsBase = "/CAPS/NewAgentInventoryVariablePrice/"; + UUID newAsset = UUID.Random(); + UUID newInvItem = UUID.Random(); + UUID parentFolder = llsdRequest.folder_id; + string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000") + "/"; + + 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( + "POST", + capsBase + uploaderPath, + uploader.uploaderCaps, + "NewAgentInventoryVariablePrice", + agentID.ToString())); + + string protocol = "http://"; + + if (MainServer.Instance.UseSSL) + protocol = "https://"; + + string uploaderURL = protocol + m_scene.RegionInfo.ExternalHostName + ":" + MainServer.Instance.Port.ToString() + capsBase + + uploaderPath; + + + LLSDNewFileAngentInventoryVariablePriceReplyResponse uploadResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); + + uploadResponse.rsvp = uploaderURL; + uploadResponse.state = "upload"; + uploadResponse.resource_cost = 0; + uploadResponse.upload_price = 0; + + uploader.OnUpLoad += //UploadCompleteHandler; + + delegate( + string passetName, string passetDescription, UUID passetID, + UUID pinventoryItem, UUID pparentFolder, byte[] pdata, string pinventoryType, + string passetType, uint pcost) + { + UploadCompleteHandler(passetName, passetDescription, passetID, + pinventoryItem, pparentFolder, pdata, pinventoryType, + passetType,agentID, pcost); + }; + + return uploadResponse; + } + + public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, + UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, + string assetType,UUID AgentID, uint cost) + { +// m_log.DebugFormat( +// "[NEW FILE AGENT INVENTORY VARIABLE PRICE MODULE]: Upload complete for {0}", inventoryItem); + + sbyte assType = 0; + sbyte inType = 0; + + if (inventoryType == "sound") + { + inType = 1; + assType = 1; + } + else if (inventoryType == "animation") + { + inType = 19; + assType = 20; + } + else if (inventoryType == "wearable") + { + inType = 18; + switch (assetType) + { + case "bodypart": + assType = 13; + break; + case "clothing": + assType = 5; + break; + } + } + else if (inventoryType == "mesh") + { + inType = (sbyte)InventoryType.Mesh; + assType = (sbyte)AssetType.Mesh; + } + + AssetBase asset; + asset = new AssetBase(assetID, assetName, assType, AgentID.ToString()); + asset.Data = data; + + if (m_scene.AssetService != null) + m_scene.AssetService.Store(asset); + + InventoryItemBase item = new InventoryItemBase(); + item.Owner = AgentID; + item.CreatorId = AgentID.ToString(); + item.ID = inventoryItem; + item.AssetID = asset.FullID; + item.Description = assetDescription; + item.Name = assetName; + item.AssetType = assType; + item.InvType = inType; + item.Folder = parentFolder; + item.CurrentPermissions + = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer); + item.BasePermissions = (uint)PermissionMask.All; + item.EveryOnePermissions = 0; + item.NextPermissions = (uint)PermissionMask.All; + item.CreationDate = Util.UnixTimeSinceEpoch(); + m_scene.AddUploadedInventoryItem(AgentID, item, cost); + } + } +} -- cgit v1.1 From 19b00a5b3ce27d3160648c6bc49699b09dc4f283 Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 11 Sep 2012 17:58:46 +0200 Subject: Removing the variable prica handler again. It's never called, was misnamed and probably never worked past the mesh beta. --- .../Caps/NewAgentInventoryVariablePriceModule.cs | 332 --------------------- 1 file changed, 332 deletions(-) delete mode 100644 OpenSim/Region/ClientStack/Linden/Caps/NewAgentInventoryVariablePriceModule.cs (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/NewAgentInventoryVariablePriceModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/NewAgentInventoryVariablePriceModule.cs deleted file mode 100644 index 423ad58..0000000 --- a/OpenSim/Region/ClientStack/Linden/Caps/NewAgentInventoryVariablePriceModule.cs +++ /dev/null @@ -1,332 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections; -using System.Collections.Specialized; -using System.Reflection; -using System.IO; -using System.Web; -using Mono.Addins; -using log4net; -using Nini.Config; -using OpenMetaverse; -using OpenMetaverse.StructuredData; -using OpenSim.Framework; -using OpenSim.Framework.Servers; -using OpenSim.Framework.Servers.HttpServer; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes; -using OpenSim.Services.Interfaces; -using Caps = OpenSim.Framework.Capabilities.Caps; -using OpenSim.Framework.Capabilities; - -namespace OpenSim.Region.ClientStack.Linden -{ - [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] - public class NewAgentInventoryVariablePriceModule : INonSharedRegionModule - { -// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private Scene m_scene; -// private IAssetService m_assetService; - private bool m_dumpAssetsToFile = false; - private bool m_enabled = true; - private int m_levelUpload = 0; - - #region IRegionModuleBase Members - - - public Type ReplaceableInterface - { - get { return null; } - } - - public void Initialise(IConfigSource source) - { - IConfig meshConfig = source.Configs["Mesh"]; - if (meshConfig == null) - return; - - m_enabled = meshConfig.GetBoolean("AllowMeshUpload", true); - m_levelUpload = meshConfig.GetInt("LevelUpload", 0); - } - - public void AddRegion(Scene pScene) - { - m_scene = pScene; - } - - public void RemoveRegion(Scene scene) - { - - m_scene.EventManager.OnRegisterCaps -= RegisterCaps; - m_scene = null; - } - - public void RegionLoaded(Scene scene) - { - -// m_assetService = m_scene.RequestModuleInterface(); - m_scene.EventManager.OnRegisterCaps += RegisterCaps; - } - - #endregion - - - #region IRegionModule Members - - - - public void Close() { } - - public string Name { get { return "NewAgentInventoryVariablePriceModule"; } } - - - public void RegisterCaps(UUID agentID, Caps caps) - { - if(!m_enabled) - return; - - UUID capID = UUID.Random(); - -// m_log.Debug("[NEW FILE AGENT INVENTORY VARIABLE PRICE]: /CAPS/" + capID); - caps.RegisterHandler( - "NewAgentInventoryVariablePrice", - new LLSDStreamhandler( - "POST", - "/CAPS/" + capID.ToString(), - req => NewAgentInventoryRequest(req, agentID), - "NewAgentInventoryVariablePrice", - agentID.ToString())); - } - - #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 - // you need to be aware of this - - //if (llsdRequest.asset_type == "texture" || - // llsdRequest.asset_type == "animation" || - // llsdRequest.asset_type == "sound") - // { - // check user level - - uint cost = 0; - - ScenePresence avatar = null; - IClientAPI client = null; - m_scene.TryGetScenePresence(agentID, out avatar); - - if (avatar != null) - { - client = avatar.ControllingClient; - - if (avatar.UserLevel < m_levelUpload) - { - if (client != null) - client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false); - - LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); - errorResponse.rsvp = ""; - errorResponse.state = "error"; - return errorResponse; - } - } - - // check funds - IMoneyModule mm = m_scene.RequestModuleInterface(); - - if (mm != null) - { - // 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); - - LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); - errorResponse.rsvp = ""; - errorResponse.state = "error"; - return errorResponse; - } - } - - // } - - string assetName = llsdRequest.name; - string assetDes = llsdRequest.description; - string capsBase = "/CAPS/NewAgentInventoryVariablePrice/"; - UUID newAsset = UUID.Random(); - UUID newInvItem = UUID.Random(); - UUID parentFolder = llsdRequest.folder_id; - string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000") + "/"; - - 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( - "POST", - capsBase + uploaderPath, - uploader.uploaderCaps, - "NewAgentInventoryVariablePrice", - agentID.ToString())); - - string protocol = "http://"; - - if (MainServer.Instance.UseSSL) - protocol = "https://"; - - string uploaderURL = protocol + m_scene.RegionInfo.ExternalHostName + ":" + MainServer.Instance.Port.ToString() + capsBase + - uploaderPath; - - - LLSDNewFileAngentInventoryVariablePriceReplyResponse uploadResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); - - uploadResponse.rsvp = uploaderURL; - uploadResponse.state = "upload"; - uploadResponse.resource_cost = 0; - uploadResponse.upload_price = 0; - - uploader.OnUpLoad += //UploadCompleteHandler; - - delegate( - string passetName, string passetDescription, UUID passetID, - UUID pinventoryItem, UUID pparentFolder, byte[] pdata, string pinventoryType, - string passetType, uint pcost) - { - UploadCompleteHandler(passetName, passetDescription, passetID, - pinventoryItem, pparentFolder, pdata, pinventoryType, - passetType,agentID, pcost); - }; - - return uploadResponse; - } - - public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, - UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, - string assetType,UUID AgentID, uint cost) - { -// m_log.DebugFormat( -// "[NEW FILE AGENT INVENTORY VARIABLE PRICE MODULE]: Upload complete for {0}", inventoryItem); - - sbyte assType = 0; - sbyte inType = 0; - - if (inventoryType == "sound") - { - inType = 1; - assType = 1; - } - else if (inventoryType == "animation") - { - inType = 19; - assType = 20; - } - else if (inventoryType == "wearable") - { - inType = 18; - switch (assetType) - { - case "bodypart": - assType = 13; - break; - case "clothing": - assType = 5; - break; - } - } - else if (inventoryType == "mesh") - { - inType = (sbyte)InventoryType.Mesh; - assType = (sbyte)AssetType.Mesh; - } - - AssetBase asset; - asset = new AssetBase(assetID, assetName, assType, AgentID.ToString()); - asset.Data = data; - - if (m_scene.AssetService != null) - m_scene.AssetService.Store(asset); - - InventoryItemBase item = new InventoryItemBase(); - item.Owner = AgentID; - item.CreatorId = AgentID.ToString(); - item.ID = inventoryItem; - item.AssetID = asset.FullID; - item.Description = assetDescription; - item.Name = assetName; - item.AssetType = assType; - item.InvType = inType; - item.Folder = parentFolder; - item.CurrentPermissions - = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer); - item.BasePermissions = (uint)PermissionMask.All; - item.EveryOnePermissions = 0; - item.NextPermissions = (uint)PermissionMask.All; - item.CreationDate = Util.UnixTimeSinceEpoch(); - m_scene.AddUploadedInventoryItem(AgentID, item, cost); - } - } -} -- cgit v1.1 From 245763b1b08d667aede3be7c092fa4c7200549c0 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 11 Sep 2012 20:30:30 +0100 Subject: let LLSDAssetUploadRequest include asset_resources information plus let NewAgentInventoryRequest know about mesh (does nothing with it still) --- OpenSim/Capabilities/LLSDAssetUploadRequest.cs | 11 ++++++++++- .../Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Capabilities/LLSDAssetUploadRequest.cs b/OpenSim/Capabilities/LLSDAssetUploadRequest.cs index 6e66f0a..f981bf0 100644 --- a/OpenSim/Capabilities/LLSDAssetUploadRequest.cs +++ b/OpenSim/Capabilities/LLSDAssetUploadRequest.cs @@ -31,6 +31,15 @@ using OpenMetaverse; namespace OpenSim.Framework.Capabilities { [OSDMap] + public class LLSDAssetResource + { + public OSDArray instance_list = new OSDArray(); + public OSDArray texture_list = new OSDArray(); + public OSDArray mesh_list = new OSDArray(); + public string metric = String.Empty; + } + + [OSDMap] public class LLSDAssetUploadRequest { public string asset_type = String.Empty; @@ -38,7 +47,7 @@ namespace OpenSim.Framework.Capabilities public UUID folder_id = UUID.Zero; public string inventory_type = String.Empty; public string name = String.Empty; - + public LLSDAssetResource asset_resources = new LLSDAssetResource(); public LLSDAssetUploadRequest() { } diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 328dc75..df43991 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -431,6 +431,7 @@ namespace OpenSim.Region.ClientStack.Linden if (llsdRequest.asset_type == "texture" || llsdRequest.asset_type == "animation" || + llsdRequest.asset_type == "mesh" || llsdRequest.asset_type == "sound") { ScenePresence avatar = null; -- cgit v1.1 From 013e94af5d45a7c99e46e01d9c5965a79ac1b231 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 11 Sep 2012 23:06:29 +0100 Subject: report mesh upload costs ( fake values) --- OpenSim/Capabilities/LLSDAssetUploadResponse.cs | 23 ++++++++++- .../Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 48 +++++++++++++++++++++- 2 files changed, 68 insertions(+), 3 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Capabilities/LLSDAssetUploadResponse.cs b/OpenSim/Capabilities/LLSDAssetUploadResponse.cs index 0d6f7f9..18285b5 100644 --- a/OpenSim/Capabilities/LLSDAssetUploadResponse.cs +++ b/OpenSim/Capabilities/LLSDAssetUploadResponse.cs @@ -30,11 +30,32 @@ using System; namespace OpenSim.Framework.Capabilities { [OSDMap] + public class LLSDAssetUploadResponsePricebrkDown + { + public int mesh_streaming; + public int mesh_physics; + public int mesh_instance; + public int texture; + public int model; + } + + [OSDMap] + public class LLSDAssetUploadResponseData + { + public double resource_cost; + public double model_streaming_cost; + public double simulation_cost; + public double physics_cost; + public LLSDAssetUploadResponsePricebrkDown upload_price_breakdown = new LLSDAssetUploadResponsePricebrkDown(); + } + + [OSDMap] public class LLSDAssetUploadResponse { public string uploader = String.Empty; public string state = String.Empty; - + public int upload_price = 0; + public LLSDAssetUploadResponseData data = null; public LLSDAssetUploadResponse() { } diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index df43991..90ac8ce 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -463,7 +463,26 @@ namespace OpenSim.Region.ClientStack.Linden if (mm != null) { // XPTO: The cost should be calculated about here - cost = (uint)mm.UploadCharge; + + if (llsdRequest.asset_type == "mesh") + { + if (llsdRequest.asset_resources == null) + { + client.SendAgentAlertMessage("Unable to upload asset. missing information.", false); + + LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); + errorResponse.uploader = ""; + errorResponse.state = "error"; + return errorResponse; + } + + uint textures_cost = (uint)llsdRequest.asset_resources.texture_list.Array.Count; + textures_cost *= (uint)mm.UploadCharge; + + cost = textures_cost; + } + else + cost = (uint)mm.UploadCharge; if (!mm.UploadCovered(client.AgentId, (int)cost)) { @@ -486,9 +505,14 @@ namespace OpenSim.Region.ClientStack.Linden UUID parentFolder = llsdRequest.folder_id; string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); + uint uploadCost = cost; + // don't charge for meshs until we done them + if (llsdRequest.asset_type == "mesh") + uploadCost = 0; + AssetUploaderWithCost uploader = new AssetUploaderWithCost(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, - llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile, cost); + llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile, uploadCost); m_HostCapsObj.HttpListener.AddStreamHandler( new BinaryStreamHandler( @@ -506,11 +530,31 @@ namespace OpenSim.Region.ClientStack.Linden string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase + uploaderPath; + LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); uploadResponse.uploader = uploaderURL; uploadResponse.state = "upload"; + uploadResponse.upload_price = (int)cost; + + // use fake values for now + if (llsdRequest.asset_type == "mesh") + { + uploadResponse.data = new LLSDAssetUploadResponseData(); + uploadResponse.data.model_streaming_cost = 1.0; + uploadResponse.data.simulation_cost = 1.5; + + uploadResponse.data.physics_cost = 2.0; + uploadResponse.data.resource_cost = 3.0; + uploadResponse.data.upload_price_breakdown.mesh_instance = 1; + uploadResponse.data.upload_price_breakdown.mesh_physics = 2; + uploadResponse.data.upload_price_breakdown.mesh_streaming = 3; + uploadResponse.data.upload_price_breakdown.texture = 5; + uploadResponse.data.upload_price_breakdown.model = 4; + } + uploader.OnUpLoad += UploadCompleteHandler; return uploadResponse; + } /// -- cgit v1.1 From fd1ee58f87dfbad96e89675bf5ab002d2d3a347f Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 11 Sep 2012 22:52:11 +0200 Subject: Add a missing brace, remove a useless temp variable, enable charging. --- .../Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 90ac8ce..9982556 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -482,7 +482,9 @@ namespace OpenSim.Region.ClientStack.Linden cost = textures_cost; } else + { cost = (uint)mm.UploadCharge; + } if (!mm.UploadCovered(client.AgentId, (int)cost)) { @@ -505,14 +507,9 @@ namespace OpenSim.Region.ClientStack.Linden UUID parentFolder = llsdRequest.folder_id; string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); - uint uploadCost = cost; - // don't charge for meshs until we done them - if (llsdRequest.asset_type == "mesh") - uploadCost = 0; - AssetUploaderWithCost uploader = new AssetUploaderWithCost(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, - llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile, uploadCost); + llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile, cost); m_HostCapsObj.HttpListener.AddStreamHandler( new BinaryStreamHandler( -- cgit v1.1 From 5139db2638fcee945961ea8d5635def581b54a4d Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 12 Sep 2012 12:56:59 +0200 Subject: Add a timer to time out upload caps handlers that are not used. --- .../ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 9982556..c4a9a19 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -26,6 +26,7 @@ */ using System; +using System.Timers; using System.Collections; using System.Collections.Generic; using System.IO; @@ -1106,6 +1107,7 @@ namespace OpenSim.Region.ClientStack.Linden private string m_invType = String.Empty; private string m_assetType = String.Empty; + private Timer m_timeoutTimer = new Timer(); public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem, UUID parentFolderID, string invType, string assetType, string path, @@ -1121,6 +1123,11 @@ namespace OpenSim.Region.ClientStack.Linden m_assetType = assetType; m_invType = invType; m_dumpAssetsToFile = dumpAssetsToFile; + + m_timeoutTimer.Elapsed += TimedOut; + m_timeoutTimer.Interval = 120000; + m_timeoutTimer.AutoReset = false; + m_timeoutTimer.Start(); } /// @@ -1163,6 +1170,11 @@ namespace OpenSim.Region.ClientStack.Linden return res; } + private void TimedOut(object sender, ElapsedEventArgs args) + { + httpListener.RemoveStreamHandler("POST", uploaderPath); + } + ///Left this in and commented in case there are unforseen issues //private void SaveAssetToFile(string filename, byte[] data) //{ -- cgit v1.1 From d8e9188908bd1f6ab505e5424f02071b44f0fab1 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 12 Sep 2012 21:14:55 +0200 Subject: Stop expiry timer when upload is complete. Log if timeout is reached. --- OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index c4a9a19..116055a 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -1149,6 +1149,7 @@ namespace OpenSim.Region.ClientStack.Linden res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); httpListener.RemoveStreamHandler("POST", uploaderPath); + m_timeoutTimer.Stop(); // TODO: probably make this a better set of extensions here string extension = ".jp2"; @@ -1172,6 +1173,7 @@ namespace OpenSim.Region.ClientStack.Linden private void TimedOut(object sender, ElapsedEventArgs args) { + m_log.InfoFormat("[CAPS]: Removing URL and handler for timed out mesh upload"); httpListener.RemoveStreamHandler("POST", uploaderPath); } -- cgit v1.1 From e7932682a2405dab69cb6b4447dde952c2a5c080 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 12 Sep 2012 21:24:09 +0200 Subject: Add a logger so the prior commit will work --- OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 116055a..88957ff 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -1093,6 +1093,9 @@ namespace OpenSim.Region.ClientStack.Linden public class AssetUploader { + private static readonly ILog m_log = + LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + public event UpLoadedAsset OnUpLoad; private UpLoadedAsset handlerUpLoad = null; -- cgit v1.1 From 52d74cf274fbf002e7ec6ad82fe1a38dc2c02d59 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 14 Sep 2012 00:11:23 +0200 Subject: Allow setting max connections for an endpoint --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 2 +- OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 7384e39..57c9d7c 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -640,7 +640,7 @@ namespace OpenSim.Framework.Servers.HttpServer // Every month or so this will wrap and give bad numbers, not really a problem // since its just for reporting int tickdiff = requestEndTick - requestStartTick; - if (tickdiff > 3000) + if (tickdiff > 3000 && requestHandler.Name != "GetTexture") { m_log.InfoFormat( "[BASE HTTP SERVER]: Slow handling of {0} {1} {2} {3} from {4} took {5}ms", diff --git a/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs b/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs index 9e04601..daf38bc 100644 --- a/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs +++ b/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs @@ -193,7 +193,7 @@ namespace OpenSim.Services.Connectors if (asset == null || asset.Data == null || asset.Data.Length == 0) { asset = SynchronousRestObjectRequester. - MakeRequest("GET", uri, 0); + MakeRequest("GET", uri, 0, 30); if (m_Cache != null) m_Cache.Cache(asset); @@ -321,7 +321,7 @@ namespace OpenSim.Services.Connectors h.Invoke(a); if (handlers != null) handlers.Clear(); - }); + }, 30); success = true; } -- cgit v1.1 From e1e9855edec647efd721b0ff34956f9a7f68942f Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 14 Sep 2012 00:12:41 +0200 Subject: Wait a bit longer for new scene presences to aid tps into laggy regions --- OpenSim/Region/Framework/Scenes/Scene.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 0dae946..9b9ad80 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -4274,7 +4274,7 @@ namespace OpenSim.Region.Framework.Scenes /// protected virtual ScenePresence WaitGetScenePresence(UUID agentID) { - int ntimes = 20; + int ntimes = 30; ScenePresence sp = null; while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0)) Thread.Sleep(1000); -- cgit v1.1 From f14b257fc0207c579dc41f2d8e4853e84ca74752 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 14 Sep 2012 00:13:08 +0200 Subject: Wait longer for arrival cofirmation to aid tps into laggy regions --- .../Framework/EntityTransfer/EntityTransferStateMachine.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs index d0cab49..70dd1bc 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs @@ -218,7 +218,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer id, m_mod.Scene.RegionInfo.RegionName, currentState)); } - int count = 200; + int count = 400; // There should be no race condition here since no other code should be removing the agent transfer or // changing the state to another other than Transferring => ReceivedAtDestination. @@ -266,4 +266,4 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer } } } -} \ No newline at end of file +} -- cgit v1.1 From 45fe25de0d9636690114091565775d264a0ca96f Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 14 Sep 2012 00:14:39 +0200 Subject: Allow some more connections to try to ease lag. --- OpenSim/Region/Application/Application.cs | 2 +- OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Application/Application.cs b/OpenSim/Region/Application/Application.cs index 78636c4..0f90d37 100644 --- a/OpenSim/Region/Application/Application.cs +++ b/OpenSim/Region/Application/Application.cs @@ -74,7 +74,7 @@ namespace OpenSim AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); - ServicePointManager.DefaultConnectionLimit = 6; + ServicePointManager.DefaultConnectionLimit = 12; // Add the arguments supplied when running the application to the configuration ArgvConfigSource configSource = new ArgvConfigSource(args); diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 88957ff..580c005 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -467,6 +467,8 @@ namespace OpenSim.Region.ClientStack.Linden if (llsdRequest.asset_type == "mesh") { + cost += 20; // Constant for now to test showing a price + if (llsdRequest.asset_resources == null) { client.SendAgentAlertMessage("Unable to upload asset. missing information.", false); @@ -480,7 +482,7 @@ namespace OpenSim.Region.ClientStack.Linden uint textures_cost = (uint)llsdRequest.asset_resources.texture_list.Array.Count; textures_cost *= (uint)mm.UploadCharge; - cost = textures_cost; + cost += textures_cost; } else { -- cgit v1.1 From 9f93bef1110e4f0152713e0ff0472bc55890d962 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 14 Sep 2012 00:15:10 +0200 Subject: Allow setting connection limits, part 2 --- OpenSim/Framework/WebUtil.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'OpenSim') diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 6a40cd5..8094b6d 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -695,6 +695,13 @@ namespace OpenSim.Framework public static void MakeRequest(string verb, string requestUrl, TRequest obj, Action action) { + MakeRequest(verb, requestUrl, obj, action, 0); + } + + public static void MakeRequest(string verb, + string requestUrl, TRequest obj, Action action, + int maxConnections) + { int reqnum = WebUtil.RequestNumber++; // m_log.DebugFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method); @@ -706,6 +713,10 @@ namespace OpenSim.Framework Type type = typeof(TRequest); WebRequest request = WebRequest.Create(requestUrl); + HttpWebRequest ht = (HttpWebRequest)request; + if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections) + ht.ServicePoint.ConnectionLimit = maxConnections; + WebResponse response = null; TResponse deserial = default(TResponse); XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); @@ -1003,6 +1014,11 @@ namespace OpenSim.Framework public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj, int pTimeout) { + return MakeRequest(verb, requestUrl, obj, pTimeout, 0); + } + + public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj, int pTimeout, int maxConnections) + { int reqnum = WebUtil.RequestNumber++; // m_log.DebugFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method); @@ -1013,6 +1029,10 @@ namespace OpenSim.Framework TResponse deserial = default(TResponse); WebRequest request = WebRequest.Create(requestUrl); + HttpWebRequest ht = (HttpWebRequest)request; + if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections) + ht.ServicePoint.ConnectionLimit = maxConnections; + request.Method = verb; if (pTimeout != 0) request.Timeout = pTimeout * 1000; -- cgit v1.1 From 387e59ff7f60f2b12526eaacd93581f76abe26e1 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 14 Sep 2012 21:24:25 +0200 Subject: Revamp the HTTP textures handler to allow a maximum of four fetches at any time and to drop requests for avatars n longer in the scene --- .../Handlers/GetTexture/GetTextureHandler.cs | 167 +++++++-------- .../GetTexture/GetTextureServerConnector.cs | 6 +- .../GetTexture/Tests/GetTextureHandlerTests.cs | 4 +- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 47 +++-- .../Servers/HttpServer/PollServiceEventArgs.cs | 3 +- .../HttpServer/PollServiceRequestManager.cs | 3 +- .../ClientStack/Linden/Caps/GetTextureModule.cs | 223 +++++++++++++++++---- 7 files changed, 295 insertions(+), 158 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs index f040ff7..4e755aa 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs @@ -47,36 +47,36 @@ using Caps = OpenSim.Framework.Capabilities.Caps; namespace OpenSim.Capabilities.Handlers { - public class GetTextureHandler : BaseStreamHandler + public class GetTextureHandler { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private IAssetService m_assetService; public const string DefaultFormat = "x-j2c"; - // TODO: Change this to a config option - const string REDIRECT_URL = null; - - public GetTextureHandler(string path, IAssetService assService, string name, string description) - : base("GET", path, name, description) + public GetTextureHandler(IAssetService assService) { m_assetService = assService; } - public override byte[] Handle(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) + public Hashtable Handle(Hashtable request) { - // Try to parse the texture ID from the request URL - NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); - string textureStr = query.GetOne("texture_id"); - string format = query.GetOne("format"); + Hashtable ret = new Hashtable(); + ret["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound; + ret["content_type"] = "text/plain"; + ret["keepalive"] = false; + ret["reusecontext"] = false; + + string textureStr = (string)request["texture_id"]; + string format = (string)request["format"]; //m_log.DebugFormat("[GETTEXTURE]: called {0}", textureStr); if (m_assetService == null) { m_log.Error("[GETTEXTURE]: Cannot fetch texture " + textureStr + " without an asset service"); - httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; } UUID textureID; @@ -91,30 +91,30 @@ namespace OpenSim.Capabilities.Handlers } else { - formats = WebUtil.GetPreferredImageTypes(httpRequest.Headers.Get("Accept")); + formats = new string[1] { DefaultFormat }; // default + if (((Hashtable)request["headers"])["Accept"] != null) + formats = WebUtil.GetPreferredImageTypes((string)((Hashtable)request["headers"])["Accept"]); if (formats.Length == 0) formats = new string[1] { DefaultFormat }; // default } // OK, we have an array with preferred formats, possibly with only one entry - httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; foreach (string f in formats) { - if (FetchTexture(httpRequest, httpResponse, textureID, f)) + if (FetchTexture(request, ret, textureID, f)) break; } } else { - m_log.Warn("[GETTEXTURE]: Failed to parse a texture_id from GetTexture request: " + httpRequest.Url); + m_log.Warn("[GETTEXTURE]: Failed to parse a texture_id from GetTexture request: " + (string)request["uri"]); } // m_log.DebugFormat( // "[GETTEXTURE]: For texture {0} sending back response {1}, data length {2}", // textureID, httpResponse.StatusCode, httpResponse.ContentLength); - - return null; + return ret; } /// @@ -125,7 +125,7 @@ namespace OpenSim.Capabilities.Handlers /// /// /// False for "caller try another codec"; true otherwise - private bool FetchTexture(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID textureID, string format) + private bool FetchTexture(Hashtable request, Hashtable response, UUID textureID, string format) { // m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format); AssetBase texture; @@ -134,84 +134,61 @@ namespace OpenSim.Capabilities.Handlers if (format != DefaultFormat) fullID = fullID + "-" + format; - if (!String.IsNullOrEmpty(REDIRECT_URL)) + // try the cache + texture = m_assetService.GetCached(fullID); + + if (texture == null) { - // Only try to fetch locally cached textures. Misses are redirected - texture = m_assetService.GetCached(fullID); + //m_log.DebugFormat("[GETTEXTURE]: texture was not in the cache"); + + // Fetch locally or remotely. Misses return a 404 + texture = m_assetService.Get(textureID.ToString()); if (texture != null) { if (texture.Type != (sbyte)AssetType.Texture) + return true; + + if (format == DefaultFormat) { - httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; + WriteTextureData(request, response, texture, format); return true; } - WriteTextureData(httpRequest, httpResponse, texture, format); - } - else - { - string textureUrl = REDIRECT_URL + textureID.ToString(); - m_log.Debug("[GETTEXTURE]: Redirecting texture request to " + textureUrl); - httpResponse.RedirectLocation = textureUrl; - return true; - } - } - else // no redirect - { - // try the cache - texture = m_assetService.GetCached(fullID); - - if (texture == null) - { - //m_log.DebugFormat("[GETTEXTURE]: texture was not in the cache"); - - // Fetch locally or remotely. Misses return a 404 - texture = m_assetService.Get(textureID.ToString()); - - if (texture != null) + else { - if (texture.Type != (sbyte)AssetType.Texture) - { - httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; - return true; - } - if (format == DefaultFormat) - { - WriteTextureData(httpRequest, httpResponse, texture, format); - return true; - } - else - { - AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID); - newTexture.Data = ConvertTextureData(texture, format); - if (newTexture.Data.Length == 0) - return false; // !!! Caller try another codec, please! - - newTexture.Flags = AssetFlags.Collectable; - newTexture.Temporary = true; - m_assetService.Store(newTexture); - WriteTextureData(httpRequest, httpResponse, newTexture, format); - return true; - } + AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID); + newTexture.Data = ConvertTextureData(texture, format); + if (newTexture.Data.Length == 0) + return false; // !!! Caller try another codec, please! + + newTexture.Flags = AssetFlags.Collectable; + newTexture.Temporary = true; + m_assetService.Store(newTexture); + WriteTextureData(request, response, newTexture, format); + return true; } - } - else // it was on the cache - { - //m_log.DebugFormat("[GETTEXTURE]: texture was in the cache"); - WriteTextureData(httpRequest, httpResponse, texture, format); - return true; - } - } + } + } + else // it was on the cache + { + //m_log.DebugFormat("[GETTEXTURE]: texture was in the cache"); + WriteTextureData(request, response, texture, format); + return true; + } // not found // m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found"); - httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; return true; } - private void WriteTextureData(IOSHttpRequest request, IOSHttpResponse response, AssetBase texture, string format) + private void WriteTextureData(Hashtable request, Hashtable response, AssetBase texture, string format) { - string range = request.Headers.GetOne("Range"); + Hashtable headers = new Hashtable(); + response["headers"] = headers; + + string range = String.Empty; + if (((Hashtable)request["headers"])["Range"] != null) + range = (string)((Hashtable)request["headers"])["Range"]; if (!String.IsNullOrEmpty(range)) // JP2's only { @@ -226,7 +203,7 @@ namespace OpenSim.Capabilities.Handlers { // response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable; // viewers don't seem to handle RequestedRangeNotSatisfiable and keep retrying with same parameters - response.StatusCode = (int)System.Net.HttpStatusCode.NotFound; + response["int_response_code"] = (int)System.Net.HttpStatusCode.NotFound; } else { @@ -240,31 +217,33 @@ namespace OpenSim.Capabilities.Handlers // We were accidentally sending back 404 before in this situation // https://issues.apache.org/bugzilla/show_bug.cgi?id=51878 supports sending 206 even if the // entire range is requested, and viewer 3.2.2 (and very probably earlier) seems fine with this. - response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; - - response.ContentLength = len; - response.ContentType = texture.Metadata.ContentType; - response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length)); + response["int_response_code"] = (int)System.Net.HttpStatusCode.PartialContent; + response["content-type"] = texture.Metadata.ContentType; + headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length); - response.Body.Write(texture.Data, start, len); + byte[] d = new byte[len]; + Array.Copy(texture.Data, start, d, 0, len); + response["bin_response_data"] = d; +// response.Body.Write(texture.Data, start, len); } } else { m_log.Warn("[GETTEXTURE]: Malformed Range header: " + range); - response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; + response["int_response_code"] = (int)System.Net.HttpStatusCode.BadRequest; } } else // JP2's or other formats { // Full content request - response.StatusCode = (int)System.Net.HttpStatusCode.OK; - response.ContentLength = texture.Data.Length; + response["int_response_code"] = (int)System.Net.HttpStatusCode.OK; if (format == DefaultFormat) - response.ContentType = texture.Metadata.ContentType; + response["content_type"] = texture.Metadata.ContentType; else - response.ContentType = "image/" + format; - response.Body.Write(texture.Data, 0, texture.Data.Length); + response["content_type"] = "image/" + format; + + response["bin_response_data"] = texture.Data; +// response.Body.Write(texture.Data, 0, texture.Data.Length); } // if (response.StatusCode < 200 || response.StatusCode > 299) @@ -368,4 +347,4 @@ namespace OpenSim.Capabilities.Handlers return null; } } -} \ No newline at end of file +} diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs index 71cf033..bf66acb 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs @@ -33,6 +33,7 @@ using OpenSim.Framework.Servers.HttpServer; using OpenSim.Server.Handlers.Base; using OpenMetaverse; +/* namespace OpenSim.Capabilities.Handlers { public class GetTextureServerConnector : ServiceConnector @@ -63,7 +64,8 @@ namespace OpenSim.Capabilities.Handlers throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); server.AddStreamHandler( - new GetTextureHandler("/CAPS/GetTexture/" /*+ UUID.Random() */, m_AssetService, "GetTexture", null)); + new GetTextureHandler("/CAPS/GetTexture/", m_AssetService, "GetTexture", null)); } } -} \ No newline at end of file +} +*/ diff --git a/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs b/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs index 761e4e7..b6ae41b 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs @@ -39,6 +39,7 @@ using OpenSim.Region.Framework.Scenes; using OpenSim.Tests.Common; using OpenSim.Tests.Common.Mock; +/* namespace OpenSim.Capabilities.Handlers.GetTexture.Tests { [TestFixture] @@ -60,4 +61,5 @@ namespace OpenSim.Capabilities.Handlers.GetTexture.Tests Assert.That(resp.StatusCode, Is.EqualTo((int)System.Net.HttpStatusCode.NotFound)); } } -} \ No newline at end of file +} +*/ diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 57c9d7c..6121371 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -1449,7 +1449,8 @@ namespace OpenSim.Framework.Servers.HttpServer internal byte[] DoHTTPGruntWork(Hashtable responsedata, OSHttpResponse response) { int responsecode; - string responseString; + string responseString = String.Empty; + byte[] responseData = null; string contentType; if (responsedata == null) @@ -1465,7 +1466,10 @@ namespace OpenSim.Framework.Servers.HttpServer { //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response"); responsecode = (int)responsedata["int_response_code"]; - responseString = (string)responsedata["str_response_string"]; + if (responsedata["bin_response_data"] != null) + responseData = (byte[])responsedata["bin_response_data"]; + else + responseString = (string)responsedata["str_response_string"]; contentType = (string)responsedata["content_type"]; } catch @@ -1520,25 +1524,40 @@ namespace OpenSim.Framework.Servers.HttpServer response.AddHeader("Content-Type", contentType); + if (responsedata.ContainsKey("headers")) + { + Hashtable headerdata = (Hashtable)responsedata["headers"]; + + foreach (string header in headerdata.Keys) + response.AddHeader(header, (string)headerdata[header]); + } + byte[] buffer; - if (!(contentType.Contains("image") - || contentType.Contains("x-shockwave-flash") - || contentType.Contains("application/x-oar") - || contentType.Contains("application/vnd.ll.mesh"))) + if (responseData != null) { - // Text - buffer = Encoding.UTF8.GetBytes(responseString); + buffer = responseData; } else { - // Binary! - buffer = Convert.FromBase64String(responseString); - } + if (!(contentType.Contains("image") + || contentType.Contains("x-shockwave-flash") + || contentType.Contains("application/x-oar") + || contentType.Contains("application/vnd.ll.mesh"))) + { + // Text + buffer = Encoding.UTF8.GetBytes(responseString); + } + else + { + // Binary! + buffer = Convert.FromBase64String(responseString); + } - response.SendChunked = false; - response.ContentLength64 = buffer.Length; - response.ContentEncoding = Encoding.UTF8; + response.SendChunked = false; + response.ContentLength64 = buffer.Length; + response.ContentEncoding = Encoding.UTF8; + } return buffer; } diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index c24a000..a80b1d7 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -52,7 +52,8 @@ namespace OpenSim.Framework.Servers.HttpServer { Normal = 0, LslHttp = 1, - Inventory = 2 + Inventory = 2, + Texture = 3 } public PollServiceEventArgs( diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index a1dee4e..db088e7 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -231,8 +231,7 @@ namespace OpenSim.Framework.Servers.HttpServer { if (m_running) { - if (req.PollServiceArgs.Type == PollServiceEventArgs.EventType.LslHttp || - req.PollServiceArgs.Type == PollServiceEventArgs.EventType.Inventory) + if (req.PollServiceArgs.Type != PollServiceEventArgs.EventType.Normal) { m_requests.Enqueue(req); } diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs index 5ae9cc3..5b125ea 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/GetTextureModule.cs @@ -27,18 +27,13 @@ using System; using System.Collections; -using System.Collections.Specialized; -using System.Drawing; -using System.Drawing.Imaging; +using System.Collections.Generic; using System.Reflection; -using System.IO; -using System.Web; +using System.Threading; using log4net; using Nini.Config; using Mono.Addins; using OpenMetaverse; -using OpenMetaverse.StructuredData; -using OpenMetaverse.Imaging; using OpenSim.Framework; using OpenSim.Framework.Servers; using OpenSim.Framework.Servers.HttpServer; @@ -47,64 +42,73 @@ using OpenSim.Region.Framework.Scenes; using OpenSim.Services.Interfaces; using Caps = OpenSim.Framework.Capabilities.Caps; using OpenSim.Capabilities.Handlers; +using OpenSim.Framework.Monitoring; namespace OpenSim.Region.ClientStack.Linden { - [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] + /// + /// This module implements both WebFetchTextureDescendents and FetchTextureDescendents2 capabilities. + /// + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GetTextureModule")] public class GetTextureModule : INonSharedRegionModule { -// private static readonly ILog m_log = -// LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private Scene m_scene; - private IAssetService m_assetService; - private bool m_Enabled = false; + private static GetTextureHandler m_getTextureHandler; + + private IAssetService m_assetService = null; - // TODO: Change this to a config option - const string REDIRECT_URL = null; + private Dictionary m_capsDict = new Dictionary(); + private static Thread[] m_workerThreads = null; - private string m_URL; + private static OpenMetaverse.BlockingQueue m_queue = + new OpenMetaverse.BlockingQueue(); #region ISharedRegionModule Members public void Initialise(IConfigSource source) { - IConfig config = source.Configs["ClientStack.LindenCaps"]; - if (config == null) - return; - - m_URL = config.GetString("Cap_GetTexture", string.Empty); - // Cap doesn't exist - if (m_URL != string.Empty) - m_Enabled = true; } public void AddRegion(Scene s) { - if (!m_Enabled) - return; - m_scene = s; + m_assetService = s.AssetService; } public void RemoveRegion(Scene s) { - if (!m_Enabled) - return; - m_scene.EventManager.OnRegisterCaps -= RegisterCaps; + m_scene.EventManager.OnDeregisterCaps -= DeregisterCaps; m_scene = null; } public void RegionLoaded(Scene s) { - if (!m_Enabled) - return; + // We'll reuse the same handler for all requests. + m_getTextureHandler = new GetTextureHandler(m_assetService); - m_assetService = m_scene.RequestModuleInterface(); m_scene.EventManager.OnRegisterCaps += RegisterCaps; + m_scene.EventManager.OnDeregisterCaps += DeregisterCaps; + + if (m_workerThreads == null) + { + m_workerThreads = new Thread[4]; + + for (uint i = 0; i < 4; i++) + { + m_workerThreads[i] = Watchdog.StartThread(DoTextureRequests, + String.Format("TextureWorkerThread{0}", i), + ThreadPriority.Normal, + false, + true, + null, + int.MaxValue); + } + } } public void PostInitialise() @@ -122,24 +126,155 @@ namespace OpenSim.Region.ClientStack.Linden #endregion - public void RegisterCaps(UUID agentID, Caps caps) + ~GetTextureModule() + { + foreach (Thread t in m_workerThreads) + t.Abort(); + } + + private class PollServiceTextureEventArgs : PollServiceEventArgs { - UUID capID = UUID.Random(); + private List requests = + new List(); + private Dictionary responses = + new Dictionary(); + + private Scene m_scene; - //caps.RegisterHandler("GetTexture", new StreamHandler("GET", "/CAPS/" + capID, ProcessGetTexture)); - if (m_URL == "localhost") + public PollServiceTextureEventArgs(UUID pId, Scene scene) : + base(null, null, null, null, pId, 30000) { -// m_log.DebugFormat("[GETTEXTURE]: /CAPS/{0} in region {1}", capID, m_scene.RegionInfo.RegionName); - caps.RegisterHandler( - "GetTexture", - new GetTextureHandler("/CAPS/" + capID + "/", m_assetService, "GetTexture", agentID.ToString())); + m_scene = scene; + + HasEvents = (x, y) => { return this.responses.ContainsKey(x); }; + GetEvents = (x, y, s) => + { + try + { + return this.responses[x]; + } + finally + { + responses.Remove(x); + } + }; + + Request = (x, y) => + { + y["RequestID"] = x.ToString(); + lock (this.requests) + this.requests.Add(y); + + m_queue.Enqueue(this); + }; + + NoEvents = (x, y) => + { + lock (this.requests) + { + Hashtable request = requests.Find(id => id["RequestID"].ToString() == x.ToString()); + requests.Remove(request); + } + + Hashtable response = new Hashtable(); + + response["int_response_code"] = 500; + response["str_response_string"] = "Script timeout"; + response["content_type"] = "text/plain"; + response["keepalive"] = false; + response["reusecontext"] = false; + + return response; + }; } - else + + public void Process() { -// m_log.DebugFormat("[GETTEXTURE]: {0} in region {1}", m_URL, m_scene.RegionInfo.RegionName); - caps.RegisterHandler("GetTexture", m_URL); + Hashtable response; + Hashtable request = null; + + try + { + lock (this.requests) + { + request = requests[0]; + requests.RemoveAt(0); + } + } + catch + { + return; + } + + UUID requestID = new UUID(request["RequestID"].ToString()); + + // If the avatar is gone, don't bother to get the texture + if (m_scene.GetScenePresence(Id) == null) + { + response = new Hashtable(); + + response["int_response_code"] = 500; + response["str_response_string"] = "Script timeout"; + response["content_type"] = "text/plain"; + response["keepalive"] = false; + response["reusecontext"] = false; + + responses[requestID] = response; + return; + } + + response = m_getTextureHandler.Handle(request); + + responses[requestID] = response; + } + } + + private void RegisterCaps(UUID agentID, Caps caps) + { + string capUrl = "/CAPS/" + UUID.Random() + "/"; + + // Register this as a poll service + // absurd large timeout to tune later to make a bit less than viewer + PollServiceTextureEventArgs args = new PollServiceTextureEventArgs(agentID, m_scene); + + args.Type = PollServiceEventArgs.EventType.Texture; + MainServer.Instance.AddPollServiceHTTPHandler(capUrl, args); + + string hostName = m_scene.RegionInfo.ExternalHostName; + uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port; + string protocol = "http"; + + if (MainServer.Instance.UseSSL) + { + hostName = MainServer.Instance.SSLCommonName; + port = MainServer.Instance.SSLPort; + protocol = "https"; } + caps.RegisterHandler("GetTexture", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl)); + + m_capsDict[agentID] = capUrl; } + private void DeregisterCaps(UUID agentID, Caps caps) + { + string capUrl; + + if (m_capsDict.TryGetValue(agentID, out capUrl)) + { + MainServer.Instance.RemoveHTTPHandler("", capUrl); + m_capsDict.Remove(agentID); + } + } + + private void DoTextureRequests() + { + while (true) + { + PollServiceTextureEventArgs args = m_queue.Dequeue(); + + args.Process(); + } + } } + } -- cgit v1.1