aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Communications/Clients/GridClient.cs378
1 files changed, 378 insertions, 0 deletions
diff --git a/OpenSim/Framework/Communications/Clients/GridClient.cs b/OpenSim/Framework/Communications/Clients/GridClient.cs
new file mode 100644
index 0000000..48083b7
--- /dev/null
+++ b/OpenSim/Framework/Communications/Clients/GridClient.cs
@@ -0,0 +1,378 @@
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 OpenSim 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;
32
33using OpenMetaverse;
34using Nwc.XmlRpc;
35
36namespace OpenSim.Framework.Communications.Clients
37{
38 public class GridClient
39 {
40
41 public bool RegisterRegion(string gridServerURL, string sendKey, string receiveKey, RegionInfo regionInfo, out bool forcefulBanLines)
42 {
43 forcefulBanLines = true;
44
45 Hashtable GridParams = new Hashtable();
46 // Login / Authentication
47
48 GridParams["authkey"] = sendKey;
49 GridParams["recvkey"] = receiveKey;
50 GridParams["UUID"] = regionInfo.RegionID.ToString();
51 GridParams["sim_ip"] = regionInfo.ExternalHostName;
52 GridParams["sim_port"] = regionInfo.InternalEndPoint.Port.ToString();
53 GridParams["region_locx"] = regionInfo.RegionLocX.ToString();
54 GridParams["region_locy"] = regionInfo.RegionLocY.ToString();
55 GridParams["sim_name"] = regionInfo.RegionName;
56 GridParams["http_port"] = regionInfo.HttpPort.ToString();
57 GridParams["remoting_port"] = ConfigSettings.DefaultRegionRemotingPort.ToString();
58 GridParams["map-image-id"] = regionInfo.RegionSettings.TerrainImageID.ToString();
59 GridParams["originUUID"] = regionInfo.originRegionID.ToString();
60 GridParams["server_uri"] = regionInfo.ServerURI;
61 GridParams["region_secret"] = regionInfo.regionSecret;
62 GridParams["major_interface_version"] = VersionInfo.MajorInterfaceVersion.ToString();
63
64 if (regionInfo.MasterAvatarAssignedUUID != UUID.Zero)
65 GridParams["master_avatar_uuid"] = regionInfo.MasterAvatarAssignedUUID.ToString();
66 else
67 GridParams["master_avatar_uuid"] = regionInfo.EstateSettings.EstateOwner.ToString();
68
69 // Package into an XMLRPC Request
70 ArrayList SendParams = new ArrayList();
71 SendParams.Add(GridParams);
72
73 // Send Request
74 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_login", SendParams);
75 XmlRpcResponse GridResp;
76
77 try
78 {
79 // The timeout should always be significantly larger than the timeout for the grid server to request
80 // the initial status of the region before confirming registration.
81 GridResp = GridReq.Send(gridServerURL, 90000);
82 }
83 catch (Exception e)
84 {
85 Exception e2
86 = new Exception(
87 String.Format(
88 "Unable to register region with grid at {0}. Grid service not running?",
89 gridServerURL),
90 e);
91
92 throw e2;
93 }
94
95 Hashtable GridRespData = (Hashtable)GridResp.Value;
96 // Hashtable griddatahash = GridRespData;
97
98 // Process Response
99 if (GridRespData.ContainsKey("error"))
100 {
101 string errorstring = (string)GridRespData["error"];
102
103 Exception e = new Exception(
104 String.Format("Unable to connect to grid at {0}: {1}", gridServerURL, errorstring));
105
106 throw e;
107 }
108 else
109 {
110 // m_knownRegions = RequestNeighbours(regionInfo.RegionLocX, regionInfo.RegionLocY);
111 if (GridRespData.ContainsKey("allow_forceful_banlines"))
112 {
113 if ((string)GridRespData["allow_forceful_banlines"] != "TRUE")
114 {
115 forcefulBanLines = false;
116 }
117 }
118
119 }
120 return true;
121 }
122
123 public bool DeregisterRegion(string gridServerURL, string sendKey, string receiveKey, RegionInfo regionInfo, out string errorMsg)
124 {
125 errorMsg = "";
126 Hashtable GridParams = new Hashtable();
127
128 GridParams["UUID"] = regionInfo.RegionID.ToString();
129
130 // Package into an XMLRPC Request
131 ArrayList SendParams = new ArrayList();
132 SendParams.Add(GridParams);
133
134 // Send Request
135 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_after_region_moved", SendParams);
136 XmlRpcResponse GridResp = null;
137
138 try
139 {
140 GridResp = GridReq.Send(gridServerURL, 10000);
141 }
142 catch (Exception e)
143 {
144 Exception e2
145 = new Exception(
146 String.Format(
147 "Unable to deregister region with grid at {0}. Grid service not running?",
148 gridServerURL),
149 e);
150
151 throw e2;
152 }
153
154 Hashtable GridRespData = (Hashtable)GridResp.Value;
155
156 // Hashtable griddatahash = GridRespData;
157
158 // Process Response
159 if (GridRespData != null && GridRespData.ContainsKey("error"))
160 {
161 errorMsg = (string)GridRespData["error"];
162 return false;
163 }
164
165 return true;
166 }
167
168 public bool RequestNeighborInfo(string gridServerURL, string sendKey, string receiveKey, UUID regionUUID, out RegionInfo regionInfo, out string errorMsg)
169 {
170 // didn't find it so far, we have to go the long way
171 regionInfo = null;
172 errorMsg = string.Empty;
173 Hashtable requestData = new Hashtable();
174 requestData["region_UUID"] = regionUUID.ToString();
175 requestData["authkey"] = sendKey;
176 ArrayList SendParams = new ArrayList();
177 SendParams.Add(requestData);
178 XmlRpcRequest gridReq = new XmlRpcRequest("simulator_data_request", SendParams);
179 XmlRpcResponse gridResp = null;
180
181 try
182 {
183 gridResp = gridReq.Send(gridServerURL, 3000);
184 }
185 catch (Exception e)
186 {
187 errorMsg = e.Message;
188 return false;
189 }
190
191 Hashtable responseData = (Hashtable)gridResp.Value;
192
193 if (responseData.ContainsKey("error"))
194 {
195 errorMsg = (string)responseData["error"];
196 return false; ;
197 }
198
199 regionInfo = BuildRegionInfo(responseData, String.Empty);
200
201 return true;
202 }
203
204 public bool RequestNeighborInfo(string gridServerURL, string sendKey, string receiveKey, ulong regionHandle, out RegionInfo regionInfo, out string errorMsg)
205 {
206 // didn't find it so far, we have to go the long way
207 regionInfo = null;
208 errorMsg = string.Empty;
209
210 try
211 {
212 Hashtable requestData = new Hashtable();
213 requestData["region_handle"] = regionHandle.ToString();
214 requestData["authkey"] = sendKey;
215 ArrayList SendParams = new ArrayList();
216 SendParams.Add(requestData);
217 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
218 XmlRpcResponse GridResp = GridReq.Send(gridServerURL, 3000);
219
220 Hashtable responseData = (Hashtable)GridResp.Value;
221
222 if (responseData.ContainsKey("error"))
223 {
224 errorMsg = (string)responseData["error"];
225 return false;
226 }
227
228 uint regX = Convert.ToUInt32((string)responseData["region_locx"]);
229 uint regY = Convert.ToUInt32((string)responseData["region_locy"]);
230 string externalHostName = (string)responseData["sim_ip"];
231 uint simPort = Convert.ToUInt32(responseData["sim_port"]);
232 string regionName = (string)responseData["region_name"];
233 UUID regionID = new UUID((string)responseData["region_UUID"]);
234 uint remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]);
235
236 uint httpPort = 9000;
237 if (responseData.ContainsKey("http_port"))
238 {
239 httpPort = Convert.ToUInt32((string)responseData["http_port"]);
240 }
241
242 // Ok, so this is definitively the wrong place to do this, way too hard coded, but it doesn't seem we GET this info?
243
244 string simURI = "http://" + externalHostName + ":" + simPort;
245
246 // string externalUri = (string) responseData["sim_uri"];
247
248 //IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int) port);
249 regionInfo = RegionInfo.Create(regionID, regionName, regX, regY, externalHostName, httpPort, simPort, remotingPort, simURI);
250 }
251 catch (Exception e)
252 {
253 errorMsg = e.Message;
254 return false;
255 }
256
257 return true;
258 }
259
260 public bool RequestClosestRegion(string gridServerURL, string sendKey, string receiveKey, string regionName, out RegionInfo regionInfo, out string errorMsg)
261 {
262 regionInfo = null;
263 errorMsg = string.Empty;
264 try
265 {
266 Hashtable requestData = new Hashtable();
267 requestData["region_name_search"] = regionName;
268 requestData["authkey"] = sendKey;
269 ArrayList SendParams = new ArrayList();
270 SendParams.Add(requestData);
271 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
272 XmlRpcResponse GridResp = GridReq.Send(gridServerURL, 3000);
273
274 Hashtable responseData = (Hashtable)GridResp.Value;
275
276 if (responseData.ContainsKey("error"))
277 {
278 errorMsg = (string)responseData["error"];
279 return false;
280 }
281
282 regionInfo = BuildRegionInfo(responseData, "");
283
284 }
285 catch (Exception e)
286 {
287 errorMsg = e.Message;
288 return false;
289 }
290 return true;
291 }
292
293 /// <summary>
294 /// Performs a XML-RPC query against the grid server returning mapblock information in the specified coordinates
295 /// </summary>
296 /// <remarks>REDUNDANT - OGS1 is to be phased out in favour of OGS2</remarks>
297 /// <param name="minX">Minimum X value</param>
298 /// <param name="minY">Minimum Y value</param>
299 /// <param name="maxX">Maximum X value</param>
300 /// <param name="maxY">Maximum Y value</param>
301 /// <returns>Hashtable of hashtables containing map data elements</returns>
302 public bool MapBlockQuery(string gridServerURL, int minX, int minY, int maxX, int maxY, out Hashtable respData, out string errorMsg)
303 {
304 respData = new Hashtable();
305 errorMsg = string.Empty;
306
307 Hashtable param = new Hashtable();
308 param["xmin"] = minX;
309 param["ymin"] = minY;
310 param["xmax"] = maxX;
311 param["ymax"] = maxY;
312 IList parameters = new ArrayList();
313 parameters.Add(param);
314
315 try
316 {
317 XmlRpcRequest req = new XmlRpcRequest("map_block", parameters);
318 XmlRpcResponse resp = req.Send(gridServerURL, 10000);
319 respData = (Hashtable)resp.Value;
320 return true;
321 }
322 catch (Exception e)
323 {
324 errorMsg = e.Message;
325 return false;
326 }
327 }
328
329 public bool SearchRegionByName(string gridServerURL, IList parameters, out Hashtable respData, out string errorMsg)
330 {
331 respData = null;
332 errorMsg = string.Empty;
333 try
334 {
335 XmlRpcRequest request = new XmlRpcRequest("search_for_region_by_name", parameters);
336 XmlRpcResponse resp = request.Send(gridServerURL, 10000);
337 respData = (Hashtable)resp.Value;
338 if (respData != null && respData.Contains("faultCode"))
339 {
340 errorMsg = (string)respData["faultString"];
341 return false;
342 }
343
344 return true;
345 }
346 catch (Exception e)
347 {
348 errorMsg = e.Message;
349 return false;
350 }
351 }
352
353 public RegionInfo BuildRegionInfo(Hashtable responseData, string prefix)
354 {
355 uint regX = Convert.ToUInt32((string)responseData[prefix + "region_locx"]);
356 uint regY = Convert.ToUInt32((string)responseData[prefix + "region_locy"]);
357 string internalIpStr = (string)responseData[prefix + "sim_ip"];
358 uint port = Convert.ToUInt32(responseData[prefix + "sim_port"]);
359
360 IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(internalIpStr), (int)port);
361
362 RegionInfo regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, internalIpStr);
363 regionInfo.RemotingPort = Convert.ToUInt32((string)responseData[prefix + "remoting_port"]);
364 regionInfo.RemotingAddress = internalIpStr;
365
366 if (responseData.ContainsKey(prefix + "http_port"))
367 {
368 regionInfo.HttpPort = Convert.ToUInt32((string)responseData[prefix + "http_port"]);
369 }
370
371 regionInfo.RegionID = new UUID((string)responseData[prefix + "region_UUID"]);
372 regionInfo.RegionName = (string)responseData[prefix + "region_name"];
373
374 regionInfo.RegionSettings.TerrainImageID = new UUID((string)responseData[prefix + "map_UUID"]);
375 return regionInfo;
376 }
377 }
378}