aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs92
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs296
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs4
3 files changed, 87 insertions, 305 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs
index 88c4d7f..9982556 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
60 60
61 public delegate void UpdateTaskScript(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors); 61 public delegate void UpdateTaskScript(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors);
62 62
63 public delegate void NewInventoryItem(UUID userID, InventoryItemBase item); 63 public delegate void NewInventoryItem(UUID userID, InventoryItemBase item, uint cost);
64 64
65 public delegate void NewAsset(AssetBase asset); 65 public delegate void NewAsset(AssetBase asset);
66 66
@@ -386,6 +386,37 @@ namespace OpenSim.Region.ClientStack.Linden
386 return UUID.Zero; 386 return UUID.Zero;
387 } 387 }
388 388
389 private delegate void UploadWithCostCompleteDelegate(string assetName,
390 string assetDescription, UUID assetID, UUID inventoryItem,
391 UUID parentFolder, byte[] data, string inventoryType,
392 string assetType, uint cost);
393
394 private class AssetUploaderWithCost : AssetUploader
395 {
396 private uint m_cost;
397
398 public event UploadWithCostCompleteDelegate OnUpLoad;
399
400 public AssetUploaderWithCost(string assetName, string description, UUID assetID,
401 UUID inventoryItem, UUID parentFolderID, string invType, string assetType,
402 string path, IHttpServer httpServer, bool dumpAssetsToFile, uint cost) :
403 base(assetName, description, assetID, inventoryItem, parentFolderID,
404 invType, assetType, path, httpServer, dumpAssetsToFile)
405 {
406 m_cost = cost;
407
408 base.OnUpLoad += UploadCompleteHandler;
409 }
410
411 private void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID,
412 UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType,
413 string assetType)
414 {
415 OnUpLoad(assetName, assetDescription, assetID, inventoryItem, parentFolder,
416 data, inventoryType, assetType, m_cost);
417 }
418 }
419
389 /// <summary> 420 /// <summary>
390 /// 421 ///
391 /// </summary> 422 /// </summary>
@@ -396,8 +427,11 @@ namespace OpenSim.Region.ClientStack.Linden
396 //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString()); 427 //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString());
397 //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type); 428 //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type);
398 429
430 uint cost = 0;
431
399 if (llsdRequest.asset_type == "texture" || 432 if (llsdRequest.asset_type == "texture" ||
400 llsdRequest.asset_type == "animation" || 433 llsdRequest.asset_type == "animation" ||
434 llsdRequest.asset_type == "mesh" ||
401 llsdRequest.asset_type == "sound") 435 llsdRequest.asset_type == "sound")
402 { 436 {
403 ScenePresence avatar = null; 437 ScenePresence avatar = null;
@@ -428,7 +462,31 @@ namespace OpenSim.Region.ClientStack.Linden
428 462
429 if (mm != null) 463 if (mm != null)
430 { 464 {
431 if (!mm.UploadCovered(client.AgentId, mm.UploadCharge)) 465 // XPTO: The cost should be calculated about here
466
467 if (llsdRequest.asset_type == "mesh")
468 {
469 if (llsdRequest.asset_resources == null)
470 {
471 client.SendAgentAlertMessage("Unable to upload asset. missing information.", false);
472
473 LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse();
474 errorResponse.uploader = "";
475 errorResponse.state = "error";
476 return errorResponse;
477 }
478
479 uint textures_cost = (uint)llsdRequest.asset_resources.texture_list.Array.Count;
480 textures_cost *= (uint)mm.UploadCharge;
481
482 cost = textures_cost;
483 }
484 else
485 {
486 cost = (uint)mm.UploadCharge;
487 }
488
489 if (!mm.UploadCovered(client.AgentId, (int)cost))
432 { 490 {
433 client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); 491 client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
434 492
@@ -449,9 +507,9 @@ namespace OpenSim.Region.ClientStack.Linden
449 UUID parentFolder = llsdRequest.folder_id; 507 UUID parentFolder = llsdRequest.folder_id;
450 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); 508 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
451 509
452 AssetUploader uploader = 510 AssetUploaderWithCost uploader =
453 new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, 511 new AssetUploaderWithCost(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type,
454 llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile); 512 llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile, cost);
455 513
456 m_HostCapsObj.HttpListener.AddStreamHandler( 514 m_HostCapsObj.HttpListener.AddStreamHandler(
457 new BinaryStreamHandler( 515 new BinaryStreamHandler(
@@ -469,11 +527,31 @@ namespace OpenSim.Region.ClientStack.Linden
469 string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase + 527 string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase +
470 uploaderPath; 528 uploaderPath;
471 529
530
472 LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); 531 LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
473 uploadResponse.uploader = uploaderURL; 532 uploadResponse.uploader = uploaderURL;
474 uploadResponse.state = "upload"; 533 uploadResponse.state = "upload";
534 uploadResponse.upload_price = (int)cost;
535
536 // use fake values for now
537 if (llsdRequest.asset_type == "mesh")
538 {
539 uploadResponse.data = new LLSDAssetUploadResponseData();
540 uploadResponse.data.model_streaming_cost = 1.0;
541 uploadResponse.data.simulation_cost = 1.5;
542
543 uploadResponse.data.physics_cost = 2.0;
544 uploadResponse.data.resource_cost = 3.0;
545 uploadResponse.data.upload_price_breakdown.mesh_instance = 1;
546 uploadResponse.data.upload_price_breakdown.mesh_physics = 2;
547 uploadResponse.data.upload_price_breakdown.mesh_streaming = 3;
548 uploadResponse.data.upload_price_breakdown.texture = 5;
549 uploadResponse.data.upload_price_breakdown.model = 4;
550 }
551
475 uploader.OnUpLoad += UploadCompleteHandler; 552 uploader.OnUpLoad += UploadCompleteHandler;
476 return uploadResponse; 553 return uploadResponse;
554
477 } 555 }
478 556
479 /// <summary> 557 /// <summary>
@@ -484,7 +562,7 @@ namespace OpenSim.Region.ClientStack.Linden
484 /// <param name="data"></param> 562 /// <param name="data"></param>
485 public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, 563 public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID,
486 UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, 564 UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType,
487 string assetType) 565 string assetType, uint cost)
488 { 566 {
489 m_log.DebugFormat( 567 m_log.DebugFormat(
490 "[BUNCH OF CAPS]: Uploaded asset {0} for inventory item {1}, inv type {2}, asset type {3}", 568 "[BUNCH OF CAPS]: Uploaded asset {0} for inventory item {1}, inv type {2}, asset type {3}",
@@ -703,7 +781,7 @@ namespace OpenSim.Region.ClientStack.Linden
703 781
704 if (AddNewInventoryItem != null) 782 if (AddNewInventoryItem != null)
705 { 783 {
706 AddNewInventoryItem(m_HostCapsObj.AgentID, item); 784 AddNewInventoryItem(m_HostCapsObj.AgentID, item, cost);
707 } 785 }
708 } 786 }
709 787
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 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Specialized;
31using System.Reflection;
32using System.IO;
33using System.Web;
34using Mono.Addins;
35using log4net;
36using Nini.Config;
37using OpenMetaverse;
38using OpenMetaverse.StructuredData;
39using OpenSim.Framework;
40using OpenSim.Framework.Servers;
41using OpenSim.Framework.Servers.HttpServer;
42using OpenSim.Region.Framework.Interfaces;
43using OpenSim.Region.Framework.Scenes;
44using OpenSim.Services.Interfaces;
45using Caps = OpenSim.Framework.Capabilities.Caps;
46using OpenSim.Framework.Capabilities;
47
48namespace OpenSim.Region.ClientStack.Linden
49{
50 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
51 public class NewFileAgentInventoryVariablePriceModule : INonSharedRegionModule
52 {
53// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54
55 private Scene m_scene;
56// private IAssetService m_assetService;
57 private bool m_dumpAssetsToFile = false;
58 private bool m_enabled = true;
59 private int m_levelUpload = 0;
60
61 #region IRegionModuleBase Members
62
63
64 public Type ReplaceableInterface
65 {
66 get { return null; }
67 }
68
69 public void Initialise(IConfigSource source)
70 {
71 IConfig meshConfig = source.Configs["Mesh"];
72 if (meshConfig == null)
73 return;
74
75 m_enabled = meshConfig.GetBoolean("AllowMeshUpload", true);
76 m_levelUpload = meshConfig.GetInt("LevelUpload", 0);
77 }
78
79 public void AddRegion(Scene pScene)
80 {
81 m_scene = pScene;
82 }
83
84 public void RemoveRegion(Scene scene)
85 {
86
87 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
88 m_scene = null;
89 }
90
91 public void RegionLoaded(Scene scene)
92 {
93
94// m_assetService = m_scene.RequestModuleInterface<IAssetService>();
95 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
96 }
97
98 #endregion
99
100
101 #region IRegionModule Members
102
103
104
105 public void Close() { }
106
107 public string Name { get { return "NewFileAgentInventoryVariablePriceModule"; } }
108
109
110 public void RegisterCaps(UUID agentID, Caps caps)
111 {
112 if(!m_enabled)
113 return;
114
115 UUID capID = UUID.Random();
116
117// m_log.Debug("[NEW FILE AGENT INVENTORY VARIABLE PRICE]: /CAPS/" + capID);
118 caps.RegisterHandler(
119 "NewFileAgentInventoryVariablePrice",
120 new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDNewFileAngentInventoryVariablePriceReplyResponse>(
121 "POST",
122 "/CAPS/" + capID.ToString(),
123 req => NewAgentInventoryRequest(req, agentID),
124 "NewFileAgentInventoryVariablePrice",
125 agentID.ToString()));
126 }
127
128 #endregion
129
130 public LLSDNewFileAngentInventoryVariablePriceReplyResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest, UUID agentID)
131 {
132 //TODO: The Mesh uploader uploads many types of content. If you're going to implement a Money based limit
133 // you need to be aware of this
134
135 //if (llsdRequest.asset_type == "texture" ||
136 // llsdRequest.asset_type == "animation" ||
137 // llsdRequest.asset_type == "sound")
138 // {
139 // check user level
140
141 ScenePresence avatar = null;
142 IClientAPI client = null;
143 m_scene.TryGetScenePresence(agentID, out avatar);
144
145 if (avatar != null)
146 {
147 client = avatar.ControllingClient;
148
149 if (avatar.UserLevel < m_levelUpload)
150 {
151 if (client != null)
152 client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false);
153
154 LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse();
155 errorResponse.rsvp = "";
156 errorResponse.state = "error";
157 return errorResponse;
158 }
159 }
160
161 // check funds
162 IMoneyModule mm = m_scene.RequestModuleInterface<IMoneyModule>();
163
164 if (mm != null)
165 {
166 if (!mm.UploadCovered(agentID, mm.UploadCharge))
167 {
168 if (client != null)
169 client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
170
171 LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse();
172 errorResponse.rsvp = "";
173 errorResponse.state = "error";
174 return errorResponse;
175 }
176 }
177
178 // }
179
180 string assetName = llsdRequest.name;
181 string assetDes = llsdRequest.description;
182 string capsBase = "/CAPS/NewFileAgentInventoryVariablePrice/";
183 UUID newAsset = UUID.Random();
184 UUID newInvItem = UUID.Random();
185 UUID parentFolder = llsdRequest.folder_id;
186 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000") + "/";
187
188 AssetUploader uploader =
189 new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type,
190 llsdRequest.asset_type, capsBase + uploaderPath, MainServer.Instance, m_dumpAssetsToFile);
191
192 MainServer.Instance.AddStreamHandler(
193 new BinaryStreamHandler(
194 "POST",
195 capsBase + uploaderPath,
196 uploader.uploaderCaps,
197 "NewFileAgentInventoryVariablePrice",
198 agentID.ToString()));
199
200 string protocol = "http://";
201
202 if (MainServer.Instance.UseSSL)
203 protocol = "https://";
204
205 string uploaderURL = protocol + m_scene.RegionInfo.ExternalHostName + ":" + MainServer.Instance.Port.ToString() + capsBase +
206 uploaderPath;
207
208
209 LLSDNewFileAngentInventoryVariablePriceReplyResponse uploadResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse();
210
211 uploadResponse.rsvp = uploaderURL;
212 uploadResponse.state = "upload";
213 uploadResponse.resource_cost = 0;
214 uploadResponse.upload_price = 0;
215
216 uploader.OnUpLoad += //UploadCompleteHandler;
217
218 delegate(
219 string passetName, string passetDescription, UUID passetID,
220 UUID pinventoryItem, UUID pparentFolder, byte[] pdata, string pinventoryType,
221 string passetType)
222 {
223 UploadCompleteHandler(passetName, passetDescription, passetID,
224 pinventoryItem, pparentFolder, pdata, pinventoryType,
225 passetType,agentID);
226 };
227
228 return uploadResponse;
229 }
230
231 public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID,
232 UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType,
233 string assetType,UUID AgentID)
234 {
235// m_log.DebugFormat(
236// "[NEW FILE AGENT INVENTORY VARIABLE PRICE MODULE]: Upload complete for {0}", inventoryItem);
237
238 sbyte assType = 0;
239 sbyte inType = 0;
240
241 if (inventoryType == "sound")
242 {
243 inType = 1;
244 assType = 1;
245 }
246 else if (inventoryType == "animation")
247 {
248 inType = 19;
249 assType = 20;
250 }
251 else if (inventoryType == "wearable")
252 {
253 inType = 18;
254 switch (assetType)
255 {
256 case "bodypart":
257 assType = 13;
258 break;
259 case "clothing":
260 assType = 5;
261 break;
262 }
263 }
264 else if (inventoryType == "mesh")
265 {
266 inType = (sbyte)InventoryType.Mesh;
267 assType = (sbyte)AssetType.Mesh;
268 }
269
270 AssetBase asset;
271 asset = new AssetBase(assetID, assetName, assType, AgentID.ToString());
272 asset.Data = data;
273
274 if (m_scene.AssetService != null)
275 m_scene.AssetService.Store(asset);
276
277 InventoryItemBase item = new InventoryItemBase();
278 item.Owner = AgentID;
279 item.CreatorId = AgentID.ToString();
280 item.ID = inventoryItem;
281 item.AssetID = asset.FullID;
282 item.Description = assetDescription;
283 item.Name = assetName;
284 item.AssetType = assType;
285 item.InvType = inType;
286 item.Folder = parentFolder;
287 item.CurrentPermissions
288 = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer);
289 item.BasePermissions = (uint)PermissionMask.All;
290 item.EveryOnePermissions = 0;
291 item.NextPermissions = (uint)PermissionMask.All;
292 item.CreationDate = Util.UnixTimeSinceEpoch();
293 m_scene.AddInventoryItem(item);
294 }
295 }
296}
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
101 engine.StartProcessing(); 101 engine.StartProcessing();
102 } 102 }
103 103
104 public void AddUploadedInventoryItem(UUID agentID, InventoryItemBase item) 104 public void AddUploadedInventoryItem(UUID agentID, InventoryItemBase item, uint cost)
105 { 105 {
106 IMoneyModule money = RequestModuleInterface<IMoneyModule>(); 106 IMoneyModule money = RequestModuleInterface<IMoneyModule>();
107 if (money != null) 107 if (money != null)
108 { 108 {
109 money.ApplyUploadCharge(agentID, money.UploadCharge, "Asset upload"); 109 money.ApplyUploadCharge(agentID, (int)cost, "Asset upload");
110 } 110 }
111 111
112 AddInventoryItem(item); 112 AddInventoryItem(item);