OGS1GridServices.cs 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. using System;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Net;
  32. using System.Net.Sockets;
  33. using System.Runtime.Remoting;
  34. using System.Runtime.Remoting.Channels;
  35. using System.Runtime.Remoting.Channels.Tcp;
  36. using System.Security.Authentication;
  37. using libsecondlife;
  38. using Nwc.XmlRpc;
  39. using OpenSim.Framework;
  40. using OpenSim.Framework.Communications;
  41. using OpenSim.Framework.Console;
  42. using OpenSim.Framework.Servers;
  43. using OpenSim.Region.Communications.Local;
  44. namespace OpenSim.Region.Communications.OGS1
  45. {
  46. public class OGS1GridServices : IGridServices, IInterRegionCommunications
  47. {
  48. private LocalBackEndServices m_localBackend = new LocalBackEndServices();
  49. private Dictionary<ulong, RegionInfo> m_remoteRegionInfoCache = new Dictionary<ulong, RegionInfo>();
  50. private List<SimpleRegionInfo> m_knownRegions = new List<SimpleRegionInfo>();
  51. private Dictionary<string, string> m_queuedGridSettings = new Dictionary<string, string>();
  52. public BaseHttpServer httpListener;
  53. public NetworkServersInfo serversInfo;
  54. public BaseHttpServer httpServer;
  55. public string _gdebugRegionName = "";
  56. public string gdebugRegionName
  57. {
  58. get { return _gdebugRegionName; }
  59. set { _gdebugRegionName = value; }
  60. }
  61. public string _rdebugRegionName = "";
  62. public string rdebugRegionName
  63. {
  64. get { return _rdebugRegionName; }
  65. set { _rdebugRegionName = value; }
  66. }
  67. /// <summary>
  68. ///
  69. /// </summary>
  70. /// <param name="servers_info"></param>
  71. /// <param name="httpServe"></param>
  72. public OGS1GridServices(NetworkServersInfo servers_info, BaseHttpServer httpServe)
  73. {
  74. serversInfo = servers_info;
  75. httpServer = httpServe;
  76. //Respond to Grid Services requests
  77. httpServer.AddXmlRPCHandler("expect_user", ExpectUser);
  78. httpServer.AddXmlRPCHandler("check", PingCheckReply);
  79. StartRemoting();
  80. }
  81. /// <summary>
  82. ///
  83. /// </summary>
  84. /// <param name="regionInfo"></param>
  85. /// <returns></returns>
  86. public RegionCommsListener RegisterRegion(RegionInfo regionInfo)
  87. {
  88. Hashtable GridParams = new Hashtable();
  89. // Login / Authentication
  90. GridParams["authkey"] = serversInfo.GridSendKey;
  91. GridParams["UUID"] = regionInfo.RegionID.ToString();
  92. GridParams["sim_ip"] = regionInfo.ExternalHostName;
  93. GridParams["sim_port"] = regionInfo.InternalEndPoint.Port.ToString();
  94. GridParams["region_locx"] = regionInfo.RegionLocX.ToString();
  95. GridParams["region_locy"] = regionInfo.RegionLocY.ToString();
  96. GridParams["sim_name"] = regionInfo.RegionName;
  97. GridParams["http_port"] = serversInfo.HttpListenerPort.ToString();
  98. GridParams["remoting_port"] = NetworkServersInfo.RemotingListenerPort.ToString();
  99. GridParams["map-image-id"] = regionInfo.EstateSettings.terrainImageID.ToString();
  100. // Package into an XMLRPC Request
  101. ArrayList SendParams = new ArrayList();
  102. SendParams.Add(GridParams);
  103. // Send Request
  104. XmlRpcRequest GridReq;
  105. XmlRpcResponse GridResp;
  106. try
  107. {
  108. GridReq = new XmlRpcRequest("simulator_login", SendParams);
  109. GridResp = GridReq.Send(serversInfo.GridURL, 10000);
  110. } catch (Exception ex)
  111. {
  112. MainLog.Instance.Error("Unable to connect to grid. Grid server not running?");
  113. throw(ex);
  114. }
  115. Hashtable GridRespData = (Hashtable)GridResp.Value;
  116. Hashtable griddatahash = GridRespData;
  117. // Process Response
  118. if (GridRespData.ContainsKey("error"))
  119. {
  120. string errorstring = (string) GridRespData["error"];
  121. MainLog.Instance.Error("Unable to connect to grid: " + errorstring);
  122. return null;
  123. }
  124. else
  125. {
  126. m_knownRegions = RequestNeighbours(regionInfo.RegionLocX, regionInfo.RegionLocY);
  127. if (GridRespData.ContainsKey("allow_forceful_banlines"))
  128. {
  129. if ((string) GridRespData["allow_forceful_banlines"] != "TRUE")
  130. {
  131. //m_localBackend.SetForcefulBanlistsDisallowed(regionInfo.RegionHandle);
  132. m_queuedGridSettings.Add("allow_forceful_banlines", "FALSE");
  133. }
  134. }
  135. }
  136. return m_localBackend.RegisterRegion(regionInfo);
  137. }
  138. public bool DeregisterRegion(RegionInfo regionInfo)
  139. {
  140. return false;
  141. }
  142. public virtual Dictionary<string, string> GetGridSettings()
  143. {
  144. Dictionary<string, string> returnGridSettings = new Dictionary<string, string>();
  145. lock (m_queuedGridSettings)
  146. {
  147. foreach (string Dictkey in m_queuedGridSettings.Keys)
  148. {
  149. returnGridSettings.Add(Dictkey, m_queuedGridSettings[Dictkey]);
  150. }
  151. m_queuedGridSettings.Clear();
  152. }
  153. return returnGridSettings;
  154. }
  155. /// <summary>
  156. ///
  157. /// </summary>
  158. /// <param name="regionInfo"></param>
  159. /// <returns></returns>
  160. public List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
  161. {
  162. Hashtable respData = MapBlockQuery((int) x - 1, (int) y - 1, (int) x + 1, (int) y + 1);
  163. List<SimpleRegionInfo> neighbours = new List<SimpleRegionInfo>();
  164. foreach (ArrayList neighboursList in respData.Values)
  165. {
  166. foreach (Hashtable neighbourData in neighboursList)
  167. {
  168. uint regX = Convert.ToUInt32(neighbourData["x"]);
  169. uint regY = Convert.ToUInt32(neighbourData["y"]);
  170. if ((x != regX) || (y != regY))
  171. {
  172. string simIp = (string) neighbourData["sim_ip"];
  173. uint port = Convert.ToUInt32(neighbourData["sim_port"]);
  174. string externalUri = (string) neighbourData["sim_uri"];
  175. string externalIpStr = Util.GetHostFromDNS(simIp).ToString();
  176. SimpleRegionInfo sri = new SimpleRegionInfo(regX, regY, simIp, port);
  177. sri.RemotingPort = Convert.ToUInt32(neighbourData["remoting_port"]);
  178. sri.RegionID = new LLUUID((string) neighbourData["uuid"]);
  179. neighbours.Add(sri);
  180. }
  181. }
  182. }
  183. return neighbours;
  184. }
  185. /// <summary>
  186. ///
  187. /// </summary>
  188. /// <param name="regionHandle"></param>
  189. /// <returns></returns>
  190. public RegionInfo RequestNeighbourInfo(LLUUID Region_UUID)
  191. {
  192. RegionInfo regionInfo;
  193. Hashtable requestData = new Hashtable();
  194. requestData["region_UUID"] = Region_UUID.ToString();
  195. requestData["authkey"] = serversInfo.GridSendKey;
  196. ArrayList SendParams = new ArrayList();
  197. SendParams.Add(requestData);
  198. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  199. XmlRpcResponse GridResp = GridReq.Send(serversInfo.GridURL, 3000);
  200. Hashtable responseData = (Hashtable) GridResp.Value;
  201. if (responseData.ContainsKey("error"))
  202. {
  203. Console.WriteLine("error received from grid server" + responseData["error"]);
  204. return null;
  205. }
  206. uint regX = Convert.ToUInt32((string) responseData["region_locx"]);
  207. uint regY = Convert.ToUInt32((string) responseData["region_locy"]);
  208. string internalIpStr = (string) responseData["sim_ip"];
  209. uint port = Convert.ToUInt32(responseData["sim_port"]);
  210. string externalUri = (string) responseData["sim_uri"];
  211. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int) port);
  212. string neighbourExternalUri = externalUri;
  213. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, internalIpStr);
  214. regionInfo.RemotingPort = Convert.ToUInt32((string) responseData["remoting_port"]);
  215. regionInfo.RemotingAddress = internalIpStr;
  216. regionInfo.RegionID = new LLUUID((string) responseData["region_UUID"]);
  217. regionInfo.RegionName = (string) responseData["region_name"];
  218. if (requestData.ContainsKey("regionHandle"))
  219. {
  220. m_remoteRegionInfoCache.Add(Convert.ToUInt64((string) requestData["regionHandle"]), regionInfo);
  221. }
  222. return regionInfo;
  223. }
  224. /// <summary>
  225. ///
  226. /// </summary>
  227. /// <param name="regionHandle"></param>
  228. /// <returns></returns>
  229. public RegionInfo RequestNeighbourInfo(ulong regionHandle)
  230. {
  231. RegionInfo regionInfo = m_localBackend.RequestNeighbourInfo(regionHandle);
  232. if (regionInfo != null)
  233. {
  234. return regionInfo;
  235. }
  236. if (m_remoteRegionInfoCache.TryGetValue(regionHandle, out regionInfo))
  237. {
  238. }
  239. else
  240. {
  241. try
  242. {
  243. Hashtable requestData = new Hashtable();
  244. requestData["region_handle"] = regionHandle.ToString();
  245. requestData["authkey"] = serversInfo.GridSendKey;
  246. ArrayList SendParams = new ArrayList();
  247. SendParams.Add(requestData);
  248. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  249. XmlRpcResponse GridResp = GridReq.Send(serversInfo.GridURL, 3000);
  250. Hashtable responseData = (Hashtable) GridResp.Value;
  251. if (responseData.ContainsKey("error"))
  252. {
  253. Console.WriteLine("error received from grid server" + responseData["error"]);
  254. return null;
  255. }
  256. uint regX = Convert.ToUInt32((string) responseData["region_locx"]);
  257. uint regY = Convert.ToUInt32((string) responseData["region_locy"]);
  258. string internalIpStr = (string) responseData["sim_ip"];
  259. uint port = Convert.ToUInt32(responseData["sim_port"]);
  260. string externalUri = (string) responseData["sim_uri"];
  261. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int) port);
  262. string neighbourExternalUri = externalUri;
  263. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, internalIpStr);
  264. regionInfo.RemotingPort = Convert.ToUInt32((string) responseData["remoting_port"]);
  265. regionInfo.RemotingAddress = internalIpStr;
  266. regionInfo.RegionID = new LLUUID((string) responseData["region_UUID"]);
  267. regionInfo.RegionName = (string) responseData["region_name"];
  268. m_remoteRegionInfoCache.Add(regionHandle, regionInfo);
  269. }
  270. catch (WebException)
  271. {
  272. MainLog.Instance.Error("GRID",
  273. "Region lookup failed for: " + regionHandle.ToString() +
  274. " - Is the GridServer down?");
  275. return null;
  276. }
  277. }
  278. return regionInfo;
  279. }
  280. /// <summary>
  281. ///
  282. /// </summary>
  283. /// <param name="minX"></param>
  284. /// <param name="minY"></param>
  285. /// <param name="maxX"></param>
  286. /// <param name="maxY"></param>
  287. /// <returns></returns>
  288. public List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
  289. {
  290. int temp = 0;
  291. if (minX > maxX)
  292. {
  293. temp = minX;
  294. minX = maxX;
  295. maxX = temp;
  296. }
  297. if (minY > maxY)
  298. {
  299. temp = minY;
  300. minY = maxY;
  301. maxY = temp;
  302. }
  303. Hashtable respData = MapBlockQuery(minX, minY, maxX, maxY);
  304. List<MapBlockData> neighbours = new List<MapBlockData>();
  305. foreach (ArrayList a in respData.Values)
  306. {
  307. foreach (Hashtable n in a)
  308. {
  309. MapBlockData neighbour = new MapBlockData();
  310. neighbour.X = Convert.ToUInt16(n["x"]);
  311. neighbour.Y = Convert.ToUInt16(n["y"]);
  312. neighbour.Name = (string) n["name"];
  313. neighbour.Access = Convert.ToByte(n["access"]);
  314. neighbour.RegionFlags = Convert.ToUInt32(n["region-flags"]);
  315. neighbour.WaterHeight = Convert.ToByte(n["water-height"]);
  316. neighbour.MapImageId = new LLUUID((string) n["map-image-id"]);
  317. neighbours.Add(neighbour);
  318. }
  319. }
  320. return neighbours;
  321. }
  322. /// <summary>
  323. /// Performs a XML-RPC query against the grid server returning mapblock information in the specified coordinates
  324. /// </summary>
  325. /// <remarks>REDUNDANT - OGS1 is to be phased out in favour of OGS2</remarks>
  326. /// <param name="minX">Minimum X value</param>
  327. /// <param name="minY">Minimum Y value</param>
  328. /// <param name="maxX">Maximum X value</param>
  329. /// <param name="maxY">Maximum Y value</param>
  330. /// <returns>Hashtable of hashtables containing map data elements</returns>
  331. private Hashtable MapBlockQuery(int minX, int minY, int maxX, int maxY)
  332. {
  333. Hashtable param = new Hashtable();
  334. param["xmin"] = minX;
  335. param["ymin"] = minY;
  336. param["xmax"] = maxX;
  337. param["ymax"] = maxY;
  338. IList parameters = new ArrayList();
  339. parameters.Add(param);
  340. try
  341. {
  342. XmlRpcRequest req = new XmlRpcRequest("map_block", parameters);
  343. XmlRpcResponse resp = req.Send(serversInfo.GridURL, 10000);
  344. Hashtable respData = (Hashtable) resp.Value;
  345. return respData;
  346. }
  347. catch (Exception e)
  348. {
  349. MainLog.Instance.Error("MapBlockQuery XMLRPC failure: " + e.ToString());
  350. return new Hashtable();
  351. }
  352. }
  353. /// <summary>
  354. /// A ping / version check
  355. /// </summary>
  356. /// <param name="request"></param>
  357. /// <returns></returns>
  358. public XmlRpcResponse PingCheckReply(XmlRpcRequest request)
  359. {
  360. XmlRpcResponse response = new XmlRpcResponse();
  361. Hashtable respData = new Hashtable();
  362. respData["online"] = "true";
  363. m_localBackend.PingCheckReply(respData);
  364. response.Value = respData;
  365. return response;
  366. }
  367. // Grid Request Processing
  368. /// <summary>
  369. ///
  370. /// </summary>
  371. /// <param name="request"></param>
  372. /// <returns></returns>
  373. public XmlRpcResponse ExpectUser(XmlRpcRequest request)
  374. {
  375. Console.WriteLine("Expecting User...");
  376. Hashtable requestData = (Hashtable) request.Params[0];
  377. AgentCircuitData agentData = new AgentCircuitData();
  378. agentData.SessionID = new LLUUID((string) requestData["session_id"]);
  379. agentData.SecureSessionID = new LLUUID((string) requestData["secure_session_id"]);
  380. agentData.firstname = (string) requestData["firstname"];
  381. agentData.lastname = (string) requestData["lastname"];
  382. agentData.AgentID = new LLUUID((string) requestData["agent_id"]);
  383. agentData.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
  384. agentData.CapsPath = (string) requestData["caps_path"];
  385. agentData.ClientVersion = (string)requestData["version"]; //rex
  386. if (requestData.ContainsKey("auth_addr")) {
  387. agentData.authenticationAddr = (string)requestData["auth_addr"];
  388. }
  389. if (requestData.ContainsKey("as_addr")) {
  390. agentData.asAddress = (string)requestData["as_addr"];
  391. }
  392. if (requestData.ContainsKey("child_agent") && requestData["child_agent"].Equals("1"))
  393. {
  394. agentData.child = true;
  395. }
  396. else
  397. {
  398. agentData.startpos =
  399. new LLVector3(Convert.ToUInt32(requestData["startpos_x"]),
  400. Convert.ToUInt32(requestData["startpos_y"]),
  401. Convert.ToUInt32(requestData["startpos_z"]));
  402. agentData.child = false;
  403. }
  404. ulong regionHandle = Convert.ToUInt64((string) requestData["regionhandle"]);
  405. m_localBackend.TriggerExpectUser(regionHandle, agentData);
  406. MainLog.Instance.Verbose("GRID", "Welcoming new user...");
  407. return new XmlRpcResponse();
  408. }
  409. #region m_interRegion Comms
  410. /// <summary>
  411. ///
  412. /// </summary>
  413. private void StartRemoting()
  414. {
  415. TcpChannel ch = new TcpChannel((int) NetworkServersInfo.RemotingListenerPort);
  416. ChannelServices.RegisterChannel(ch, false); // Disabled security as Mono doesnt support this.
  417. WellKnownServiceTypeEntry wellType =
  418. new WellKnownServiceTypeEntry(typeof (OGS1InterRegionRemoting), "InterRegions",
  419. WellKnownObjectMode.Singleton);
  420. RemotingConfiguration.RegisterWellKnownServiceType(wellType);
  421. InterRegionSingleton.Instance.OnArrival += TriggerExpectAvatarCrossing;
  422. InterRegionSingleton.Instance.OnChildAgent += IncomingChildAgent;
  423. InterRegionSingleton.Instance.OnPrimGroupArrival += IncomingPrim;
  424. InterRegionSingleton.Instance.OnPrimGroupNear += TriggerExpectPrimCrossing;
  425. InterRegionSingleton.Instance.OnRegionUp += TriggerRegionUp;
  426. InterRegionSingleton.Instance.OnChildAgentUpdate += TriggerChildAgentUpdate;
  427. //InterRegionSingleton.Instance.OnRegionUp += RegionUp;
  428. }
  429. #region Methods called by regions in this instance
  430. public bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
  431. {
  432. RegionInfo regInfo = null;
  433. try
  434. {
  435. if (m_localBackend.ChildAgentUpdate(regionHandle, cAgentData))
  436. {
  437. return true;
  438. }
  439. regInfo = RequestNeighbourInfo(regionHandle);
  440. if (regInfo != null)
  441. {
  442. //don't want to be creating a new link to the remote instance every time like we are here
  443. bool retValue = false;
  444. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
  445. typeof (OGS1InterRegionRemoting),
  446. "tcp://" + regInfo.RemotingAddress +
  447. ":" + regInfo.RemotingPort +
  448. "/InterRegions");
  449. if (remObject != null)
  450. {
  451. retValue = remObject.ChildAgentUpdate(regionHandle, cAgentData);
  452. }
  453. else
  454. {
  455. Console.WriteLine("remoting object not found");
  456. }
  457. remObject = null;
  458. MainLog.Instance.Verbose("INTER",
  459. gdebugRegionName +
  460. ": OGS1 tried to Update Child Agent data on outside region and got " +
  461. retValue.ToString());
  462. return retValue;
  463. }
  464. return false;
  465. }
  466. catch (RemotingException e)
  467. {
  468. MainLog.Instance.Warn("Remoting Error: Unable to connect to adjacent region: " + regInfo.RegionName +
  469. " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  470. MainLog.Instance.Debug(e.ToString());
  471. return false;
  472. }
  473. catch (SocketException e)
  474. {
  475. MainLog.Instance.Warn("Socket Error: Unable to connect to adjacent region: " + regInfo.RegionName + " " +
  476. regInfo.RegionLocX + "," + regInfo.RegionLocY);
  477. MainLog.Instance.Debug(e.ToString());
  478. return false;
  479. }
  480. catch (InvalidCredentialException e)
  481. {
  482. MainLog.Instance.Warn("Invalid Credentials: Unable to connect to adjacent region: " + regInfo.RegionName +
  483. " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  484. MainLog.Instance.Debug(e.ToString());
  485. return false;
  486. }
  487. catch (AuthenticationException e)
  488. {
  489. MainLog.Instance.Warn("Authentication exception: Unable to connect to adjacent region: " +
  490. regInfo.RegionName + " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  491. MainLog.Instance.Debug(e.ToString());
  492. return false;
  493. }
  494. catch (Exception e)
  495. {
  496. MainLog.Instance.Warn("Unknown exception: Unable to connect to adjacent region: " + regInfo.RegionName +
  497. " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  498. MainLog.Instance.Debug(e.ToString());
  499. return false;
  500. }
  501. }
  502. /// <summary>
  503. ///
  504. /// </summary>
  505. /// <param name="regionHandle"></param>
  506. /// <param name="agentData"></param>
  507. /// <returns></returns>
  508. public bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData)
  509. {
  510. RegionInfo regInfo = null;
  511. try
  512. {
  513. if (m_localBackend.InformRegionOfChildAgent(regionHandle, agentData))
  514. {
  515. return true;
  516. }
  517. regInfo = RequestNeighbourInfo(regionHandle);
  518. if (regInfo != null)
  519. {
  520. //don't want to be creating a new link to the remote instance every time like we are here
  521. bool retValue = false;
  522. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
  523. typeof (OGS1InterRegionRemoting),
  524. "tcp://" + regInfo.RemotingAddress +
  525. ":" + regInfo.RemotingPort +
  526. "/InterRegions");
  527. if (remObject != null)
  528. {
  529. retValue = remObject.InformRegionOfChildAgent(regionHandle, new sAgentCircuitData(agentData));
  530. }
  531. else
  532. {
  533. Console.WriteLine("remoting object not found");
  534. }
  535. remObject = null;
  536. MainLog.Instance.Verbose("INTER",
  537. gdebugRegionName + ": OGS1 tried to InformRegionOfChildAgent for " +
  538. agentData.firstname + " " + agentData.lastname + " and got " +
  539. retValue.ToString());
  540. return retValue;
  541. }
  542. return false;
  543. }
  544. catch (RemotingException e)
  545. {
  546. MainLog.Instance.Warn("Remoting Error: Unable to connect to adjacent region: " + regInfo.RegionName +
  547. " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  548. MainLog.Instance.Debug(e.ToString());
  549. return false;
  550. }
  551. catch (SocketException e)
  552. {
  553. MainLog.Instance.Warn("Socket Error: Unable to connect to adjacent region: " + regInfo.RegionName + " " +
  554. regInfo.RegionLocX + "," + regInfo.RegionLocY);
  555. MainLog.Instance.Debug(e.ToString());
  556. return false;
  557. }
  558. catch (InvalidCredentialException e)
  559. {
  560. MainLog.Instance.Warn("Invalid Credentials: Unable to connect to adjacent region: " + regInfo.RegionName +
  561. " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  562. MainLog.Instance.Debug(e.ToString());
  563. return false;
  564. }
  565. catch (AuthenticationException e)
  566. {
  567. MainLog.Instance.Warn("Authentication exception: Unable to connect to adjacent region: " +
  568. regInfo.RegionName + " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  569. MainLog.Instance.Debug(e.ToString());
  570. return false;
  571. }
  572. catch (Exception e)
  573. {
  574. MainLog.Instance.Warn("Unknown exception: Unable to connect to adjacent region: " + regInfo.RegionName +
  575. " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  576. MainLog.Instance.Debug(e.ToString());
  577. return false;
  578. }
  579. }
  580. // UGLY!
  581. public bool RegionUp(SearializableRegionInfo region, ulong regionhandle)
  582. {
  583. SearializableRegionInfo regInfo = null;
  584. try
  585. {
  586. // You may ask why this is in here...
  587. // The region asking the grid services about itself..
  588. // And, surprisingly, the reason is.. it doesn't know
  589. // it's own remoting port! How special.
  590. region = new SearializableRegionInfo(RequestNeighbourInfo(region.RegionHandle));
  591. region.RemotingAddress = region.ExternalHostName;
  592. region.RemotingPort = NetworkServersInfo.RemotingListenerPort;
  593. if (m_localBackend.RegionUp(region, regionhandle))
  594. {
  595. return true;
  596. }
  597. regInfo = new SearializableRegionInfo(RequestNeighbourInfo(regionhandle));
  598. if (regInfo != null)
  599. {
  600. // If we're not trying to remote to ourselves.
  601. if (regInfo.RemotingAddress != region.RemotingAddress && region.RemotingAddress != null)
  602. {
  603. //don't want to be creating a new link to the remote instance every time like we are here
  604. bool retValue = false;
  605. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
  606. typeof (
  607. OGS1InterRegionRemoting),
  608. "tcp://" +
  609. regInfo.RemotingAddress +
  610. ":" + regInfo.RemotingPort +
  611. "/InterRegions");
  612. if (remObject != null)
  613. {
  614. retValue = remObject.RegionUp(region, regionhandle);
  615. }
  616. else
  617. {
  618. Console.WriteLine("remoting object not found");
  619. }
  620. remObject = null;
  621. MainLog.Instance.Verbose("INTER", gdebugRegionName + ": OGS1 tried to inform region I'm up");
  622. return retValue;
  623. }
  624. else
  625. {
  626. // We're trying to inform ourselves via remoting.
  627. // This is here because we're looping over the listeners before we get here.
  628. // Odd but it should work.
  629. return true;
  630. }
  631. }
  632. return false;
  633. }
  634. catch (RemotingException e)
  635. {
  636. MainLog.Instance.Warn("Remoting Error: Unable to connect to adjacent region using tcp://" +
  637. regInfo.RemotingAddress +
  638. ":" + regInfo.RemotingPort +
  639. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
  640. " - Is this neighbor up?");
  641. MainLog.Instance.Debug(e.ToString());
  642. return false;
  643. }
  644. catch (SocketException e)
  645. {
  646. MainLog.Instance.Warn("Socket Error: Unable to connect to adjacent region using tcp://" +
  647. regInfo.RemotingAddress +
  648. ":" + regInfo.RemotingPort +
  649. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
  650. " - Is this neighbor up?");
  651. MainLog.Instance.Debug(e.ToString());
  652. return false;
  653. }
  654. catch (InvalidCredentialException e)
  655. {
  656. MainLog.Instance.Warn("Invalid Credentials: Unable to connect to adjacent region using tcp://" +
  657. regInfo.RemotingAddress +
  658. ":" + regInfo.RemotingPort +
  659. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  660. MainLog.Instance.Debug(e.ToString());
  661. return false;
  662. }
  663. catch (AuthenticationException e)
  664. {
  665. MainLog.Instance.Warn("Authentication exception: Unable to connect to adjacent region using tcp://" +
  666. regInfo.RemotingAddress +
  667. ":" + regInfo.RemotingPort +
  668. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  669. MainLog.Instance.Debug(e.ToString());
  670. return false;
  671. }
  672. catch (Exception e)
  673. {
  674. // This line errors with a Null Reference Exception.. Why? @.@
  675. //MainLog.Instance.Warn("Unknown exception: Unable to connect to adjacent region using tcp://" + regInfo.RemotingAddress +
  676. // ":" + regInfo.RemotingPort +
  677. //"/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY + " - This is likely caused by an incompatibility in the protocol between this sim and that one");
  678. MainLog.Instance.Debug(e.ToString());
  679. return false;
  680. }
  681. }
  682. /// <summary>
  683. ///
  684. /// </summary>
  685. /// <param name="regionHandle"></param>
  686. /// <param name="agentData"></param>
  687. /// <returns></returns>
  688. public bool InformRegionOfPrimCrossing(ulong regionHandle, LLUUID primID, string objData)
  689. {
  690. RegionInfo regInfo = null;
  691. try
  692. {
  693. if (m_localBackend.InformRegionOfPrimCrossing(regionHandle, primID, objData))
  694. {
  695. return true;
  696. }
  697. regInfo = RequestNeighbourInfo(regionHandle);
  698. if (regInfo != null)
  699. {
  700. //don't want to be creating a new link to the remote instance every time like we are here
  701. bool retValue = false;
  702. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
  703. typeof (OGS1InterRegionRemoting),
  704. "tcp://" + regInfo.RemotingAddress +
  705. ":" + regInfo.RemotingPort +
  706. "/InterRegions");
  707. if (remObject != null)
  708. {
  709. retValue = remObject.InformRegionOfPrimCrossing(regionHandle, primID.UUID, objData);
  710. }
  711. else
  712. {
  713. Console.WriteLine("remoting object not found");
  714. }
  715. remObject = null;
  716. return retValue;
  717. }
  718. return false;
  719. }
  720. catch (RemotingException e)
  721. {
  722. MainLog.Instance.Warn("Remoting Error: Unable to connect to adjacent region: " + regInfo.RegionName +
  723. " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  724. MainLog.Instance.Debug(e.ToString());
  725. return false;
  726. }
  727. catch (SocketException e)
  728. {
  729. MainLog.Instance.Warn("Socket Error: Unable to connect to adjacent region: " + regInfo.RegionName + " " +
  730. regInfo.RegionLocX + "," + regInfo.RegionLocY);
  731. MainLog.Instance.Debug(e.ToString());
  732. return false;
  733. }
  734. catch (InvalidCredentialException e)
  735. {
  736. MainLog.Instance.Warn("Invalid Credentials: Unable to connect to adjacent region: " + regInfo.RegionName +
  737. " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  738. MainLog.Instance.Debug(e.ToString());
  739. return false;
  740. }
  741. catch (AuthenticationException e)
  742. {
  743. MainLog.Instance.Warn("Authentication exception: Unable to connect to adjacent region: " +
  744. regInfo.RegionName + " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  745. MainLog.Instance.Debug(e.ToString());
  746. return false;
  747. }
  748. catch (Exception e)
  749. {
  750. MainLog.Instance.Warn("Unknown exception: Unable to connect to adjacent region: " + regInfo.RegionName +
  751. " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  752. MainLog.Instance.Debug(e.ToString());
  753. return false;
  754. }
  755. }
  756. /// <summary>
  757. ///
  758. /// </summary>
  759. /// <param name="regionHandle"></param>
  760. /// <param name="agentID"></param>
  761. /// <param name="position"></param>
  762. /// <returns></returns>
  763. public bool ExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying)
  764. {
  765. RegionInfo regInfo = null;
  766. try
  767. {
  768. if (m_localBackend.TriggerExpectAvatarCrossing(regionHandle, agentID, position, isFlying))
  769. {
  770. return true;
  771. }
  772. regInfo = RequestNeighbourInfo(regionHandle);
  773. if (regInfo != null)
  774. {
  775. bool retValue = false;
  776. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
  777. typeof (OGS1InterRegionRemoting),
  778. "tcp://" + regInfo.RemotingAddress +
  779. ":" + regInfo.RemotingPort +
  780. "/InterRegions");
  781. if (remObject != null)
  782. {
  783. retValue =
  784. remObject.ExpectAvatarCrossing(regionHandle, agentID.UUID, new sLLVector3(position),
  785. isFlying);
  786. }
  787. else
  788. {
  789. Console.WriteLine("remoting object not found");
  790. }
  791. remObject = null;
  792. return retValue;
  793. }
  794. //TODO need to see if we know about where this region is and use .net remoting
  795. // to inform it.
  796. return false;
  797. }
  798. catch (RemotingException e)
  799. {
  800. MainLog.Instance.Warn("Remoting Error: Unable to connect to adjacent region: " + regInfo.RegionName +
  801. " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  802. MainLog.Instance.Debug(e.ToString());
  803. return false;
  804. }
  805. catch
  806. {
  807. return false;
  808. }
  809. }
  810. public bool ExpectPrimCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isPhysical)
  811. {
  812. RegionInfo regInfo = null;
  813. try
  814. {
  815. if (m_localBackend.TriggerExpectPrimCrossing(regionHandle, agentID, position, isPhysical))
  816. {
  817. return true;
  818. }
  819. regInfo = RequestNeighbourInfo(regionHandle);
  820. if (regInfo != null)
  821. {
  822. bool retValue = false;
  823. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
  824. typeof (OGS1InterRegionRemoting),
  825. "tcp://" + regInfo.RemotingAddress +
  826. ":" + regInfo.RemotingPort +
  827. "/InterRegions");
  828. if (remObject != null)
  829. {
  830. retValue =
  831. remObject.ExpectAvatarCrossing(regionHandle, agentID.UUID, new sLLVector3(position),
  832. isPhysical);
  833. }
  834. else
  835. {
  836. Console.WriteLine("remoting object not found");
  837. }
  838. remObject = null;
  839. return retValue;
  840. }
  841. //TODO need to see if we know about where this region is and use .net remoting
  842. // to inform it.
  843. return false;
  844. }
  845. catch (RemotingException e)
  846. {
  847. MainLog.Instance.Warn("Remoting Error: Unable to connect to adjacent region: " + regInfo.RegionName +
  848. " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  849. MainLog.Instance.Debug(e.ToString());
  850. return false;
  851. }
  852. catch
  853. {
  854. return false;
  855. }
  856. }
  857. public void TellRegionToCloseChildConnection(ulong regionHandle, LLUUID agentID)
  858. {
  859. }
  860. public bool AcknowledgeAgentCrossed(ulong regionHandle, LLUUID agentId)
  861. {
  862. return m_localBackend.AcknowledgeAgentCrossed(regionHandle, agentId);
  863. }
  864. public bool AcknowledgePrimCrossed(ulong regionHandle, LLUUID primId)
  865. {
  866. return m_localBackend.AcknowledgePrimCrossed(regionHandle, primId);
  867. }
  868. #endregion
  869. #region Methods triggered by calls from external instances
  870. /// <summary>
  871. ///
  872. /// </summary>
  873. /// <param name="regionHandle"></param>
  874. /// <param name="agentData"></param>
  875. /// <returns></returns>
  876. public bool IncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
  877. {
  878. //MainLog.Instance.Verbose("INTER", gdebugRegionName + ": Incoming OGS1 Agent " + agentData.firstname + " " + agentData.lastname);
  879. try
  880. {
  881. return m_localBackend.IncomingChildAgent(regionHandle, agentData);
  882. }
  883. catch (RemotingException)
  884. {
  885. //MainLog.Instance.Error("Remoting Error: Unable to connect to adjacent region.\n" + e.ToString());
  886. return false;
  887. }
  888. }
  889. public bool TriggerRegionUp(SearializableRegionInfo regionData, ulong regionhandle)
  890. {
  891. MainLog.Instance.Verbose("INTER",
  892. gdebugRegionName + "Incoming OGS1 RegionUpReport: " + "(" + regionData.RegionLocX +
  893. "," + regionData.RegionLocY + ")");
  894. try
  895. {
  896. return m_localBackend.TriggerRegionUp(new RegionInfo(regionData), regionhandle);
  897. }
  898. catch (RemotingException e)
  899. {
  900. MainLog.Instance.Error("Remoting Error: Unable to connect to adjacent region.\n" + e.ToString());
  901. return false;
  902. }
  903. }
  904. public bool TriggerChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
  905. {
  906. MainLog.Instance.Verbose("INTER", "Incoming OGS1 Child Agent Data Update");
  907. try
  908. {
  909. return m_localBackend.TriggerChildAgentUpdate(regionHandle, cAgentData);
  910. }
  911. catch (RemotingException e)
  912. {
  913. MainLog.Instance.Error("Remoting Error: Unable to connect to adjacent region.\n" + e.ToString());
  914. return false;
  915. }
  916. }
  917. /// <summary>
  918. ///
  919. /// </summary>
  920. /// <param name="regionHandle"></param>
  921. /// <param name="agentData"></param>
  922. /// <returns></returns>
  923. public bool IncomingPrim(ulong regionHandle, LLUUID primID, string objData)
  924. {
  925. // Is this necessary?
  926. try
  927. {
  928. //return m_localBackend.TriggerExpectPrim(regionHandle,primID, objData);
  929. //m_localBackend.
  930. return false;
  931. }
  932. catch (RemotingException e)
  933. {
  934. MainLog.Instance.Error("Remoting Error: Unable to connect to adjacent region.\n" + e.ToString());
  935. return false;
  936. }
  937. }
  938. /// <summary>
  939. ///
  940. /// </summary>
  941. /// <param name="regionHandle"></param>
  942. /// <param name="agentID"></param>
  943. /// <param name="position"></param>
  944. /// <returns></returns>
  945. public bool TriggerExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying)
  946. {
  947. try
  948. {
  949. return m_localBackend.TriggerExpectAvatarCrossing(regionHandle, agentID, position, isFlying);
  950. }
  951. catch (RemotingException e)
  952. {
  953. MainLog.Instance.Error("Remoting Error: Unable to connect to adjacent region.\n" + e.ToString());
  954. return false;
  955. }
  956. }
  957. public bool TriggerExpectPrimCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isPhysical)
  958. {
  959. try
  960. {
  961. return m_localBackend.TriggerExpectPrimCrossing(regionHandle, agentID, position, isPhysical);
  962. }
  963. catch (RemotingException e)
  964. {
  965. MainLog.Instance.Error("Remoting Error: Unable to connect to adjacent region.\n" + e.ToString());
  966. return false;
  967. }
  968. }
  969. #endregion
  970. #endregion
  971. }
  972. }