diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs new file mode 100644 index 0000000..1d57143 --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/Caps/GetMeshModule.cs | |||
@@ -0,0 +1,211 @@ | |||
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.ClientStack.Linden | ||
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 | |||
55 | private Scene m_scene; | ||
56 | private IAssetService m_assetService; | ||
57 | private bool m_enabled = true; | ||
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 | IConfig meshConfig = source.Configs["Mesh"]; | ||
70 | if (meshConfig == null) | ||
71 | return; | ||
72 | |||
73 | m_enabled = meshConfig.GetBoolean("AllowMeshUpload", true); | ||
74 | } | ||
75 | |||
76 | public void AddRegion(Scene pScene) | ||
77 | { | ||
78 | m_scene = pScene; | ||
79 | } | ||
80 | |||
81 | public void RemoveRegion(Scene scene) | ||
82 | { | ||
83 | |||
84 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | ||
85 | m_scene = null; | ||
86 | } | ||
87 | |||
88 | public void RegionLoaded(Scene scene) | ||
89 | { | ||
90 | |||
91 | m_assetService = m_scene.RequestModuleInterface<IAssetService>(); | ||
92 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | ||
93 | } | ||
94 | |||
95 | #endregion | ||
96 | |||
97 | |||
98 | #region IRegionModule Members | ||
99 | |||
100 | |||
101 | |||
102 | public void Close() { } | ||
103 | |||
104 | public string Name { get { return "GetMeshModule"; } } | ||
105 | |||
106 | |||
107 | public void RegisterCaps(UUID agentID, Caps caps) | ||
108 | { | ||
109 | if(!m_enabled) | ||
110 | return; | ||
111 | |||
112 | UUID capID = UUID.Random(); | ||
113 | |||
114 | // m_log.Info("[GETMESH]: /CAPS/" + capID); | ||
115 | |||
116 | caps.RegisterHandler("GetMesh", | ||
117 | new RestHTTPHandler("GET", "/CAPS/" + capID, | ||
118 | delegate(Hashtable m_dhttpMethod) | ||
119 | { | ||
120 | return ProcessGetMesh(m_dhttpMethod, agentID, caps); | ||
121 | })); | ||
122 | } | ||
123 | |||
124 | #endregion | ||
125 | |||
126 | public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap) | ||
127 | { | ||
128 | |||
129 | Hashtable responsedata = new Hashtable(); | ||
130 | responsedata["int_response_code"] = 400; //501; //410; //404; | ||
131 | responsedata["content_type"] = "text/plain"; | ||
132 | responsedata["keepalive"] = false; | ||
133 | responsedata["str_response_string"] = "Request wasn't what was expected"; | ||
134 | |||
135 | string meshStr = string.Empty; | ||
136 | |||
137 | if (request.ContainsKey("mesh_id")) | ||
138 | meshStr = request["mesh_id"].ToString(); | ||
139 | |||
140 | |||
141 | UUID meshID = UUID.Zero; | ||
142 | if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID)) | ||
143 | { | ||
144 | if (m_assetService == null) | ||
145 | { | ||
146 | responsedata["int_response_code"] = 404; //501; //410; //404; | ||
147 | responsedata["content_type"] = "text/plain"; | ||
148 | responsedata["keepalive"] = false; | ||
149 | responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh."; | ||
150 | return responsedata; | ||
151 | } | ||
152 | |||
153 | AssetBase mesh; | ||
154 | // Only try to fetch locally cached textures. Misses are redirected | ||
155 | mesh = m_assetService.GetCached(meshID.ToString()); | ||
156 | if (mesh != null) | ||
157 | { | ||
158 | if (mesh.Type == (SByte)AssetType.Mesh) | ||
159 | { | ||
160 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | ||
161 | responsedata["content_type"] = "application/vnd.ll.mesh"; | ||
162 | responsedata["int_response_code"] = 200; | ||
163 | } | ||
164 | // Optionally add additional mesh types here | ||
165 | else | ||
166 | { | ||
167 | responsedata["int_response_code"] = 404; //501; //410; //404; | ||
168 | responsedata["content_type"] = "text/plain"; | ||
169 | responsedata["keepalive"] = false; | ||
170 | responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; | ||
171 | return responsedata; | ||
172 | } | ||
173 | } | ||
174 | else | ||
175 | { | ||
176 | mesh = m_assetService.Get(meshID.ToString()); | ||
177 | if (mesh != null) | ||
178 | { | ||
179 | if (mesh.Type == (SByte)AssetType.Mesh) | ||
180 | { | ||
181 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | ||
182 | responsedata["content_type"] = "application/vnd.ll.mesh"; | ||
183 | responsedata["int_response_code"] = 200; | ||
184 | } | ||
185 | // Optionally add additional mesh types here | ||
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"] = "Unfortunately, this asset isn't a mesh."; | ||
192 | return responsedata; | ||
193 | } | ||
194 | } | ||
195 | |||
196 | else | ||
197 | { | ||
198 | responsedata["int_response_code"] = 404; //501; //410; //404; | ||
199 | responsedata["content_type"] = "text/plain"; | ||
200 | responsedata["keepalive"] = false; | ||
201 | responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; | ||
202 | return responsedata; | ||
203 | } | ||
204 | } | ||
205 | |||
206 | } | ||
207 | |||
208 | return responsedata; | ||
209 | } | ||
210 | } | ||
211 | } | ||