SceneCommunicationService.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Net;
  30. using System.Reflection;
  31. using System.Threading;
  32. using libsecondlife;
  33. using log4net;
  34. using OpenSim.Framework;
  35. using OpenSim.Framework.Communications;
  36. namespace OpenSim.Region.Environment.Scenes
  37. {
  38. public delegate void KillObjectDelegate(uint localID);
  39. public delegate void RemoveKnownRegionsFromAvatarList(LLUUID avatarID, List<ulong> regionlst);
  40. public class SceneCommunicationService //one instance per region
  41. {
  42. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  43. protected CommunicationsManager m_commsProvider;
  44. protected RegionInfo m_regionInfo;
  45. protected RegionCommsListener regionCommsHost;
  46. public event AgentCrossing OnAvatarCrossingIntoRegion;
  47. public event ExpectUserDelegate OnExpectUser;
  48. public event ExpectPrimDelegate OnExpectPrim;
  49. public event CloseAgentConnection OnCloseAgentConnection;
  50. public event PrimCrossing OnPrimCrossingIntoRegion;
  51. public event RegionUp OnRegionUp;
  52. public event ChildAgentUpdate OnChildAgentUpdate;
  53. public event RemoveKnownRegionsFromAvatarList OnRemoveKnownRegionFromAvatar;
  54. public event LogOffUser OnLogOffUser;
  55. private AgentCrossing handlerAvatarCrossingIntoRegion = null; // OnAvatarCrossingIntoRegion;
  56. private ExpectUserDelegate handlerExpectUser = null; // OnExpectUser;
  57. private ExpectPrimDelegate handlerExpectPrim = null; // OnExpectPrim;
  58. private CloseAgentConnection handlerCloseAgentConnection = null; // OnCloseAgentConnection;
  59. private PrimCrossing handlerPrimCrossingIntoRegion = null; // OnPrimCrossingIntoRegion;
  60. private RegionUp handlerRegionUp = null; // OnRegionUp;
  61. private ChildAgentUpdate handlerChildAgentUpdate = null; // OnChildAgentUpdate;
  62. private RemoveKnownRegionsFromAvatarList handlerRemoveKnownRegionFromAvatar = null; // OnRemoveKnownRegionFromAvatar;
  63. private LogOffUser handlerLogOffUser = null;
  64. public KillObjectDelegate KillObject;
  65. public string _debugRegionName = String.Empty;
  66. public string debugRegionName
  67. {
  68. get { return _debugRegionName; }
  69. set { _debugRegionName = value; }
  70. }
  71. public SceneCommunicationService(CommunicationsManager commsMan)
  72. {
  73. m_commsProvider = commsMan;
  74. m_commsProvider.GridService.gdebugRegionName = _debugRegionName;
  75. m_commsProvider.InterRegion.rdebugRegionName = _debugRegionName;
  76. }
  77. /// <summary>
  78. /// Register a region with the grid
  79. /// </summary>
  80. /// <param name="regionInfos"></param>
  81. /// <exception cref="System.Exception">Thrown if region registration fails.</exception>
  82. public void RegisterRegion(RegionInfo regionInfos)
  83. {
  84. m_regionInfo = regionInfos;
  85. regionCommsHost = m_commsProvider.GridService.RegisterRegion(m_regionInfo);
  86. if (regionCommsHost != null)
  87. {
  88. //m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: registered with gridservice and got" + regionCommsHost.ToString());
  89. regionCommsHost.debugRegionName = _debugRegionName;
  90. regionCommsHost.OnExpectPrim += IncomingPrimCrossing;
  91. regionCommsHost.OnExpectUser += NewUserConnection;
  92. regionCommsHost.OnAvatarCrossingIntoRegion += AgentCrossing;
  93. regionCommsHost.OnCloseAgentConnection += CloseConnection;
  94. regionCommsHost.OnRegionUp += newRegionUp;
  95. regionCommsHost.OnChildAgentUpdate += ChildAgentUpdate;
  96. regionCommsHost.OnLogOffUser += GridLogOffUser;
  97. }
  98. else
  99. {
  100. //m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: registered with gridservice and got null");
  101. }
  102. }
  103. public RegionInfo RequestClosestRegion(string name)
  104. {
  105. return m_commsProvider.GridService.RequestClosestRegion(name);
  106. }
  107. public void Close()
  108. {
  109. if (regionCommsHost != null)
  110. {
  111. regionCommsHost.OnLogOffUser -= GridLogOffUser;
  112. regionCommsHost.OnChildAgentUpdate -= ChildAgentUpdate;
  113. regionCommsHost.OnRegionUp -= newRegionUp;
  114. regionCommsHost.OnExpectUser -= NewUserConnection;
  115. regionCommsHost.OnExpectPrim -= IncomingPrimCrossing;
  116. regionCommsHost.OnAvatarCrossingIntoRegion -= AgentCrossing;
  117. regionCommsHost.OnCloseAgentConnection -= CloseConnection;
  118. m_commsProvider.GridService.DeregisterRegion(m_regionInfo);
  119. regionCommsHost = null;
  120. }
  121. }
  122. #region CommsManager Event handlers
  123. /// <summary>
  124. ///
  125. /// </summary>
  126. /// <param name="regionHandle"></param>
  127. /// <param name="agent"></param>
  128. ///
  129. protected void NewUserConnection(ulong regionHandle, AgentCircuitData agent)
  130. {
  131. handlerExpectUser = OnExpectUser;
  132. if (handlerExpectUser != null)
  133. {
  134. //m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: OnExpectUser Fired for User:" + agent.firstname + " " + agent.lastname);
  135. handlerExpectUser(regionHandle, agent);
  136. }
  137. }
  138. protected void GridLogOffUser(ulong regionHandle, LLUUID AgentID, LLUUID RegionSecret, string message)
  139. {
  140. handlerLogOffUser = OnLogOffUser;
  141. if (handlerLogOffUser != null)
  142. {
  143. handlerLogOffUser(regionHandle, AgentID, RegionSecret, message);
  144. }
  145. }
  146. protected bool newRegionUp(RegionInfo region)
  147. {
  148. handlerRegionUp = OnRegionUp;
  149. if (handlerRegionUp != null)
  150. {
  151. //m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: newRegionUp Fired for User:" + region.RegionName);
  152. handlerRegionUp(region);
  153. }
  154. return true;
  155. }
  156. protected bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData)
  157. {
  158. handlerChildAgentUpdate = OnChildAgentUpdate;
  159. if (handlerChildAgentUpdate != null)
  160. handlerChildAgentUpdate(regionHandle, cAgentData);
  161. return true;
  162. }
  163. protected void AgentCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying)
  164. {
  165. handlerAvatarCrossingIntoRegion = OnAvatarCrossingIntoRegion;
  166. if (handlerAvatarCrossingIntoRegion != null)
  167. {
  168. handlerAvatarCrossingIntoRegion(regionHandle, agentID, position, isFlying);
  169. }
  170. }
  171. protected bool IncomingPrimCrossing(ulong regionHandle, LLUUID primID, String objXMLData, int XMLMethod)
  172. {
  173. handlerExpectPrim = OnExpectPrim;
  174. if (handlerExpectPrim != null)
  175. {
  176. return handlerExpectPrim(regionHandle, primID, objXMLData, XMLMethod);
  177. }
  178. else
  179. {
  180. return false;
  181. }
  182. }
  183. protected void PrimCrossing(ulong regionHandle, LLUUID primID, LLVector3 position, bool isPhysical)
  184. {
  185. handlerPrimCrossingIntoRegion = OnPrimCrossingIntoRegion;
  186. if (handlerPrimCrossingIntoRegion != null)
  187. {
  188. handlerPrimCrossingIntoRegion(regionHandle, primID, position, isPhysical);
  189. }
  190. }
  191. protected bool CloseConnection(ulong regionHandle, LLUUID agentID)
  192. {
  193. m_log.Info("[INTERREGION]: Incoming Agent Close Request for agent: " + agentID.ToString());
  194. handlerCloseAgentConnection = OnCloseAgentConnection;
  195. if (handlerCloseAgentConnection != null)
  196. {
  197. return handlerCloseAgentConnection(regionHandle, agentID);
  198. }
  199. return false;
  200. }
  201. #endregion
  202. #region Inform Client of Neighbours
  203. private delegate void InformClientOfNeighbourDelegate(
  204. ScenePresence avatar, AgentCircuitData a, ulong regionHandle, IPEndPoint endPoint);
  205. private void InformClientOfNeighbourCompleted(IAsyncResult iar)
  206. {
  207. InformClientOfNeighbourDelegate icon = (InformClientOfNeighbourDelegate) iar.AsyncState;
  208. icon.EndInvoke(iar);
  209. }
  210. /// <summary>
  211. /// Async compnent for informing client of which neighbours exists
  212. /// </summary>
  213. /// <remarks>
  214. /// This needs to run asynchronesously, as a network timeout may block the thread for a long while
  215. /// </remarks>
  216. /// <param name="remoteClient"></param>
  217. /// <param name="a"></param>
  218. /// <param name="regionHandle"></param>
  219. /// <param name="endPoint"></param>
  220. private void InformClientOfNeighbourAsync(ScenePresence avatar, AgentCircuitData a, ulong regionHandle,
  221. IPEndPoint endPoint)
  222. {
  223. m_log.Info("[INTERGRID]: Starting to inform client about neighbours");
  224. bool regionAccepted = m_commsProvider.InterRegion.InformRegionOfChildAgent(regionHandle, a);
  225. if (regionAccepted)
  226. {
  227. avatar.ControllingClient.InformClientOfNeighbour(regionHandle, endPoint);
  228. avatar.AddNeighbourRegion(regionHandle);
  229. m_log.Info("[INTERGRID]: Completed inform client about neighbours");
  230. }
  231. }
  232. public void RequestNeighbors(RegionInfo region)
  233. {
  234. // List<SimpleRegionInfo> neighbours =
  235. m_commsProvider.GridService.RequestNeighbours(m_regionInfo.RegionLocX, m_regionInfo.RegionLocY);
  236. //IPEndPoint blah = new IPEndPoint();
  237. //blah.Address = region.RemotingAddress;
  238. //blah.Port = region.RemotingPort;
  239. }
  240. /// <summary>
  241. /// This informs all neighboring regions about agent "avatar".
  242. /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
  243. /// </summary>
  244. public void EnableNeighbourChildAgents(ScenePresence avatar, List<RegionInfo> lstneighbours)
  245. {
  246. List<SimpleRegionInfo> neighbours = new List<SimpleRegionInfo>();
  247. //m_commsProvider.GridService.RequestNeighbours(m_regionInfo.RegionLocX, m_regionInfo.RegionLocY);
  248. for (int i = 0; i < lstneighbours.Count; i++)
  249. {
  250. // We don't want to keep sending to regions that consistently fail on comms.
  251. if (!(lstneighbours[i].commFailTF))
  252. {
  253. neighbours.Add(new SimpleRegionInfo(lstneighbours[i]));
  254. }
  255. }
  256. // we're going to be using the above code once neighbour cache is correct. Currently it doesn't appear to be
  257. // So we're temporarily going back to the old method of grabbing it from the Grid Server Every time :/
  258. neighbours =
  259. m_commsProvider.GridService.RequestNeighbours(m_regionInfo.RegionLocX, m_regionInfo.RegionLocY);
  260. if (neighbours != null)
  261. {
  262. for (int i = 0; i < neighbours.Count; i++)
  263. {
  264. AgentCircuitData agent = avatar.ControllingClient.RequestClientInfo();
  265. agent.BaseFolder = LLUUID.Zero;
  266. agent.InventoryFolder = LLUUID.Zero;
  267. agent.startpos = new LLVector3(128, 128, 70);
  268. agent.child = true;
  269. InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync;
  270. try
  271. {
  272. d.BeginInvoke(avatar, agent, neighbours[i].RegionHandle, neighbours[i].ExternalEndPoint,
  273. InformClientOfNeighbourCompleted,
  274. d);
  275. }
  276. catch (Exception e)
  277. {
  278. m_log.ErrorFormat(
  279. "[REGIONINFO]: Could not resolve external hostname {0} for region {1} ({2}, {3}). {4}",
  280. neighbours[i].ExternalHostName,
  281. neighbours[i].RegionHandle,
  282. neighbours[i].RegionLocX,
  283. neighbours[i].RegionLocY,
  284. e);
  285. // FIXME: Okay, even though we've failed, we're still going to throw the exception on,
  286. // since I don't know what will happen if we just let the client continue
  287. // XXX: Well, decided to swallow the exception instead for now. Let us see how that goes.
  288. // throw e;
  289. }
  290. }
  291. }
  292. }
  293. /// <summary>
  294. /// This informs a single neighboring region about agent "avatar".
  295. /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
  296. /// </summary>
  297. public void InformNeighborChildAgent(ScenePresence avatar, RegionInfo region, List<RegionInfo> neighbours)
  298. {
  299. AgentCircuitData agent = avatar.ControllingClient.RequestClientInfo();
  300. agent.BaseFolder = LLUUID.Zero;
  301. agent.InventoryFolder = LLUUID.Zero;
  302. agent.startpos = new LLVector3(128, 128, 70);
  303. agent.child = true;
  304. InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync;
  305. d.BeginInvoke(avatar, agent, region.RegionHandle, region.ExternalEndPoint,
  306. InformClientOfNeighbourCompleted,
  307. d);
  308. }
  309. #endregion
  310. public delegate void InformNeighbourThatRegionUpDelegate(RegionInfo region, ulong regionhandle);
  311. private void InformNeighborsThatRegionisUpCompleted(IAsyncResult iar)
  312. {
  313. InformNeighbourThatRegionUpDelegate icon = (InformNeighbourThatRegionUpDelegate) iar.AsyncState;
  314. icon.EndInvoke(iar);
  315. }
  316. /// <summary>
  317. /// Asynchronous call to information neighbouring regions that this region is up
  318. /// </summary>
  319. /// <param name="region"></param>
  320. /// <param name="regionhandle"></param>
  321. private void InformNeighboursThatRegionIsUpAsync(RegionInfo region, ulong regionhandle)
  322. {
  323. m_log.Info("[INTERGRID]: Starting to inform neighbors that I'm here");
  324. //RegionUpData regiondata = new RegionUpData(region.RegionLocX, region.RegionLocY, region.ExternalHostName, region.InternalEndPoint.Port);
  325. bool regionAccepted =
  326. m_commsProvider.InterRegion.RegionUp(new SerializableRegionInfo(region), regionhandle);
  327. if (regionAccepted)
  328. {
  329. m_log.Info("[INTERGRID]: Completed informing neighbors that I'm here");
  330. handlerRegionUp = OnRegionUp;
  331. // yes, we're notifying ourselves.
  332. if (handlerRegionUp != null)
  333. handlerRegionUp(region);
  334. }
  335. else
  336. {
  337. m_log.Warn("[INTERGRID]: Failed to inform neighbors that I'm here.");
  338. }
  339. }
  340. /// <summary>
  341. /// Called by scene when region is initialized (not always when it's listening for agents)
  342. /// This is an inter-region message that informs the surrounding neighbors that the sim is up.
  343. /// </summary>
  344. public void InformNeighborsThatRegionisUp(RegionInfo region)
  345. {
  346. //m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: Sending InterRegion Notification that region is up " + region.RegionName);
  347. List<SimpleRegionInfo> neighbours = new List<SimpleRegionInfo>();
  348. // This stays uncached because we don't already know about our neighbors at this point.
  349. neighbours = m_commsProvider.GridService.RequestNeighbours(m_regionInfo.RegionLocX, m_regionInfo.RegionLocY);
  350. if (neighbours != null)
  351. {
  352. for (int i = 0; i < neighbours.Count; i++)
  353. {
  354. InformNeighbourThatRegionUpDelegate d = InformNeighboursThatRegionIsUpAsync;
  355. d.BeginInvoke(region, neighbours[i].RegionHandle,
  356. InformNeighborsThatRegionisUpCompleted,
  357. d);
  358. }
  359. }
  360. //bool val = m_commsProvider.InterRegion.RegionUp(new SerializableRegionInfo(region));
  361. }
  362. public delegate void SendChildAgentDataUpdateDelegate(ChildAgentDataUpdate cAgentData, ScenePresence presence);
  363. /// <summary>
  364. /// This informs all neighboring regions about the settings of it's child agent.
  365. /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
  366. ///
  367. /// This contains information, such as, Draw Distance, Camera location, Current Position, Current throttle settings, etc.
  368. ///
  369. /// </summary>
  370. private void SendChildAgentDataUpdateAsync(ChildAgentDataUpdate cAgentData, ScenePresence presence)
  371. {
  372. //m_log.Info("[INTERGRID]: Informing neighbors about my agent.");
  373. try
  374. {
  375. foreach (ulong regionHandle in presence.KnownChildRegions)
  376. {
  377. bool regionAccepted = m_commsProvider.InterRegion.ChildAgentUpdate(regionHandle, cAgentData);
  378. if (regionAccepted)
  379. {
  380. //m_log.Info("[INTERGRID]: Completed sending a neighbor an update about my agent");
  381. }
  382. else
  383. {
  384. //m_log.Info("[INTERGRID]: Failed sending a neighbor an update about my agent");
  385. }
  386. }
  387. }
  388. catch (InvalidOperationException)
  389. {
  390. // We're ignoring a collection was modified error because this data gets old and outdated fast.
  391. }
  392. }
  393. private void SendChildAgentDataUpdateCompleted(IAsyncResult iar)
  394. {
  395. SendChildAgentDataUpdateDelegate icon = (SendChildAgentDataUpdateDelegate) iar.AsyncState;
  396. icon.EndInvoke(iar);
  397. }
  398. public void SendChildAgentDataUpdate(ChildAgentDataUpdate cAgentData, ScenePresence presence)
  399. {
  400. // This assumes that we know what our neighbors are.
  401. SendChildAgentDataUpdateDelegate d = SendChildAgentDataUpdateAsync;
  402. d.BeginInvoke(cAgentData,presence,
  403. SendChildAgentDataUpdateCompleted,
  404. d);
  405. }
  406. public delegate void SendCloseChildAgentDelegate(LLUUID agentID, List<ulong> regionlst);
  407. /// <summary>
  408. /// This Closes child agents on neighboring regions
  409. /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
  410. /// </summary>
  411. private void SendCloseChildAgentAsync(LLUUID agentID, List<ulong> regionlst)
  412. {
  413. foreach (ulong regionHandle in regionlst)
  414. {
  415. bool regionAccepted = m_commsProvider.InterRegion.TellRegionToCloseChildConnection(regionHandle, agentID);
  416. if (regionAccepted)
  417. {
  418. m_log.Info("[INTERGRID]: Completed sending agent Close agent Request to neighbor");
  419. }
  420. else
  421. {
  422. m_log.Info("[INTERGRID]: Failed sending agent Close agent Request to neighbor");
  423. }
  424. }
  425. // We remove the list of known regions from the agent's known region list through an event
  426. // to scene, because, if an agent logged of, it's likely that there will be no scene presence
  427. // by the time we get to this part of the method.
  428. handlerRemoveKnownRegionFromAvatar = OnRemoveKnownRegionFromAvatar;
  429. if (handlerRemoveKnownRegionFromAvatar != null)
  430. {
  431. handlerRemoveKnownRegionFromAvatar(agentID, regionlst);
  432. }
  433. }
  434. private void SendCloseChildAgentCompleted(IAsyncResult iar)
  435. {
  436. SendCloseChildAgentDelegate icon = (SendCloseChildAgentDelegate)iar.AsyncState;
  437. icon.EndInvoke(iar);
  438. }
  439. public void SendCloseChildAgentConnections(LLUUID agentID, List<ulong> regionslst)
  440. {
  441. // This assumes that we know what our neighbors are.
  442. SendCloseChildAgentDelegate d = SendCloseChildAgentAsync;
  443. d.BeginInvoke(agentID, regionslst,
  444. SendCloseChildAgentCompleted,
  445. d);
  446. }
  447. /// <summary>
  448. /// Helper function to request neighbors from grid-comms
  449. /// </summary>
  450. /// <param name="regionHandle"></param>
  451. /// <returns></returns>
  452. public virtual RegionInfo RequestNeighbouringRegionInfo(ulong regionHandle)
  453. {
  454. //m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: Sending Grid Services Request about neighbor " + regionHandle.ToString());
  455. return m_commsProvider.GridService.RequestNeighbourInfo(regionHandle);
  456. }
  457. /// <summary>
  458. /// Requests map blocks in area of minX, maxX, minY, MaxY in world cordinates
  459. /// </summary>
  460. /// <param name="minX"></param>
  461. /// <param name="minY"></param>
  462. /// <param name="maxX"></param>
  463. /// <param name="maxY"></param>
  464. public virtual void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY)
  465. {
  466. List<MapBlockData> mapBlocks;
  467. mapBlocks = m_commsProvider.GridService.RequestNeighbourMapBlocks(minX - 4, minY - 4, minX + 4, minY + 4);
  468. remoteClient.SendMapBlock(mapBlocks, 0);
  469. }
  470. /// <summary>
  471. /// Try to teleport an agent to a new region.
  472. /// </summary>
  473. /// <param name="remoteClient"></param>
  474. /// <param name="RegionHandle"></param>
  475. /// <param name="position"></param>
  476. /// <param name="lookAt"></param>
  477. /// <param name="flags"></param>
  478. public virtual void RequestTeleportToLocation(ScenePresence avatar, ulong regionHandle, LLVector3 position,
  479. LLVector3 lookAt, uint flags)
  480. {
  481. bool destRegionUp = false;
  482. if (regionHandle == m_regionInfo.RegionHandle)
  483. {
  484. avatar.ControllingClient.SendTeleportLocationStart();
  485. avatar.ControllingClient.SendLocalTeleport(position, lookAt, flags);
  486. avatar.Teleport(position);
  487. }
  488. else
  489. {
  490. RegionInfo reg = RequestNeighbouringRegionInfo(regionHandle);
  491. if (reg != null)
  492. {
  493. avatar.ControllingClient.SendTeleportLocationStart();
  494. AgentCircuitData agent = avatar.ControllingClient.RequestClientInfo();
  495. agent.BaseFolder = LLUUID.Zero;
  496. agent.InventoryFolder = LLUUID.Zero;
  497. agent.startpos = position;
  498. agent.child = true;
  499. if (reg.RemotingAddress != "" && reg.RemotingPort != 0)
  500. {
  501. // region is remote. see if it is up
  502. m_commsProvider.InterRegion.CheckRegion(reg.RemotingAddress, reg.RemotingPort);
  503. destRegionUp = m_commsProvider.InterRegion.Available;
  504. }
  505. else
  506. {
  507. // assume local regions are always up
  508. destRegionUp = true;
  509. }
  510. if (destRegionUp)
  511. {
  512. avatar.Close();
  513. // Compared to ScenePresence.CrossToNewRegion(), there's no obvious code to handle a teleport
  514. // failure at this point (unlike a border crossing failure). So perhaps this can never fail
  515. // once we reach here...
  516. avatar.Scene.RemoveCapsHandler(avatar.UUID);
  517. m_commsProvider.InterRegion.InformRegionOfChildAgent(regionHandle, agent);
  518. m_commsProvider.InterRegion.ExpectAvatarCrossing(regionHandle, avatar.ControllingClient.AgentId,
  519. position, false);
  520. AgentCircuitData circuitdata = avatar.ControllingClient.RequestClientInfo();
  521. // TODO Should construct this behind a method
  522. string capsPath =
  523. "http://" + reg.ExternalHostName + ":" + reg.HttpPort
  524. + "/CAPS/" + circuitdata.CapsPath + "0000/";
  525. m_log.DebugFormat(
  526. "[CAPS]: Sending new CAPS seed url {0} to client {1}", capsPath, avatar.UUID);
  527. avatar.ControllingClient.SendRegionTeleport(regionHandle, 13, reg.ExternalEndPoint, 4, (1 << 4),
  528. capsPath);
  529. avatar.MakeChildAgent();
  530. Thread.Sleep(5000);
  531. avatar.CrossAttachmentsIntoNewRegion(regionHandle);
  532. if (KillObject != null)
  533. {
  534. KillObject(avatar.LocalId);
  535. }
  536. uint newRegionX = (uint)(regionHandle >> 40);
  537. uint newRegionY = (((uint)(regionHandle)) >> 8);
  538. uint oldRegionX = (uint)(m_regionInfo.RegionHandle >> 40);
  539. uint oldRegionY = (((uint)(m_regionInfo.RegionHandle)) >> 8);
  540. if (Util.fast_distance2d((int)(newRegionX - oldRegionX), (int)(newRegionY - oldRegionY)) > 3)
  541. {
  542. SendCloseChildAgentConnections(avatar.UUID,avatar.GetKnownRegionList());
  543. }
  544. }
  545. else
  546. {
  547. avatar.ControllingClient.SendTeleportFailed("Remote Region appears to be down");
  548. }
  549. }
  550. }
  551. }
  552. /// <summary>
  553. ///
  554. /// </summary>
  555. /// <param name="regionhandle"></param>
  556. /// <param name="agentID"></param>
  557. /// <param name="position"></param>
  558. public bool CrossToNeighbouringRegion(ulong regionhandle, LLUUID agentID, LLVector3 position, bool isFlying)
  559. {
  560. return m_commsProvider.InterRegion.ExpectAvatarCrossing(regionhandle, agentID, position, isFlying);
  561. }
  562. public bool PrimCrossToNeighboringRegion(ulong regionhandle, LLUUID primID, string objData, int XMLMethod)
  563. {
  564. return m_commsProvider.InterRegion.InformRegionOfPrimCrossing(regionhandle, primID, objData, XMLMethod);
  565. }
  566. public Dictionary<string, string> GetGridSettings()
  567. {
  568. return m_commsProvider.GridService.GetGridSettings();
  569. }
  570. public void LogOffUser(LLUUID userid, LLUUID regionid, ulong regionhandle, float posx, float posy, float posz)
  571. {
  572. m_commsProvider.LogOffUser(userid, regionid, regionhandle, posx, posy, posz);
  573. }
  574. public void ClearUserAgent(LLUUID avatarID)
  575. {
  576. m_commsProvider.UserService.ClearUserAgent(avatarID);
  577. }
  578. public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms)
  579. {
  580. m_commsProvider.AddNewUserFriend(friendlistowner, friend, perms);
  581. }
  582. public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms)
  583. {
  584. m_commsProvider.UpdateUserFriendPerms(friendlistowner, friend, perms);
  585. }
  586. public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend)
  587. {
  588. m_commsProvider.RemoveUserFriend(friendlistowner, friend);
  589. }
  590. public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner)
  591. {
  592. return m_commsProvider.GetUserFriendList(friendlistowner);
  593. }
  594. public List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY)
  595. {
  596. return m_commsProvider.GridService.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
  597. }
  598. public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(LLUUID queryID, string query)
  599. {
  600. return m_commsProvider.GenerateAgentPickerRequestResponse(queryID, query);
  601. }
  602. }
  603. }