aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Cache/AssetCache.cs
diff options
context:
space:
mode:
authorMW2007-07-25 18:19:38 +0000
committerMW2007-07-25 18:19:38 +0000
commit2b42ea0a429c722bd7c5c67d3815c2ddc8399e78 (patch)
tree0a6338ff52efbdaadaa9a307bee618867460cfb6 /OpenSim/Framework/Communications/Cache/AssetCache.cs
parent* Terrain now uses the older slower method again until the fast version can b... (diff)
downloadopensim-SC_OLD-2b42ea0a429c722bd7c5c67d3815c2ddc8399e78.zip
opensim-SC_OLD-2b42ea0a429c722bd7c5c67d3815c2ddc8399e78.tar.gz
opensim-SC_OLD-2b42ea0a429c722bd7c5c67d3815c2ddc8399e78.tar.bz2
opensim-SC_OLD-2b42ea0a429c722bd7c5c67d3815c2ddc8399e78.tar.xz
Start of the OpenSim library , for now only contains a few textures.
Diffstat (limited to 'OpenSim/Framework/Communications/Cache/AssetCache.cs')
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetCache.cs1122
1 files changed, 561 insertions, 561 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs
index 3d0fd76..a3480ec 100644
--- a/OpenSim/Framework/Communications/Cache/AssetCache.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs
@@ -1,561 +1,561 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32using System.Reflection; 32using System.Reflection;
33using System.Threading; 33using System.Threading;
34using libsecondlife; 34using libsecondlife;
35using libsecondlife.Packets; 35using libsecondlife.Packets;
36using OpenSim.Framework.Interfaces; 36using OpenSim.Framework.Interfaces;
37using OpenSim.Framework.Servers; 37using OpenSim.Framework.Servers;
38using OpenSim.Framework.Types; 38using OpenSim.Framework.Types;
39using OpenSim.Framework.Utilities; 39using OpenSim.Framework.Utilities;
40 40
41namespace OpenSim.Framework.Communications.Caches 41namespace OpenSim.Framework.Communications.Caches
42{ 42{
43 public delegate void DownloadComplete(AssetCache.TextureSender sender); 43 public delegate void DownloadComplete(AssetCache.TextureSender sender);
44 44
45 public class AssetCache : IAssetReceiver 45 public class AssetCache : IAssetReceiver
46 { 46 {
47 // Fields 47 // Fields
48 private Thread _assetCacheThread; 48 private Thread _assetCacheThread;
49 private IAssetServer _assetServer; 49 private IAssetServer _assetServer;
50 public List<AssetRequest> AssetRequests; 50 public List<AssetRequest> AssetRequests;
51 public Dictionary<LLUUID, AssetInfo> Assets; 51 public Dictionary<LLUUID, AssetInfo> Assets;
52 public Dictionary<LLUUID, AssetRequest> RequestedAssets; 52 public Dictionary<LLUUID, AssetRequest> RequestedAssets;
53 public Dictionary<LLUUID, AssetRequest> RequestedTextures; 53 public Dictionary<LLUUID, AssetRequest> RequestedTextures;
54 public Dictionary<LLUUID, TextureSender> SendingTextures; 54 public Dictionary<LLUUID, TextureSender> SendingTextures;
55 private LLUUID[] textureList; 55 private LLUUID[] textureList;
56 public List<AssetRequest> TextureRequests; 56 public List<AssetRequest> TextureRequests;
57 public Dictionary<LLUUID, TextureImage> Textures; 57 public Dictionary<LLUUID, TextureImage> Textures;
58 58
59 // Methods 59 // Methods
60 public AssetCache(IAssetServer assetServer) 60 public AssetCache(IAssetServer assetServer)
61 { 61 {
62 this.AssetRequests = new List<AssetRequest>(); 62 this.AssetRequests = new List<AssetRequest>();
63 this.TextureRequests = new List<AssetRequest>(); 63 this.TextureRequests = new List<AssetRequest>();
64 this.RequestedAssets = new Dictionary<LLUUID, AssetRequest>(); 64 this.RequestedAssets = new Dictionary<LLUUID, AssetRequest>();
65 this.RequestedTextures = new Dictionary<LLUUID, AssetRequest>(); 65 this.RequestedTextures = new Dictionary<LLUUID, AssetRequest>();
66 this.SendingTextures = new Dictionary<LLUUID, TextureSender>(); 66 this.SendingTextures = new Dictionary<LLUUID, TextureSender>();
67 this.textureList = new LLUUID[5]; 67 this.textureList = new LLUUID[5];
68 Console.WriteLine("Creating Asset cache"); 68 Console.WriteLine("Creating Asset cache");
69 this._assetServer = assetServer; 69 this._assetServer = assetServer;
70 this._assetServer.SetReceiver(this); 70 this._assetServer.SetReceiver(this);
71 this.Assets = new Dictionary<LLUUID, AssetInfo>(); 71 this.Assets = new Dictionary<LLUUID, AssetInfo>();
72 this.Textures = new Dictionary<LLUUID, TextureImage>(); 72 this.Textures = new Dictionary<LLUUID, TextureImage>();
73 this._assetCacheThread = new Thread(new ThreadStart(this.RunAssetManager)); 73 this._assetCacheThread = new Thread(new ThreadStart(this.RunAssetManager));
74 this._assetCacheThread.IsBackground = true; 74 this._assetCacheThread.IsBackground = true;
75 this._assetCacheThread.Start(); 75 this._assetCacheThread.Start();
76 } 76 }
77 77
78 public AssetCache(string assetServerDLLName, string assetServerURL, string assetServerKey) 78 public AssetCache(string assetServerDLLName, string assetServerURL, string assetServerKey)
79 { 79 {
80 this.AssetRequests = new List<AssetRequest>(); 80 this.AssetRequests = new List<AssetRequest>();
81 this.TextureRequests = new List<AssetRequest>(); 81 this.TextureRequests = new List<AssetRequest>();
82 this.RequestedAssets = new Dictionary<LLUUID, AssetRequest>(); 82 this.RequestedAssets = new Dictionary<LLUUID, AssetRequest>();
83 this.RequestedTextures = new Dictionary<LLUUID, AssetRequest>(); 83 this.RequestedTextures = new Dictionary<LLUUID, AssetRequest>();
84 this.SendingTextures = new Dictionary<LLUUID, TextureSender>(); 84 this.SendingTextures = new Dictionary<LLUUID, TextureSender>();
85 this.textureList = new LLUUID[5]; 85 this.textureList = new LLUUID[5];
86 Console.WriteLine("Creating Asset cache"); 86 Console.WriteLine("Creating Asset cache");
87 this._assetServer = this.LoadAssetDll(assetServerDLLName); 87 this._assetServer = this.LoadAssetDll(assetServerDLLName);
88 this._assetServer.SetServerInfo(assetServerURL, assetServerKey); 88 this._assetServer.SetServerInfo(assetServerURL, assetServerKey);
89 this._assetServer.SetReceiver(this); 89 this._assetServer.SetReceiver(this);
90 this.Assets = new Dictionary<LLUUID, AssetInfo>(); 90 this.Assets = new Dictionary<LLUUID, AssetInfo>();
91 this.Textures = new Dictionary<LLUUID, TextureImage>(); 91 this.Textures = new Dictionary<LLUUID, TextureImage>();
92 this._assetCacheThread = new Thread(new ThreadStart(this.RunAssetManager)); 92 this._assetCacheThread = new Thread(new ThreadStart(this.RunAssetManager));
93 this._assetCacheThread.IsBackground = true; 93 this._assetCacheThread.IsBackground = true;
94 this._assetCacheThread.Start(); 94 this._assetCacheThread.Start();
95 } 95 }
96 96
97 public void AddAsset(AssetBase asset) 97 public void AddAsset(AssetBase asset)
98 { 98 {
99 if (asset.Type == 0) 99 if (asset.Type == 0)
100 { 100 {
101 if (!this.Textures.ContainsKey(asset.FullID)) 101 if (!this.Textures.ContainsKey(asset.FullID))
102 { 102 {
103 TextureImage image = new TextureImage(asset); 103 TextureImage image = new TextureImage(asset);
104 this.Textures.Add(image.FullID, image); 104 this.Textures.Add(image.FullID, image);
105 this._assetServer.UploadNewAsset(asset); 105 this._assetServer.UploadNewAsset(asset);
106 } 106 }
107 } 107 }
108 else if (!this.Assets.ContainsKey(asset.FullID)) 108 else if (!this.Assets.ContainsKey(asset.FullID))
109 { 109 {
110 AssetInfo info = new AssetInfo(asset); 110 AssetInfo info = new AssetInfo(asset);
111 this.Assets.Add(info.FullID, info); 111 this.Assets.Add(info.FullID, info);
112 this._assetServer.UploadNewAsset(asset); 112 this._assetServer.UploadNewAsset(asset);
113 } 113 }
114 } 114 }
115 115
116 public void AddAssetRequest(IClientAPI userInfo, TransferRequestPacket transferRequest) 116 public void AddAssetRequest(IClientAPI userInfo, TransferRequestPacket transferRequest)
117 { 117 {
118 LLUUID assetID = new LLUUID(transferRequest.TransferInfo.Params, 0); 118 LLUUID assetID = new LLUUID(transferRequest.TransferInfo.Params, 0);
119 if (!this.Assets.ContainsKey(assetID)) 119 if (!this.Assets.ContainsKey(assetID))
120 { 120 {
121 if (!this.RequestedAssets.ContainsKey(assetID)) 121 if (!this.RequestedAssets.ContainsKey(assetID))
122 { 122 {
123 AssetRequest request = new AssetRequest(); 123 AssetRequest request = new AssetRequest();
124 request.RequestUser = userInfo; 124 request.RequestUser = userInfo;
125 request.RequestAssetID = assetID; 125 request.RequestAssetID = assetID;
126 request.TransferRequestID = transferRequest.TransferInfo.TransferID; 126 request.TransferRequestID = transferRequest.TransferInfo.TransferID;
127 this.RequestedAssets.Add(assetID, request); 127 this.RequestedAssets.Add(assetID, request);
128 this._assetServer.RequestAsset(assetID, false); 128 this._assetServer.RequestAsset(assetID, false);
129 } 129 }
130 } 130 }
131 else 131 else
132 { 132 {
133 AssetInfo info = this.Assets[assetID]; 133 AssetInfo info = this.Assets[assetID];
134 AssetRequest request2 = new AssetRequest(); 134 AssetRequest request2 = new AssetRequest();
135 request2.RequestUser = userInfo; 135 request2.RequestUser = userInfo;
136 request2.RequestAssetID = assetID; 136 request2.RequestAssetID = assetID;
137 request2.TransferRequestID = transferRequest.TransferInfo.TransferID; 137 request2.TransferRequestID = transferRequest.TransferInfo.TransferID;
138 request2.AssetInf = info; 138 request2.AssetInf = info;
139 if (info.Data.LongLength > 600) 139 if (info.Data.LongLength > 600)
140 { 140 {
141 request2.NumPackets = 1 + (((info.Data.Length - 600) + 0x3e7) / 0x3e8); 141 request2.NumPackets = 1 + (((info.Data.Length - 600) + 0x3e7) / 0x3e8);
142 } 142 }
143 else 143 else
144 { 144 {
145 request2.NumPackets = 1; 145 request2.NumPackets = 1;
146 } 146 }
147 this.AssetRequests.Add(request2); 147 this.AssetRequests.Add(request2);
148 } 148 }
149 } 149 }
150 150
151 public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID) 151 public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID)
152 { 152 {
153 if (!this.Textures.ContainsKey(imageID)) 153 if (!this.Textures.ContainsKey(imageID))
154 { 154 {
155 if (!this.RequestedTextures.ContainsKey(imageID)) 155 if (!this.RequestedTextures.ContainsKey(imageID))
156 { 156 {
157 AssetRequest request = new AssetRequest(); 157 AssetRequest request = new AssetRequest();
158 request.RequestUser = userInfo; 158 request.RequestUser = userInfo;
159 request.RequestAssetID = imageID; 159 request.RequestAssetID = imageID;
160 request.IsTextureRequest = true; 160 request.IsTextureRequest = true;
161 this.RequestedTextures.Add(imageID, request); 161 this.RequestedTextures.Add(imageID, request);
162 this._assetServer.RequestAsset(imageID, true); 162 this._assetServer.RequestAsset(imageID, true);
163 } 163 }
164 } 164 }
165 else 165 else
166 { 166 {
167 TextureImage image = this.Textures[imageID]; 167 TextureImage image = this.Textures[imageID];
168 AssetRequest request2 = new AssetRequest(); 168 AssetRequest request2 = new AssetRequest();
169 request2.RequestUser = userInfo; 169 request2.RequestUser = userInfo;
170 request2.RequestAssetID = imageID; 170 request2.RequestAssetID = imageID;
171 request2.IsTextureRequest = true; 171 request2.IsTextureRequest = true;
172 request2.ImageInfo = image; 172 request2.ImageInfo = image;
173 if (image.Data.LongLength > 600) 173 if (image.Data.LongLength > 600)
174 { 174 {
175 request2.NumPackets = 1 + (((image.Data.Length - 600) + 0x3e7) / 0x3e8); 175 request2.NumPackets = 1 + (((image.Data.Length - 600) + 0x3e7) / 0x3e8);
176 } 176 }
177 else 177 else
178 { 178 {
179 request2.NumPackets = 1; 179 request2.NumPackets = 1;
180 } 180 }
181 this.TextureRequests.Add(request2); 181 this.TextureRequests.Add(request2);
182 } 182 }
183 } 183 }
184 184
185 public void AssetNotFound(AssetBase asset) 185 public void AssetNotFound(AssetBase asset)
186 { 186 {
187 } 187 }
188 188
189 public void AssetReceived(AssetBase asset, bool IsTexture) 189 public void AssetReceived(AssetBase asset, bool IsTexture)
190 { 190 {
191 if (asset.FullID != LLUUID.Zero) 191 if (asset.FullID != LLUUID.Zero)
192 { 192 {
193 if (IsTexture) 193 if (IsTexture)
194 { 194 {
195 TextureImage image = new TextureImage(asset); 195 TextureImage image = new TextureImage(asset);
196 this.Textures.Add(image.FullID, image); 196 this.Textures.Add(image.FullID, image);
197 if (this.RequestedTextures.ContainsKey(image.FullID)) 197 if (this.RequestedTextures.ContainsKey(image.FullID))
198 { 198 {
199 AssetRequest request = this.RequestedTextures[image.FullID]; 199 AssetRequest request = this.RequestedTextures[image.FullID];
200 request.ImageInfo = image; 200 request.ImageInfo = image;
201 if (image.Data.LongLength > 600) 201 if (image.Data.LongLength > 600)
202 { 202 {
203 request.NumPackets = 1 + (((image.Data.Length - 600) + 0x3e7) / 0x3e8); 203 request.NumPackets = 1 + (((image.Data.Length - 600) + 0x3e7) / 0x3e8);
204 } 204 }
205 else 205 else
206 { 206 {
207 request.NumPackets = 1; 207 request.NumPackets = 1;
208 } 208 }
209 this.RequestedTextures.Remove(image.FullID); 209 this.RequestedTextures.Remove(image.FullID);
210 this.TextureRequests.Add(request); 210 this.TextureRequests.Add(request);
211 } 211 }
212 } 212 }
213 else 213 else
214 { 214 {
215 AssetInfo info = new AssetInfo(asset); 215 AssetInfo info = new AssetInfo(asset);
216 this.Assets.Add(info.FullID, info); 216 this.Assets.Add(info.FullID, info);
217 if (this.RequestedAssets.ContainsKey(info.FullID)) 217 if (this.RequestedAssets.ContainsKey(info.FullID))
218 { 218 {
219 AssetRequest request2 = this.RequestedAssets[info.FullID]; 219 AssetRequest request2 = this.RequestedAssets[info.FullID];
220 request2.AssetInf = info; 220 request2.AssetInf = info;
221 if (info.Data.LongLength > 600) 221 if (info.Data.LongLength > 600)
222 { 222 {
223 request2.NumPackets = 1 + (((info.Data.Length - 600) + 0x3e7) / 0x3e8); 223 request2.NumPackets = 1 + (((info.Data.Length - 600) + 0x3e7) / 0x3e8);
224 } 224 }
225 else 225 else
226 { 226 {
227 request2.NumPackets = 1; 227 request2.NumPackets = 1;
228 } 228 }
229 this.RequestedAssets.Remove(info.FullID); 229 this.RequestedAssets.Remove(info.FullID);
230 this.AssetRequests.Add(request2); 230 this.AssetRequests.Add(request2);
231 } 231 }
232 } 232 }
233 } 233 }
234 } 234 }
235 235
236 public AssetInfo CloneAsset(LLUUID newOwner, AssetInfo sourceAsset) 236 public AssetInfo CloneAsset(LLUUID newOwner, AssetInfo sourceAsset)
237 { 237 {
238 AssetInfo info = new AssetInfo(); 238 AssetInfo info = new AssetInfo();
239 info.Data = new byte[sourceAsset.Data.Length]; 239 info.Data = new byte[sourceAsset.Data.Length];
240 Array.Copy(sourceAsset.Data, info.Data, sourceAsset.Data.Length); 240 Array.Copy(sourceAsset.Data, info.Data, sourceAsset.Data.Length);
241 info.FullID = LLUUID.Random(); 241 info.FullID = LLUUID.Random();
242 info.Type = sourceAsset.Type; 242 info.Type = sourceAsset.Type;
243 info.InvType = sourceAsset.InvType; 243 info.InvType = sourceAsset.InvType;
244 return info; 244 return info;
245 } 245 }
246 246
247 public TextureImage CloneImage(LLUUID newOwner, TextureImage source) 247 public TextureImage CloneImage(LLUUID newOwner, TextureImage source)
248 { 248 {
249 TextureImage image = new TextureImage(); 249 TextureImage image = new TextureImage();
250 image.Data = new byte[source.Data.Length]; 250 image.Data = new byte[source.Data.Length];
251 Array.Copy(source.Data, image.Data, source.Data.Length); 251 Array.Copy(source.Data, image.Data, source.Data.Length);
252 image.FullID = LLUUID.Random(); 252 image.FullID = LLUUID.Random();
253 image.Name = source.Name; 253 image.Name = source.Name;
254 return image; 254 return image;
255 } 255 }
256 256
257 public AssetBase[] CreateNewInventorySet(LLUUID agentID) 257 public AssetBase[] CreateNewInventorySet(LLUUID agentID)
258 { 258 {
259 AssetBase[] baseArray = new AssetBase[this.textureList.Length]; 259 AssetBase[] baseArray = new AssetBase[this.textureList.Length];
260 for (int i = 0; i < this.textureList.Length; i++) 260 for (int i = 0; i < this.textureList.Length; i++)
261 { 261 {
262 if (this.Textures.ContainsKey(this.textureList[i])) 262 if (this.Textures.ContainsKey(this.textureList[i]))
263 { 263 {
264 baseArray[i] = this.CloneImage(agentID, this.Textures[this.textureList[i]]); 264 baseArray[i] = this.CloneImage(agentID, this.Textures[this.textureList[i]]);
265 TextureImage asset = new TextureImage(baseArray[i]); 265 TextureImage asset = new TextureImage(baseArray[i]);
266 this.Textures.Add(asset.FullID, asset); 266 this.Textures.Add(asset.FullID, asset);
267 this._assetServer.UploadNewAsset(asset); 267 this._assetServer.UploadNewAsset(asset);
268 } 268 }
269 } 269 }
270 return baseArray; 270 return baseArray;
271 } 271 }
272 272
273 public AssetBase GetAsset(LLUUID assetID) 273 public AssetBase GetAsset(LLUUID assetID)
274 { 274 {
275 AssetBase base2 = null; 275 AssetBase base2 = null;
276 if (this.Textures.ContainsKey(assetID)) 276 if (this.Textures.ContainsKey(assetID))
277 { 277 {
278 return this.Textures[assetID]; 278 return this.Textures[assetID];
279 } 279 }
280 if (this.Assets.ContainsKey(assetID)) 280 if (this.Assets.ContainsKey(assetID))
281 { 281 {
282 base2 = this.Assets[assetID]; 282 base2 = this.Assets[assetID];
283 } 283 }
284 return base2; 284 return base2;
285 } 285 }
286 286
287 private IAssetServer LoadAssetDll(string dllName) 287 private IAssetServer LoadAssetDll(string dllName)
288 { 288 {
289 Assembly assembly = Assembly.LoadFrom(dllName); 289 Assembly assembly = Assembly.LoadFrom(dllName);
290 IAssetServer assetServer = null; 290 IAssetServer assetServer = null;
291 foreach (Type type in assembly.GetTypes()) 291 foreach (Type type in assembly.GetTypes())
292 { 292 {
293 if (type.IsPublic && !type.IsAbstract) 293 if (type.IsPublic && !type.IsAbstract)
294 { 294 {
295 if (type.GetInterface("IAssetPlugin", true) != null) 295 if (type.GetInterface("IAssetPlugin", true) != null)
296 { 296 {
297 assetServer = ((IAssetPlugin)Activator.CreateInstance(assembly.GetType(type.ToString()))).GetAssetServer(); 297 assetServer = ((IAssetPlugin)Activator.CreateInstance(assembly.GetType(type.ToString()))).GetAssetServer();
298 break; 298 break;
299 } 299 }
300 } 300 }
301 } 301 }
302 assembly = null; 302 assembly = null;
303 return assetServer; 303 return assetServer;
304 } 304 }
305 305
306 public void LoadDefaultTextureSet() 306 public void LoadDefaultTextureSet()
307 { 307 {
308 this.textureList[0] = new LLUUID("00000000-0000-0000-9999-000000000001"); 308 this.textureList[0] = new LLUUID("00000000-0000-0000-9999-000000000001");
309 this.textureList[1] = new LLUUID("00000000-0000-0000-9999-000000000002"); 309 this.textureList[1] = new LLUUID("00000000-0000-0000-9999-000000000002");
310 this.textureList[2] = new LLUUID("00000000-0000-0000-9999-000000000003"); 310 this.textureList[2] = new LLUUID("00000000-0000-0000-9999-000000000003");
311 this.textureList[3] = new LLUUID("00000000-0000-0000-9999-000000000004"); 311 this.textureList[3] = new LLUUID("00000000-0000-0000-9999-000000000004");
312 this.textureList[4] = new LLUUID("00000000-0000-0000-9999-000000000005"); 312 this.textureList[4] = new LLUUID("00000000-0000-0000-9999-000000000005");
313 for (int i = 0; i < this.textureList.Length; i++) 313 for (int i = 0; i < this.textureList.Length; i++)
314 { 314 {
315 this._assetServer.RequestAsset(this.textureList[i], true); 315 this._assetServer.RequestAsset(this.textureList[i], true);
316 } 316 }
317 } 317 }
318 318
319 private void ProcessAssetQueue() 319 private void ProcessAssetQueue()
320 { 320 {
321 if (this.AssetRequests.Count != 0) 321 if (this.AssetRequests.Count != 0)
322 { 322 {
323 int num; 323 int num;
324 if (this.AssetRequests.Count < 5) 324 if (this.AssetRequests.Count < 5)
325 { 325 {
326 num = this.AssetRequests.Count; 326 num = this.AssetRequests.Count;
327 } 327 }
328 else 328 else
329 { 329 {
330 num = 5; 330 num = 5;
331 } 331 }
332 for (int i = 0; i < num; i++) 332 for (int i = 0; i < num; i++)
333 { 333 {
334 AssetRequest request = this.AssetRequests[i]; 334 AssetRequest request = this.AssetRequests[i];
335 TransferInfoPacket newPack = new TransferInfoPacket(); 335 TransferInfoPacket newPack = new TransferInfoPacket();
336 newPack.TransferInfo.ChannelType = 2; 336 newPack.TransferInfo.ChannelType = 2;
337 newPack.TransferInfo.Status = 0; 337 newPack.TransferInfo.Status = 0;
338 newPack.TransferInfo.TargetType = 0; 338 newPack.TransferInfo.TargetType = 0;
339 newPack.TransferInfo.Params = request.RequestAssetID.GetBytes(); 339 newPack.TransferInfo.Params = request.RequestAssetID.GetBytes();
340 newPack.TransferInfo.Size = request.AssetInf.Data.Length; 340 newPack.TransferInfo.Size = request.AssetInf.Data.Length;
341 newPack.TransferInfo.TransferID = request.TransferRequestID; 341 newPack.TransferInfo.TransferID = request.TransferRequestID;
342 request.RequestUser.OutPacket(newPack); 342 request.RequestUser.OutPacket(newPack);
343 if (request.NumPackets == 1) 343 if (request.NumPackets == 1)
344 { 344 {
345 TransferPacketPacket packet2 = new TransferPacketPacket(); 345 TransferPacketPacket packet2 = new TransferPacketPacket();
346 packet2.TransferData.Packet = 0; 346 packet2.TransferData.Packet = 0;
347 packet2.TransferData.ChannelType = 2; 347 packet2.TransferData.ChannelType = 2;
348 packet2.TransferData.TransferID = request.TransferRequestID; 348 packet2.TransferData.TransferID = request.TransferRequestID;
349 packet2.TransferData.Data = request.AssetInf.Data; 349 packet2.TransferData.Data = request.AssetInf.Data;
350 packet2.TransferData.Status = 1; 350 packet2.TransferData.Status = 1;
351 request.RequestUser.OutPacket(packet2); 351 request.RequestUser.OutPacket(packet2);
352 } 352 }
353 else 353 else
354 { 354 {
355 TransferPacketPacket packet3 = new TransferPacketPacket(); 355 TransferPacketPacket packet3 = new TransferPacketPacket();
356 packet3.TransferData.Packet = 0; 356 packet3.TransferData.Packet = 0;
357 packet3.TransferData.ChannelType = 2; 357 packet3.TransferData.ChannelType = 2;
358 packet3.TransferData.TransferID = request.TransferRequestID; 358 packet3.TransferData.TransferID = request.TransferRequestID;
359 byte[] destinationArray = new byte[0x3e8]; 359 byte[] destinationArray = new byte[0x3e8];
360 Array.Copy(request.AssetInf.Data, destinationArray, 0x3e8); 360 Array.Copy(request.AssetInf.Data, destinationArray, 0x3e8);
361 packet3.TransferData.Data = destinationArray; 361 packet3.TransferData.Data = destinationArray;
362 packet3.TransferData.Status = 0; 362 packet3.TransferData.Status = 0;
363 request.RequestUser.OutPacket(packet3); 363 request.RequestUser.OutPacket(packet3);
364 packet3 = new TransferPacketPacket(); 364 packet3 = new TransferPacketPacket();
365 packet3.TransferData.Packet = 1; 365 packet3.TransferData.Packet = 1;
366 packet3.TransferData.ChannelType = 2; 366 packet3.TransferData.ChannelType = 2;
367 packet3.TransferData.TransferID = request.TransferRequestID; 367 packet3.TransferData.TransferID = request.TransferRequestID;
368 byte[] buffer2 = new byte[request.AssetInf.Data.Length - 0x3e8]; 368 byte[] buffer2 = new byte[request.AssetInf.Data.Length - 0x3e8];
369 Array.Copy(request.AssetInf.Data, 0x3e8, buffer2, 0, buffer2.Length); 369 Array.Copy(request.AssetInf.Data, 0x3e8, buffer2, 0, buffer2.Length);
370 packet3.TransferData.Data = buffer2; 370 packet3.TransferData.Data = buffer2;
371 packet3.TransferData.Status = 1; 371 packet3.TransferData.Status = 1;
372 request.RequestUser.OutPacket(packet3); 372 request.RequestUser.OutPacket(packet3);
373 } 373 }
374 } 374 }
375 for (int j = 0; j < num; j++) 375 for (int j = 0; j < num; j++)
376 { 376 {
377 this.AssetRequests.RemoveAt(0); 377 this.AssetRequests.RemoveAt(0);
378 } 378 }
379 } 379 }
380 } 380 }
381 381
382 private void ProcessTextureQueue() 382 private void ProcessTextureQueue()
383 { 383 {
384 if (this.TextureRequests.Count != 0) 384 if (this.TextureRequests.Count != 0)
385 { 385 {
386 int num = this.TextureRequests.Count; 386 int num = this.TextureRequests.Count;
387 for (int i = 0; i < num; i++) 387 for (int i = 0; i < num; i++)
388 { 388 {
389 AssetRequest req = this.TextureRequests[i]; 389 AssetRequest req = this.TextureRequests[i];
390 if (!this.SendingTextures.ContainsKey(req.ImageInfo.FullID)) 390 if (!this.SendingTextures.ContainsKey(req.ImageInfo.FullID))
391 { 391 {
392 TextureSender sender = new TextureSender(req); 392 TextureSender sender = new TextureSender(req);
393 sender.OnComplete += new DownloadComplete(this.TextureSent); 393 sender.OnComplete += new DownloadComplete(this.TextureSent);
394 lock (this.SendingTextures) 394 lock (this.SendingTextures)
395 { 395 {
396 this.SendingTextures.Add(req.ImageInfo.FullID, sender); 396 this.SendingTextures.Add(req.ImageInfo.FullID, sender);
397 } 397 }
398 } 398 }
399 } 399 }
400 this.TextureRequests.Clear(); 400 this.TextureRequests.Clear();
401 } 401 }
402 } 402 }
403 403
404 public void RunAssetManager() 404 public void RunAssetManager()
405 { 405 {
406 Label_0000: 406 Label_0000:
407 try 407 try
408 { 408 {
409 this.ProcessAssetQueue(); 409 this.ProcessAssetQueue();
410 this.ProcessTextureQueue(); 410 this.ProcessTextureQueue();
411 Thread.Sleep(500); 411 Thread.Sleep(500);
412 goto Label_0000; 412 goto Label_0000;
413 } 413 }
414 catch (Exception exception) 414 catch (Exception exception)
415 { 415 {
416 Console.WriteLine(exception.Message); 416 Console.WriteLine(exception.Message);
417 goto Label_0000; 417 goto Label_0000;
418 } 418 }
419 } 419 }
420 420
421 public void TextureSent(TextureSender sender) 421 public void TextureSent(TextureSender sender)
422 { 422 {
423 if (this.SendingTextures.ContainsKey(sender.request.ImageInfo.FullID)) 423 if (this.SendingTextures.ContainsKey(sender.request.ImageInfo.FullID))
424 { 424 {
425 lock (this.SendingTextures) 425 lock (this.SendingTextures)
426 { 426 {
427 this.SendingTextures.Remove(sender.request.ImageInfo.FullID); 427 this.SendingTextures.Remove(sender.request.ImageInfo.FullID);
428 } 428 }
429 } 429 }
430 } 430 }
431 431
432 // Nested Types 432 // Nested Types
433 public class AssetInfo : AssetBase 433 public class AssetInfo : AssetBase
434 { 434 {
435 // Methods 435 // Methods
436 public AssetInfo() 436 public AssetInfo()
437 { 437 {
438 } 438 }
439 439
440 public AssetInfo(AssetBase aBase) 440 public AssetInfo(AssetBase aBase)
441 { 441 {
442 base.Data = aBase.Data; 442 base.Data = aBase.Data;
443 base.FullID = aBase.FullID; 443 base.FullID = aBase.FullID;
444 base.Type = aBase.Type; 444 base.Type = aBase.Type;
445 base.InvType = aBase.InvType; 445 base.InvType = aBase.InvType;
446 base.Name = aBase.Name; 446 base.Name = aBase.Name;
447 base.Description = aBase.Description; 447 base.Description = aBase.Description;
448 } 448 }
449 } 449 }
450 450
451 public class AssetRequest 451 public class AssetRequest
452 { 452 {
453 // Fields 453 // Fields
454 public AssetCache.AssetInfo AssetInf; 454 public AssetCache.AssetInfo AssetInf;
455 public long DataPointer; 455 public long DataPointer;
456 public AssetCache.TextureImage ImageInfo; 456 public AssetCache.TextureImage ImageInfo;
457 public bool IsTextureRequest; 457 public bool IsTextureRequest;
458 public int NumPackets; 458 public int NumPackets;
459 public int PacketCounter; 459 public int PacketCounter;
460 public LLUUID RequestAssetID; 460 public LLUUID RequestAssetID;
461 public IClientAPI RequestUser; 461 public IClientAPI RequestUser;
462 public LLUUID TransferRequestID; 462 public LLUUID TransferRequestID;
463 } 463 }
464 464
465 public class TextureImage : AssetBase 465 public class TextureImage : AssetBase
466 { 466 {
467 // Methods 467 // Methods
468 public TextureImage() 468 public TextureImage()
469 { 469 {
470 } 470 }
471 471
472 public TextureImage(AssetBase aBase) 472 public TextureImage(AssetBase aBase)
473 { 473 {
474 base.Data = aBase.Data; 474 base.Data = aBase.Data;
475 base.FullID = aBase.FullID; 475 base.FullID = aBase.FullID;
476 base.Type = aBase.Type; 476 base.Type = aBase.Type;
477 base.InvType = aBase.InvType; 477 base.InvType = aBase.InvType;
478 base.Name = aBase.Name; 478 base.Name = aBase.Name;
479 base.Description = aBase.Description; 479 base.Description = aBase.Description;
480 } 480 }
481 } 481 }
482 482
483 public class TextureSender 483 public class TextureSender
484 { 484 {
485 // Fields 485 // Fields
486 private Thread m_thread; 486 private Thread m_thread;
487 public AssetCache.AssetRequest request; 487 public AssetCache.AssetRequest request;
488 488
489 // Events 489 // Events
490 public event DownloadComplete OnComplete; 490 public event DownloadComplete OnComplete;
491 491
492 // Methods 492 // Methods
493 public TextureSender(AssetCache.AssetRequest req) 493 public TextureSender(AssetCache.AssetRequest req)
494 { 494 {
495 this.request = req; 495 this.request = req;
496 this.m_thread = new Thread(new ThreadStart(this.SendTexture)); 496 this.m_thread = new Thread(new ThreadStart(this.SendTexture));
497 this.m_thread.IsBackground = true; 497 this.m_thread.IsBackground = true;
498 this.m_thread.Start(); 498 this.m_thread.Start();
499 } 499 }
500 500
501 public void SendPacket() 501 public void SendPacket()
502 { 502 {
503 AssetCache.AssetRequest request = this.request; 503 AssetCache.AssetRequest request = this.request;
504 if (request.PacketCounter == 0) 504 if (request.PacketCounter == 0)
505 { 505 {
506 if (request.NumPackets == 1) 506 if (request.NumPackets == 1)
507 { 507 {
508 ImageDataPacket newPack = new ImageDataPacket(); 508 ImageDataPacket newPack = new ImageDataPacket();
509 newPack.ImageID.Packets = 1; 509 newPack.ImageID.Packets = 1;
510 newPack.ImageID.ID = request.ImageInfo.FullID; 510 newPack.ImageID.ID = request.ImageInfo.FullID;
511 newPack.ImageID.Size = (uint)request.ImageInfo.Data.Length; 511 newPack.ImageID.Size = (uint)request.ImageInfo.Data.Length;
512 newPack.ImageData.Data = request.ImageInfo.Data; 512 newPack.ImageData.Data = request.ImageInfo.Data;
513 newPack.ImageID.Codec = 2; 513 newPack.ImageID.Codec = 2;
514 request.RequestUser.OutPacket(newPack); 514 request.RequestUser.OutPacket(newPack);
515 request.PacketCounter++; 515 request.PacketCounter++;
516 } 516 }
517 else 517 else
518 { 518 {
519 ImageDataPacket packet2 = new ImageDataPacket(); 519 ImageDataPacket packet2 = new ImageDataPacket();
520 packet2.ImageID.Packets = (ushort)request.NumPackets; 520 packet2.ImageID.Packets = (ushort)request.NumPackets;
521 packet2.ImageID.ID = request.ImageInfo.FullID; 521 packet2.ImageID.ID = request.ImageInfo.FullID;
522 packet2.ImageID.Size = (uint)request.ImageInfo.Data.Length; 522 packet2.ImageID.Size = (uint)request.ImageInfo.Data.Length;
523 packet2.ImageData.Data = new byte[600]; 523 packet2.ImageData.Data = new byte[600];
524 Array.Copy(request.ImageInfo.Data, 0, packet2.ImageData.Data, 0, 600); 524 Array.Copy(request.ImageInfo.Data, 0, packet2.ImageData.Data, 0, 600);
525 packet2.ImageID.Codec = 2; 525 packet2.ImageID.Codec = 2;
526 request.RequestUser.OutPacket(packet2); 526 request.RequestUser.OutPacket(packet2);
527 request.PacketCounter++; 527 request.PacketCounter++;
528 } 528 }
529 } 529 }
530 else 530 else
531 { 531 {
532 ImagePacketPacket packet3 = new ImagePacketPacket(); 532 ImagePacketPacket packet3 = new ImagePacketPacket();
533 packet3.ImageID.Packet = (ushort)request.PacketCounter; 533 packet3.ImageID.Packet = (ushort)request.PacketCounter;
534 packet3.ImageID.ID = request.ImageInfo.FullID; 534 packet3.ImageID.ID = request.ImageInfo.FullID;
535 int length = (request.ImageInfo.Data.Length - 600) - (0x3e8 * (request.PacketCounter - 1)); 535 int length = (request.ImageInfo.Data.Length - 600) - (0x3e8 * (request.PacketCounter - 1));
536 if (length > 0x3e8) 536 if (length > 0x3e8)
537 { 537 {
538 length = 0x3e8; 538 length = 0x3e8;
539 } 539 }
540 packet3.ImageData.Data = new byte[length]; 540 packet3.ImageData.Data = new byte[length];
541 Array.Copy(request.ImageInfo.Data, 600 + (0x3e8 * (request.PacketCounter - 1)), packet3.ImageData.Data, 0, length); 541 Array.Copy(request.ImageInfo.Data, 600 + (0x3e8 * (request.PacketCounter - 1)), packet3.ImageData.Data, 0, length);
542 request.RequestUser.OutPacket(packet3); 542 request.RequestUser.OutPacket(packet3);
543 request.PacketCounter++; 543 request.PacketCounter++;
544 } 544 }
545 } 545 }
546 546
547 public void SendTexture() 547 public void SendTexture()
548 { 548 {
549 while (this.request.PacketCounter != this.request.NumPackets) 549 while (this.request.PacketCounter != this.request.NumPackets)
550 { 550 {
551 this.SendPacket(); 551 this.SendPacket();
552 Thread.Sleep(500); 552 Thread.Sleep(500);
553 } 553 }
554 if (this.OnComplete != null) 554 if (this.OnComplete != null)
555 { 555 {
556 this.OnComplete(this); 556 this.OnComplete(this);
557 } 557 }
558 } 558 }
559 } 559 }
560 } 560 }
561} 561}