aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs')
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs193
1 files changed, 187 insertions, 6 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs
index 79a935d..cf95463 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic;
30using System.Collections.Specialized; 31using System.Collections.Specialized;
31using System.Drawing; 32using System.Drawing;
32using System.Drawing.Imaging; 33using System.Drawing.Imaging;
@@ -53,8 +54,8 @@ namespace OpenSim.Region.ClientStack.Linden
53 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UploadBakedTextureModule")] 54 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UploadBakedTextureModule")]
54 public class UploadBakedTextureModule : INonSharedRegionModule 55 public class UploadBakedTextureModule : INonSharedRegionModule
55 { 56 {
56// private static readonly ILog m_log = 57 private static readonly ILog m_log =
57// LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 58 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
58 59
59 /// <summary> 60 /// <summary>
60 /// For historical reasons this is fixed, but there 61 /// For historical reasons this is fixed, but there
@@ -65,6 +66,8 @@ namespace OpenSim.Region.ClientStack.Linden
65 private bool m_persistBakedTextures; 66 private bool m_persistBakedTextures;
66 private string m_URL; 67 private string m_URL;
67 68
69 private IBakedTextureModule m_BakedTextureModule;
70
68 public void Initialise(IConfigSource source) 71 public void Initialise(IConfigSource source)
69 { 72 {
70 IConfig config = source.Configs["ClientStack.LindenCaps"]; 73 IConfig config = source.Configs["ClientStack.LindenCaps"];
@@ -76,26 +79,203 @@ namespace OpenSim.Region.ClientStack.Linden
76 IConfig appearanceConfig = source.Configs["Appearance"]; 79 IConfig appearanceConfig = source.Configs["Appearance"];
77 if (appearanceConfig != null) 80 if (appearanceConfig != null)
78 m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures); 81 m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures);
82
83
79 } 84 }
80 85
81 public void AddRegion(Scene s) 86 public void AddRegion(Scene s)
82 { 87 {
83 m_scene = s; 88 m_scene = s;
89
84 } 90 }
85 91
86 public void RemoveRegion(Scene s) 92 public void RemoveRegion(Scene s)
87 { 93 {
94 s.EventManager.OnRegisterCaps -= RegisterCaps;
95 s.EventManager.OnNewPresence -= RegisterNewPresence;
96 s.EventManager.OnRemovePresence -= DeRegisterPresence;
97 m_BakedTextureModule = null;
98 m_scene = null;
88 } 99 }
89 100
101
102
90 public void RegionLoaded(Scene s) 103 public void RegionLoaded(Scene s)
91 { 104 {
92 m_scene.EventManager.OnRegisterCaps += RegisterCaps; 105 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
106 m_scene.EventManager.OnNewPresence += RegisterNewPresence;
107 m_scene.EventManager.OnRemovePresence += DeRegisterPresence;
108
109 }
110
111 private void DeRegisterPresence(UUID agentId)
112 {
113 ScenePresence presence = null;
114 if (m_scene.TryGetScenePresence(agentId, out presence))
115 {
116 presence.ControllingClient.OnSetAppearance -= CaptureAppearanceSettings;
117 }
118
119 }
120
121 private void RegisterNewPresence(ScenePresence presence)
122 {
123 presence.ControllingClient.OnSetAppearance += CaptureAppearanceSettings;
124
125 }
126
127 private void CaptureAppearanceSettings(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 avSize, WearableCacheItem[] cacheItems)
128 {
129 int maxCacheitemsLoop = cacheItems.Length;
130 if (maxCacheitemsLoop > AvatarWearable.MAX_WEARABLES)
131 {
132 maxCacheitemsLoop = AvatarWearable.MAX_WEARABLES;
133 m_log.WarnFormat("[CACHEDBAKES]: Too Many Cache items Provided {0}, the max is {1}. Truncating!", cacheItems.Length, AvatarWearable.MAX_WEARABLES);
134 }
135
136 m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
137 if (cacheItems.Length > 0)
138 {
139 m_log.Debug("[Cacheitems]: " + cacheItems.Length);
140 for (int iter = 0; iter < maxCacheitemsLoop; iter++)
141 {
142 m_log.Debug("[Cacheitems] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" +
143 cacheItems[iter].TextureID);
144 }
145
146 ScenePresence p = null;
147 if (m_scene.TryGetScenePresence(remoteClient.AgentId, out p))
148 {
149
150 WearableCacheItem[] existingitems = p.Appearance.WearableCacheItems;
151 if (existingitems == null)
152 {
153 if (m_BakedTextureModule != null)
154 {
155 WearableCacheItem[] savedcache = null;
156 try
157 {
158 if (p.Appearance.WearableCacheItemsDirty)
159 {
160 savedcache = m_BakedTextureModule.Get(p.UUID);
161 p.Appearance.WearableCacheItems = savedcache;
162 p.Appearance.WearableCacheItemsDirty = false;
163 }
164
165 }
166 /*
167 * The following Catch types DO NOT WORK with m_BakedTextureModule.Get
168 * it jumps to the General Packet Exception Handler if you don't catch Exception!
169 *
170 catch (System.Net.Sockets.SocketException)
171 {
172 cacheItems = null;
173 }
174 catch (WebException)
175 {
176 cacheItems = null;
177 }
178 catch (InvalidOperationException)
179 {
180 cacheItems = null;
181 } */
182 catch (Exception)
183 {
184 // The service logs a sufficient error message.
185 }
186
187
188 if (savedcache != null)
189 existingitems = savedcache;
190 }
191 }
192 // Existing items null means it's a fully new appearance
193 if (existingitems == null)
194 {
195
196 for (int i = 0; i < maxCacheitemsLoop; i++)
197 {
198 if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex)
199 {
200 Primitive.TextureEntryFace face = textureEntry.FaceTextures[cacheItems[i].TextureIndex];
201 if (face == null)
202 {
203 textureEntry.CreateFace(cacheItems[i].TextureIndex);
204 textureEntry.FaceTextures[cacheItems[i].TextureIndex].TextureID =
205 AppearanceManager.DEFAULT_AVATAR_TEXTURE;
206 continue;
207 }
208 cacheItems[i].TextureID =face.TextureID;
209 if (m_scene.AssetService != null)
210 cacheItems[i].TextureAsset =
211 m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString());
212 }
213 else
214 {
215 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);
216 }
217
218
219 }
220 }
221 else
222
223
224 {
225 // for each uploaded baked texture
226 for (int i = 0; i < maxCacheitemsLoop; i++)
227 {
228 if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex)
229 {
230 Primitive.TextureEntryFace face = textureEntry.FaceTextures[cacheItems[i].TextureIndex];
231 if (face == null)
232 {
233 textureEntry.CreateFace(cacheItems[i].TextureIndex);
234 textureEntry.FaceTextures[cacheItems[i].TextureIndex].TextureID =
235 AppearanceManager.DEFAULT_AVATAR_TEXTURE;
236 continue;
237 }
238 cacheItems[i].TextureID =
239 face.TextureID;
240 }
241 else
242 {
243 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);
244 }
245 }
246
247 for (int i = 0; i < maxCacheitemsLoop; i++)
248 {
249 if (cacheItems[i].TextureAsset == null)
250 {
251 cacheItems[i].TextureAsset =
252 m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString());
253 }
254 }
255 }
256
257
258
259 p.Appearance.WearableCacheItems = cacheItems;
260
261
262
263 if (m_BakedTextureModule != null)
264 {
265 m_BakedTextureModule.Store(remoteClient.AgentId, cacheItems);
266 p.Appearance.WearableCacheItemsDirty = true;
267
268 }
269 }
270 }
93 } 271 }
94 272
95 public void PostInitialise() 273 public void PostInitialise()
96 { 274 {
97 } 275 }
98 276
277
278
99 public void Close() { } 279 public void Close() { }
100 280
101 public string Name { get { return "UploadBakedTextureModule"; } } 281 public string Name { get { return "UploadBakedTextureModule"; } }
@@ -112,13 +292,15 @@ namespace OpenSim.Region.ClientStack.Linden
112 //caps.RegisterHandler("GetTexture", new StreamHandler("GET", "/CAPS/" + capID, ProcessGetTexture)); 292 //caps.RegisterHandler("GetTexture", new StreamHandler("GET", "/CAPS/" + capID, ProcessGetTexture));
113 if (m_URL == "localhost") 293 if (m_URL == "localhost")
114 { 294 {
295 UploadBakedTextureHandler avatarhandler = new UploadBakedTextureHandler(
296 caps, m_scene.AssetService, m_persistBakedTextures);
297
115 caps.RegisterHandler( 298 caps.RegisterHandler(
116 "UploadBakedTexture", 299 "UploadBakedTexture",
117 new RestStreamHandler( 300 new RestStreamHandler(
118 "POST", 301 "POST",
119 "/CAPS/" + caps.CapsObjectPath + m_uploadBakedTexturePath, 302 "/CAPS/" + caps.CapsObjectPath + m_uploadBakedTexturePath,
120 new UploadBakedTextureHandler( 303 avatarhandler.UploadBakedTexture,
121 caps, m_scene.AssetService, m_persistBakedTextures).UploadBakedTexture,
122 "UploadBakedTexture", 304 "UploadBakedTexture",
123 agentID.ToString())); 305 agentID.ToString()));
124 306
@@ -127,7 +309,6 @@ namespace OpenSim.Region.ClientStack.Linden
127 { 309 {
128 caps.RegisterHandler("UploadBakedTexture", m_URL); 310 caps.RegisterHandler("UploadBakedTexture", m_URL);
129 } 311 }
130
131 } 312 }
132 } 313 }
133} \ No newline at end of file 314}