aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMW2008-02-27 21:11:01 +0000
committerMW2008-02-27 21:11:01 +0000
commite978d00914a25c12cc03efd597125e2948526681 (patch)
treeaec69b83655fa054c364443a9163b95163f41cb3 /OpenSim
parent* Turned Friends Module into a shared module (to comply with Scene.AddXmlRPCH... (diff)
downloadopensim-SC-e978d00914a25c12cc03efd597125e2948526681.zip
opensim-SC-e978d00914a25c12cc03efd597125e2948526681.tar.gz
opensim-SC-e978d00914a25c12cc03efd597125e2948526681.tar.bz2
opensim-SC-e978d00914a25c12cc03efd597125e2948526681.tar.xz
After seeing sdague do his happy dance over trunk working "the best he has ever seen". I'm not sure I should be doing this commit, but oh well.
So anyway, it moves the Asset downloading (packet sending) to a module (AssetDownloadModule). So now at last, AssetCache should be just dealing with fetching assets from the asset server and caching them.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetCache.cs35
-rw-r--r--OpenSim/Framework/IClientAPI.cs3
-rw-r--r--OpenSim/Region/ClientStack/ClientView.cs147
-rw-r--r--OpenSim/Region/Environment/Modules/AssetDownloadModule.cs270
-rw-r--r--OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs1
5 files changed, 367 insertions, 89 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs
index 061b857..abb7ce1 100644
--- a/OpenSim/Framework/Communications/Cache/AssetCache.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs
@@ -69,12 +69,12 @@ namespace OpenSim.Framework.Communications.Cache
69 /// 69 ///
70 /// Assets requests which are waiting for asset server data. This includes texture requests 70 /// Assets requests which are waiting for asset server data. This includes texture requests
71 /// </summary> 71 /// </summary>
72 private Dictionary<LLUUID, AssetRequest> RequestedAssets; 72 // private Dictionary<LLUUID, AssetRequest> RequestedAssets;
73 73
74 /// <summary> 74 /// <summary>
75 /// Asset requests with data which are ready to be sent back to requesters. This includes textures. 75 /// Asset requests with data which are ready to be sent back to requesters. This includes textures.
76 /// </summary> 76 /// </summary>
77 private List<AssetRequest> AssetRequests; 77 // private List<AssetRequest> AssetRequests;
78 78
79 79
80 /// <summary> 80 /// <summary>
@@ -84,7 +84,7 @@ namespace OpenSim.Framework.Communications.Cache
84 84
85 private readonly IAssetServer m_assetServer; 85 private readonly IAssetServer m_assetServer;
86 86
87 private readonly Thread m_assetCacheThread; 87 // private readonly Thread m_assetCacheThread;
88 88
89 /// <summary> 89 /// <summary>
90 /// Report statistical data. 90 /// Report statistical data.
@@ -94,8 +94,8 @@ namespace OpenSim.Framework.Communications.Cache
94 m_log.InfoFormat("Assets:{0} Textures:{1} AssetRequests:{2} RequestedAssets:{3} RequestLists:{4}", 94 m_log.InfoFormat("Assets:{0} Textures:{1} AssetRequests:{2} RequestedAssets:{3} RequestLists:{4}",
95 Assets.Count, 95 Assets.Count,
96 Textures.Count, 96 Textures.Count,
97 AssetRequests.Count, 97 // AssetRequests.Count,
98 RequestedAssets.Count, 98 // RequestedAssets.Count,
99 RequestLists.Count); 99 RequestLists.Count);
100 100
101 int temporaryImages = 0; 101 int temporaryImages = 0;
@@ -150,9 +150,9 @@ namespace OpenSim.Framework.Communications.Cache
150 { 150 {
151 Assets = new Dictionary<LLUUID, AssetInfo>(); 151 Assets = new Dictionary<LLUUID, AssetInfo>();
152 Textures = new Dictionary<LLUUID, TextureImage>(); 152 Textures = new Dictionary<LLUUID, TextureImage>();
153 AssetRequests = new List<AssetRequest>(); 153 // AssetRequests = new List<AssetRequest>();
154 154
155 RequestedAssets = new Dictionary<LLUUID, AssetRequest>(); 155 // RequestedAssets = new Dictionary<LLUUID, AssetRequest>();
156 RequestLists = new Dictionary<LLUUID, AssetRequestsList>(); 156 RequestLists = new Dictionary<LLUUID, AssetRequestsList>();
157 } 157 }
158 158
@@ -168,18 +168,18 @@ namespace OpenSim.Framework.Communications.Cache
168 m_assetServer = assetServer; 168 m_assetServer = assetServer;
169 m_assetServer.SetReceiver(this); 169 m_assetServer.SetReceiver(this);
170 170
171 m_assetCacheThread = new Thread(new ThreadStart(RunAssetManager)); 171 // m_assetCacheThread = new Thread(new ThreadStart(RunAssetManager));
172 m_assetCacheThread.Name = "AssetCacheThread"; 172 // m_assetCacheThread.Name = "AssetCacheThread";
173 m_assetCacheThread.IsBackground = true; 173 // m_assetCacheThread.IsBackground = true;
174 m_assetCacheThread.Start(); 174 // m_assetCacheThread.Start();
175 OpenSim.Framework.ThreadTracker.Add(m_assetCacheThread); 175 // OpenSim.Framework.ThreadTracker.Add(m_assetCacheThread);
176 } 176 }
177 177
178 /// <summary> 178 /// <summary>
179 /// Process the asset queue which holds data which is packeted up and sent 179 /// Process the asset queue which holds data which is packeted up and sent
180 /// directly back to the client. 180 /// directly back to the client.
181 /// </summary> 181 /// </summary>
182 public void RunAssetManager() 182 /* public void RunAssetManager()
183 { 183 {
184 while (true) 184 while (true)
185 { 185 {
@@ -193,7 +193,7 @@ namespace OpenSim.Framework.Communications.Cache
193 m_log.Error("[ASSET CACHE]: " + e.ToString()); 193 m_log.Error("[ASSET CACHE]: " + e.ToString());
194 } 194 }
195 } 195 }
196 } 196 }*/
197 197
198 /// <summary> 198 /// <summary>
199 /// Only get an asset if we already have it in the cache. 199 /// Only get an asset if we already have it in the cache.
@@ -449,7 +449,7 @@ namespace OpenSim.Framework.Communications.Cache
449 StatsManager.SimExtraStats.AddAsset(assetInf); 449 StatsManager.SimExtraStats.AddAsset(assetInf);
450 } 450 }
451 451
452 if (RequestedAssets.ContainsKey(assetInf.FullID)) 452 /* if (RequestedAssets.ContainsKey(assetInf.FullID))
453 { 453 {
454 #if DEBUG 454 #if DEBUG
455 //m_log.DebugFormat("[ASSET CACHE]: Moving {0} from RequestedAssets to AssetRequests", asset.FullID); 455 //m_log.DebugFormat("[ASSET CACHE]: Moving {0} from RequestedAssets to AssetRequests", asset.FullID);
@@ -461,7 +461,7 @@ namespace OpenSim.Framework.Communications.Cache
461 461
462 RequestedAssets.Remove(assetInf.FullID); 462 RequestedAssets.Remove(assetInf.FullID);
463 AssetRequests.Add(req); 463 AssetRequests.Add(req);
464 } 464 }*/
465 } 465 }
466 } 466 }
467 467
@@ -541,6 +541,7 @@ namespace OpenSim.Framework.Communications.Cache
541 541
542 } 542 }
543 543
544 /*
544 /// <summary> 545 /// <summary>
545 /// Calculate the number of packets required to send the asset to the client. 546 /// Calculate the number of packets required to send the asset to the client.
546 /// </summary> 547 /// </summary>
@@ -734,7 +735,7 @@ namespace OpenSim.Framework.Communications.Cache
734 { 735 {
735 } 736 }
736 } 737 }
737 738 */
738 739
739 public class AssetInfo : AssetBase 740 public class AssetInfo : AssetBase
740 { 741 {
diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs
index 2635a23..511bbad 100644
--- a/OpenSim/Framework/IClientAPI.cs
+++ b/OpenSim/Framework/IClientAPI.cs
@@ -390,6 +390,8 @@ namespace OpenSim.Framework
390 public delegate void RemoveInventoryFolder( 390 public delegate void RemoveInventoryFolder(
391 IClientAPI remoteClient, LLUUID folderID); 391 IClientAPI remoteClient, LLUUID folderID);
392 392
393 public delegate void RequestAsset(IClientAPI remoteClient, TransferRequestPacket transferRequest);
394
393 public delegate void RezScript(IClientAPI remoteClient, LLUUID itemID, uint localID); 395 public delegate void RezScript(IClientAPI remoteClient, LLUUID itemID, uint localID);
394 396
395 public delegate void UpdateTaskInventory(IClientAPI remoteClient, LLUUID itemID, LLUUID folderID, uint localID); 397 public delegate void UpdateTaskInventory(IClientAPI remoteClient, LLUUID itemID, LLUUID folderID, uint localID);
@@ -503,6 +505,7 @@ namespace OpenSim.Framework
503 event RezScript OnRezScript; 505 event RezScript OnRezScript;
504 event UpdateTaskInventory OnUpdateTaskInventory; 506 event UpdateTaskInventory OnUpdateTaskInventory;
505 event RemoveTaskInventory OnRemoveTaskItem; 507 event RemoveTaskInventory OnRemoveTaskItem;
508 event RequestAsset OnRequestAsset;
506 509
507 event UUIDNameRequest OnNameFromUUIDRequest; 510 event UUIDNameRequest OnNameFromUUIDRequest;
508 511
diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs
index de3e29d..55c5726 100644
--- a/OpenSim/Region/ClientStack/ClientView.cs
+++ b/OpenSim/Region/ClientStack/ClientView.cs
@@ -51,10 +51,10 @@ namespace OpenSim.Region.ClientStack
51 /// </summary> 51 /// </summary>
52 public class ClientView : IClientAPI 52 public class ClientView : IClientAPI
53 { 53 {
54// ~ClientView() 54 // ~ClientView()
55// { 55 // {
56// System.Console.WriteLine("[CLIENTVIEW]: Destructor called"); 56 // System.Console.WriteLine("[CLIENTVIEW]: Destructor called");
57// } 57 // }
58 58
59 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 59 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
60 60
@@ -119,7 +119,7 @@ namespace OpenSim.Region.ClientStack
119 protected LLVector3 m_startpos; 119 protected LLVector3 m_startpos;
120 protected EndPoint m_userEndPoint; 120 protected EndPoint m_userEndPoint;
121 121
122 /* Instantiated Designated Event Delegates */ 122 /* Instantiated Designated Event Delegates */
123 //- used so we don't create new objects for each incoming packet and then toss it out later */ 123 //- used so we don't create new objects for each incoming packet and then toss it out later */
124 124
125 private RequestAvatarProperties handler001 = null; //OnRequestAvatarProperties; 125 private RequestAvatarProperties handler001 = null; //OnRequestAvatarProperties;
@@ -214,7 +214,8 @@ namespace OpenSim.Region.ClientStack
214 private UpdateVector handler089 = null; //OnUpdatePrimGroupPosition; 214 private UpdateVector handler089 = null; //OnUpdatePrimGroupPosition;
215 private UpdatePrimRotation handler090 = null; //OnUpdatePrimGroupRotation; 215 private UpdatePrimRotation handler090 = null; //OnUpdatePrimGroupRotation;
216 private UpdatePrimGroupRotation handler091 = null; //OnUpdatePrimGroupMouseRotation; 216 private UpdatePrimGroupRotation handler091 = null; //OnUpdatePrimGroupMouseRotation;
217 private PacketStats handler093 = null; // OnPacketStats; 217 private PacketStats handler093 = null; // OnPacketStats;#
218 private RequestAsset handler094 = null; // OnRequestAsset;
218 219
219 220
220 /* Properties */ 221 /* Properties */
@@ -363,7 +364,7 @@ namespace OpenSim.Region.ClientStack
363 // We can't reach into other scenes and close the connection 364 // We can't reach into other scenes and close the connection
364 // We need to do this over grid communications 365 // We need to do this over grid communications
365 //m_scene.CloseAllAgents(CircuitCode); 366 //m_scene.CloseAllAgents(CircuitCode);
366 367
367 // If we're not shutting down the circuit, then this is the last time we'll go here. 368 // If we're not shutting down the circuit, then this is the last time we'll go here.
368 // If we are shutting down the circuit, the UDP Server will come back here with 369 // If we are shutting down the circuit, the UDP Server will come back here with
369 // ShutDownCircuit = false 370 // ShutDownCircuit = false
@@ -502,7 +503,7 @@ namespace OpenSim.Region.ClientStack
502 protected virtual void ClientLoop() 503 protected virtual void ClientLoop()
503 { 504 {
504 m_log.Info("[CLIENT]: Entered loop"); 505 m_log.Info("[CLIENT]: Entered loop");
505 while( true ) 506 while (true)
506 { 507 {
507 QueItem nextPacket = m_packetQueue.Dequeue(); 508 QueItem nextPacket = m_packetQueue.Dequeue();
508 if (nextPacket.Incoming) 509 if (nextPacket.Incoming)
@@ -690,6 +691,7 @@ namespace OpenSim.Region.ClientStack
690 public event RezScript OnRezScript; 691 public event RezScript OnRezScript;
691 public event UpdateTaskInventory OnUpdateTaskInventory; 692 public event UpdateTaskInventory OnUpdateTaskInventory;
692 public event RemoveTaskInventory OnRemoveTaskItem; 693 public event RemoveTaskInventory OnRemoveTaskItem;
694 public event RequestAsset OnRequestAsset;
693 695
694 public event UUIDNameRequest OnNameFromUUIDRequest; 696 public event UUIDNameRequest OnNameFromUUIDRequest;
695 697
@@ -1410,7 +1412,7 @@ namespace OpenSim.Region.ClientStack
1410 OutPacket(replyPacket, ThrottleOutPacketType.Task); 1412 OutPacket(replyPacket, ThrottleOutPacketType.Task);
1411 } 1413 }
1412 1414
1413 public void SendAgentDataUpdate(LLUUID agentid, LLUUID activegroupid, string firstname, string lastname, ulong grouppowers, string groupname,string grouptitle) 1415 public void SendAgentDataUpdate(LLUUID agentid, LLUUID activegroupid, string firstname, string lastname, ulong grouppowers, string groupname, string grouptitle)
1414 { 1416 {
1415 AgentDataUpdatePacket sendAgentDataUpdate = (AgentDataUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentDataUpdate); 1417 AgentDataUpdatePacket sendAgentDataUpdate = (AgentDataUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentDataUpdate);
1416 sendAgentDataUpdate.AgentData.ActiveGroupID = activegroupid; 1418 sendAgentDataUpdate.AgentData.ActiveGroupID = activegroupid;
@@ -1420,7 +1422,7 @@ namespace OpenSim.Region.ClientStack
1420 sendAgentDataUpdate.AgentData.GroupPowers = grouppowers; 1422 sendAgentDataUpdate.AgentData.GroupPowers = grouppowers;
1421 sendAgentDataUpdate.AgentData.GroupTitle = Helpers.StringToField(grouptitle); 1423 sendAgentDataUpdate.AgentData.GroupTitle = Helpers.StringToField(grouptitle);
1422 sendAgentDataUpdate.AgentData.LastName = Helpers.StringToField(lastname); 1424 sendAgentDataUpdate.AgentData.LastName = Helpers.StringToField(lastname);
1423 OutPacket(sendAgentDataUpdate,ThrottleOutPacketType.Task); 1425 OutPacket(sendAgentDataUpdate, ThrottleOutPacketType.Task);
1424 } 1426 }
1425 1427
1426 /// <summary> 1428 /// <summary>
@@ -2329,10 +2331,10 @@ namespace OpenSim.Region.ClientStack
2329 { 2331 {
2330 LLUUID partId = part.UUID; 2332 LLUUID partId = part.UUID;
2331 2333
2332 2334
2333 2335
2334 2336
2335 2337
2336 UpdatePrimRotation handler090 = OnUpdatePrimGroupRotation; 2338 UpdatePrimRotation handler090 = OnUpdatePrimGroupRotation;
2337 UpdatePrimGroupRotation handler091 = OnUpdatePrimGroupMouseRotation; 2339 UpdatePrimGroupRotation handler091 = OnUpdatePrimGroupMouseRotation;
2338 2340
@@ -2344,7 +2346,7 @@ namespace OpenSim.Region.ClientStack
2344 handler086 = OnUpdatePrimSinglePosition; 2346 handler086 = OnUpdatePrimSinglePosition;
2345 if (handler086 != null) 2347 if (handler086 != null)
2346 { 2348 {
2347 2349
2348 // System.Console.WriteLine("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z); 2350 // System.Console.WriteLine("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
2349 handler086(localId, pos1, this); 2351 handler086(localId, pos1, this);
2350 } 2352 }
@@ -2355,18 +2357,18 @@ namespace OpenSim.Region.ClientStack
2355 handler087 = OnUpdatePrimSingleRotation; 2357 handler087 = OnUpdatePrimSingleRotation;
2356 if (handler087 != null) 2358 if (handler087 != null)
2357 { 2359 {
2358 2360
2359 //System.Console.WriteLine("new tab rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W); 2361 //System.Console.WriteLine("new tab rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
2360 handler087(localId, rot1, this); 2362 handler087(localId, rot1, this);
2361 } 2363 }
2362 break; 2364 break;
2363 case 3: 2365 case 3:
2364 2366
2365 LLQuaternion rot2 = new LLQuaternion(block.Data, 12, true); 2367 LLQuaternion rot2 = new LLQuaternion(block.Data, 12, true);
2366 handler087 = OnUpdatePrimSingleRotation; 2368 handler087 = OnUpdatePrimSingleRotation;
2367 if (handler087 != null) 2369 if (handler087 != null)
2368 { 2370 {
2369 2371
2370 //System.Console.WriteLine("new mouse rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W); 2372 //System.Console.WriteLine("new mouse rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
2371 handler087(localId, rot2, this); 2373 handler087(localId, rot2, this);
2372 } 2374 }
@@ -2378,7 +2380,7 @@ namespace OpenSim.Region.ClientStack
2378 handler088 = OnUpdatePrimScale; 2380 handler088 = OnUpdatePrimScale;
2379 if (handler088 != null) 2381 if (handler088 != null)
2380 { 2382 {
2381 2383
2382 // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z); 2384 // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
2383 handler088(localId, scale1, this); 2385 handler088(localId, scale1, this);
2384 } 2386 }
@@ -2390,18 +2392,18 @@ namespace OpenSim.Region.ClientStack
2390 2392
2391 if (handler089 != null) 2393 if (handler089 != null)
2392 { 2394 {
2393 2395
2394 handler089(localId, pos2, this); 2396 handler089(localId, pos2, this);
2395 } 2397 }
2396 break; 2398 break;
2397 case 10: 2399 case 10:
2398 2400
2399 LLQuaternion rot3 = new LLQuaternion(block.Data, 0, true); 2401 LLQuaternion rot3 = new LLQuaternion(block.Data, 0, true);
2400 2402
2401 handler090 = OnUpdatePrimGroupRotation; 2403 handler090 = OnUpdatePrimGroupRotation;
2402 if (handler090 != null) 2404 if (handler090 != null)
2403 { 2405 {
2404 2406
2405 // Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W); 2407 // Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
2406 handler090(localId, rot3, this); 2408 handler090(localId, rot3, this);
2407 } 2409 }
@@ -2429,7 +2431,7 @@ namespace OpenSim.Region.ClientStack
2429 handler088 = OnUpdatePrimScale; 2431 handler088 = OnUpdatePrimScale;
2430 if (handler088 != null) 2432 if (handler088 != null)
2431 { 2433 {
2432 2434
2433 //Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z); 2435 //Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
2434 handler088(localId, scale2, this); 2436 handler088(localId, scale2, this);
2435 2437
@@ -2449,10 +2451,10 @@ namespace OpenSim.Region.ClientStack
2449 handler088 = OnUpdatePrimScale; 2451 handler088 = OnUpdatePrimScale;
2450 if (handler088 != null) 2452 if (handler088 != null)
2451 { 2453 {
2452 2454
2453 // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z ); 2455 // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z );
2454 handler088(localId, scale5, this); 2456 handler088(localId, scale5, this);
2455 2457
2456 handler086 = OnUpdatePrimSinglePosition; 2458 handler086 = OnUpdatePrimSinglePosition;
2457 if (handler086 != null) 2459 if (handler086 != null)
2458 { 2460 {
@@ -2762,7 +2764,7 @@ namespace OpenSim.Region.ClientStack
2762 if ((now - packet.TickCount > RESEND_TIMEOUT) && (!packet.Header.Resent)) 2764 if ((now - packet.TickCount > RESEND_TIMEOUT) && (!packet.Header.Resent))
2763 { 2765 {
2764 //m_log.Debug("[NETWORK]: Resending " + packet.Type.ToString() + " packet, " + 2766 //m_log.Debug("[NETWORK]: Resending " + packet.Type.ToString() + " packet, " +
2765 //(now - packet.TickCount) + "ms have passed"); 2767 //(now - packet.TickCount) + "ms have passed");
2766 2768
2767 packet.Header.Resent = true; 2769 packet.Header.Resent = true;
2768 OutPacket(packet, ThrottleOutPacketType.Resend); 2770 OutPacket(packet, ThrottleOutPacketType.Resend);
@@ -2863,13 +2865,13 @@ namespace OpenSim.Region.ClientStack
2863 2865
2864 case PacketType.AvatarPropertiesRequest: 2866 case PacketType.AvatarPropertiesRequest:
2865 AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack; 2867 AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack;
2866 2868
2867 handler001 = OnRequestAvatarProperties; 2869 handler001 = OnRequestAvatarProperties;
2868 if (handler001 != null) 2870 if (handler001 != null)
2869 { 2871 {
2870 handler001(this, avatarProperties.AgentData.AvatarID); 2872 handler001(this, avatarProperties.AgentData.AvatarID);
2871 } 2873 }
2872 2874
2873 2875
2874 break; 2876 break;
2875 case PacketType.ChatFromViewer: 2877 case PacketType.ChatFromViewer:
@@ -2900,7 +2902,7 @@ namespace OpenSim.Region.ClientStack
2900 handler002(this, args); 2902 handler002(this, args);
2901 } 2903 }
2902 2904
2903 2905
2904 2906
2905 break; 2907 break;
2906 case PacketType.ScriptDialogReply: 2908 case PacketType.ScriptDialogReply:
@@ -2921,7 +2923,7 @@ namespace OpenSim.Region.ClientStack
2921 if (handler003 != null) 2923 if (handler003 != null)
2922 handler003(this, args); 2924 handler003(this, args);
2923 } 2925 }
2924 2926
2925 break; 2927 break;
2926 case PacketType.ImprovedInstantMessage: 2928 case PacketType.ImprovedInstantMessage:
2927 ImprovedInstantMessagePacket msgpack = (ImprovedInstantMessagePacket)Pack; 2929 ImprovedInstantMessagePacket msgpack = (ImprovedInstantMessagePacket)Pack;
@@ -2940,7 +2942,7 @@ namespace OpenSim.Region.ClientStack
2940 msgpack.MessageBlock.BinaryBucket); 2942 msgpack.MessageBlock.BinaryBucket);
2941 } 2943 }
2942 2944
2943 2945
2944 break; 2946 break;
2945 2947
2946 case PacketType.AcceptFriendship: 2948 case PacketType.AcceptFriendship:
@@ -2963,7 +2965,7 @@ namespace OpenSim.Region.ClientStack
2963 handler005(this, agentID, transactionID, callingCardFolders); 2965 handler005(this, agentID, transactionID, callingCardFolders);
2964 } 2966 }
2965 2967
2966 2968
2967 2969
2968 2970
2969 break; 2971 break;
@@ -2977,7 +2979,7 @@ namespace OpenSim.Region.ClientStack
2977 { 2979 {
2978 handler006(this, listOwnerAgentID, exFriendID); 2980 handler006(this, listOwnerAgentID, exFriendID);
2979 } 2981 }
2980 2982
2981 2983
2982 break; 2984 break;
2983 case PacketType.RezObject: 2985 case PacketType.RezObject:
@@ -2995,7 +2997,7 @@ namespace OpenSim.Region.ClientStack
2995 //rezPacket.RezData.RezSelected; 2997 //rezPacket.RezData.RezSelected;
2996 //rezPacket.RezData.FromTaskID; 2998 //rezPacket.RezData.FromTaskID;
2997 //m_log.Info("[REZData]: " + rezPacket.ToString()); 2999 //m_log.Info("[REZData]: " + rezPacket.ToString());
2998 3000
2999 handler007(this, rezPacket.InventoryData.ItemID, rezPacket.RezData.RayEnd, 3001 handler007(this, rezPacket.InventoryData.ItemID, rezPacket.RezData.RayEnd,
3000 rezPacket.RezData.RayStart, rezPacket.RezData.RayTargetID, 3002 rezPacket.RezData.RayStart, rezPacket.RezData.RayTargetID,
3001 rezPacket.RezData.BypassRaycast, rezPacket.RezData.RayEndIsIntersection, 3003 rezPacket.RezData.BypassRaycast, rezPacket.RezData.RayEndIsIntersection,
@@ -3004,7 +3006,7 @@ namespace OpenSim.Region.ClientStack
3004 rezPacket.RezData.RezSelected, rezPacket.RezData.RemoveItem, 3006 rezPacket.RezData.RezSelected, rezPacket.RezData.RemoveItem,
3005 rezPacket.RezData.FromTaskID); 3007 rezPacket.RezData.FromTaskID);
3006 } 3008 }
3007 3009
3008 break; 3010 break;
3009 case PacketType.DeRezObject: 3011 case PacketType.DeRezObject:
3010 handler008 = OnDeRezObject; 3012 handler008 = OnDeRezObject;
@@ -3012,7 +3014,7 @@ namespace OpenSim.Region.ClientStack
3012 { 3014 {
3013 handler008(Pack, this); 3015 handler008(Pack, this);
3014 } 3016 }
3015 3017
3016 break; 3018 break;
3017 case PacketType.ModifyLand: 3019 case PacketType.ModifyLand:
3018 ModifyLandPacket modify = (ModifyLandPacket)Pack; 3020 ModifyLandPacket modify = (ModifyLandPacket)Pack;
@@ -3021,7 +3023,7 @@ namespace OpenSim.Region.ClientStack
3021 { 3023 {
3022 if (OnModifyTerrain != null) 3024 if (OnModifyTerrain != null)
3023 { 3025 {
3024 3026
3025 for (int i = 0; i < modify.ParcelData.Length; i++) 3027 for (int i = 0; i < modify.ParcelData.Length; i++)
3026 { 3028 {
3027 handler009 = OnModifyTerrain; 3029 handler009 = OnModifyTerrain;
@@ -3036,7 +3038,7 @@ namespace OpenSim.Region.ClientStack
3036 } 3038 }
3037 } 3039 }
3038 } 3040 }
3039 3041
3040 break; 3042 break;
3041 case PacketType.RegionHandshakeReply: 3043 case PacketType.RegionHandshakeReply:
3042 3044
@@ -3045,7 +3047,7 @@ namespace OpenSim.Region.ClientStack
3045 { 3047 {
3046 handler010(this); 3048 handler010(this);
3047 } 3049 }
3048 3050
3049 break; 3051 break;
3050 case PacketType.AgentWearablesRequest: 3052 case PacketType.AgentWearablesRequest:
3051 handler011 = OnRequestWearables; 3053 handler011 = OnRequestWearables;
@@ -3054,7 +3056,7 @@ namespace OpenSim.Region.ClientStack
3054 { 3056 {
3055 handler011(); 3057 handler011();
3056 } 3058 }
3057 3059
3058 3060
3059 handler012 = OnRequestAvatarsData; 3061 handler012 = OnRequestAvatarsData;
3060 3062
@@ -3063,7 +3065,7 @@ namespace OpenSim.Region.ClientStack
3063 handler012(this); 3065 handler012(this);
3064 } 3066 }
3065 3067
3066 3068
3067 break; 3069 break;
3068 case PacketType.AgentSetAppearance: 3070 case PacketType.AgentSetAppearance:
3069 AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack; 3071 AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack;
@@ -3073,7 +3075,7 @@ namespace OpenSim.Region.ClientStack
3073 { 3075 {
3074 handler013(appear.ObjectData.TextureEntry, appear.VisualParam); 3076 handler013(appear.ObjectData.TextureEntry, appear.VisualParam);
3075 } 3077 }
3076 3078
3077 break; 3079 break;
3078 case PacketType.AgentIsNowWearing: 3080 case PacketType.AgentIsNowWearing:
3079 if (OnAvatarNowWearing != null) 3081 if (OnAvatarNowWearing != null)
@@ -3094,7 +3096,7 @@ namespace OpenSim.Region.ClientStack
3094 handler014(this, wearingArgs); 3096 handler014(this, wearingArgs);
3095 } 3097 }
3096 3098
3097 3099
3098 } 3100 }
3099 break; 3101 break;
3100 case PacketType.RezSingleAttachmentFromInv: 3102 case PacketType.RezSingleAttachmentFromInv:
@@ -3102,28 +3104,28 @@ namespace OpenSim.Region.ClientStack
3102 handler015 = OnRezSingleAttachmentFromInv; 3104 handler015 = OnRezSingleAttachmentFromInv;
3103 if (handler015 != null) 3105 if (handler015 != null)
3104 { 3106 {
3105 RezSingleAttachmentFromInvPacket rez = (RezSingleAttachmentFromInvPacket) Pack; 3107 RezSingleAttachmentFromInvPacket rez = (RezSingleAttachmentFromInvPacket)Pack;
3106 handler015(this, rez.ObjectData.ItemID, 3108 handler015(this, rez.ObjectData.ItemID,
3107 rez.ObjectData.AttachmentPt, rez.ObjectData.ItemFlags, rez.ObjectData.NextOwnerMask); 3109 rez.ObjectData.AttachmentPt, rez.ObjectData.ItemFlags, rez.ObjectData.NextOwnerMask);
3108 } 3110 }
3109 3111
3110 break; 3112 break;
3111 case PacketType.ObjectAttach: 3113 case PacketType.ObjectAttach:
3112 3114
3113 3115
3114 if (OnObjectAttach != null) 3116 if (OnObjectAttach != null)
3115 { 3117 {
3116 ObjectAttachPacket att = (ObjectAttachPacket)Pack; 3118 ObjectAttachPacket att = (ObjectAttachPacket)Pack;
3117 3119
3118 handler016 = OnObjectAttach; 3120 handler016 = OnObjectAttach;
3119 3121
3120 if (handler016 != null) 3122 if (handler016 != null)
3121 { 3123 {
3122 handler016(this, att.ObjectData[0].ObjectLocalID, att.AgentData.AttachmentPoint, att.ObjectData[0].Rotation); 3124 handler016(this, att.ObjectData[0].ObjectLocalID, att.AgentData.AttachmentPoint, att.ObjectData[0].Rotation);
3123 } 3125 }
3124 } 3126 }
3125 3127
3126 break; 3128 break;
3127 case PacketType.SetAlwaysRun: 3129 case PacketType.SetAlwaysRun:
3128 SetAlwaysRunPacket run = (SetAlwaysRunPacket)Pack; 3130 SetAlwaysRunPacket run = (SetAlwaysRunPacket)Pack;
3129 3131
@@ -3131,7 +3133,7 @@ namespace OpenSim.Region.ClientStack
3131 if (handler017 != null) 3133 if (handler017 != null)
3132 handler017(this, run.AgentData.AlwaysRun); 3134 handler017(this, run.AgentData.AlwaysRun);
3133 3135
3134 3136
3135 3137
3136 break; 3138 break;
3137 case PacketType.CompleteAgentMovement: 3139 case PacketType.CompleteAgentMovement:
@@ -3243,7 +3245,7 @@ namespace OpenSim.Region.ClientStack
3243 3245
3244 case PacketType.SetStartLocationRequest: 3246 case PacketType.SetStartLocationRequest:
3245 SetStartLocationRequestPacket avSetStartLocationRequestPacket = (SetStartLocationRequestPacket)Pack; 3247 SetStartLocationRequestPacket avSetStartLocationRequestPacket = (SetStartLocationRequestPacket)Pack;
3246 3248
3247 if (avSetStartLocationRequestPacket.AgentData.AgentID == AgentId && avSetStartLocationRequestPacket.AgentData.SessionID == SessionId) 3249 if (avSetStartLocationRequestPacket.AgentData.AgentID == AgentId && avSetStartLocationRequestPacket.AgentData.SessionID == SessionId)
3248 { 3250 {
3249 handler027 = OnSetStartLocationRequest; 3251 handler027 = OnSetStartLocationRequest;
@@ -3494,7 +3496,7 @@ namespace OpenSim.Region.ClientStack
3494 byte set = permChanges.Set; 3496 byte set = permChanges.Set;
3495 3497
3496 handler043 = OnObjectPermissions; 3498 handler043 = OnObjectPermissions;
3497 3499
3498 if (handler043 != null) 3500 if (handler043 != null)
3499 OnObjectPermissions(this, AgentID, SessionID, field, localID, mask, set); 3501 OnObjectPermissions(this, AgentID, SessionID, field, localID, mask, set);
3500 } 3502 }
@@ -3539,7 +3541,7 @@ namespace OpenSim.Region.ClientStack
3539 case PacketType.RequestImage: 3541 case PacketType.RequestImage:
3540 RequestImagePacket imageRequest = (RequestImagePacket)Pack; 3542 RequestImagePacket imageRequest = (RequestImagePacket)Pack;
3541 //Console.WriteLine("image request: " + Pack.ToString()); 3543 //Console.WriteLine("image request: " + Pack.ToString());
3542 3544
3543 handler045 = null; 3545 handler045 = null;
3544 3546
3545 for (int i = 0; i < imageRequest.RequestImage.Length; i++) 3547 for (int i = 0; i < imageRequest.RequestImage.Length; i++)
@@ -3551,9 +3553,9 @@ namespace OpenSim.Region.ClientStack
3551 args.DiscardLevel = imageRequest.RequestImage[i].DiscardLevel; 3553 args.DiscardLevel = imageRequest.RequestImage[i].DiscardLevel;
3552 args.PacketNumber = imageRequest.RequestImage[i].Packet; 3554 args.PacketNumber = imageRequest.RequestImage[i].Packet;
3553 args.Priority = imageRequest.RequestImage[i].DownloadPriority; 3555 args.Priority = imageRequest.RequestImage[i].DownloadPriority;
3554 3556
3555 handler045 = OnRequestTexture; 3557 handler045 = OnRequestTexture;
3556 3558
3557 if (handler045 != null) 3559 if (handler045 != null)
3558 OnRequestTexture(this, args); 3560 OnRequestTexture(this, args);
3559 } 3561 }
@@ -3562,7 +3564,12 @@ namespace OpenSim.Region.ClientStack
3562 case PacketType.TransferRequest: 3564 case PacketType.TransferRequest:
3563 //Console.WriteLine("ClientView.ProcessPackets.cs:ProcessInPacket() - Got transfer request"); 3565 //Console.WriteLine("ClientView.ProcessPackets.cs:ProcessInPacket() - Got transfer request");
3564 TransferRequestPacket transfer = (TransferRequestPacket)Pack; 3566 TransferRequestPacket transfer = (TransferRequestPacket)Pack;
3565 m_assetCache.AddAssetRequest(this, transfer); 3567 // m_assetCache.AddAssetRequest(this, transfer);
3568 handler094 = OnRequestAsset;
3569 if (handler094 != null)
3570 {
3571 handler094(this, transfer);
3572 }
3566 break; 3573 break;
3567 case PacketType.AssetUploadRequest: 3574 case PacketType.AssetUploadRequest:
3568 AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack; 3575 AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack;
@@ -3606,7 +3613,7 @@ namespace OpenSim.Region.ClientStack
3606 handler049 = OnConfirmXfer; 3613 handler049 = OnConfirmXfer;
3607 if (handler049 != null) 3614 if (handler049 != null)
3608 { 3615 {
3609 handler049(this, confirmXfer.XferID.ID, confirmXfer.XferID.Packet); 3616 handler049(this, confirmXfer.XferID.ID, confirmXfer.XferID.Packet);
3610 } 3617 }
3611 break; 3618 break;
3612 case PacketType.CreateInventoryFolder: 3619 case PacketType.CreateInventoryFolder:
@@ -3615,7 +3622,7 @@ namespace OpenSim.Region.ClientStack
3615 handler050 = OnCreateNewInventoryFolder; 3622 handler050 = OnCreateNewInventoryFolder;
3616 if (handler050 != null) 3623 if (handler050 != null)
3617 { 3624 {
3618 3625
3619 handler050(this, invFolder.FolderData.FolderID, 3626 handler050(this, invFolder.FolderData.FolderID,
3620 (ushort)invFolder.FolderData.Type, 3627 (ushort)invFolder.FolderData.Type,
3621 Util.FieldToString(invFolder.FolderData.Name), 3628 Util.FieldToString(invFolder.FolderData.Name),
@@ -3709,7 +3716,7 @@ namespace OpenSim.Region.ClientStack
3709 } 3716 }
3710 break; 3717 break;
3711 case PacketType.PurgeInventoryDescendents: 3718 case PacketType.PurgeInventoryDescendents:
3712 3719
3713 PurgeInventoryDescendentsPacket Purge = (PurgeInventoryDescendentsPacket)Pack; 3720 PurgeInventoryDescendentsPacket Purge = (PurgeInventoryDescendentsPacket)Pack;
3714 3721
3715 handler056 = OnPurgeInventoryDescendents; 3722 handler056 = OnPurgeInventoryDescendents;
@@ -4130,7 +4137,7 @@ namespace OpenSim.Region.ClientStack
4130 } 4137 }
4131 break; 4138 break;
4132 case PacketType.EstateCovenantRequest: 4139 case PacketType.EstateCovenantRequest:
4133 4140
4134 EstateCovenantRequestPacket.AgentDataBlock epack = 4141 EstateCovenantRequestPacket.AgentDataBlock epack =
4135 ((EstateCovenantRequestPacket)Pack).AgentData; 4142 ((EstateCovenantRequestPacket)Pack).AgentData;
4136 4143
@@ -4246,9 +4253,9 @@ namespace OpenSim.Region.ClientStack
4246 m_log.Warn("[CLIENT]: unhandled MuteListRequest packet"); 4253 m_log.Warn("[CLIENT]: unhandled MuteListRequest packet");
4247 break; 4254 break;
4248 //case PacketType.AgentDataUpdateRequest: 4255 //case PacketType.AgentDataUpdateRequest:
4249 // TODO: handle this packet 4256 // TODO: handle this packet
4250 //m_log.Warn("[CLIENT]: unhandled AgentDataUpdateRequest packet"); 4257 //m_log.Warn("[CLIENT]: unhandled AgentDataUpdateRequest packet");
4251 //break; 4258 //break;
4252 4259
4253 case PacketType.ParcelDwellRequest: 4260 case PacketType.ParcelDwellRequest:
4254 // TODO: handle this packet 4261 // TODO: handle this packet
@@ -4275,9 +4282,9 @@ namespace OpenSim.Region.ClientStack
4275 m_log.Warn("[CLIENT]: unhandled SoundTrigger packet"); 4282 m_log.Warn("[CLIENT]: unhandled SoundTrigger packet");
4276 break; 4283 break;
4277 //case PacketType.UserInfoRequest: 4284 //case PacketType.UserInfoRequest:
4278 // TODO: handle this packet 4285 // TODO: handle this packet
4279 //m_log.Warn("[CLIENT]: unhandled UserInfoRequest packet"); 4286 //m_log.Warn("[CLIENT]: unhandled UserInfoRequest packet");
4280 //break; 4287 //break;
4281 case PacketType.InventoryDescendents: 4288 case PacketType.InventoryDescendents:
4282 // TODO: handle this packet 4289 // TODO: handle this packet
4283 m_log.Warn("[CLIENT]: unhandled InventoryDescent packet"); 4290 m_log.Warn("[CLIENT]: unhandled InventoryDescent packet");
diff --git a/OpenSim/Region/Environment/Modules/AssetDownloadModule.cs b/OpenSim/Region/Environment/Modules/AssetDownloadModule.cs
index 012f920..ca01cae 100644
--- a/OpenSim/Region/Environment/Modules/AssetDownloadModule.cs
+++ b/OpenSim/Region/Environment/Modules/AssetDownloadModule.cs
@@ -26,25 +26,57 @@
26* 26*
27*/ 27*/
28 28
29using System;
30using System.Collections.Generic;
31using System.Threading;
29using Nini.Config; 32using Nini.Config;
30using OpenSim.Framework; 33using OpenSim.Framework;
31using OpenSim.Region.Environment.Interfaces; 34using OpenSim.Region.Environment.Interfaces;
32using OpenSim.Region.Environment.Scenes; 35using OpenSim.Region.Environment.Scenes;
36using libsecondlife;
37using libsecondlife.Packets;
33 38
34namespace OpenSim.Region.Environment.Modules 39namespace OpenSim.Region.Environment.Modules
35{ 40{
36 public class AssetDownloadModule : IRegionModule 41 public class AssetDownloadModule : IRegionModule
37 { 42 {
38 private Scene m_scene; 43 private Scene m_scene;
44 private Dictionary<LLUUID, Scene> RegisteredScenes = new Dictionary<LLUUID, Scene>();
45 ///
46 /// Assets requests (for each user) which are waiting for asset server data. This includes texture requests
47 /// </summary>
48 private Dictionary<LLUUID, Dictionary<LLUUID,AssetRequest>> RequestedAssets;
49
50 /// <summary>
51 /// Asset requests with data which are ready to be sent back to requesters. This includes textures.
52 /// </summary>
53 private List<AssetRequest> AssetRequests;
54
55 private Thread m_thread;
39 56
40 public AssetDownloadModule() 57 public AssetDownloadModule()
41 { 58 {
59 RequestedAssets = new Dictionary<LLUUID, Dictionary<LLUUID, AssetRequest>>();
60 AssetRequests = new List<AssetRequest>();
42 } 61 }
43 62
44 public void Initialise(Scene scene, IConfigSource config) 63 public void Initialise(Scene scene, IConfigSource config)
45 { 64 {
46 m_scene = scene; 65 if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID))
47 m_scene.EventManager.OnNewClient += NewClient; 66 {
67 RegisteredScenes.Add(scene.RegionInfo.RegionID, scene);
68 scene.EventManager.OnNewClient += NewClient;
69 }
70
71 if (m_scene == null)
72 {
73 m_scene = scene;
74 m_thread = new Thread(new ThreadStart(RunAssetQueue));
75 m_thread.Name = "AssetDownloadQueueThread";
76 m_thread.IsBackground = true;
77 m_thread.Start();
78 OpenSim.Framework.ThreadTracker.Add(m_thread);
79 }
48 } 80 }
49 81
50 public void PostInitialise() 82 public void PostInitialise()
@@ -67,6 +99,240 @@ namespace OpenSim.Region.Environment.Modules
67 99
68 public void NewClient(IClientAPI client) 100 public void NewClient(IClientAPI client)
69 { 101 {
102 client.OnRequestAsset += AddAssetRequest;
103 }
104
105 /// <summary>
106 /// Make an asset request the result of which will be packeted up and sent directly back to the client.
107 /// </summary>
108 /// <param name="userInfo"></param>
109 /// <param name="transferRequest"></param>
110 public void AddAssetRequest(IClientAPI userInfo, TransferRequestPacket transferRequest)
111 {
112 LLUUID requestID = null;
113 byte source = 2;
114 if (transferRequest.TransferInfo.SourceType == 2)
115 {
116 //direct asset request
117 requestID = new LLUUID(transferRequest.TransferInfo.Params, 0);
118 }
119 else if (transferRequest.TransferInfo.SourceType == 3)
120 {
121 //inventory asset request
122 requestID = new LLUUID(transferRequest.TransferInfo.Params, 80);
123 source = 3;
124 //Console.WriteLine("asset request " + requestID);
125 }
126
127 //not found asset
128 // so request from asset server
129 Dictionary<LLUUID, AssetRequest> userRequests = null;
130 if (RequestedAssets.TryGetValue(userInfo.AgentId, out userRequests))
131 {
132 if (!userRequests.ContainsKey(requestID))
133 {
134
135 AssetRequest request = new AssetRequest();
136 request.RequestUser = userInfo;
137 request.RequestAssetID = requestID;
138 request.TransferRequestID = transferRequest.TransferInfo.TransferID;
139 request.AssetRequestSource = source;
140 request.Params = transferRequest.TransferInfo.Params;
141 userRequests[requestID] = request;
142 m_scene.AssetCache.GetAsset(requestID, AssetCallback, false);
143 }
144 }
145 else
146 {
147 userRequests = new Dictionary<LLUUID, AssetRequest>();
148 AssetRequest request = new AssetRequest();
149 request.RequestUser = userInfo;
150 request.RequestAssetID = requestID;
151 request.TransferRequestID = transferRequest.TransferInfo.TransferID;
152 request.AssetRequestSource = source;
153 request.Params = transferRequest.TransferInfo.Params;
154 userRequests.Add(requestID, request);
155 RequestedAssets[userInfo.AgentId] = userRequests;
156 m_scene.AssetCache.GetAsset(requestID, AssetCallback, false);
157
158 }
159 return;
160 }
161
162 public void AssetCallback(LLUUID assetID, AssetBase asset)
163 {
164 if (asset != null)
165 {
166 foreach (Dictionary<LLUUID, AssetRequest> userRequests in RequestedAssets.Values)
167 {
168 if (userRequests.ContainsKey(assetID))
169 {
170 AssetRequest req = userRequests[assetID];
171 if (req != null)
172 {
173 req.AssetInf = asset;
174 req.NumPackets = CalculateNumPackets(asset.Data);
175
176 userRequests.Remove(assetID);
177 AssetRequests.Add(req);
178 }
179 }
180 }
181 }
182 }
183
184 private void RunAssetQueue()
185 {
186 while (true)
187 {
188 try
189 {
190 ProcessAssetQueue();
191 Thread.Sleep(500);
192 }
193 catch (Exception e)
194 {
195 // m_log.Error("[ASSET CACHE]: " + e.ToString());
196 }
197 }
198 }
199
200 /// <summary>
201 /// Process the asset queue which sends packets directly back to the client.
202 /// </summary>
203 private void ProcessAssetQueue()
204 {
205 //should move the asset downloading to a module, like has been done with texture downloading
206 if (AssetRequests.Count == 0)
207 {
208 //no requests waiting
209 return;
210 }
211 // if less than 5, do all of them
212 int num = Math.Min(5, AssetRequests.Count);
213
214 AssetRequest req;
215 for (int i = 0; i < num; i++)
216 {
217 req = (AssetRequest)AssetRequests[i];
218 //Console.WriteLine("sending asset " + req.RequestAssetID);
219 TransferInfoPacket Transfer = new TransferInfoPacket();
220 Transfer.TransferInfo.ChannelType = 2;
221 Transfer.TransferInfo.Status = 0;
222 Transfer.TransferInfo.TargetType = 0;
223 if (req.AssetRequestSource == 2)
224 {
225 Transfer.TransferInfo.Params = new byte[20];
226 Array.Copy(req.RequestAssetID.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16);
227 int assType = (int)req.AssetInf.Type;
228 Array.Copy(Helpers.IntToBytes(assType), 0, Transfer.TransferInfo.Params, 16, 4);
229 }
230 else if (req.AssetRequestSource == 3)
231 {
232 Transfer.TransferInfo.Params = req.Params;
233 // Transfer.TransferInfo.Params = new byte[100];
234 //Array.Copy(req.RequestUser.AgentId.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16);
235 //Array.Copy(req.RequestUser.SessionId.GetBytes(), 0, Transfer.TransferInfo.Params, 16, 16);
236 }
237 Transfer.TransferInfo.Size = (int)req.AssetInf.Data.Length;
238 Transfer.TransferInfo.TransferID = req.TransferRequestID;
239 req.RequestUser.OutPacket(Transfer, ThrottleOutPacketType.Asset);
240
241 if (req.NumPackets == 1)
242 {
243 TransferPacketPacket TransferPacket = new TransferPacketPacket();
244 TransferPacket.TransferData.Packet = 0;
245 TransferPacket.TransferData.ChannelType = 2;
246 TransferPacket.TransferData.TransferID = req.TransferRequestID;
247 TransferPacket.TransferData.Data = req.AssetInf.Data;
248 TransferPacket.TransferData.Status = 1;
249 req.RequestUser.OutPacket(TransferPacket, ThrottleOutPacketType.Asset);
250 }
251 else
252 {
253 int processedLength = 0;
254 // libsecondlife hardcodes 1500 as the maximum data chunk size
255 int maxChunkSize = 1250;
256 int packetNumber = 0;
257
258 while (processedLength < req.AssetInf.Data.Length)
259 {
260 TransferPacketPacket TransferPacket = new TransferPacketPacket();
261 TransferPacket.TransferData.Packet = packetNumber;
262 TransferPacket.TransferData.ChannelType = 2;
263 TransferPacket.TransferData.TransferID = req.TransferRequestID;
264
265 int chunkSize = Math.Min(req.AssetInf.Data.Length - processedLength, maxChunkSize);
266 byte[] chunk = new byte[chunkSize];
267 Array.Copy(req.AssetInf.Data, processedLength, chunk, 0, chunk.Length);
268
269 TransferPacket.TransferData.Data = chunk;
270
271 // 0 indicates more packets to come, 1 indicates last packet
272 if (req.AssetInf.Data.Length - processedLength > maxChunkSize)
273 {
274 TransferPacket.TransferData.Status = 0;
275 }
276 else
277 {
278 TransferPacket.TransferData.Status = 1;
279 }
280
281 req.RequestUser.OutPacket(TransferPacket, ThrottleOutPacketType.Asset);
282
283 processedLength += chunkSize;
284 packetNumber++;
285 }
286 }
287 }
288
289 //remove requests that have been completed
290 for (int i = 0; i < num; i++)
291 {
292 AssetRequests.RemoveAt(0);
293 }
294 }
295 /// <summary>
296 /// Calculate the number of packets required to send the asset to the client.
297 /// </summary>
298 /// <param name="data"></param>
299 /// <returns></returns>
300 private int CalculateNumPackets(byte[] data)
301 {
302 const uint m_maxPacketSize = 600;
303 int numPackets = 1;
304
305 if (data.LongLength > m_maxPacketSize)
306 {
307 // over max number of bytes so split up file
308 long restData = data.LongLength - m_maxPacketSize;
309 int restPackets = (int)((restData + m_maxPacketSize - 1) / m_maxPacketSize);
310 numPackets += restPackets;
311 }
312
313 return numPackets;
314 }
315
316 public class AssetRequest
317 {
318 public IClientAPI RequestUser;
319 public LLUUID RequestAssetID;
320 public AssetBase AssetInf;
321 public AssetBase ImageInfo;
322 public LLUUID TransferRequestID;
323 public long DataPointer = 0;
324 public int NumPackets = 0;
325 public int PacketCounter = 0;
326 public bool IsTextureRequest;
327 public byte AssetRequestSource = 2;
328 public byte[] Params = null;
329 //public bool AssetInCache;
330 //public int TimeRequested;
331 public int DiscardLevel = -1;
332
333 public AssetRequest()
334 {
335 }
70 } 336 }
71 } 337 }
72} \ No newline at end of file 338} \ No newline at end of file
diff --git a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs
index e821800..30a41b7 100644
--- a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs
+++ b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs
@@ -131,6 +131,7 @@ namespace SimpleApp
131 public event RezScript OnRezScript; 131 public event RezScript OnRezScript;
132 public event UpdateTaskInventory OnUpdateTaskInventory; 132 public event UpdateTaskInventory OnUpdateTaskInventory;
133 public event RemoveTaskInventory OnRemoveTaskItem; 133 public event RemoveTaskInventory OnRemoveTaskItem;
134 public event RequestAsset OnRequestAsset;
134 135
135 public event UUIDNameRequest OnNameFromUUIDRequest; 136 public event UUIDNameRequest OnNameFromUUIDRequest;
136 137