SceneCommunicationService.cs 29 KB

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