diff options
Diffstat (limited to 'OpenSim/Region')
7 files changed, 1434 insertions, 274 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs index 2d81e4c..8b7a878 100644 --- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs | |||
@@ -54,12 +54,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
54 | { | 54 | { |
55 | public UUID requestID; | 55 | public UUID requestID; |
56 | public Dictionary<string, string> headers; | 56 | public Dictionary<string, string> headers; |
57 | public string body; | 57 | public string body; |
58 | public int responseCode; | 58 | public int responseCode; |
59 | public string responseBody; | 59 | public string responseBody; |
60 | public ManualResetEvent ev; | 60 | public ManualResetEvent ev; |
61 | public bool requestDone; | 61 | public bool requestDone; |
62 | public int startTime; | 62 | public int startTime; |
63 | public string uri; | 63 | public string uri; |
64 | } | 64 | } |
65 | 65 | ||
@@ -73,23 +73,23 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
73 | new Dictionary<UUID, UrlData>(); | 73 | new Dictionary<UUID, UrlData>(); |
74 | 74 | ||
75 | private Dictionary<string, UrlData> m_UrlMap = | 75 | private Dictionary<string, UrlData> m_UrlMap = |
76 | new Dictionary<string, UrlData>(); | 76 | new Dictionary<string, UrlData>(); |
77 | 77 | ||
78 | 78 | ||
79 | private int m_TotalUrls = 100; | 79 | private int m_TotalUrls = 100; |
80 | 80 | ||
81 | private IHttpServer m_HttpServer = null; | 81 | private IHttpServer m_HttpServer = null; |
82 | 82 | ||
83 | private string m_ExternalHostNameForLSL = ""; | 83 | private string m_ExternalHostNameForLSL = ""; |
84 | 84 | ||
85 | public Type ReplaceableInterface | 85 | public Type ReplaceableInterface |
86 | { | 86 | { |
87 | get { return null; } | 87 | get { return null; } |
88 | } | 88 | } |
89 | 89 | ||
90 | private Hashtable HandleHttpPoll(Hashtable request) | 90 | private Hashtable HandleHttpPoll(Hashtable request) |
91 | { | 91 | { |
92 | return new Hashtable(); | 92 | return new Hashtable(); |
93 | } | 93 | } |
94 | 94 | ||
95 | public string Name | 95 | public string Name |
@@ -98,7 +98,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
98 | } | 98 | } |
99 | 99 | ||
100 | public void Initialise(IConfigSource config) | 100 | public void Initialise(IConfigSource config) |
101 | { | 101 | { |
102 | m_ExternalHostNameForLSL = config.Configs["Network"].GetString("ExternalHostNameForLSL", System.Environment.MachineName); | 102 | m_ExternalHostNameForLSL = config.Configs["Network"].GetString("ExternalHostNameForLSL", System.Environment.MachineName); |
103 | } | 103 | } |
104 | 104 | ||
@@ -130,7 +130,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
130 | 130 | ||
131 | public void Close() | 131 | public void Close() |
132 | { | 132 | { |
133 | } | 133 | } |
134 | public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID) | 134 | public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID) |
135 | { | 135 | { |
136 | UUID urlcode = UUID.Random(); | 136 | UUID urlcode = UUID.Random(); |
@@ -141,8 +141,8 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
141 | { | 141 | { |
142 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); | 142 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); |
143 | return urlcode; | 143 | return urlcode; |
144 | } | 144 | } |
145 | string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/"; | 145 | string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/"; |
146 | 146 | ||
147 | UrlData urlData = new UrlData(); | 147 | UrlData urlData = new UrlData(); |
148 | urlData.hostID = host.UUID; | 148 | urlData.hostID = host.UUID; |
@@ -152,14 +152,14 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
152 | urlData.urlcode = urlcode; | 152 | urlData.urlcode = urlcode; |
153 | urlData.requests = new Dictionary<UUID, RequestData>(); | 153 | urlData.requests = new Dictionary<UUID, RequestData>(); |
154 | 154 | ||
155 | 155 | ||
156 | m_UrlMap[url] = urlData; | 156 | m_UrlMap[url] = urlData; |
157 | 157 | ||
158 | string uri = "/lslhttp/" + urlcode.ToString() + "/"; | 158 | string uri = "/lslhttp/" + urlcode.ToString() + "/"; |
159 | 159 | ||
160 | m_HttpServer.AddPollServiceHTTPHandler(uri,HandleHttpPoll, | 160 | m_HttpServer.AddPollServiceHTTPHandler(uri,HandleHttpPoll, |
161 | new PollServiceEventArgs(HttpRequestHandler,HasEvents, GetEvents, NoEvents, | 161 | new PollServiceEventArgs(HttpRequestHandler,HasEvents, GetEvents, NoEvents, |
162 | urlcode)); | 162 | urlcode)); |
163 | 163 | ||
164 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); | 164 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); |
165 | } | 165 | } |
@@ -180,11 +180,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
180 | { | 180 | { |
181 | lock (m_UrlMap) | 181 | lock (m_UrlMap) |
182 | { | 182 | { |
183 | UrlData data; | 183 | UrlData data; |
184 | 184 | ||
185 | if (!m_UrlMap.TryGetValue(url, out data)) | 185 | if (!m_UrlMap.TryGetValue(url, out data)) |
186 | { | 186 | { |
187 | return; | 187 | return; |
188 | } | 188 | } |
189 | 189 | ||
190 | foreach (UUID req in data.requests.Keys) | 190 | foreach (UUID req in data.requests.Keys) |
@@ -196,36 +196,36 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
196 | } | 196 | } |
197 | 197 | ||
198 | public void HttpResponse(UUID request, int status, string body) | 198 | public void HttpResponse(UUID request, int status, string body) |
199 | { | 199 | { |
200 | if (m_RequestMap.ContainsKey(request)) | 200 | if (m_RequestMap.ContainsKey(request)) |
201 | { | 201 | { |
202 | UrlData urlData = m_RequestMap[request]; | 202 | UrlData urlData = m_RequestMap[request]; |
203 | RequestData requestData=urlData.requests[request]; | 203 | RequestData requestData=urlData.requests[request]; |
204 | urlData.requests[request].responseCode = status; | 204 | urlData.requests[request].responseCode = status; |
205 | urlData.requests[request].responseBody = body; | 205 | urlData.requests[request].responseBody = body; |
206 | //urlData.requests[request].ev.Set(); | 206 | //urlData.requests[request].ev.Set(); |
207 | urlData.requests[request].requestDone=true; | 207 | urlData.requests[request].requestDone=true; |
208 | } | 208 | } |
209 | else | 209 | else |
210 | { | 210 | { |
211 | m_log.Info("[HttpRequestHandler] There is no http-in request with id " + request.ToString()); | 211 | m_log.Info("[HttpRequestHandler] There is no http-in request with id " + request.ToString()); |
212 | } | 212 | } |
213 | } | 213 | } |
214 | 214 | ||
215 | public string GetHttpHeader(UUID requestId, string header) | 215 | public string GetHttpHeader(UUID requestId, string header) |
216 | { | 216 | { |
217 | if (m_RequestMap.ContainsKey(requestId)) | 217 | if (m_RequestMap.ContainsKey(requestId)) |
218 | { | 218 | { |
219 | UrlData urlData=m_RequestMap[requestId]; | 219 | UrlData urlData=m_RequestMap[requestId]; |
220 | string value; | 220 | string value; |
221 | if (urlData.requests[requestId].headers.TryGetValue(header,out value)) | 221 | if (urlData.requests[requestId].headers.TryGetValue(header,out value)) |
222 | return value; | 222 | return value; |
223 | } | 223 | } |
224 | else | 224 | else |
225 | { | 225 | { |
226 | m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId); | 226 | m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId); |
227 | } | 227 | } |
228 | return String.Empty; | 228 | return String.Empty; |
229 | } | 229 | } |
230 | 230 | ||
231 | public int GetFreeUrls() | 231 | public int GetFreeUrls() |
@@ -275,63 +275,63 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
275 | foreach (string urlname in removeURLs) | 275 | foreach (string urlname in removeURLs) |
276 | m_UrlMap.Remove(urlname); | 276 | m_UrlMap.Remove(urlname); |
277 | } | 277 | } |
278 | } | 278 | } |
279 | 279 | ||
280 | 280 | ||
281 | private void RemoveUrl(UrlData data) | 281 | private void RemoveUrl(UrlData data) |
282 | { | 282 | { |
283 | m_HttpServer.RemoveHTTPHandler("", "/lslhttp/"+data.urlcode.ToString()+"/"); | 283 | m_HttpServer.RemoveHTTPHandler("", "/lslhttp/"+data.urlcode.ToString()+"/"); |
284 | } | 284 | } |
285 | 285 | ||
286 | private Hashtable NoEvents(UUID requestID, UUID sessionID) | 286 | private Hashtable NoEvents(UUID requestID, UUID sessionID) |
287 | { | 287 | { |
288 | Hashtable response = new Hashtable(); | 288 | Hashtable response = new Hashtable(); |
289 | UrlData url; | 289 | UrlData url; |
290 | lock (m_RequestMap) | 290 | lock (m_RequestMap) |
291 | { | 291 | { |
292 | if (!m_RequestMap.ContainsKey(requestID)) | 292 | if (!m_RequestMap.ContainsKey(requestID)) |
293 | return response; | 293 | return response; |
294 | url = m_RequestMap[requestID]; | 294 | url = m_RequestMap[requestID]; |
295 | } | 295 | } |
296 | 296 | ||
297 | if (System.Environment.TickCount - url.requests[requestID].startTime > 25000) | 297 | if (System.Environment.TickCount - url.requests[requestID].startTime > 25000) |
298 | { | 298 | { |
299 | response["int_response_code"] = 500; | 299 | response["int_response_code"] = 500; |
300 | response["str_response_string"] = "Script timeout"; | 300 | response["str_response_string"] = "Script timeout"; |
301 | response["content_type"] = "text/plain"; | 301 | response["content_type"] = "text/plain"; |
302 | response["keepalive"] = false; | 302 | response["keepalive"] = false; |
303 | response["reusecontext"] = false; | 303 | response["reusecontext"] = false; |
304 | 304 | ||
305 | //remove from map | 305 | //remove from map |
306 | lock (url) | 306 | lock (url) |
307 | { | 307 | { |
308 | url.requests.Remove(requestID); | 308 | url.requests.Remove(requestID); |
309 | m_RequestMap.Remove(requestID); | 309 | m_RequestMap.Remove(requestID); |
310 | } | 310 | } |
311 | 311 | ||
312 | return response; | 312 | return response; |
313 | } | 313 | } |
314 | 314 | ||
315 | 315 | ||
316 | return response; | 316 | return response; |
317 | } | 317 | } |
318 | 318 | ||
319 | private bool HasEvents(UUID requestID, UUID sessionID) | 319 | private bool HasEvents(UUID requestID, UUID sessionID) |
320 | { | 320 | { |
321 | UrlData url=null; | 321 | UrlData url=null; |
322 | 322 | ||
323 | lock (m_RequestMap) | 323 | lock (m_RequestMap) |
324 | { | 324 | { |
325 | if (!m_RequestMap.ContainsKey(requestID)) | 325 | if (!m_RequestMap.ContainsKey(requestID)) |
326 | { | 326 | { |
327 | return false; | 327 | return false; |
328 | } | ||
329 | url = m_RequestMap[requestID]; | ||
330 | if (!url.requests.ContainsKey(requestID)) | ||
331 | { | ||
332 | return false; | ||
333 | } | 328 | } |
334 | } | 329 | url = m_RequestMap[requestID]; |
330 | if (!url.requests.ContainsKey(requestID)) | ||
331 | { | ||
332 | return false; | ||
333 | } | ||
334 | } | ||
335 | 335 | ||
336 | if (System.Environment.TickCount-url.requests[requestID].startTime>25000) | 336 | if (System.Environment.TickCount-url.requests[requestID].startTime>25000) |
337 | { | 337 | { |
@@ -343,146 +343,146 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
343 | else | 343 | else |
344 | return false; | 344 | return false; |
345 | 345 | ||
346 | } | 346 | } |
347 | private Hashtable GetEvents(UUID requestID, UUID sessionID, string request) | 347 | private Hashtable GetEvents(UUID requestID, UUID sessionID, string request) |
348 | { | 348 | { |
349 | UrlData url = null; | 349 | UrlData url = null; |
350 | RequestData requestData = null; | 350 | RequestData requestData = null; |
351 | 351 | ||
352 | lock (m_RequestMap) | 352 | lock (m_RequestMap) |
353 | { | 353 | { |
354 | if (!m_RequestMap.ContainsKey(requestID)) | 354 | if (!m_RequestMap.ContainsKey(requestID)) |
355 | return NoEvents(requestID,sessionID); | 355 | return NoEvents(requestID,sessionID); |
356 | url = m_RequestMap[requestID]; | 356 | url = m_RequestMap[requestID]; |
357 | requestData = url.requests[requestID]; | 357 | requestData = url.requests[requestID]; |
358 | } | 358 | } |
359 | 359 | ||
360 | if (!requestData.requestDone) | 360 | if (!requestData.requestDone) |
361 | return NoEvents(requestID,sessionID); | 361 | return NoEvents(requestID,sessionID); |
362 | 362 | ||
363 | Hashtable response = new Hashtable(); | 363 | Hashtable response = new Hashtable(); |
364 | 364 | ||
365 | if (System.Environment.TickCount - requestData.startTime > 25000) | 365 | if (System.Environment.TickCount - requestData.startTime > 25000) |
366 | { | 366 | { |
367 | response["int_response_code"] = 500; | 367 | response["int_response_code"] = 500; |
368 | response["str_response_string"] = "Script timeout"; | 368 | response["str_response_string"] = "Script timeout"; |
369 | response["content_type"] = "text/plain"; | 369 | response["content_type"] = "text/plain"; |
370 | response["keepalive"] = false; | 370 | response["keepalive"] = false; |
371 | response["reusecontext"] = false; | 371 | response["reusecontext"] = false; |
372 | return response; | 372 | return response; |
373 | } | 373 | } |
374 | //put response | 374 | //put response |
375 | response["int_response_code"] = requestData.responseCode; | 375 | response["int_response_code"] = requestData.responseCode; |
376 | response["str_response_string"] = requestData.responseBody; | 376 | response["str_response_string"] = requestData.responseBody; |
377 | response["content_type"] = "text/plain"; | 377 | response["content_type"] = "text/plain"; |
378 | response["keepalive"] = false; | 378 | response["keepalive"] = false; |
379 | response["reusecontext"] = false; | 379 | response["reusecontext"] = false; |
380 | 380 | ||
381 | //remove from map | 381 | //remove from map |
382 | lock (url) | 382 | lock (url) |
383 | { | 383 | { |
384 | url.requests.Remove(requestID); | 384 | url.requests.Remove(requestID); |
385 | m_RequestMap.Remove(requestID); | 385 | m_RequestMap.Remove(requestID); |
386 | } | 386 | } |
387 | 387 | ||
388 | return response; | 388 | return response; |
389 | } | 389 | } |
390 | public void HttpRequestHandler(UUID requestID, Hashtable request) | 390 | public void HttpRequestHandler(UUID requestID, Hashtable request) |
391 | { | 391 | { |
392 | lock (request) | 392 | lock (request) |
393 | { | 393 | { |
394 | string uri = request["uri"].ToString(); | 394 | string uri = request["uri"].ToString(); |
395 | 395 | ||
396 | try | 396 | try |
397 | { | 397 | { |
398 | Hashtable headers = (Hashtable)request["headers"]; | 398 | Hashtable headers = (Hashtable)request["headers"]; |
399 | 399 | ||
400 | string uri_full = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/"; | 400 | string uri_full = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/"; |
401 | 401 | ||
402 | int pos1 = uri.IndexOf("/");// /lslhttp | 402 | int pos1 = uri.IndexOf("/");// /lslhttp |
403 | int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/ | 403 | int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/ |
404 | int pos3 = uri.IndexOf("/", pos2 + 1);// /lslhttp/<UUID>/ | 404 | int pos3 = uri.IndexOf("/", pos2 + 1);// /lslhttp/<UUID>/ |
405 | string uri_tmp = uri.Substring(0, pos3 + 1); | 405 | string uri_tmp = uri.Substring(0, pos3 + 1); |
406 | //HTTP server code doesn't provide us with QueryStrings | 406 | //HTTP server code doesn't provide us with QueryStrings |
407 | string pathInfo; | 407 | string pathInfo; |
408 | string queryString; | 408 | string queryString; |
409 | queryString = ""; | 409 | queryString = ""; |
410 | 410 | ||
411 | pathInfo = uri.Substring(pos3); | 411 | pathInfo = uri.Substring(pos3); |
412 | 412 | ||
413 | UrlData url = m_UrlMap["http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp]; | 413 | UrlData url = m_UrlMap["http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp]; |
414 | 414 | ||
415 | //for llGetHttpHeader support we need to store original URI here | 415 | //for llGetHttpHeader support we need to store original URI here |
416 | //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers | 416 | //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers |
417 | //as per http://wiki.secondlife.com/wiki/LlGetHTTPHeader | 417 | //as per http://wiki.secondlife.com/wiki/LlGetHTTPHeader |
418 | 418 | ||
419 | RequestData requestData = new RequestData(); | 419 | RequestData requestData = new RequestData(); |
420 | requestData.requestID = requestID; | 420 | requestData.requestID = requestID; |
421 | requestData.requestDone = false; | 421 | requestData.requestDone = false; |
422 | requestData.startTime = System.Environment.TickCount; | 422 | requestData.startTime = System.Environment.TickCount; |
423 | requestData.uri = uri; | 423 | requestData.uri = uri; |
424 | if (requestData.headers == null) | 424 | if (requestData.headers == null) |
425 | requestData.headers = new Dictionary<string, string>(); | 425 | requestData.headers = new Dictionary<string, string>(); |
426 | 426 | ||
427 | foreach (DictionaryEntry header in headers) | 427 | foreach (DictionaryEntry header in headers) |
428 | { | 428 | { |
429 | string key = (string)header.Key; | 429 | string key = (string)header.Key; |
430 | string value = (string)header.Value; | 430 | string value = (string)header.Value; |
431 | requestData.headers.Add(key, value); | 431 | requestData.headers.Add(key, value); |
432 | } | 432 | } |
433 | foreach (DictionaryEntry de in request) | 433 | foreach (DictionaryEntry de in request) |
434 | { | 434 | { |
435 | if (de.Key.ToString() == "querystringkeys") | 435 | if (de.Key.ToString() == "querystringkeys") |
436 | { | 436 | { |
437 | System.String[] keys = (System.String[])de.Value; | 437 | System.String[] keys = (System.String[])de.Value; |
438 | foreach (String key in keys) | 438 | foreach (String key in keys) |
439 | { | 439 | { |
440 | if (request.ContainsKey(key)) | 440 | if (request.ContainsKey(key)) |
441 | { | 441 | { |
442 | string val = (String)request[key]; | 442 | string val = (String)request[key]; |
443 | queryString = queryString + key + "=" + val + "&"; | 443 | queryString = queryString + key + "=" + val + "&"; |
444 | } | 444 | } |
445 | } | 445 | } |
446 | if (queryString.Length > 1) | 446 | if (queryString.Length > 1) |
447 | queryString = queryString.Substring(0, queryString.Length - 1); | 447 | queryString = queryString.Substring(0, queryString.Length - 1); |
448 | 448 | ||
449 | } | 449 | } |
450 | 450 | ||
451 | } | 451 | } |
452 | 452 | ||
453 | //if this machine is behind DNAT/port forwarding, currently this is being | 453 | //if this machine is behind DNAT/port forwarding, currently this is being |
454 | //set to address of port forwarding router | 454 | //set to address of port forwarding router |
455 | requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"]; | 455 | requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"]; |
456 | requestData.headers["x-path-info"] = pathInfo; | 456 | requestData.headers["x-path-info"] = pathInfo; |
457 | requestData.headers["x-query-string"] = queryString; | 457 | requestData.headers["x-query-string"] = queryString; |
458 | requestData.headers["x-script-url"] = url.url; | 458 | requestData.headers["x-script-url"] = url.url; |
459 | 459 | ||
460 | requestData.ev = new ManualResetEvent(false); | 460 | requestData.ev = new ManualResetEvent(false); |
461 | lock (url.requests) | 461 | lock (url.requests) |
462 | { | 462 | { |
463 | url.requests.Add(requestID, requestData); | 463 | url.requests.Add(requestID, requestData); |
464 | } | 464 | } |
465 | lock (m_RequestMap) | 465 | lock (m_RequestMap) |
466 | { | 466 | { |
467 | //add to request map | 467 | //add to request map |
468 | m_RequestMap.Add(requestID, url); | 468 | m_RequestMap.Add(requestID, url); |
469 | } | 469 | } |
470 | 470 | ||
471 | url.engine.PostScriptEvent(url.itemID, "http_request", new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() }); | 471 | url.engine.PostScriptEvent(url.itemID, "http_request", new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() }); |
472 | 472 | ||
473 | //send initial response? | 473 | //send initial response? |
474 | Hashtable response = new Hashtable(); | 474 | Hashtable response = new Hashtable(); |
475 | 475 | ||
476 | return; | 476 | return; |
477 | 477 | ||
478 | } | 478 | } |
479 | catch (Exception we) | 479 | catch (Exception we) |
480 | { | 480 | { |
481 | //Hashtable response = new Hashtable(); | 481 | //Hashtable response = new Hashtable(); |
482 | m_log.Warn("[HttpRequestHandler]: http-in request failed"); | 482 | m_log.Warn("[HttpRequestHandler]: http-in request failed"); |
483 | m_log.Warn(we.Message); | 483 | m_log.Warn(we.Message); |
484 | m_log.Warn(we.StackTrace); | 484 | m_log.Warn(we.StackTrace); |
485 | } | 485 | } |
486 | } | 486 | } |
487 | } | 487 | } |
488 | 488 | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs new file mode 100644 index 0000000..8d113d3 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs | |||
@@ -0,0 +1,129 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using System.Collections.Generic; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Servers.HttpServer; | ||
35 | using OpenSim.Region.Framework.Scenes; | ||
36 | using OpenSim.Region.Framework.Interfaces; | ||
37 | using OpenSim.Server.Base; | ||
38 | using OpenSim.Server.Handlers.Base; | ||
39 | using OpenSim.Server.Handlers.Grid; | ||
40 | |||
41 | namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid | ||
42 | { | ||
43 | public class HypergridServiceInConnectorModule : ISharedRegionModule | ||
44 | { | ||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | private static bool m_Enabled = false; | ||
47 | |||
48 | private IConfigSource m_Config; | ||
49 | bool m_Registered = false; | ||
50 | HypergridServiceInConnector m_HypergridHandler; | ||
51 | |||
52 | #region IRegionModule interface | ||
53 | |||
54 | public void Initialise(IConfigSource config) | ||
55 | { | ||
56 | //// This module is only on for standalones in hypergrid mode | ||
57 | //enabled = (!config.Configs["Startup"].GetBoolean("gridmode", true)) && | ||
58 | // config.Configs["Startup"].GetBoolean("hypergrid", true); | ||
59 | //m_log.DebugFormat("[RegionInventoryService]: enabled? {0}", enabled); | ||
60 | m_Config = config; | ||
61 | IConfig moduleConfig = config.Configs["Modules"]; | ||
62 | if (moduleConfig != null) | ||
63 | { | ||
64 | m_Enabled = moduleConfig.GetBoolean("HypergridServiceInConnector", false); | ||
65 | if (m_Enabled) | ||
66 | { | ||
67 | m_log.Info("[INVENTORY IN CONNECTOR]: Hypergrid Service In Connector enabled"); | ||
68 | } | ||
69 | |||
70 | } | ||
71 | |||
72 | } | ||
73 | |||
74 | public void PostInitialise() | ||
75 | { | ||
76 | } | ||
77 | |||
78 | public void Close() | ||
79 | { | ||
80 | } | ||
81 | |||
82 | public Type ReplaceableInterface | ||
83 | { | ||
84 | get { return null; } | ||
85 | } | ||
86 | |||
87 | public string Name | ||
88 | { | ||
89 | get { return "HypergridService"; } | ||
90 | } | ||
91 | |||
92 | public void AddRegion(Scene scene) | ||
93 | { | ||
94 | if (!m_Enabled) | ||
95 | return; | ||
96 | |||
97 | if (!m_Registered) | ||
98 | { | ||
99 | m_Registered = true; | ||
100 | |||
101 | m_log.Info("[HypergridService]: Starting..."); | ||
102 | |||
103 | Object[] args = new Object[] { m_Config, MainServer.Instance }; | ||
104 | |||
105 | m_HypergridHandler = new HypergridServiceInConnector(m_Config, MainServer.Instance); | ||
106 | //ServerUtils.LoadPlugin<HypergridServiceInConnector>("OpenSim.Server.Handlers.dll:HypergridServiceInConnector", args); | ||
107 | } | ||
108 | |||
109 | SimpleRegionInfo rinfo = new SimpleRegionInfo(scene.RegionInfo); | ||
110 | m_HypergridHandler.AddRegion(rinfo); | ||
111 | } | ||
112 | |||
113 | public void RemoveRegion(Scene scene) | ||
114 | { | ||
115 | if (!m_Enabled) | ||
116 | return; | ||
117 | |||
118 | SimpleRegionInfo rinfo = new SimpleRegionInfo(scene.RegionInfo); | ||
119 | m_HypergridHandler.RemoveRegion(rinfo); | ||
120 | } | ||
121 | |||
122 | public void RegionLoaded(Scene scene) | ||
123 | { | ||
124 | } | ||
125 | |||
126 | #endregion | ||
127 | |||
128 | } | ||
129 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs new file mode 100644 index 0000000..eee3a6c --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs | |||
@@ -0,0 +1,295 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Xml; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | //using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Console; | ||
37 | using OpenSim.Region.Framework; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Region.Framework.Scenes.Hypergrid; | ||
40 | |||
41 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | ||
42 | { | ||
43 | public class HGCommands | ||
44 | { | ||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | private HGGridConnector m_HGGridConnector; | ||
47 | private Scene m_scene; | ||
48 | |||
49 | private static uint m_autoMappingX = 0; | ||
50 | private static uint m_autoMappingY = 0; | ||
51 | private static bool m_enableAutoMapping = false; | ||
52 | |||
53 | public HGCommands(HGGridConnector hgConnector, Scene scene) | ||
54 | { | ||
55 | m_HGGridConnector = hgConnector; | ||
56 | m_scene = scene; | ||
57 | } | ||
58 | |||
59 | //public static Scene CreateScene(RegionInfo regionInfo, AgentCircuitManager circuitManager, CommunicationsManager m_commsManager, | ||
60 | // StorageManager storageManager, ModuleLoader m_moduleLoader, ConfigSettings m_configSettings, OpenSimConfigSource m_config, string m_version) | ||
61 | //{ | ||
62 | // HGSceneCommunicationService sceneGridService = new HGSceneCommunicationService(m_commsManager, HGServices); | ||
63 | |||
64 | // return | ||
65 | // new HGScene( | ||
66 | // regionInfo, circuitManager, m_commsManager, sceneGridService, storageManager, | ||
67 | // m_moduleLoader, false, m_configSettings.PhysicalPrim, | ||
68 | // m_configSettings.See_into_region_from_neighbor, m_config.Source, m_version); | ||
69 | //} | ||
70 | |||
71 | public void RunCommand(string module, string[] cmdparams) | ||
72 | { | ||
73 | List<string> args = new List<string>(cmdparams); | ||
74 | if (args.Count < 1) | ||
75 | return; | ||
76 | |||
77 | string command = args[0]; | ||
78 | args.RemoveAt(0); | ||
79 | |||
80 | cmdparams = args.ToArray(); | ||
81 | |||
82 | RunHGCommand(command, cmdparams); | ||
83 | |||
84 | } | ||
85 | |||
86 | private void RunHGCommand(string command, string[] cmdparams) | ||
87 | { | ||
88 | if (command.Equals("link-mapping")) | ||
89 | { | ||
90 | if (cmdparams.Length == 2) | ||
91 | { | ||
92 | try | ||
93 | { | ||
94 | m_autoMappingX = Convert.ToUInt32(cmdparams[0]); | ||
95 | m_autoMappingY = Convert.ToUInt32(cmdparams[1]); | ||
96 | m_enableAutoMapping = true; | ||
97 | } | ||
98 | catch (Exception) | ||
99 | { | ||
100 | m_autoMappingX = 0; | ||
101 | m_autoMappingY = 0; | ||
102 | m_enableAutoMapping = false; | ||
103 | } | ||
104 | } | ||
105 | } | ||
106 | else if (command.Equals("link-region")) | ||
107 | { | ||
108 | if (cmdparams.Length < 3) | ||
109 | { | ||
110 | if ((cmdparams.Length == 1) || (cmdparams.Length == 2)) | ||
111 | { | ||
112 | LoadXmlLinkFile(cmdparams); | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | LinkRegionCmdUsage(); | ||
117 | } | ||
118 | return; | ||
119 | } | ||
120 | |||
121 | if (cmdparams[2].Contains(":")) | ||
122 | { | ||
123 | // New format | ||
124 | uint xloc, yloc; | ||
125 | string mapName; | ||
126 | try | ||
127 | { | ||
128 | xloc = Convert.ToUInt32(cmdparams[0]); | ||
129 | yloc = Convert.ToUInt32(cmdparams[1]); | ||
130 | mapName = cmdparams[2]; | ||
131 | if (cmdparams.Length > 3) | ||
132 | for (int i = 3; i < cmdparams.Length; i++) | ||
133 | mapName += " " + cmdparams[i]; | ||
134 | |||
135 | m_log.Info(">> MapName: " + mapName); | ||
136 | //internalPort = Convert.ToUInt32(cmdparams[4]); | ||
137 | //remotingPort = Convert.ToUInt32(cmdparams[5]); | ||
138 | } | ||
139 | catch (Exception e) | ||
140 | { | ||
141 | m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message); | ||
142 | LinkRegionCmdUsage(); | ||
143 | return; | ||
144 | } | ||
145 | |||
146 | m_HGGridConnector.TryLinkRegionToCoords(m_scene, null, mapName, xloc, yloc); | ||
147 | } | ||
148 | else | ||
149 | { | ||
150 | // old format | ||
151 | SimpleRegionInfo regInfo; | ||
152 | uint xloc, yloc; | ||
153 | uint externalPort; | ||
154 | string externalHostName; | ||
155 | try | ||
156 | { | ||
157 | xloc = Convert.ToUInt32(cmdparams[0]); | ||
158 | yloc = Convert.ToUInt32(cmdparams[1]); | ||
159 | externalPort = Convert.ToUInt32(cmdparams[3]); | ||
160 | externalHostName = cmdparams[2]; | ||
161 | //internalPort = Convert.ToUInt32(cmdparams[4]); | ||
162 | //remotingPort = Convert.ToUInt32(cmdparams[5]); | ||
163 | } | ||
164 | catch (Exception e) | ||
165 | { | ||
166 | m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message); | ||
167 | LinkRegionCmdUsage(); | ||
168 | return; | ||
169 | } | ||
170 | |||
171 | //if (TryCreateLink(xloc, yloc, externalPort, externalHostName, out regInfo)) | ||
172 | if (m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort, externalHostName, out regInfo)) | ||
173 | { | ||
174 | if (cmdparams.Length >= 5) | ||
175 | { | ||
176 | regInfo.RegionName = ""; | ||
177 | for (int i = 4; i < cmdparams.Length; i++) | ||
178 | regInfo.RegionName += cmdparams[i] + " "; | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | return; | ||
183 | } | ||
184 | else if (command.Equals("unlink-region")) | ||
185 | { | ||
186 | if (cmdparams.Length < 1) | ||
187 | { | ||
188 | UnlinkRegionCmdUsage(); | ||
189 | return; | ||
190 | } | ||
191 | if (m_HGGridConnector.TryUnlinkRegion(m_scene, cmdparams[0])) | ||
192 | m_log.InfoFormat("[HGrid]: Successfully unlinked {0}", cmdparams[0]); | ||
193 | else | ||
194 | m_log.InfoFormat("[HGrid]: Unable to unlink {0}, region not found", cmdparams[0]); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | private void LoadXmlLinkFile(string[] cmdparams) | ||
199 | { | ||
200 | //use http://www.hgurl.com/hypergrid.xml for test | ||
201 | try | ||
202 | { | ||
203 | XmlReader r = XmlReader.Create(cmdparams[0]); | ||
204 | XmlConfigSource cs = new XmlConfigSource(r); | ||
205 | string[] excludeSections = null; | ||
206 | |||
207 | if (cmdparams.Length == 2) | ||
208 | { | ||
209 | if (cmdparams[1].ToLower().StartsWith("excludelist:")) | ||
210 | { | ||
211 | string excludeString = cmdparams[1].ToLower(); | ||
212 | excludeString = excludeString.Remove(0, 12); | ||
213 | char[] splitter = { ';' }; | ||
214 | |||
215 | excludeSections = excludeString.Split(splitter); | ||
216 | } | ||
217 | } | ||
218 | |||
219 | for (int i = 0; i < cs.Configs.Count; i++) | ||
220 | { | ||
221 | bool skip = false; | ||
222 | if ((excludeSections != null) && (excludeSections.Length > 0)) | ||
223 | { | ||
224 | for (int n = 0; n < excludeSections.Length; n++) | ||
225 | { | ||
226 | if (excludeSections[n] == cs.Configs[i].Name.ToLower()) | ||
227 | { | ||
228 | skip = true; | ||
229 | break; | ||
230 | } | ||
231 | } | ||
232 | } | ||
233 | if (!skip) | ||
234 | { | ||
235 | ReadLinkFromConfig(cs.Configs[i]); | ||
236 | } | ||
237 | } | ||
238 | } | ||
239 | catch (Exception e) | ||
240 | { | ||
241 | m_log.Error(e.ToString()); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | |||
246 | private void ReadLinkFromConfig(IConfig config) | ||
247 | { | ||
248 | SimpleRegionInfo regInfo; | ||
249 | uint xloc, yloc; | ||
250 | uint externalPort; | ||
251 | string externalHostName; | ||
252 | uint realXLoc, realYLoc; | ||
253 | |||
254 | xloc = Convert.ToUInt32(config.GetString("xloc", "0")); | ||
255 | yloc = Convert.ToUInt32(config.GetString("yloc", "0")); | ||
256 | externalPort = Convert.ToUInt32(config.GetString("externalPort", "0")); | ||
257 | externalHostName = config.GetString("externalHostName", ""); | ||
258 | realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0")); | ||
259 | realYLoc = Convert.ToUInt32(config.GetString("real-yloc", "0")); | ||
260 | |||
261 | if (m_enableAutoMapping) | ||
262 | { | ||
263 | xloc = (uint)((xloc % 100) + m_autoMappingX); | ||
264 | yloc = (uint)((yloc % 100) + m_autoMappingY); | ||
265 | } | ||
266 | |||
267 | if (((realXLoc == 0) && (realYLoc == 0)) || | ||
268 | (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) && | ||
269 | ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896)))) | ||
270 | { | ||
271 | if ( | ||
272 | m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort, | ||
273 | externalHostName, out regInfo)) | ||
274 | { | ||
275 | regInfo.RegionName = config.GetString("localName", ""); | ||
276 | } | ||
277 | } | ||
278 | } | ||
279 | |||
280 | |||
281 | private void LinkRegionCmdUsage() | ||
282 | { | ||
283 | m_log.Info("Usage: link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]"); | ||
284 | m_log.Info("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]"); | ||
285 | m_log.Info("Usage: link-region <URI_of_xml> [<exclude>]"); | ||
286 | } | ||
287 | |||
288 | private void UnlinkRegionCmdUsage() | ||
289 | { | ||
290 | m_log.Info("Usage: unlink-region <HostName>:<HttpPort>"); | ||
291 | m_log.Info("Usage: unlink-region <LocalName>"); | ||
292 | } | ||
293 | |||
294 | } | ||
295 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs new file mode 100644 index 0000000..7aeb761 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs | |||
@@ -0,0 +1,548 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using System.Reflection; | ||
32 | using System.Xml; | ||
33 | |||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Region.Framework.Interfaces; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | using OpenSim.Region.Framework.Scenes.Hypergrid; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Connectors.Grid; | ||
41 | using OpenSim.Framework.Console; | ||
42 | |||
43 | using OpenMetaverse; | ||
44 | using log4net; | ||
45 | using Nini.Config; | ||
46 | |||
47 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | ||
48 | { | ||
49 | public class HGGridConnector : ISharedRegionModule, IGridService | ||
50 | { | ||
51 | private static readonly ILog m_log = | ||
52 | LogManager.GetLogger( | ||
53 | MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | |||
55 | private bool m_Enabled = false; | ||
56 | private bool m_Initialized = false; | ||
57 | |||
58 | private IGridService m_GridServiceConnector; | ||
59 | private HypergridServiceConnector m_HypergridServiceConnector; | ||
60 | |||
61 | // Hyperlink regions are hyperlinks on the map | ||
62 | protected Dictionary<UUID, SimpleRegionInfo> m_HyperlinkRegions = new Dictionary<UUID, SimpleRegionInfo>(); | ||
63 | |||
64 | // Known regions are home regions of visiting foreign users. | ||
65 | // They are not on the map as static hyperlinks. They are dynamic hyperlinks, they go away when | ||
66 | // the visitor goes away. They are mapped to X=0 on the map. | ||
67 | // This is key-ed on agent ID | ||
68 | protected Dictionary<UUID, SimpleRegionInfo> m_knownRegions = new Dictionary<UUID, SimpleRegionInfo>(); | ||
69 | |||
70 | protected Dictionary<UUID, ulong> m_HyperlinkHandles = new Dictionary<UUID, ulong>(); | ||
71 | |||
72 | #region ISharedRegionModule | ||
73 | |||
74 | public Type ReplaceableInterface | ||
75 | { | ||
76 | get { return null; } | ||
77 | } | ||
78 | |||
79 | public string Name | ||
80 | { | ||
81 | get { return "HGGridServicesConnector"; } | ||
82 | } | ||
83 | |||
84 | public void Initialise(IConfigSource source) | ||
85 | { | ||
86 | IConfig moduleConfig = source.Configs["Modules"]; | ||
87 | if (moduleConfig != null) | ||
88 | { | ||
89 | string name = moduleConfig.GetString("GridServices", ""); | ||
90 | if (name == Name) | ||
91 | { | ||
92 | IConfig gridConfig = source.Configs["GridService"]; | ||
93 | if (gridConfig == null) | ||
94 | { | ||
95 | m_log.Error("[HGGRID CONNECTOR]: GridService missing from OpenSim.ini"); | ||
96 | return; | ||
97 | } | ||
98 | |||
99 | |||
100 | InitialiseConnectorModule(source); | ||
101 | |||
102 | m_Enabled = true; | ||
103 | m_log.Info("[HGGRID CONNECTOR]: HG grid enabled"); | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | |||
108 | private void InitialiseConnectorModule(IConfigSource source) | ||
109 | { | ||
110 | IConfig gridConfig = source.Configs["GridService"]; | ||
111 | if (gridConfig == null) | ||
112 | { | ||
113 | m_log.Error("[HGGRID CONNECTOR]: GridService missing from OpenSim.ini"); | ||
114 | throw new Exception("Grid connector init error"); | ||
115 | } | ||
116 | |||
117 | string module = gridConfig.GetString("GridServiceConnectorModule", String.Empty); | ||
118 | if (module == String.Empty) | ||
119 | { | ||
120 | m_log.Error("[HGGRID CONNECTOR]: No GridServiceConnectorModule named in section GridService"); | ||
121 | //return; | ||
122 | throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's"); | ||
123 | } | ||
124 | |||
125 | Object[] args = new Object[] { source }; | ||
126 | m_GridServiceConnector = ServerUtils.LoadPlugin<IGridService>(module, args); | ||
127 | |||
128 | } | ||
129 | |||
130 | public void PostInitialise() | ||
131 | { | ||
132 | } | ||
133 | |||
134 | public void Close() | ||
135 | { | ||
136 | } | ||
137 | |||
138 | public void AddRegion(Scene scene) | ||
139 | { | ||
140 | if (!m_Enabled) | ||
141 | return; | ||
142 | |||
143 | scene.RegisterModuleInterface<IGridService>(this); | ||
144 | |||
145 | } | ||
146 | |||
147 | public void RemoveRegion(Scene scene) | ||
148 | { | ||
149 | } | ||
150 | |||
151 | public void RegionLoaded(Scene scene) | ||
152 | { | ||
153 | if (!m_Enabled) | ||
154 | return; | ||
155 | |||
156 | if (!m_Initialized) | ||
157 | { | ||
158 | m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService); | ||
159 | m_Initialized = true; | ||
160 | } | ||
161 | |||
162 | HGCommands hgCommands = new HGCommands(this, scene); | ||
163 | scene.AddCommand("HG", "link-region", | ||
164 | "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>", | ||
165 | "Link a hypergrid region", hgCommands.RunCommand); | ||
166 | scene.AddCommand("HG", "unlink-region", | ||
167 | "unlink-region <local name> or <HostName>:<HttpPort> <cr>", | ||
168 | "Unlink a hypergrid region", hgCommands.RunCommand); | ||
169 | scene.AddCommand("HG", "link-mapping", "link-mapping [<x> <y>] <cr>", | ||
170 | "Set local coordinate to map HG regions to", hgCommands.RunCommand); | ||
171 | |||
172 | } | ||
173 | |||
174 | #endregion | ||
175 | |||
176 | #region IGridService | ||
177 | |||
178 | public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo) | ||
179 | { | ||
180 | // Region doesn't exist here. Trying to link remote region | ||
181 | if (regionInfo.RegionID.Equals(UUID.Zero)) | ||
182 | { | ||
183 | m_log.Info("[HGrid]: Linking remote region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort); | ||
184 | ulong regionHandle = 0; | ||
185 | regionInfo.RegionID = m_HypergridServiceConnector.LinkRegion(regionInfo, out regionHandle); | ||
186 | if (!regionInfo.RegionID.Equals(UUID.Zero)) | ||
187 | { | ||
188 | AddHyperlinkRegion(regionInfo, regionHandle); | ||
189 | m_log.Info("[HGrid]: Successfully linked to region_uuid " + regionInfo.RegionID); | ||
190 | |||
191 | // Try get the map image | ||
192 | m_HypergridServiceConnector.GetMapImage(regionInfo); | ||
193 | return true; | ||
194 | } | ||
195 | else | ||
196 | { | ||
197 | m_log.Info("[HGrid]: No such region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort + "(" + regionInfo.InternalEndPoint.Port + ")"); | ||
198 | return false; | ||
199 | } | ||
200 | // Note that these remote regions aren't registered in localBackend, so return null, no local listeners | ||
201 | } | ||
202 | else // normal grid | ||
203 | return m_GridServiceConnector.RegisterRegion(scopeID, regionInfo); | ||
204 | } | ||
205 | |||
206 | public bool DeregisterRegion(UUID regionID) | ||
207 | { | ||
208 | // Try the hyperlink collection | ||
209 | if (m_HyperlinkRegions.ContainsKey(regionID)) | ||
210 | { | ||
211 | RemoveHyperlinkRegion(regionID); | ||
212 | return true; | ||
213 | } | ||
214 | // Try the foreign users home collection | ||
215 | |||
216 | foreach (SimpleRegionInfo r in m_knownRegions.Values) | ||
217 | if (r.RegionID == regionID) | ||
218 | { | ||
219 | RemoveHyperlinkHomeRegion(regionID); | ||
220 | return true; | ||
221 | } | ||
222 | |||
223 | // Finally, try the normal route | ||
224 | return m_GridServiceConnector.DeregisterRegion(regionID); | ||
225 | } | ||
226 | |||
227 | public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID) | ||
228 | { | ||
229 | // No serving neighbours on hyperliked regions. | ||
230 | // Just the regular regions. | ||
231 | return m_GridServiceConnector.GetNeighbours(scopeID, regionID); | ||
232 | } | ||
233 | |||
234 | public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) | ||
235 | { | ||
236 | // Try the hyperlink collection | ||
237 | if (m_HyperlinkRegions.ContainsKey(regionID)) | ||
238 | return m_HyperlinkRegions[regionID]; | ||
239 | |||
240 | // Try the foreign users home collection | ||
241 | foreach (SimpleRegionInfo r in m_knownRegions.Values) | ||
242 | if (r.RegionID == regionID) | ||
243 | return m_knownRegions[regionID]; | ||
244 | |||
245 | // Finally, try the normal route | ||
246 | return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID); | ||
247 | } | ||
248 | |||
249 | public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) | ||
250 | { | ||
251 | int snapX = (int) (x / Constants.RegionSize) * (int)Constants.RegionSize; | ||
252 | int snapY = (int) (y / Constants.RegionSize) * (int)Constants.RegionSize; | ||
253 | // Try the hyperlink collection | ||
254 | foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) | ||
255 | { | ||
256 | if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY)) | ||
257 | return r; | ||
258 | } | ||
259 | |||
260 | // Try the foreign users home collection | ||
261 | foreach (SimpleRegionInfo r in m_knownRegions.Values) | ||
262 | { | ||
263 | if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY)) | ||
264 | return r; | ||
265 | } | ||
266 | |||
267 | // Finally, try the normal route | ||
268 | return m_GridServiceConnector.GetRegionByPosition(scopeID, x, y); | ||
269 | } | ||
270 | |||
271 | public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) | ||
272 | { | ||
273 | // Try normal grid first | ||
274 | SimpleRegionInfo region = m_GridServiceConnector.GetRegionByName(scopeID, regionName); | ||
275 | if (region != null) | ||
276 | return region; | ||
277 | |||
278 | // Try the hyperlink collection | ||
279 | foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) | ||
280 | { | ||
281 | if (r.RegionName == regionName) | ||
282 | return r; | ||
283 | } | ||
284 | |||
285 | // Try the foreign users home collection | ||
286 | foreach (SimpleRegionInfo r in m_knownRegions.Values) | ||
287 | { | ||
288 | if (r.RegionName == regionName) | ||
289 | return r; | ||
290 | } | ||
291 | return null; | ||
292 | } | ||
293 | |||
294 | public List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber) | ||
295 | { | ||
296 | List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); | ||
297 | |||
298 | // Commenting until regionname exists | ||
299 | //foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) | ||
300 | // if ((r.RegionName != null) && r.RegionName.StartsWith(name)) | ||
301 | // rinfos.Add(r); | ||
302 | |||
303 | rinfos.AddRange(m_GridServiceConnector.GetRegionsByName(scopeID, name, maxNumber)); | ||
304 | return rinfos; | ||
305 | } | ||
306 | |||
307 | public List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) | ||
308 | { | ||
309 | int snapXmin = (int)(xmin / Constants.RegionSize) * (int)Constants.RegionSize; | ||
310 | int snapXmax = (int)(xmax / Constants.RegionSize) * (int)Constants.RegionSize; | ||
311 | int snapYmin = (int)(ymin / Constants.RegionSize) * (int)Constants.RegionSize; | ||
312 | int snapYmax = (int)(ymax / Constants.RegionSize) * (int)Constants.RegionSize; | ||
313 | |||
314 | List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>(); | ||
315 | foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) | ||
316 | if ((r.RegionLocX > snapXmin) && (r.RegionLocX < snapYmax) && | ||
317 | (r.RegionLocY > snapYmin) && (r.RegionLocY < snapYmax)) | ||
318 | rinfos.Add(r); | ||
319 | |||
320 | rinfos.AddRange(m_GridServiceConnector.GetRegionRange(scopeID, xmin, xmax, ymin, ymax)); | ||
321 | |||
322 | return rinfos; | ||
323 | } | ||
324 | |||
325 | #endregion | ||
326 | |||
327 | #region Auxiliary | ||
328 | |||
329 | private void AddHyperlinkRegion(SimpleRegionInfo regionInfo, ulong regionHandle) | ||
330 | { | ||
331 | m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo); | ||
332 | m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); | ||
333 | } | ||
334 | |||
335 | private void RemoveHyperlinkRegion(UUID regionID) | ||
336 | { | ||
337 | m_HyperlinkRegions.Remove(regionID); | ||
338 | m_HyperlinkHandles.Remove(regionID); | ||
339 | } | ||
340 | |||
341 | private void AddHyperlinkHomeRegion(UUID userID, SimpleRegionInfo regionInfo, ulong regionHandle) | ||
342 | { | ||
343 | m_knownRegions.Add(userID, regionInfo); | ||
344 | m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle); | ||
345 | } | ||
346 | |||
347 | private void RemoveHyperlinkHomeRegion(UUID regionID) | ||
348 | { | ||
349 | foreach (KeyValuePair<UUID, SimpleRegionInfo> kvp in m_knownRegions) | ||
350 | { | ||
351 | if (kvp.Value.RegionID == regionID) | ||
352 | { | ||
353 | m_knownRegions.Remove(kvp.Key); | ||
354 | } | ||
355 | } | ||
356 | m_HyperlinkHandles.Remove(regionID); | ||
357 | } | ||
358 | #endregion | ||
359 | |||
360 | #region Hyperlinks | ||
361 | |||
362 | private static Random random = new Random(); | ||
363 | |||
364 | public SimpleRegionInfo TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, uint xloc, uint yloc) | ||
365 | { | ||
366 | string host = "127.0.0.1"; | ||
367 | string portstr; | ||
368 | string regionName = ""; | ||
369 | uint port = 9000; | ||
370 | string[] parts = mapName.Split(new char[] { ':' }); | ||
371 | if (parts.Length >= 1) | ||
372 | { | ||
373 | host = parts[0]; | ||
374 | } | ||
375 | if (parts.Length >= 2) | ||
376 | { | ||
377 | portstr = parts[1]; | ||
378 | if (!UInt32.TryParse(portstr, out port)) | ||
379 | regionName = parts[1]; | ||
380 | } | ||
381 | // always take the last one | ||
382 | if (parts.Length >= 3) | ||
383 | { | ||
384 | regionName = parts[2]; | ||
385 | } | ||
386 | |||
387 | // Sanity check. Don't ever link to this sim. | ||
388 | IPAddress ipaddr = null; | ||
389 | try | ||
390 | { | ||
391 | ipaddr = Util.GetHostFromDNS(host); | ||
392 | } | ||
393 | catch { } | ||
394 | |||
395 | if ((ipaddr != null) && | ||
396 | !((m_scene.RegionInfo.ExternalEndPoint.Address.Equals(ipaddr)) && (m_scene.RegionInfo.HttpPort == port))) | ||
397 | { | ||
398 | SimpleRegionInfo regInfo; | ||
399 | bool success = TryCreateLink(m_scene, client, xloc, yloc, regionName, port, host, out regInfo); | ||
400 | if (success) | ||
401 | { | ||
402 | regInfo.RegionName = mapName; | ||
403 | return regInfo; | ||
404 | } | ||
405 | } | ||
406 | |||
407 | return null; | ||
408 | } | ||
409 | |||
410 | public SimpleRegionInfo TryLinkRegion(Scene m_scene, IClientAPI client, string mapName) | ||
411 | { | ||
412 | uint xloc = (uint)(random.Next(0, Int16.MaxValue)); | ||
413 | return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0); | ||
414 | } | ||
415 | |||
416 | public bool TryCreateLink(Scene m_scene, IClientAPI client, uint xloc, uint yloc, | ||
417 | string externalRegionName, uint externalPort, string externalHostName, out SimpleRegionInfo regInfo) | ||
418 | { | ||
419 | m_log.DebugFormat("[HGrid]: Link to {0}:{1}, in {2}-{3}", externalHostName, externalPort, xloc, yloc); | ||
420 | |||
421 | regInfo = new SimpleRegionInfo(); | ||
422 | regInfo.RegionName = externalRegionName; | ||
423 | regInfo.HttpPort = externalPort; | ||
424 | regInfo.ExternalHostName = externalHostName; | ||
425 | regInfo.RegionLocX = xloc; | ||
426 | regInfo.RegionLocY = yloc; | ||
427 | |||
428 | try | ||
429 | { | ||
430 | regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0); | ||
431 | } | ||
432 | catch (Exception e) | ||
433 | { | ||
434 | m_log.Warn("[HGrid]: Wrong format for link-region: " + e.Message); | ||
435 | return false; | ||
436 | } | ||
437 | |||
438 | // Finally, link it | ||
439 | try | ||
440 | { | ||
441 | RegisterRegion(UUID.Zero, regInfo); | ||
442 | } | ||
443 | catch (Exception e) | ||
444 | { | ||
445 | m_log.Warn("[HGrid]: Unable to link region: " + e.Message); | ||
446 | return false; | ||
447 | } | ||
448 | |||
449 | uint x, y; | ||
450 | if (!Check4096(m_scene, regInfo, out x, out y)) | ||
451 | { | ||
452 | DeregisterRegion(regInfo.RegionID); | ||
453 | if (client != null) | ||
454 | client.SendAlertMessage("Region is too far (" + x + ", " + y + ")"); | ||
455 | m_log.Info("[HGrid]: Unable to link, region is too far (" + x + ", " + y + ")"); | ||
456 | return false; | ||
457 | } | ||
458 | |||
459 | if (!CheckCoords(m_scene.RegionInfo.RegionLocX, m_scene.RegionInfo.RegionLocY, x, y)) | ||
460 | { | ||
461 | DeregisterRegion(regInfo.RegionID); | ||
462 | if (client != null) | ||
463 | client.SendAlertMessage("Region has incompatible coordinates (" + x + ", " + y + ")"); | ||
464 | m_log.Info("[HGrid]: Unable to link, region has incompatible coordinates (" + x + ", " + y + ")"); | ||
465 | return false; | ||
466 | } | ||
467 | |||
468 | m_log.Debug("[HGrid]: link region succeeded"); | ||
469 | return true; | ||
470 | } | ||
471 | |||
472 | public bool TryUnlinkRegion(Scene m_scene, string mapName) | ||
473 | { | ||
474 | SimpleRegionInfo regInfo = null; | ||
475 | if (mapName.Contains(":")) | ||
476 | { | ||
477 | string host = "127.0.0.1"; | ||
478 | //string portstr; | ||
479 | //string regionName = ""; | ||
480 | uint port = 9000; | ||
481 | string[] parts = mapName.Split(new char[] { ':' }); | ||
482 | if (parts.Length >= 1) | ||
483 | { | ||
484 | host = parts[0]; | ||
485 | } | ||
486 | // if (parts.Length >= 2) | ||
487 | // { | ||
488 | // portstr = parts[1]; | ||
489 | // if (!UInt32.TryParse(portstr, out port)) | ||
490 | // regionName = parts[1]; | ||
491 | // } | ||
492 | // always take the last one | ||
493 | // if (parts.Length >= 3) | ||
494 | // { | ||
495 | // regionName = parts[2]; | ||
496 | // } | ||
497 | foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) | ||
498 | if (host.Equals(r.ExternalHostName) && (port == r.HttpPort)) | ||
499 | regInfo = r; | ||
500 | } | ||
501 | else | ||
502 | { | ||
503 | foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) | ||
504 | if (r.RegionName.Equals(mapName)) | ||
505 | regInfo = r; | ||
506 | } | ||
507 | if (regInfo != null) | ||
508 | { | ||
509 | return DeregisterRegion(regInfo.RegionID); | ||
510 | } | ||
511 | else | ||
512 | { | ||
513 | m_log.InfoFormat("[HGrid]: Region {0} not found", mapName); | ||
514 | return false; | ||
515 | } | ||
516 | } | ||
517 | |||
518 | /// <summary> | ||
519 | /// Cope with this viewer limitation. | ||
520 | /// </summary> | ||
521 | /// <param name="regInfo"></param> | ||
522 | /// <returns></returns> | ||
523 | public bool Check4096(Scene m_scene, SimpleRegionInfo regInfo, out uint x, out uint y) | ||
524 | { | ||
525 | ulong realHandle = m_HyperlinkHandles[regInfo.RegionID]; | ||
526 | Utils.LongToUInts(realHandle, out x, out y); | ||
527 | x = x / Constants.RegionSize; | ||
528 | y = y / Constants.RegionSize; | ||
529 | |||
530 | if ((Math.Abs((int)m_scene.RegionInfo.RegionLocX - (int)x) >= 4096) || | ||
531 | (Math.Abs((int)m_scene.RegionInfo.RegionLocY - (int)y) >= 4096)) | ||
532 | { | ||
533 | return false; | ||
534 | } | ||
535 | return true; | ||
536 | } | ||
537 | |||
538 | public bool CheckCoords(uint thisx, uint thisy, uint x, uint y) | ||
539 | { | ||
540 | if ((thisx == x) && (thisy == y)) | ||
541 | return false; | ||
542 | return true; | ||
543 | } | ||
544 | |||
545 | #endregion | ||
546 | |||
547 | } | ||
548 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs index 74ece2e..3f29401 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs | |||
@@ -50,6 +50,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
50 | 50 | ||
51 | private bool m_Enabled = false; | 51 | private bool m_Enabled = false; |
52 | 52 | ||
53 | public LocalGridServicesConnector(IConfigSource source) | ||
54 | { | ||
55 | InitialiseService(source); | ||
56 | } | ||
57 | |||
53 | #region ISharedRegionModule | 58 | #region ISharedRegionModule |
54 | 59 | ||
55 | public Type ReplaceableInterface | 60 | public Type ReplaceableInterface |
@@ -70,38 +75,43 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
70 | string name = moduleConfig.GetString("GridServices", ""); | 75 | string name = moduleConfig.GetString("GridServices", ""); |
71 | if (name == Name) | 76 | if (name == Name) |
72 | { | 77 | { |
73 | IConfig assetConfig = source.Configs["GridService"]; | 78 | InitialiseService(source); |
74 | if (assetConfig == null) | ||
75 | { | ||
76 | m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini"); | ||
77 | return; | ||
78 | } | ||
79 | |||
80 | string serviceDll = assetConfig.GetString("LocalServiceModule", | ||
81 | String.Empty); | ||
82 | |||
83 | if (serviceDll == String.Empty) | ||
84 | { | ||
85 | m_log.Error("[GRID CONNECTOR]: No LocalServiceModule named in section GridService"); | ||
86 | return; | ||
87 | } | ||
88 | |||
89 | Object[] args = new Object[] { source }; | ||
90 | m_GridService = | ||
91 | ServerUtils.LoadPlugin<IGridService>(serviceDll, | ||
92 | args); | ||
93 | |||
94 | if (m_GridService == null) | ||
95 | { | ||
96 | m_log.Error("[GRID CONNECTOR]: Can't load asset service"); | ||
97 | return; | ||
98 | } | ||
99 | m_Enabled = true; | 79 | m_Enabled = true; |
100 | m_log.Info("[GRID CONNECTOR]: Local grid connector enabled"); | 80 | m_log.Info("[LOCAL GRID CONNECTOR]: Local grid connector enabled"); |
101 | } | 81 | } |
102 | } | 82 | } |
103 | } | 83 | } |
104 | 84 | ||
85 | private void InitialiseService(IConfigSource source) | ||
86 | { | ||
87 | IConfig assetConfig = source.Configs["GridService"]; | ||
88 | if (assetConfig == null) | ||
89 | { | ||
90 | m_log.Error("[LOCAL GRID CONNECTOR]: GridService missing from OpenSim.ini"); | ||
91 | return; | ||
92 | } | ||
93 | |||
94 | string serviceDll = assetConfig.GetString("LocalServiceModule", | ||
95 | String.Empty); | ||
96 | |||
97 | if (serviceDll == String.Empty) | ||
98 | { | ||
99 | m_log.Error("[LOCAL GRID CONNECTOR]: No LocalServiceModule named in section GridService"); | ||
100 | return; | ||
101 | } | ||
102 | |||
103 | Object[] args = new Object[] { source }; | ||
104 | m_GridService = | ||
105 | ServerUtils.LoadPlugin<IGridService>(serviceDll, | ||
106 | args); | ||
107 | |||
108 | if (m_GridService == null) | ||
109 | { | ||
110 | m_log.Error("[LOCAL GRID CONNECTOR]: Can't load asset service"); | ||
111 | return; | ||
112 | } | ||
113 | } | ||
114 | |||
105 | public void PostInitialise() | 115 | public void PostInitialise() |
106 | { | 116 | { |
107 | } | 117 | } |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs new file mode 100644 index 0000000..8526653 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs | |||
@@ -0,0 +1,178 @@ | |||
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 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using Nini.Config; | ||
33 | using OpenMetaverse; | ||
34 | |||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Services.Connectors; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | |||
41 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | ||
42 | { | ||
43 | public class RemoteGridServicesConnector : | ||
44 | GridServicesConnector, ISharedRegionModule, IGridService | ||
45 | { | ||
46 | private static readonly ILog m_log = | ||
47 | LogManager.GetLogger( | ||
48 | MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private bool m_Enabled = false; | ||
51 | |||
52 | private IGridService m_LocalGridService; | ||
53 | |||
54 | public RemoteGridServicesConnector(IConfigSource source) | ||
55 | { | ||
56 | InitialiseServices(source); | ||
57 | } | ||
58 | |||
59 | #region ISharedRegionmodule | ||
60 | |||
61 | public Type ReplaceableInterface | ||
62 | { | ||
63 | get { return null; } | ||
64 | } | ||
65 | |||
66 | public string Name | ||
67 | { | ||
68 | get { return "RemoteGridServicesConnector"; } | ||
69 | } | ||
70 | |||
71 | public override void Initialise(IConfigSource source) | ||
72 | { | ||
73 | IConfig moduleConfig = source.Configs["Modules"]; | ||
74 | if (moduleConfig != null) | ||
75 | { | ||
76 | string name = moduleConfig.GetString("GridServices", ""); | ||
77 | if (name == Name) | ||
78 | { | ||
79 | InitialiseServices(source); | ||
80 | m_Enabled = true; | ||
81 | m_log.Info("[REMOTE GRID CONNECTOR]: Remote grid enabled"); | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | |||
86 | private void InitialiseServices(IConfigSource source) | ||
87 | { | ||
88 | IConfig gridConfig = source.Configs["GridService"]; | ||
89 | if (gridConfig == null) | ||
90 | { | ||
91 | m_log.Error("[REMOTE GRID CONNECTOR]: GridService missing from OpenSim.ini"); | ||
92 | return; | ||
93 | } | ||
94 | |||
95 | base.Initialise(source); | ||
96 | |||
97 | m_LocalGridService = new LocalGridServicesConnector(source); | ||
98 | } | ||
99 | |||
100 | public void PostInitialise() | ||
101 | { | ||
102 | } | ||
103 | |||
104 | public void Close() | ||
105 | { | ||
106 | } | ||
107 | |||
108 | public void AddRegion(Scene scene) | ||
109 | { | ||
110 | if (!m_Enabled) | ||
111 | return; | ||
112 | |||
113 | scene.RegisterModuleInterface<IGridService>(this); | ||
114 | } | ||
115 | |||
116 | public void RemoveRegion(Scene scene) | ||
117 | { | ||
118 | } | ||
119 | |||
120 | public void RegionLoaded(Scene scene) | ||
121 | { | ||
122 | } | ||
123 | |||
124 | #endregion | ||
125 | |||
126 | #region IGridService | ||
127 | |||
128 | public override bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo) | ||
129 | { | ||
130 | if (m_LocalGridService.RegisterRegion(scopeID, regionInfo)) | ||
131 | return base.RegisterRegion(scopeID, regionInfo); | ||
132 | |||
133 | return false; | ||
134 | } | ||
135 | |||
136 | public override bool DeregisterRegion(UUID regionID) | ||
137 | { | ||
138 | if (m_LocalGridService.DeregisterRegion(regionID)) | ||
139 | return base.DeregisterRegion(regionID); | ||
140 | |||
141 | return false; | ||
142 | } | ||
143 | |||
144 | // Let's not override GetNeighbours -- let's get them all from the grid server | ||
145 | |||
146 | public override SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) | ||
147 | { | ||
148 | SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByUUID(scopeID, regionID); | ||
149 | if (rinfo == null) | ||
150 | rinfo = base.GetRegionByUUID(scopeID, regionID); | ||
151 | |||
152 | return rinfo; | ||
153 | } | ||
154 | |||
155 | public override SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) | ||
156 | { | ||
157 | SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); | ||
158 | if (rinfo == null) | ||
159 | rinfo = base.GetRegionByPosition(scopeID, x, y); | ||
160 | |||
161 | return rinfo; | ||
162 | } | ||
163 | |||
164 | public override SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) | ||
165 | { | ||
166 | SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByName(scopeID, regionName); | ||
167 | if (rinfo == null) | ||
168 | rinfo = base.GetRegionByName(scopeID, regionName); | ||
169 | |||
170 | return rinfo; | ||
171 | } | ||
172 | |||
173 | // Let's not override GetRegionsByName -- let's get them all from the grid server | ||
174 | // Let's not override GetRegionRange -- let's get them all from the grid server | ||
175 | |||
176 | #endregion | ||
177 | } | ||
178 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index b631478..d4d5ccc 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -7838,8 +7838,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7838 | public LSL_String llGetHTTPHeader(LSL_Key request_id, string header) | 7838 | public LSL_String llGetHTTPHeader(LSL_Key request_id, string header) |
7839 | { | 7839 | { |
7840 | m_host.AddScriptLPS(1); | 7840 | m_host.AddScriptLPS(1); |
7841 | 7841 | ||
7842 | if (m_UrlModule != null) | 7842 | if (m_UrlModule != null) |
7843 | return m_UrlModule.GetHttpHeader(new UUID(request_id), header); | 7843 | return m_UrlModule.GetHttpHeader(new UUID(request_id), header); |
7844 | return String.Empty; | 7844 | return String.Empty; |
7845 | } | 7845 | } |
@@ -9124,9 +9124,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9124 | // Partial implementation: support for parameter flags needed | 9124 | // Partial implementation: support for parameter flags needed |
9125 | // see http://wiki.secondlife.com/wiki/llHTTPResponse | 9125 | // see http://wiki.secondlife.com/wiki/llHTTPResponse |
9126 | 9126 | ||
9127 | m_host.AddScriptLPS(1); | 9127 | m_host.AddScriptLPS(1); |
9128 | 9128 | ||
9129 | if (m_UrlModule != null) | 9129 | if (m_UrlModule != null) |
9130 | m_UrlModule.HttpResponse(new UUID(id), status,body); | 9130 | m_UrlModule.HttpResponse(new UUID(id), status,body); |
9131 | } | 9131 | } |
9132 | 9132 | ||