clockwerk-opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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.Generic; |
||
31 | using System.Collections.Specialized; |
||
32 | using System.Drawing; |
||
33 | using System.Drawing.Imaging; |
||
34 | using System.Reflection; |
||
35 | using System.IO; |
||
36 | using System.Web; |
||
37 | using log4net; |
||
38 | using Nini.Config; |
||
39 | using Mono.Addins; |
||
40 | using OpenMetaverse; |
||
41 | using OpenMetaverse.StructuredData; |
||
42 | using OpenMetaverse.Imaging; |
||
43 | using OpenSim.Framework; |
||
44 | using OpenSim.Framework.Servers; |
||
45 | using OpenSim.Framework.Servers.HttpServer; |
||
46 | using OpenSim.Region.Framework.Interfaces; |
||
47 | using OpenSim.Region.Framework.Scenes; |
||
48 | using OpenSim.Services.Interfaces; |
||
49 | using Caps = OpenSim.Framework.Capabilities.Caps; |
||
50 | using OpenSim.Capabilities.Handlers; |
||
51 | |||
52 | namespace OpenSim.Region.ClientStack.Linden |
||
53 | { |
||
54 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UploadBakedTextureModule")] |
||
55 | public class UploadBakedTextureModule : INonSharedRegionModule |
||
56 | { |
||
57 | private static readonly ILog m_log = |
||
58 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
59 | |||
60 | /// <summary> |
||
61 | /// For historical reasons this is fixed, but there |
||
62 | /// </summary> |
||
63 | private static readonly string m_uploadBakedTexturePath = "0010/";// This is in the LandManagementModule. |
||
64 | |||
65 | private Scene m_scene; |
||
66 | private bool m_persistBakedTextures; |
||
67 | |||
68 | private IBakedTextureModule m_BakedTextureModule; |
||
69 | |||
70 | public void Initialise(IConfigSource source) |
||
71 | { |
||
72 | IConfig appearanceConfig = source.Configs["Appearance"]; |
||
73 | if (appearanceConfig != null) |
||
74 | m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); |
||
75 | |||
76 | |||
77 | } |
||
78 | |||
79 | public void AddRegion(Scene s) |
||
80 | { |
||
81 | m_scene = s; |
||
82 | |||
83 | } |
||
84 | |||
85 | public void RemoveRegion(Scene s) |
||
86 | { |
||
87 | s.EventManager.OnRegisterCaps -= RegisterCaps; |
||
88 | s.EventManager.OnNewPresence -= RegisterNewPresence; |
||
89 | s.EventManager.OnRemovePresence -= DeRegisterPresence; |
||
90 | m_BakedTextureModule = null; |
||
91 | m_scene = null; |
||
92 | } |
||
93 | |||
94 | |||
95 | |||
96 | public void RegionLoaded(Scene s) |
||
97 | { |
||
98 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; |
||
99 | m_scene.EventManager.OnNewPresence += RegisterNewPresence; |
||
100 | m_scene.EventManager.OnRemovePresence += DeRegisterPresence; |
||
101 | |||
102 | } |
||
103 | |||
104 | private void DeRegisterPresence(UUID agentId) |
||
105 | { |
||
106 | ScenePresence presence = null; |
||
107 | if (m_scene.TryGetScenePresence(agentId, out presence)) |
||
108 | { |
||
109 | presence.ControllingClient.OnSetAppearance -= CaptureAppearanceSettings; |
||
110 | } |
||
111 | |||
112 | } |
||
113 | |||
114 | private void RegisterNewPresence(ScenePresence presence) |
||
115 | { |
||
116 | presence.ControllingClient.OnSetAppearance += CaptureAppearanceSettings; |
||
117 | |||
118 | } |
||
119 | |||
120 | private void CaptureAppearanceSettings(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 avSize, WearableCacheItem[] cacheItems) |
||
121 | { |
||
122 | int maxCacheitemsLoop = cacheItems.Length; |
||
123 | if (maxCacheitemsLoop > AvatarWearable.MAX_WEARABLES) |
||
124 | { |
||
125 | maxCacheitemsLoop = AvatarWearable.MAX_WEARABLES; |
||
126 | m_log.WarnFormat("[CACHEDBAKES]: Too Many Cache items Provided {0}, the max is {1}. Truncating!", cacheItems.Length, AvatarWearable.MAX_WEARABLES); |
||
127 | } |
||
128 | |||
129 | m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>(); |
||
130 | if (cacheItems.Length > 0) |
||
131 | { |
||
132 | // m_log.Debug("[Cacheitems]: " + cacheItems.Length); |
||
133 | // for (int iter = 0; iter < maxCacheitemsLoop; iter++) |
||
134 | // { |
||
135 | // m_log.Debug("[Cacheitems] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" + |
||
136 | // cacheItems[iter].TextureID); |
||
137 | // } |
||
138 | |||
139 | ScenePresence p = null; |
||
140 | if (m_scene.TryGetScenePresence(remoteClient.AgentId, out p)) |
||
141 | { |
||
142 | |||
143 | WearableCacheItem[] existingitems = p.Appearance.WearableCacheItems; |
||
144 | if (existingitems == null) |
||
145 | { |
||
146 | if (m_BakedTextureModule != null) |
||
147 | { |
||
148 | WearableCacheItem[] savedcache = null; |
||
149 | try |
||
150 | { |
||
151 | if (p.Appearance.WearableCacheItemsDirty) |
||
152 | { |
||
153 | savedcache = m_BakedTextureModule.Get(p.UUID); |
||
154 | p.Appearance.WearableCacheItems = savedcache; |
||
155 | p.Appearance.WearableCacheItemsDirty = false; |
||
156 | } |
||
157 | |||
158 | } |
||
159 | /* |
||
160 | * The following Catch types DO NOT WORK with m_BakedTextureModule.Get |
||
161 | * it jumps to the General Packet Exception Handler if you don't catch Exception! |
||
162 | * |
||
163 | catch (System.Net.Sockets.SocketException) |
||
164 | { |
||
165 | cacheItems = null; |
||
166 | } |
||
167 | catch (WebException) |
||
168 | { |
||
169 | cacheItems = null; |
||
170 | } |
||
171 | catch (InvalidOperationException) |
||
172 | { |
||
173 | cacheItems = null; |
||
174 | } */ |
||
175 | catch (Exception) |
||
176 | { |
||
177 | // The service logs a sufficient error message. |
||
178 | } |
||
179 | |||
180 | |||
181 | if (savedcache != null) |
||
182 | existingitems = savedcache; |
||
183 | } |
||
184 | } |
||
185 | // Existing items null means it's a fully new appearance |
||
186 | if (existingitems == null) |
||
187 | { |
||
188 | |||
189 | for (int i = 0; i < maxCacheitemsLoop; i++) |
||
190 | { |
||
191 | if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) |
||
192 | { |
||
193 | Primitive.TextureEntryFace face = textureEntry.FaceTextures[cacheItems[i].TextureIndex]; |
||
194 | if (face == null) |
||
195 | { |
||
196 | textureEntry.CreateFace(cacheItems[i].TextureIndex); |
||
197 | textureEntry.FaceTextures[cacheItems[i].TextureIndex].TextureID = |
||
198 | AppearanceManager.DEFAULT_AVATAR_TEXTURE; |
||
199 | continue; |
||
200 | } |
||
201 | cacheItems[i].TextureID =face.TextureID; |
||
202 | if (m_scene.AssetService != null) |
||
203 | cacheItems[i].TextureAsset = |
||
204 | m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString()); |
||
205 | } |
||
206 | else |
||
207 | { |
||
208 | m_log.WarnFormat("[CACHEDBAKES]: Invalid Texture Index Provided, Texture doesn't exist or hasn't been uploaded yet {0}, the max is {1}. Skipping!", cacheItems[i].TextureIndex, textureEntry.FaceTextures.Length); |
||
209 | } |
||
210 | |||
211 | |||
212 | } |
||
213 | } |
||
214 | else |
||
215 | |||
216 | |||
217 | { |
||
218 | // for each uploaded baked texture |
||
219 | for (int i = 0; i < maxCacheitemsLoop; i++) |
||
220 | { |
||
221 | if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) |
||
222 | { |
||
223 | Primitive.TextureEntryFace face = textureEntry.FaceTextures[cacheItems[i].TextureIndex]; |
||
224 | if (face == null) |
||
225 | { |
||
226 | textureEntry.CreateFace(cacheItems[i].TextureIndex); |
||
227 | textureEntry.FaceTextures[cacheItems[i].TextureIndex].TextureID = |
||
228 | AppearanceManager.DEFAULT_AVATAR_TEXTURE; |
||
229 | continue; |
||
230 | } |
||
231 | cacheItems[i].TextureID = |
||
232 | face.TextureID; |
||
233 | } |
||
234 | else |
||
235 | { |
||
236 | m_log.WarnFormat("[CACHEDBAKES]: Invalid Texture Index Provided, Texture doesn't exist or hasn't been uploaded yet {0}, the max is {1}. Skipping!", cacheItems[i].TextureIndex, textureEntry.FaceTextures.Length); |
||
237 | } |
||
238 | } |
||
239 | |||
240 | for (int i = 0; i < maxCacheitemsLoop; i++) |
||
241 | { |
||
242 | if (cacheItems[i].TextureAsset == null) |
||
243 | { |
||
244 | cacheItems[i].TextureAsset = |
||
245 | m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString()); |
||
246 | } |
||
247 | } |
||
248 | } |
||
249 | |||
250 | |||
251 | |||
252 | p.Appearance.WearableCacheItems = cacheItems; |
||
253 | |||
254 | |||
255 | |||
256 | if (m_BakedTextureModule != null) |
||
257 | { |
||
258 | m_BakedTextureModule.Store(remoteClient.AgentId, cacheItems); |
||
259 | p.Appearance.WearableCacheItemsDirty = true; |
||
260 | |||
261 | } |
||
262 | } |
||
263 | } |
||
264 | } |
||
265 | |||
266 | public void PostInitialise() |
||
267 | { |
||
268 | } |
||
269 | |||
270 | |||
271 | |||
272 | public void Close() { } |
||
273 | |||
274 | public string Name { get { return "UploadBakedTextureModule"; } } |
||
275 | |||
276 | public Type ReplaceableInterface |
||
277 | { |
||
278 | get { return null; } |
||
279 | } |
||
280 | |||
281 | public void RegisterCaps(UUID agentID, Caps caps) |
||
282 | { |
||
283 | UploadBakedTextureHandler avatarhandler = new UploadBakedTextureHandler( |
||
284 | caps, m_scene.AssetService, m_persistBakedTextures); |
||
285 | |||
286 | |||
287 | |||
288 | caps.RegisterHandler( |
||
289 | "UploadBakedTexture", |
||
290 | new RestStreamHandler( |
||
291 | "POST", |
||
292 | "/CAPS/" + caps.CapsObjectPath + m_uploadBakedTexturePath, |
||
293 | avatarhandler.UploadBakedTexture, |
||
294 | "UploadBakedTexture", |
||
295 | agentID.ToString())); |
||
296 | |||
297 | |||
298 | |||
299 | |||
300 | } |
||
301 | } |
||
302 | } |