HGGridServices.cs 56 KB

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