aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/RemoteServers/RemoteGridServers/RemoteGrid.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/RemoteServers/RemoteGridServers/RemoteGrid.cs279
1 files changed, 0 insertions, 279 deletions
diff --git a/src/RemoteServers/RemoteGridServers/RemoteGrid.cs b/src/RemoteServers/RemoteGridServers/RemoteGrid.cs
deleted file mode 100644
index adb3d0f..0000000
--- a/src/RemoteServers/RemoteGridServers/RemoteGrid.cs
+++ /dev/null
@@ -1,279 +0,0 @@
1/*
2* Copyright (c) OpenSim project, http://sim.opensecondlife.org/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
10* documentation and/or other materials provided with the distribution.
11* * Neither the name of the <organization> nor the
12* names of its contributors may be used to endorse or promote products
13* derived from this software without specific prior written permission.
14*
15* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
16* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
19* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*
26*/
27using System;
28using System.Collections;
29using System.Collections.Generic;
30using System.Threading;
31using System.Net;
32using System.Net.Sockets;
33using System.IO;
34using System.Xml;
35using libsecondlife;
36using OpenSim.GridServers;
37
38namespace RemoteGridServers
39{
40 /// <summary>
41 ///
42 /// </summary>
43 ///
44
45 public class RemoteGridPlugin : IGridPlugin
46 {
47 public RemoteGridPlugin()
48 {
49
50 }
51
52 public IGridServer GetGridServer()
53 {
54 return(new RemoteGridServer());
55 }
56 }
57
58 public class RemoteAssetPlugin : IAssetPlugin
59 {
60 public RemoteAssetPlugin()
61 {
62
63 }
64
65 public IAssetServer GetAssetServer()
66 {
67 return(new RemoteAssetServer());
68 }
69 }
70 public class RemoteGridServer : RemoteGridBase
71 {
72 private string GridServerUrl;
73 private string GridSendKey;
74 private string GridRecvKey;
75 private string UserServerUrl;
76 private string UserSendKey;
77 private string UserRecvKey;
78
79 private Dictionary<uint, agentcircuitdata> AgentCircuits = new Dictionary<uint, agentcircuitdata>();
80
81 public override Dictionary<uint, agentcircuitdata> agentcircuits {
82 get {return AgentCircuits;}
83 set {AgentCircuits=value;}
84 }
85
86 public RemoteGridServer()
87 {
88 ServerConsole.MainConsole.Instance.WriteLine("Remote Grid Server class created");
89 }
90
91 public override bool RequestConnection()
92 {
93 return true;
94 }
95
96 public override AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitcode)
97 {
98 agentcircuitdata validcircuit=this.AgentCircuits[circuitcode];
99 AuthenticateResponse user = new AuthenticateResponse();
100 if((sessionID==validcircuit.SessionID) && (agentID==validcircuit.AgentID))
101 {
102 // YAY! Valid login
103 user.Authorised = true;
104 user.LoginInfo = new Login();
105 user.LoginInfo.Agent = agentID;
106 user.LoginInfo.Session = sessionID;
107 user.LoginInfo.First = validcircuit.firstname;
108 user.LoginInfo.Last = validcircuit.lastname;
109 }
110 else
111 {
112 // Invalid
113 user.Authorised = false;
114 }
115
116 return(user);
117 }
118
119 public override bool LogoutSession(LLUUID sessionID, LLUUID agentID, uint circuitCode)
120 {
121 WebRequest DeleteSession = WebRequest.Create(UserServerUrl + "/usersessions/" + sessionID.ToString());
122 DeleteSession.Method="DELETE";
123 DeleteSession.ContentType="text/plaintext";
124 DeleteSession.ContentLength=0;
125
126 StreamWriter stOut = new StreamWriter (DeleteSession.GetRequestStream(), System.Text.Encoding.ASCII);
127 stOut.Write("");
128 stOut.Close();
129
130 StreamReader stIn = new StreamReader(DeleteSession.GetResponse().GetResponseStream());
131 string GridResponse = stIn.ReadToEnd();
132 stIn.Close();
133 return(true);
134 }
135
136 public override UUIDBlock RequestUUIDBlock()
137 {
138 UUIDBlock uuidBlock = new UUIDBlock();
139 return(uuidBlock);
140 }
141
142 public override neighbourinfo[] RequestNeighbours(ulong regionhandle)
143 {
144 ArrayList neighbourlist = new ArrayList();
145
146 WebRequest FindNeighbours = WebRequest.Create(GridServerUrl + "/regions/" + regionhandle.ToString() + "/neighbours");
147 FindNeighbours.ContentType="text/plaintext";
148 FindNeighbours.ContentLength=0;
149
150 StreamWriter stOut = new StreamWriter (FindNeighbours.GetRequestStream(), System.Text.Encoding.ASCII);
151 stOut.Write("");
152 stOut.Close();
153
154
155 XmlDocument GridRespXml = new XmlDocument();
156 GridRespXml.Load(FindNeighbours.GetResponse().GetResponseStream());
157
158
159 XmlNode NeighboursRoot = GridRespXml.FirstChild;
160 if(NeighboursRoot.Name != "neighbours") {
161 return new neighbourinfo[0];
162 }
163
164 FindNeighbours.GetResponse().GetResponseStream().Close();
165
166 return new neighbourinfo[0];
167 }
168
169 public override void SetServerInfo(string UserServerUrl, string UserSendKey, string UserRecvKey, string GridServerUrl, string GridSendKey, string GridRecvKey)
170 {
171 this.UserServerUrl = UserServerUrl;
172 this.UserSendKey = UserSendKey;
173 this.UserRecvKey = UserRecvKey;
174 this.GridServerUrl = GridServerUrl;
175 this.GridSendKey = GridSendKey;
176 this.GridRecvKey = GridRecvKey;
177 }
178
179 public override string GetName()
180 {
181 return "Remote";
182 }
183 }
184
185
186 public class RemoteAssetServer : IAssetServer
187 {
188 private IAssetReceiver _receiver;
189 private BlockingQueue<ARequest> _assetRequests;
190 private Thread _remoteAssetServerThread;
191 private string AssetServerUrl;
192 private string AssetSendKey;
193
194 public RemoteAssetServer()
195 {
196 this._assetRequests = new BlockingQueue<ARequest>();
197 this._remoteAssetServerThread = new Thread(new ThreadStart(RunRequests));
198 this._remoteAssetServerThread.IsBackground = true;
199 this._remoteAssetServerThread.Start();
200 ServerConsole.MainConsole.Instance.WriteLine("Remote Asset Server class created");
201 }
202
203 public void SetReceiver(IAssetReceiver receiver)
204 {
205 this._receiver = receiver;
206 }
207
208 public void RequestAsset(LLUUID assetID, bool isTexture)
209 {
210 ARequest req = new ARequest();
211 req.AssetID = assetID;
212 req.IsTexture = isTexture;
213 this._assetRequests.Enqueue(req);
214 }
215
216 public void UpdateAsset(AssetBase asset)
217 {
218
219 }
220
221 public void UploadNewAsset(AssetBase asset)
222 {
223
224 }
225
226 public void SetServerInfo(string ServerUrl, string ServerKey)
227 {
228 this.AssetServerUrl = ServerUrl;
229 this.AssetSendKey = ServerKey;
230 }
231
232 private void RunRequests()
233 {
234 while(true)
235 {
236 //we need to add support for the asset server not knowing about a requested asset
237 ARequest req = this._assetRequests.Dequeue();
238 LLUUID assetID = req.AssetID;
239 ServerConsole.MainConsole.Instance.WriteLine(" RemoteAssetServer- Got a AssetServer request, processing it");
240 WebRequest AssetLoad = WebRequest.Create(this.AssetServerUrl + "getasset/" + AssetSendKey + "/" + assetID + "/data");
241 WebResponse AssetResponse = AssetLoad.GetResponse();
242 byte[] idata = new byte[(int)AssetResponse.ContentLength];
243 BinaryReader br = new BinaryReader(AssetResponse.GetResponseStream());
244 idata = br.ReadBytes((int)AssetResponse.ContentLength);
245 br.Close();
246
247 AssetBase asset = new AssetBase();
248 asset.FullID = assetID;
249 asset.Data = idata;
250 _receiver.AssetReceived(asset, req.IsTexture );
251 }
252 }
253 }
254
255 public class BlockingQueue< T > {
256 private Queue< T > _queue = new Queue< T >();
257 private object _queueSync = new object();
258
259 public void Enqueue(T value)
260 {
261 lock(_queueSync)
262 {
263 _queue.Enqueue(value);
264 Monitor.Pulse(_queueSync);
265 }
266 }
267
268 public T Dequeue()
269 {
270 lock(_queueSync)
271 {
272 if( _queue.Count < 1)
273 Monitor.Wait(_queueSync);
274
275 return _queue.Dequeue();
276 }
277 }
278 }
279}