AssetCache.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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.Generic;
  30. using System.Reflection;
  31. using System.Threading;
  32. using libsecondlife;
  33. using libsecondlife.Packets;
  34. using OpenSim.Framework.Interfaces;
  35. using OpenSim.Framework.Types;
  36. namespace OpenSim.Region.Caches
  37. {
  38. public delegate void DownloadComplete(AssetCache.TextureSender sender);
  39. /// <summary>
  40. /// Manages local cache of assets and their sending to viewers.
  41. /// </summary>
  42. public class AssetCache : IAssetReceiver
  43. {
  44. public Dictionary<LLUUID, AssetInfo> Assets;
  45. public Dictionary<LLUUID, TextureImage> Textures;
  46. public List<AssetRequest> AssetRequests = new List<AssetRequest>(); //assets ready to be sent to viewers
  47. public List<AssetRequest> TextureRequests = new List<AssetRequest>(); //textures ready to be sent
  48. public Dictionary<LLUUID, AssetRequest> RequestedAssets = new Dictionary<LLUUID, AssetRequest>(); //Assets requested from the asset server
  49. public Dictionary<LLUUID, AssetRequest> RequestedTextures = new Dictionary<LLUUID, AssetRequest>(); //Textures requested from the asset server
  50. public Dictionary<LLUUID, TextureSender> SendingTextures = new Dictionary<LLUUID, TextureSender>();
  51. private IAssetServer _assetServer;
  52. private Thread _assetCacheThread;
  53. private LLUUID[] textureList = new LLUUID[5];
  54. /// <summary>
  55. ///
  56. /// </summary>
  57. public AssetCache(IAssetServer assetServer)
  58. {
  59. Console.WriteLine("Creating Asset cache");
  60. _assetServer = assetServer;
  61. _assetServer.SetReceiver(this);
  62. Assets = new Dictionary<LLUUID, AssetInfo>();
  63. Textures = new Dictionary<LLUUID, TextureImage>();
  64. this._assetCacheThread = new Thread(new ThreadStart(RunAssetManager));
  65. this._assetCacheThread.IsBackground = true;
  66. this._assetCacheThread.Start();
  67. }
  68. public AssetCache(string assetServerDLLName, string assetServerURL, string assetServerKey)
  69. {
  70. Console.WriteLine("Creating Asset cache");
  71. _assetServer = this.LoadAssetDll(assetServerDLLName);
  72. _assetServer.SetServerInfo(assetServerURL, assetServerKey);
  73. _assetServer.SetReceiver(this);
  74. Assets = new Dictionary<LLUUID, AssetInfo>();
  75. Textures = new Dictionary<LLUUID, TextureImage>();
  76. this._assetCacheThread = new Thread(new ThreadStart(RunAssetManager));
  77. this._assetCacheThread.IsBackground = true;
  78. this._assetCacheThread.Start();
  79. }
  80. /// <summary>
  81. ///
  82. /// </summary>
  83. public void RunAssetManager()
  84. {
  85. while (true)
  86. {
  87. try
  88. {
  89. //Console.WriteLine("Asset cache loop");
  90. this.ProcessAssetQueue();
  91. this.ProcessTextureQueue();
  92. Thread.Sleep(500);
  93. }
  94. catch (Exception e)
  95. {
  96. Console.WriteLine(e.Message);
  97. }
  98. }
  99. }
  100. public void LoadDefaultTextureSet()
  101. {
  102. //hack: so we can give each user a set of textures
  103. textureList[0] = new LLUUID("00000000-0000-0000-9999-000000000001");
  104. textureList[1] = new LLUUID("00000000-0000-0000-9999-000000000002");
  105. textureList[2] = new LLUUID("00000000-0000-0000-9999-000000000003");
  106. textureList[3] = new LLUUID("00000000-0000-0000-9999-000000000004");
  107. textureList[4] = new LLUUID("00000000-0000-0000-9999-000000000005");
  108. for (int i = 0; i < textureList.Length; i++)
  109. {
  110. this._assetServer.RequestAsset(textureList[i], true);
  111. }
  112. }
  113. public AssetBase[] CreateNewInventorySet(LLUUID agentID)
  114. {
  115. AssetBase[] inventorySet = new AssetBase[this.textureList.Length];
  116. for (int i = 0; i < textureList.Length; i++)
  117. {
  118. if (this.Textures.ContainsKey(textureList[i]))
  119. {
  120. inventorySet[i] = this.CloneImage(agentID, this.Textures[textureList[i]]);
  121. TextureImage image = new TextureImage(inventorySet[i]);
  122. this.Textures.Add(image.FullID, image);
  123. this._assetServer.UploadNewAsset(image); //save the asset to the asset server
  124. }
  125. }
  126. return inventorySet;
  127. }
  128. public AssetBase GetAsset(LLUUID assetID)
  129. {
  130. AssetBase asset = null;
  131. if (this.Textures.ContainsKey(assetID))
  132. {
  133. asset = this.Textures[assetID];
  134. }
  135. else if (this.Assets.ContainsKey(assetID))
  136. {
  137. asset = this.Assets[assetID];
  138. }
  139. return asset;
  140. }
  141. public void AddAsset(AssetBase asset)
  142. {
  143. // Console.WriteLine("adding asset " + asset.FullID.ToStringHyphenated());
  144. if (asset.Type == 0)
  145. {
  146. //Console.WriteLine("which is a texture");
  147. if (!this.Textures.ContainsKey(asset.FullID))
  148. { //texture
  149. TextureImage textur = new TextureImage(asset);
  150. this.Textures.Add(textur.FullID, textur);
  151. this._assetServer.UploadNewAsset(asset);
  152. }
  153. }
  154. else
  155. {
  156. if (!this.Assets.ContainsKey(asset.FullID))
  157. {
  158. AssetInfo assetInf = new AssetInfo(asset);
  159. this.Assets.Add(assetInf.FullID, assetInf);
  160. this._assetServer.UploadNewAsset(asset);
  161. }
  162. }
  163. }
  164. /// <summary>
  165. ///
  166. /// </summary>
  167. private void ProcessTextureQueue()
  168. {
  169. if (this.TextureRequests.Count == 0)
  170. {
  171. //no requests waiting
  172. return;
  173. }
  174. int num;
  175. num = this.TextureRequests.Count;
  176. AssetRequest req;
  177. for (int i = 0; i < num; i++)
  178. {
  179. req = (AssetRequest)this.TextureRequests[i];
  180. if (!this.SendingTextures.ContainsKey(req.ImageInfo.FullID))
  181. {
  182. TextureSender sender = new TextureSender(req);
  183. sender.OnComplete += this.TextureSent;
  184. lock (this.SendingTextures)
  185. {
  186. this.SendingTextures.Add(req.ImageInfo.FullID, sender);
  187. }
  188. }
  189. }
  190. this.TextureRequests.Clear();
  191. }
  192. /// <summary>
  193. /// Event handler, called by a TextureSender object to say that texture has been sent
  194. /// </summary>
  195. /// <param name="sender"></param>
  196. public void TextureSent(TextureSender sender)
  197. {
  198. if (this.SendingTextures.ContainsKey(sender.request.ImageInfo.FullID))
  199. {
  200. lock (this.SendingTextures)
  201. {
  202. this.SendingTextures.Remove(sender.request.ImageInfo.FullID);
  203. }
  204. }
  205. }
  206. public void AssetReceived(AssetBase asset, bool IsTexture)
  207. {
  208. if (asset.FullID != LLUUID.Zero) // if it is set to zero then the asset wasn't found by the server
  209. {
  210. //check if it is a texture or not
  211. //then add to the correct cache list
  212. //then check for waiting requests for this asset/texture (in the Requested lists)
  213. //and move those requests into the Requests list.
  214. if (IsTexture)
  215. {
  216. TextureImage image = new TextureImage(asset);
  217. this.Textures.Add(image.FullID, image);
  218. if (this.RequestedTextures.ContainsKey(image.FullID))
  219. {
  220. AssetRequest req = this.RequestedTextures[image.FullID];
  221. req.ImageInfo = image;
  222. if (image.Data.LongLength > 600)
  223. {
  224. //over 600 bytes so split up file
  225. req.NumPackets = 1 + (int)(image.Data.Length - 600 + 999) / 1000;
  226. }
  227. else
  228. {
  229. req.NumPackets = 1;
  230. }
  231. this.RequestedTextures.Remove(image.FullID);
  232. this.TextureRequests.Add(req);
  233. }
  234. }
  235. else
  236. {
  237. AssetInfo assetInf = new AssetInfo(asset);
  238. this.Assets.Add(assetInf.FullID, assetInf);
  239. if (this.RequestedAssets.ContainsKey(assetInf.FullID))
  240. {
  241. AssetRequest req = this.RequestedAssets[assetInf.FullID];
  242. req.AssetInf = assetInf;
  243. if (assetInf.Data.LongLength > 600)
  244. {
  245. //over 600 bytes so split up file
  246. req.NumPackets = 1 + (int)(assetInf.Data.Length - 600 + 999) / 1000;
  247. }
  248. else
  249. {
  250. req.NumPackets = 1;
  251. }
  252. this.RequestedAssets.Remove(assetInf.FullID);
  253. this.AssetRequests.Add(req);
  254. }
  255. }
  256. }
  257. }
  258. public void AssetNotFound(AssetBase asset)
  259. {
  260. //the asset server had no knowledge of requested asset
  261. }
  262. #region Assets
  263. /// <summary>
  264. ///
  265. /// </summary>
  266. /// <param name="userInfo"></param>
  267. /// <param name="transferRequest"></param>
  268. public void AddAssetRequest(IClientAPI userInfo, TransferRequestPacket transferRequest)
  269. {
  270. LLUUID requestID = new LLUUID(transferRequest.TransferInfo.Params, 0);
  271. //check to see if asset is in local cache, if not we need to request it from asset server.
  272. if (!this.Assets.ContainsKey(requestID))
  273. {
  274. //not found asset
  275. // so request from asset server
  276. if (!this.RequestedAssets.ContainsKey(requestID))
  277. {
  278. AssetRequest request = new AssetRequest();
  279. request.RequestUser = userInfo;
  280. request.RequestAssetID = requestID;
  281. request.TransferRequestID = transferRequest.TransferInfo.TransferID;
  282. this.RequestedAssets.Add(requestID, request);
  283. this._assetServer.RequestAsset(requestID, false);
  284. }
  285. return;
  286. }
  287. //it is in our cache
  288. AssetInfo asset = this.Assets[requestID];
  289. //work out how many packets it should be sent in
  290. // and add to the AssetRequests list
  291. AssetRequest req = new AssetRequest();
  292. req.RequestUser = userInfo;
  293. req.RequestAssetID = requestID;
  294. req.TransferRequestID = transferRequest.TransferInfo.TransferID;
  295. req.AssetInf = asset;
  296. if (asset.Data.LongLength > 600)
  297. {
  298. //over 600 bytes so split up file
  299. req.NumPackets = 1 + (int)(asset.Data.Length - 600 + 999) / 1000;
  300. }
  301. else
  302. {
  303. req.NumPackets = 1;
  304. }
  305. this.AssetRequests.Add(req);
  306. }
  307. /// <summary>
  308. ///
  309. /// </summary>
  310. private void ProcessAssetQueue()
  311. {
  312. if (this.AssetRequests.Count == 0)
  313. {
  314. //no requests waiting
  315. return;
  316. }
  317. int num;
  318. if (this.AssetRequests.Count < 5)
  319. {
  320. //lower than 5 so do all of them
  321. num = this.AssetRequests.Count;
  322. }
  323. else
  324. {
  325. num = 5;
  326. }
  327. AssetRequest req;
  328. for (int i = 0; i < num; i++)
  329. {
  330. req = (AssetRequest)this.AssetRequests[i];
  331. TransferInfoPacket Transfer = new TransferInfoPacket();
  332. Transfer.TransferInfo.ChannelType = 2;
  333. Transfer.TransferInfo.Status = 0;
  334. Transfer.TransferInfo.TargetType = 0;
  335. Transfer.TransferInfo.Params = req.RequestAssetID.GetBytes();
  336. Transfer.TransferInfo.Size = (int)req.AssetInf.Data.Length;
  337. Transfer.TransferInfo.TransferID = req.TransferRequestID;
  338. req.RequestUser.OutPacket(Transfer);
  339. if (req.NumPackets == 1)
  340. {
  341. TransferPacketPacket TransferPacket = new TransferPacketPacket();
  342. TransferPacket.TransferData.Packet = 0;
  343. TransferPacket.TransferData.ChannelType = 2;
  344. TransferPacket.TransferData.TransferID = req.TransferRequestID;
  345. TransferPacket.TransferData.Data = req.AssetInf.Data;
  346. TransferPacket.TransferData.Status = 1;
  347. req.RequestUser.OutPacket(TransferPacket);
  348. }
  349. else
  350. {
  351. //more than one packet so split file up , for now it can't be bigger than 2000 bytes
  352. TransferPacketPacket TransferPacket = new TransferPacketPacket();
  353. TransferPacket.TransferData.Packet = 0;
  354. TransferPacket.TransferData.ChannelType = 2;
  355. TransferPacket.TransferData.TransferID = req.TransferRequestID;
  356. byte[] chunk = new byte[1000];
  357. Array.Copy(req.AssetInf.Data, chunk, 1000);
  358. TransferPacket.TransferData.Data = chunk;
  359. TransferPacket.TransferData.Status = 0;
  360. req.RequestUser.OutPacket(TransferPacket);
  361. TransferPacket = new TransferPacketPacket();
  362. TransferPacket.TransferData.Packet = 1;
  363. TransferPacket.TransferData.ChannelType = 2;
  364. TransferPacket.TransferData.TransferID = req.TransferRequestID;
  365. byte[] chunk1 = new byte[(req.AssetInf.Data.Length - 1000)];
  366. Array.Copy(req.AssetInf.Data, 1000, chunk1, 0, chunk1.Length);
  367. TransferPacket.TransferData.Data = chunk1;
  368. TransferPacket.TransferData.Status = 1;
  369. req.RequestUser.OutPacket(TransferPacket);
  370. }
  371. }
  372. //remove requests that have been completed
  373. for (int i = 0; i < num; i++)
  374. {
  375. this.AssetRequests.RemoveAt(0);
  376. }
  377. }
  378. public AssetInfo CloneAsset(LLUUID newOwner, AssetInfo sourceAsset)
  379. {
  380. AssetInfo newAsset = new AssetInfo();
  381. newAsset.Data = new byte[sourceAsset.Data.Length];
  382. Array.Copy(sourceAsset.Data, newAsset.Data, sourceAsset.Data.Length);
  383. newAsset.FullID = LLUUID.Random();
  384. newAsset.Type = sourceAsset.Type;
  385. newAsset.InvType = sourceAsset.InvType;
  386. return (newAsset);
  387. }
  388. #endregion
  389. #region Textures
  390. /// <summary>
  391. ///
  392. /// </summary>
  393. /// <param name="userInfo"></param>
  394. /// <param name="imageID"></param>
  395. public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID)
  396. {
  397. //Console.WriteLine("texture request for " + imageID.ToStringHyphenated());
  398. //check to see if texture is in local cache, if not request from asset server
  399. if (!this.Textures.ContainsKey(imageID))
  400. {
  401. if (!this.RequestedTextures.ContainsKey(imageID))
  402. {
  403. //not is cache so request from asset server
  404. AssetRequest request = new AssetRequest();
  405. request.RequestUser = userInfo;
  406. request.RequestAssetID = imageID;
  407. request.IsTextureRequest = true;
  408. this.RequestedTextures.Add(imageID, request);
  409. this._assetServer.RequestAsset(imageID, true);
  410. }
  411. return;
  412. }
  413. //Console.WriteLine("texture already in cache");
  414. TextureImage imag = this.Textures[imageID];
  415. AssetRequest req = new AssetRequest();
  416. req.RequestUser = userInfo;
  417. req.RequestAssetID = imageID;
  418. req.IsTextureRequest = true;
  419. req.ImageInfo = imag;
  420. if (imag.Data.LongLength > 600)
  421. {
  422. //over 600 bytes so split up file
  423. req.NumPackets = 1 + (int)(imag.Data.Length - 600 + 999) / 1000;
  424. }
  425. else
  426. {
  427. req.NumPackets = 1;
  428. }
  429. this.TextureRequests.Add(req);
  430. }
  431. public TextureImage CloneImage(LLUUID newOwner, TextureImage source)
  432. {
  433. TextureImage newImage = new TextureImage();
  434. newImage.Data = new byte[source.Data.Length];
  435. Array.Copy(source.Data, newImage.Data, source.Data.Length);
  436. //newImage.filename = source.filename;
  437. newImage.FullID = LLUUID.Random();
  438. newImage.Name = source.Name;
  439. return (newImage);
  440. }
  441. #endregion
  442. private IAssetServer LoadAssetDll(string dllName)
  443. {
  444. Assembly pluginAssembly = Assembly.LoadFrom(dllName);
  445. IAssetServer server = null;
  446. foreach (Type pluginType in pluginAssembly.GetTypes())
  447. {
  448. if (pluginType.IsPublic)
  449. {
  450. if (!pluginType.IsAbstract)
  451. {
  452. Type typeInterface = pluginType.GetInterface("IAssetPlugin", true);
  453. if (typeInterface != null)
  454. {
  455. IAssetPlugin plug = (IAssetPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
  456. server = plug.GetAssetServer();
  457. break;
  458. }
  459. typeInterface = null;
  460. }
  461. }
  462. }
  463. pluginAssembly = null;
  464. return server;
  465. }
  466. public class AssetRequest
  467. {
  468. public IClientAPI RequestUser;
  469. public LLUUID RequestAssetID;
  470. public AssetInfo AssetInf;
  471. public TextureImage ImageInfo;
  472. public LLUUID TransferRequestID;
  473. public long DataPointer = 0;
  474. public int NumPackets = 0;
  475. public int PacketCounter = 0;
  476. public bool IsTextureRequest;
  477. //public bool AssetInCache;
  478. //public int TimeRequested;
  479. public AssetRequest()
  480. {
  481. }
  482. }
  483. public class AssetInfo : AssetBase
  484. {
  485. public AssetInfo()
  486. {
  487. }
  488. public AssetInfo(AssetBase aBase)
  489. {
  490. Data = aBase.Data;
  491. FullID = aBase.FullID;
  492. Type = aBase.Type;
  493. InvType = aBase.InvType;
  494. Name = aBase.Name;
  495. Description = aBase.Description;
  496. }
  497. }
  498. public class TextureImage : AssetBase
  499. {
  500. public TextureImage()
  501. {
  502. }
  503. public TextureImage(AssetBase aBase)
  504. {
  505. Data = aBase.Data;
  506. FullID = aBase.FullID;
  507. Type = aBase.Type;
  508. InvType = aBase.InvType;
  509. Name = aBase.Name;
  510. Description = aBase.Description;
  511. }
  512. }
  513. public class TextureSender
  514. {
  515. public AssetRequest request;
  516. public event DownloadComplete OnComplete;
  517. Thread m_thread;
  518. public TextureSender(AssetRequest req)
  519. {
  520. request = req;
  521. //Console.WriteLine("creating worker thread for texture " + req.ImageInfo.FullID.ToStringHyphenated());
  522. //Console.WriteLine("texture data length is " + req.ImageInfo.Data.Length);
  523. // Console.WriteLine("in " + req.NumPackets + " packets");
  524. //ThreadPool.QueueUserWorkItem(new WaitCallback(SendTexture), new object());
  525. //need some sort of custom threadpool here, as using the .net one, overloads it and stops the handling of incoming packets etc
  526. //but don't really want to create a thread for every texture download
  527. m_thread = new Thread(new ThreadStart(SendTexture));
  528. m_thread.IsBackground = true;
  529. m_thread.Start();
  530. }
  531. public void SendTexture()
  532. {
  533. //Console.WriteLine("starting to send sending texture " + request.ImageInfo.FullID.ToStringHyphenated());
  534. while (request.PacketCounter != request.NumPackets)
  535. {
  536. SendPacket();
  537. Thread.Sleep(500);
  538. }
  539. //Console.WriteLine("finished sending texture " + request.ImageInfo.FullID.ToStringHyphenated());
  540. if (OnComplete != null)
  541. {
  542. OnComplete(this);
  543. }
  544. }
  545. public void SendPacket()
  546. {
  547. AssetRequest req = request;
  548. // Console.WriteLine("sending " + req.ImageInfo.FullID);
  549. // if (req.ImageInfo.FullID == new LLUUID("00000000-0000-0000-5005-000000000005"))
  550. if (req.PacketCounter == 0)
  551. {
  552. //first time for this request so send imagedata packet
  553. if (req.NumPackets == 1)
  554. {
  555. //only one packet so send whole file
  556. ImageDataPacket im = new ImageDataPacket();
  557. im.ImageID.Packets = 1;
  558. im.ImageID.ID = req.ImageInfo.FullID;
  559. im.ImageID.Size = (uint)req.ImageInfo.Data.Length;
  560. im.ImageData.Data = req.ImageInfo.Data;
  561. im.ImageID.Codec = 2;
  562. req.RequestUser.OutPacket(im);
  563. req.PacketCounter++;
  564. //req.ImageInfo.l= time;
  565. //System.Console.WriteLine("sent texture: " + req.ImageInfo.FullID);
  566. // Console.WriteLine("sending packet 1 for " + req.ImageInfo.FullID.ToStringHyphenated());
  567. }
  568. else
  569. {
  570. //more than one packet so split file up
  571. ImageDataPacket im = new ImageDataPacket();
  572. im.ImageID.Packets = (ushort)req.NumPackets;
  573. im.ImageID.ID = req.ImageInfo.FullID;
  574. im.ImageID.Size = (uint)req.ImageInfo.Data.Length;
  575. im.ImageData.Data = new byte[600];
  576. Array.Copy(req.ImageInfo.Data, 0, im.ImageData.Data, 0, 600);
  577. im.ImageID.Codec = 2;
  578. req.RequestUser.OutPacket(im);
  579. req.PacketCounter++;
  580. //req.ImageInfo.last_used = time;
  581. //System.Console.WriteLine("sent first packet of texture:
  582. // Console.WriteLine("sending packet 1 for " + req.ImageInfo.FullID.ToStringHyphenated());
  583. }
  584. }
  585. else
  586. {
  587. //Console.WriteLine("sending packet" + req.PacketCounter + "for " + req.ImageInfo.FullID.ToStringHyphenated());
  588. //send imagepacket
  589. //more than one packet so split file up
  590. ImagePacketPacket im = new ImagePacketPacket();
  591. im.ImageID.Packet = (ushort)req.PacketCounter;
  592. im.ImageID.ID = req.ImageInfo.FullID;
  593. int size = req.ImageInfo.Data.Length - 600 - 1000 * (req.PacketCounter - 1);
  594. if (size > 1000) size = 1000;
  595. im.ImageData.Data = new byte[size];
  596. Array.Copy(req.ImageInfo.Data, 600 + 1000 * (req.PacketCounter - 1), im.ImageData.Data, 0, size);
  597. req.RequestUser.OutPacket(im);
  598. req.PacketCounter++;
  599. //req.ImageInfo.last_used = time;
  600. //System.Console.WriteLine("sent a packet of texture: "+req.image_info.FullID);
  601. }
  602. }
  603. }
  604. }
  605. }