diff options
author | Jonathan Freedman | 2010-10-17 18:45:25 -0400 |
---|---|---|
committer | Jonathan Freedman | 2010-10-17 18:45:25 -0400 |
commit | 4e4fb93fae6c13ca6c6ac521991c4e4969b0fe65 (patch) | |
tree | 79142f2364b658f52b63e3ae688a5521290e2a4f /OpenSim/Region/CoreModules/Avatar/Assets/GetMeshModule.cs | |
parent | * more url / hg cleanup (diff) | |
parent | Merge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC_OLD-4e4fb93fae6c13ca6c6ac521991c4e4969b0fe65.zip opensim-SC_OLD-4e4fb93fae6c13ca6c6ac521991c4e4969b0fe65.tar.gz opensim-SC_OLD-4e4fb93fae6c13ca6c6ac521991c4e4969b0fe65.tar.bz2 opensim-SC_OLD-4e4fb93fae6c13ca6c6ac521991c4e4969b0fe65.tar.xz |
Merge branch 'master' of git://opensimulator.org/git/opensim
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Assets/GetMeshModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Assets/GetMeshModule.cs | 202 |
1 files changed, 202 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..36aaab3 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Assets/GetMeshModule.cs | |||
@@ -0,0 +1,202 @@ | |||
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("GET", "/CAPS/" + capID, | ||
108 | delegate(Hashtable m_dhttpMethod) | ||
109 | { | ||
110 | return ProcessGetMesh(m_dhttpMethod, agentID, caps); | ||
111 | })); | ||
112 | |||
113 | } | ||
114 | |||
115 | #endregion | ||
116 | |||
117 | public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap) | ||
118 | { | ||
119 | |||
120 | Hashtable responsedata = new Hashtable(); | ||
121 | responsedata["int_response_code"] = 400; //501; //410; //404; | ||
122 | responsedata["content_type"] = "text/plain"; | ||
123 | responsedata["keepalive"] = false; | ||
124 | responsedata["str_response_string"] = "Request wasn't what was expected"; | ||
125 | |||
126 | string meshStr = string.Empty; | ||
127 | |||
128 | if (request.ContainsKey("mesh_id")) | ||
129 | meshStr = request["mesh_id"].ToString(); | ||
130 | |||
131 | |||
132 | UUID meshID = UUID.Zero; | ||
133 | if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID)) | ||
134 | { | ||
135 | if (m_assetService == null) | ||
136 | { | ||
137 | responsedata["int_response_code"] = 404; //501; //410; //404; | ||
138 | responsedata["content_type"] = "text/plain"; | ||
139 | responsedata["keepalive"] = false; | ||
140 | responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh."; | ||
141 | return responsedata; | ||
142 | } | ||
143 | |||
144 | AssetBase mesh; | ||
145 | // Only try to fetch locally cached textures. Misses are redirected | ||
146 | mesh = m_assetService.GetCached(meshID.ToString()); | ||
147 | if (mesh != null) | ||
148 | { | ||
149 | if (mesh.Type == (SByte)AssetType.Mesh) | ||
150 | { | ||
151 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | ||
152 | responsedata["content_type"] = "application/vnd.ll.mesh"; | ||
153 | responsedata["int_response_code"] = 200; | ||
154 | } | ||
155 | // Optionally add additional mesh types here | ||
156 | else | ||
157 | { | ||
158 | responsedata["int_response_code"] = 404; //501; //410; //404; | ||
159 | responsedata["content_type"] = "text/plain"; | ||
160 | responsedata["keepalive"] = false; | ||
161 | responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; | ||
162 | return responsedata; | ||
163 | } | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | mesh = m_assetService.Get(meshID.ToString()); | ||
168 | if (mesh != null) | ||
169 | { | ||
170 | if (mesh.Type == (SByte)AssetType.Mesh) | ||
171 | { | ||
172 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | ||
173 | responsedata["content_type"] = "application/vnd.ll.mesh"; | ||
174 | responsedata["int_response_code"] = 200; | ||
175 | } | ||
176 | // Optionally add additional mesh types here | ||
177 | else | ||
178 | { | ||
179 | responsedata["int_response_code"] = 404; //501; //410; //404; | ||
180 | responsedata["content_type"] = "text/plain"; | ||
181 | responsedata["keepalive"] = false; | ||
182 | responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; | ||
183 | return responsedata; | ||
184 | } | ||
185 | } | ||
186 | |||
187 | else | ||
188 | { | ||
189 | responsedata["int_response_code"] = 404; //501; //410; //404; | ||
190 | responsedata["content_type"] = "text/plain"; | ||
191 | responsedata["keepalive"] = false; | ||
192 | responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; | ||
193 | return responsedata; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | } | ||
198 | |||
199 | return responsedata; | ||
200 | } | ||
201 | } | ||
202 | } | ||