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