aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Clients/GridClient.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications/Clients/GridClient.cs')
-rw-r--r--OpenSim/Framework/Communications/Clients/GridClient.cs392
1 files changed, 0 insertions, 392 deletions
diff --git a/OpenSim/Framework/Communications/Clients/GridClient.cs b/OpenSim/Framework/Communications/Clients/GridClient.cs
deleted file mode 100644
index 4836556..0000000
--- a/OpenSim/Framework/Communications/Clients/GridClient.cs
+++ /dev/null
@@ -1,392 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Net;
32using System.Reflection;
33
34using log4net;
35using OpenMetaverse;
36using Nwc.XmlRpc;
37
38namespace OpenSim.Framework.Communications.Clients
39{
40 public class GridClient
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
44 public bool RegisterRegion(
45 string gridServerURL, string sendKey, string receiveKey, RegionInfo regionInfo, out bool forcefulBanLines)
46 {
47 m_log.InfoFormat(
48 "[GRID CLIENT]: Registering region {0} with grid at {1}", regionInfo.RegionName, gridServerURL);
49
50 forcefulBanLines = true;
51
52 Hashtable GridParams = new Hashtable();
53 // Login / Authentication
54
55 GridParams["authkey"] = sendKey;
56 GridParams["recvkey"] = receiveKey;
57 GridParams["UUID"] = regionInfo.RegionID.ToString();
58 GridParams["sim_ip"] = regionInfo.ExternalHostName;
59 GridParams["sim_port"] = regionInfo.InternalEndPoint.Port.ToString();
60 GridParams["region_locx"] = regionInfo.RegionLocX.ToString();
61 GridParams["region_locy"] = regionInfo.RegionLocY.ToString();
62 GridParams["sim_name"] = regionInfo.RegionName;
63 GridParams["http_port"] = regionInfo.HttpPort.ToString();
64 GridParams["remoting_port"] = ConfigSettings.DefaultRegionRemotingPort.ToString();
65 GridParams["map-image-id"] = regionInfo.RegionSettings.TerrainImageID.ToString();
66 GridParams["originUUID"] = regionInfo.originRegionID.ToString();
67 GridParams["server_uri"] = regionInfo.ServerURI;
68 GridParams["region_secret"] = regionInfo.regionSecret;
69 GridParams["major_interface_version"] = VersionInfo.MajorInterfaceVersion.ToString();
70
71 if (regionInfo.MasterAvatarAssignedUUID != UUID.Zero)
72 GridParams["master_avatar_uuid"] = regionInfo.MasterAvatarAssignedUUID.ToString();
73 else
74 GridParams["master_avatar_uuid"] = regionInfo.EstateSettings.EstateOwner.ToString();
75
76 // Package into an XMLRPC Request
77 ArrayList SendParams = new ArrayList();
78 SendParams.Add(GridParams);
79
80 // Send Request
81 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_login", SendParams);
82 XmlRpcResponse GridResp;
83
84 try
85 {
86 // The timeout should always be significantly larger than the timeout for the grid server to request
87 // the initial status of the region before confirming registration.
88 GridResp = GridReq.Send(gridServerURL, 90000);
89 }
90 catch (Exception e)
91 {
92 Exception e2
93 = new Exception(
94 String.Format(
95 "Unable to register region with grid at {0}. Grid service not running?",
96 gridServerURL),
97 e);
98
99 throw e2;
100 }
101
102 Hashtable GridRespData = (Hashtable)GridResp.Value;
103 // Hashtable griddatahash = GridRespData;
104
105 // Process Response
106 if (GridRespData.ContainsKey("error"))
107 {
108 string errorstring = (string)GridRespData["error"];
109
110 Exception e = new Exception(
111 String.Format("Unable to connect to grid at {0}: {1}", gridServerURL, errorstring));
112
113 throw e;
114 }
115 else
116 {
117 // m_knownRegions = RequestNeighbours(regionInfo.RegionLocX, regionInfo.RegionLocY);
118 if (GridRespData.ContainsKey("allow_forceful_banlines"))
119 {
120 if ((string)GridRespData["allow_forceful_banlines"] != "TRUE")
121 {
122 forcefulBanLines = false;
123 }
124 }
125
126 }
127 return true;
128 }
129
130 public bool DeregisterRegion(string gridServerURL, string sendKey, string receiveKey, RegionInfo regionInfo, out string errorMsg)
131 {
132 errorMsg = "";
133 Hashtable GridParams = new Hashtable();
134
135 GridParams["UUID"] = regionInfo.RegionID.ToString();
136
137 // Package into an XMLRPC Request
138 ArrayList SendParams = new ArrayList();
139 SendParams.Add(GridParams);
140
141 // Send Request
142 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_after_region_moved", SendParams);
143 XmlRpcResponse GridResp = null;
144
145 try
146 {
147 GridResp = GridReq.Send(gridServerURL, 10000);
148 }
149 catch (Exception e)
150 {
151 Exception e2
152 = new Exception(
153 String.Format(
154 "Unable to deregister region with grid at {0}. Grid service not running?",
155 gridServerURL),
156 e);
157
158 throw e2;
159 }
160
161 Hashtable GridRespData = (Hashtable)GridResp.Value;
162
163 // Hashtable griddatahash = GridRespData;
164
165 // Process Response
166 if (GridRespData != null && GridRespData.ContainsKey("error"))
167 {
168 errorMsg = (string)GridRespData["error"];
169 return false;
170 }
171
172 return true;
173 }
174
175 public bool RequestNeighborInfo(
176 string gridServerURL, string sendKey, string receiveKey, UUID regionUUID,
177 out RegionInfo regionInfo, out string errorMsg)
178 {
179 // didn't find it so far, we have to go the long way
180 regionInfo = null;
181 errorMsg = string.Empty;
182 Hashtable requestData = new Hashtable();
183 requestData["region_UUID"] = regionUUID.ToString();
184 requestData["authkey"] = sendKey;
185 ArrayList SendParams = new ArrayList();
186 SendParams.Add(requestData);
187 XmlRpcRequest gridReq = new XmlRpcRequest("simulator_data_request", SendParams);
188 XmlRpcResponse gridResp = null;
189
190 try
191 {
192 gridResp = gridReq.Send(gridServerURL, 3000);
193 }
194 catch (Exception e)
195 {
196 errorMsg = e.Message;
197 return false;
198 }
199
200 Hashtable responseData = (Hashtable)gridResp.Value;
201
202 if (responseData.ContainsKey("error"))
203 {
204 errorMsg = (string)responseData["error"];
205 return false; ;
206 }
207
208 regionInfo = BuildRegionInfo(responseData, String.Empty);
209
210 return true;
211 }
212
213 public bool RequestNeighborInfo(
214 string gridServerURL, string sendKey, string receiveKey, ulong regionHandle,
215 out RegionInfo regionInfo, out string errorMsg)
216 {
217 // didn't find it so far, we have to go the long way
218 regionInfo = null;
219 errorMsg = string.Empty;
220
221 try
222 {
223 Hashtable requestData = new Hashtable();
224 requestData["region_handle"] = regionHandle.ToString();
225 requestData["authkey"] = sendKey;
226 ArrayList SendParams = new ArrayList();
227 SendParams.Add(requestData);
228 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
229 XmlRpcResponse GridResp = GridReq.Send(gridServerURL, 3000);
230
231 Hashtable responseData = (Hashtable)GridResp.Value;
232
233 if (responseData.ContainsKey("error"))
234 {
235 errorMsg = (string)responseData["error"];
236 return false;
237 }
238
239 uint regX = Convert.ToUInt32((string)responseData["region_locx"]);
240 uint regY = Convert.ToUInt32((string)responseData["region_locy"]);
241 string externalHostName = (string)responseData["sim_ip"];
242 uint simPort = Convert.ToUInt32(responseData["sim_port"]);
243 string regionName = (string)responseData["region_name"];
244 UUID regionID = new UUID((string)responseData["region_UUID"]);
245 uint remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]);
246
247 uint httpPort = 9000;
248 if (responseData.ContainsKey("http_port"))
249 {
250 httpPort = Convert.ToUInt32((string)responseData["http_port"]);
251 }
252
253 // Ok, so this is definitively the wrong place to do this, way too hard coded, but it doesn't seem we GET this info?
254
255 string simURI = "http://" + externalHostName + ":" + simPort;
256
257 // string externalUri = (string) responseData["sim_uri"];
258
259 //IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int) port);
260 regionInfo = RegionInfo.Create(regionID, regionName, regX, regY, externalHostName, httpPort, simPort, remotingPort, simURI);
261 }
262 catch (Exception e)
263 {
264 errorMsg = e.Message;
265 return false;
266 }
267
268 return true;
269 }
270
271 public bool RequestClosestRegion(
272 string gridServerURL, string sendKey, string receiveKey, string regionName,
273 out RegionInfo regionInfo, out string errorMsg)
274 {
275 regionInfo = null;
276 errorMsg = string.Empty;
277 try
278 {
279 Hashtable requestData = new Hashtable();
280 requestData["region_name_search"] = regionName;
281 requestData["authkey"] = sendKey;
282 ArrayList SendParams = new ArrayList();
283 SendParams.Add(requestData);
284 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
285 XmlRpcResponse GridResp = GridReq.Send(gridServerURL, 3000);
286
287 Hashtable responseData = (Hashtable)GridResp.Value;
288
289 if (responseData.ContainsKey("error"))
290 {
291 errorMsg = (string)responseData["error"];
292 return false;
293 }
294
295 regionInfo = BuildRegionInfo(responseData, "");
296
297 }
298 catch (Exception e)
299 {
300 errorMsg = e.Message;
301 return false;
302 }
303 return true;
304 }
305
306 /// <summary>
307 /// Performs a XML-RPC query against the grid server returning mapblock information in the specified coordinates
308 /// </summary>
309 /// <remarks>REDUNDANT - OGS1 is to be phased out in favour of OGS2</remarks>
310 /// <param name="minX">Minimum X value</param>
311 /// <param name="minY">Minimum Y value</param>
312 /// <param name="maxX">Maximum X value</param>
313 /// <param name="maxY">Maximum Y value</param>
314 /// <returns>Hashtable of hashtables containing map data elements</returns>
315 public bool MapBlockQuery(
316 string gridServerURL, int minX, int minY, int maxX, int maxY, out Hashtable respData, out string errorMsg)
317 {
318 respData = new Hashtable();
319 errorMsg = string.Empty;
320
321 Hashtable param = new Hashtable();
322 param["xmin"] = minX;
323 param["ymin"] = minY;
324 param["xmax"] = maxX;
325 param["ymax"] = maxY;
326 IList parameters = new ArrayList();
327 parameters.Add(param);
328
329 try
330 {
331 XmlRpcRequest req = new XmlRpcRequest("map_block", parameters);
332 XmlRpcResponse resp = req.Send(gridServerURL, 10000);
333 respData = (Hashtable)resp.Value;
334 return true;
335 }
336 catch (Exception e)
337 {
338 errorMsg = e.Message;
339 return false;
340 }
341 }
342
343 public bool SearchRegionByName(string gridServerURL, IList parameters, out Hashtable respData, out string errorMsg)
344 {
345 respData = null;
346 errorMsg = string.Empty;
347 try
348 {
349 XmlRpcRequest request = new XmlRpcRequest("search_for_region_by_name", parameters);
350 XmlRpcResponse resp = request.Send(gridServerURL, 10000);
351 respData = (Hashtable)resp.Value;
352 if (respData != null && respData.Contains("faultCode"))
353 {
354 errorMsg = (string)respData["faultString"];
355 return false;
356 }
357
358 return true;
359 }
360 catch (Exception e)
361 {
362 errorMsg = e.Message;
363 return false;
364 }
365 }
366
367 public RegionInfo BuildRegionInfo(Hashtable responseData, string prefix)
368 {
369 uint regX = Convert.ToUInt32((string)responseData[prefix + "region_locx"]);
370 uint regY = Convert.ToUInt32((string)responseData[prefix + "region_locy"]);
371 string internalIpStr = (string)responseData[prefix + "sim_ip"];
372 uint port = Convert.ToUInt32(responseData[prefix + "sim_port"]);
373
374 IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(internalIpStr), (int)port);
375
376 RegionInfo regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, internalIpStr);
377 regionInfo.RemotingPort = Convert.ToUInt32((string)responseData[prefix + "remoting_port"]);
378 regionInfo.RemotingAddress = internalIpStr;
379
380 if (responseData.ContainsKey(prefix + "http_port"))
381 {
382 regionInfo.HttpPort = Convert.ToUInt32((string)responseData[prefix + "http_port"]);
383 }
384
385 regionInfo.RegionID = new UUID((string)responseData[prefix + "region_UUID"]);
386 regionInfo.RegionName = (string)responseData[prefix + "region_name"];
387
388 regionInfo.RegionSettings.TerrainImageID = new UUID((string)responseData[prefix + "map_UUID"]);
389 return regionInfo;
390 }
391 }
392}