diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs | 297 |
1 files changed, 0 insertions, 297 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs deleted file mode 100644 index f69a0bb..0000000 --- a/OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs +++ /dev/null | |||
@@ -1,297 +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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Specialized; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Web; | ||
34 | using Mono.Addins; | ||
35 | using log4net; | ||
36 | using Nini.Config; | ||
37 | using OpenMetaverse; | ||
38 | using OpenMetaverse.StructuredData; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.Servers; | ||
41 | using OpenSim.Framework.Servers.HttpServer; | ||
42 | using OpenSim.Region.Framework.Interfaces; | ||
43 | using OpenSim.Region.Framework.Scenes; | ||
44 | using OpenSim.Services.Interfaces; | ||
45 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
46 | using OpenSim.Framework.Capabilities; | ||
47 | using PermissionMask = OpenSim.Framework.PermissionMask; | ||
48 | |||
49 | namespace OpenSim.Region.ClientStack.Linden | ||
50 | { | ||
51 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "NewFileAgentInventoryVariablePriceModule")] | ||
52 | public class NewFileAgentInventoryVariablePriceModule : INonSharedRegionModule | ||
53 | { | ||
54 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | |||
56 | private Scene m_scene; | ||
57 | // private IAssetService m_assetService; | ||
58 | private bool m_dumpAssetsToFile = false; | ||
59 | private bool m_enabled = true; | ||
60 | private int m_levelUpload = 0; | ||
61 | |||
62 | #region Region Module interfaceBase Members | ||
63 | |||
64 | |||
65 | public Type ReplaceableInterface | ||
66 | { | ||
67 | get { return null; } | ||
68 | } | ||
69 | |||
70 | public void Initialise(IConfigSource source) | ||
71 | { | ||
72 | IConfig meshConfig = source.Configs["Mesh"]; | ||
73 | if (meshConfig == null) | ||
74 | return; | ||
75 | |||
76 | m_enabled = meshConfig.GetBoolean("AllowMeshUpload", true); | ||
77 | m_levelUpload = meshConfig.GetInt("LevelUpload", 0); | ||
78 | } | ||
79 | |||
80 | public void AddRegion(Scene pScene) | ||
81 | { | ||
82 | m_scene = pScene; | ||
83 | } | ||
84 | |||
85 | public void RemoveRegion(Scene scene) | ||
86 | { | ||
87 | |||
88 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | ||
89 | m_scene = null; | ||
90 | } | ||
91 | |||
92 | public void RegionLoaded(Scene scene) | ||
93 | { | ||
94 | |||
95 | // m_assetService = m_scene.RequestModuleInterface<IAssetService>(); | ||
96 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | ||
97 | } | ||
98 | |||
99 | #endregion | ||
100 | |||
101 | |||
102 | #region Region Module interface | ||
103 | |||
104 | |||
105 | |||
106 | public void Close() { } | ||
107 | |||
108 | public string Name { get { return "NewFileAgentInventoryVariablePriceModule"; } } | ||
109 | |||
110 | |||
111 | public void RegisterCaps(UUID agentID, Caps caps) | ||
112 | { | ||
113 | if(!m_enabled) | ||
114 | return; | ||
115 | |||
116 | UUID capID = UUID.Random(); | ||
117 | |||
118 | // m_log.Debug("[NEW FILE AGENT INVENTORY VARIABLE PRICE]: /CAPS/" + capID); | ||
119 | caps.RegisterHandler( | ||
120 | "NewFileAgentInventoryVariablePrice", | ||
121 | new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDNewFileAngentInventoryVariablePriceReplyResponse>( | ||
122 | "POST", | ||
123 | "/CAPS/" + capID.ToString(), | ||
124 | req => NewAgentInventoryRequest(req, agentID), | ||
125 | "NewFileAgentInventoryVariablePrice", | ||
126 | agentID.ToString())); | ||
127 | } | ||
128 | |||
129 | #endregion | ||
130 | |||
131 | public LLSDNewFileAngentInventoryVariablePriceReplyResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest, UUID agentID) | ||
132 | { | ||
133 | //TODO: The Mesh uploader uploads many types of content. If you're going to implement a Money based limit | ||
134 | // you need to be aware of this | ||
135 | |||
136 | //if (llsdRequest.asset_type == "texture" || | ||
137 | // llsdRequest.asset_type == "animation" || | ||
138 | // llsdRequest.asset_type == "sound") | ||
139 | // { | ||
140 | // check user level | ||
141 | |||
142 | ScenePresence avatar = null; | ||
143 | IClientAPI client = null; | ||
144 | m_scene.TryGetScenePresence(agentID, out avatar); | ||
145 | |||
146 | if (avatar != null) | ||
147 | { | ||
148 | client = avatar.ControllingClient; | ||
149 | |||
150 | if (avatar.UserLevel < m_levelUpload) | ||
151 | { | ||
152 | if (client != null) | ||
153 | client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false); | ||
154 | |||
155 | LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); | ||
156 | errorResponse.rsvp = ""; | ||
157 | errorResponse.state = "error"; | ||
158 | return errorResponse; | ||
159 | } | ||
160 | } | ||
161 | |||
162 | // check funds | ||
163 | IMoneyModule mm = m_scene.RequestModuleInterface<IMoneyModule>(); | ||
164 | |||
165 | if (mm != null) | ||
166 | { | ||
167 | if (!mm.UploadCovered(agentID, mm.UploadCharge)) | ||
168 | { | ||
169 | if (client != null) | ||
170 | client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); | ||
171 | |||
172 | LLSDNewFileAngentInventoryVariablePriceReplyResponse errorResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); | ||
173 | errorResponse.rsvp = ""; | ||
174 | errorResponse.state = "error"; | ||
175 | return errorResponse; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | // } | ||
180 | |||
181 | string assetName = llsdRequest.name; | ||
182 | string assetDes = llsdRequest.description; | ||
183 | string capsBase = "/CAPS/NewFileAgentInventoryVariablePrice/"; | ||
184 | UUID newAsset = UUID.Random(); | ||
185 | UUID newInvItem = UUID.Random(); | ||
186 | UUID parentFolder = llsdRequest.folder_id; | ||
187 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000") + "/"; | ||
188 | |||
189 | AssetUploader uploader = | ||
190 | new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, | ||
191 | llsdRequest.asset_type, capsBase + uploaderPath, MainServer.Instance, m_dumpAssetsToFile); | ||
192 | |||
193 | MainServer.Instance.AddStreamHandler( | ||
194 | new BinaryStreamHandler( | ||
195 | "POST", | ||
196 | capsBase + uploaderPath, | ||
197 | uploader.uploaderCaps, | ||
198 | "NewFileAgentInventoryVariablePrice", | ||
199 | agentID.ToString())); | ||
200 | |||
201 | string protocol = "http://"; | ||
202 | |||
203 | if (MainServer.Instance.UseSSL) | ||
204 | protocol = "https://"; | ||
205 | |||
206 | string uploaderURL = protocol + m_scene.RegionInfo.ExternalHostName + ":" + MainServer.Instance.Port.ToString() + capsBase + | ||
207 | uploaderPath; | ||
208 | |||
209 | |||
210 | LLSDNewFileAngentInventoryVariablePriceReplyResponse uploadResponse = new LLSDNewFileAngentInventoryVariablePriceReplyResponse(); | ||
211 | |||
212 | uploadResponse.rsvp = uploaderURL; | ||
213 | uploadResponse.state = "upload"; | ||
214 | uploadResponse.resource_cost = 0; | ||
215 | uploadResponse.upload_price = 0; | ||
216 | |||
217 | uploader.OnUpLoad += //UploadCompleteHandler; | ||
218 | |||
219 | delegate( | ||
220 | string passetName, string passetDescription, UUID passetID, | ||
221 | UUID pinventoryItem, UUID pparentFolder, byte[] pdata, string pinventoryType, | ||
222 | string passetType) | ||
223 | { | ||
224 | UploadCompleteHandler(passetName, passetDescription, passetID, | ||
225 | pinventoryItem, pparentFolder, pdata, pinventoryType, | ||
226 | passetType,agentID); | ||
227 | }; | ||
228 | |||
229 | return uploadResponse; | ||
230 | } | ||
231 | |||
232 | public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, | ||
233 | UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, | ||
234 | string assetType,UUID AgentID) | ||
235 | { | ||
236 | // m_log.DebugFormat( | ||
237 | // "[NEW FILE AGENT INVENTORY VARIABLE PRICE MODULE]: Upload complete for {0}", inventoryItem); | ||
238 | |||
239 | sbyte assType = 0; | ||
240 | sbyte inType = 0; | ||
241 | |||
242 | if (inventoryType == "sound") | ||
243 | { | ||
244 | inType = 1; | ||
245 | assType = 1; | ||
246 | } | ||
247 | else if (inventoryType == "animation") | ||
248 | { | ||
249 | inType = 19; | ||
250 | assType = 20; | ||
251 | } | ||
252 | else if (inventoryType == "wearable") | ||
253 | { | ||
254 | inType = 18; | ||
255 | switch (assetType) | ||
256 | { | ||
257 | case "bodypart": | ||
258 | assType = 13; | ||
259 | break; | ||
260 | case "clothing": | ||
261 | assType = 5; | ||
262 | break; | ||
263 | } | ||
264 | } | ||
265 | else if (inventoryType == "mesh") | ||
266 | { | ||
267 | inType = (sbyte)InventoryType.Mesh; | ||
268 | assType = (sbyte)AssetType.Mesh; | ||
269 | } | ||
270 | |||
271 | AssetBase asset; | ||
272 | asset = new AssetBase(assetID, assetName, assType, AgentID.ToString()); | ||
273 | asset.Data = data; | ||
274 | |||
275 | if (m_scene.AssetService != null) | ||
276 | m_scene.AssetService.Store(asset); | ||
277 | |||
278 | InventoryItemBase item = new InventoryItemBase(); | ||
279 | item.Owner = AgentID; | ||
280 | item.CreatorId = AgentID.ToString(); | ||
281 | item.ID = inventoryItem; | ||
282 | item.AssetID = asset.FullID; | ||
283 | item.Description = assetDescription; | ||
284 | item.Name = assetName; | ||
285 | item.AssetType = assType; | ||
286 | item.InvType = inType; | ||
287 | item.Folder = parentFolder; | ||
288 | item.CurrentPermissions | ||
289 | = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer); | ||
290 | item.BasePermissions = (uint)PermissionMask.All; | ||
291 | item.EveryOnePermissions = 0; | ||
292 | item.NextPermissions = (uint)PermissionMask.All; | ||
293 | item.CreationDate = Util.UnixTimeSinceEpoch(); | ||
294 | m_scene.AddInventoryItem(item); | ||
295 | } | ||
296 | } | ||
297 | } | ||