SceneCommunicationService.cs 29 KB

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