aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Grid
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Connectors/Grid')
-rw-r--r--OpenSim/Services/Connectors/Grid/GridServiceConnector.cs300
-rw-r--r--OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs152
2 files changed, 353 insertions, 99 deletions
diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs
index ae7db7e..748892a 100644
--- a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs
@@ -35,6 +35,7 @@ using OpenSim.Framework;
35using OpenSim.Framework.Communications; 35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Servers.HttpServer; 36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Services.Interfaces; 37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
38using OpenSim.Server.Base; 39using OpenSim.Server.Base;
39using OpenMetaverse; 40using OpenMetaverse;
40 41
@@ -85,7 +86,7 @@ namespace OpenSim.Services.Connectors
85 86
86 #region IGridService 87 #region IGridService
87 88
88 public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo) 89 public virtual bool RegisterRegion(UUID scopeID, GridRegion regionInfo)
89 { 90 {
90 Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs(); 91 Dictionary<string, object> rinfo = regionInfo.ToKeyValuePairs();
91 Dictionary<string, string> sendData = new Dictionary<string,string>(); 92 Dictionary<string, string> sendData = new Dictionary<string,string>();
@@ -96,19 +97,32 @@ namespace OpenSim.Services.Connectors
96 97
97 sendData["METHOD"] = "register"; 98 sendData["METHOD"] = "register";
98 99
99 string reply = SynchronousRestFormsRequester.MakeRequest("POST", 100 string reqString = ServerUtils.BuildQueryString(sendData);
100 m_ServerURI + "/grid", 101 //m_log.DebugFormat("[GRID CONNECTOR]: queryString = {0}", reqString);
101 ServerUtils.BuildQueryString(sendData)); 102 try
102 103 {
103 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); 104 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
105 m_ServerURI + "/grid",
106 reqString);
107 if (reply != string.Empty)
108 {
109 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
104 110
105 if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success")) 111 if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success"))
106 return true; 112 return true;
113 }
114 else
115 m_log.DebugFormat("[GRID CONNECTOR]: RegisterRegion received null reply");
116 }
117 catch (Exception e)
118 {
119 m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message);
120 }
107 121
108 return false; 122 return false;
109 } 123 }
110 124
111 public bool DeregisterRegion(UUID regionID) 125 public virtual bool DeregisterRegion(UUID regionID)
112 { 126 {
113 Dictionary<string, string> sendData = new Dictionary<string, string>(); 127 Dictionary<string, string> sendData = new Dictionary<string, string>();
114 128
@@ -116,19 +130,31 @@ namespace OpenSim.Services.Connectors
116 130
117 sendData["METHOD"] = "deregister"; 131 sendData["METHOD"] = "deregister";
118 132
119 string reply = SynchronousRestFormsRequester.MakeRequest("POST", 133 try
120 m_ServerURI + "/grid", 134 {
121 ServerUtils.BuildQueryString(sendData)); 135 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
136 m_ServerURI + "/grid",
137 ServerUtils.BuildQueryString(sendData));
122 138
123 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); 139 if (reply != string.Empty)
140 {
141 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
124 142
125 if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success")) 143 if ((replyData["Result"] != null) && (replyData["Result"].ToString().ToLower() == "success"))
126 return true; 144 return true;
145 }
146 else
147 m_log.DebugFormat("[GRID CONNECTOR]: DeregisterRegion received null reply");
148 }
149 catch (Exception e)
150 {
151 m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message);
152 }
127 153
128 return false; 154 return false;
129 } 155 }
130 156
131 public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID) 157 public virtual List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
132 { 158 {
133 Dictionary<string, string> sendData = new Dictionary<string, string>(); 159 Dictionary<string, string> sendData = new Dictionary<string, string>();
134 160
@@ -137,26 +163,38 @@ namespace OpenSim.Services.Connectors
137 163
138 sendData["METHOD"] = "get_neighbours"; 164 sendData["METHOD"] = "get_neighbours";
139 165
140 string reply = SynchronousRestFormsRequester.MakeRequest("POST", 166 List<GridRegion> rinfos = new List<GridRegion>();
141 m_ServerURI + "/grid", 167
142 ServerUtils.BuildQueryString(sendData)); 168 string reqString = ServerUtils.BuildQueryString(sendData);
169 string reply = string.Empty;
170 try
171 {
172 reply = SynchronousRestFormsRequester.MakeRequest("POST",
173 m_ServerURI + "/grid",
174 reqString);
175 }
176 catch (Exception e)
177 {
178 m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message);
179 return rinfos;
180 }
143 181
144 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); 182 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
145 183
146 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
147 if (replyData != null) 184 if (replyData != null)
148 { 185 {
149 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; 186 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
187 //m_log.DebugFormat("[GRID CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count);
150 foreach (object r in rinfosList) 188 foreach (object r in rinfosList)
151 { 189 {
152 if (r is Dictionary<string, object>) 190 if (r is Dictionary<string, object>)
153 { 191 {
154 SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r); 192 GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
155 rinfos.Add(rinfo); 193 rinfos.Add(rinfo);
156 } 194 }
157 else 195 else
158 m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received invalid response", 196 m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received invalid response type {2}",
159 scopeID, regionID); 197 scopeID, regionID, r.GetType());
160 } 198 }
161 } 199 }
162 else 200 else
@@ -166,7 +204,7 @@ namespace OpenSim.Services.Connectors
166 return rinfos; 204 return rinfos;
167 } 205 }
168 206
169 public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) 207 public virtual GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
170 { 208 {
171 Dictionary<string, string> sendData = new Dictionary<string, string>(); 209 Dictionary<string, string> sendData = new Dictionary<string, string>();
172 210
@@ -175,29 +213,44 @@ namespace OpenSim.Services.Connectors
175 213
176 sendData["METHOD"] = "get_region_by_uuid"; 214 sendData["METHOD"] = "get_region_by_uuid";
177 215
178 string reply = SynchronousRestFormsRequester.MakeRequest("POST", 216 string reply = string.Empty;
179 m_ServerURI + "/grid", 217 try
180 ServerUtils.BuildQueryString(sendData)); 218 {
219 reply = SynchronousRestFormsRequester.MakeRequest("POST",
220 m_ServerURI + "/grid",
221 ServerUtils.BuildQueryString(sendData));
222 }
223 catch (Exception e)
224 {
225 m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message);
226 return null;
227 }
181 228
182 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); 229 GridRegion rinfo = null;
183 230
184 SimpleRegionInfo rinfo = null; 231 if (reply != string.Empty)
185 if ((replyData != null) && (replyData["result"] != null))
186 { 232 {
187 if (replyData["result"] is Dictionary<string, object>) 233 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
188 rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]); 234
235 if ((replyData != null) && (replyData["result"] != null))
236 {
237 if (replyData["result"] is Dictionary<string, object>)
238 rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
239 //else
240 // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response",
241 // scopeID, regionID);
242 }
189 else 243 else
190 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received invalid response", 244 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response",
191 scopeID, regionID); 245 scopeID, regionID);
192 } 246 }
193 else 247 else
194 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID {0}, {1} received null response", 248 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByUUID received null reply");
195 scopeID, regionID);
196 249
197 return rinfo; 250 return rinfo;
198 } 251 }
199 252
200 public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) 253 public virtual GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
201 { 254 {
202 Dictionary<string, string> sendData = new Dictionary<string, string>(); 255 Dictionary<string, string> sendData = new Dictionary<string, string>();
203 256
@@ -206,30 +259,43 @@ namespace OpenSim.Services.Connectors
206 sendData["Y"] = y.ToString(); 259 sendData["Y"] = y.ToString();
207 260
208 sendData["METHOD"] = "get_region_by_position"; 261 sendData["METHOD"] = "get_region_by_position";
262 string reply = string.Empty;
263 try
264 {
265 reply = SynchronousRestFormsRequester.MakeRequest("POST",
266 m_ServerURI + "/grid",
267 ServerUtils.BuildQueryString(sendData));
268 }
269 catch (Exception e)
270 {
271 m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message);
272 return null;
273 }
209 274
210 string reply = SynchronousRestFormsRequester.MakeRequest("POST", 275 GridRegion rinfo = null;
211 m_ServerURI + "/grid", 276 if (reply != string.Empty)
212 ServerUtils.BuildQueryString(sendData));
213
214 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
215
216 SimpleRegionInfo rinfo = null;
217 if ((replyData != null) && (replyData["result"] != null))
218 { 277 {
219 if (replyData["result"] is Dictionary<string, object>) 278 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
220 rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]); 279
280 if ((replyData != null) && (replyData["result"] != null))
281 {
282 if (replyData["result"] is Dictionary<string, object>)
283 rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
284 else
285 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received invalid response",
286 scopeID, x, y);
287 }
221 else 288 else
222 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received invalid response", 289 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received null response",
223 scopeID, x, y); 290 scopeID, x, y);
224 } 291 }
225 else 292 else
226 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1}-{2} received null response", 293 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition received null reply");
227 scopeID, x, y);
228 294
229 return rinfo; 295 return rinfo;
230 } 296 }
231 297
232 public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) 298 public virtual GridRegion GetRegionByName(UUID scopeID, string regionName)
233 { 299 {
234 Dictionary<string, string> sendData = new Dictionary<string, string>(); 300 Dictionary<string, string> sendData = new Dictionary<string, string>();
235 301
@@ -237,30 +303,40 @@ namespace OpenSim.Services.Connectors
237 sendData["NAME"] = regionName; 303 sendData["NAME"] = regionName;
238 304
239 sendData["METHOD"] = "get_region_by_name"; 305 sendData["METHOD"] = "get_region_by_name";
306 string reply = string.Empty;
307 try
308 {
309 reply = SynchronousRestFormsRequester.MakeRequest("POST",
310 m_ServerURI + "/grid",
311 ServerUtils.BuildQueryString(sendData));
312 }
313 catch (Exception e)
314 {
315 m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message);
316 return null;
317 }
240 318
241 string reply = SynchronousRestFormsRequester.MakeRequest("POST", 319 GridRegion rinfo = null;
242 m_ServerURI + "/grid", 320 if (reply != string.Empty)
243 ServerUtils.BuildQueryString(sendData));
244
245 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
246
247 SimpleRegionInfo rinfo = null;
248 if ((replyData != null) && (replyData["result"] != null))
249 { 321 {
250 if (replyData["result"] is Dictionary<string, object>) 322 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
251 rinfo = new SimpleRegionInfo((Dictionary<string, object>)replyData["result"]); 323
324 if ((replyData != null) && (replyData["result"] != null))
325 {
326 if (replyData["result"] is Dictionary<string, object>)
327 rinfo = new GridRegion((Dictionary<string, object>)replyData["result"]);
328 }
252 else 329 else
253 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received invalid response", 330 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received null response",
254 scopeID, regionName); 331 scopeID, regionName);
255 } 332 }
256 else 333 else
257 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByPosition {0}, {1} received null response", 334 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionByName received null reply");
258 scopeID, regionName);
259 335
260 return rinfo; 336 return rinfo;
261 } 337 }
262 338
263 public List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber) 339 public virtual List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
264 { 340 {
265 Dictionary<string, string> sendData = new Dictionary<string, string>(); 341 Dictionary<string, string> sendData = new Dictionary<string, string>();
266 342
@@ -269,37 +345,50 @@ namespace OpenSim.Services.Connectors
269 sendData["MAX"] = maxNumber.ToString(); 345 sendData["MAX"] = maxNumber.ToString();
270 346
271 sendData["METHOD"] = "get_regions_by_name"; 347 sendData["METHOD"] = "get_regions_by_name";
348 List<GridRegion> rinfos = new List<GridRegion>();
349 string reply = string.Empty;
350 try
351 {
352 reply = SynchronousRestFormsRequester.MakeRequest("POST",
353 m_ServerURI + "/grid",
354 ServerUtils.BuildQueryString(sendData));
355 }
356 catch (Exception e)
357 {
358 m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message);
359 return rinfos;
360 }
272 361
273 string reply = SynchronousRestFormsRequester.MakeRequest("POST", 362 if (reply != string.Empty)
274 m_ServerURI + "/grid",
275 ServerUtils.BuildQueryString(sendData));
276
277 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
278
279 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
280 if (replyData != null)
281 { 363 {
282 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; 364 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
283 foreach (object r in rinfosList) 365
366 if (replyData != null)
284 { 367 {
285 if (r is Dictionary<string, object>) 368 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
369 foreach (object r in rinfosList)
286 { 370 {
287 SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r); 371 if (r is Dictionary<string, object>)
288 rinfos.Add(rinfo); 372 {
373 GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
374 rinfos.Add(rinfo);
375 }
376 else
377 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received invalid response",
378 scopeID, name, maxNumber);
289 } 379 }
290 else
291 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received invalid response",
292 scopeID, name, maxNumber);
293 } 380 }
381 else
382 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received null response",
383 scopeID, name, maxNumber);
294 } 384 }
295 else 385 else
296 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName {0}, {1}, {2} received null response", 386 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionsByName received null reply");
297 scopeID, name, maxNumber);
298 387
299 return rinfos; 388 return rinfos;
300 } 389 }
301 390
302 public List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) 391 public virtual List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
303 { 392 {
304 Dictionary<string, string> sendData = new Dictionary<string, string>(); 393 Dictionary<string, string> sendData = new Dictionary<string, string>();
305 394
@@ -311,31 +400,44 @@ namespace OpenSim.Services.Connectors
311 400
312 sendData["METHOD"] = "get_region_range"; 401 sendData["METHOD"] = "get_region_range";
313 402
314 string reply = SynchronousRestFormsRequester.MakeRequest("POST", 403 List<GridRegion> rinfos = new List<GridRegion>();
315 m_ServerURI + "/grid", 404 string reply = string.Empty;
316 ServerUtils.BuildQueryString(sendData)); 405 try
406 {
407 reply = SynchronousRestFormsRequester.MakeRequest("POST",
408 m_ServerURI + "/grid",
409 ServerUtils.BuildQueryString(sendData));
317 410
318 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); 411 //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply);
412 }
413 catch (Exception e)
414 {
415 m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message);
416 return rinfos;
417 }
319 418
320 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); 419 if (reply != string.Empty)
321 if (replyData != null)
322 { 420 {
323 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; 421 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
324 foreach (object r in rinfosList) 422
423 if (replyData != null)
325 { 424 {
326 if (r is Dictionary<string, object>) 425 Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
426 foreach (object r in rinfosList)
327 { 427 {
328 SimpleRegionInfo rinfo = new SimpleRegionInfo((Dictionary<string, object>)r); 428 if (r is Dictionary<string, object>)
329 rinfos.Add(rinfo); 429 {
430 GridRegion rinfo = new GridRegion((Dictionary<string, object>)r);
431 rinfos.Add(rinfo);
432 }
330 } 433 }
331 else
332 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received invalid response",
333 scopeID, xmin, xmax, ymin, ymax);
334 } 434 }
435 else
436 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received null response",
437 scopeID, xmin, xmax, ymin, ymax);
335 } 438 }
336 else 439 else
337 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange {0}, {1}-{2} {3}-{4} received null response", 440 m_log.DebugFormat("[GRID CONNECTOR]: GetRegionRange received null reply");
338 scopeID, xmin, xmax, ymin, ymax);
339 441
340 return rinfos; 442 return rinfos;
341 } 443 }
diff --git a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs
new file mode 100644
index 0000000..b5e8743
--- /dev/null
+++ b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs
@@ -0,0 +1,152 @@
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.Text;
32using System.Drawing;
33using System.Net;
34using System.Reflection;
35using OpenSim.Services.Interfaces;
36using GridRegion = OpenSim.Services.Interfaces.GridRegion;
37
38using OpenSim.Framework;
39
40using OpenMetaverse;
41using OpenMetaverse.Imaging;
42using log4net;
43using Nwc.XmlRpc;
44
45namespace OpenSim.Services.Connectors.Grid
46{
47 public class HypergridServiceConnector
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IAssetService m_AssetService;
52
53 public HypergridServiceConnector(IAssetService assService)
54 {
55 m_AssetService = assService;
56 }
57
58 public UUID LinkRegion(GridRegion info, out ulong realHandle)
59 {
60 UUID uuid = UUID.Zero;
61 realHandle = 0;
62
63 Hashtable hash = new Hashtable();
64 hash["region_name"] = info.RegionName;
65
66 IList paramList = new ArrayList();
67 paramList.Add(hash);
68
69 XmlRpcRequest request = new XmlRpcRequest("linkk_region", paramList);
70 string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
71 m_log.Debug("[HGrid]: Linking to " + uri);
72 XmlRpcResponse response = request.Send(uri, 10000);
73 if (response.IsFault)
74 {
75 m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
76 }
77 else
78 {
79 hash = (Hashtable)response.Value;
80 //foreach (Object o in hash)
81 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
82 try
83 {
84 UUID.TryParse((string)hash["uuid"], out uuid);
85 info.RegionID = uuid;
86 if ((string)hash["handle"] != null)
87 {
88 realHandle = Convert.ToUInt64((string)hash["handle"]);
89 m_log.Debug(">> HERE, realHandle: " + realHandle);
90 }
91 //if (hash["region_image"] != null)
92 //{
93 // UUID img = UUID.Zero;
94 // UUID.TryParse((string)hash["region_image"], out img);
95 // info.RegionSettings.TerrainImageID = img;
96 //}
97 if (hash["region_name"] != null)
98 {
99 info.RegionName = (string)hash["region_name"];
100 //m_log.Debug(">> " + info.RegionName);
101 }
102 if (hash["internal_port"] != null)
103 {
104 int port = Convert.ToInt32((string)hash["internal_port"]);
105 info.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port);
106 //m_log.Debug(">> " + info.InternalEndPoint.ToString());
107 }
108
109 }
110 catch (Exception e)
111 {
112 m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace);
113 }
114 }
115 return uuid;
116 }
117
118 public void GetMapImage(GridRegion info)
119 {
120 try
121 {
122 string regionimage = "regionImage" + info.RegionID.ToString();
123 regionimage = regionimage.Replace("-", "");
124
125 WebClient c = new WebClient();
126 string uri = "http://" + info.ExternalHostName + ":" + info.HttpPort + "/index.php?method=" + regionimage;
127 //m_log.Debug("JPEG: " + uri);
128 c.DownloadFile(uri, info.RegionID.ToString() + ".jpg");
129 Bitmap m = new Bitmap(info.RegionID.ToString() + ".jpg");
130 //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width);
131 byte[] imageData = OpenJPEG.EncodeFromImage(m, true);
132 AssetBase ass = new AssetBase(UUID.Random(), "region " + info.RegionID.ToString());
133
134 // !!! for now
135 //info.RegionSettings.TerrainImageID = ass.FullID;
136
137 ass.Type = (int)AssetType.Texture;
138 ass.Temporary = true;
139 ass.Local = true;
140 ass.Data = imageData;
141
142 m_AssetService.Store(ass);
143
144 }
145 catch // LEGIT: Catching problems caused by OpenJPEG p/invoke
146 {
147 m_log.Warn("[HGrid]: Failed getting/storing map image, because it is probably already in the cache");
148 }
149 }
150
151 }
152}