RemoteAssetServer.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.Assets;
  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. ARequest req = this._assetRequests.Dequeue();
  57. LLUUID assetID = req.AssetID;
  58. OpenSim.Framework.Console.MainConsole.Instance.WriteLine(" RemoteAssetServer- Got a AssetServer request, processing it");
  59. WebRequest AssetLoad = WebRequest.Create(this.AssetServerUrl + "getasset/" + AssetSendKey + "/" + assetID + "/data");
  60. WebResponse AssetResponse = AssetLoad.GetResponse();
  61. byte[] idata = new byte[(int)AssetResponse.ContentLength];
  62. BinaryReader br = new BinaryReader(AssetResponse.GetResponseStream());
  63. idata = br.ReadBytes((int)AssetResponse.ContentLength);
  64. br.Close();
  65. AssetBase asset = new AssetBase();
  66. asset.FullID = assetID;
  67. asset.Data = idata;
  68. _receiver.AssetReceived(asset, req.IsTexture);
  69. }
  70. }
  71. public void Close()
  72. {
  73. }
  74. }
  75. public class RemoteAssetPlugin : IAssetPlugin
  76. {
  77. public RemoteAssetPlugin()
  78. {
  79. }
  80. public IAssetServer GetAssetServer()
  81. {
  82. return (new RemoteAssetServer());
  83. }
  84. }
  85. }