diff options
Diffstat (limited to 'OpenSim/Region/ClientStack')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/NewFileAgentInventoryVariablePriceModule.cs | 296 |
1 files changed, 296 insertions, 0 deletions
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 @@ | |||
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 | |||
48 | namespace 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 | } | ||