aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs')
-rw-r--r--OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs102
1 files changed, 102 insertions, 0 deletions
diff --git a/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs b/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs
new file mode 100644
index 0000000..528e9fa
--- /dev/null
+++ b/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs
@@ -0,0 +1,102 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading;
5using System.Net;
6using System.Net.Sockets;
7using System.IO;
8using libsecondlife;
9using OpenSim.Framework.Interfaces;
10using OpenSim.Framework.Assets;
11using OpenSim.Framework.Utilities;
12
13namespace OpenSim.GridInterfaces.Remote
14{
15 public class RemoteAssetServer : IAssetServer
16 {
17 private IAssetReceiver _receiver;
18 private BlockingQueue<ARequest> _assetRequests;
19 private Thread _remoteAssetServerThread;
20 private string AssetServerUrl;
21 private string AssetSendKey;
22
23 public RemoteAssetServer()
24 {
25 this._assetRequests = new BlockingQueue<ARequest>();
26 this._remoteAssetServerThread = new Thread(new ThreadStart(RunRequests));
27 this._remoteAssetServerThread.IsBackground = true;
28 this._remoteAssetServerThread.Start();
29 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Remote Asset Server class created");
30 }
31
32 public void SetReceiver(IAssetReceiver receiver)
33 {
34 this._receiver = receiver;
35 }
36
37 public void RequestAsset(LLUUID assetID, bool isTexture)
38 {
39 ARequest req = new ARequest();
40 req.AssetID = assetID;
41 req.IsTexture = isTexture;
42 this._assetRequests.Enqueue(req);
43 }
44
45 public void UpdateAsset(AssetBase asset)
46 {
47
48 }
49
50 public void UploadNewAsset(AssetBase asset)
51 {
52
53 }
54
55 public void SetServerInfo(string ServerUrl, string ServerKey)
56 {
57 this.AssetServerUrl = ServerUrl;
58 this.AssetSendKey = ServerKey;
59 }
60
61 private void RunRequests()
62 {
63 while (true)
64 {
65 //we need to add support for the asset server not knowing about a requested asset
66 ARequest req = this._assetRequests.Dequeue();
67 LLUUID assetID = req.AssetID;
68 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(" RemoteAssetServer- Got a AssetServer request, processing it");
69 WebRequest AssetLoad = WebRequest.Create(this.AssetServerUrl + "getasset/" + AssetSendKey + "/" + assetID + "/data");
70 WebResponse AssetResponse = AssetLoad.GetResponse();
71 byte[] idata = new byte[(int)AssetResponse.ContentLength];
72 BinaryReader br = new BinaryReader(AssetResponse.GetResponseStream());
73 idata = br.ReadBytes((int)AssetResponse.ContentLength);
74 br.Close();
75
76 AssetBase asset = new AssetBase();
77 asset.FullID = assetID;
78 asset.Data = idata;
79 _receiver.AssetReceived(asset, req.IsTexture);
80 }
81 }
82
83 public void Close()
84 {
85
86 }
87 }
88
89 public class RemoteAssetPlugin : IAssetPlugin
90 {
91 public RemoteAssetPlugin()
92 {
93
94 }
95
96 public IAssetServer GetAssetServer()
97 {
98 return (new RemoteAssetServer());
99 }
100 }
101
102}