diff options
Start of rewrite 5279!
Diffstat (limited to '')
-rw-r--r-- | OpenSim/OpenSim.GridInterfaces/Remote/RemoteGridServer.cs | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.GridInterfaces/Remote/RemoteGridServer.cs b/OpenSim/OpenSim.GridInterfaces/Remote/RemoteGridServer.cs new file mode 100644 index 0000000..7f911d8 --- /dev/null +++ b/OpenSim/OpenSim.GridInterfaces/Remote/RemoteGridServer.cs | |||
@@ -0,0 +1,210 @@ | |||
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 | */ | ||
27 | using System; | ||
28 | using System.Collections; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Threading; | ||
31 | using System.Net; | ||
32 | using System.Net.Sockets; | ||
33 | using System.IO; | ||
34 | using libsecondlife; | ||
35 | using Nwc.XmlRpc; | ||
36 | using OpenSim.Framework.Interfaces; | ||
37 | using OpenSim.Framework.Types; | ||
38 | |||
39 | namespace OpenSim.GridInterfaces.Remote | ||
40 | { | ||
41 | public class RemoteGridServer : RemoteGridBase | ||
42 | { | ||
43 | private string GridServerUrl; | ||
44 | private string GridSendKey; | ||
45 | private string GridRecvKey; | ||
46 | private Dictionary<uint, AgentCircuitData> AgentCircuits = new Dictionary<uint, AgentCircuitData>(); | ||
47 | private ArrayList simneighbours = new ArrayList(); | ||
48 | private Hashtable griddatahash; | ||
49 | |||
50 | public override Dictionary<uint, AgentCircuitData> agentcircuits | ||
51 | { | ||
52 | get { return AgentCircuits; } | ||
53 | set { AgentCircuits = value; } | ||
54 | } | ||
55 | |||
56 | public override ArrayList neighbours | ||
57 | { | ||
58 | get { return simneighbours; } | ||
59 | set { simneighbours = value; } | ||
60 | } | ||
61 | |||
62 | public override Hashtable GridData | ||
63 | { | ||
64 | get { return griddatahash; } | ||
65 | set { griddatahash = value; } | ||
66 | } | ||
67 | |||
68 | |||
69 | public RemoteGridServer() | ||
70 | { | ||
71 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Remote Grid Server class created"); | ||
72 | } | ||
73 | |||
74 | public override bool RequestConnection(LLUUID SimUUID, string sim_ip, uint sim_port) | ||
75 | { | ||
76 | Hashtable GridParams = new Hashtable(); | ||
77 | GridParams["authkey"] = GridSendKey; | ||
78 | GridParams["UUID"] = SimUUID.ToString(); | ||
79 | GridParams["sim_ip"] = sim_ip; | ||
80 | GridParams["sim_port"] = sim_port.ToString(); | ||
81 | ArrayList SendParams = new ArrayList(); | ||
82 | SendParams.Add(GridParams); | ||
83 | |||
84 | XmlRpcRequest GridReq = new XmlRpcRequest("simulator_login", SendParams); | ||
85 | XmlRpcResponse GridResp = GridReq.Send(this.GridServerUrl, 3000); | ||
86 | Hashtable GridRespData = (Hashtable)GridResp.Value; | ||
87 | this.griddatahash = GridRespData; | ||
88 | |||
89 | if (GridRespData.ContainsKey("error")) | ||
90 | { | ||
91 | string errorstring = (string)GridRespData["error"]; | ||
92 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "Error connecting to grid:"); | ||
93 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, errorstring); | ||
94 | return false; | ||
95 | } | ||
96 | this.neighbours = (ArrayList)GridRespData["neighbours"]; | ||
97 | Console.WriteLine(simneighbours.Count); | ||
98 | return true; | ||
99 | } | ||
100 | |||
101 | public override AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitcode) | ||
102 | { | ||
103 | AgentCircuitData validcircuit = null; | ||
104 | if (this.AgentCircuits.ContainsKey(circuitcode)) | ||
105 | { | ||
106 | validcircuit = this.AgentCircuits[circuitcode]; | ||
107 | } | ||
108 | AuthenticateResponse user = new AuthenticateResponse(); | ||
109 | if (validcircuit == null) | ||
110 | { | ||
111 | //don't have this circuit code in our list | ||
112 | user.Authorised = false; | ||
113 | return (user); | ||
114 | } | ||
115 | |||
116 | if ((sessionID == validcircuit.SessionID) && (agentID == validcircuit.AgentID)) | ||
117 | { | ||
118 | // YAY! Valid login | ||
119 | user.Authorised = true; | ||
120 | user.LoginInfo = new Login(); | ||
121 | user.LoginInfo.Agent = agentID; | ||
122 | user.LoginInfo.Session = sessionID; | ||
123 | user.LoginInfo.SecureSession = validcircuit.SecureSessionID; | ||
124 | user.LoginInfo.First = validcircuit.firstname; | ||
125 | user.LoginInfo.Last = validcircuit.lastname; | ||
126 | } | ||
127 | else | ||
128 | { | ||
129 | // Invalid | ||
130 | user.Authorised = false; | ||
131 | } | ||
132 | |||
133 | return (user); | ||
134 | } | ||
135 | |||
136 | public override bool LogoutSession(LLUUID sessionID, LLUUID agentID, uint circuitCode) | ||
137 | { | ||
138 | WebRequest DeleteSession = WebRequest.Create(GridServerUrl + "/usersessions/" + sessionID.ToString()); | ||
139 | DeleteSession.Method = "DELETE"; | ||
140 | DeleteSession.ContentType = "text/plaintext"; | ||
141 | DeleteSession.ContentLength = 0; | ||
142 | |||
143 | StreamWriter stOut = new StreamWriter(DeleteSession.GetRequestStream(), System.Text.Encoding.ASCII); | ||
144 | stOut.Write(""); | ||
145 | stOut.Close(); | ||
146 | |||
147 | StreamReader stIn = new StreamReader(DeleteSession.GetResponse().GetResponseStream()); | ||
148 | string GridResponse = stIn.ReadToEnd(); | ||
149 | stIn.Close(); | ||
150 | return (true); | ||
151 | } | ||
152 | |||
153 | public override UUIDBlock RequestUUIDBlock() | ||
154 | { | ||
155 | UUIDBlock uuidBlock = new UUIDBlock(); | ||
156 | return (uuidBlock); | ||
157 | } | ||
158 | |||
159 | public override NeighbourInfo[] RequestNeighbours() | ||
160 | { | ||
161 | return null; | ||
162 | } | ||
163 | |||
164 | public override IList RequestMapBlocks(int minX, int minY, int maxX, int maxY) | ||
165 | { | ||
166 | Hashtable param = new Hashtable(); | ||
167 | param["xmin"] = minX; | ||
168 | param["ymin"] = minY; | ||
169 | param["xmax"] = maxX; | ||
170 | param["ymax"] = maxY; | ||
171 | IList parameters = new ArrayList(); | ||
172 | parameters.Add(param); | ||
173 | XmlRpcRequest req = new XmlRpcRequest("map_block", parameters); | ||
174 | XmlRpcResponse resp = req.Send(GridServerUrl, 3000); | ||
175 | Hashtable respData = (Hashtable)resp.Value; | ||
176 | return (IList)respData["sim-profiles"]; | ||
177 | } | ||
178 | |||
179 | public override void SetServerInfo(string ServerUrl, string SendKey, string RecvKey) | ||
180 | { | ||
181 | this.GridServerUrl = ServerUrl; | ||
182 | this.GridSendKey = SendKey; | ||
183 | this.GridRecvKey = RecvKey; | ||
184 | } | ||
185 | |||
186 | public override string GetName() | ||
187 | { | ||
188 | return "Remote"; | ||
189 | } | ||
190 | |||
191 | public override void Close() | ||
192 | { | ||
193 | |||
194 | } | ||
195 | } | ||
196 | |||
197 | public class RemoteGridPlugin : IGridPlugin | ||
198 | { | ||
199 | public RemoteGridPlugin() | ||
200 | { | ||
201 | |||
202 | } | ||
203 | |||
204 | public IGridServer GetGridServer() | ||
205 | { | ||
206 | return (new RemoteGridServer()); | ||
207 | } | ||
208 | } | ||
209 | |||
210 | } | ||