HGGridServices.cs 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. /**
  2. * Copyright (c) 2008, Contributors. All rights reserved.
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * * Neither the name of the Organizations nor the names of Individual
  14. * Contributors may be used to endorse or promote products derived from
  15. * this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  20. * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  22. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  23. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  25. * OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. using System;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Drawing;
  32. using System.Drawing.Drawing2D;
  33. using System.Drawing.Imaging;
  34. using System.IO;
  35. using System.Net;
  36. using System.Net.Sockets;
  37. using System.Reflection;
  38. using System.Runtime.Remoting;
  39. using System.Runtime.Remoting.Channels;
  40. using System.Runtime.Remoting.Channels.Tcp;
  41. using System.Security.Authentication;
  42. using System.Threading;
  43. using OpenMetaverse;
  44. using OpenMetaverse.Imaging;
  45. using log4net;
  46. using Nwc.XmlRpc;
  47. using OpenSim.Framework;
  48. using OpenSim.Framework.Communications;
  49. using OpenSim.Framework.Communications.Cache;
  50. using OpenSim.Framework.Servers;
  51. using OpenSim.Region.Communications.Local;
  52. using OpenSim.Region.Communications.OGS1;
  53. using OpenSim.Region.Environment.Modules.Framework;
  54. using OpenSim.Region.Environment.Scenes;
  55. using OpenSim.Region.Interfaces;
  56. namespace OpenSim.Region.Communications.Hypergrid
  57. {
  58. /// <summary>
  59. /// This class encapsulates the main hypergrid functions related to creating and managing
  60. /// hyperlinks, as well as processing all the inter-region comms between a region and
  61. /// an hyperlinked region.
  62. /// </summary>
  63. public class HGGridServices : IGridServices, IInterRegionCommunications, IHyperlink
  64. {
  65. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  66. public BaseHttpServer httpListener;
  67. public NetworkServersInfo serversInfo;
  68. public BaseHttpServer httpServer;
  69. protected List<RegionInfo> m_regionsOnInstance = new List<RegionInfo>();
  70. // Hyperlink regions are hyperlinks on the map
  71. protected List<RegionInfo> m_hyperlinkRegions = new List<RegionInfo>();
  72. // Known regions are home regions of visiting foreign users.
  73. // They are not on the map as static hyperlinks. They are dynamic hyperlinks, they go away when
  74. // the visitor goes away. They are mapped to X=0 on the map.
  75. // This is key-ed on agent ID
  76. protected Dictionary<UUID, RegionInfo> m_knownRegions = new Dictionary<UUID, RegionInfo>();
  77. protected AssetCache m_assetcache;
  78. protected UserProfileCacheService m_userProfileCache;
  79. protected SceneManager m_sceneman;
  80. private Dictionary<string, string> m_queuedGridSettings = new Dictionary<string, string>();
  81. public virtual string gdebugRegionName
  82. {
  83. get { return "Override me"; }
  84. set { ; }
  85. }
  86. public string rdebugRegionName
  87. {
  88. get { return _rdebugRegionName; }
  89. set { _rdebugRegionName = value; }
  90. }
  91. private string _rdebugRegionName = String.Empty;
  92. public virtual bool RegionLoginsEnabled
  93. {
  94. get { return true; }
  95. set { ; }
  96. }
  97. public UserProfileCacheService UserProfileCache
  98. {
  99. set { m_userProfileCache = value; }
  100. }
  101. /// <summary>
  102. /// Contructor. Adds "expect_hg_user" and "check" xmlrpc method handlers
  103. /// </summary>
  104. /// <param name="servers_info"></param>
  105. /// <param name="httpServe"></param>
  106. public HGGridServices(NetworkServersInfo servers_info, BaseHttpServer httpServe, AssetCache asscache, SceneManager sman)
  107. {
  108. serversInfo = servers_info;
  109. httpServer = httpServe;
  110. m_assetcache = asscache;
  111. m_sceneman = sman;
  112. httpServer.AddXmlRPCHandler("link_region", LinkRegionRequest);
  113. httpServer.AddXmlRPCHandler("expect_hg_user", ExpectHGUser);
  114. HGNetworkServersInfo.Init(servers_info.AssetURL, servers_info.InventoryURL, servers_info.UserURL);
  115. }
  116. // see IGridServices
  117. public virtual RegionCommsListener RegisterRegion(RegionInfo regionInfo)
  118. {
  119. // Region doesn't exist here. Trying to link remote region
  120. m_log.Info("[HGrid]: Linking remote region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort );
  121. regionInfo.RegionID = LinkRegion(regionInfo); // UUID.Random();
  122. if (!regionInfo.RegionID.Equals(UUID.Zero))
  123. {
  124. m_hyperlinkRegions.Add(regionInfo);
  125. m_log.Info("[HGrid]: Successfully linked to region_uuid " + regionInfo.RegionID);
  126. //Try get the map image
  127. GetMapImage(regionInfo);
  128. }
  129. else
  130. {
  131. m_log.Info("[HGrid]: No such region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort + "(" + regionInfo.InternalEndPoint.Port + ")");
  132. }
  133. // Note that these remote regions aren't registered in localBackend, so return null, no local listeners
  134. return null;
  135. }
  136. // see IGridServices
  137. public virtual bool DeregisterRegion(RegionInfo regionInfo)
  138. {
  139. if (m_hyperlinkRegions.Contains(regionInfo))
  140. {
  141. m_hyperlinkRegions.Remove(regionInfo);
  142. return true;
  143. }
  144. foreach (KeyValuePair<UUID, RegionInfo> kvp in m_knownRegions)
  145. {
  146. if (kvp.Value == regionInfo)
  147. {
  148. m_knownRegions.Remove(kvp.Key);
  149. return true;
  150. }
  151. }
  152. return false;
  153. }
  154. public virtual Dictionary<string, string> GetGridSettings()
  155. {
  156. Dictionary<string, string> returnGridSettings = new Dictionary<string, string>();
  157. lock (m_queuedGridSettings)
  158. {
  159. foreach (string Dictkey in m_queuedGridSettings.Keys)
  160. {
  161. returnGridSettings.Add(Dictkey, m_queuedGridSettings[Dictkey]);
  162. }
  163. m_queuedGridSettings.Clear();
  164. }
  165. return returnGridSettings;
  166. }
  167. // see IGridServices
  168. public virtual List<SimpleRegionInfo> RequestNeighbours(uint x, uint y)
  169. {
  170. List<SimpleRegionInfo> neighbours = new List<SimpleRegionInfo>();
  171. foreach (RegionInfo reg in m_hyperlinkRegions)
  172. {
  173. if (reg.RegionLocX != x || reg.RegionLocY != y)
  174. {
  175. //Console.WriteLine("CommsManager- RequestNeighbours() - found a different region in list, checking location");
  176. if ((reg.RegionLocX > (x - 2)) && (reg.RegionLocX < (x + 2)))
  177. {
  178. if ((reg.RegionLocY > (y - 2)) && (reg.RegionLocY < (y + 2)))
  179. {
  180. neighbours.Add(reg);
  181. }
  182. }
  183. }
  184. }
  185. return neighbours;
  186. }
  187. /// <summary>
  188. /// Request information about a region.
  189. /// </summary>
  190. /// <param name="regionHandle"></param>
  191. /// <returns>
  192. /// null on a failure to contact or get a response from the grid server
  193. /// FIXME: Might be nicer to return a proper exception here since we could inform the client more about the
  194. /// nature of the faiulre.
  195. /// </returns>
  196. public virtual RegionInfo RequestNeighbourInfo(UUID Region_UUID)
  197. {
  198. foreach (RegionInfo info in m_hyperlinkRegions)
  199. {
  200. if (info.RegionID == Region_UUID) return info;
  201. }
  202. // I don't trust region uuids to be unique...
  203. //foreach (RegionInfo info in m_knownRegions.Values)
  204. //{
  205. // if (info.RegionID == Region_UUID) return info;
  206. //}
  207. return null;
  208. }
  209. /// <summary>
  210. /// Request information about a region.
  211. /// </summary>
  212. /// <param name="regionHandle"></param>
  213. /// <returns></returns>
  214. public virtual RegionInfo RequestNeighbourInfo(ulong regionHandle)
  215. {
  216. //Console.WriteLine("RequestNeighbourInfo for " + regionHandle);
  217. foreach (RegionInfo info in m_hyperlinkRegions)
  218. {
  219. //Console.WriteLine(" .. " + info.RegionHandle);
  220. if (info.RegionHandle == regionHandle) return info;
  221. }
  222. foreach (RegionInfo info in m_knownRegions.Values)
  223. {
  224. if (info.RegionHandle == regionHandle)
  225. {
  226. //Console.WriteLine("XXX------ Found known region " + info.RegionHandle);
  227. return info;
  228. }
  229. }
  230. return null;
  231. }
  232. public virtual RegionInfo RequestClosestRegion(string regionName)
  233. {
  234. foreach (RegionInfo info in m_hyperlinkRegions)
  235. {
  236. if (info.RegionName == regionName) return info;
  237. }
  238. return null;
  239. }
  240. /// <summary>
  241. ///
  242. /// </summary>
  243. /// <param name="minX"></param>
  244. /// <param name="minY"></param>
  245. /// <param name="maxX"></param>
  246. /// <param name="maxY"></param>
  247. /// <returns></returns>
  248. public virtual List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
  249. {
  250. List<MapBlockData> neighbours = new List<MapBlockData>();
  251. foreach (RegionInfo regInfo in m_hyperlinkRegions)
  252. {
  253. if (((regInfo.RegionLocX >= minX) && (regInfo.RegionLocX <= maxX)) &&
  254. ((regInfo.RegionLocY >= minY) && (regInfo.RegionLocY <= maxY)))
  255. {
  256. MapBlockData map = new MapBlockData();
  257. map.Name = regInfo.RegionName;
  258. map.X = (ushort)regInfo.RegionLocX;
  259. map.Y = (ushort)regInfo.RegionLocY;
  260. map.WaterHeight = (byte)regInfo.RegionSettings.WaterHeight;
  261. map.MapImageId = regInfo.RegionSettings.TerrainImageID;
  262. // Console.WriteLine("ImgID: " + map.MapImageId);
  263. map.Agents = 1;
  264. map.RegionFlags = 72458694;
  265. map.Access = 13;
  266. neighbours.Add(map);
  267. }
  268. }
  269. return neighbours;
  270. }
  271. protected virtual void GetMapImage(RegionInfo info)
  272. {
  273. try
  274. {
  275. string regionimage = "regionImage" + info.RegionID.ToString();
  276. regionimage = regionimage.Replace("-", "");
  277. WebClient c = new WebClient();
  278. string uri = "http://" + info.ExternalHostName + ":" + info.HttpPort + "/index.php?method=" + regionimage;
  279. //Console.WriteLine("JPEG: " + uri);
  280. c.DownloadFile(uri, info.RegionID.ToString() + ".jpg");
  281. Bitmap m = new Bitmap(info.RegionID.ToString() + ".jpg");
  282. //Console.WriteLine("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width);
  283. byte[] imageData = OpenJPEG.EncodeFromImage(m, true);
  284. AssetBase ass = new AssetBase(UUID.Random(), "region " + info.RegionID.ToString());
  285. info.RegionSettings.TerrainImageID = ass.FullID;
  286. ass.Type = (int)AssetType.Texture;
  287. ass.Temporary = false;
  288. //imageData.CopyTo(ass.Data, 0);
  289. ass.Data = imageData;
  290. m_assetcache.AddAsset(ass);
  291. }
  292. catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
  293. {
  294. Console.WriteLine("Failed getting/storing map image: " + e);
  295. }
  296. }
  297. // A little ugly, since this code is exactly the same as OSG1's, and we're already
  298. // calling that for when the region in in grid mode... (for the grid regions)
  299. //
  300. public virtual LandData RequestLandData (ulong regionHandle, uint x, uint y)
  301. {
  302. m_log.DebugFormat("[HGrid]: requests land data in {0}, at {1}, {2}",
  303. regionHandle, x, y);
  304. // Remote region
  305. Hashtable hash = new Hashtable();
  306. hash["region_handle"] = regionHandle.ToString();
  307. hash["x"] = x.ToString();
  308. hash["y"] = y.ToString();
  309. IList paramList = new ArrayList();
  310. paramList.Add(hash);
  311. LandData landData = null;
  312. try
  313. {
  314. RegionInfo info = RequestNeighbourInfo(regionHandle);
  315. if (info != null) // just to be sure
  316. {
  317. XmlRpcRequest request = new XmlRpcRequest("land_data", paramList);
  318. string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
  319. XmlRpcResponse response = request.Send(uri, 10000);
  320. if (response.IsFault)
  321. {
  322. m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
  323. }
  324. else
  325. {
  326. hash = (Hashtable)response.Value;
  327. try
  328. {
  329. landData = new LandData();
  330. landData.AABBMax = Vector3.Parse((string)hash["AABBMax"]);
  331. landData.AABBMin = Vector3.Parse((string)hash["AABBMin"]);
  332. landData.Area = Convert.ToInt32(hash["Area"]);
  333. landData.AuctionID = Convert.ToUInt32(hash["AuctionID"]);
  334. landData.Description = (string)hash["Description"];
  335. landData.Flags = Convert.ToUInt32(hash["Flags"]);
  336. landData.GlobalID = new UUID((string)hash["GlobalID"]);
  337. landData.Name = (string)hash["Name"];
  338. landData.OwnerID = new UUID((string)hash["OwnerID"]);
  339. landData.SalePrice = Convert.ToInt32(hash["SalePrice"]);
  340. landData.SnapshotID = new UUID((string)hash["SnapshotID"]);
  341. landData.UserLocation = Vector3.Parse((string)hash["UserLocation"]);
  342. m_log.DebugFormat("[HGrid]: Got land data for parcel {0}", landData.Name);
  343. }
  344. catch (Exception e)
  345. {
  346. m_log.Error("[HGrid]: Got exception while parsing land-data:", e);
  347. }
  348. }
  349. }
  350. else m_log.WarnFormat("[HGrid]: Couldn't find region with handle {0}", regionHandle);
  351. }
  352. catch (Exception e)
  353. {
  354. m_log.ErrorFormat("[HGrid]: Couldn't contact region {0}: {1}", regionHandle, e);
  355. }
  356. return landData;
  357. }
  358. // Grid Request Processing
  359. public virtual List<RegionInfo> RequestNamedRegions (string name, int maxNumber)
  360. {
  361. List<RegionInfo> infos = new List<RegionInfo>();
  362. foreach (RegionInfo info in m_hyperlinkRegions)
  363. {
  364. if (info.RegionName.ToLower().Contains(name))
  365. {
  366. infos.Add(info);
  367. }
  368. }
  369. return infos;
  370. }
  371. private UUID LinkRegion(RegionInfo info)
  372. {
  373. UUID uuid = UUID.Zero;
  374. Hashtable hash = new Hashtable();
  375. hash["region_name"] = info.RegionName;
  376. IList paramList = new ArrayList();
  377. paramList.Add(hash);
  378. XmlRpcRequest request = new XmlRpcRequest("link_region", paramList);
  379. string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
  380. m_log.Debug("[HGrid]: Linking to " + uri);
  381. XmlRpcResponse response = request.Send(uri, 10000);
  382. if (response.IsFault)
  383. {
  384. m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
  385. }
  386. else
  387. {
  388. hash = (Hashtable)response.Value;
  389. //foreach (Object o in hash)
  390. // Console.WriteLine(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  391. try
  392. {
  393. UUID.TryParse((string)hash["uuid"], out uuid);
  394. info.RegionID = uuid;
  395. if ((string)hash["handle"] != null)
  396. {
  397. info.regionSecret = (string)hash["handle"];
  398. //Console.WriteLine(">> HERE: " + info.regionSecret);
  399. }
  400. if (hash["region_image"] != null)
  401. {
  402. UUID img = UUID.Zero;
  403. UUID.TryParse((string)hash["region_image"], out img);
  404. info.RegionSettings.TerrainImageID = img;
  405. }
  406. if (hash["region_name"] != null)
  407. {
  408. info.RegionName = (string)hash["region_name"];
  409. }
  410. if (hash["internal_port"] != null)
  411. {
  412. int port = Convert.ToInt32((string)hash["internal_port"]);
  413. info.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port);
  414. //Console.WriteLine(">> " + info.InternalEndPoint.ToString());
  415. }
  416. if (hash["remoting_port"] != null)
  417. {
  418. info.RemotingPort = Convert.ToUInt32(hash["remoting_port"]);
  419. //Console.WriteLine(">> " + info.RemotingPort);
  420. }
  421. }
  422. catch (Exception e)
  423. {
  424. m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace);
  425. }
  426. }
  427. return uuid;
  428. }
  429. /// <summary>
  430. /// Someone wants to link to us
  431. /// </summary>
  432. /// <param name="request"></param>
  433. /// <returns></returns>
  434. public XmlRpcResponse LinkRegionRequest(XmlRpcRequest request)
  435. {
  436. Hashtable requestData = (Hashtable)request.Params[0];
  437. //string host = (string)requestData["host"];
  438. //string portstr = (string)requestData["port"];
  439. string name = (string)requestData["region_name"];
  440. m_log.DebugFormat("[HGrid]: Hyperlink request");
  441. RegionInfo regInfo = null;
  442. foreach (RegionInfo r in m_regionsOnInstance)
  443. {
  444. if ((r.RegionName != null) && (name != null) && (r.RegionName.ToLower() == name.ToLower()))
  445. {
  446. regInfo = r;
  447. break;
  448. }
  449. }
  450. if (regInfo == null)
  451. regInfo = m_regionsOnInstance[0]; // Send out the first region
  452. Hashtable hash = new Hashtable();
  453. hash["uuid"] = regInfo.RegionID.ToString();
  454. hash["handle"] = regInfo.RegionHandle.ToString();
  455. //Console.WriteLine(">> Here " + regInfo.RegionHandle);
  456. hash["region_image"] = regInfo.RegionSettings.TerrainImageID.ToString();
  457. hash["region_name"] = regInfo.RegionName;
  458. hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString();
  459. hash["remoting_port"] = NetworkServersInfo.RemotingListenerPort.ToString();
  460. //Console.WriteLine(">> Here: " + regInfo.InternalEndPoint.Port);
  461. XmlRpcResponse response = new XmlRpcResponse();
  462. response.Value = hash;
  463. return response;
  464. }
  465. public bool InformRegionOfUser(RegionInfo regInfo, AgentCircuitData agentData)
  466. {
  467. //ulong regionHandle = regInfo.RegionHandle;
  468. try
  469. {
  470. //regionHandle = Convert.ToUInt64(regInfo.regionSecret);
  471. m_log.Info("[HGrid]: InformRegionOfUser: Remote hyperlinked region " + regInfo.regionSecret);
  472. }
  473. catch
  474. {
  475. m_log.Info("[HGrid]: InformRegionOfUser: Local grid region " + regInfo.regionSecret);
  476. }
  477. string capsPath = agentData.CapsPath;
  478. Hashtable loginParams = new Hashtable();
  479. loginParams["session_id"] = agentData.SessionID.ToString();
  480. loginParams["secure_session_id"] = agentData.SecureSessionID.ToString();
  481. loginParams["firstname"] = agentData.firstname;
  482. loginParams["lastname"] = agentData.lastname;
  483. loginParams["agent_id"] = agentData.AgentID.ToString();
  484. loginParams["circuit_code"] = agentData.circuitcode.ToString();
  485. loginParams["startpos_x"] = agentData.startpos.X.ToString();
  486. loginParams["startpos_y"] = agentData.startpos.Y.ToString();
  487. loginParams["startpos_z"] = agentData.startpos.Z.ToString();
  488. loginParams["caps_path"] = capsPath;
  489. CachedUserInfo u = m_userProfileCache.GetUserDetails(agentData.AgentID);
  490. if (u != null && u.UserProfile != null)
  491. {
  492. loginParams["region_uuid"] = u.UserProfile.HomeRegionID.ToString(); // This seems to be always Zero
  493. //Console.WriteLine(" --------- Home Region UUID -------");
  494. //Console.WriteLine(" >> " + loginParams["region_uuid"] + " <<");
  495. //Console.WriteLine(" --------- ---------------- -------");
  496. string serverURI = "";
  497. if (u.UserProfile is ForeignUserProfileData)
  498. serverURI = HGNetworkServersInfo.ServerURI(((ForeignUserProfileData)u.UserProfile).UserServerURI);
  499. loginParams["userserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalUserServerURI : serverURI;
  500. serverURI = HGNetworkServersInfo.ServerURI(u.UserProfile.UserAssetURI);
  501. loginParams["assetserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalAssetServerURI : serverURI;
  502. serverURI = HGNetworkServersInfo.ServerURI(u.UserProfile.UserInventoryURI);
  503. loginParams["inventoryserver_id"] = (serverURI == "") || (serverURI == null) ? HGNetworkServersInfo.Singleton.LocalInventoryServerURI : serverURI;
  504. loginParams["root_folder_id"] = u.UserProfile.RootInventoryFolderID;
  505. RegionInfo rinfo = RequestNeighbourInfo(u.UserProfile.HomeRegion);
  506. if (rinfo != null)
  507. {
  508. loginParams["internal_port"] = rinfo.InternalEndPoint.Port.ToString();
  509. if (!IsLocalUser(u))
  510. {
  511. loginParams["regionhandle"] = rinfo.regionSecret; // user.CurrentAgent.Handle.ToString();
  512. //Console.WriteLine("XXX--- informregionofuser (foreign user) here handle: " + rinfo.regionSecret);
  513. loginParams["home_address"] = ((ForeignUserProfileData)(u.UserProfile)).UserHomeAddress;
  514. loginParams["home_port"] = ((ForeignUserProfileData)(u.UserProfile)).UserHomePort;
  515. loginParams["home_remoting"] = ((ForeignUserProfileData)(u.UserProfile)).UserHomeRemotingPort;
  516. }
  517. else
  518. {
  519. //Console.WriteLine("XXX--- informregionofuser (local user) here handle: " + rinfo.regionSecret);
  520. //// local user about to jump out, let's process the name
  521. // On second thoughts, let's not do this for the *user*; let's only do it for the *agent*
  522. //loginParams["firstname"] = agentData.firstname + "." + agentData.lastname;
  523. //loginParams["lastname"] = serversInfo.UserURL;
  524. // local user, first time out. let's ask the grid about this user's home region
  525. loginParams["regionhandle"] = u.UserProfile.HomeRegion.ToString(); // user.CurrentAgent.Handle.ToString();
  526. loginParams["home_address"] = rinfo.ExternalHostName;
  527. Console.WriteLine(" --------- Home Address -------");
  528. Console.WriteLine(" >> " + loginParams["home_address"] + " <<");
  529. Console.WriteLine(" --------- ------------ -------");
  530. loginParams["home_port"] = rinfo.HttpPort.ToString();
  531. loginParams["home_remoting"] = NetworkServersInfo.RemotingListenerPort.ToString(); ;
  532. }
  533. }
  534. else
  535. {
  536. m_log.Warn("[HGrid]: User's home region info not found: " + u.UserProfile.HomeRegionX + ", " + u.UserProfile.HomeRegionY);
  537. }
  538. }
  539. ArrayList SendParams = new ArrayList();
  540. SendParams.Add(loginParams);
  541. // Send
  542. string uri = "http://" + regInfo.ExternalHostName + ":" + regInfo.HttpPort + "/";
  543. //Console.WriteLine("XXX uri: " + uri);
  544. XmlRpcRequest request = new XmlRpcRequest("expect_hg_user", SendParams);
  545. XmlRpcResponse reply;
  546. try
  547. {
  548. reply = request.Send(uri, 6000);
  549. }
  550. catch (Exception e)
  551. {
  552. m_log.Warn("[HGrid]: Failed to notify region about user. Reason: " + e.Message);
  553. return false;
  554. }
  555. if (!reply.IsFault)
  556. {
  557. bool responseSuccess = true;
  558. if (reply.Value != null)
  559. {
  560. Hashtable resp = (Hashtable)reply.Value;
  561. if (resp.ContainsKey("success"))
  562. {
  563. if ((string)resp["success"] == "FALSE")
  564. {
  565. responseSuccess = false;
  566. }
  567. }
  568. }
  569. if (responseSuccess)
  570. {
  571. m_log.Info("[HGrid]: Successfully informed remote region about user " + agentData.AgentID);
  572. return true;
  573. }
  574. else
  575. {
  576. m_log.ErrorFormat("[HGrid]: Region responded that it is not available to receive clients");
  577. return false;
  578. }
  579. }
  580. else
  581. {
  582. m_log.ErrorFormat("[HGrid]: XmlRpc request to region failed with message {0}, code {1} ", reply.FaultString, reply.FaultCode);
  583. return false;
  584. }
  585. }
  586. /// <summary>
  587. /// Received from other HGrid nodes when a user wants to teleport here. This call allows
  588. /// the region to prepare for direct communication from the client. Sends back an empty
  589. /// xmlrpc response on completion.
  590. /// This is somewhat similar to OGS1's ExpectUser, but with the additional task of
  591. /// registering the user in the local user cache.
  592. /// </summary>
  593. /// <param name="request"></param>
  594. /// <returns></returns>
  595. public XmlRpcResponse ExpectHGUser(XmlRpcRequest request)
  596. {
  597. Hashtable requestData = (Hashtable)request.Params[0];
  598. ForeignUserProfileData userData = new ForeignUserProfileData();
  599. userData.FirstName = (string)requestData["firstname"];
  600. userData.SurName = (string)requestData["lastname"];
  601. userData.ID = new UUID((string)requestData["agent_id"]);
  602. userData.HomeLocation = new Vector3((float)Convert.ToDecimal((string)requestData["startpos_x"]),
  603. (float)Convert.ToDecimal((string)requestData["startpos_y"]),
  604. (float)Convert.ToDecimal((string)requestData["startpos_z"]));
  605. userData.UserServerURI = (string)requestData["userserver_id"];
  606. userData.UserAssetURI = (string)requestData["assetserver_id"];
  607. userData.UserInventoryURI = (string)requestData["inventoryserver_id"];
  608. UUID rootID = UUID.Zero;
  609. UUID.TryParse((string)requestData["root_folder_id"], out rootID);
  610. userData.RootInventoryFolderID = rootID;
  611. UUID uuid = UUID.Zero;
  612. UUID.TryParse((string)requestData["region_uuid"], out uuid);
  613. userData.HomeRegionID = uuid; // not quite comfortable about this...
  614. ulong userRegionHandle = Convert.ToUInt64((string)requestData["regionhandle"]);
  615. //userData.HomeRegion = userRegionHandle;
  616. userData.UserHomeAddress = (string)requestData["home_address"];
  617. userData.UserHomePort = (string)requestData["home_port"];
  618. int userhomeinternalport = Convert.ToInt32((string)requestData["internal_port"]);
  619. userData.UserHomeRemotingPort = (string)requestData["home_remoting"];
  620. m_log.DebugFormat("[HGrid]: Told by user service to prepare for a connection from {0} {1} {2}",
  621. userData.FirstName, userData.SurName, userData.ID);
  622. m_log.Debug("[HGrid]: home_address: " + userData.UserHomeAddress +
  623. "; home_port: " + userData.UserHomePort + "; remoting: " + userData.UserHomeRemotingPort);
  624. XmlRpcResponse resp = new XmlRpcResponse();
  625. if (!RegionLoginsEnabled)
  626. {
  627. m_log.InfoFormat(
  628. "[HGrid]: Denying access for user {0} {1} because region login is currently disabled",
  629. userData.FirstName, userData.SurName);
  630. Hashtable respdata = new Hashtable();
  631. respdata["success"] = "FALSE";
  632. respdata["reason"] = "region login currently disabled";
  633. resp.Value = respdata;
  634. }
  635. else
  636. {
  637. RegionInfo[] regions = m_regionsOnInstance.ToArray();
  638. //bool banned = false;
  639. // Just check one region. We assume they all belong to the same estate.
  640. if ((regions.Length > 0) && (regions[0].EstateSettings.IsBanned(userData.ID)))
  641. {
  642. m_log.InfoFormat(
  643. "[HGrid]: Denying access for user {0} {1} because user is banned",
  644. userData.FirstName, userData.SurName);
  645. Hashtable respdata = new Hashtable();
  646. respdata["success"] = "FALSE";
  647. respdata["reason"] = "banned";
  648. resp.Value = respdata;
  649. }
  650. else
  651. {
  652. // Finally, everything looks ok
  653. //Console.WriteLine("XXX---- EVERYTHING OK ---XXX");
  654. // Nope, let's do it only for the *agent*
  655. //// 0 - Switch name if necessary
  656. //if (IsComingHome(userData))
  657. //{
  658. // string[] parts = userData.FirstName.Split( new char[] {'.'});
  659. // if (parts.Length >= 1)
  660. // userData.FirstName = parts[0];
  661. // if (parts.Length == 2)
  662. // userData.SurName = parts[1];
  663. // else
  664. // m_log.Warn("[HGrid]: Something fishy with user " + userData.FirstName + userData.SurName);
  665. // m_log.Info("[HGrid]: Welcome home, " + userData.FirstName + " " + userData.SurName);
  666. //}
  667. // 1 - Preload the user data
  668. m_userProfileCache.PreloadUserCache(userData.ID, userData);
  669. // 2 - Load the region info into list of known regions
  670. RegionInfo rinfo = new RegionInfo();
  671. rinfo.RegionID = userData.HomeRegionID;
  672. rinfo.ExternalHostName = userData.UserHomeAddress;
  673. rinfo.HttpPort = Convert.ToUInt32(userData.UserHomePort);
  674. rinfo.RemotingPort = Convert.ToUInt32(userData.UserHomeRemotingPort);
  675. rinfo.RegionID = userData.HomeRegionID;
  676. // X=0 on the map
  677. rinfo.RegionLocX = 0;
  678. rinfo.RegionLocY = (uint)m_knownRegions.Count;
  679. rinfo.regionSecret = userRegionHandle.ToString();
  680. //Console.WriteLine("XXX--- Here: handle = " + rinfo.regionSecret);
  681. try
  682. {
  683. rinfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)userhomeinternalport);
  684. }
  685. catch (Exception e)
  686. {
  687. m_log.Warn("[HGrid]: Exception while constructing internal endpoint: " + e);
  688. }
  689. rinfo.RemotingAddress = rinfo.ExternalEndPoint.Address.ToString(); //userData.UserHomeAddress;
  690. if (!IsComingHome(userData))
  691. {
  692. // Change the user's home region here!!!
  693. userData.HomeRegion = rinfo.RegionHandle;
  694. }
  695. if (!m_knownRegions.ContainsKey(userData.ID))
  696. m_knownRegions.Add(userData.ID, rinfo);
  697. else
  698. // just update it. The previous one was left there when the user departed
  699. m_knownRegions[userData.ID] = rinfo;
  700. // 3 - Send the reply
  701. Hashtable respdata = new Hashtable();
  702. respdata["success"] = "TRUE";
  703. resp.Value = respdata;
  704. DumpUserData(userData);
  705. DumpRegionData(rinfo);
  706. }
  707. }
  708. return resp;
  709. }
  710. #region IInterRegionCommunications interface
  711. public virtual bool AcknowledgeAgentCrossed(ulong regionHandle, UUID agentId) { return false; }
  712. public virtual bool AcknowledgePrimCrossed(ulong regionHandle, UUID primID) { return false; }
  713. public virtual bool CheckRegion(string address, uint port) { return false; }
  714. public virtual bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData) { return false; }
  715. public virtual bool ExpectAvatarCrossing(ulong regionHandle, UUID agentID, Vector3 position, bool isFlying) {
  716. // Remote region
  717. RegionInfo regInfo = null;
  718. ulong remoteHandle = 0;
  719. try
  720. {
  721. regInfo = RequestNeighbourInfo(regionHandle);
  722. if (regInfo != null)
  723. {
  724. try
  725. {
  726. remoteHandle = Convert.ToUInt64(regInfo.regionSecret);
  727. }
  728. catch
  729. {
  730. m_log.Warn("[HGrid]: Invalid remote region with handle " + regInfo.regionSecret);
  731. return false;
  732. }
  733. //Console.WriteLine("XXX---- Sending Expectavatarcrossing into : " + remoteHandle);
  734. bool retValue = false;
  735. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
  736. typeof(OGS1InterRegionRemoting),
  737. "tcp://" + regInfo.RemotingAddress +
  738. ":" + regInfo.RemotingPort +
  739. "/InterRegions");
  740. if (remObject != null)
  741. {
  742. retValue =
  743. remObject.ExpectAvatarCrossing(remoteHandle, agentID.Guid, new sLLVector3(position),
  744. isFlying);
  745. }
  746. else
  747. {
  748. m_log.Warn("[HGrid]: Remoting object not found");
  749. }
  750. remObject = null;
  751. return retValue;
  752. }
  753. //TODO need to see if we know about where this region is and use .net remoting
  754. // to inform it.
  755. //NoteDeadRegion(regionHandle);
  756. return false;
  757. }
  758. catch (RemotingException e)
  759. {
  760. // NoteDeadRegion(regionHandle);
  761. m_log.WarnFormat(
  762. "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  763. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  764. m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
  765. return false;
  766. }
  767. catch
  768. {
  769. // NoteDeadRegion(regionHandle);
  770. return false;
  771. }
  772. }
  773. public virtual bool ExpectPrimCrossing(ulong regionHandle, UUID primID, Vector3 position, bool isFlying) { return false; }
  774. public virtual bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData)
  775. {
  776. // If we're here, it's because regionHandle is a remote, non-grided region
  777. m_log.Info("[HGrid]: InformRegionOfChildAgent for " + regionHandle);
  778. RegionInfo regInfo = GetHyperlinkRegion(regionHandle);
  779. if (regInfo == null)
  780. return false;
  781. //ulong realHandle = regionHandle;
  782. CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID);
  783. if ((uinfo == null) || !IsGoingHome(uinfo, regInfo))
  784. {
  785. m_log.Info("[HGrid]: User seems to be going to foreign region " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName);
  786. if (!InformRegionOfUser(regInfo, agentData))
  787. {
  788. m_log.Warn("[HGrid]: Could not inform remote region of transferring user.");
  789. return false;
  790. }
  791. }
  792. else
  793. m_log.Info("[HGrid]: User seems to be going home " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName);
  794. try
  795. {
  796. // ... and then
  797. m_log.Debug("[HGrid]: Region is hyperlink.");
  798. bool retValue = false;
  799. try
  800. {
  801. regionHandle = Convert.ToUInt64(regInfo.regionSecret);
  802. }
  803. catch (Exception)
  804. {
  805. m_log.Warn("[HGrid]: Invalid hyperlink region.");
  806. return false;
  807. }
  808. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
  809. typeof(OGS1InterRegionRemoting),
  810. "tcp://" + regInfo.RemotingAddress +
  811. ":" + regInfo.RemotingPort +
  812. "/InterRegions");
  813. if (remObject != null)
  814. {
  815. sAgentCircuitData sag = new sAgentCircuitData(agentData);
  816. // May need to change agent's name
  817. if (IsLocalUser(uinfo))
  818. {
  819. sag.firstname = agentData.firstname + "." + agentData.lastname;
  820. sag.lastname = serversInfo.UserURL; //HGNetworkServersInfo.Singleton.LocalUserServerURI;
  821. }
  822. retValue = remObject.InformRegionOfChildAgent(regionHandle, sag);
  823. }
  824. else
  825. {
  826. m_log.Warn("[HGrid]: remoting object not found");
  827. }
  828. remObject = null;
  829. m_log.Info("[HGrid]: tried to InformRegionOfChildAgent for " +
  830. agentData.firstname + " " + agentData.lastname + " and got " +
  831. retValue.ToString());
  832. // Remove the info from this region
  833. if (m_knownRegions.ContainsKey(uinfo.UserProfile.ID))
  834. m_knownRegions.Remove(uinfo.UserProfile.ID);
  835. return retValue;
  836. }
  837. catch (RemotingException e)
  838. {
  839. //NoteDeadRegion(regionHandle);
  840. m_log.WarnFormat(
  841. "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  842. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  843. m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
  844. return false;
  845. }
  846. catch (SocketException e)
  847. {
  848. //NoteDeadRegion(regionHandle);
  849. m_log.WarnFormat(
  850. "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  851. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  852. m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
  853. return false;
  854. }
  855. catch (InvalidCredentialException e)
  856. {
  857. //NoteDeadRegion(regionHandle);
  858. m_log.WarnFormat(
  859. "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  860. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  861. m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
  862. return false;
  863. }
  864. catch (AuthenticationException e)
  865. {
  866. //NoteDeadRegion(regionHandle);
  867. m_log.WarnFormat(
  868. "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  869. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  870. m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
  871. return false;
  872. }
  873. catch (Exception e)
  874. {
  875. //NoteDeadRegion(regionHandle);
  876. if (regInfo != null)
  877. {
  878. m_log.WarnFormat(
  879. "[HGrid]: Remoting Error: Unable to connect to adjacent region: {0} {1},{2}",
  880. regInfo.RegionName, regInfo.RegionLocX, regInfo.RegionLocY);
  881. }
  882. m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
  883. return false;
  884. }
  885. }
  886. public virtual bool InformRegionOfPrimCrossing(ulong regionHandle, UUID primID, string objData, int XMLMethod) { return false; }
  887. public virtual bool RegionUp(SerializableRegionInfo region, ulong regionhandle) {
  888. ulong realHandle = FindRegionHandle(regionhandle);
  889. if (realHandle == regionhandle) // something wrong, not remote region
  890. return false;
  891. SerializableRegionInfo regInfo = null;
  892. try
  893. {
  894. // You may ask why this is in here...
  895. // The region asking the grid services about itself..
  896. // And, surprisingly, the reason is.. it doesn't know
  897. // it's own remoting port! How special.
  898. RegionUpData regiondata = new RegionUpData(region.RegionLocX, region.RegionLocY, region.ExternalHostName, region.InternalEndPoint.Port);
  899. region = new SerializableRegionInfo(RequestNeighbourInfo(realHandle));
  900. region.RemotingAddress = region.ExternalHostName;
  901. region.RemotingPort = NetworkServersInfo.RemotingListenerPort;
  902. region.HttpPort = serversInfo.HttpListenerPort;
  903. regInfo = new SerializableRegionInfo(RequestNeighbourInfo(regionhandle));
  904. if (regInfo != null)
  905. {
  906. // If we're not trying to remote to ourselves.
  907. if (regInfo.RemotingAddress != region.RemotingAddress && region.RemotingAddress != null)
  908. {
  909. //don't want to be creating a new link to the remote instance every time like we are here
  910. bool retValue = false;
  911. OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject(
  912. typeof(OGS1InterRegionRemoting),
  913. "tcp://" +
  914. regInfo.RemotingAddress +
  915. ":" + regInfo.RemotingPort +
  916. "/InterRegions");
  917. if (remObject != null)
  918. {
  919. retValue = remObject.RegionUp(regiondata, realHandle);
  920. }
  921. else
  922. {
  923. m_log.Warn("[HGrid]: remoting object not found");
  924. }
  925. remObject = null;
  926. m_log.Info(
  927. "[HGrid]: tried to inform region I'm up");
  928. return retValue;
  929. }
  930. else
  931. {
  932. // We're trying to inform ourselves via remoting.
  933. // This is here because we're looping over the listeners before we get here.
  934. // Odd but it should work.
  935. return true;
  936. }
  937. }
  938. return false;
  939. }
  940. catch (RemotingException e)
  941. {
  942. m_log.Warn("[HGrid]: Remoting Error: Unable to connect to adjacent region using tcp://" +
  943. regInfo.RemotingAddress +
  944. ":" + regInfo.RemotingPort +
  945. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
  946. " - Is this neighbor up?");
  947. m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
  948. return false;
  949. }
  950. catch (SocketException e)
  951. {
  952. m_log.Warn("[HGrid]: Socket Error: Unable to connect to adjacent region using tcp://" +
  953. regInfo.RemotingAddress +
  954. ":" + regInfo.RemotingPort +
  955. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY +
  956. " - Is this neighbor up?");
  957. m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
  958. return false;
  959. }
  960. catch (InvalidCredentialException e)
  961. {
  962. m_log.Warn("[HGrid]: Invalid Credentials: Unable to connect to adjacent region using tcp://" +
  963. regInfo.RemotingAddress +
  964. ":" + regInfo.RemotingPort +
  965. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  966. m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
  967. return false;
  968. }
  969. catch (AuthenticationException e)
  970. {
  971. m_log.Warn("[HGrid]: Authentication exception: Unable to connect to adjacent region using tcp://" +
  972. regInfo.RemotingAddress +
  973. ":" + regInfo.RemotingPort +
  974. "/InterRegions - @ " + regInfo.RegionLocX + "," + regInfo.RegionLocY);
  975. m_log.DebugFormat("[HGrid]: {0} {1}", e.Source, e.Message);
  976. return false;
  977. }
  978. catch (Exception e)
  979. {
  980. m_log.Debug(e.ToString());
  981. return false;
  982. }
  983. }
  984. public virtual bool TellRegionToCloseChildConnection(ulong regionHandle, UUID agentID) { return false; }
  985. public virtual List<UUID> InformFriendsInOtherRegion(UUID agentId, ulong destRegionHandle, List<UUID> friends, bool online)
  986. {
  987. return new List<UUID>();
  988. }
  989. public virtual bool TriggerTerminateFriend(ulong regionHandle, UUID agentID, UUID exFriendID)
  990. {
  991. return true;
  992. }
  993. #endregion
  994. #region Methods triggered by calls from external instances
  995. /// <summary>
  996. ///
  997. /// </summary>
  998. /// <param name="regionHandle"></param>
  999. /// <param name="agentData"></param>
  1000. /// <returns></returns>
  1001. protected bool HGIncomingChildAgent(ulong regionHandle, AgentCircuitData agentData)
  1002. {
  1003. CachedUserInfo uinfo = m_userProfileCache.GetUserDetails(agentData.AgentID);
  1004. if ((uinfo != null) && (uinfo.UserProfile != null) &&
  1005. (IsLocalUser(uinfo) || !(uinfo.UserProfile is ForeignUserProfileData)))
  1006. {
  1007. //Console.WriteLine("---------------> Local User!");
  1008. string[] parts = agentData.firstname.Split(new char[] { '.' });
  1009. if (parts.Length == 2)
  1010. {
  1011. agentData.firstname = parts[0];
  1012. agentData.lastname = parts[1];
  1013. }
  1014. }
  1015. //else
  1016. // Console.WriteLine("---------------> Foreign User!");
  1017. return true;
  1018. }
  1019. #endregion
  1020. #region IHyperGrid interface
  1021. public virtual bool IsHyperlinkRegion(ulong ihandle)
  1022. {
  1023. if (GetHyperlinkRegion(ihandle) == null)
  1024. return false;
  1025. else
  1026. return true;
  1027. }
  1028. public virtual RegionInfo GetHyperlinkRegion(ulong ihandle)
  1029. {
  1030. foreach (RegionInfo info in m_hyperlinkRegions)
  1031. {
  1032. if (info.RegionHandle == ihandle)
  1033. return info;
  1034. }
  1035. foreach (RegionInfo info in m_knownRegions.Values)
  1036. {
  1037. if (info.RegionHandle == ihandle)
  1038. return info;
  1039. }
  1040. return null;
  1041. }
  1042. public virtual ulong FindRegionHandle(ulong ihandle)
  1043. {
  1044. long ohandle = -1;
  1045. List<RegionInfo> rlist = new List<RegionInfo>(m_hyperlinkRegions);
  1046. rlist.AddRange(m_knownRegions.Values);
  1047. foreach (RegionInfo info in rlist)
  1048. {
  1049. if (info.RegionHandle == ihandle)
  1050. {
  1051. try
  1052. {
  1053. ohandle = Convert.ToInt64(info.regionSecret);
  1054. m_log.Info("[HGrid] remote region " + ohandle);
  1055. }
  1056. catch
  1057. {
  1058. m_log.Error("[HGrid] Could not convert secret for " + ihandle + " (" + info.regionSecret + ")");
  1059. }
  1060. break;
  1061. }
  1062. }
  1063. return ohandle < 0 ? ihandle : (ulong)ohandle;
  1064. }
  1065. #endregion
  1066. #region Misc
  1067. protected bool IsComingHome(ForeignUserProfileData userData)
  1068. {
  1069. return (userData.UserServerURI == HGNetworkServersInfo.Singleton.LocalUserServerURI);
  1070. }
  1071. protected bool IsGoingHome(CachedUserInfo uinfo, RegionInfo rinfo)
  1072. {
  1073. if (uinfo.UserProfile == null)
  1074. return false;
  1075. string userUserServerURI = String.Empty;
  1076. if (uinfo.UserProfile is ForeignUserProfileData)
  1077. {
  1078. userUserServerURI = HGNetworkServersInfo.ServerURI(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI);
  1079. }
  1080. return ((uinfo.UserProfile.HomeRegionID == rinfo.RegionID) &&
  1081. (userUserServerURI != HGNetworkServersInfo.Singleton.LocalUserServerURI));
  1082. }
  1083. protected bool IsLocalUser(CachedUserInfo uinfo)
  1084. {
  1085. if (uinfo == null)
  1086. return true;
  1087. if (uinfo.UserProfile is ForeignUserProfileData)
  1088. return HGNetworkServersInfo.Singleton.IsLocalUser(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI);
  1089. else
  1090. return true;
  1091. }
  1092. protected bool IsLocalRegion(ulong handle)
  1093. {
  1094. foreach (RegionInfo reg in m_regionsOnInstance)
  1095. if (reg.RegionHandle == handle)
  1096. return true;
  1097. return false;
  1098. }
  1099. private void DumpUserData(ForeignUserProfileData userData)
  1100. {
  1101. Console.WriteLine(" ------------ User Data Dump ----------");
  1102. Console.WriteLine(" >> Name: " + userData.FirstName + " " + userData.SurName);
  1103. Console.WriteLine(" >> HomeID: " + userData.HomeRegionID);
  1104. Console.WriteLine(" >> HomeHandle: " + userData.HomeRegion);
  1105. Console.WriteLine(" >> HomeX: " + userData.HomeRegionX);
  1106. Console.WriteLine(" >> HomeY: " + userData.HomeRegionY);
  1107. Console.WriteLine(" >> UserServer: " + userData.UserServerURI);
  1108. Console.WriteLine(" >> InvServer: " + userData.UserInventoryURI);
  1109. Console.WriteLine(" >> AssetServer: " + userData.UserAssetURI);
  1110. Console.WriteLine(" ------------ -------------- ----------");
  1111. }
  1112. private void DumpRegionData(RegionInfo rinfo)
  1113. {
  1114. Console.WriteLine(" ------------ Region Data Dump ----------");
  1115. Console.WriteLine(" >> handle: " + rinfo.RegionHandle);
  1116. Console.WriteLine(" >> coords: " + rinfo.RegionLocX + ", " + rinfo.RegionLocY);
  1117. Console.WriteLine(" >> secret: " + rinfo.regionSecret);
  1118. Console.WriteLine(" >> remoting address: " + rinfo.RemotingAddress);
  1119. Console.WriteLine(" >> remoting port: " + rinfo.RemotingPort);
  1120. Console.WriteLine(" >> external host name: " + rinfo.ExternalHostName);
  1121. Console.WriteLine(" >> http port: " + rinfo.HttpPort);
  1122. Console.WriteLine(" >> external EP address: " + rinfo.ExternalEndPoint.Address);
  1123. Console.WriteLine(" >> external EP port: " + rinfo.ExternalEndPoint.Port);
  1124. Console.WriteLine(" ------------ -------------- ----------");
  1125. }
  1126. #endregion
  1127. }
  1128. }