diff options
7 files changed, 1356 insertions, 0 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs new file mode 100644 index 0000000..3d0fd76 --- /dev/null +++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs | |||
@@ -0,0 +1,561 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Text; | ||
32 | using System.Reflection; | ||
33 | using System.Threading; | ||
34 | using libsecondlife; | ||
35 | using libsecondlife.Packets; | ||
36 | using OpenSim.Framework.Interfaces; | ||
37 | using OpenSim.Framework.Servers; | ||
38 | using OpenSim.Framework.Types; | ||
39 | using OpenSim.Framework.Utilities; | ||
40 | |||
41 | namespace OpenSim.Framework.Communications.Caches | ||
42 | { | ||
43 | public delegate void DownloadComplete(AssetCache.TextureSender sender); | ||
44 | |||
45 | public class AssetCache : IAssetReceiver | ||
46 | { | ||
47 | // Fields | ||
48 | private Thread _assetCacheThread; | ||
49 | private IAssetServer _assetServer; | ||
50 | public List<AssetRequest> AssetRequests; | ||
51 | public Dictionary<LLUUID, AssetInfo> Assets; | ||
52 | public Dictionary<LLUUID, AssetRequest> RequestedAssets; | ||
53 | public Dictionary<LLUUID, AssetRequest> RequestedTextures; | ||
54 | public Dictionary<LLUUID, TextureSender> SendingTextures; | ||
55 | private LLUUID[] textureList; | ||
56 | public List<AssetRequest> TextureRequests; | ||
57 | public Dictionary<LLUUID, TextureImage> Textures; | ||
58 | |||
59 | // Methods | ||
60 | public AssetCache(IAssetServer assetServer) | ||
61 | { | ||
62 | this.AssetRequests = new List<AssetRequest>(); | ||
63 | this.TextureRequests = new List<AssetRequest>(); | ||
64 | this.RequestedAssets = new Dictionary<LLUUID, AssetRequest>(); | ||
65 | this.RequestedTextures = new Dictionary<LLUUID, AssetRequest>(); | ||
66 | this.SendingTextures = new Dictionary<LLUUID, TextureSender>(); | ||
67 | this.textureList = new LLUUID[5]; | ||
68 | Console.WriteLine("Creating Asset cache"); | ||
69 | this._assetServer = assetServer; | ||
70 | this._assetServer.SetReceiver(this); | ||
71 | this.Assets = new Dictionary<LLUUID, AssetInfo>(); | ||
72 | this.Textures = new Dictionary<LLUUID, TextureImage>(); | ||
73 | this._assetCacheThread = new Thread(new ThreadStart(this.RunAssetManager)); | ||
74 | this._assetCacheThread.IsBackground = true; | ||
75 | this._assetCacheThread.Start(); | ||
76 | } | ||
77 | |||
78 | public AssetCache(string assetServerDLLName, string assetServerURL, string assetServerKey) | ||
79 | { | ||
80 | this.AssetRequests = new List<AssetRequest>(); | ||
81 | this.TextureRequests = new List<AssetRequest>(); | ||
82 | this.RequestedAssets = new Dictionary<LLUUID, AssetRequest>(); | ||
83 | this.RequestedTextures = new Dictionary<LLUUID, AssetRequest>(); | ||
84 | this.SendingTextures = new Dictionary<LLUUID, TextureSender>(); | ||
85 | this.textureList = new LLUUID[5]; | ||
86 | Console.WriteLine("Creating Asset cache"); | ||
87 | this._assetServer = this.LoadAssetDll(assetServerDLLName); | ||
88 | this._assetServer.SetServerInfo(assetServerURL, assetServerKey); | ||
89 | this._assetServer.SetReceiver(this); | ||
90 | this.Assets = new Dictionary<LLUUID, AssetInfo>(); | ||
91 | this.Textures = new Dictionary<LLUUID, TextureImage>(); | ||
92 | this._assetCacheThread = new Thread(new ThreadStart(this.RunAssetManager)); | ||
93 | this._assetCacheThread.IsBackground = true; | ||
94 | this._assetCacheThread.Start(); | ||
95 | } | ||
96 | |||
97 | public void AddAsset(AssetBase asset) | ||
98 | { | ||
99 | if (asset.Type == 0) | ||
100 | { | ||
101 | if (!this.Textures.ContainsKey(asset.FullID)) | ||
102 | { | ||
103 | TextureImage image = new TextureImage(asset); | ||
104 | this.Textures.Add(image.FullID, image); | ||
105 | this._assetServer.UploadNewAsset(asset); | ||
106 | } | ||
107 | } | ||
108 | else if (!this.Assets.ContainsKey(asset.FullID)) | ||
109 | { | ||
110 | AssetInfo info = new AssetInfo(asset); | ||
111 | this.Assets.Add(info.FullID, info); | ||
112 | this._assetServer.UploadNewAsset(asset); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | public void AddAssetRequest(IClientAPI userInfo, TransferRequestPacket transferRequest) | ||
117 | { | ||
118 | LLUUID assetID = new LLUUID(transferRequest.TransferInfo.Params, 0); | ||
119 | if (!this.Assets.ContainsKey(assetID)) | ||
120 | { | ||
121 | if (!this.RequestedAssets.ContainsKey(assetID)) | ||
122 | { | ||
123 | AssetRequest request = new AssetRequest(); | ||
124 | request.RequestUser = userInfo; | ||
125 | request.RequestAssetID = assetID; | ||
126 | request.TransferRequestID = transferRequest.TransferInfo.TransferID; | ||
127 | this.RequestedAssets.Add(assetID, request); | ||
128 | this._assetServer.RequestAsset(assetID, false); | ||
129 | } | ||
130 | } | ||
131 | else | ||
132 | { | ||
133 | AssetInfo info = this.Assets[assetID]; | ||
134 | AssetRequest request2 = new AssetRequest(); | ||
135 | request2.RequestUser = userInfo; | ||
136 | request2.RequestAssetID = assetID; | ||
137 | request2.TransferRequestID = transferRequest.TransferInfo.TransferID; | ||
138 | request2.AssetInf = info; | ||
139 | if (info.Data.LongLength > 600) | ||
140 | { | ||
141 | request2.NumPackets = 1 + (((info.Data.Length - 600) + 0x3e7) / 0x3e8); | ||
142 | } | ||
143 | else | ||
144 | { | ||
145 | request2.NumPackets = 1; | ||
146 | } | ||
147 | this.AssetRequests.Add(request2); | ||
148 | } | ||
149 | } | ||
150 | |||
151 | public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID) | ||
152 | { | ||
153 | if (!this.Textures.ContainsKey(imageID)) | ||
154 | { | ||
155 | if (!this.RequestedTextures.ContainsKey(imageID)) | ||
156 | { | ||
157 | AssetRequest request = new AssetRequest(); | ||
158 | request.RequestUser = userInfo; | ||
159 | request.RequestAssetID = imageID; | ||
160 | request.IsTextureRequest = true; | ||
161 | this.RequestedTextures.Add(imageID, request); | ||
162 | this._assetServer.RequestAsset(imageID, true); | ||
163 | } | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | TextureImage image = this.Textures[imageID]; | ||
168 | AssetRequest request2 = new AssetRequest(); | ||
169 | request2.RequestUser = userInfo; | ||
170 | request2.RequestAssetID = imageID; | ||
171 | request2.IsTextureRequest = true; | ||
172 | request2.ImageInfo = image; | ||
173 | if (image.Data.LongLength > 600) | ||
174 | { | ||
175 | request2.NumPackets = 1 + (((image.Data.Length - 600) + 0x3e7) / 0x3e8); | ||
176 | } | ||
177 | else | ||
178 | { | ||
179 | request2.NumPackets = 1; | ||
180 | } | ||
181 | this.TextureRequests.Add(request2); | ||
182 | } | ||
183 | } | ||
184 | |||
185 | public void AssetNotFound(AssetBase asset) | ||
186 | { | ||
187 | } | ||
188 | |||
189 | public void AssetReceived(AssetBase asset, bool IsTexture) | ||
190 | { | ||
191 | if (asset.FullID != LLUUID.Zero) | ||
192 | { | ||
193 | if (IsTexture) | ||
194 | { | ||
195 | TextureImage image = new TextureImage(asset); | ||
196 | this.Textures.Add(image.FullID, image); | ||
197 | if (this.RequestedTextures.ContainsKey(image.FullID)) | ||
198 | { | ||
199 | AssetRequest request = this.RequestedTextures[image.FullID]; | ||
200 | request.ImageInfo = image; | ||
201 | if (image.Data.LongLength > 600) | ||
202 | { | ||
203 | request.NumPackets = 1 + (((image.Data.Length - 600) + 0x3e7) / 0x3e8); | ||
204 | } | ||
205 | else | ||
206 | { | ||
207 | request.NumPackets = 1; | ||
208 | } | ||
209 | this.RequestedTextures.Remove(image.FullID); | ||
210 | this.TextureRequests.Add(request); | ||
211 | } | ||
212 | } | ||
213 | else | ||
214 | { | ||
215 | AssetInfo info = new AssetInfo(asset); | ||
216 | this.Assets.Add(info.FullID, info); | ||
217 | if (this.RequestedAssets.ContainsKey(info.FullID)) | ||
218 | { | ||
219 | AssetRequest request2 = this.RequestedAssets[info.FullID]; | ||
220 | request2.AssetInf = info; | ||
221 | if (info.Data.LongLength > 600) | ||
222 | { | ||
223 | request2.NumPackets = 1 + (((info.Data.Length - 600) + 0x3e7) / 0x3e8); | ||
224 | } | ||
225 | else | ||
226 | { | ||
227 | request2.NumPackets = 1; | ||
228 | } | ||
229 | this.RequestedAssets.Remove(info.FullID); | ||
230 | this.AssetRequests.Add(request2); | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | |||
236 | public AssetInfo CloneAsset(LLUUID newOwner, AssetInfo sourceAsset) | ||
237 | { | ||
238 | AssetInfo info = new AssetInfo(); | ||
239 | info.Data = new byte[sourceAsset.Data.Length]; | ||
240 | Array.Copy(sourceAsset.Data, info.Data, sourceAsset.Data.Length); | ||
241 | info.FullID = LLUUID.Random(); | ||
242 | info.Type = sourceAsset.Type; | ||
243 | info.InvType = sourceAsset.InvType; | ||
244 | return info; | ||
245 | } | ||
246 | |||
247 | public TextureImage CloneImage(LLUUID newOwner, TextureImage source) | ||
248 | { | ||
249 | TextureImage image = new TextureImage(); | ||
250 | image.Data = new byte[source.Data.Length]; | ||
251 | Array.Copy(source.Data, image.Data, source.Data.Length); | ||
252 | image.FullID = LLUUID.Random(); | ||
253 | image.Name = source.Name; | ||
254 | return image; | ||
255 | } | ||
256 | |||
257 | public AssetBase[] CreateNewInventorySet(LLUUID agentID) | ||
258 | { | ||
259 | AssetBase[] baseArray = new AssetBase[this.textureList.Length]; | ||
260 | for (int i = 0; i < this.textureList.Length; i++) | ||
261 | { | ||
262 | if (this.Textures.ContainsKey(this.textureList[i])) | ||
263 | { | ||
264 | baseArray[i] = this.CloneImage(agentID, this.Textures[this.textureList[i]]); | ||
265 | TextureImage asset = new TextureImage(baseArray[i]); | ||
266 | this.Textures.Add(asset.FullID, asset); | ||
267 | this._assetServer.UploadNewAsset(asset); | ||
268 | } | ||
269 | } | ||
270 | return baseArray; | ||
271 | } | ||
272 | |||
273 | public AssetBase GetAsset(LLUUID assetID) | ||
274 | { | ||
275 | AssetBase base2 = null; | ||
276 | if (this.Textures.ContainsKey(assetID)) | ||
277 | { | ||
278 | return this.Textures[assetID]; | ||
279 | } | ||
280 | if (this.Assets.ContainsKey(assetID)) | ||
281 | { | ||
282 | base2 = this.Assets[assetID]; | ||
283 | } | ||
284 | return base2; | ||
285 | } | ||
286 | |||
287 | private IAssetServer LoadAssetDll(string dllName) | ||
288 | { | ||
289 | Assembly assembly = Assembly.LoadFrom(dllName); | ||
290 | IAssetServer assetServer = null; | ||
291 | foreach (Type type in assembly.GetTypes()) | ||
292 | { | ||
293 | if (type.IsPublic && !type.IsAbstract) | ||
294 | { | ||
295 | if (type.GetInterface("IAssetPlugin", true) != null) | ||
296 | { | ||
297 | assetServer = ((IAssetPlugin)Activator.CreateInstance(assembly.GetType(type.ToString()))).GetAssetServer(); | ||
298 | break; | ||
299 | } | ||
300 | } | ||
301 | } | ||
302 | assembly = null; | ||
303 | return assetServer; | ||
304 | } | ||
305 | |||
306 | public void LoadDefaultTextureSet() | ||
307 | { | ||
308 | this.textureList[0] = new LLUUID("00000000-0000-0000-9999-000000000001"); | ||
309 | this.textureList[1] = new LLUUID("00000000-0000-0000-9999-000000000002"); | ||
310 | this.textureList[2] = new LLUUID("00000000-0000-0000-9999-000000000003"); | ||
311 | this.textureList[3] = new LLUUID("00000000-0000-0000-9999-000000000004"); | ||
312 | this.textureList[4] = new LLUUID("00000000-0000-0000-9999-000000000005"); | ||
313 | for (int i = 0; i < this.textureList.Length; i++) | ||
314 | { | ||
315 | this._assetServer.RequestAsset(this.textureList[i], true); | ||
316 | } | ||
317 | } | ||
318 | |||
319 | private void ProcessAssetQueue() | ||
320 | { | ||
321 | if (this.AssetRequests.Count != 0) | ||
322 | { | ||
323 | int num; | ||
324 | if (this.AssetRequests.Count < 5) | ||
325 | { | ||
326 | num = this.AssetRequests.Count; | ||
327 | } | ||
328 | else | ||
329 | { | ||
330 | num = 5; | ||
331 | } | ||
332 | for (int i = 0; i < num; i++) | ||
333 | { | ||
334 | AssetRequest request = this.AssetRequests[i]; | ||
335 | TransferInfoPacket newPack = new TransferInfoPacket(); | ||
336 | newPack.TransferInfo.ChannelType = 2; | ||
337 | newPack.TransferInfo.Status = 0; | ||
338 | newPack.TransferInfo.TargetType = 0; | ||
339 | newPack.TransferInfo.Params = request.RequestAssetID.GetBytes(); | ||
340 | newPack.TransferInfo.Size = request.AssetInf.Data.Length; | ||
341 | newPack.TransferInfo.TransferID = request.TransferRequestID; | ||
342 | request.RequestUser.OutPacket(newPack); | ||
343 | if (request.NumPackets == 1) | ||
344 | { | ||
345 | TransferPacketPacket packet2 = new TransferPacketPacket(); | ||
346 | packet2.TransferData.Packet = 0; | ||
347 | packet2.TransferData.ChannelType = 2; | ||
348 | packet2.TransferData.TransferID = request.TransferRequestID; | ||
349 | packet2.TransferData.Data = request.AssetInf.Data; | ||
350 | packet2.TransferData.Status = 1; | ||
351 | request.RequestUser.OutPacket(packet2); | ||
352 | } | ||
353 | else | ||
354 | { | ||
355 | TransferPacketPacket packet3 = new TransferPacketPacket(); | ||
356 | packet3.TransferData.Packet = 0; | ||
357 | packet3.TransferData.ChannelType = 2; | ||
358 | packet3.TransferData.TransferID = request.TransferRequestID; | ||
359 | byte[] destinationArray = new byte[0x3e8]; | ||
360 | Array.Copy(request.AssetInf.Data, destinationArray, 0x3e8); | ||
361 | packet3.TransferData.Data = destinationArray; | ||
362 | packet3.TransferData.Status = 0; | ||
363 | request.RequestUser.OutPacket(packet3); | ||
364 | packet3 = new TransferPacketPacket(); | ||
365 | packet3.TransferData.Packet = 1; | ||
366 | packet3.TransferData.ChannelType = 2; | ||
367 | packet3.TransferData.TransferID = request.TransferRequestID; | ||
368 | byte[] buffer2 = new byte[request.AssetInf.Data.Length - 0x3e8]; | ||
369 | Array.Copy(request.AssetInf.Data, 0x3e8, buffer2, 0, buffer2.Length); | ||
370 | packet3.TransferData.Data = buffer2; | ||
371 | packet3.TransferData.Status = 1; | ||
372 | request.RequestUser.OutPacket(packet3); | ||
373 | } | ||
374 | } | ||
375 | for (int j = 0; j < num; j++) | ||
376 | { | ||
377 | this.AssetRequests.RemoveAt(0); | ||
378 | } | ||
379 | } | ||
380 | } | ||
381 | |||
382 | private void ProcessTextureQueue() | ||
383 | { | ||
384 | if (this.TextureRequests.Count != 0) | ||
385 | { | ||
386 | int num = this.TextureRequests.Count; | ||
387 | for (int i = 0; i < num; i++) | ||
388 | { | ||
389 | AssetRequest req = this.TextureRequests[i]; | ||
390 | if (!this.SendingTextures.ContainsKey(req.ImageInfo.FullID)) | ||
391 | { | ||
392 | TextureSender sender = new TextureSender(req); | ||
393 | sender.OnComplete += new DownloadComplete(this.TextureSent); | ||
394 | lock (this.SendingTextures) | ||
395 | { | ||
396 | this.SendingTextures.Add(req.ImageInfo.FullID, sender); | ||
397 | } | ||
398 | } | ||
399 | } | ||
400 | this.TextureRequests.Clear(); | ||
401 | } | ||
402 | } | ||
403 | |||
404 | public void RunAssetManager() | ||
405 | { | ||
406 | Label_0000: | ||
407 | try | ||
408 | { | ||
409 | this.ProcessAssetQueue(); | ||
410 | this.ProcessTextureQueue(); | ||
411 | Thread.Sleep(500); | ||
412 | goto Label_0000; | ||
413 | } | ||
414 | catch (Exception exception) | ||
415 | { | ||
416 | Console.WriteLine(exception.Message); | ||
417 | goto Label_0000; | ||
418 | } | ||
419 | } | ||
420 | |||
421 | public void TextureSent(TextureSender sender) | ||
422 | { | ||
423 | if (this.SendingTextures.ContainsKey(sender.request.ImageInfo.FullID)) | ||
424 | { | ||
425 | lock (this.SendingTextures) | ||
426 | { | ||
427 | this.SendingTextures.Remove(sender.request.ImageInfo.FullID); | ||
428 | } | ||
429 | } | ||
430 | } | ||
431 | |||
432 | // Nested Types | ||
433 | public class AssetInfo : AssetBase | ||
434 | { | ||
435 | // Methods | ||
436 | public AssetInfo() | ||
437 | { | ||
438 | } | ||
439 | |||
440 | public AssetInfo(AssetBase aBase) | ||
441 | { | ||
442 | base.Data = aBase.Data; | ||
443 | base.FullID = aBase.FullID; | ||
444 | base.Type = aBase.Type; | ||
445 | base.InvType = aBase.InvType; | ||
446 | base.Name = aBase.Name; | ||
447 | base.Description = aBase.Description; | ||
448 | } | ||
449 | } | ||
450 | |||
451 | public class AssetRequest | ||
452 | { | ||
453 | // Fields | ||
454 | public AssetCache.AssetInfo AssetInf; | ||
455 | public long DataPointer; | ||
456 | public AssetCache.TextureImage ImageInfo; | ||
457 | public bool IsTextureRequest; | ||
458 | public int NumPackets; | ||
459 | public int PacketCounter; | ||
460 | public LLUUID RequestAssetID; | ||
461 | public IClientAPI RequestUser; | ||
462 | public LLUUID TransferRequestID; | ||
463 | } | ||
464 | |||
465 | public class TextureImage : AssetBase | ||
466 | { | ||
467 | // Methods | ||
468 | public TextureImage() | ||
469 | { | ||
470 | } | ||
471 | |||
472 | public TextureImage(AssetBase aBase) | ||
473 | { | ||
474 | base.Data = aBase.Data; | ||
475 | base.FullID = aBase.FullID; | ||
476 | base.Type = aBase.Type; | ||
477 | base.InvType = aBase.InvType; | ||
478 | base.Name = aBase.Name; | ||
479 | base.Description = aBase.Description; | ||
480 | } | ||
481 | } | ||
482 | |||
483 | public class TextureSender | ||
484 | { | ||
485 | // Fields | ||
486 | private Thread m_thread; | ||
487 | public AssetCache.AssetRequest request; | ||
488 | |||
489 | // Events | ||
490 | public event DownloadComplete OnComplete; | ||
491 | |||
492 | // Methods | ||
493 | public TextureSender(AssetCache.AssetRequest req) | ||
494 | { | ||
495 | this.request = req; | ||
496 | this.m_thread = new Thread(new ThreadStart(this.SendTexture)); | ||
497 | this.m_thread.IsBackground = true; | ||
498 | this.m_thread.Start(); | ||
499 | } | ||
500 | |||
501 | public void SendPacket() | ||
502 | { | ||
503 | AssetCache.AssetRequest request = this.request; | ||
504 | if (request.PacketCounter == 0) | ||
505 | { | ||
506 | if (request.NumPackets == 1) | ||
507 | { | ||
508 | ImageDataPacket newPack = new ImageDataPacket(); | ||
509 | newPack.ImageID.Packets = 1; | ||
510 | newPack.ImageID.ID = request.ImageInfo.FullID; | ||
511 | newPack.ImageID.Size = (uint)request.ImageInfo.Data.Length; | ||
512 | newPack.ImageData.Data = request.ImageInfo.Data; | ||
513 | newPack.ImageID.Codec = 2; | ||
514 | request.RequestUser.OutPacket(newPack); | ||
515 | request.PacketCounter++; | ||
516 | } | ||
517 | else | ||
518 | { | ||
519 | ImageDataPacket packet2 = new ImageDataPacket(); | ||
520 | packet2.ImageID.Packets = (ushort)request.NumPackets; | ||
521 | packet2.ImageID.ID = request.ImageInfo.FullID; | ||
522 | packet2.ImageID.Size = (uint)request.ImageInfo.Data.Length; | ||
523 | packet2.ImageData.Data = new byte[600]; | ||
524 | Array.Copy(request.ImageInfo.Data, 0, packet2.ImageData.Data, 0, 600); | ||
525 | packet2.ImageID.Codec = 2; | ||
526 | request.RequestUser.OutPacket(packet2); | ||
527 | request.PacketCounter++; | ||
528 | } | ||
529 | } | ||
530 | else | ||
531 | { | ||
532 | ImagePacketPacket packet3 = new ImagePacketPacket(); | ||
533 | packet3.ImageID.Packet = (ushort)request.PacketCounter; | ||
534 | packet3.ImageID.ID = request.ImageInfo.FullID; | ||
535 | int length = (request.ImageInfo.Data.Length - 600) - (0x3e8 * (request.PacketCounter - 1)); | ||
536 | if (length > 0x3e8) | ||
537 | { | ||
538 | length = 0x3e8; | ||
539 | } | ||
540 | packet3.ImageData.Data = new byte[length]; | ||
541 | Array.Copy(request.ImageInfo.Data, 600 + (0x3e8 * (request.PacketCounter - 1)), packet3.ImageData.Data, 0, length); | ||
542 | request.RequestUser.OutPacket(packet3); | ||
543 | request.PacketCounter++; | ||
544 | } | ||
545 | } | ||
546 | |||
547 | public void SendTexture() | ||
548 | { | ||
549 | while (this.request.PacketCounter != this.request.NumPackets) | ||
550 | { | ||
551 | this.SendPacket(); | ||
552 | Thread.Sleep(500); | ||
553 | } | ||
554 | if (this.OnComplete != null) | ||
555 | { | ||
556 | this.OnComplete(this); | ||
557 | } | ||
558 | } | ||
559 | } | ||
560 | } | ||
561 | } | ||
diff --git a/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs b/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs new file mode 100644 index 0000000..8b485af --- /dev/null +++ b/OpenSim/Framework/Communications/Cache/AssetTransactionManager.cs | |||
@@ -0,0 +1,81 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Text; | ||
32 | using System.IO; | ||
33 | using libsecondlife; | ||
34 | using OpenSim.Framework.Interfaces; | ||
35 | using OpenSim.Framework.Types; | ||
36 | using OpenSim.Framework.Utilities; | ||
37 | using OpenSim.Framework.Data; | ||
38 | |||
39 | namespace OpenSim.Framework.Communications.Caches | ||
40 | { | ||
41 | public class AssetTransactionManager | ||
42 | { | ||
43 | // Fields | ||
44 | public Dictionary<LLUUID, AgentAssetTransactions> AgentTransactions = new Dictionary<LLUUID, AgentAssetTransactions>(); | ||
45 | |||
46 | // Methods | ||
47 | public AgentAssetTransactions AddUser(LLUUID userID) | ||
48 | { | ||
49 | if (!this.AgentTransactions.ContainsKey(userID)) | ||
50 | { | ||
51 | AgentAssetTransactions transactions = new AgentAssetTransactions(userID); | ||
52 | this.AgentTransactions.Add(userID, transactions); | ||
53 | return transactions; | ||
54 | } | ||
55 | return null; | ||
56 | } | ||
57 | |||
58 | public AgentAssetTransactions GetUserTransActions(LLUUID userID) | ||
59 | { | ||
60 | if (this.AgentTransactions.ContainsKey(userID)) | ||
61 | { | ||
62 | return this.AgentTransactions[userID]; | ||
63 | } | ||
64 | return null; | ||
65 | } | ||
66 | |||
67 | public void HandleInventoryFromTransaction() | ||
68 | { | ||
69 | } | ||
70 | |||
71 | public void HandleUDPUploadRequest() | ||
72 | { | ||
73 | } | ||
74 | |||
75 | public void HandleXfer(IClientAPI remoteClient, uint xferID, uint packetID, byte[] data) | ||
76 | { | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | |||
81 | |||
diff --git a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs new file mode 100644 index 0000000..bb9c069 --- /dev/null +++ b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs | |||
@@ -0,0 +1,275 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Text; | ||
32 | using System.IO; | ||
33 | using libsecondlife; | ||
34 | using libsecondlife.Packets; | ||
35 | using OpenSim.Framework.Interfaces; | ||
36 | using OpenSim.Framework.Types; | ||
37 | using OpenSim.Framework.Utilities; | ||
38 | using OpenSim.Region.Capabilities; | ||
39 | using OpenSim.Framework.Servers; | ||
40 | |||
41 | namespace OpenSim.Framework.Communications.Caches | ||
42 | { | ||
43 | public class AgentAssetTransactions | ||
44 | { | ||
45 | // Fields | ||
46 | public List<AssetCapsUploader> CapsUploaders = new List<AssetCapsUploader>(); | ||
47 | public List<NoteCardCapsUpdate> NotecardUpdaters = new List<NoteCardCapsUpdate>(); | ||
48 | public LLUUID UserID; | ||
49 | public Dictionary<LLUUID, AssetXferUploader> XferUploaders = new Dictionary<LLUUID, AssetXferUploader>(); | ||
50 | |||
51 | // Methods | ||
52 | public AgentAssetTransactions(LLUUID agentID) | ||
53 | { | ||
54 | this.UserID = agentID; | ||
55 | } | ||
56 | |||
57 | public AssetCapsUploader RequestCapsUploader() | ||
58 | { | ||
59 | AssetCapsUploader uploader = new AssetCapsUploader(); | ||
60 | this.CapsUploaders.Add(uploader); | ||
61 | return uploader; | ||
62 | } | ||
63 | |||
64 | public NoteCardCapsUpdate RequestNoteCardUpdater() | ||
65 | { | ||
66 | NoteCardCapsUpdate update = new NoteCardCapsUpdate(); | ||
67 | this.NotecardUpdaters.Add(update); | ||
68 | return update; | ||
69 | } | ||
70 | |||
71 | public AssetXferUploader RequestXferUploader(LLUUID transactionID) | ||
72 | { | ||
73 | AssetXferUploader uploader = new AssetXferUploader(); | ||
74 | this.XferUploaders.Add(transactionID, uploader); | ||
75 | return uploader; | ||
76 | } | ||
77 | |||
78 | // Nested Types | ||
79 | public class AssetCapsUploader | ||
80 | { | ||
81 | // Fields | ||
82 | private BaseHttpServer httpListener; | ||
83 | private LLUUID inventoryItemID; | ||
84 | private string m_assetDescription = ""; | ||
85 | private string m_assetName = ""; | ||
86 | private LLUUID m_folderID; | ||
87 | private LLUUID newAssetID; | ||
88 | private bool SaveImages; | ||
89 | private string uploaderPath = ""; | ||
90 | |||
91 | // Events | ||
92 | public event UpLoadedTexture OnUpLoad; | ||
93 | |||
94 | // Methods | ||
95 | public void Initialise(string assetName, string assetDescription, LLUUID assetID, LLUUID inventoryItem, LLUUID folderID, string path, BaseHttpServer httpServer) | ||
96 | { | ||
97 | this.m_assetName = assetName; | ||
98 | this.m_assetDescription = assetDescription; | ||
99 | this.m_folderID = folderID; | ||
100 | this.newAssetID = assetID; | ||
101 | this.inventoryItemID = inventoryItem; | ||
102 | this.uploaderPath = path; | ||
103 | this.httpListener = httpServer; | ||
104 | } | ||
105 | |||
106 | private void SaveImageToFile(string filename, byte[] data) | ||
107 | { | ||
108 | FileStream output = File.Create(filename); | ||
109 | BinaryWriter writer = new BinaryWriter(output); | ||
110 | writer.Write(data); | ||
111 | writer.Close(); | ||
112 | output.Close(); | ||
113 | } | ||
114 | |||
115 | public string uploaderCaps(byte[] data, string path, string param) | ||
116 | { | ||
117 | LLUUID inventoryItemID = this.inventoryItemID; | ||
118 | string text = ""; | ||
119 | LLSDAssetUploadComplete complete = new LLSDAssetUploadComplete(); | ||
120 | complete.new_asset = this.newAssetID.ToStringHyphenated(); | ||
121 | complete.new_inventory_item = inventoryItemID; | ||
122 | complete.state = "complete"; | ||
123 | text = LLSDHelpers.SerialiseLLSDReply(complete); | ||
124 | this.httpListener.RemoveStreamHandler("POST", this.uploaderPath); | ||
125 | if (this.SaveImages) | ||
126 | { | ||
127 | this.SaveImageToFile(this.m_assetName + ".jp2", data); | ||
128 | } | ||
129 | if (this.OnUpLoad != null) | ||
130 | { | ||
131 | this.OnUpLoad(this.m_assetName, this.newAssetID, inventoryItemID, data); | ||
132 | } | ||
133 | return text; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | public class AssetXferUploader | ||
138 | { | ||
139 | // Fields | ||
140 | public bool AddToInventory; | ||
141 | public AssetBase Asset; | ||
142 | public LLUUID InventFolder = LLUUID.Zero; | ||
143 | private IClientAPI ourClient; | ||
144 | public LLUUID TransactionID = LLUUID.Zero; | ||
145 | public bool UploadComplete; | ||
146 | public uint XferID; | ||
147 | |||
148 | // Methods | ||
149 | public void HandleXferPacket(uint xferID, uint packetID, byte[] data) | ||
150 | { | ||
151 | if (this.XferID == xferID) | ||
152 | { | ||
153 | if (this.Asset.Data.Length > 1) | ||
154 | { | ||
155 | byte[] destinationArray = new byte[this.Asset.Data.Length + data.Length]; | ||
156 | Array.Copy(this.Asset.Data, 0, destinationArray, 0, this.Asset.Data.Length); | ||
157 | Array.Copy(data, 0, destinationArray, this.Asset.Data.Length, data.Length); | ||
158 | this.Asset.Data = destinationArray; | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | byte[] buffer2 = new byte[data.Length - 4]; | ||
163 | Array.Copy(data, 4, buffer2, 0, data.Length - 4); | ||
164 | this.Asset.Data = buffer2; | ||
165 | } | ||
166 | ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket(); | ||
167 | newPack.XferID.ID = xferID; | ||
168 | newPack.XferID.Packet = packetID; | ||
169 | this.ourClient.OutPacket(newPack); | ||
170 | if ((packetID & 0x80000000) != 0) | ||
171 | { | ||
172 | this.SendCompleteMessage(); | ||
173 | } | ||
174 | } | ||
175 | } | ||
176 | |||
177 | public void Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data) | ||
178 | { | ||
179 | this.ourClient = remoteClient; | ||
180 | this.Asset = new AssetBase(); | ||
181 | this.Asset.FullID = assetID; | ||
182 | this.Asset.InvType = type; | ||
183 | this.Asset.Type = type; | ||
184 | this.Asset.Data = data; | ||
185 | this.Asset.Name = "blank"; | ||
186 | this.Asset.Description = "empty"; | ||
187 | this.TransactionID = transaction; | ||
188 | if (this.Asset.Data.Length > 2) | ||
189 | { | ||
190 | this.SendCompleteMessage(); | ||
191 | } | ||
192 | else | ||
193 | { | ||
194 | this.ReqestStartXfer(); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | protected void ReqestStartXfer() | ||
199 | { | ||
200 | this.UploadComplete = false; | ||
201 | this.XferID = Util.GetNextXferID(); | ||
202 | RequestXferPacket newPack = new RequestXferPacket(); | ||
203 | newPack.XferID.ID = this.XferID; | ||
204 | newPack.XferID.VFileType = this.Asset.Type; | ||
205 | newPack.XferID.VFileID = this.Asset.FullID; | ||
206 | newPack.XferID.FilePath = 0; | ||
207 | newPack.XferID.Filename = new byte[0]; | ||
208 | this.ourClient.OutPacket(newPack); | ||
209 | } | ||
210 | |||
211 | protected void SendCompleteMessage() | ||
212 | { | ||
213 | this.UploadComplete = true; | ||
214 | AssetUploadCompletePacket newPack = new AssetUploadCompletePacket(); | ||
215 | newPack.AssetBlock.Type = this.Asset.Type; | ||
216 | newPack.AssetBlock.Success = true; | ||
217 | newPack.AssetBlock.UUID = this.Asset.FullID; | ||
218 | this.ourClient.OutPacket(newPack); | ||
219 | } | ||
220 | } | ||
221 | |||
222 | public class NoteCardCapsUpdate | ||
223 | { | ||
224 | // Fields | ||
225 | private BaseHttpServer httpListener; | ||
226 | private LLUUID inventoryItemID; | ||
227 | private string m_assetName = ""; | ||
228 | private LLUUID newAssetID; | ||
229 | private bool SaveImages; | ||
230 | private string uploaderPath = ""; | ||
231 | |||
232 | // Events | ||
233 | public event UpLoadedTexture OnUpLoad; | ||
234 | |||
235 | // Methods | ||
236 | public void Initialise(LLUUID inventoryItem, string path, BaseHttpServer httpServer) | ||
237 | { | ||
238 | this.inventoryItemID = inventoryItem; | ||
239 | this.uploaderPath = path; | ||
240 | this.httpListener = httpServer; | ||
241 | this.newAssetID = LLUUID.Random(); | ||
242 | } | ||
243 | |||
244 | private void SaveImageToFile(string filename, byte[] data) | ||
245 | { | ||
246 | FileStream output = File.Create(filename); | ||
247 | BinaryWriter writer = new BinaryWriter(output); | ||
248 | writer.Write(data); | ||
249 | writer.Close(); | ||
250 | output.Close(); | ||
251 | } | ||
252 | |||
253 | public string uploaderCaps(byte[] data, string path, string param) | ||
254 | { | ||
255 | LLUUID inventoryItemID = this.inventoryItemID; | ||
256 | string text = ""; | ||
257 | LLSDAssetUploadComplete complete = new LLSDAssetUploadComplete(); | ||
258 | complete.new_asset = this.newAssetID.ToStringHyphenated(); | ||
259 | complete.new_inventory_item = inventoryItemID; | ||
260 | complete.state = "complete"; | ||
261 | text = LLSDHelpers.SerialiseLLSDReply(complete); | ||
262 | this.httpListener.RemoveStreamHandler("POST", this.uploaderPath); | ||
263 | if (this.SaveImages) | ||
264 | { | ||
265 | this.SaveImageToFile(this.m_assetName + "notecard.txt", data); | ||
266 | } | ||
267 | if (this.OnUpLoad != null) | ||
268 | { | ||
269 | this.OnUpLoad(this.m_assetName, this.newAssetID, inventoryItemID, data); | ||
270 | } | ||
271 | return text; | ||
272 | } | ||
273 | } | ||
274 | } | ||
275 | } \ No newline at end of file | ||
diff --git a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs new file mode 100644 index 0000000..2660df3 --- /dev/null +++ b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Text; | ||
32 | using System.IO; | ||
33 | using libsecondlife; | ||
34 | using OpenSim.Framework.Interfaces; | ||
35 | using OpenSim.Framework.Types; | ||
36 | using OpenSim.Framework.Data; | ||
37 | using OpenSim.Framework.Utilities; | ||
38 | |||
39 | namespace OpenSim.Framework.Communications.Caches | ||
40 | { | ||
41 | public class CachedUserInfo | ||
42 | { | ||
43 | // Fields | ||
44 | public InventoryFolder RootFolder; | ||
45 | public UserProfileData UserProfile; | ||
46 | |||
47 | // Methods | ||
48 | public void FolderReceive(LLUUID userID, InventoryFolder folderInfo) | ||
49 | { | ||
50 | if (userID == this.UserProfile.UUID) | ||
51 | { | ||
52 | if (this.RootFolder == null) | ||
53 | { | ||
54 | if (folderInfo.parentID == LLUUID.Zero) | ||
55 | { | ||
56 | this.RootFolder = folderInfo; | ||
57 | } | ||
58 | } | ||
59 | else if (this.RootFolder.folderID == folderInfo.parentID) | ||
60 | { | ||
61 | this.RootFolder.SubFolders.Add(folderInfo.folderID, folderInfo); | ||
62 | } | ||
63 | else | ||
64 | { | ||
65 | InventoryFolder folder = this.RootFolder.HasSubFolder(folderInfo.parentID); | ||
66 | if (folder != null) | ||
67 | { | ||
68 | folder.SubFolders.Add(folderInfo.folderID, folderInfo); | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | |||
74 | public void ItemReceive(LLUUID userID, InventoryItemBase itemInfo) | ||
75 | { | ||
76 | if ((userID == this.UserProfile.UUID) && (this.RootFolder != null)) | ||
77 | { | ||
78 | if (itemInfo.parentFolderID == this.RootFolder.folderID) | ||
79 | { | ||
80 | this.RootFolder.Items.Add(itemInfo.inventoryID, itemInfo); | ||
81 | } | ||
82 | else | ||
83 | { | ||
84 | InventoryFolder folder = this.RootFolder.HasSubFolder(itemInfo.parentFolderID); | ||
85 | if (folder != null) | ||
86 | { | ||
87 | folder.Items.Add(itemInfo.inventoryID, itemInfo); | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | |||
diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolder.cs b/OpenSim/Framework/Communications/Cache/InventoryFolder.cs new file mode 100644 index 0000000..8670eb0 --- /dev/null +++ b/OpenSim/Framework/Communications/Cache/InventoryFolder.cs | |||
@@ -0,0 +1,109 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Text; | ||
32 | using System.IO; | ||
33 | using libsecondlife; | ||
34 | using OpenSim.Framework.Interfaces; | ||
35 | using OpenSim.Framework.Data; | ||
36 | using OpenSim.Framework.Types; | ||
37 | using OpenSim.Framework.Utilities; | ||
38 | |||
39 | namespace OpenSim.Framework.Communications.Caches | ||
40 | { | ||
41 | public class InventoryFolder : InventoryFolderBase | ||
42 | { | ||
43 | // Fields | ||
44 | public Dictionary<LLUUID, InventoryItemBase> Items = new Dictionary<LLUUID, InventoryItemBase>(); | ||
45 | public Dictionary<LLUUID, InventoryFolder> SubFolders = new Dictionary<LLUUID, InventoryFolder>(); | ||
46 | |||
47 | // Methods | ||
48 | public InventoryFolder CreateNewSubFolder(LLUUID folderID, string folderName, ushort type) | ||
49 | { | ||
50 | InventoryFolder subFold = new InventoryFolder(); | ||
51 | subFold.name = folderName; | ||
52 | subFold.folderID = folderID; | ||
53 | subFold.type = type; | ||
54 | subFold.parentID = this.folderID; | ||
55 | subFold.agentID = this.agentID; | ||
56 | this.SubFolders.Add(subFold.folderID, subFold); | ||
57 | return subFold; | ||
58 | } | ||
59 | |||
60 | public InventoryItemBase HasItem(LLUUID itemID) | ||
61 | { | ||
62 | InventoryItemBase base2 = null; | ||
63 | if (this.Items.ContainsKey(itemID)) | ||
64 | { | ||
65 | return this.Items[itemID]; | ||
66 | } | ||
67 | foreach (InventoryFolder folder in this.SubFolders.Values) | ||
68 | { | ||
69 | base2 = folder.HasItem(itemID); | ||
70 | if (base2 != null) | ||
71 | { | ||
72 | break; | ||
73 | } | ||
74 | } | ||
75 | return base2; | ||
76 | } | ||
77 | |||
78 | public InventoryFolder HasSubFolder(LLUUID folderID) | ||
79 | { | ||
80 | InventoryFolder returnFolder = null; | ||
81 | if (this.SubFolders.ContainsKey(folderID)) | ||
82 | { | ||
83 | returnFolder = this.SubFolders[folderID]; | ||
84 | } | ||
85 | else | ||
86 | { | ||
87 | foreach (InventoryFolder folder in this.SubFolders.Values) | ||
88 | { | ||
89 | returnFolder = folder.HasSubFolder(folderID); | ||
90 | if (returnFolder != null) | ||
91 | { | ||
92 | break; | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | return returnFolder; | ||
97 | } | ||
98 | |||
99 | public List<InventoryItemBase> RequestListOfItems() | ||
100 | { | ||
101 | List<InventoryItemBase> itemList = new List<InventoryItemBase>(); | ||
102 | foreach (InventoryItemBase item in this.Items.Values) | ||
103 | { | ||
104 | itemList.Add(item); | ||
105 | } | ||
106 | return itemList; | ||
107 | } | ||
108 | } | ||
109 | } | ||
diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs new file mode 100644 index 0000000..8210702 --- /dev/null +++ b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs | |||
@@ -0,0 +1,170 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Text; | ||
32 | using System.IO; | ||
33 | using libsecondlife; | ||
34 | using OpenSim.Framework.Interfaces; | ||
35 | using OpenSim.Framework.Types; | ||
36 | using OpenSim.Framework.Utilities; | ||
37 | using OpenSim.Framework.Data; | ||
38 | |||
39 | namespace OpenSim.Framework.Communications.Caches | ||
40 | { | ||
41 | |||
42 | public class UserProfileCache | ||
43 | { | ||
44 | // Fields | ||
45 | private CommunicationsManager m_parent; | ||
46 | public Dictionary<LLUUID, CachedUserInfo> UserProfiles = new Dictionary<LLUUID, CachedUserInfo>(); | ||
47 | |||
48 | // Methods | ||
49 | public UserProfileCache(CommunicationsManager parent) | ||
50 | { | ||
51 | this.m_parent = parent; | ||
52 | } | ||
53 | |||
54 | public void AddNewUser(LLUUID userID) | ||
55 | { | ||
56 | if (!this.UserProfiles.ContainsKey(userID)) | ||
57 | { | ||
58 | CachedUserInfo userInfo = new CachedUserInfo(); | ||
59 | userInfo.UserProfile = this.RequestUserProfileForUser(userID); | ||
60 | if (userInfo.UserProfile != null) | ||
61 | { | ||
62 | this.RequestInventoryForUser(userID, userInfo); | ||
63 | this.UserProfiles.Add(userID, userInfo); | ||
64 | } | ||
65 | else | ||
66 | { | ||
67 | Console.WriteLine("UserProfileCache.cs: user profile for user not found"); | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | |||
72 | public void AddNewUser(string firstName, string lastName) | ||
73 | { | ||
74 | } | ||
75 | |||
76 | public CachedUserInfo GetUserDetails(LLUUID userID) | ||
77 | { | ||
78 | if (this.UserProfiles.ContainsKey(userID)) | ||
79 | { | ||
80 | return this.UserProfiles[userID]; | ||
81 | } | ||
82 | return null; | ||
83 | } | ||
84 | |||
85 | public void HandleCreateInventoryFolder(IClientAPI remoteClient, LLUUID folderID, ushort folderType, string folderName, LLUUID parentID) | ||
86 | { | ||
87 | if (this.UserProfiles.ContainsKey(remoteClient.AgentId)) | ||
88 | { | ||
89 | CachedUserInfo info = this.UserProfiles[remoteClient.AgentId]; | ||
90 | if (info.RootFolder.folderID == parentID) | ||
91 | { | ||
92 | info.RootFolder.CreateNewSubFolder(folderID, folderName, folderType); | ||
93 | } | ||
94 | else | ||
95 | { | ||
96 | InventoryFolder folder = info.RootFolder.HasSubFolder(parentID); | ||
97 | if (folder != null) | ||
98 | { | ||
99 | folder.CreateNewSubFolder(folderID, folderName, folderType); | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | |||
105 | public void HandleFecthInventoryDescendents(IClientAPI remoteClient, LLUUID folderID, LLUUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder) | ||
106 | { | ||
107 | if (this.UserProfiles.ContainsKey(remoteClient.AgentId)) | ||
108 | { | ||
109 | CachedUserInfo info = this.UserProfiles[remoteClient.AgentId]; | ||
110 | if (info.RootFolder.folderID == folderID) | ||
111 | { | ||
112 | if (fetchItems) | ||
113 | { | ||
114 | remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, info.RootFolder.RequestListOfItems()); | ||
115 | } | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | InventoryFolder folder = info.RootFolder.HasSubFolder(folderID); | ||
120 | if ((folder != null) && fetchItems) | ||
121 | { | ||
122 | remoteClient.SendInventoryFolderDetails(remoteClient.AgentId, folderID, folder.RequestListOfItems()); | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | |||
128 | public void HandleFetchInventory(IClientAPI remoteClient, LLUUID itemID, LLUUID ownerID) | ||
129 | { | ||
130 | if (this.UserProfiles.ContainsKey(remoteClient.AgentId)) | ||
131 | { | ||
132 | InventoryItemBase item = this.UserProfiles[remoteClient.AgentId].RootFolder.HasItem(itemID); | ||
133 | if (item != null) | ||
134 | { | ||
135 | remoteClient.SendInventoryItemDetails(ownerID, item); | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | |||
140 | private void RequestInventoryForUser(LLUUID userID, CachedUserInfo userInfo) | ||
141 | { | ||
142 | InventoryFolder folderInfo = new InventoryFolder(); | ||
143 | folderInfo.agentID = userID; | ||
144 | folderInfo.folderID = userInfo.UserProfile.rootInventoryFolderID; | ||
145 | folderInfo.name = "My Inventory"; | ||
146 | folderInfo.parentID = LLUUID.Zero; | ||
147 | folderInfo.type = 8; | ||
148 | folderInfo.version = 1; | ||
149 | userInfo.FolderReceive(userID, folderInfo); | ||
150 | } | ||
151 | |||
152 | private UserProfileData RequestUserProfileForUser(LLUUID userID) | ||
153 | { | ||
154 | return this.m_parent.UserServer.GetUserProfile(userID); | ||
155 | } | ||
156 | |||
157 | private void UpdateInventoryToServer(LLUUID userID) | ||
158 | { | ||
159 | } | ||
160 | |||
161 | private void UpdateUserProfileToServer(LLUUID userID) | ||
162 | { | ||
163 | } | ||
164 | |||
165 | public void UserLogOut(LLUUID userID) | ||
166 | { | ||
167 | } | ||
168 | } | ||
169 | } | ||
170 | |||
diff --git a/OpenSim/Region/Physics/BulletXPlugin/OpenSim.Region.Physics.BulletXPlugin.csproj b/OpenSim/Region/Physics/BulletXPlugin/OpenSim.Region.Physics.BulletXPlugin.csproj new file mode 100644 index 0000000..fdb1d38 --- /dev/null +++ b/OpenSim/Region/Physics/BulletXPlugin/OpenSim.Region.Physics.BulletXPlugin.csproj | |||
@@ -0,0 +1,66 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
3 | <PropertyGroup> | ||
4 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
5 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
6 | <ProductVersion>8.0.50727</ProductVersion> | ||
7 | <SchemaVersion>2.0</SchemaVersion> | ||
8 | <ProjectGuid>{2D3DE8E4-9202-46A4-857B-3579B70E8356}</ProjectGuid> | ||
9 | <OutputType>Library</OutputType> | ||
10 | <AppDesignerFolder>Properties</AppDesignerFolder> | ||
11 | <RootNamespace>OpenSim.Region.Physics.BulletXPlugin</RootNamespace> | ||
12 | <AssemblyName>OpenSim.Region.Physics.BulletXPlugin</AssemblyName> | ||
13 | <StartupObject> | ||
14 | </StartupObject> | ||
15 | </PropertyGroup> | ||
16 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
17 | <DebugSymbols>true</DebugSymbols> | ||
18 | <DebugType>full</DebugType> | ||
19 | <Optimize>false</Optimize> | ||
20 | <OutputPath>bin\Debug\</OutputPath> | ||
21 | <DefineConstants>DEBUG;TRACE</DefineConstants> | ||
22 | <ErrorReport>prompt</ErrorReport> | ||
23 | <WarningLevel>4</WarningLevel> | ||
24 | </PropertyGroup> | ||
25 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
26 | <DebugType>pdbonly</DebugType> | ||
27 | <Optimize>true</Optimize> | ||
28 | <OutputPath>..\..\..\..\bin\Physics\</OutputPath> | ||
29 | <DefineConstants>TRACE</DefineConstants> | ||
30 | <ErrorReport>prompt</ErrorReport> | ||
31 | <WarningLevel>4</WarningLevel> | ||
32 | </PropertyGroup> | ||
33 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
34 | <!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
35 | Other similar extension points exist, see Microsoft.Common.targets. | ||
36 | <Target Name="BeforeBuild"> | ||
37 | </Target> | ||
38 | <Target Name="AfterBuild"> | ||
39 | </Target> | ||
40 | --> | ||
41 | <ItemGroup> | ||
42 | <Compile Include="AssemblyInfo.cs" /> | ||
43 | <Compile Include="BulletXPlugin.cs" /> | ||
44 | </ItemGroup> | ||
45 | <ItemGroup> | ||
46 | <Reference Include="Axiom.MathLib.dll"> | ||
47 | <HintPath>..\..\..\..\bin\Axiom.MathLib.dll</HintPath> | ||
48 | <Private>False</Private> | ||
49 | </Reference> | ||
50 | <Reference Include="Modified.XnaDevRu.BulletX, Version=2.50.149.21894, Culture=neutral, processorArchitecture=x86"> | ||
51 | <SpecificVersion>False</SpecificVersion> | ||
52 | <HintPath>..\..\..\..\bin\Modified.XnaDevRu.BulletX.dll</HintPath> | ||
53 | </Reference> | ||
54 | <Reference Include="MonoXnaCompactMaths, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
55 | <SpecificVersion>False</SpecificVersion> | ||
56 | <HintPath>..\..\..\..\bin\MonoXnaCompactMaths.dll</HintPath> | ||
57 | </Reference> | ||
58 | <Reference Include="OpenSim.Region.Physics.Manager, Version=1.0.2741.37128, Culture=neutral, processorArchitecture=MSIL"> | ||
59 | <SpecificVersion>False</SpecificVersion> | ||
60 | <HintPath>..\..\..\..\bin\OpenSim.Region.Physics.Manager.dll</HintPath> | ||
61 | </Reference> | ||
62 | <Reference Include="System" /> | ||
63 | <Reference Include="System.Data" /> | ||
64 | <Reference Include="System.Xml" /> | ||
65 | </ItemGroup> | ||
66 | </Project> \ No newline at end of file | ||