aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim-Source/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim-Source/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs')
-rw-r--r--OpenSim-Source/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs108
1 files changed, 108 insertions, 0 deletions
diff --git a/OpenSim-Source/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs b/OpenSim-Source/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs
new file mode 100644
index 0000000..7432dee
--- /dev/null
+++ b/OpenSim-Source/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs
@@ -0,0 +1,108 @@
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.Types;
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(OpenSim.Framework.Console.LogPriority.LOW,"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 Encoding Windows1252Encoding = Encoding.GetEncoding(1252);
53 string ret = Windows1252Encoding.GetString(asset.Data);
54 byte[] buffer = Windows1252Encoding.GetBytes(ret);
55 WebClient client = new WebClient();
56 client.UploadData(this.AssetServerUrl + "assets/" + asset.FullID, buffer);
57
58 }
59
60 public void SetServerInfo(string ServerUrl, string ServerKey)
61 {
62 this.AssetServerUrl = ServerUrl;
63 this.AssetSendKey = ServerKey;
64 }
65
66 private void RunRequests()
67 {
68 while (true)
69 {
70 //we need to add support for the asset server not knowing about a requested asset
71 // 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
72 ARequest req = this._assetRequests.Dequeue();
73 LLUUID assetID = req.AssetID;
74 // OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW," RemoteAssetServer- Got a AssetServer request, processing it - " + this.AssetServerUrl + "assets/" + assetID);
75 WebRequest AssetLoad = WebRequest.Create(this.AssetServerUrl + "assets/" + assetID);
76 WebResponse AssetResponse = AssetLoad.GetResponse();
77 byte[] idata = new byte[(int)AssetResponse.ContentLength];
78 BinaryReader br = new BinaryReader(AssetResponse.GetResponseStream());
79 idata = br.ReadBytes((int)AssetResponse.ContentLength);
80 br.Close();
81
82 AssetBase asset = new AssetBase();
83 asset.FullID = assetID;
84 asset.Data = idata;
85 _receiver.AssetReceived(asset, req.IsTexture);
86 }
87 }
88
89 public void Close()
90 {
91
92 }
93 }
94
95 public class RemoteAssetPlugin : IAssetPlugin
96 {
97 public RemoteAssetPlugin()
98 {
99
100 }
101
102 public IAssetServer GetAssetServer()
103 {
104 return (new RemoteAssetServer());
105 }
106 }
107
108}