OGS1GridServices.cs 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891
  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. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Net;
  32. using System.Net.Sockets;
  33. using System.Reflection;
  34. using System.Runtime.Remoting;
  35. using System.Runtime.Remoting.Channels;
  36. using System.Runtime.Remoting.Channels.Tcp;
  37. using System.Security.Authentication;
  38. using System.Threading;
  39. using OpenMetaverse;
  40. using log4net;
  41. using Nini.Config;
  42. using Nwc.XmlRpc;
  43. using OpenSim.Framework;
  44. using OpenSim.Framework.Communications;
  45. using OpenSim.Framework.Servers;
  46. using OpenSim.Region.Communications.Local;
  47. namespace OpenSim.Region.Communications.OGS1
  48. {
  49. public class OGS1GridServices : IGridServices, IInterRegionCommunications
  50. {
  51. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  52. /// <summary>
  53. /// Encapsulate local backend services for manipulation of local regions
  54. /// </summary>
  55. private LocalBackEndServices m_localBackend = new LocalBackEndServices();
  56. private Dictionary<ulong, RegionInfo> m_remoteRegionInfoCache = new Dictionary<ulong, RegionInfo>();
  57. // private List<SimpleRegionInfo> m_knownRegions = new List<SimpleRegionInfo>();
  58. private Dictionary<ulong, int> m_deadRegionCache = new Dictionary<ulong, int>();
  59. private Dictionary<string, string> m_queuedGridSettings = new Dictionary<string, string>();
  60. private List<RegionInfo> m_regionsOnInstance = new List<RegionInfo>();
  61. public BaseHttpServer httpListener;
  62. public NetworkServersInfo serversInfo;
  63. public BaseHttpServer httpServer;
  64. public string gdebugRegionName
  65. {
  66. get { return m_localBackend.gdebugRegionName; }
  67. set { m_localBackend.gdebugRegionName = value; }
  68. }
  69. public string rdebugRegionName
  70. {
  71. get { return _rdebugRegionName; }
  72. set { _rdebugRegionName = value; }
  73. }
  74. private string _rdebugRegionName = String.Empty;
  75. public bool RegionLoginsEnabled
  76. {
  77. get { return m_localBackend.RegionLoginsEnabled; }
  78. set { m_localBackend.RegionLoginsEnabled = value; }
  79. }
  80. /// <summary>
  81. /// Contructor. Adds "expect_user" and "check" xmlrpc method handlers
  82. /// </summary>
  83. /// <param name="servers_info"></param>
  84. /// <param name="httpServe"></param>
  85. public OGS1GridServices(NetworkServersInfo servers_info, BaseHttpServer httpServe)
  86. {
  87. serversInfo = servers_info;
  88. httpServer = httpServe;
  89. //Respond to Grid Services requests
  90. httpServer.AddXmlRPCHandler("expect_user", ExpectUser);
  91. httpServer.AddXmlRPCHandler("logoff_user", LogOffUser);
  92. httpServer.AddXmlRPCHandler("check", PingCheckReply);
  93. httpServer.AddXmlRPCHandler("land_data", LandData);
  94. StartRemoting();
  95. }
  96. // see IGridServices
  97. public RegionCommsListener RegisterRegion(RegionInfo regionInfo)
  98. {
  99. m_regionsOnInstance.Add(regionInfo);
  100. m_log.InfoFormat(
  101. "[OGS1 GRID SERVICES]: Attempting to register region {0} with grid at {1}",
  102. regionInfo.RegionName, serversInfo.GridURL);
  103. Hashtable GridParams = new Hashtable();
  104. // Login / Authentication
  105. GridParams["authkey"] = serversInfo.GridSendKey;
  106. GridParams["recvkey"] = serversInfo.GridRecvKey;
  107. GridParams["UUID"] = regionInfo.RegionID.ToString();
  108. GridParams["sim_ip"] = regionInfo.ExternalHostName;
  109. GridParams["sim_port"] = regionInfo.InternalEndPoint.Port.ToString();
  110. GridParams["region_locx"] = regionInfo.RegionLocX.ToString();
  111. GridParams["region_locy"] = regionInfo.RegionLocY.ToString();
  112. GridParams["sim_name"] = regionInfo.RegionName;
  113. GridParams["http_port"] = serversInfo.HttpListenerPort.ToString();
  114. GridParams["remoting_port"] = NetworkServersInfo.RemotingListenerPort.ToString();
  115. GridParams["map-image-id"] = regionInfo.RegionSettings.TerrainImageID.ToString();
  116. GridParams["originUUID"] = regionInfo.originRegionID.ToString();
  117. GridParams["server_uri"] = regionInfo.ServerURI;
  118. GridParams["region_secret"] = regionInfo.regionSecret;
  119. GridParams["major_interface_version"] = VersionInfo.MajorInterfaceVersion.ToString();
  120. if (regionInfo.MasterAvatarAssignedUUID != UUID.Zero)
  121. GridParams["master_avatar_uuid"] = regionInfo.MasterAvatarAssignedUUID.ToString();
  122. else
  123. GridParams["master_avatar_uuid"] = regionInfo.EstateSettings.EstateOwner.ToString();
  124. // Package into an XMLRPC Request
  125. ArrayList SendParams = new ArrayList();
  126. SendParams.Add(GridParams);
  127. // Send Request
  128. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_login", SendParams);
  129. XmlRpcResponse GridResp;
  130. try
  131. {
  132. // The timeout should always be significantly larger than the timeout for the grid server to request
  133. // the initial status of the region before confirming registration.
  134. GridResp = GridReq.Send(serversInfo.GridURL, 90000);
  135. }
  136. catch (Exception e)
  137. {
  138. Exception e2
  139. = new Exception(
  140. String.Format(
  141. "Unable to register region with grid at {0}. Grid service not running?",
  142. serversInfo.GridURL),
  143. e);
  144. throw e2;
  145. }
  146. Hashtable GridRespData = (Hashtable)GridResp.Value;
  147. // Hashtable griddatahash = GridRespData;
  148. // Process Response
  149. if (GridRespData.ContainsKey("error"))
  150. {
  151. string errorstring = (string) GridRespData["error"];
  152. Exception e = new Exception(
  153. String.Format("Unable to connect to grid at {0}: {1}", serversInfo.GridURL, errorstring));
  154. throw e;
  155. }
  156. else
  157. {
  158. // m_knownRegions = RequestNeighbours(regionInfo.RegionLocX, regionInfo.RegionLocY);
  159. if (GridRespData.ContainsKey("allow_forceful_banlines"))
  160. {
  161. if ((string) GridRespData["allow_forceful_banlines"] != "TRUE")
  162. {
  163. //m_localBackend.SetForcefulBanlistsDisallowed(regionInfo.RegionHandle);
  164. m_queuedGridSettings.Add("allow_forceful_banlines", "FALSE");
  165. }
  166. }
  167. m_log.InfoFormat(
  168. "[OGS1 GRID SERVICES]: Region {0} successfully registered with grid at {1}",
  169. regionInfo.RegionName, serversInfo.GridURL);
  170. }
  171. return m_localBackend.RegisterRegion(regionInfo);
  172. }
  173. // see IGridServices
  174. public bool DeregisterRegion(RegionInfo regionInfo)
  175. {
  176. Hashtable GridParams = new Hashtable();
  177. GridParams["UUID"] = regionInfo.RegionID.ToString();
  178. // Package into an XMLRPC Request
  179. ArrayList SendParams = new ArrayList();
  180. SendParams.Add(GridParams);
  181. // Send Request
  182. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_after_region_moved", SendParams);
  183. XmlRpcResponse GridResp = null;
  184. try
  185. {
  186. GridResp = GridReq.Send(serversInfo.GridURL, 10000);
  187. }
  188. catch (Exception e)
  189. {
  190. Exception e2
  191. = new Exception(
  192. String.Format(
  193. "Unable to deregister region with grid at {0}. Grid service not running?",
  194. serversInfo.GridURL),
  195. e);
  196. throw e2;
  197. }
  198. Hashtable GridRespData = (Hashtable) GridResp.Value;
  199. // Hashtable griddatahash = GridRespData;
  200. // Process Response
  201. if (GridRespData != null && GridRespData.ContainsKey("error"))
  202. {
  203. string errorstring = (string)GridRespData["error"];
  204. m_log.Error("Unable to connect to grid: " + errorstring);
  205. return false;
  206. }
  207. return m_localBackend.DeregisterRegion(regionInfo);
  208. }
  209. public virtual Dictionary<string, string> GetGridSettings()
  210. {
  211. Dictionary<string, string> returnGridSettings = new Dictionary<string, string>();
  212. lock (m_queuedGridSettings)
  213. {
  214. foreach (string Dictkey in m_queuedGridSettings.Keys)
  215. {
  216. returnGridSettings.Add(Dictkey, m_queuedGridSettings[Dictkey]);
  217. }
  218. m_queuedGridSettings.Clear();
  219. }
  220. return returnGridSettings;
  221. }
  222. // see IGridServices
  223. public List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
  224. {
  225. Hashtable respData = MapBlockQuery((int) x - 1, (int) y - 1, (int) x + 1, (int) y + 1);
  226. List<SimpleRegionInfo> neighbours = new List<SimpleRegionInfo>();
  227. foreach (ArrayList neighboursList in respData.Values)
  228. {
  229. foreach (Hashtable neighbourData in neighboursList)
  230. {
  231. uint regX = Convert.ToUInt32(neighbourData["x"]);
  232. uint regY = Convert.ToUInt32(neighbourData["y"]);
  233. if ((x != regX) || (y != regY))
  234. {
  235. string simIp = (string) neighbourData["sim_ip"];
  236. uint port = Convert.ToUInt32(neighbourData["sim_port"]);
  237. // string externalUri = (string) neighbourData["sim_uri"];
  238. // string externalIpStr = String.Empty;
  239. try
  240. {
  241. // externalIpStr = Util.GetHostFromDNS(simIp).ToString();
  242. Util.GetHostFromDNS(simIp).ToString();
  243. }
  244. catch (SocketException e)
  245. {
  246. m_log.WarnFormat(
  247. "[OGS1 GRID SERVICES]: RequestNeighbours(): Lookup of neighbour {0} failed! Not including in neighbours list. {1}",
  248. simIp, e);
  249. continue;
  250. }
  251. SimpleRegionInfo sri = new SimpleRegionInfo(regX, regY, simIp, port);
  252. sri.RemotingPort = Convert.ToUInt32(neighbourData["remoting_port"]);
  253. if (neighbourData.ContainsKey("http_port"))
  254. {
  255. sri.HttpPort = Convert.ToUInt32(neighbourData["http_port"]);
  256. }
  257. else
  258. {
  259. m_log.Error("[OGS1 GRID SERVICES]: Couldn't find httpPort, using default 9000; please upgrade your grid-server to r7621 or later");
  260. sri.HttpPort = 9000; // that's the default and will probably be wrong
  261. }
  262. sri.RegionID = new UUID((string) neighbourData["uuid"]);
  263. neighbours.Add(sri);
  264. }
  265. }
  266. }
  267. return neighbours;
  268. }
  269. /// <summary>
  270. /// Request information about a region.
  271. /// </summary>
  272. /// <param name="regionHandle"></param>
  273. /// <returns>
  274. /// null on a failure to contact or get a response from the grid server
  275. /// FIXME: Might be nicer to return a proper exception here since we could inform the client more about the
  276. /// nature of the faiulre.
  277. /// </returns>
  278. public RegionInfo RequestNeighbourInfo(UUID Region_UUID)
  279. {
  280. // don't ask the gridserver about regions on this instance...
  281. foreach (RegionInfo info in m_regionsOnInstance)
  282. {
  283. if (info.RegionID == Region_UUID) return info;
  284. }
  285. // didn't find it so far, we have to go the long way
  286. RegionInfo regionInfo;
  287. Hashtable requestData = new Hashtable();
  288. requestData["region_UUID"] = Region_UUID.ToString();
  289. requestData["authkey"] = serversInfo.GridSendKey;
  290. ArrayList SendParams = new ArrayList();
  291. SendParams.Add(requestData);
  292. XmlRpcRequest gridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  293. XmlRpcResponse gridResp = null;
  294. try
  295. {
  296. gridResp = gridReq.Send(serversInfo.GridURL, 3000);
  297. }
  298. catch (Exception e)
  299. {
  300. m_log.ErrorFormat(
  301. "[OGS1 GRID SERVICES]: Communication with the grid server at {0} failed, {1}",
  302. serversInfo.GridURL, e);
  303. return null;
  304. }
  305. Hashtable responseData = (Hashtable)gridResp.Value;
  306. if (responseData.ContainsKey("error"))
  307. {
  308. m_log.WarnFormat("[OGS1 GRID SERVICES]: Error received from grid server: {0}", responseData["error"]);
  309. return null;
  310. }
  311. regionInfo = buildRegionInfo(responseData, String.Empty);
  312. if (requestData.ContainsKey("regionHandle"))
  313. {
  314. m_remoteRegionInfoCache.Add(Convert.ToUInt64((string) requestData["regionHandle"]), regionInfo);
  315. }
  316. return regionInfo;
  317. }
  318. /// <summary>
  319. /// Request information about a region.
  320. /// </summary>
  321. /// <param name="regionHandle"></param>
  322. /// <returns></returns>
  323. public RegionInfo RequestNeighbourInfo(ulong regionHandle)
  324. {
  325. RegionInfo regionInfo = m_localBackend.RequestNeighbourInfo(regionHandle);
  326. if (regionInfo != null)
  327. {
  328. return regionInfo;
  329. }
  330. if (!m_remoteRegionInfoCache.TryGetValue(regionHandle, out regionInfo))
  331. {
  332. try
  333. {
  334. Hashtable requestData = new Hashtable();
  335. requestData["region_handle"] = regionHandle.ToString();
  336. requestData["authkey"] = serversInfo.GridSendKey;
  337. ArrayList SendParams = new ArrayList();
  338. SendParams.Add(requestData);
  339. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  340. XmlRpcResponse GridResp = GridReq.Send(serversInfo.GridURL, 3000);
  341. Hashtable responseData = (Hashtable) GridResp.Value;
  342. if (responseData.ContainsKey("error"))
  343. {
  344. m_log.Error("[OGS1 GRID SERVICES]: Error received from grid server: " + responseData["error"]);
  345. return null;
  346. }
  347. uint regX = Convert.ToUInt32((string) responseData["region_locx"]);
  348. uint regY = Convert.ToUInt32((string) responseData["region_locy"]);
  349. string externalHostName = (string) responseData["sim_ip"];
  350. uint port = Convert.ToUInt32(responseData["sim_port"]);
  351. // string externalUri = (string) responseData["sim_uri"];
  352. //IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int) port);
  353. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(externalHostName), (int)port);
  354. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, externalHostName);
  355. regionInfo.RemotingPort = Convert.ToUInt32((string) responseData["remoting_port"]);
  356. regionInfo.RemotingAddress = externalHostName;
  357. if (responseData.ContainsKey("http_port"))
  358. {
  359. regionInfo.HttpPort = Convert.ToUInt32((string) responseData["http_port"]);
  360. }
  361. regionInfo.RegionID = new UUID((string) responseData["region_UUID"]);
  362. regionInfo.RegionName = (string) responseData["region_name"];
  363. lock (m_remoteRegionInfoCache)
  364. {
  365. if (!m_remoteRegionInfoCache.ContainsKey(regionHandle))
  366. {
  367. m_remoteRegionInfoCache.Add(regionHandle, regionInfo);
  368. }
  369. }
  370. }
  371. catch (Exception e)
  372. {
  373. m_log.Error("[OGS1 GRID SERVICES]: " +
  374. "Region lookup failed for: " + regionHandle.ToString() +
  375. " - Is the GridServer down?" + e.ToString());
  376. return null;
  377. }
  378. }
  379. return regionInfo;
  380. }
  381. public RegionInfo RequestClosestRegion(string regionName)
  382. {
  383. foreach (RegionInfo ri in m_remoteRegionInfoCache.Values)
  384. {
  385. if (ri.RegionName == regionName)
  386. return ri;
  387. }
  388. RegionInfo regionInfo = null;
  389. try
  390. {
  391. Hashtable requestData = new Hashtable();
  392. requestData["region_name_search"] = regionName;
  393. requestData["authkey"] = serversInfo.GridSendKey;
  394. ArrayList SendParams = new ArrayList();
  395. SendParams.Add(requestData);
  396. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  397. XmlRpcResponse GridResp = GridReq.Send(serversInfo.GridURL, 3000);
  398. Hashtable responseData = (Hashtable) GridResp.Value;
  399. if (responseData.ContainsKey("error"))
  400. {
  401. m_log.ErrorFormat("[OGS1 GRID SERVICES]: Error received from grid server: ", responseData["error"]);
  402. return null;
  403. }
  404. regionInfo = buildRegionInfo(responseData, "");
  405. if (!m_remoteRegionInfoCache.ContainsKey(regionInfo.RegionHandle))
  406. m_remoteRegionInfoCache.Add(regionInfo.RegionHandle, regionInfo);
  407. }
  408. catch
  409. {
  410. m_log.Error("[OGS1 GRID SERVICES]: " +
  411. "Region lookup failed for: " + regionName +
  412. " - Is the GridServer down?");
  413. }
  414. return regionInfo;
  415. }
  416. /// <summary>
  417. ///
  418. /// </summary>
  419. /// <param name="minX"></param>
  420. /// <param name="minY"></param>
  421. /// <param name="maxX"></param>
  422. /// <param name="maxY"></param>
  423. /// <returns></returns>
  424. public List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
  425. {
  426. int temp = 0;
  427. if (minX > maxX)
  428. {
  429. temp = minX;
  430. minX = maxX;
  431. maxX = temp;
  432. }
  433. if (minY > maxY)
  434. {
  435. temp = minY;
  436. minY = maxY;
  437. maxY = temp;
  438. }
  439. Hashtable respData = MapBlockQuery(minX, minY, maxX, maxY);
  440. List<MapBlockData> neighbours = new List<MapBlockData>();
  441. foreach (ArrayList a in respData.Values)
  442. {
  443. foreach (Hashtable n in a)
  444. {
  445. MapBlockData neighbour = new MapBlockData();
  446. neighbour.X = Convert.ToUInt16(n["x"]);
  447. neighbour.Y = Convert.ToUInt16(n["y"]);
  448. neighbour.Name = (string) n["name"];
  449. neighbour.Access = Convert.ToByte(n["access"]);
  450. neighbour.RegionFlags = Convert.ToUInt32(n["region-flags"]);
  451. neighbour.WaterHeight = Convert.ToByte(n["water-height"]);
  452. neighbour.MapImageId = new UUID((string) n["map-image-id"]);
  453. neighbours.Add(neighbour);
  454. }
  455. }
  456. return neighbours;
  457. }
  458. /// <summary>
  459. /// Performs a XML-RPC query against the grid server returning mapblock information in the specified coordinates
  460. /// </summary>
  461. /// <remarks>REDUNDANT - OGS1 is to be phased out in favour of OGS2</remarks>
  462. /// <param name="minX">Minimum X value</param>
  463. /// <param name="minY">Minimum Y value</param>
  464. /// <param name="maxX">Maximum X value</param>
  465. /// <param name="maxY">Maximum Y value</param>
  466. /// <returns>Hashtable of hashtables containing map data elements</returns>
  467. private Hashtable MapBlockQuery(int minX, int minY, int maxX, int maxY)
  468. {
  469. Hashtable param = new Hashtable();
  470. param["xmin"] = minX;
  471. param["ymin"] = minY;
  472. param["xmax"] = maxX;
  473. param["ymax"] = maxY;
  474. IList parameters = new ArrayList();
  475. parameters.Add(param);
  476. try
  477. {
  478. XmlRpcRequest req = new XmlRpcRequest("map_block", parameters);
  479. XmlRpcResponse resp = req.Send(serversInfo.GridURL, 10000);
  480. Hashtable respData = (Hashtable) resp.Value;
  481. return respData;
  482. }
  483. catch (Exception e)
  484. {
  485. m_log.Error("MapBlockQuery XMLRPC failure: " + e);
  486. return new Hashtable();
  487. }
  488. }
  489. /// <summary>
  490. /// A ping / version check
  491. /// </summary>
  492. /// <param name="request"></param>
  493. /// <returns></returns>
  494. public XmlRpcResponse PingCheckReply(XmlRpcRequest request)
  495. {
  496. XmlRpcResponse response = new XmlRpcResponse();
  497. Hashtable respData = new Hashtable();
  498. respData["online"] = "true";
  499. m_localBackend.PingCheckReply(respData);
  500. response.Value = respData;
  501. return response;
  502. }
  503. /// <summary>
  504. /// Received from the user server when a user starts logging in. This call allows
  505. /// the region to prepare for direct communication from the client. Sends back an empty
  506. /// xmlrpc response on completion.
  507. /// </summary>
  508. /// <param name="request"></param>
  509. /// <returns></returns>
  510. public XmlRpcResponse ExpectUser(XmlRpcRequest request)
  511. {
  512. Hashtable requestData = (Hashtable) request.Params[0];
  513. AgentCircuitData agentData = new AgentCircuitData();
  514. agentData.SessionID = new UUID((string) requestData["session_id"]);
  515. agentData.SecureSessionID = new UUID((string) requestData["secure_session_id"]);
  516. agentData.firstname = (string) requestData["firstname"];
  517. agentData.lastname = (string) requestData["lastname"];
  518. agentData.AgentID = new UUID((string) requestData["agent_id"]);
  519. agentData.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
  520. agentData.CapsPath = (string) requestData["caps_path"];
  521. ulong regionHandle = Convert.ToUInt64((string) requestData["regionhandle"]);
  522. m_log.DebugFormat(
  523. "[CLIENT]: Told by user service to prepare for a connection from {0} {1} {2}, circuit {3}",
  524. agentData.firstname, agentData.lastname, agentData.AgentID, agentData.circuitcode);
  525. if (requestData.ContainsKey("child_agent") && requestData["child_agent"].Equals("1"))
  526. {
  527. //m_log.Debug("[CLIENT]: Child agent detected");
  528. agentData.child = true;
  529. }
  530. else
  531. {
  532. //m_log.Debug("[CLIENT]: Main agent detected");
  533. agentData.startpos =
  534. new Vector3((float)Convert.ToDecimal((string)requestData["startpos_x"]),
  535. (float)Convert.ToDecimal((string)requestData["startpos_y"]),
  536. (float)Convert.ToDecimal((string)requestData["startpos_z"]));
  537. agentData.child = false;
  538. }
  539. XmlRpcResponse resp = new XmlRpcResponse();
  540. if (!RegionLoginsEnabled)
  541. {
  542. m_log.InfoFormat(
  543. "[CLIENT]: Denying access for user {0} {1} because region login is currently disabled",
  544. agentData.firstname, agentData.lastname);
  545. Hashtable respdata = new Hashtable();
  546. respdata["success"] = "FALSE";
  547. respdata["reason"] = "region login currently disabled";
  548. resp.Value = respdata;
  549. }
  550. else
  551. {
  552. RegionInfo[] regions = m_regionsOnInstance.ToArray();
  553. bool banned = false;
  554. for (int i = 0; i < regions.Length; i++)
  555. {
  556. if (regions[i] != null)
  557. {
  558. if (regions[i].RegionHandle == regionHandle)
  559. {
  560. if (regions[i].EstateSettings.IsBanned(agentData.AgentID))
  561. {
  562. banned = true;
  563. break;
  564. }
  565. }
  566. }
  567. }
  568. if (banned)
  569. {
  570. m_log.InfoFormat(
  571. "[CLIENT]: Denying access for user {0} {1} because user is banned",
  572. agentData.firstname, agentData.lastname);
  573. Hashtable respdata = new Hashtable();
  574. respdata["success"] = "FALSE";
  575. respdata["reason"] = "banned";
  576. resp.Value = respdata;
  577. }
  578. else
  579. {
  580. m_localBackend.TriggerExpectUser(regionHandle, agentData);
  581. Hashtable respdata = new Hashtable();
  582. respdata["success"] = "TRUE";
  583. resp.Value = respdata;
  584. }
  585. }
  586. return resp;
  587. }
  588. // Grid Request Processing
  589. /// <summary>
  590. /// Ooops, our Agent must be dead if we're getting this request!
  591. /// </summary>
  592. /// <param name="request"></param>
  593. /// <returns></returns>
  594. public XmlRpcResponse LogOffUser(XmlRpcRequest request)
  595. {
  596. m_log.Debug("[CONNECTION DEBUGGING]: LogOff User Called");
  597. Hashtable requestData = (Hashtable)request.Params[0];
  598. string message = (string)requestData["message"];
  599. UUID agentID = UUID.Zero;
  600. UUID RegionSecret = UUID.Zero;
  601. UUID.TryParse((string)requestData["agent_id"], out agentID);
  602. UUID.TryParse((string)requestData["region_secret"], out RegionSecret);
  603. ulong regionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
  604. m_localBackend.TriggerLogOffUser(regionHandle, agentID, RegionSecret,message);
  605. return new XmlRpcResponse();
  606. }
  607. #region m_interRegion Comms
  608. /// <summary>
  609. /// Start listening for .net remoting calls from other regions.
  610. /// </summary>
  611. private void StartRemoting()
  612. {
  613. TcpChannel ch;
  614. try
  615. {
  616. ch = new TcpChannel((int)NetworkServersInfo.RemotingListenerPort);
  617. ChannelServices.RegisterChannel(ch, false); // Disabled security as Mono doesn't support this.
  618. }
  619. catch (Exception ex)
  620. {
  621. m_log.Error("[OGS1 GRID SERVICES]: Exception while attempting to listen on TCP port " + (int)NetworkServersInfo.RemotingListenerPort + ".");
  622. throw (ex);
  623. }
  624. WellKnownServiceTypeEntry wellType =
  625. new WellKnownServiceTypeEntry(typeof (OGS1InterRegionRemoting), "InterRegions",
  626. WellKnownObjectMode.Singleton);
  627. RemotingConfiguration.RegisterWellKnownServiceType(wellType);
  628. InterRegionSingleton.Instance.OnArrival += TriggerExpectAvatarCrossing;
  629. InterRegionSingleton.Instance.OnChildAgent += IncomingChildAgent;
  630. InterRegionSingleton.Instance.OnPrimGroupArrival += IncomingPrim;
  631. InterRegionSingleton.Instance.OnPrimGroupNear += TriggerExpectPrimCrossing;
  632. InterRegionSingleton.Instance.OnRegionUp += TriggerRegionUp;
  633. InterRegionSingleton.Instance.OnChildAgentUpdate += TriggerChildAgentUpdate;
  634. InterRegionSingleton.Instance.OnTellRegionToCloseChildConnection += TriggerTellRegionToCloseChildConnection;
  635. }
  636. #region Methods called by regions in this instance
  637. public bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
  638. {
  639. int failures = 0;
  640. lock (m_deadRegionCache)
  641. {
  642. if (m_deadRegionCache.ContainsKey(regionHandle))
  643. {
  644. failures = m_deadRegionCache[regionHandle];
  645. }
  646. }
  647. if (failures <= 3)
  648. {
  649. RegionInfo regInfo = null;
  650. try
  651. {
  652. if (m_localBackend.ChildAgentUpdate(regionHandle, cAgentData))
  653. {
  654. return true;
  655. }
  656. regInfo = RequestNeighbourInfo(regionHandle);
  657. if (regInfo != null)
  658. {
  659. //don't want to be creating a new link to the remote instance every time like we are here
  660. bool retValue = false;
  661. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
  662. typeof(OGS1InterRegionRemoting),
  663. "tcp://" + regInfo.RemotingAddress +
  664. ":" + regInfo.RemotingPort +
  665. "/InterRegions");
  666. if (remObject != null)
  667. {
  668. retValue = remObject.ChildAgentUpdate(regionHandle, cAgentData);
  669. }
  670. else
  671. {
  672. m_log.Warn("[OGS1 GRID SERVICES]: remoting object not found");
  673. }
  674. remObject = null;
  675. // m_log.Info("[INTER]: " +
  676. // gdebugRegionName +
  677. // ": OGS1 tried to Update Child Agent data on outside region and got " +
  678. // retValue.ToString());
  679. return retValue;
  680. }
  681. NoteDeadRegion(regionHandle);
  682. return false;
  683. }
  684. catch (RemotingException e)
  685. {
  686. NoteDeadRegion(regionHandle);
  687. m_log.WarnFormat(
  688. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  689. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  690. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  691. return false;
  692. }
  693. catch (SocketException e)
  694. {
  695. NoteDeadRegion(regionHandle);
  696. m_log.WarnFormat(
  697. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  698. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  699. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  700. return false;
  701. }
  702. catch (InvalidCredentialException e)
  703. {
  704. NoteDeadRegion(regionHandle);
  705. m_log.WarnFormat(
  706. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  707. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  708. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  709. return false;
  710. }
  711. catch (AuthenticationException e)
  712. {
  713. NoteDeadRegion(regionHandle);
  714. m_log.WarnFormat(
  715. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  716. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  717. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  718. return false;
  719. }
  720. catch (Exception e)
  721. {
  722. NoteDeadRegion(regionHandle);
  723. m_log.WarnFormat("[OGS1 GRID SERVICES]: Unable to connect to adjacent region: {0} {1},{2}",
  724. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  725. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  726. return false;
  727. }
  728. }
  729. else
  730. {
  731. //m_log.Info("[INTERREGION]: Skipped Sending Child Update to a region because it failed too many times:" + regionHandle.ToString());
  732. return false;
  733. }
  734. }
  735. /// <summary>
  736. /// Inform a region that a child agent will be on the way from a client.
  737. /// </summary>
  738. /// <param name="regionHandle"></param>
  739. /// <param name="agentData"></param>
  740. /// <returns></returns>
  741. public bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData)
  742. {
  743. RegionInfo regInfo = null;
  744. try
  745. {
  746. if (m_localBackend.InformRegionOfChildAgent(regionHandle, agentData))
  747. {
  748. return true;
  749. }
  750. regInfo = RequestNeighbourInfo(regionHandle);
  751. if (regInfo != null)
  752. {
  753. //don't want to be creating a new link to the remote instance every time like we are here
  754. bool retValue = false;
  755. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
  756. typeof(OGS1InterRegionRemoting),
  757. "tcp://" + regInfo.RemotingAddress +
  758. ":" + regInfo.RemotingPort +
  759. "/InterRegions");
  760. if (remObject != null)
  761. {
  762. retValue = remObject.InformRegionOfChildAgent(regionHandle, new sAgentCircuitData(agentData));
  763. }
  764. else
  765. {
  766. m_log.Warn("[OGS1 GRID SERVICES]: remoting object not found");
  767. }
  768. remObject = null;
  769. m_log.Info("[OGS1 GRID SERVICES]: " +
  770. m_localBackend._gdebugRegionName + ": OGS1 tried to InformRegionOfChildAgent for " +
  771. agentData.firstname + " " + agentData.lastname + " and got " +
  772. retValue.ToString());
  773. return retValue;
  774. }
  775. NoteDeadRegion(regionHandle);
  776. return false;
  777. }
  778. catch (RemotingException e)
  779. {
  780. NoteDeadRegion(regionHandle);
  781. m_log.WarnFormat(
  782. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  783. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  784. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  785. return false;
  786. }
  787. catch (SocketException e)
  788. {
  789. NoteDeadRegion(regionHandle);
  790. m_log.WarnFormat(
  791. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  792. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  793. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  794. return false;
  795. }
  796. catch (InvalidCredentialException e)
  797. {
  798. NoteDeadRegion(regionHandle);
  799. m_log.WarnFormat(
  800. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  801. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  802. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  803. return false;
  804. }
  805. catch (AuthenticationException e)
  806. {
  807. NoteDeadRegion(regionHandle);
  808. m_log.WarnFormat(
  809. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  810. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  811. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  812. return false;
  813. }
  814. catch (Exception e)
  815. {
  816. NoteDeadRegion(regionHandle);
  817. if (regInfo != null)
  818. {
  819. m_log.WarnFormat(
  820. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  821. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  822. }
  823. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  824. return false;
  825. }
  826. }
  827. // UGLY!
  828. public bool RegionUp(SerializableRegionInfo region, ulong regionhandle)
  829. {
  830. SerializableRegionInfo regInfo = null;
  831. try
  832. {
  833. // You may ask why this is in here...
  834. // The region asking the grid services about itself..
  835. // And, surprisingly, the reason is.. it doesn't know
  836. // it's own remoting port! How special.
  837. RegionUpData regiondata = new RegionUpData(region.RegionLocX, region.RegionLocY, region.ExternalHostName, region.InternalEndPoint.Port);
  838. region = new SerializableRegionInfo(RequestNeighbourInfo(region.RegionHandle));
  839. region.RemotingAddress = region.ExternalHostName;
  840. region.RemotingPort = NetworkServersInfo.RemotingListenerPort;
  841. region.HttpPort = serversInfo.HttpListenerPort;
  842. if (m_localBackend.RegionUp(region, regionhandle))
  843. {
  844. return true;
  845. }
  846. regInfo = new SerializableRegionInfo(RequestNeighbourInfo(regionhandle));
  847. if (regInfo != null)
  848. {
  849. // If we're not trying to remote to ourselves.
  850. if (regInfo.RemotingAddress != region.RemotingAddress && region.RemotingAddress != null)
  851. {
  852. //don't want to be creating a new link to the remote instance every time like we are here
  853. bool retValue = false;
  854. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
  855. typeof(OGS1InterRegionRemoting),
  856. "tcp://" +
  857. regInfo.RemotingAddress +
  858. ":" + regInfo.RemotingPort +
  859. "/InterRegions");
  860. if (remObject != null)
  861. {
  862. retValue = remObject.RegionUp(regiondata, regionhandle);
  863. }
  864. else
  865. {
  866. m_log.Warn("[OGS1 GRID SERVICES]: remoting object not found");
  867. }
  868. remObject = null;
  869. m_log.Info(
  870. "[INTER]: " + m_localBackend._gdebugRegionName + ": OGS1 tried to inform region I'm up");
  871. return retValue;
  872. }
  873. else
  874. {
  875. // We're trying to inform ourselves via remoting.
  876. // This is here because we're looping over the listeners before we get here.
  877. // Odd but it should work.
  878. return true;
  879. }
  880. }
  881. return false;
  882. }
  883. catch (RemotingException e)
  884. {
  885. m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region using tcp://" +
  886. regInfo.RemotingAddress +
  887. ":" + regInfo.RemotingPort +
  888. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
  889. " - Is this neighbor up?");
  890. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  891. return false;
  892. }
  893. catch (SocketException e)
  894. {
  895. m_log.Warn("[OGS1 GRID SERVICES]: Socket Error: Unable to connect to adjacent region using tcp://" +
  896. regInfo.RemotingAddress +
  897. ":" + regInfo.RemotingPort +
  898. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
  899. " - Is this neighbor up?");
  900. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  901. return false;
  902. }
  903. catch (InvalidCredentialException e)
  904. {
  905. m_log.Warn("[OGS1 GRID SERVICES]: Invalid Credentials: Unable to connect to adjacent region using tcp://" +
  906. regInfo.RemotingAddress +
  907. ":" + regInfo.RemotingPort +
  908. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  909. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  910. return false;
  911. }
  912. catch (AuthenticationException e)
  913. {
  914. m_log.Warn("[OGS1 GRID SERVICES]: Authentication exception: Unable to connect to adjacent region using tcp://" +
  915. regInfo.RemotingAddress +
  916. ":" + regInfo.RemotingPort +
  917. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  918. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  919. return false;
  920. }
  921. catch (Exception e)
  922. {
  923. // This line errors with a Null Reference Exception.. Why? @.@
  924. //m_log.Warn("Unknown exception: Unable to connect to adjacent region using tcp://" + regInfo.RemotingAddress +
  925. // ":" + regInfo.RemotingPort +
  926. //"/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY + " - This is likely caused by an incompatibility in the protocol between this sim and that one");
  927. m_log.Debug(e.ToString());
  928. return false;
  929. }
  930. }
  931. /// <summary>
  932. ///
  933. /// </summary>
  934. /// <param name="regionHandle"></param>
  935. /// <param name="agentData"></param>
  936. /// <returns></returns>
  937. public bool InformRegionOfPrimCrossing(ulong regionHandle, UUID primID, string objData, int XMLMethod)
  938. {
  939. int failures = 0;
  940. lock (m_deadRegionCache)
  941. {
  942. if (m_deadRegionCache.ContainsKey(regionHandle))
  943. {
  944. failures = m_deadRegionCache[regionHandle];
  945. }
  946. }
  947. if (failures <= 1)
  948. {
  949. RegionInfo regInfo = null;
  950. try
  951. {
  952. if (m_localBackend.InformRegionOfPrimCrossing(regionHandle, primID, objData, XMLMethod))
  953. {
  954. return true;
  955. }
  956. regInfo = RequestNeighbourInfo(regionHandle);
  957. if (regInfo != null)
  958. {
  959. //don't want to be creating a new link to the remote instance every time like we are here
  960. bool retValue = false;
  961. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
  962. typeof(OGS1InterRegionRemoting),
  963. "tcp://" + regInfo.RemotingAddress +
  964. ":" + regInfo.RemotingPort +
  965. "/InterRegions");
  966. if (remObject != null)
  967. {
  968. m_log.DebugFormat("[INTERREGION]: Sending prim crossing message for prim {0}", primID.ToString());
  969. retValue = remObject.InformRegionOfPrimCrossing(regionHandle, primID.Guid, objData, XMLMethod);
  970. m_log.DebugFormat("[INTERREGION]: Return from prim crossing message for prim {0}: {1}", primID.ToString(), retValue.ToString());
  971. }
  972. else
  973. {
  974. m_log.Warn("[OGS1 GRID SERVICES]: Remoting object not found");
  975. }
  976. remObject = null;
  977. return retValue;
  978. }
  979. NoteDeadRegion(regionHandle);
  980. return false;
  981. }
  982. catch (RemotingException e)
  983. {
  984. NoteDeadRegion(regionHandle);
  985. m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
  986. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  987. return false;
  988. }
  989. catch (SocketException e)
  990. {
  991. NoteDeadRegion(regionHandle);
  992. m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
  993. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  994. return false;
  995. }
  996. catch (InvalidCredentialException e)
  997. {
  998. NoteDeadRegion(regionHandle);
  999. m_log.Warn("[OGS1 GRID SERVICES]: Invalid Credential Exception: Invalid Credentials : " + regionHandle);
  1000. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1001. return false;
  1002. }
  1003. catch (AuthenticationException e)
  1004. {
  1005. NoteDeadRegion(regionHandle);
  1006. m_log.Warn("[OGS1 GRID SERVICES]: Authentication exception: Unable to connect to adjacent region: " + regionHandle);
  1007. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1008. return false;
  1009. }
  1010. catch (Exception e)
  1011. {
  1012. NoteDeadRegion(regionHandle);
  1013. m_log.Warn("[OGS1 GRID SERVICES]: Unknown exception: Unable to connect to adjacent region: " + regionHandle);
  1014. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0}", e);
  1015. return false;
  1016. }
  1017. }
  1018. else
  1019. {
  1020. return false;
  1021. }
  1022. }
  1023. /// <summary>
  1024. ///
  1025. /// </summary>
  1026. /// <param name="regionHandle"></param>
  1027. /// <param name="agentID"></param>
  1028. /// <param name="position"></param>
  1029. /// <returns></returns>
  1030. public bool ExpectAvatarCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isFlying)
  1031. {
  1032. RegionInfo[] regions = m_regionsOnInstance.ToArray();
  1033. bool banned = false;
  1034. for (int i = 0; i < regions.Length; i++)
  1035. {
  1036. if (regions[i] != null)
  1037. {
  1038. if (regions[i].RegionHandle == regionHandle)
  1039. {
  1040. if (regions[i].EstateSettings.IsBanned(agentID))
  1041. {
  1042. banned = true;
  1043. break;
  1044. }
  1045. }
  1046. }
  1047. }
  1048. if (banned)
  1049. return false;
  1050. RegionInfo regInfo = null;
  1051. try
  1052. {
  1053. if (m_localBackend.TriggerExpectAvatarCrossing(regionHandle, agentID, position, isFlying))
  1054. {
  1055. return true;
  1056. }
  1057. regInfo = RequestNeighbourInfo(regionHandle);
  1058. if (regInfo != null)
  1059. {
  1060. bool retValue = false;
  1061. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
  1062. typeof (OGS1InterRegionRemoting),
  1063. "tcp://" + regInfo.RemotingAddress +
  1064. ":" + regInfo.RemotingPort +
  1065. "/InterRegions");
  1066. if (remObject != null)
  1067. {
  1068. retValue =
  1069. remObject.ExpectAvatarCrossing(regionHandle, agentID.Guid, new sLLVector3(position),
  1070. isFlying);
  1071. }
  1072. else
  1073. {
  1074. m_log.Warn("[OGS1 GRID SERVICES]: Remoting object not found");
  1075. }
  1076. remObject = null;
  1077. return retValue;
  1078. }
  1079. //TODO need to see if we know about where this region is and use .net remoting
  1080. // to inform it.
  1081. NoteDeadRegion(regionHandle);
  1082. return false;
  1083. }
  1084. catch (RemotingException e)
  1085. {
  1086. NoteDeadRegion(regionHandle);
  1087. m_log.WarnFormat(
  1088. "[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  1089. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  1090. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1091. return false;
  1092. }
  1093. catch
  1094. {
  1095. NoteDeadRegion(regionHandle);
  1096. return false;
  1097. }
  1098. }
  1099. public bool ExpectPrimCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isPhysical)
  1100. {
  1101. RegionInfo regInfo = null;
  1102. try
  1103. {
  1104. if (m_localBackend.TriggerExpectPrimCrossing(regionHandle, agentID, position, isPhysical))
  1105. {
  1106. return true;
  1107. }
  1108. regInfo = RequestNeighbourInfo(regionHandle);
  1109. if (regInfo != null)
  1110. {
  1111. bool retValue = false;
  1112. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting) Activator.GetObject(
  1113. typeof (OGS1InterRegionRemoting),
  1114. "tcp://" + regInfo.RemotingAddress +
  1115. ":" + regInfo.RemotingPort +
  1116. "/InterRegions");
  1117. if (remObject != null)
  1118. {
  1119. retValue =
  1120. remObject.ExpectAvatarCrossing(regionHandle, agentID.Guid, new sLLVector3(position),
  1121. isPhysical);
  1122. }
  1123. else
  1124. {
  1125. m_log.Warn("[OGS1 GRID SERVICES]: Remoting object not found");
  1126. }
  1127. remObject = null;
  1128. return retValue;
  1129. }
  1130. //TODO need to see if we know about where this region is and use .net remoting
  1131. // to inform it.
  1132. NoteDeadRegion(regionHandle);
  1133. return false;
  1134. }
  1135. catch (RemotingException e)
  1136. {
  1137. NoteDeadRegion(regionHandle);
  1138. m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
  1139. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1140. return false;
  1141. }
  1142. catch (SocketException e)
  1143. {
  1144. NoteDeadRegion(regionHandle);
  1145. m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region: " + regionHandle);
  1146. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1147. return false;
  1148. }
  1149. catch (InvalidCredentialException e)
  1150. {
  1151. NoteDeadRegion(regionHandle);
  1152. m_log.Warn("[OGS1 GRID SERVICES]: Invalid Credential Exception: Invalid Credentials : " + regionHandle);
  1153. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1154. return false;
  1155. }
  1156. catch (AuthenticationException e)
  1157. {
  1158. NoteDeadRegion(regionHandle);
  1159. m_log.Warn("[OGS1 GRID SERVICES]: Authentication exception: Unable to connect to adjacent region: " + regionHandle);
  1160. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1161. return false;
  1162. }
  1163. catch (Exception e)
  1164. {
  1165. NoteDeadRegion(regionHandle);
  1166. m_log.Warn("[OGS1 GRID SERVICES]: Unknown exception: Unable to connect to adjacent region: " + regionHandle);
  1167. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0}", e);
  1168. return false;
  1169. }
  1170. }
  1171. public bool TellRegionToCloseChildConnection(ulong regionHandle, UUID agentID)
  1172. {
  1173. RegionInfo regInfo = null;
  1174. try
  1175. {
  1176. if (m_localBackend.TriggerTellRegionToCloseChildConnection(regionHandle, agentID))
  1177. {
  1178. return true;
  1179. }
  1180. regInfo = RequestNeighbourInfo(regionHandle);
  1181. if (regInfo != null)
  1182. {
  1183. // bool retValue = false;
  1184. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
  1185. typeof(OGS1InterRegionRemoting),
  1186. "tcp://" + regInfo.RemotingAddress +
  1187. ":" + regInfo.RemotingPort +
  1188. "/InterRegions");
  1189. if (remObject != null)
  1190. {
  1191. // retValue =
  1192. remObject.TellRegionToCloseChildConnection(regionHandle, agentID.Guid);
  1193. }
  1194. else
  1195. {
  1196. m_log.Warn("[OGS1 GRID SERVICES]: Remoting object not found");
  1197. }
  1198. remObject = null;
  1199. return true;
  1200. }
  1201. //TODO need to see if we know about where this region is and use .net remoting
  1202. // to inform it.
  1203. NoteDeadRegion(regionHandle);
  1204. return false;
  1205. }
  1206. catch (RemotingException)
  1207. {
  1208. NoteDeadRegion(regionHandle);
  1209. m_log.Warn("[OGS1 GRID SERVICES]: Remoting Error: Unable to connect to adjacent region to tell it to close child agents: " + regInfo.RegionName +
  1210. " " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  1211. //m_log.Debug(e.ToString());
  1212. return false;
  1213. }
  1214. catch (SocketException e)
  1215. {
  1216. NoteDeadRegion(regionHandle);
  1217. m_log.Warn("[OGS1 GRID SERVICES]: Socket Error: Unable to connect to adjacent region using tcp://" +
  1218. regInfo.RemotingAddress +
  1219. ":" + regInfo.RemotingPort +
  1220. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
  1221. " - Is this neighbor up?");
  1222. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1223. return false;
  1224. }
  1225. catch (InvalidCredentialException e)
  1226. {
  1227. NoteDeadRegion(regionHandle);
  1228. m_log.Warn("[OGS1 GRID SERVICES]: Invalid Credentials: Unable to connect to adjacent region using tcp://" +
  1229. regInfo.RemotingAddress +
  1230. ":" + regInfo.RemotingPort +
  1231. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  1232. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1233. return false;
  1234. }
  1235. catch (AuthenticationException e)
  1236. {
  1237. NoteDeadRegion(regionHandle);
  1238. m_log.Warn("[OGS1 GRID SERVICES]: Authentication exception: Unable to connect to adjacent region using tcp://" +
  1239. regInfo.RemotingAddress +
  1240. ":" + regInfo.RemotingPort +
  1241. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  1242. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1243. return false;
  1244. }
  1245. catch (WebException e)
  1246. {
  1247. NoteDeadRegion(regionHandle);
  1248. m_log.Warn("[OGS1 GRID SERVICES]: WebException exception: Unable to connect to adjacent region using tcp://" +
  1249. regInfo.RemotingAddress +
  1250. ":" + regInfo.RemotingPort +
  1251. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  1252. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0} {1}", e.Source, e.Message);
  1253. return false;
  1254. }
  1255. catch (Exception e)
  1256. {
  1257. NoteDeadRegion(regionHandle);
  1258. // This line errors with a Null Reference Exception.. Why? @.@
  1259. //m_log.Warn("Unknown exception: Unable to connect to adjacent region using tcp://" + regInfo.RemotingAddress +
  1260. // ":" + regInfo.RemotingPort +
  1261. //"/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY + " - This is likely caused by an incompatibility in the protocol between this sim and that one");
  1262. m_log.DebugFormat("[OGS1 GRID SERVICES]: {0}", e);
  1263. return false;
  1264. }
  1265. }
  1266. public bool AcknowledgeAgentCrossed(ulong regionHandle, UUID agentId)
  1267. {
  1268. return m_localBackend.AcknowledgeAgentCrossed(regionHandle, agentId);
  1269. }
  1270. public bool AcknowledgePrimCrossed(ulong regionHandle, UUID primId)
  1271. {
  1272. return m_localBackend.AcknowledgePrimCrossed(regionHandle, primId);
  1273. }
  1274. #endregion
  1275. #region Methods triggered by calls from external instances
  1276. /// <summary>
  1277. ///
  1278. /// </summary>
  1279. /// <param name="regionHandle"></param>
  1280. /// <param name="agentData"></param>
  1281. /// <returns></returns>
  1282. public bool IncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
  1283. {
  1284. //m_log.Info("[INTER]: " + gdebugRegionName + ": Incoming OGS1 Agent " + agentData.firstname + " " + agentData.lastname);
  1285. return m_localBackend.IncomingChildAgent(regionHandle, agentData);
  1286. }
  1287. public bool TriggerRegionUp(RegionUpData regionData, ulong regionhandle)
  1288. {
  1289. m_log.Info(
  1290. "[OGS1 GRID SERVICES]: " +
  1291. m_localBackend._gdebugRegionName + "Incoming OGS1 RegionUpReport: " + "(" + regionData.X +
  1292. "," + regionData.Y + "). Giving this region a fresh set of 'dead' tries");
  1293. RegionInfo nRegionInfo = new RegionInfo();
  1294. nRegionInfo.SetEndPoint("127.0.0.1", regionData.PORT);
  1295. nRegionInfo.ExternalHostName = regionData.IPADDR;
  1296. nRegionInfo.RegionLocX = regionData.X;
  1297. nRegionInfo.RegionLocY = regionData.Y;
  1298. lock (m_deadRegionCache)
  1299. {
  1300. if (m_deadRegionCache.ContainsKey(nRegionInfo.RegionHandle))
  1301. {
  1302. m_deadRegionCache.Remove(nRegionInfo.RegionHandle);
  1303. }
  1304. }
  1305. return m_localBackend.TriggerRegionUp(nRegionInfo, regionhandle);
  1306. }
  1307. public bool TriggerChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
  1308. {
  1309. //m_log.Info("[INTER]: Incoming OGS1 Child Agent Data Update");
  1310. return m_localBackend.TriggerChildAgentUpdate(regionHandle, cAgentData);
  1311. }
  1312. /// <summary>
  1313. ///
  1314. /// </summary>
  1315. /// <param name="regionHandle"></param>
  1316. /// <param name="agentData"></param>
  1317. /// <returns></returns>
  1318. public bool IncomingPrim(ulong regionHandle, UUID primID, string objData, int XMLMethod)
  1319. {
  1320. m_log.DebugFormat("[INTERREGION]: Got prim crosssing request for {0}", primID);
  1321. m_localBackend.TriggerExpectPrim(regionHandle, primID, objData, XMLMethod);
  1322. return true;
  1323. }
  1324. /// <summary>
  1325. ///
  1326. /// </summary>
  1327. /// <param name="regionHandle"></param>
  1328. /// <param name="agentID"></param>
  1329. /// <param name="position"></param>
  1330. /// <returns></returns>
  1331. public bool TriggerExpectAvatarCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isFlying)
  1332. {
  1333. return m_localBackend.TriggerExpectAvatarCrossing(regionHandle, agentID, position, isFlying);
  1334. }
  1335. public bool TriggerExpectPrimCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isPhysical)
  1336. {
  1337. return m_localBackend.TriggerExpectPrimCrossing(regionHandle, agentID, position, isPhysical);
  1338. }
  1339. public bool TriggerTellRegionToCloseChildConnection(ulong regionHandle, UUID agentID)
  1340. {
  1341. return m_localBackend.TriggerTellRegionToCloseChildConnection(regionHandle, agentID);
  1342. }
  1343. #endregion
  1344. #endregion
  1345. int timeOut = 10; //10 seconds
  1346. /// <summary>
  1347. /// Check that a region is available for TCP comms. This is necessary for .NET remoting between regions.
  1348. /// </summary>
  1349. /// <param name="address"></param>
  1350. /// <param name="port"></param>
  1351. /// <param name="retry"></param>
  1352. /// <returns></returns>
  1353. public bool CheckRegion(string address, uint port, bool retry)
  1354. {
  1355. bool available = false;
  1356. bool timed_out = true;
  1357. IPAddress ia = Util.GetHostFromDNS(address);
  1358. IPEndPoint m_EndPoint;
  1359. try
  1360. {
  1361. m_EndPoint = new IPEndPoint(ia, (int)port);
  1362. }
  1363. catch (Exception)
  1364. {
  1365. m_log.Debug("[OGS1 GRID SERVICES]: Invalid remoting address: " + address);
  1366. return false;
  1367. }
  1368. AsyncCallback callback = delegate(IAsyncResult iar)
  1369. {
  1370. timed_out = false;
  1371. Socket s = (Socket)iar.AsyncState;
  1372. try
  1373. {
  1374. s.EndConnect(iar);
  1375. available = true;
  1376. }
  1377. catch (Exception e)
  1378. {
  1379. m_log.DebugFormat(
  1380. "[OGS1 GRID SERVICES]: Callback EndConnect exception: {0}:{1}", e.Message, e.StackTrace);
  1381. }
  1382. s.Close();
  1383. };
  1384. IAsyncResult ar;
  1385. try
  1386. {
  1387. Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  1388. ar = socket.BeginConnect(m_EndPoint, callback, socket);
  1389. ar.AsyncWaitHandle.WaitOne(timeOut * 1000, false);
  1390. }
  1391. catch (Exception e)
  1392. {
  1393. m_log.DebugFormat(
  1394. "[OGS1 GRID SERVICES]: CheckRegion Socket Setup exception: {0}:{1}", e.Message, e.StackTrace);
  1395. return false;
  1396. }
  1397. ar.AsyncWaitHandle.Close();
  1398. if (timed_out)
  1399. {
  1400. m_log.DebugFormat(
  1401. "[OGS1 GRID SERVICES]: socket [{0}] timed out ({1}) waiting to obtain a connection.",
  1402. m_EndPoint, timeOut * 1000);
  1403. if (retry)
  1404. {
  1405. return CheckRegion(address, port, false);
  1406. }
  1407. }
  1408. return available;
  1409. }
  1410. public bool CheckRegion(string address, uint port)
  1411. {
  1412. return CheckRegion(address, port, true);
  1413. }
  1414. public void NoteDeadRegion(ulong regionhandle)
  1415. {
  1416. lock (m_deadRegionCache)
  1417. {
  1418. if (m_deadRegionCache.ContainsKey(regionhandle))
  1419. {
  1420. m_deadRegionCache[regionhandle] = m_deadRegionCache[regionhandle] + 1;
  1421. }
  1422. else
  1423. {
  1424. m_deadRegionCache.Add(regionhandle, 1);
  1425. }
  1426. }
  1427. }
  1428. public LandData RequestLandData (ulong regionHandle, uint x, uint y)
  1429. {
  1430. m_log.DebugFormat("[OGS1 GRID SERVICES] requests land data in {0}, at {1}, {2}",
  1431. regionHandle, x, y);
  1432. LandData landData = m_localBackend.RequestLandData(regionHandle, x, y);
  1433. if (landData == null)
  1434. {
  1435. Hashtable hash = new Hashtable();
  1436. hash["region_handle"] = regionHandle.ToString();
  1437. hash["x"] = x.ToString();
  1438. hash["y"] = y.ToString();
  1439. IList paramList = new ArrayList();
  1440. paramList.Add(hash);
  1441. try
  1442. {
  1443. // this might be cached, as we probably requested it just a moment ago...
  1444. RegionInfo info = RequestNeighbourInfo(regionHandle);
  1445. if (info != null) // just to be sure
  1446. {
  1447. XmlRpcRequest request = new XmlRpcRequest("land_data", paramList);
  1448. string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
  1449. XmlRpcResponse response = request.Send(uri, 10000);
  1450. if (response.IsFault)
  1451. {
  1452. m_log.ErrorFormat("[OGS1 GRID SERVICES] remote call returned an error: {0}", response.FaultString);
  1453. }
  1454. else
  1455. {
  1456. hash = (Hashtable)response.Value;
  1457. try
  1458. {
  1459. landData = new LandData();
  1460. landData.AABBMax = Vector3.Parse((string)hash["AABBMax"]);
  1461. landData.AABBMin = Vector3.Parse((string)hash["AABBMin"]);
  1462. landData.Area = Convert.ToInt32(hash["Area"]);
  1463. landData.AuctionID = Convert.ToUInt32(hash["AuctionID"]);
  1464. landData.Description = (string)hash["Description"];
  1465. landData.Flags = Convert.ToUInt32(hash["Flags"]);
  1466. landData.GlobalID = new UUID((string)hash["GlobalID"]);
  1467. landData.Name = (string)hash["Name"];
  1468. landData.OwnerID = new UUID((string)hash["OwnerID"]);
  1469. landData.SalePrice = Convert.ToInt32(hash["SalePrice"]);
  1470. landData.SnapshotID = new UUID((string)hash["SnapshotID"]);
  1471. landData.UserLocation = Vector3.Parse((string)hash["UserLocation"]);
  1472. m_log.DebugFormat("[OGS1 GRID SERVICES] Got land data for parcel {0}", landData.Name);
  1473. }
  1474. catch (Exception e)
  1475. {
  1476. m_log.Error("[OGS1 GRID SERVICES] Got exception while parsing land-data:", e);
  1477. }
  1478. }
  1479. }
  1480. else m_log.WarnFormat("[OGS1 GRID SERVICES] Couldn't find region with handle {0}", regionHandle);
  1481. }
  1482. catch (Exception e)
  1483. {
  1484. m_log.ErrorFormat("[OGS1 GRID SERVICES] Couldn't contact region {0}: {1}", regionHandle, e);
  1485. }
  1486. }
  1487. return landData;
  1488. }
  1489. // Grid Request Processing
  1490. /// <summary>
  1491. /// Someone asked us about parcel-information
  1492. /// </summary>
  1493. /// <param name="request"></param>
  1494. /// <returns></returns>
  1495. public XmlRpcResponse LandData(XmlRpcRequest request)
  1496. {
  1497. Hashtable requestData = (Hashtable)request.Params[0];
  1498. ulong regionHandle = Convert.ToUInt64(requestData["region_handle"]);
  1499. uint x = Convert.ToUInt32(requestData["x"]);
  1500. uint y = Convert.ToUInt32(requestData["y"]);
  1501. m_log.DebugFormat("[OGS1 GRID SERVICES]: Got XML reqeuest for land data at {0}, {1} in region {2}", x, y, regionHandle);
  1502. LandData landData = m_localBackend.RequestLandData(regionHandle, x, y);
  1503. Hashtable hash = new Hashtable();
  1504. if (landData != null)
  1505. {
  1506. // for now, only push out the data we need for answering a ParcelInfoReqeust
  1507. hash["AABBMax"] = landData.AABBMax.ToString();
  1508. hash["AABBMin"] = landData.AABBMin.ToString();
  1509. hash["Area"] = landData.Area.ToString();
  1510. hash["AuctionID"] = landData.AuctionID.ToString();
  1511. hash["Description"] = landData.Description;
  1512. hash["Flags"] = landData.Flags.ToString();
  1513. hash["GlobalID"] = landData.GlobalID.ToString();
  1514. hash["Name"] = landData.Name;
  1515. hash["OwnerID"] = landData.OwnerID.ToString();
  1516. hash["SalePrice"] = landData.SalePrice.ToString();
  1517. hash["SnapshotID"] = landData.SnapshotID.ToString();
  1518. hash["UserLocation"] = landData.UserLocation.ToString();
  1519. }
  1520. XmlRpcResponse response = new XmlRpcResponse();
  1521. response.Value = hash;
  1522. return response;
  1523. }
  1524. public List<RegionInfo> RequestNamedRegions (string name, int maxNumber)
  1525. {
  1526. // no asking of the local backend first, here, as we have to ask the gridserver anyway.
  1527. Hashtable hash = new Hashtable();
  1528. hash["name"] = name;
  1529. hash["maxNumber"] = maxNumber.ToString();
  1530. IList paramList = new ArrayList();
  1531. paramList.Add(hash);
  1532. Hashtable result = XmlRpcSearchForRegionByName(paramList);
  1533. if (result == null) return null;
  1534. uint numberFound = Convert.ToUInt32(result["numFound"]);
  1535. List<RegionInfo> infos = new List<RegionInfo>();
  1536. for (int i = 0; i < numberFound; ++i)
  1537. {
  1538. string prefix = "region" + i + ".";
  1539. RegionInfo info = buildRegionInfo(result, prefix);
  1540. infos.Add(info);
  1541. }
  1542. return infos;
  1543. }
  1544. private RegionInfo buildRegionInfo(Hashtable responseData, string prefix)
  1545. {
  1546. uint regX = Convert.ToUInt32((string) responseData[prefix + "region_locx"]);
  1547. uint regY = Convert.ToUInt32((string) responseData[prefix + "region_locy"]);
  1548. string internalIpStr = (string) responseData[prefix + "sim_ip"];
  1549. uint port = Convert.ToUInt32(responseData[prefix + "sim_port"]);
  1550. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(internalIpStr), (int) port);
  1551. RegionInfo regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, internalIpStr);
  1552. regionInfo.RemotingPort = Convert.ToUInt32((string) responseData[prefix + "remoting_port"]);
  1553. regionInfo.RemotingAddress = internalIpStr;
  1554. if (responseData.ContainsKey(prefix + "http_port"))
  1555. {
  1556. regionInfo.HttpPort = Convert.ToUInt32((string) responseData[prefix + "http_port"]);
  1557. }
  1558. regionInfo.RegionID = new UUID((string) responseData[prefix + "region_UUID"]);
  1559. regionInfo.RegionName = (string) responseData[prefix + "region_name"];
  1560. regionInfo.RegionSettings.TerrainImageID = new UUID((string) responseData[prefix + "map_UUID"]);
  1561. return regionInfo;
  1562. }
  1563. private Hashtable XmlRpcSearchForRegionByName(IList parameters)
  1564. {
  1565. try
  1566. {
  1567. XmlRpcRequest request = new XmlRpcRequest("search_for_region_by_name", parameters);
  1568. XmlRpcResponse resp = request.Send(serversInfo.GridURL, 10000);
  1569. Hashtable respData = (Hashtable) resp.Value;
  1570. if (respData != null && respData.Contains("faultCode"))
  1571. {
  1572. m_log.WarnFormat("[OGS1 GRID SERVICES]: Got an error while contacting GridServer: {0}", respData["faultString"]);
  1573. return null;
  1574. }
  1575. return respData;
  1576. }
  1577. catch (Exception e)
  1578. {
  1579. m_log.Error("[OGS1 GRID SERVICES]: MapBlockQuery XMLRPC failure: ", e);
  1580. return null;
  1581. }
  1582. }
  1583. public List<UUID> InformFriendsInOtherRegion(UUID agentId, ulong destRegionHandle, List<UUID> friends, bool online)
  1584. {
  1585. List<UUID> tpdAway = new List<UUID>();
  1586. // destRegionHandle is a region on another server
  1587. RegionInfo info = RequestNeighbourInfo(destRegionHandle);
  1588. if (info != null)
  1589. {
  1590. string httpServer = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/presence_update_bulk";
  1591. Hashtable reqParams = new Hashtable();
  1592. reqParams["agentID"] = agentId.ToString();
  1593. reqParams["agentOnline"] = online;
  1594. int count = 0;
  1595. foreach (UUID uuid in friends)
  1596. {
  1597. reqParams["friendID_" + count++] = uuid.ToString();
  1598. }
  1599. reqParams["friendCount"] = count;
  1600. IList parameters = new ArrayList();
  1601. parameters.Add(reqParams);
  1602. try
  1603. {
  1604. XmlRpcRequest request = new XmlRpcRequest("presence_update_bulk", parameters);
  1605. XmlRpcResponse response = request.Send(httpServer, 5000);
  1606. Hashtable respData = (Hashtable)response.Value;
  1607. count = (int)respData["friendCount"];
  1608. for (int i = 0; i < count; ++i)
  1609. {
  1610. UUID uuid;
  1611. if (UUID.TryParse((string)respData["friendID_" + i], out uuid)) tpdAway.Add(uuid);
  1612. }
  1613. }
  1614. catch (Exception e)
  1615. {
  1616. m_log.Error("[OGS1 GRID SERVICES]: InformFriendsInOtherRegion XMLRPC failure: ", e);
  1617. }
  1618. }
  1619. else m_log.WarnFormat("[OGS1 GRID SERVICES]: Couldn't find region {0}???", destRegionHandle);
  1620. return tpdAway;
  1621. }
  1622. public bool TriggerTerminateFriend(ulong destRegionHandle, UUID agentID, UUID exFriendID)
  1623. {
  1624. // destRegionHandle is a region on another server
  1625. RegionInfo info = RequestNeighbourInfo(destRegionHandle);
  1626. if (info == null)
  1627. {
  1628. m_log.WarnFormat("[OGS1 GRID SERVICES]: Couldn't find region {0}", destRegionHandle);
  1629. return false; // region not found???
  1630. }
  1631. string httpServer = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/presence_update_bulk";
  1632. Hashtable reqParams = new Hashtable();
  1633. reqParams["agentID"] = agentID.ToString();
  1634. reqParams["friendID"] = exFriendID.ToString();
  1635. IList parameters = new ArrayList();
  1636. parameters.Add(reqParams);
  1637. try
  1638. {
  1639. XmlRpcRequest request = new XmlRpcRequest("terminate_friend", parameters);
  1640. XmlRpcResponse response = request.Send(httpServer, 5000);
  1641. Hashtable respData = (Hashtable)response.Value;
  1642. return (bool)respData["success"];
  1643. }
  1644. catch (Exception e)
  1645. {
  1646. m_log.Error("[OGS1 GRID SERVICES]: InformFriendsInOtherRegion XMLRPC failure: ", e);
  1647. return false;
  1648. }
  1649. }
  1650. }
  1651. }