diff options
author | Teravus Ovares (Dan Olivares) | 2010-10-14 02:19:42 -0400 |
---|---|---|
committer | Teravus Ovares (Dan Olivares) | 2010-10-14 02:19:42 -0400 |
commit | 3384f643ebbc377ecbaae885941a08484bf259f5 (patch) | |
tree | 60c1692cc3c22781a66653faca3bf930a95548cd /OpenSim/Region/CoreModules/Avatar | |
parent | Merge branch 'master' of ssh://MyConnection/var/git/opensim (diff) | |
download | opensim-SC_OLD-3384f643ebbc377ecbaae885941a08484bf259f5.zip opensim-SC_OLD-3384f643ebbc377ecbaae885941a08484bf259f5.tar.gz opensim-SC_OLD-3384f643ebbc377ecbaae885941a08484bf259f5.tar.bz2 opensim-SC_OLD-3384f643ebbc377ecbaae885941a08484bf259f5.tar.xz |
* Partially complete stuff for Mesh support that Melanie wanted to see before it was done.
* Shouldn't break the build.
* Doesn't work yet either.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Assets/GetMeshModule.cs | 201 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Assets/UploadObjectAssetModule.cs | 248 |
2 files changed, 449 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Assets/GetMeshModule.cs b/OpenSim/Region/CoreModules/Avatar/Assets/GetMeshModule.cs new file mode 100644 index 0000000..c1e9891 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Assets/GetMeshModule.cs | |||
@@ -0,0 +1,201 @@ | |||
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 | |||
47 | namespace OpenSim.Region.CoreModules.Avatar.Assets | ||
48 | { | ||
49 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] | ||
50 | public class GetMeshModule : INonSharedRegionModule | ||
51 | { | ||
52 | private static readonly ILog m_log = | ||
53 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | private Scene m_scene; | ||
55 | private IAssetService m_assetService; | ||
56 | |||
57 | #region IRegionModuleBase Members | ||
58 | |||
59 | |||
60 | public Type ReplaceableInterface | ||
61 | { | ||
62 | get { return null; } | ||
63 | } | ||
64 | |||
65 | public void Initialise(IConfigSource source) | ||
66 | { | ||
67 | |||
68 | } | ||
69 | |||
70 | public void AddRegion(Scene pScene) | ||
71 | { | ||
72 | m_scene = pScene; | ||
73 | } | ||
74 | |||
75 | public void RemoveRegion(Scene scene) | ||
76 | { | ||
77 | |||
78 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | ||
79 | m_scene = null; | ||
80 | } | ||
81 | |||
82 | public void RegionLoaded(Scene scene) | ||
83 | { | ||
84 | |||
85 | m_assetService = m_scene.RequestModuleInterface<IAssetService>(); | ||
86 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | ||
87 | } | ||
88 | |||
89 | #endregion | ||
90 | |||
91 | |||
92 | #region IRegionModule Members | ||
93 | |||
94 | |||
95 | |||
96 | public void Close() { } | ||
97 | |||
98 | public string Name { get { return "GetMeshModule"; } } | ||
99 | |||
100 | |||
101 | public void RegisterCaps(UUID agentID, Caps caps) | ||
102 | { | ||
103 | UUID capID = UUID.Random(); | ||
104 | |||
105 | m_log.Info("[GETMESH]: /CAPS/" + capID); | ||
106 | caps.RegisterHandler("GetMesh", | ||
107 | new RestHTTPHandler("POST", "/CAPS/" + capID + "/", | ||
108 | delegate(Hashtable m_dhttpMethod) | ||
109 | { | ||
110 | return ProcessGetMesh(m_dhttpMethod, agentID, caps); | ||
111 | })); | ||
112 | |||
113 | } | ||
114 | |||
115 | #endregion | ||
116 | public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap) | ||
117 | { | ||
118 | |||
119 | Hashtable responsedata = new Hashtable(); | ||
120 | responsedata["int_response_code"] = 400; //501; //410; //404; | ||
121 | responsedata["content_type"] = "text/plain"; | ||
122 | responsedata["keepalive"] = false; | ||
123 | responsedata["str_response_string"] = "Request wasn't what was expected"; | ||
124 | |||
125 | string meshStr = string.Empty; | ||
126 | |||
127 | if (request.ContainsKey("mesh_id")) | ||
128 | meshStr = request["mesh_id"].ToString(); | ||
129 | |||
130 | |||
131 | UUID meshID = UUID.Zero; | ||
132 | if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID)) | ||
133 | { | ||
134 | if (m_assetService == null) | ||
135 | { | ||
136 | responsedata["int_response_code"] = 404; //501; //410; //404; | ||
137 | responsedata["content_type"] = "text/plain"; | ||
138 | responsedata["keepalive"] = false; | ||
139 | responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh."; | ||
140 | return responsedata; | ||
141 | } | ||
142 | |||
143 | AssetBase mesh; | ||
144 | // Only try to fetch locally cached textures. Misses are redirected | ||
145 | mesh = m_assetService.GetCached(meshID.ToString()); | ||
146 | if (mesh != null) | ||
147 | { | ||
148 | if (mesh.Type == (sbyte)45) //TODO: Change to AssetType.Mesh when libomv gets updated! | ||
149 | { | ||
150 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | ||
151 | responsedata["content_type"] = "application/vnd.ll.mesh"; | ||
152 | responsedata["int_response_code"] = 200; | ||
153 | } | ||
154 | // Optionally add additional mesh types here | ||
155 | else | ||
156 | { | ||
157 | responsedata["int_response_code"] = 404; //501; //410; //404; | ||
158 | responsedata["content_type"] = "text/plain"; | ||
159 | responsedata["keepalive"] = false; | ||
160 | responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; | ||
161 | return responsedata; | ||
162 | } | ||
163 | } | ||
164 | else | ||
165 | { | ||
166 | mesh = m_assetService.Get(meshID.ToString()); | ||
167 | if (mesh != null) | ||
168 | { | ||
169 | if (mesh.Type == (sbyte)45) //TODO: Change to AssetType.Mesh when libomv gets updated! | ||
170 | { | ||
171 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | ||
172 | responsedata["content_type"] = "application/vnd.ll.mesh"; | ||
173 | responsedata["int_response_code"] = 200; | ||
174 | } | ||
175 | // Optionally add additional mesh types here | ||
176 | else | ||
177 | { | ||
178 | responsedata["int_response_code"] = 404; //501; //410; //404; | ||
179 | responsedata["content_type"] = "text/plain"; | ||
180 | responsedata["keepalive"] = false; | ||
181 | responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; | ||
182 | return responsedata; | ||
183 | } | ||
184 | } | ||
185 | |||
186 | else | ||
187 | { | ||
188 | responsedata["int_response_code"] = 404; //501; //410; //404; | ||
189 | responsedata["content_type"] = "text/plain"; | ||
190 | responsedata["keepalive"] = false; | ||
191 | responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; | ||
192 | return responsedata; | ||
193 | } | ||
194 | } | ||
195 | |||
196 | } | ||
197 | |||
198 | return responsedata; | ||
199 | } | ||
200 | } | ||
201 | } | ||
diff --git a/OpenSim/Region/CoreModules/Avatar/Assets/UploadObjectAssetModule.cs b/OpenSim/Region/CoreModules/Avatar/Assets/UploadObjectAssetModule.cs new file mode 100644 index 0000000..2600506 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Assets/UploadObjectAssetModule.cs | |||
@@ -0,0 +1,248 @@ | |||
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.CoreModules.Avatar.Assets | ||
49 | { | ||
50 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] | ||
51 | public class UploadObjectAssetModule : INonSharedRegionModule | ||
52 | { | ||
53 | private static readonly ILog m_log = | ||
54 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | private Scene m_scene; | ||
56 | private IAssetService m_assetService; | ||
57 | private bool m_dumpAssetsToFile = false; | ||
58 | |||
59 | #region IRegionModuleBase Members | ||
60 | |||
61 | |||
62 | public Type ReplaceableInterface | ||
63 | { | ||
64 | get { return null; } | ||
65 | } | ||
66 | |||
67 | public void Initialise(IConfigSource source) | ||
68 | { | ||
69 | |||
70 | } | ||
71 | |||
72 | public void AddRegion(Scene pScene) | ||
73 | { | ||
74 | m_scene = pScene; | ||
75 | } | ||
76 | |||
77 | public void RemoveRegion(Scene scene) | ||
78 | { | ||
79 | |||
80 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | ||
81 | m_scene = null; | ||
82 | } | ||
83 | |||
84 | public void RegionLoaded(Scene scene) | ||
85 | { | ||
86 | |||
87 | m_assetService = m_scene.RequestModuleInterface<IAssetService>(); | ||
88 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | ||
89 | } | ||
90 | |||
91 | #endregion | ||
92 | |||
93 | |||
94 | #region IRegionModule Members | ||
95 | |||
96 | |||
97 | |||
98 | public void Close() { } | ||
99 | |||
100 | public string Name { get { return "UploadObjectAssetModule"; } } | ||
101 | |||
102 | |||
103 | public void RegisterCaps(UUID agentID, Caps caps) | ||
104 | { | ||
105 | UUID capID = UUID.Random(); | ||
106 | |||
107 | m_log.Info("[GETMESH]: /CAPS/" + capID); | ||
108 | caps.RegisterHandler("UploadObjectAsset", | ||
109 | |||
110 | new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>("POST", | ||
111 | "/CAPS/" + capID.ToString(), | ||
112 | delegate(LLSDAssetUploadRequest req) | ||
113 | { | ||
114 | return NewAgentInventoryRequest(req,agentID); | ||
115 | })); | ||
116 | |||
117 | } | ||
118 | |||
119 | #endregion | ||
120 | |||
121 | public LLSDAssetUploadResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest, UUID agentID) | ||
122 | { | ||
123 | //if (llsdRequest.asset_type == "texture" || | ||
124 | // llsdRequest.asset_type == "animation" || | ||
125 | // llsdRequest.asset_type == "sound") | ||
126 | // { | ||
127 | IClientAPI client = null; | ||
128 | |||
129 | |||
130 | IMoneyModule mm = m_scene.RequestModuleInterface<IMoneyModule>(); | ||
131 | |||
132 | if (mm != null) | ||
133 | { | ||
134 | if (m_scene.TryGetClient(agentID, out client)) | ||
135 | { | ||
136 | if (!mm.UploadCovered(client, mm.UploadCharge)) | ||
137 | { | ||
138 | if (client != null) | ||
139 | client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); | ||
140 | |||
141 | LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); | ||
142 | errorResponse.uploader = ""; | ||
143 | errorResponse.state = "error"; | ||
144 | return errorResponse; | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | // } | ||
149 | |||
150 | |||
151 | |||
152 | string assetName = llsdRequest.name; | ||
153 | string assetDes = llsdRequest.description; | ||
154 | string capsBase = "/CAPS/UploadObjectAsset/"; | ||
155 | UUID newAsset = UUID.Random(); | ||
156 | UUID newInvItem = UUID.Random(); | ||
157 | UUID parentFolder = llsdRequest.folder_id; | ||
158 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); | ||
159 | |||
160 | Caps.AssetUploader uploader = | ||
161 | new Caps.AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, | ||
162 | llsdRequest.asset_type, capsBase + uploaderPath, MainServer.Instance, m_dumpAssetsToFile); | ||
163 | MainServer.Instance.AddStreamHandler( | ||
164 | new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); | ||
165 | |||
166 | string protocol = "http://"; | ||
167 | |||
168 | if (MainServer.Instance.UseSSL) | ||
169 | protocol = "https://"; | ||
170 | |||
171 | string uploaderURL = protocol + m_scene.RegionInfo.ExternalHostName + ":" + MainServer.Instance.Port.ToString() + capsBase + | ||
172 | uploaderPath; | ||
173 | |||
174 | LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); | ||
175 | uploadResponse.uploader = uploaderURL; | ||
176 | uploadResponse.state = "upload"; | ||
177 | |||
178 | uploader.OnUpLoad += delegate( | ||
179 | string passetName, string passetDescription, UUID passetID, | ||
180 | UUID pinventoryItem, UUID pparentFolder, byte[] pdata, string pinventoryType, | ||
181 | string passetType) | ||
182 | { | ||
183 | UploadCompleteHandler(passetName, passetDescription, passetID, | ||
184 | pinventoryItem, pparentFolder, pdata, pinventoryType, | ||
185 | passetType,agentID); | ||
186 | }; | ||
187 | return uploadResponse; | ||
188 | } | ||
189 | |||
190 | |||
191 | public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID, | ||
192 | UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType, | ||
193 | string assetType,UUID AgentID) | ||
194 | { | ||
195 | sbyte assType = 0; | ||
196 | sbyte inType = 0; | ||
197 | |||
198 | if (inventoryType == "sound") | ||
199 | { | ||
200 | inType = 1; | ||
201 | assType = 1; | ||
202 | } | ||
203 | else if (inventoryType == "animation") | ||
204 | { | ||
205 | inType = 19; | ||
206 | assType = 20; | ||
207 | } | ||
208 | else if (inventoryType == "wearable") | ||
209 | { | ||
210 | inType = 18; | ||
211 | switch (assetType) | ||
212 | { | ||
213 | case "bodypart": | ||
214 | assType = 13; | ||
215 | break; | ||
216 | case "clothing": | ||
217 | assType = 5; | ||
218 | break; | ||
219 | } | ||
220 | } | ||
221 | |||
222 | AssetBase asset; | ||
223 | asset = new AssetBase(assetID, assetName, assType, AgentID.ToString()); | ||
224 | asset.Data = data; | ||
225 | |||
226 | if (m_scene.AssetService != null) | ||
227 | m_scene.AssetService.Store(asset); | ||
228 | |||
229 | InventoryItemBase item = new InventoryItemBase(); | ||
230 | item.Owner = AgentID; | ||
231 | item.CreatorId = AgentID.ToString(); | ||
232 | item.ID = inventoryItem; | ||
233 | item.AssetID = asset.FullID; | ||
234 | item.Description = assetDescription; | ||
235 | item.Name = assetName; | ||
236 | item.AssetType = assType; | ||
237 | item.InvType = inType; | ||
238 | item.Folder = parentFolder; | ||
239 | item.CurrentPermissions = 2147483647; | ||
240 | item.BasePermissions = 2147483647; | ||
241 | item.EveryOnePermissions = 0; | ||
242 | item.NextPermissions = 2147483647; | ||
243 | item.CreationDate = Util.UnixTimeSinceEpoch(); | ||
244 | m_scene.AddInventoryItem(item); | ||
245 | |||
246 | } | ||
247 | } | ||
248 | } | ||