EntityTransferModule.cs 72 KB

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