RemoteAssetServer.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading;
  5. using System.Net;
  6. using System.Net.Sockets;
  7. using System.IO;
  8. using libsecondlife;
  9. using OpenSim.Framework.Interfaces;
  10. using OpenSim.Framework.Types;
  11. using OpenSim.Framework.Utilities;
  12. namespace OpenSim.GridInterfaces.Remote
  13. {
  14. public class RemoteAssetServer : IAssetServer
  15. {
  16. private IAssetReceiver _receiver;
  17. private BlockingQueue<ARequest> _assetRequests;
  18. private Thread _remoteAssetServerThread;
  19. private string AssetServerUrl;
  20. private string AssetSendKey;
  21. public RemoteAssetServer()
  22. {
  23. this._assetRequests = new BlockingQueue<ARequest>();
  24. this._remoteAssetServerThread = new Thread(new ThreadStart(RunRequests));
  25. this._remoteAssetServerThread.IsBackground = true;
  26. this._remoteAssetServerThread.Start();
  27. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Remote Asset Server class created");
  28. }
  29. public void SetReceiver(IAssetReceiver receiver)
  30. {
  31. this._receiver = receiver;
  32. }
  33. public void RequestAsset(LLUUID assetID, bool isTexture)
  34. {
  35. ARequest req = new ARequest();
  36. req.AssetID = assetID;
  37. req.IsTexture = isTexture;
  38. this._assetRequests.Enqueue(req);
  39. }
  40. public void UpdateAsset(AssetBase asset)
  41. {
  42. }
  43. public void UploadNewAsset(AssetBase asset)
  44. {
  45. }
  46. public void SetServerInfo(string ServerUrl, string ServerKey)
  47. {
  48. this.AssetServerUrl = ServerUrl;
  49. this.AssetSendKey = ServerKey;
  50. }
  51. private void RunRequests()
  52. {
  53. while (true)
  54. {
  55. //we need to add support for the asset server not knowing about a requested asset
  56. // 404... THE MAGIC FILE NOT FOUND ERROR, very useful for telling you things such as a file (or asset ;) ) not being found!!!!!!!!!!! it's 2:22AM
  57. ARequest req = this._assetRequests.Dequeue();
  58. LLUUID assetID = req.AssetID;
  59. OpenSim.Framework.Console.MainConsole.Instance.WriteLine(" RemoteAssetServer- Got a AssetServer request, processing it - " + this.AssetServerUrl + "assets/" + assetID);
  60. WebRequest AssetLoad = WebRequest.Create(this.AssetServerUrl + "assets/" + assetID);
  61. WebResponse AssetResponse = AssetLoad.GetResponse();
  62. byte[] idata = new byte[(int)AssetResponse.ContentLength];
  63. BinaryReader br = new BinaryReader(AssetResponse.GetResponseStream());
  64. idata = br.ReadBytes((int)AssetResponse.ContentLength);
  65. br.Close();
  66. AssetBase asset = new AssetBase();
  67. asset.FullID = assetID;
  68. asset.Data = idata;
  69. _receiver.AssetReceived(asset, req.IsTexture);
  70. }
  71. }
  72. public void Close()
  73. {
  74. }
  75. }
  76. public class RemoteAssetPlugin : IAssetPlugin
  77. {
  78. public RemoteAssetPlugin()
  79. {
  80. }
  81. public IAssetServer GetAssetServer()
  82. {
  83. return (new RemoteAssetServer());
  84. }
  85. }
  86. }