EntityTransferModule.cs 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  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 OpenSimulator 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 OpenSim.Framework;
  33. using OpenSim.Framework.Capabilities;
  34. using OpenSim.Framework.Client;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenSim.Region.Framework.Scenes;
  37. using OpenSim.Services.Interfaces;
  38. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  39. using OpenMetaverse;
  40. using log4net;
  41. using Nini.Config;
  42. namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
  43. {
  44. public class EntityTransferModule : ISharedRegionModule, IEntityTransferModule
  45. {
  46. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. protected bool m_Enabled = false;
  48. protected Scene m_aScene;
  49. protected List<UUID> m_agentsInTransit;
  50. #region ISharedRegionModule
  51. public Type ReplaceableInterface
  52. {
  53. get { return null; }
  54. }
  55. public virtual string Name
  56. {
  57. get { return "BasicEntityTransferModule"; }
  58. }
  59. public virtual void Initialise(IConfigSource source)
  60. {
  61. IConfig moduleConfig = source.Configs["Modules"];
  62. if (moduleConfig != null)
  63. {
  64. string name = moduleConfig.GetString("EntityTransferModule", "");
  65. if (name == Name)
  66. {
  67. m_agentsInTransit = new List<UUID>();
  68. m_Enabled = true;
  69. m_log.InfoFormat("[ENTITY TRANSFER MODULE]: {0} enabled.", Name);
  70. }
  71. }
  72. }
  73. public virtual void PostInitialise()
  74. {
  75. }
  76. public virtual void AddRegion(Scene scene)
  77. {
  78. if (!m_Enabled)
  79. return;
  80. if (m_aScene == null)
  81. m_aScene = scene;
  82. scene.RegisterModuleInterface<IEntityTransferModule>(this);
  83. scene.EventManager.OnNewClient += OnNewClient;
  84. }
  85. protected virtual void OnNewClient(IClientAPI client)
  86. {
  87. client.OnTeleportHomeRequest += TeleportHome;
  88. }
  89. public virtual void Close()
  90. {
  91. if (!m_Enabled)
  92. return;
  93. }
  94. public virtual void RemoveRegion(Scene scene)
  95. {
  96. if (!m_Enabled)
  97. return;
  98. if (scene == m_aScene)
  99. m_aScene = null;
  100. }
  101. public virtual void RegionLoaded(Scene scene)
  102. {
  103. if (!m_Enabled)
  104. return;
  105. }
  106. #endregion
  107. #region Agent Teleports
  108. public void Teleport(ScenePresence sp, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags)
  109. {
  110. if (!sp.Scene.Permissions.CanTeleport(sp.UUID))
  111. return;
  112. IEventQueue eq = sp.Scene.RequestModuleInterface<IEventQueue>();
  113. // Reset animations; the viewer does that in teleports.
  114. sp.Animator.ResetAnimations();
  115. try
  116. {
  117. if (regionHandle == sp.Scene.RegionInfo.RegionHandle)
  118. {
  119. m_log.DebugFormat(
  120. "[ENTITY TRANSFER MODULE]: RequestTeleportToLocation {0} within {1}",
  121. position, sp.Scene.RegionInfo.RegionName);
  122. // Teleport within the same region
  123. if (IsOutsideRegion(sp.Scene, position) || position.Z < 0)
  124. {
  125. Vector3 emergencyPos = new Vector3(128, 128, 128);
  126. m_log.WarnFormat(
  127. "[ENTITY TRANSFER MODULE]: RequestTeleportToLocation() was given an illegal position of {0} for avatar {1}, {2}. Substituting {3}",
  128. position, sp.Name, sp.UUID, emergencyPos);
  129. position = emergencyPos;
  130. }
  131. // TODO: Get proper AVG Height
  132. float localAVHeight = 1.56f;
  133. float posZLimit = 22;
  134. // TODO: Check other Scene HeightField
  135. if (position.X > 0 && position.X <= (int)Constants.RegionSize && position.Y > 0 && position.Y <= (int)Constants.RegionSize)
  136. {
  137. posZLimit = (float)sp.Scene.Heightmap[(int)position.X, (int)position.Y];
  138. }
  139. float newPosZ = posZLimit + localAVHeight;
  140. if (posZLimit >= (position.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
  141. {
  142. position.Z = newPosZ;
  143. }
  144. // Only send this if the event queue is null
  145. if (eq == null)
  146. sp.ControllingClient.SendTeleportLocationStart();
  147. sp.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags);
  148. sp.Teleport(position);
  149. foreach (SceneObjectGroup grp in sp.Attachments)
  150. sp.Scene.EventManager.TriggerOnScriptChangedEvent(grp.LocalId, (uint)Changed.TELEPORT);
  151. }
  152. else // Another region possibly in another simulator
  153. {
  154. uint x = 0, y = 0;
  155. Utils.LongToUInts(regionHandle, out x, out y);
  156. GridRegion reg = m_aScene.GridService.GetRegionByPosition(sp.Scene.RegionInfo.ScopeID, (int)x, (int)y);
  157. if (reg != null)
  158. {
  159. GridRegion finalDestination = GetFinalDestination(reg);
  160. if (finalDestination == null)
  161. {
  162. m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Final destination is having problems. Unable to teleport agent.");
  163. sp.ControllingClient.SendTeleportFailed("Problem at destination");
  164. return;
  165. }
  166. m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Final destination is x={0} y={1} uuid={2}",
  167. finalDestination.RegionLocX / Constants.RegionSize, finalDestination.RegionLocY / Constants.RegionSize, finalDestination.RegionID);
  168. //
  169. // This is it
  170. //
  171. DoTeleport(sp, reg, finalDestination, position, lookAt, teleportFlags, eq);
  172. //
  173. //
  174. //
  175. }
  176. else
  177. {
  178. // TP to a place that doesn't exist (anymore)
  179. // Inform the viewer about that
  180. sp.ControllingClient.SendTeleportFailed("The region you tried to teleport to doesn't exist anymore");
  181. // and set the map-tile to '(Offline)'
  182. uint regX, regY;
  183. Utils.LongToUInts(regionHandle, out regX, out regY);
  184. MapBlockData block = new MapBlockData();
  185. block.X = (ushort)(regX / Constants.RegionSize);
  186. block.Y = (ushort)(regY / Constants.RegionSize);
  187. block.Access = 254; // == not there
  188. List<MapBlockData> blocks = new List<MapBlockData>();
  189. blocks.Add(block);
  190. sp.ControllingClient.SendMapBlock(blocks, 0);
  191. }
  192. }
  193. }
  194. catch (Exception e)
  195. {
  196. m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Exception on teleport: {0}\n{1}", e.Message, e.StackTrace);
  197. sp.ControllingClient.SendTeleportFailed("Internal error");
  198. }
  199. }
  200. protected void DoTeleport(ScenePresence sp, GridRegion reg, GridRegion finalDestination, Vector3 position, Vector3 lookAt, uint teleportFlags, IEventQueue eq)
  201. {
  202. if (reg == null || finalDestination == null)
  203. {
  204. sp.ControllingClient.SendTeleportFailed("Unable to locate destination");
  205. return;
  206. }
  207. m_log.DebugFormat(
  208. "[ENTITY TRANSFER MODULE]: Request Teleport to {0}:{1}:{2}/{3}",
  209. reg.ExternalHostName, reg.HttpPort, finalDestination.RegionName, position);
  210. uint newRegionX = (uint)(reg.RegionHandle >> 40);
  211. uint newRegionY = (((uint)(reg.RegionHandle)) >> 8);
  212. uint oldRegionX = (uint)(sp.Scene.RegionInfo.RegionHandle >> 40);
  213. uint oldRegionY = (((uint)(sp.Scene.RegionInfo.RegionHandle)) >> 8);
  214. ulong destinationHandle = finalDestination.RegionHandle;
  215. if (eq == null)
  216. sp.ControllingClient.SendTeleportLocationStart();
  217. // Let's do DNS resolution only once in this process, please!
  218. // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field,
  219. // it's actually doing a lot of work.
  220. IPEndPoint endPoint = finalDestination.ExternalEndPoint;
  221. if (endPoint.Address != null)
  222. {
  223. // Fixing a bug where teleporting while sitting results in the avatar ending up removed from
  224. // both regions
  225. if (sp.ParentID != (uint)0)
  226. sp.StandUp();
  227. if (!sp.ValidateAttachments())
  228. {
  229. sp.ControllingClient.SendTeleportFailed("Inconsistent attachment state");
  230. return;
  231. }
  232. // the avatar.Close below will clear the child region list. We need this below for (possibly)
  233. // closing the child agents, so save it here (we need a copy as it is Clear()-ed).
  234. //List<ulong> childRegions = new List<ulong>(avatar.GetKnownRegionList());
  235. // Compared to ScenePresence.CrossToNewRegion(), there's no obvious code to handle a teleport
  236. // failure at this point (unlike a border crossing failure). So perhaps this can never fail
  237. // once we reach here...
  238. //avatar.Scene.RemoveCapsHandler(avatar.UUID);
  239. string capsPath = String.Empty;
  240. AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
  241. AgentCircuitData agentCircuit = sp.ControllingClient.RequestClientInfo();
  242. agentCircuit.startpos = position;
  243. agentCircuit.child = true;
  244. agentCircuit.Appearance = sp.Appearance;
  245. if (currentAgentCircuit != null)
  246. {
  247. agentCircuit.ServiceURLs = currentAgentCircuit.ServiceURLs;
  248. agentCircuit.Viewer = currentAgentCircuit.Viewer;
  249. }
  250. if (NeedsNewAgent(oldRegionX, newRegionX, oldRegionY, newRegionY))
  251. {
  252. // brand new agent, let's create a new caps seed
  253. agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
  254. }
  255. string reason = String.Empty;
  256. // Let's create an agent there if one doesn't exist yet.
  257. if (!CreateAgent(sp, reg, finalDestination, agentCircuit, teleportFlags, out reason))
  258. {
  259. sp.ControllingClient.SendTeleportFailed(String.Format("Destination refused: {0}",
  260. reason));
  261. return;
  262. }
  263. // OK, it got this agent. Let's close some child agents
  264. sp.CloseChildAgents(newRegionX, newRegionY);
  265. if (NeedsNewAgent(oldRegionX, newRegionX, oldRegionY, newRegionY))
  266. {
  267. #region IP Translation for NAT
  268. IClientIPEndpoint ipepClient;
  269. if (sp.ClientView.TryGet(out ipepClient))
  270. {
  271. capsPath
  272. = "http://"
  273. + NetworkUtil.GetHostFor(ipepClient.EndPoint, finalDestination.ExternalHostName)
  274. + ":"
  275. + finalDestination.HttpPort
  276. + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
  277. }
  278. else
  279. {
  280. capsPath
  281. = "http://"
  282. + finalDestination.ExternalHostName
  283. + ":"
  284. + finalDestination.HttpPort
  285. + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
  286. }
  287. #endregion
  288. if (eq != null)
  289. {
  290. #region IP Translation for NAT
  291. // Uses ipepClient above
  292. if (sp.ClientView.TryGet(out ipepClient))
  293. {
  294. endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
  295. }
  296. #endregion
  297. eq.EnableSimulator(destinationHandle, endPoint, sp.UUID);
  298. // ES makes the client send a UseCircuitCode message to the destination,
  299. // which triggers a bunch of things there.
  300. // So let's wait
  301. Thread.Sleep(200);
  302. eq.EstablishAgentCommunication(sp.UUID, endPoint, capsPath);
  303. }
  304. else
  305. {
  306. sp.ControllingClient.InformClientOfNeighbour(destinationHandle, endPoint);
  307. }
  308. }
  309. else
  310. {
  311. agentCircuit.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, reg.RegionHandle);
  312. capsPath = "http://" + finalDestination.ExternalHostName + ":" + finalDestination.HttpPort
  313. + "/CAPS/" + agentCircuit.CapsPath + "0000/";
  314. }
  315. // Expect avatar crossing is a heavy-duty function at the destination.
  316. // That is where MakeRoot is called, which fetches appearance and inventory.
  317. // Plus triggers OnMakeRoot, which spawns a series of asynchronous updates.
  318. //m_commsProvider.InterRegion.ExpectAvatarCrossing(reg.RegionHandle, avatar.ControllingClient.AgentId,
  319. // position, false);
  320. //{
  321. // avatar.ControllingClient.SendTeleportFailed("Problem with destination.");
  322. // // We should close that agent we just created over at destination...
  323. // List<ulong> lst = new List<ulong>();
  324. // lst.Add(reg.RegionHandle);
  325. // SendCloseChildAgentAsync(avatar.UUID, lst);
  326. // return;
  327. //}
  328. SetInTransit(sp.UUID);
  329. // Let's send a full update of the agent. This is a synchronous call.
  330. AgentData agent = new AgentData();
  331. sp.CopyTo(agent);
  332. agent.Position = position;
  333. SetCallbackURL(agent, sp.Scene.RegionInfo);
  334. if (!UpdateAgent(reg, finalDestination, agent))
  335. {
  336. // Region doesn't take it
  337. Fail(sp, finalDestination);
  338. return;
  339. }
  340. m_log.DebugFormat(
  341. "[ENTITY TRANSFER MODULE]: Sending new CAPS seed url {0} to client {1}", capsPath, sp.UUID);
  342. if (eq != null)
  343. {
  344. eq.TeleportFinishEvent(destinationHandle, 13, endPoint,
  345. 0, teleportFlags, capsPath, sp.UUID);
  346. }
  347. else
  348. {
  349. sp.ControllingClient.SendRegionTeleport(destinationHandle, 13, endPoint, 4,
  350. teleportFlags, capsPath);
  351. }
  352. // Let's set this to true tentatively. This does not trigger OnChildAgent
  353. sp.IsChildAgent = true;
  354. // TeleportFinish makes the client send CompleteMovementIntoRegion (at the destination), which
  355. // trigers a whole shebang of things there, including MakeRoot. So let's wait for confirmation
  356. // that the client contacted the destination before we send the attachments and close things here.
  357. if (!WaitForCallback(sp.UUID))
  358. {
  359. Fail(sp, finalDestination);
  360. return;
  361. }
  362. // CrossAttachmentsIntoNewRegion is a synchronous call. We shouldn't need to wait after it
  363. CrossAttachmentsIntoNewRegion(finalDestination, sp, true);
  364. KillEntity(sp.Scene, sp.LocalId);
  365. // Now let's make it officially a child agent
  366. sp.MakeChildAgent();
  367. // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone
  368. if (NeedsClosing(oldRegionX, newRegionX, oldRegionY, newRegionY, reg))
  369. {
  370. Thread.Sleep(5000);
  371. sp.Close();
  372. sp.Scene.IncomingCloseAgent(sp.UUID);
  373. }
  374. else
  375. // now we have a child agent in this region.
  376. sp.Reset();
  377. // REFACTORING PROBLEM. Well, not a problem, but this method is HORRIBLE!
  378. if (sp.Scene.NeedSceneCacheClear(sp.UUID))
  379. {
  380. m_log.DebugFormat(
  381. "[ENTITY TRANSFER MODULE]: User {0} is going to another region, profile cache removed",
  382. sp.UUID);
  383. }
  384. }
  385. else
  386. {
  387. sp.ControllingClient.SendTeleportFailed("Remote Region appears to be down");
  388. }
  389. }
  390. private void Fail(ScenePresence sp, GridRegion finalDestination)
  391. {
  392. // Client never contacted destination. Let's restore everything back
  393. sp.ControllingClient.SendTeleportFailed("Problems connecting to destination.");
  394. // Fail. Reset it back
  395. sp.IsChildAgent = false;
  396. ResetFromTransit(sp.UUID);
  397. EnableChildAgents(sp);
  398. // Finally, kill the agent we just created at the destination.
  399. m_aScene.SimulationService.CloseAgent(finalDestination, sp.UUID);
  400. }
  401. protected virtual bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason)
  402. {
  403. return m_aScene.SimulationService.CreateAgent(finalDestination, agentCircuit, teleportFlags, out reason);
  404. }
  405. protected virtual bool UpdateAgent(GridRegion reg, GridRegion finalDestination, AgentData agent)
  406. {
  407. return m_aScene.SimulationService.UpdateAgent(finalDestination, agent);
  408. }
  409. protected virtual void SetCallbackURL(AgentData agent, RegionInfo region)
  410. {
  411. agent.CallbackURI = "http://" + region.ExternalHostName + ":" + region.HttpPort +
  412. "/agent/" + agent.AgentID.ToString() + "/" + region.RegionID.ToString() + "/release/";
  413. }
  414. protected void KillEntity(Scene scene, uint localID)
  415. {
  416. scene.SendKillObject(localID);
  417. }
  418. protected virtual GridRegion GetFinalDestination(GridRegion region)
  419. {
  420. return region;
  421. }
  422. protected virtual bool NeedsNewAgent(uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY)
  423. {
  424. return Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY);
  425. }
  426. protected virtual bool NeedsClosing(uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY, GridRegion reg)
  427. {
  428. return Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY);
  429. }
  430. protected virtual bool IsOutsideRegion(Scene s, Vector3 pos)
  431. {
  432. if (s.TestBorderCross(pos, Cardinals.N))
  433. return true;
  434. if (s.TestBorderCross(pos, Cardinals.S))
  435. return true;
  436. if (s.TestBorderCross(pos, Cardinals.E))
  437. return true;
  438. if (s.TestBorderCross(pos, Cardinals.W))
  439. return true;
  440. return false;
  441. }
  442. #endregion
  443. #region Teleport Home
  444. public virtual void TeleportHome(UUID id, IClientAPI client)
  445. {
  446. m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Request to teleport {0} {1} home", client.FirstName, client.LastName);
  447. //OpenSim.Services.Interfaces.PresenceInfo pinfo = m_aScene.PresenceService.GetAgent(client.SessionId);
  448. GridUserInfo uinfo = m_aScene.GridUserService.GetGridUserInfo(client.AgentId.ToString());
  449. if (uinfo != null)
  450. {
  451. GridRegion regionInfo = m_aScene.GridService.GetRegionByUUID(UUID.Zero, uinfo.HomeRegionID);
  452. if (regionInfo == null)
  453. {
  454. // can't find the Home region: Tell viewer and abort
  455. client.SendTeleportFailed("Your home region could not be found.");
  456. return;
  457. }
  458. m_log.DebugFormat("[ENTITY TRANSFER MODULE]: User's home region is {0} {1} ({2}-{3})",
  459. regionInfo.RegionName, regionInfo.RegionID, regionInfo.RegionLocX / Constants.RegionSize, regionInfo.RegionLocY / Constants.RegionSize);
  460. // a little eekie that this goes back to Scene and with a forced cast, will fix that at some point...
  461. ((Scene)(client.Scene)).RequestTeleportLocation(
  462. client, regionInfo.RegionHandle, uinfo.HomePosition, uinfo.HomeLookAt,
  463. (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
  464. }
  465. }
  466. #endregion
  467. #region Agent Crossings
  468. public void Cross(ScenePresence agent, bool isFlying)
  469. {
  470. Scene scene = agent.Scene;
  471. Vector3 pos = agent.AbsolutePosition;
  472. Vector3 newpos = new Vector3(pos.X, pos.Y, pos.Z);
  473. uint neighbourx = scene.RegionInfo.RegionLocX;
  474. uint neighboury = scene.RegionInfo.RegionLocY;
  475. const float boundaryDistance = 1.7f;
  476. Vector3 northCross = new Vector3(0, boundaryDistance, 0);
  477. Vector3 southCross = new Vector3(0, -1 * boundaryDistance, 0);
  478. Vector3 eastCross = new Vector3(boundaryDistance, 0, 0);
  479. Vector3 westCross = new Vector3(-1 * boundaryDistance, 0, 0);
  480. // distance to edge that will trigger crossing
  481. // distance into new region to place avatar
  482. const float enterDistance = 0.5f;
  483. if (scene.TestBorderCross(pos + westCross, Cardinals.W))
  484. {
  485. if (scene.TestBorderCross(pos + northCross, Cardinals.N))
  486. {
  487. Border b = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
  488. neighboury += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
  489. }
  490. else if (scene.TestBorderCross(pos + southCross, Cardinals.S))
  491. {
  492. Border b = scene.GetCrossedBorder(pos + southCross, Cardinals.S);
  493. if (b.TriggerRegionX == 0 && b.TriggerRegionY == 0)
  494. {
  495. neighboury--;
  496. newpos.Y = Constants.RegionSize - enterDistance;
  497. }
  498. else
  499. {
  500. neighboury = b.TriggerRegionY;
  501. neighbourx = b.TriggerRegionX;
  502. Vector3 newposition = pos;
  503. newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
  504. newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
  505. agent.ControllingClient.SendAgentAlertMessage(
  506. String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
  507. InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
  508. return;
  509. }
  510. }
  511. Border ba = scene.GetCrossedBorder(pos + westCross, Cardinals.W);
  512. if (ba.TriggerRegionX == 0 && ba.TriggerRegionY == 0)
  513. {
  514. neighbourx--;
  515. newpos.X = Constants.RegionSize - enterDistance;
  516. }
  517. else
  518. {
  519. neighboury = ba.TriggerRegionY;
  520. neighbourx = ba.TriggerRegionX;
  521. Vector3 newposition = pos;
  522. newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
  523. newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
  524. agent.ControllingClient.SendAgentAlertMessage(
  525. String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
  526. InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
  527. return;
  528. }
  529. }
  530. else if (scene.TestBorderCross(pos + eastCross, Cardinals.E))
  531. {
  532. Border b = scene.GetCrossedBorder(pos + eastCross, Cardinals.E);
  533. neighbourx += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
  534. newpos.X = enterDistance;
  535. if (scene.TestBorderCross(pos + southCross, Cardinals.S))
  536. {
  537. Border ba = scene.GetCrossedBorder(pos + southCross, Cardinals.S);
  538. if (ba.TriggerRegionX == 0 && ba.TriggerRegionY == 0)
  539. {
  540. neighboury--;
  541. newpos.Y = Constants.RegionSize - enterDistance;
  542. }
  543. else
  544. {
  545. neighboury = ba.TriggerRegionY;
  546. neighbourx = ba.TriggerRegionX;
  547. Vector3 newposition = pos;
  548. newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
  549. newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
  550. agent.ControllingClient.SendAgentAlertMessage(
  551. String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
  552. InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
  553. return;
  554. }
  555. }
  556. else if (scene.TestBorderCross(pos + northCross, Cardinals.N))
  557. {
  558. Border c = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
  559. neighboury += (uint)(int)(c.BorderLine.Z / (int)Constants.RegionSize);
  560. newpos.Y = enterDistance;
  561. }
  562. }
  563. else if (scene.TestBorderCross(pos + southCross, Cardinals.S))
  564. {
  565. Border b = scene.GetCrossedBorder(pos + southCross, Cardinals.S);
  566. if (b.TriggerRegionX == 0 && b.TriggerRegionY == 0)
  567. {
  568. neighboury--;
  569. newpos.Y = Constants.RegionSize - enterDistance;
  570. }
  571. else
  572. {
  573. neighboury = b.TriggerRegionY;
  574. neighbourx = b.TriggerRegionX;
  575. Vector3 newposition = pos;
  576. newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
  577. newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
  578. agent.ControllingClient.SendAgentAlertMessage(
  579. String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
  580. InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
  581. return;
  582. }
  583. }
  584. else if (scene.TestBorderCross(pos + northCross, Cardinals.N))
  585. {
  586. Border b = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
  587. neighboury += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
  588. newpos.Y = enterDistance;
  589. }
  590. /*
  591. if (pos.X < boundaryDistance) //West
  592. {
  593. neighbourx--;
  594. newpos.X = Constants.RegionSize - enterDistance;
  595. }
  596. else if (pos.X > Constants.RegionSize - boundaryDistance) // East
  597. {
  598. neighbourx++;
  599. newpos.X = enterDistance;
  600. }
  601. if (pos.Y < boundaryDistance) // South
  602. {
  603. neighboury--;
  604. newpos.Y = Constants.RegionSize - enterDistance;
  605. }
  606. else if (pos.Y > Constants.RegionSize - boundaryDistance) // North
  607. {
  608. neighboury++;
  609. newpos.Y = enterDistance;
  610. }
  611. */
  612. CrossAgentToNewRegionDelegate d = CrossAgentToNewRegionAsync;
  613. d.BeginInvoke(agent, newpos, neighbourx, neighboury, isFlying, CrossAgentToNewRegionCompleted, d);
  614. }
  615. public delegate void InformClientToInitateTeleportToLocationDelegate(ScenePresence agent, uint regionX, uint regionY,
  616. Vector3 position,
  617. Scene initiatingScene);
  618. private void InformClientToInitateTeleportToLocation(ScenePresence agent, uint regionX, uint regionY, Vector3 position, Scene initiatingScene)
  619. {
  620. // This assumes that we know what our neighbors are.
  621. InformClientToInitateTeleportToLocationDelegate d = InformClientToInitiateTeleportToLocationAsync;
  622. d.BeginInvoke(agent, regionX, regionY, position, initiatingScene,
  623. InformClientToInitiateTeleportToLocationCompleted,
  624. d);
  625. }
  626. public void InformClientToInitiateTeleportToLocationAsync(ScenePresence agent, uint regionX, uint regionY, Vector3 position,
  627. Scene initiatingScene)
  628. {
  629. Thread.Sleep(10000);
  630. IMessageTransferModule im = initiatingScene.RequestModuleInterface<IMessageTransferModule>();
  631. if (im != null)
  632. {
  633. UUID gotoLocation = Util.BuildFakeParcelID(
  634. Util.UIntsToLong(
  635. (regionX *
  636. (uint)Constants.RegionSize),
  637. (regionY *
  638. (uint)Constants.RegionSize)),
  639. (uint)(int)position.X,
  640. (uint)(int)position.Y,
  641. (uint)(int)position.Z);
  642. GridInstantMessage m = new GridInstantMessage(initiatingScene, UUID.Zero,
  643. "Region", agent.UUID,
  644. (byte)InstantMessageDialog.GodLikeRequestTeleport, false,
  645. "", gotoLocation, false, new Vector3(127, 0, 0),
  646. new Byte[0]);
  647. im.SendInstantMessage(m, delegate(bool success)
  648. {
  649. m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Client Initiating Teleport sending IM success = {0}", success);
  650. });
  651. }
  652. }
  653. private void InformClientToInitiateTeleportToLocationCompleted(IAsyncResult iar)
  654. {
  655. InformClientToInitateTeleportToLocationDelegate icon =
  656. (InformClientToInitateTeleportToLocationDelegate)iar.AsyncState;
  657. icon.EndInvoke(iar);
  658. }
  659. public delegate ScenePresence CrossAgentToNewRegionDelegate(ScenePresence agent, Vector3 pos, uint neighbourx, uint neighboury, bool isFlying);
  660. /// <summary>
  661. /// This Closes child agents on neighboring regions
  662. /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
  663. /// </summary>
  664. protected ScenePresence CrossAgentToNewRegionAsync(ScenePresence agent, Vector3 pos, uint neighbourx, uint neighboury, bool isFlying)
  665. {
  666. m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Crossing agent {0} {1} to {2}-{3}", agent.Firstname, agent.Lastname, neighbourx, neighboury);
  667. Scene m_scene = agent.Scene;
  668. ulong neighbourHandle = Utils.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize));
  669. int x = (int)(neighbourx * Constants.RegionSize), y = (int)(neighboury * Constants.RegionSize);
  670. GridRegion neighbourRegion = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
  671. if (neighbourRegion != null && agent.ValidateAttachments())
  672. {
  673. pos = pos + (agent.Velocity);
  674. SetInTransit(agent.UUID);
  675. AgentData cAgent = new AgentData();
  676. agent.CopyTo(cAgent);
  677. cAgent.Position = pos;
  678. if (isFlying)
  679. cAgent.ControlFlags |= (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;
  680. cAgent.CallbackURI = "http://" + m_scene.RegionInfo.ExternalHostName + ":" + m_scene.RegionInfo.HttpPort +
  681. "/agent/" + agent.UUID.ToString() + "/" + m_scene.RegionInfo.RegionID.ToString() + "/release/";
  682. if (!m_scene.SimulationService.UpdateAgent(neighbourRegion, cAgent))
  683. {
  684. // region doesn't take it
  685. ResetFromTransit(agent.UUID);
  686. return agent;
  687. }
  688. // Next, let's close the child agent connections that are too far away.
  689. agent.CloseChildAgents(neighbourx, neighboury);
  690. //AgentCircuitData circuitdata = m_controllingClient.RequestClientInfo();
  691. agent.ControllingClient.RequestClientInfo();
  692. //m_log.Debug("BEFORE CROSS");
  693. //Scene.DumpChildrenSeeds(UUID);
  694. //DumpKnownRegions();
  695. string agentcaps;
  696. if (!agent.KnownRegions.TryGetValue(neighbourRegion.RegionHandle, out agentcaps))
  697. {
  698. m_log.ErrorFormat("[ENTITY TRANSFER MODULE]: No ENTITY TRANSFER MODULE information for region handle {0}, exiting CrossToNewRegion.",
  699. neighbourRegion.RegionHandle);
  700. return agent;
  701. }
  702. // TODO Should construct this behind a method
  703. string capsPath =
  704. "http://" + neighbourRegion.ExternalHostName + ":" + neighbourRegion.HttpPort
  705. + "/CAPS/" + agentcaps /*circuitdata.CapsPath*/ + "0000/";
  706. m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Sending new CAPS seed url {0} to client {1}", capsPath, agent.UUID);
  707. IEventQueue eq = agent.Scene.RequestModuleInterface<IEventQueue>();
  708. if (eq != null)
  709. {
  710. eq.CrossRegion(neighbourHandle, pos, agent.Velocity, neighbourRegion.ExternalEndPoint,
  711. capsPath, agent.UUID, agent.ControllingClient.SessionId);
  712. }
  713. else
  714. {
  715. agent.ControllingClient.CrossRegion(neighbourHandle, pos, agent.Velocity, neighbourRegion.ExternalEndPoint,
  716. capsPath);
  717. }
  718. if (!WaitForCallback(agent.UUID))
  719. {
  720. m_log.Debug("[ENTITY TRANSFER MODULE]: Callback never came in crossing agent");
  721. ResetFromTransit(agent.UUID);
  722. // Yikes! We should just have a ref to scene here.
  723. //agent.Scene.InformClientOfNeighbours(agent);
  724. EnableChildAgents(agent);
  725. return agent;
  726. }
  727. agent.MakeChildAgent();
  728. // now we have a child agent in this region. Request all interesting data about other (root) agents
  729. agent.SendInitialFullUpdateToAllClients();
  730. CrossAttachmentsIntoNewRegion(neighbourRegion, agent, true);
  731. // the user may change their profile information in other region,
  732. // so the userinfo in UserProfileCache is not reliable any more, delete it
  733. // REFACTORING PROBLEM. Well, not a problem, but this method is HORRIBLE!
  734. if (agent.Scene.NeedSceneCacheClear(agent.UUID))
  735. {
  736. m_log.DebugFormat(
  737. "[ENTITY TRANSFER MODULE]: User {0} is going to another region", agent.UUID);
  738. }
  739. }
  740. //m_log.Debug("AFTER CROSS");
  741. //Scene.DumpChildrenSeeds(UUID);
  742. //DumpKnownRegions();
  743. return agent;
  744. }
  745. private void CrossAgentToNewRegionCompleted(IAsyncResult iar)
  746. {
  747. CrossAgentToNewRegionDelegate icon = (CrossAgentToNewRegionDelegate)iar.AsyncState;
  748. ScenePresence agent = icon.EndInvoke(iar);
  749. // If the cross was successful, this agent is a child agent
  750. if (agent.IsChildAgent)
  751. agent.Reset();
  752. else // Not successful
  753. agent.RestoreInCurrentScene();
  754. // In any case
  755. agent.NotInTransit();
  756. //m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Crossing agent {0} {1} completed.", agent.Firstname, agent.Lastname);
  757. }
  758. #endregion
  759. #region Enable Child Agent
  760. /// <summary>
  761. /// This informs a single neighboring region about agent "avatar".
  762. /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
  763. /// </summary>
  764. public void EnableChildAgent(ScenePresence sp, GridRegion region)
  765. {
  766. m_log.DebugFormat("[ENTITY TRANSFER]: Enabling child agent in new neighour {0}", region.RegionName);
  767. AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
  768. AgentCircuitData agent = sp.ControllingClient.RequestClientInfo();
  769. agent.BaseFolder = UUID.Zero;
  770. agent.InventoryFolder = UUID.Zero;
  771. agent.startpos = new Vector3(128, 128, 70);
  772. agent.child = true;
  773. agent.Appearance = sp.Appearance;
  774. agent.CapsPath = CapsUtil.GetRandomCapsObjectPath();
  775. agent.ChildrenCapSeeds = new Dictionary<ulong, string>(sp.Scene.CapsModule.GetChildrenSeeds(sp.UUID));
  776. m_log.DebugFormat("[XXX] Seeds 1 {0}", agent.ChildrenCapSeeds.Count);
  777. if (!agent.ChildrenCapSeeds.ContainsKey(sp.Scene.RegionInfo.RegionHandle))
  778. agent.ChildrenCapSeeds.Add(sp.Scene.RegionInfo.RegionHandle, sp.ControllingClient.RequestClientInfo().CapsPath);
  779. m_log.DebugFormat("[XXX] Seeds 2 {0}", agent.ChildrenCapSeeds.Count);
  780. sp.AddNeighbourRegion(region.RegionHandle, agent.CapsPath);
  781. foreach (ulong h in agent.ChildrenCapSeeds.Keys)
  782. m_log.DebugFormat("[XXX] --> {0}", h);
  783. m_log.DebugFormat("[XXX] Adding {0}", region.RegionHandle);
  784. agent.ChildrenCapSeeds.Add(region.RegionHandle, agent.CapsPath);
  785. if (sp.Scene.CapsModule != null)
  786. {
  787. sp.Scene.CapsModule.SetChildrenSeed(sp.UUID, agent.ChildrenCapSeeds);
  788. }
  789. if (currentAgentCircuit != null)
  790. {
  791. agent.ServiceURLs = currentAgentCircuit.ServiceURLs;
  792. agent.Viewer = currentAgentCircuit.Viewer;
  793. }
  794. InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync;
  795. d.BeginInvoke(sp, agent, region, region.ExternalEndPoint, true,
  796. InformClientOfNeighbourCompleted,
  797. d);
  798. }
  799. #endregion
  800. #region Enable Child Agents
  801. private delegate void InformClientOfNeighbourDelegate(
  802. ScenePresence avatar, AgentCircuitData a, GridRegion reg, IPEndPoint endPoint, bool newAgent);
  803. /// <summary>
  804. /// This informs all neighboring regions about agent "avatar".
  805. /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
  806. /// </summary>
  807. public void EnableChildAgents(ScenePresence sp)
  808. {
  809. List<GridRegion> neighbours = new List<GridRegion>();
  810. RegionInfo m_regionInfo = sp.Scene.RegionInfo;
  811. if (m_regionInfo != null)
  812. {
  813. neighbours = RequestNeighbours(sp.Scene, m_regionInfo.RegionLocX, m_regionInfo.RegionLocY);
  814. }
  815. else
  816. {
  817. m_log.Debug("[ENTITY TRANSFER MODULE]: m_regionInfo was null in EnableChildAgents, is this a NPC?");
  818. }
  819. /// We need to find the difference between the new regions where there are no child agents
  820. /// and the regions where there are already child agents. We only send notification to the former.
  821. List<ulong> neighbourHandles = NeighbourHandles(neighbours); // on this region
  822. neighbourHandles.Add(sp.Scene.RegionInfo.RegionHandle); // add this region too
  823. List<ulong> previousRegionNeighbourHandles;
  824. if (sp.Scene.CapsModule != null)
  825. {
  826. previousRegionNeighbourHandles =
  827. new List<ulong>(sp.Scene.CapsModule.GetChildrenSeeds(sp.UUID).Keys);
  828. }
  829. else
  830. {
  831. previousRegionNeighbourHandles = new List<ulong>();
  832. }
  833. List<ulong> newRegions = NewNeighbours(neighbourHandles, previousRegionNeighbourHandles);
  834. List<ulong> oldRegions = OldNeighbours(neighbourHandles, previousRegionNeighbourHandles);
  835. //Dump("Current Neighbors", neighbourHandles);
  836. //Dump("Previous Neighbours", previousRegionNeighbourHandles);
  837. //Dump("New Neighbours", newRegions);
  838. //Dump("Old Neighbours", oldRegions);
  839. /// Update the scene presence's known regions here on this region
  840. sp.DropOldNeighbours(oldRegions);
  841. /// Collect as many seeds as possible
  842. Dictionary<ulong, string> seeds;
  843. if (sp.Scene.CapsModule != null)
  844. seeds
  845. = new Dictionary<ulong, string>(sp.Scene.CapsModule.GetChildrenSeeds(sp.UUID));
  846. else
  847. seeds = new Dictionary<ulong, string>();
  848. //m_log.Debug(" !!! No. of seeds: " + seeds.Count);
  849. if (!seeds.ContainsKey(sp.Scene.RegionInfo.RegionHandle))
  850. seeds.Add(sp.Scene.RegionInfo.RegionHandle, sp.ControllingClient.RequestClientInfo().CapsPath);
  851. /// Create the necessary child agents
  852. List<AgentCircuitData> cagents = new List<AgentCircuitData>();
  853. foreach (GridRegion neighbour in neighbours)
  854. {
  855. if (neighbour.RegionHandle != sp.Scene.RegionInfo.RegionHandle)
  856. {
  857. AgentCircuitData currentAgentCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
  858. AgentCircuitData agent = sp.ControllingClient.RequestClientInfo();
  859. agent.BaseFolder = UUID.Zero;
  860. agent.InventoryFolder = UUID.Zero;
  861. agent.startpos = new Vector3(128, 128, 70);
  862. agent.child = true;
  863. agent.Appearance = sp.Appearance;
  864. if (currentAgentCircuit != null)
  865. {
  866. agent.ServiceURLs = currentAgentCircuit.ServiceURLs;
  867. agent.Viewer = currentAgentCircuit.Viewer;
  868. }
  869. if (newRegions.Contains(neighbour.RegionHandle))
  870. {
  871. agent.CapsPath = CapsUtil.GetRandomCapsObjectPath();
  872. sp.AddNeighbourRegion(neighbour.RegionHandle, agent.CapsPath);
  873. seeds.Add(neighbour.RegionHandle, agent.CapsPath);
  874. }
  875. else
  876. agent.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, neighbour.RegionHandle);
  877. cagents.Add(agent);
  878. }
  879. }
  880. /// Update all child agent with everyone's seeds
  881. foreach (AgentCircuitData a in cagents)
  882. {
  883. a.ChildrenCapSeeds = new Dictionary<ulong, string>(seeds);
  884. }
  885. if (sp.Scene.CapsModule != null)
  886. {
  887. sp.Scene.CapsModule.SetChildrenSeed(sp.UUID, seeds);
  888. }
  889. sp.KnownRegions = seeds;
  890. //avatar.Scene.DumpChildrenSeeds(avatar.UUID);
  891. //avatar.DumpKnownRegions();
  892. bool newAgent = false;
  893. int count = 0;
  894. foreach (GridRegion neighbour in neighbours)
  895. {
  896. //m_log.WarnFormat("--> Going to send child agent to {0}", neighbour.RegionName);
  897. // Don't do it if there's already an agent in that region
  898. if (newRegions.Contains(neighbour.RegionHandle))
  899. newAgent = true;
  900. else
  901. newAgent = false;
  902. if (neighbour.RegionHandle != sp.Scene.RegionInfo.RegionHandle)
  903. {
  904. InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync;
  905. try
  906. {
  907. d.BeginInvoke(sp, cagents[count], neighbour, neighbour.ExternalEndPoint, newAgent,
  908. InformClientOfNeighbourCompleted,
  909. d);
  910. }
  911. catch (ArgumentOutOfRangeException)
  912. {
  913. m_log.ErrorFormat(
  914. "[ENTITY TRANSFER MODULE]: Neighbour Regions response included the current region in the neighbor list. The following region will not display to the client: {0} for region {1} ({2}, {3}).",
  915. neighbour.ExternalHostName,
  916. neighbour.RegionHandle,
  917. neighbour.RegionLocX,
  918. neighbour.RegionLocY);
  919. }
  920. catch (Exception e)
  921. {
  922. m_log.ErrorFormat(
  923. "[ENTITY TRANSFER MODULE]: Could not resolve external hostname {0} for region {1} ({2}, {3}). {4}",
  924. neighbour.ExternalHostName,
  925. neighbour.RegionHandle,
  926. neighbour.RegionLocX,
  927. neighbour.RegionLocY,
  928. e);
  929. // FIXME: Okay, even though we've failed, we're still going to throw the exception on,
  930. // since I don't know what will happen if we just let the client continue
  931. // XXX: Well, decided to swallow the exception instead for now. Let us see how that goes.
  932. // throw e;
  933. }
  934. }
  935. count++;
  936. }
  937. }
  938. private void InformClientOfNeighbourCompleted(IAsyncResult iar)
  939. {
  940. InformClientOfNeighbourDelegate icon = (InformClientOfNeighbourDelegate)iar.AsyncState;
  941. icon.EndInvoke(iar);
  942. //m_log.WarnFormat(" --> InformClientOfNeighbourCompleted");
  943. }
  944. /// <summary>
  945. /// Async component for informing client of which neighbours exist
  946. /// </summary>
  947. /// <remarks>
  948. /// This needs to run asynchronously, as a network timeout may block the thread for a long while
  949. /// </remarks>
  950. /// <param name="remoteClient"></param>
  951. /// <param name="a"></param>
  952. /// <param name="regionHandle"></param>
  953. /// <param name="endPoint"></param>
  954. private void InformClientOfNeighbourAsync(ScenePresence sp, AgentCircuitData a, GridRegion reg,
  955. IPEndPoint endPoint, bool newAgent)
  956. {
  957. // Let's wait just a little to give time to originating regions to catch up with closing child agents
  958. // after a cross here
  959. Thread.Sleep(500);
  960. Scene m_scene = sp.Scene;
  961. uint x, y;
  962. Utils.LongToUInts(reg.RegionHandle, out x, out y);
  963. x = x / Constants.RegionSize;
  964. y = y / Constants.RegionSize;
  965. m_log.Info("[ENTITY TRANSFER MODULE]: Starting to inform client about neighbour " + x + ", " + y + "(" + endPoint.ToString() + ")");
  966. string capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort
  967. + "/CAPS/" + a.CapsPath + "0000/";
  968. string reason = String.Empty;
  969. bool regionAccepted = m_scene.SimulationService.CreateAgent(reg, a, (uint)TeleportFlags.Default, out reason);
  970. if (regionAccepted && newAgent)
  971. {
  972. IEventQueue eq = sp.Scene.RequestModuleInterface<IEventQueue>();
  973. if (eq != null)
  974. {
  975. #region IP Translation for NAT
  976. IClientIPEndpoint ipepClient;
  977. if (sp.ClientView.TryGet(out ipepClient))
  978. {
  979. endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
  980. }
  981. #endregion
  982. m_log.DebugFormat("[ENTITY TRANSFER MODULE]: {0} is sending {1} EnableSimulator for neighbor region {2} @ {3} " +
  983. "and EstablishAgentCommunication with seed cap {4}",
  984. m_scene.RegionInfo.RegionName, sp.Name, reg.RegionName, reg.RegionHandle, capsPath);
  985. eq.EnableSimulator(reg.RegionHandle, endPoint, sp.UUID);
  986. eq.EstablishAgentCommunication(sp.UUID, endPoint, capsPath);
  987. }
  988. else
  989. {
  990. sp.ControllingClient.InformClientOfNeighbour(reg.RegionHandle, endPoint);
  991. // TODO: make Event Queue disablable!
  992. }
  993. m_log.Info("[ENTITY TRANSFER MODULE]: Completed inform client about neighbour " + endPoint.ToString());
  994. }
  995. }
  996. protected List<GridRegion> RequestNeighbours(Scene pScene, uint pRegionLocX, uint pRegionLocY)
  997. {
  998. RegionInfo m_regionInfo = pScene.RegionInfo;
  999. Border[] northBorders = pScene.NorthBorders.ToArray();
  1000. Border[] southBorders = pScene.SouthBorders.ToArray();
  1001. Border[] eastBorders = pScene.EastBorders.ToArray();
  1002. Border[] westBorders = pScene.WestBorders.ToArray();
  1003. // Legacy one region. Provided for simplicity while testing the all inclusive method in the else statement.
  1004. if (northBorders.Length <= 1 && southBorders.Length <= 1 && eastBorders.Length <= 1 && westBorders.Length <= 1)
  1005. {
  1006. return pScene.GridService.GetNeighbours(m_regionInfo.ScopeID, m_regionInfo.RegionID);
  1007. }
  1008. else
  1009. {
  1010. Vector2 extent = Vector2.Zero;
  1011. for (int i = 0; i < eastBorders.Length; i++)
  1012. {
  1013. extent.X = (eastBorders[i].BorderLine.Z > extent.X) ? eastBorders[i].BorderLine.Z : extent.X;
  1014. }
  1015. for (int i = 0; i < northBorders.Length; i++)
  1016. {
  1017. extent.Y = (northBorders[i].BorderLine.Z > extent.Y) ? northBorders[i].BorderLine.Z : extent.Y;
  1018. }
  1019. // Loss of fraction on purpose
  1020. extent.X = ((int)extent.X / (int)Constants.RegionSize) + 1;
  1021. extent.Y = ((int)extent.Y / (int)Constants.RegionSize) + 1;
  1022. int startX = (int)(pRegionLocX - 1) * (int)Constants.RegionSize;
  1023. int startY = (int)(pRegionLocY - 1) * (int)Constants.RegionSize;
  1024. int endX = ((int)pRegionLocX + (int)extent.X) * (int)Constants.RegionSize;
  1025. int endY = ((int)pRegionLocY + (int)extent.Y) * (int)Constants.RegionSize;
  1026. List<GridRegion> neighbours = pScene.GridService.GetRegionRange(m_regionInfo.ScopeID, startX, endX, startY, endY);
  1027. neighbours.RemoveAll(delegate(GridRegion r) { return r.RegionID == m_regionInfo.RegionID; });
  1028. return neighbours;
  1029. }
  1030. }
  1031. private List<ulong> NewNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours)
  1032. {
  1033. return currentNeighbours.FindAll(delegate(ulong handle) { return !previousNeighbours.Contains(handle); });
  1034. }
  1035. // private List<ulong> CommonNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours)
  1036. // {
  1037. // return currentNeighbours.FindAll(delegate(ulong handle) { return previousNeighbours.Contains(handle); });
  1038. // }
  1039. private List<ulong> OldNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours)
  1040. {
  1041. return previousNeighbours.FindAll(delegate(ulong handle) { return !currentNeighbours.Contains(handle); });
  1042. }
  1043. private List<ulong> NeighbourHandles(List<GridRegion> neighbours)
  1044. {
  1045. List<ulong> handles = new List<ulong>();
  1046. foreach (GridRegion reg in neighbours)
  1047. {
  1048. handles.Add(reg.RegionHandle);
  1049. }
  1050. return handles;
  1051. }
  1052. private void Dump(string msg, List<ulong> handles)
  1053. {
  1054. m_log.InfoFormat("-------------- HANDLE DUMP ({0}) ---------", msg);
  1055. foreach (ulong handle in handles)
  1056. {
  1057. uint x, y;
  1058. Utils.LongToUInts(handle, out x, out y);
  1059. x = x / Constants.RegionSize;
  1060. y = y / Constants.RegionSize;
  1061. m_log.InfoFormat("({0}, {1})", x, y);
  1062. }
  1063. }
  1064. #endregion
  1065. #region Agent Arrived
  1066. public void AgentArrivedAtDestination(UUID id)
  1067. {
  1068. //m_log.Debug(" >>> ReleaseAgent called <<< ");
  1069. ResetFromTransit(id);
  1070. }
  1071. #endregion
  1072. #region Object Transfers
  1073. /// <summary>
  1074. /// Move the given scene object into a new region depending on which region its absolute position has moved
  1075. /// into.
  1076. ///
  1077. /// This method locates the new region handle and offsets the prim position for the new region
  1078. /// </summary>
  1079. /// <param name="attemptedPosition">the attempted out of region position of the scene object</param>
  1080. /// <param name="grp">the scene object that we're crossing</param>
  1081. public void Cross(SceneObjectGroup grp, Vector3 attemptedPosition, bool silent)
  1082. {
  1083. if (grp == null)
  1084. return;
  1085. if (grp.IsDeleted)
  1086. return;
  1087. Scene scene = grp.Scene;
  1088. if (scene == null)
  1089. return;
  1090. if (grp.RootPart.DIE_AT_EDGE)
  1091. {
  1092. // We remove the object here
  1093. try
  1094. {
  1095. scene.DeleteSceneObject(grp, false);
  1096. }
  1097. catch (Exception)
  1098. {
  1099. m_log.Warn("[DATABASE]: exception when trying to remove the prim that crossed the border.");
  1100. }
  1101. return;
  1102. }
  1103. int thisx = (int)scene.RegionInfo.RegionLocX;
  1104. int thisy = (int)scene.RegionInfo.RegionLocY;
  1105. Vector3 EastCross = new Vector3(0.1f, 0, 0);
  1106. Vector3 WestCross = new Vector3(-0.1f, 0, 0);
  1107. Vector3 NorthCross = new Vector3(0, 0.1f, 0);
  1108. Vector3 SouthCross = new Vector3(0, -0.1f, 0);
  1109. // use this if no borders were crossed!
  1110. ulong newRegionHandle
  1111. = Util.UIntsToLong((uint)((thisx) * Constants.RegionSize),
  1112. (uint)((thisy) * Constants.RegionSize));
  1113. Vector3 pos = attemptedPosition;
  1114. int changeX = 1;
  1115. int changeY = 1;
  1116. if (scene.TestBorderCross(attemptedPosition + WestCross, Cardinals.W))
  1117. {
  1118. if (scene.TestBorderCross(attemptedPosition + SouthCross, Cardinals.S))
  1119. {
  1120. Border crossedBorderx = scene.GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
  1121. if (crossedBorderx.BorderLine.Z > 0)
  1122. {
  1123. pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
  1124. changeX = (int)(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize);
  1125. }
  1126. else
  1127. pos.X = ((pos.X + Constants.RegionSize));
  1128. Border crossedBordery = scene.GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
  1129. //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
  1130. if (crossedBordery.BorderLine.Z > 0)
  1131. {
  1132. pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
  1133. changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
  1134. }
  1135. else
  1136. pos.Y = ((pos.Y + Constants.RegionSize));
  1137. newRegionHandle
  1138. = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize),
  1139. (uint)((thisy - changeY) * Constants.RegionSize));
  1140. // x - 1
  1141. // y - 1
  1142. }
  1143. else if (scene.TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
  1144. {
  1145. Border crossedBorderx = scene.GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
  1146. if (crossedBorderx.BorderLine.Z > 0)
  1147. {
  1148. pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
  1149. changeX = (int)(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize);
  1150. }
  1151. else
  1152. pos.X = ((pos.X + Constants.RegionSize));
  1153. Border crossedBordery = scene.GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
  1154. //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
  1155. if (crossedBordery.BorderLine.Z > 0)
  1156. {
  1157. pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
  1158. changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
  1159. }
  1160. else
  1161. pos.Y = ((pos.Y + Constants.RegionSize));
  1162. newRegionHandle
  1163. = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize),
  1164. (uint)((thisy + changeY) * Constants.RegionSize));
  1165. // x - 1
  1166. // y + 1
  1167. }
  1168. else
  1169. {
  1170. Border crossedBorderx = scene.GetCrossedBorder(attemptedPosition + WestCross, Cardinals.W);
  1171. if (crossedBorderx.BorderLine.Z > 0)
  1172. {
  1173. pos.X = ((pos.X + crossedBorderx.BorderLine.Z));
  1174. changeX = (int)(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize);
  1175. }
  1176. else
  1177. pos.X = ((pos.X + Constants.RegionSize));
  1178. newRegionHandle
  1179. = Util.UIntsToLong((uint)((thisx - changeX) * Constants.RegionSize),
  1180. (uint)(thisy * Constants.RegionSize));
  1181. // x - 1
  1182. }
  1183. }
  1184. else if (scene.TestBorderCross(attemptedPosition + EastCross, Cardinals.E))
  1185. {
  1186. if (scene.TestBorderCross(attemptedPosition + SouthCross, Cardinals.S))
  1187. {
  1188. pos.X = ((pos.X - Constants.RegionSize));
  1189. Border crossedBordery = scene.GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
  1190. //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
  1191. if (crossedBordery.BorderLine.Z > 0)
  1192. {
  1193. pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
  1194. changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
  1195. }
  1196. else
  1197. pos.Y = ((pos.Y + Constants.RegionSize));
  1198. newRegionHandle
  1199. = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
  1200. (uint)((thisy - changeY) * Constants.RegionSize));
  1201. // x + 1
  1202. // y - 1
  1203. }
  1204. else if (scene.TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
  1205. {
  1206. pos.X = ((pos.X - Constants.RegionSize));
  1207. pos.Y = ((pos.Y - Constants.RegionSize));
  1208. newRegionHandle
  1209. = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
  1210. (uint)((thisy + changeY) * Constants.RegionSize));
  1211. // x + 1
  1212. // y + 1
  1213. }
  1214. else
  1215. {
  1216. pos.X = ((pos.X - Constants.RegionSize));
  1217. newRegionHandle
  1218. = Util.UIntsToLong((uint)((thisx + changeX) * Constants.RegionSize),
  1219. (uint)(thisy * Constants.RegionSize));
  1220. // x + 1
  1221. }
  1222. }
  1223. else if (scene.TestBorderCross(attemptedPosition + SouthCross, Cardinals.S))
  1224. {
  1225. Border crossedBordery = scene.GetCrossedBorder(attemptedPosition + SouthCross, Cardinals.S);
  1226. //(crossedBorderx.BorderLine.Z / (int)Constants.RegionSize)
  1227. if (crossedBordery.BorderLine.Z > 0)
  1228. {
  1229. pos.Y = ((pos.Y + crossedBordery.BorderLine.Z));
  1230. changeY = (int)(crossedBordery.BorderLine.Z / (int)Constants.RegionSize);
  1231. }
  1232. else
  1233. pos.Y = ((pos.Y + Constants.RegionSize));
  1234. newRegionHandle
  1235. = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy - changeY) * Constants.RegionSize));
  1236. // y - 1
  1237. }
  1238. else if (scene.TestBorderCross(attemptedPosition + NorthCross, Cardinals.N))
  1239. {
  1240. pos.Y = ((pos.Y - Constants.RegionSize));
  1241. newRegionHandle
  1242. = Util.UIntsToLong((uint)(thisx * Constants.RegionSize), (uint)((thisy + changeY) * Constants.RegionSize));
  1243. // y + 1
  1244. }
  1245. // Offset the positions for the new region across the border
  1246. Vector3 oldGroupPosition = grp.RootPart.GroupPosition;
  1247. grp.OffsetForNewRegion(pos);
  1248. // If we fail to cross the border, then reset the position of the scene object on that border.
  1249. uint x = 0, y = 0;
  1250. Utils.LongToUInts(newRegionHandle, out x, out y);
  1251. GridRegion destination = scene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y);
  1252. if (destination != null && !CrossPrimGroupIntoNewRegion(destination, grp, silent))
  1253. {
  1254. grp.OffsetForNewRegion(oldGroupPosition);
  1255. grp.ScheduleGroupForFullUpdate();
  1256. }
  1257. }
  1258. /// <summary>
  1259. /// Move the given scene object into a new region
  1260. /// </summary>
  1261. /// <param name="newRegionHandle"></param>
  1262. /// <param name="grp">Scene Object Group that we're crossing</param>
  1263. /// <returns>
  1264. /// true if the crossing itself was successful, false on failure
  1265. /// FIMXE: we still return true if the crossing object was not successfully deleted from the originating region
  1266. /// </returns>
  1267. protected bool CrossPrimGroupIntoNewRegion(GridRegion destination, SceneObjectGroup grp, bool silent)
  1268. {
  1269. //m_log.Debug(" >>> CrossPrimGroupIntoNewRegion <<<");
  1270. bool successYN = false;
  1271. grp.RootPart.UpdateFlag = 0;
  1272. //int primcrossingXMLmethod = 0;
  1273. if (destination != null)
  1274. {
  1275. //string objectState = grp.GetStateSnapshot();
  1276. //successYN
  1277. // = m_sceneGridService.PrimCrossToNeighboringRegion(
  1278. // newRegionHandle, grp.UUID, m_serialiser.SaveGroupToXml2(grp), primcrossingXMLmethod);
  1279. //if (successYN && (objectState != "") && m_allowScriptCrossings)
  1280. //{
  1281. // successYN = m_sceneGridService.PrimCrossToNeighboringRegion(
  1282. // newRegionHandle, grp.UUID, objectState, 100);
  1283. //}
  1284. //// And the new channel...
  1285. //if (m_interregionCommsOut != null)
  1286. // successYN = m_interregionCommsOut.SendCreateObject(newRegionHandle, grp, true);
  1287. if (m_aScene.SimulationService != null)
  1288. successYN = m_aScene.SimulationService.CreateObject(destination, grp, true);
  1289. if (successYN)
  1290. {
  1291. // We remove the object here
  1292. try
  1293. {
  1294. grp.Scene.DeleteSceneObject(grp, silent);
  1295. }
  1296. catch (Exception e)
  1297. {
  1298. m_log.ErrorFormat(
  1299. "[ENTITY TRANSFER MODULE]: Exception deleting the old object left behind on a border crossing for {0}, {1}",
  1300. grp, e);
  1301. }
  1302. }
  1303. else
  1304. {
  1305. if (!grp.IsDeleted)
  1306. {
  1307. if (grp.RootPart.PhysActor != null)
  1308. {
  1309. grp.RootPart.PhysActor.CrossingFailure();
  1310. }
  1311. }
  1312. m_log.ErrorFormat("[ENTITY TRANSFER MODULE]: Prim crossing failed for {0}", grp);
  1313. }
  1314. }
  1315. else
  1316. {
  1317. m_log.Error("[ENTITY TRANSFER MODULE]: destination was unexpectedly null in Scene.CrossPrimGroupIntoNewRegion()");
  1318. }
  1319. return successYN;
  1320. }
  1321. protected bool CrossAttachmentsIntoNewRegion(GridRegion destination, ScenePresence sp, bool silent)
  1322. {
  1323. List<SceneObjectGroup> m_attachments = sp.Attachments;
  1324. lock (m_attachments)
  1325. {
  1326. // Validate
  1327. foreach (SceneObjectGroup gobj in m_attachments)
  1328. {
  1329. if (gobj == null || gobj.IsDeleted)
  1330. return false;
  1331. }
  1332. foreach (SceneObjectGroup gobj in m_attachments)
  1333. {
  1334. // If the prim group is null then something must have happened to it!
  1335. if (gobj != null && gobj.RootPart != null)
  1336. {
  1337. // Set the parent localID to 0 so it transfers over properly.
  1338. gobj.RootPart.SetParentLocalId(0);
  1339. gobj.AbsolutePosition = gobj.RootPart.AttachedPos;
  1340. gobj.RootPart.IsAttachment = false;
  1341. //gobj.RootPart.LastOwnerID = gobj.GetFromAssetID();
  1342. m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Sending attachment {0} to region {1}", gobj.UUID, destination.RegionName);
  1343. CrossPrimGroupIntoNewRegion(destination, gobj, silent);
  1344. }
  1345. }
  1346. m_attachments.Clear();
  1347. return true;
  1348. }
  1349. }
  1350. #endregion
  1351. #region Misc
  1352. protected bool WaitForCallback(UUID id)
  1353. {
  1354. int count = 200;
  1355. while (m_agentsInTransit.Contains(id) && count-- > 0)
  1356. {
  1357. //m_log.Debug(" >>> Waiting... " + count);
  1358. Thread.Sleep(100);
  1359. }
  1360. if (count > 0)
  1361. return true;
  1362. else
  1363. return false;
  1364. }
  1365. protected void SetInTransit(UUID id)
  1366. {
  1367. lock (m_agentsInTransit)
  1368. {
  1369. if (!m_agentsInTransit.Contains(id))
  1370. m_agentsInTransit.Add(id);
  1371. }
  1372. }
  1373. protected bool ResetFromTransit(UUID id)
  1374. {
  1375. lock (m_agentsInTransit)
  1376. {
  1377. if (m_agentsInTransit.Contains(id))
  1378. {
  1379. m_agentsInTransit.Remove(id);
  1380. return true;
  1381. }
  1382. }
  1383. return false;
  1384. }
  1385. #endregion
  1386. }
  1387. }