diff options
author | MW | 2007-05-26 13:40:19 +0000 |
---|---|---|
committer | MW | 2007-05-26 13:40:19 +0000 |
commit | 3436961bb5c01d659d09be134368f4f69460cef9 (patch) | |
tree | 3753ba4d7818df2a6bce0bbe863ff033cdfd568a /OpenSim/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs | |
download | opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.zip opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.tar.gz opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.tar.bz2 opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.tar.xz |
Start of rewrite 5279!
Diffstat (limited to '')
-rw-r--r-- | OpenSim/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs b/OpenSim/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs new file mode 100644 index 0000000..7432dee --- /dev/null +++ b/OpenSim/OpenSim.GridInterfaces/Remote/RemoteAssetServer.cs | |||
@@ -0,0 +1,108 @@ | |||
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 | |||
13 | namespace 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 | } | ||