diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs | 1203 |
1 files changed, 10 insertions, 1193 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs index 6164368..f1813a5 100644 --- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs +++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs | |||
@@ -36,7 +36,6 @@ using log4net; | |||
36 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
37 | using OpenSim.Framework.Client; | 37 | using OpenSim.Framework.Client; |
38 | using OpenSim.Framework.Communications; | 38 | using OpenSim.Framework.Communications; |
39 | using OpenSim.Framework.Communications.Cache; | ||
40 | using OpenSim.Framework.Capabilities; | 39 | using OpenSim.Framework.Capabilities; |
41 | using OpenSim.Region.Framework.Interfaces; | 40 | using OpenSim.Region.Framework.Interfaces; |
42 | using OpenSim.Services.Interfaces; | 41 | using OpenSim.Services.Interfaces; |
@@ -56,8 +55,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
56 | { | 55 | { |
57 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 56 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
58 | 57 | ||
59 | protected CommunicationsManager m_commsProvider; | ||
60 | protected IInterregionCommsOut m_interregionCommsOut; | ||
61 | protected RegionInfo m_regionInfo; | 58 | protected RegionInfo m_regionInfo; |
62 | protected Scene m_scene; | 59 | protected Scene m_scene; |
63 | 60 | ||
@@ -118,17 +115,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
118 | 115 | ||
119 | public KiPrimitiveDelegate KiPrimitive; | 116 | public KiPrimitiveDelegate KiPrimitive; |
120 | 117 | ||
121 | public SceneCommunicationService(CommunicationsManager commsMan) | 118 | public SceneCommunicationService() |
122 | { | 119 | { |
123 | m_commsProvider = commsMan; | ||
124 | m_agentsInTransit = new List<UUID>(); | ||
125 | } | 120 | } |
126 | 121 | ||
127 | public void SetScene(Scene s) | 122 | public void SetScene(Scene s) |
128 | { | 123 | { |
129 | m_scene = s; | 124 | m_scene = s; |
130 | m_regionInfo = s.RegionInfo; | 125 | m_regionInfo = s.RegionInfo; |
131 | m_interregionCommsOut = m_scene.RequestModuleInterface<IInterregionCommsOut>(); | ||
132 | } | 126 | } |
133 | 127 | ||
134 | /// <summary> | 128 | /// <summary> |
@@ -148,378 +142,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
148 | { | 142 | { |
149 | } | 143 | } |
150 | 144 | ||
151 | #region CommsManager Event handlers | ||
152 | |||
153 | /// <summary> | ||
154 | /// A New User will arrive shortly, Informs the scene that there's a new user on the way | ||
155 | /// </summary> | ||
156 | /// <param name="agent">Data we need to ensure that the agent can connect</param> | ||
157 | /// | ||
158 | protected void NewUserConnection(AgentCircuitData agent) | ||
159 | { | ||
160 | handlerExpectUser = OnExpectUser; | ||
161 | if (handlerExpectUser != null) | ||
162 | { | ||
163 | //m_log.Info("[INTER]: " + debugRegionName + ": SceneCommunicationService: OnExpectUser Fired for User:" + agent.firstname + " " + agent.lastname); | ||
164 | handlerExpectUser(agent); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | /// <summary> | ||
169 | /// The Grid has requested us to log-off the user | ||
170 | /// </summary> | ||
171 | /// <param name="AgentID">Unique ID of agent to log-off</param> | ||
172 | /// <param name="RegionSecret">The secret string that the region establishes with the grid when registering</param> | ||
173 | /// <param name="message">The message to send to the user that tells them why they were logged off</param> | ||
174 | protected void GridLogOffUser(UUID AgentID, UUID RegionSecret, string message) | ||
175 | { | ||
176 | handlerLogOffUser = OnLogOffUser; | ||
177 | if (handlerLogOffUser != null) | ||
178 | { | ||
179 | handlerLogOffUser(AgentID, RegionSecret, message); | ||
180 | } | ||
181 | } | ||
182 | |||
183 | /// <summary> | ||
184 | /// Inform the scene that we've got an update about a child agent that we have | ||
185 | /// </summary> | ||
186 | /// <param name="cAgentData"></param> | ||
187 | /// <returns></returns> | ||
188 | protected bool ChildAgentUpdate(ChildAgentDataUpdate cAgentData) | ||
189 | { | ||
190 | handlerChildAgentUpdate = OnChildAgentUpdate; | ||
191 | if (handlerChildAgentUpdate != null) | ||
192 | handlerChildAgentUpdate(cAgentData); | ||
193 | |||
194 | |||
195 | return true; | ||
196 | } | ||
197 | |||
198 | |||
199 | protected void AgentCrossing(UUID agentID, Vector3 position, bool isFlying) | ||
200 | { | ||
201 | handlerAvatarCrossingIntoRegion = OnAvatarCrossingIntoRegion; | ||
202 | if (handlerAvatarCrossingIntoRegion != null) | ||
203 | { | ||
204 | handlerAvatarCrossingIntoRegion(agentID, position, isFlying); | ||
205 | } | ||
206 | } | ||
207 | |||
208 | protected void PrimCrossing(UUID primID, Vector3 position, bool isPhysical) | ||
209 | { | ||
210 | handlerPrimCrossingIntoRegion = OnPrimCrossingIntoRegion; | ||
211 | if (handlerPrimCrossingIntoRegion != null) | ||
212 | { | ||
213 | handlerPrimCrossingIntoRegion(primID, position, isPhysical); | ||
214 | } | ||
215 | } | ||
216 | |||
217 | protected bool CloseConnection(UUID agentID) | ||
218 | { | ||
219 | m_log.Debug("[INTERREGION]: Incoming Agent Close Request for agent: " + agentID); | ||
220 | |||
221 | handlerCloseAgentConnection = OnCloseAgentConnection; | ||
222 | if (handlerCloseAgentConnection != null) | ||
223 | { | ||
224 | return handlerCloseAgentConnection(agentID); | ||
225 | } | ||
226 | |||
227 | return false; | ||
228 | } | ||
229 | |||
230 | protected LandData FetchLandData(uint x, uint y) | ||
231 | { | ||
232 | handlerGetLandData = OnGetLandData; | ||
233 | if (handlerGetLandData != null) | ||
234 | { | ||
235 | return handlerGetLandData(x, y); | ||
236 | } | ||
237 | return null; | ||
238 | } | ||
239 | |||
240 | #endregion | ||
241 | |||
242 | #region Inform Client of Neighbours | ||
243 | |||
244 | private delegate void InformClientOfNeighbourDelegate( | ||
245 | ScenePresence avatar, AgentCircuitData a, GridRegion reg, IPEndPoint endPoint, bool newAgent); | ||
246 | |||
247 | private void InformClientOfNeighbourCompleted(IAsyncResult iar) | ||
248 | { | ||
249 | InformClientOfNeighbourDelegate icon = (InformClientOfNeighbourDelegate) iar.AsyncState; | ||
250 | icon.EndInvoke(iar); | ||
251 | } | ||
252 | |||
253 | /// <summary> | ||
254 | /// Async component for informing client of which neighbours exist | ||
255 | /// </summary> | ||
256 | /// <remarks> | ||
257 | /// This needs to run asynchronously, as a network timeout may block the thread for a long while | ||
258 | /// </remarks> | ||
259 | /// <param name="remoteClient"></param> | ||
260 | /// <param name="a"></param> | ||
261 | /// <param name="regionHandle"></param> | ||
262 | /// <param name="endPoint"></param> | ||
263 | private void InformClientOfNeighbourAsync(ScenePresence avatar, AgentCircuitData a, GridRegion reg, | ||
264 | IPEndPoint endPoint, bool newAgent) | ||
265 | { | ||
266 | // Let's wait just a little to give time to originating regions to catch up with closing child agents | ||
267 | // after a cross here | ||
268 | Thread.Sleep(500); | ||
269 | |||
270 | uint x, y; | ||
271 | Utils.LongToUInts(reg.RegionHandle, out x, out y); | ||
272 | x = x / Constants.RegionSize; | ||
273 | y = y / Constants.RegionSize; | ||
274 | m_log.Info("[INTERGRID]: Starting to inform client about neighbour " + x + ", " + y + "(" + endPoint.ToString() + ")"); | ||
275 | |||
276 | string capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort | ||
277 | + "/CAPS/" + a.CapsPath + "0000/"; | ||
278 | |||
279 | string reason = String.Empty; | ||
280 | |||
281 | |||
282 | bool regionAccepted = m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, a, 0, out reason); | ||
283 | |||
284 | if (regionAccepted && newAgent) | ||
285 | { | ||
286 | IEventQueue eq = avatar.Scene.RequestModuleInterface<IEventQueue>(); | ||
287 | if (eq != null) | ||
288 | { | ||
289 | #region IP Translation for NAT | ||
290 | IClientIPEndpoint ipepClient; | ||
291 | if (avatar.ClientView.TryGet(out ipepClient)) | ||
292 | { | ||
293 | endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address); | ||
294 | } | ||
295 | #endregion | ||
296 | |||
297 | eq.EnableSimulator(reg.RegionHandle, endPoint, avatar.UUID); | ||
298 | eq.EstablishAgentCommunication(avatar.UUID, endPoint, capsPath); | ||
299 | m_log.DebugFormat("[CAPS]: Sending new CAPS seed url {0} to client {1} in region {2}", | ||
300 | capsPath, avatar.UUID, avatar.Scene.RegionInfo.RegionName); | ||
301 | } | ||
302 | else | ||
303 | { | ||
304 | avatar.ControllingClient.InformClientOfNeighbour(reg.RegionHandle, endPoint); | ||
305 | // TODO: make Event Queue disablable! | ||
306 | } | ||
307 | |||
308 | m_log.Info("[INTERGRID]: Completed inform client about neighbour " + endPoint.ToString()); | ||
309 | |||
310 | } | ||
311 | |||
312 | } | ||
313 | |||
314 | public List<GridRegion> RequestNeighbours(Scene pScene, uint pRegionLocX, uint pRegionLocY) | ||
315 | { | ||
316 | Border[] northBorders = pScene.NorthBorders.ToArray(); | ||
317 | Border[] southBorders = pScene.SouthBorders.ToArray(); | ||
318 | Border[] eastBorders = pScene.EastBorders.ToArray(); | ||
319 | Border[] westBorders = pScene.WestBorders.ToArray(); | ||
320 | |||
321 | // Legacy one region. Provided for simplicity while testing the all inclusive method in the else statement. | ||
322 | if (northBorders.Length <= 1 && southBorders.Length <= 1 && eastBorders.Length <= 1 && westBorders.Length <= 1) | ||
323 | { | ||
324 | return m_scene.GridService.GetNeighbours(m_regionInfo.ScopeID, m_regionInfo.RegionID); | ||
325 | } | ||
326 | else | ||
327 | { | ||
328 | Vector2 extent = Vector2.Zero; | ||
329 | for (int i = 0; i < eastBorders.Length; i++) | ||
330 | { | ||
331 | extent.X = (eastBorders[i].BorderLine.Z > extent.X) ? eastBorders[i].BorderLine.Z : extent.X; | ||
332 | } | ||
333 | for (int i = 0; i < northBorders.Length; i++) | ||
334 | { | ||
335 | extent.Y = (northBorders[i].BorderLine.Z > extent.Y) ? northBorders[i].BorderLine.Z : extent.Y; | ||
336 | } | ||
337 | |||
338 | // Loss of fraction on purpose | ||
339 | extent.X = ((int)extent.X / (int)Constants.RegionSize) + 1; | ||
340 | extent.Y = ((int)extent.Y / (int)Constants.RegionSize) + 1; | ||
341 | |||
342 | int startX = (int)(pRegionLocX - 1) * (int)Constants.RegionSize; | ||
343 | int startY = (int)(pRegionLocY - 1) * (int)Constants.RegionSize; | ||
344 | |||
345 | int endX = ((int)pRegionLocX + (int)extent.X) * (int)Constants.RegionSize; | ||
346 | int endY = ((int)pRegionLocY + (int)extent.Y) * (int)Constants.RegionSize; | ||
347 | |||
348 | List<GridRegion> neighbours = m_scene.GridService.GetRegionRange(m_regionInfo.ScopeID, startX, endX, startY, endY); | ||
349 | neighbours.RemoveAll(delegate(GridRegion r) { return r.RegionID == m_regionInfo.RegionID; }); | ||
350 | |||
351 | return neighbours; | ||
352 | } | ||
353 | } | ||
354 | |||
355 | /// <summary> | ||
356 | /// This informs all neighboring regions about agent "avatar". | ||
357 | /// Calls an asynchronous method to do so.. so it doesn't lag the sim. | ||
358 | /// </summary> | ||
359 | public void EnableNeighbourChildAgents(ScenePresence avatar, List<RegionInfo> lstneighbours) | ||
360 | { | ||
361 | List<GridRegion> neighbours = new List<GridRegion>(); | ||
362 | |||
363 | if (m_regionInfo != null) | ||
364 | { | ||
365 | neighbours = RequestNeighbours(avatar.Scene,m_regionInfo.RegionLocX, m_regionInfo.RegionLocY); | ||
366 | } | ||
367 | else | ||
368 | { | ||
369 | m_log.Debug("[ENABLENEIGHBOURCHILDAGENTS]: m_regionInfo was null in EnableNeighbourChildAgents, is this a NPC?"); | ||
370 | } | ||
371 | |||
372 | /// We need to find the difference between the new regions where there are no child agents | ||
373 | /// and the regions where there are already child agents. We only send notification to the former. | ||
374 | List<ulong> neighbourHandles = NeighbourHandles(neighbours); // on this region | ||
375 | neighbourHandles.Add(avatar.Scene.RegionInfo.RegionHandle); // add this region too | ||
376 | List<ulong> previousRegionNeighbourHandles ; | ||
377 | |||
378 | if (avatar.Scene.CapsModule != null) | ||
379 | { | ||
380 | previousRegionNeighbourHandles = | ||
381 | new List<ulong>(avatar.Scene.CapsModule.GetChildrenSeeds(avatar.UUID).Keys); | ||
382 | } | ||
383 | else | ||
384 | { | ||
385 | previousRegionNeighbourHandles = new List<ulong>(); | ||
386 | } | ||
387 | |||
388 | List<ulong> newRegions = NewNeighbours(neighbourHandles, previousRegionNeighbourHandles); | ||
389 | List<ulong> oldRegions = OldNeighbours(neighbourHandles, previousRegionNeighbourHandles); | ||
390 | |||
391 | //Dump("Current Neighbors", neighbourHandles); | ||
392 | //Dump("Previous Neighbours", previousRegionNeighbourHandles); | ||
393 | //Dump("New Neighbours", newRegions); | ||
394 | //Dump("Old Neighbours", oldRegions); | ||
395 | |||
396 | /// Update the scene presence's known regions here on this region | ||
397 | avatar.DropOldNeighbours(oldRegions); | ||
398 | |||
399 | /// Collect as many seeds as possible | ||
400 | Dictionary<ulong, string> seeds; | ||
401 | if (avatar.Scene.CapsModule != null) | ||
402 | seeds | ||
403 | = new Dictionary<ulong, string>(avatar.Scene.CapsModule.GetChildrenSeeds(avatar.UUID)); | ||
404 | else | ||
405 | seeds = new Dictionary<ulong, string>(); | ||
406 | |||
407 | //m_log.Debug(" !!! No. of seeds: " + seeds.Count); | ||
408 | if (!seeds.ContainsKey(avatar.Scene.RegionInfo.RegionHandle)) | ||
409 | seeds.Add(avatar.Scene.RegionInfo.RegionHandle, avatar.ControllingClient.RequestClientInfo().CapsPath); | ||
410 | |||
411 | /// Create the necessary child agents | ||
412 | List<AgentCircuitData> cagents = new List<AgentCircuitData>(); | ||
413 | foreach (GridRegion neighbour in neighbours) | ||
414 | { | ||
415 | if (neighbour.RegionHandle != avatar.Scene.RegionInfo.RegionHandle) | ||
416 | { | ||
417 | |||
418 | AgentCircuitData agent = avatar.ControllingClient.RequestClientInfo(); | ||
419 | agent.BaseFolder = UUID.Zero; | ||
420 | agent.InventoryFolder = UUID.Zero; | ||
421 | agent.startpos = new Vector3(128, 128, 70); | ||
422 | agent.child = true; | ||
423 | |||
424 | if (newRegions.Contains(neighbour.RegionHandle)) | ||
425 | { | ||
426 | agent.CapsPath = CapsUtil.GetRandomCapsObjectPath(); | ||
427 | avatar.AddNeighbourRegion(neighbour.RegionHandle, agent.CapsPath); | ||
428 | seeds.Add(neighbour.RegionHandle, agent.CapsPath); | ||
429 | } | ||
430 | else | ||
431 | agent.CapsPath = avatar.Scene.CapsModule.GetChildSeed(avatar.UUID, neighbour.RegionHandle); | ||
432 | |||
433 | cagents.Add(agent); | ||
434 | } | ||
435 | } | ||
436 | |||
437 | /// Update all child agent with everyone's seeds | ||
438 | foreach (AgentCircuitData a in cagents) | ||
439 | { | ||
440 | a.ChildrenCapSeeds = new Dictionary<ulong, string>(seeds); | ||
441 | } | ||
442 | |||
443 | if (avatar.Scene.CapsModule != null) | ||
444 | { | ||
445 | // These two are the same thing! | ||
446 | avatar.Scene.CapsModule.SetChildrenSeed(avatar.UUID, seeds); | ||
447 | } | ||
448 | avatar.KnownRegions = seeds; | ||
449 | //avatar.Scene.DumpChildrenSeeds(avatar.UUID); | ||
450 | //avatar.DumpKnownRegions(); | ||
451 | |||
452 | bool newAgent = false; | ||
453 | int count = 0; | ||
454 | foreach (GridRegion neighbour in neighbours) | ||
455 | { | ||
456 | // Don't do it if there's already an agent in that region | ||
457 | if (newRegions.Contains(neighbour.RegionHandle)) | ||
458 | newAgent = true; | ||
459 | else | ||
460 | newAgent = false; | ||
461 | |||
462 | if (neighbour.RegionHandle != avatar.Scene.RegionInfo.RegionHandle) | ||
463 | { | ||
464 | InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync; | ||
465 | try | ||
466 | { | ||
467 | d.BeginInvoke(avatar, cagents[count], neighbour, neighbour.ExternalEndPoint, newAgent, | ||
468 | InformClientOfNeighbourCompleted, | ||
469 | d); | ||
470 | } | ||
471 | |||
472 | catch (ArgumentOutOfRangeException) | ||
473 | { | ||
474 | m_log.ErrorFormat( | ||
475 | "[REGIONINFO]: 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}).", | ||
476 | neighbour.ExternalHostName, | ||
477 | neighbour.RegionHandle, | ||
478 | neighbour.RegionLocX, | ||
479 | neighbour.RegionLocY); | ||
480 | } | ||
481 | catch (Exception e) | ||
482 | { | ||
483 | m_log.ErrorFormat( | ||
484 | "[REGIONINFO]: Could not resolve external hostname {0} for region {1} ({2}, {3}). {4}", | ||
485 | neighbour.ExternalHostName, | ||
486 | neighbour.RegionHandle, | ||
487 | neighbour.RegionLocX, | ||
488 | neighbour.RegionLocY, | ||
489 | e); | ||
490 | |||
491 | // FIXME: Okay, even though we've failed, we're still going to throw the exception on, | ||
492 | // since I don't know what will happen if we just let the client continue | ||
493 | |||
494 | // XXX: Well, decided to swallow the exception instead for now. Let us see how that goes. | ||
495 | // throw e; | ||
496 | |||
497 | } | ||
498 | } | ||
499 | count++; | ||
500 | } | ||
501 | } | ||
502 | |||
503 | /// <summary> | ||
504 | /// This informs a single neighboring region about agent "avatar". | ||
505 | /// Calls an asynchronous method to do so.. so it doesn't lag the sim. | ||
506 | /// </summary> | ||
507 | public void InformNeighborChildAgent(ScenePresence avatar, GridRegion region) | ||
508 | { | ||
509 | AgentCircuitData agent = avatar.ControllingClient.RequestClientInfo(); | ||
510 | agent.BaseFolder = UUID.Zero; | ||
511 | agent.InventoryFolder = UUID.Zero; | ||
512 | agent.startpos = new Vector3(128, 128, 70); | ||
513 | agent.child = true; | ||
514 | |||
515 | InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync; | ||
516 | d.BeginInvoke(avatar, agent, region, region.ExternalEndPoint, true, | ||
517 | InformClientOfNeighbourCompleted, | ||
518 | d); | ||
519 | } | ||
520 | |||
521 | #endregion | ||
522 | |||
523 | public delegate void InformNeighbourThatRegionUpDelegate(INeighbourService nService, RegionInfo region, ulong regionhandle); | 145 | public delegate void InformNeighbourThatRegionUpDelegate(INeighbourService nService, RegionInfo region, ulong regionhandle); |
524 | 146 | ||
525 | private void InformNeighborsThatRegionisUpCompleted(IAsyncResult iar) | 147 | private void InformNeighborsThatRegionisUpCompleted(IAsyncResult iar) |
@@ -593,7 +215,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
593 | try | 215 | try |
594 | { | 216 | { |
595 | //m_commsProvider.InterRegion.ChildAgentUpdate(regionHandle, cAgentData); | 217 | //m_commsProvider.InterRegion.ChildAgentUpdate(regionHandle, cAgentData); |
596 | m_interregionCommsOut.SendChildAgentUpdate(regionHandle, cAgentData); | 218 | uint x = 0, y = 0; |
219 | Utils.LongToUInts(regionHandle, out x, out y); | ||
220 | GridRegion destination = m_scene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y); | ||
221 | m_scene.SimulationService.UpdateAgent(destination, cAgentData); | ||
597 | } | 222 | } |
598 | catch | 223 | catch |
599 | { | 224 | { |
@@ -653,7 +278,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
653 | // let's do our best, but there's not much we can do if the neighbour doesn't accept. | 278 | // let's do our best, but there's not much we can do if the neighbour doesn't accept. |
654 | 279 | ||
655 | //m_commsProvider.InterRegion.TellRegionToCloseChildConnection(regionHandle, agentID); | 280 | //m_commsProvider.InterRegion.TellRegionToCloseChildConnection(regionHandle, agentID); |
656 | m_interregionCommsOut.SendCloseAgent(regionHandle, agentID); | 281 | uint x = 0, y = 0; |
282 | Utils.LongToUInts(regionHandle, out x, out y); | ||
283 | GridRegion destination = m_scene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y); | ||
284 | m_scene.SimulationService.CloseAgent(destination, agentID); | ||
657 | } | 285 | } |
658 | 286 | ||
659 | private void SendCloseChildAgentCompleted(IAsyncResult iar) | 287 | private void SendCloseChildAgentCompleted(IAsyncResult iar) |
@@ -672,822 +300,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
672 | d); | 300 | d); |
673 | } | 301 | } |
674 | } | 302 | } |
675 | 303 | ||
676 | |||
677 | /// <summary> | ||
678 | /// Try to teleport an agent to a new region. | ||
679 | /// </summary> | ||
680 | /// <param name="remoteClient"></param> | ||
681 | /// <param name="RegionHandle"></param> | ||
682 | /// <param name="position"></param> | ||
683 | /// <param name="lookAt"></param> | ||
684 | /// <param name="flags"></param> | ||
685 | public virtual void RequestTeleportToLocation(ScenePresence avatar, ulong regionHandle, Vector3 position, | ||
686 | Vector3 lookAt, uint teleportFlags) | ||
687 | { | ||
688 | if (!avatar.Scene.Permissions.CanTeleport(avatar.UUID)) | ||
689 | return; | ||
690 | |||
691 | bool destRegionUp = true; | ||
692 | |||
693 | IEventQueue eq = avatar.Scene.RequestModuleInterface<IEventQueue>(); | ||
694 | |||
695 | // Reset animations; the viewer does that in teleports. | ||
696 | avatar.Animator.ResetAnimations(); | ||
697 | |||
698 | if (regionHandle == m_regionInfo.RegionHandle) | ||
699 | { | ||
700 | m_log.DebugFormat( | ||
701 | "[SCENE COMMUNICATION SERVICE]: RequestTeleportToLocation {0} within {1}", | ||
702 | position, m_regionInfo.RegionName); | ||
703 | |||
704 | // Teleport within the same region | ||
705 | if (IsOutsideRegion(avatar.Scene, position) || position.Z < 0) | ||
706 | { | ||
707 | Vector3 emergencyPos = new Vector3(128, 128, 128); | ||
708 | |||
709 | m_log.WarnFormat( | ||
710 | "[SCENE COMMUNICATION SERVICE]: RequestTeleportToLocation() was given an illegal position of {0} for avatar {1}, {2}. Substituting {3}", | ||
711 | position, avatar.Name, avatar.UUID, emergencyPos); | ||
712 | position = emergencyPos; | ||
713 | } | ||
714 | |||
715 | // TODO: Get proper AVG Height | ||
716 | float localAVHeight = 1.56f; | ||
717 | float posZLimit = 22; | ||
718 | |||
719 | // TODO: Check other Scene HeightField | ||
720 | if (position.X > 0 && position.X <= (int)Constants.RegionSize && position.Y > 0 && position.Y <=(int)Constants.RegionSize) | ||
721 | { | ||
722 | posZLimit = (float) avatar.Scene.Heightmap[(int) position.X, (int) position.Y]; | ||
723 | } | ||
724 | |||
725 | float newPosZ = posZLimit + localAVHeight; | ||
726 | if (posZLimit >= (position.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) | ||
727 | { | ||
728 | position.Z = newPosZ; | ||
729 | } | ||
730 | |||
731 | // Only send this if the event queue is null | ||
732 | if (eq == null) | ||
733 | avatar.ControllingClient.SendTeleportLocationStart(); | ||
734 | |||
735 | avatar.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags); | ||
736 | avatar.Teleport(position); | ||
737 | } | ||
738 | else | ||
739 | { | ||
740 | uint x = 0, y = 0; | ||
741 | Utils.LongToUInts(regionHandle, out x, out y); | ||
742 | GridRegion reg = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y); | ||
743 | |||
744 | if (reg != null) | ||
745 | { | ||
746 | m_log.DebugFormat( | ||
747 | "[SCENE COMMUNICATION SERVICE]: RequestTeleportToLocation to {0} in {1}", | ||
748 | position, reg.RegionName); | ||
749 | |||
750 | if (eq == null) | ||
751 | avatar.ControllingClient.SendTeleportLocationStart(); | ||
752 | |||
753 | // Let's do DNS resolution only once in this process, please! | ||
754 | // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field, | ||
755 | // it's actually doing a lot of work. | ||
756 | IPEndPoint endPoint = reg.ExternalEndPoint; | ||
757 | if (endPoint.Address == null) | ||
758 | { | ||
759 | // Couldn't resolve the name. Can't TP, because the viewer wants IP addresses. | ||
760 | destRegionUp = false; | ||
761 | } | ||
762 | |||
763 | if (destRegionUp) | ||
764 | { | ||
765 | uint newRegionX = (uint)(reg.RegionHandle >> 40); | ||
766 | uint newRegionY = (((uint)(reg.RegionHandle)) >> 8); | ||
767 | uint oldRegionX = (uint)(m_regionInfo.RegionHandle >> 40); | ||
768 | uint oldRegionY = (((uint)(m_regionInfo.RegionHandle)) >> 8); | ||
769 | |||
770 | // Fixing a bug where teleporting while sitting results in the avatar ending up removed from | ||
771 | // both regions | ||
772 | if (avatar.ParentID != (uint)0) | ||
773 | avatar.StandUp(); | ||
774 | |||
775 | if (!avatar.ValidateAttachments()) | ||
776 | { | ||
777 | avatar.ControllingClient.SendTeleportFailed("Inconsistent attachment state"); | ||
778 | return; | ||
779 | } | ||
780 | |||
781 | // the avatar.Close below will clear the child region list. We need this below for (possibly) | ||
782 | // closing the child agents, so save it here (we need a copy as it is Clear()-ed). | ||
783 | //List<ulong> childRegions = new List<ulong>(avatar.GetKnownRegionList()); | ||
784 | // Compared to ScenePresence.CrossToNewRegion(), there's no obvious code to handle a teleport | ||
785 | // failure at this point (unlike a border crossing failure). So perhaps this can never fail | ||
786 | // once we reach here... | ||
787 | //avatar.Scene.RemoveCapsHandler(avatar.UUID); | ||
788 | |||
789 | string capsPath = String.Empty; | ||
790 | AgentCircuitData agentCircuit = avatar.ControllingClient.RequestClientInfo(); | ||
791 | agentCircuit.BaseFolder = UUID.Zero; | ||
792 | agentCircuit.InventoryFolder = UUID.Zero; | ||
793 | agentCircuit.startpos = position; | ||
794 | agentCircuit.child = true; | ||
795 | |||
796 | if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY)) | ||
797 | { | ||
798 | // brand new agent, let's create a new caps seed | ||
799 | agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath(); | ||
800 | } | ||
801 | |||
802 | string reason = String.Empty; | ||
803 | |||
804 | // Let's create an agent there if one doesn't exist yet. | ||
805 | //if (!m_commsProvider.InterRegion.InformRegionOfChildAgent(reg.RegionHandle, agentCircuit)) | ||
806 | if (!m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, agentCircuit, teleportFlags, out reason)) | ||
807 | { | ||
808 | avatar.ControllingClient.SendTeleportFailed(String.Format("Destination is not accepting teleports: {0}", | ||
809 | reason)); | ||
810 | return; | ||
811 | } | ||
812 | |||
813 | // OK, it got this agent. Let's close some child agents | ||
814 | avatar.CloseChildAgents(newRegionX, newRegionY); | ||
815 | |||
816 | if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY)) | ||
817 | { | ||
818 | #region IP Translation for NAT | ||
819 | IClientIPEndpoint ipepClient; | ||
820 | if (avatar.ClientView.TryGet(out ipepClient)) | ||
821 | { | ||
822 | capsPath | ||
823 | = "http://" | ||
824 | + NetworkUtil.GetHostFor(ipepClient.EndPoint, reg.ExternalHostName) | ||
825 | + ":" | ||
826 | + reg.HttpPort | ||
827 | + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath); | ||
828 | } | ||
829 | else | ||
830 | { | ||
831 | capsPath | ||
832 | = "http://" | ||
833 | + reg.ExternalHostName | ||
834 | + ":" | ||
835 | + reg.HttpPort | ||
836 | + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath); | ||
837 | } | ||
838 | #endregion | ||
839 | |||
840 | if (eq != null) | ||
841 | { | ||
842 | #region IP Translation for NAT | ||
843 | // Uses ipepClient above | ||
844 | if (avatar.ClientView.TryGet(out ipepClient)) | ||
845 | { | ||
846 | endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address); | ||
847 | } | ||
848 | #endregion | ||
849 | |||
850 | eq.EnableSimulator(reg.RegionHandle, endPoint, avatar.UUID); | ||
851 | |||
852 | // ES makes the client send a UseCircuitCode message to the destination, | ||
853 | // which triggers a bunch of things there. | ||
854 | // So let's wait | ||
855 | Thread.Sleep(2000); | ||
856 | |||
857 | eq.EstablishAgentCommunication(avatar.UUID, endPoint, capsPath); | ||
858 | } | ||
859 | else | ||
860 | { | ||
861 | avatar.ControllingClient.InformClientOfNeighbour(reg.RegionHandle, endPoint); | ||
862 | } | ||
863 | } | ||
864 | else | ||
865 | { | ||
866 | agentCircuit.CapsPath = avatar.Scene.CapsModule.GetChildSeed(avatar.UUID, reg.RegionHandle); | ||
867 | capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort | ||
868 | + "/CAPS/" + agentCircuit.CapsPath + "0000/"; | ||
869 | } | ||
870 | |||
871 | // Expect avatar crossing is a heavy-duty function at the destination. | ||
872 | // That is where MakeRoot is called, which fetches appearance and inventory. | ||
873 | // Plus triggers OnMakeRoot, which spawns a series of asynchronous updates. | ||
874 | //m_commsProvider.InterRegion.ExpectAvatarCrossing(reg.RegionHandle, avatar.ControllingClient.AgentId, | ||
875 | // position, false); | ||
876 | |||
877 | //{ | ||
878 | // avatar.ControllingClient.SendTeleportFailed("Problem with destination."); | ||
879 | // // We should close that agent we just created over at destination... | ||
880 | // List<ulong> lst = new List<ulong>(); | ||
881 | // lst.Add(reg.RegionHandle); | ||
882 | // SendCloseChildAgentAsync(avatar.UUID, lst); | ||
883 | // return; | ||
884 | //} | ||
885 | |||
886 | SetInTransit(avatar.UUID); | ||
887 | // Let's send a full update of the agent. This is a synchronous call. | ||
888 | AgentData agent = new AgentData(); | ||
889 | avatar.CopyTo(agent); | ||
890 | agent.Position = position; | ||
891 | agent.CallbackURI = "http://" + m_regionInfo.ExternalHostName + ":" + m_regionInfo.HttpPort + | ||
892 | "/agent/" + avatar.UUID.ToString() + "/" + avatar.Scene.RegionInfo.RegionHandle.ToString() + "/release/"; | ||
893 | |||
894 | m_interregionCommsOut.SendChildAgentUpdate(reg.RegionHandle, agent); | ||
895 | |||
896 | m_log.DebugFormat( | ||
897 | "[CAPS]: Sending new CAPS seed url {0} to client {1}", capsPath, avatar.UUID); | ||
898 | |||
899 | |||
900 | if (eq != null) | ||
901 | { | ||
902 | eq.TeleportFinishEvent(reg.RegionHandle, 13, endPoint, | ||
903 | 0, teleportFlags, capsPath, avatar.UUID); | ||
904 | } | ||
905 | else | ||
906 | { | ||
907 | avatar.ControllingClient.SendRegionTeleport(reg.RegionHandle, 13, endPoint, 4, | ||
908 | teleportFlags, capsPath); | ||
909 | } | ||
910 | |||
911 | // TeleportFinish makes the client send CompleteMovementIntoRegion (at the destination), which | ||
912 | // trigers a whole shebang of things there, including MakeRoot. So let's wait for confirmation | ||
913 | // that the client contacted the destination before we send the attachments and close things here. | ||
914 | if (!WaitForCallback(avatar.UUID)) | ||
915 | { | ||
916 | // Client never contacted destination. Let's restore everything back | ||
917 | avatar.ControllingClient.SendTeleportFailed("Problems connecting to destination."); | ||
918 | |||
919 | ResetFromTransit(avatar.UUID); | ||
920 | |||
921 | // Yikes! We should just have a ref to scene here. | ||
922 | avatar.Scene.InformClientOfNeighbours(avatar); | ||
923 | |||
924 | // Finally, kill the agent we just created at the destination. | ||
925 | m_interregionCommsOut.SendCloseAgent(reg.RegionHandle, avatar.UUID); | ||
926 | |||
927 | return; | ||
928 | } | ||
929 | |||
930 | // Can't go back from here | ||
931 | if (KiPrimitive != null) | ||
932 | { | ||
933 | KiPrimitive(avatar.LocalId); | ||
934 | } | ||
935 | |||
936 | avatar.MakeChildAgent(); | ||
937 | |||
938 | // CrossAttachmentsIntoNewRegion is a synchronous call. We shouldn't need to wait after it | ||
939 | avatar.CrossAttachmentsIntoNewRegion(reg.RegionHandle, true); | ||
940 | |||
941 | // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone | ||
942 | |||
943 | if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY)) | ||
944 | { | ||
945 | Thread.Sleep(5000); | ||
946 | avatar.Close(); | ||
947 | CloseConnection(avatar.UUID); | ||
948 | } | ||
949 | else | ||
950 | // now we have a child agent in this region. | ||
951 | avatar.Reset(); | ||
952 | |||
953 | |||
954 | // if (teleport success) // seems to be always success here | ||
955 | // the user may change their profile information in other region, | ||
956 | // so the userinfo in UserProfileCache is not reliable any more, delete it | ||
957 | if (avatar.Scene.NeedSceneCacheClear(avatar.UUID)) | ||
958 | { | ||
959 | m_commsProvider.UserProfileCacheService.RemoveUser(avatar.UUID); | ||
960 | m_log.DebugFormat( | ||
961 | "[SCENE COMMUNICATION SERVICE]: User {0} is going to another region, profile cache removed", | ||
962 | avatar.UUID); | ||
963 | } | ||
964 | } | ||
965 | else | ||
966 | { | ||
967 | avatar.ControllingClient.SendTeleportFailed("Remote Region appears to be down"); | ||
968 | } | ||
969 | } | ||
970 | else | ||
971 | { | ||
972 | // TP to a place that doesn't exist (anymore) | ||
973 | // Inform the viewer about that | ||
974 | avatar.ControllingClient.SendTeleportFailed("The region you tried to teleport to doesn't exist anymore"); | ||
975 | |||
976 | // and set the map-tile to '(Offline)' | ||
977 | uint regX, regY; | ||
978 | Utils.LongToUInts(regionHandle, out regX, out regY); | ||
979 | |||
980 | MapBlockData block = new MapBlockData(); | ||
981 | block.X = (ushort)(regX / Constants.RegionSize); | ||
982 | block.Y = (ushort)(regY / Constants.RegionSize); | ||
983 | block.Access = 254; // == not there | ||
984 | |||
985 | List<MapBlockData> blocks = new List<MapBlockData>(); | ||
986 | blocks.Add(block); | ||
987 | avatar.ControllingClient.SendMapBlock(blocks, 0); | ||
988 | } | ||
989 | } | ||
990 | } | ||
991 | |||
992 | protected bool IsOutsideRegion(Scene s, Vector3 pos) | ||
993 | { | ||
994 | |||
995 | if (s.TestBorderCross(pos,Cardinals.N)) | ||
996 | return true; | ||
997 | if (s.TestBorderCross(pos, Cardinals.S)) | ||
998 | return true; | ||
999 | if (s.TestBorderCross(pos, Cardinals.E)) | ||
1000 | return true; | ||
1001 | if (s.TestBorderCross(pos, Cardinals.W)) | ||
1002 | return true; | ||
1003 | |||
1004 | return false; | ||
1005 | } | ||
1006 | |||
1007 | public bool WaitForCallback(UUID id) | ||
1008 | { | ||
1009 | int count = 200; | ||
1010 | while (m_agentsInTransit.Contains(id) && count-- > 0) | ||
1011 | { | ||
1012 | //m_log.Debug(" >>> Waiting... " + count); | ||
1013 | Thread.Sleep(100); | ||
1014 | } | ||
1015 | |||
1016 | if (count > 0) | ||
1017 | return true; | ||
1018 | else | ||
1019 | return false; | ||
1020 | } | ||
1021 | |||
1022 | public bool ReleaseAgent(UUID id) | ||
1023 | { | ||
1024 | //m_log.Debug(" >>> ReleaseAgent called <<< "); | ||
1025 | return ResetFromTransit(id); | ||
1026 | } | ||
1027 | |||
1028 | public void SetInTransit(UUID id) | ||
1029 | { | ||
1030 | lock (m_agentsInTransit) | ||
1031 | { | ||
1032 | if (!m_agentsInTransit.Contains(id)) | ||
1033 | m_agentsInTransit.Add(id); | ||
1034 | } | ||
1035 | } | ||
1036 | |||
1037 | protected bool ResetFromTransit(UUID id) | ||
1038 | { | ||
1039 | lock (m_agentsInTransit) | ||
1040 | { | ||
1041 | if (m_agentsInTransit.Contains(id)) | ||
1042 | { | ||
1043 | m_agentsInTransit.Remove(id); | ||
1044 | return true; | ||
1045 | } | ||
1046 | } | ||
1047 | return false; | ||
1048 | } | ||
1049 | |||
1050 | private List<ulong> NeighbourHandles(List<GridRegion> neighbours) | ||
1051 | { | ||
1052 | List<ulong> handles = new List<ulong>(); | ||
1053 | foreach (GridRegion reg in neighbours) | ||
1054 | { | ||
1055 | handles.Add(reg.RegionHandle); | ||
1056 | } | ||
1057 | return handles; | ||
1058 | } | ||
1059 | |||
1060 | private List<ulong> NewNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours) | ||
1061 | { | ||
1062 | return currentNeighbours.FindAll(delegate(ulong handle) { return !previousNeighbours.Contains(handle); }); | ||
1063 | } | ||
1064 | |||
1065 | // private List<ulong> CommonNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours) | ||
1066 | // { | ||
1067 | // return currentNeighbours.FindAll(delegate(ulong handle) { return previousNeighbours.Contains(handle); }); | ||
1068 | // } | ||
1069 | |||
1070 | private List<ulong> OldNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours) | ||
1071 | { | ||
1072 | return previousNeighbours.FindAll(delegate(ulong handle) { return !currentNeighbours.Contains(handle); }); | ||
1073 | } | ||
1074 | |||
1075 | public void CrossAgentToNewRegion(Scene scene, ScenePresence agent, bool isFlying) | ||
1076 | { | ||
1077 | Vector3 pos = agent.AbsolutePosition; | ||
1078 | Vector3 newpos = new Vector3(pos.X, pos.Y, pos.Z); | ||
1079 | uint neighbourx = m_regionInfo.RegionLocX; | ||
1080 | uint neighboury = m_regionInfo.RegionLocY; | ||
1081 | const float boundaryDistance = 1.7f; | ||
1082 | Vector3 northCross = new Vector3(0,boundaryDistance, 0); | ||
1083 | Vector3 southCross = new Vector3(0, -1 * boundaryDistance, 0); | ||
1084 | Vector3 eastCross = new Vector3(boundaryDistance, 0, 0); | ||
1085 | Vector3 westCross = new Vector3(-1 * boundaryDistance, 0, 0); | ||
1086 | |||
1087 | // distance to edge that will trigger crossing | ||
1088 | |||
1089 | |||
1090 | // distance into new region to place avatar | ||
1091 | const float enterDistance = 0.5f; | ||
1092 | |||
1093 | if (scene.TestBorderCross(pos + westCross, Cardinals.W)) | ||
1094 | { | ||
1095 | if (scene.TestBorderCross(pos + northCross, Cardinals.N)) | ||
1096 | { | ||
1097 | Border b = scene.GetCrossedBorder(pos + northCross, Cardinals.N); | ||
1098 | neighboury += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize); | ||
1099 | } | ||
1100 | else if (scene.TestBorderCross(pos + southCross, Cardinals.S)) | ||
1101 | { | ||
1102 | Border b = scene.GetCrossedBorder(pos + southCross, Cardinals.S); | ||
1103 | if (b.TriggerRegionX == 0 && b.TriggerRegionY == 0) | ||
1104 | { | ||
1105 | neighboury--; | ||
1106 | newpos.Y = Constants.RegionSize - enterDistance; | ||
1107 | } | ||
1108 | else | ||
1109 | { | ||
1110 | neighboury = b.TriggerRegionY; | ||
1111 | neighbourx = b.TriggerRegionX; | ||
1112 | |||
1113 | Vector3 newposition = pos; | ||
1114 | newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize; | ||
1115 | newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize; | ||
1116 | agent.ControllingClient.SendAgentAlertMessage( | ||
1117 | String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false); | ||
1118 | InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene); | ||
1119 | return; | ||
1120 | } | ||
1121 | } | ||
1122 | |||
1123 | Border ba = scene.GetCrossedBorder(pos + westCross, Cardinals.W); | ||
1124 | if (ba.TriggerRegionX == 0 && ba.TriggerRegionY == 0) | ||
1125 | { | ||
1126 | neighbourx--; | ||
1127 | newpos.X = Constants.RegionSize - enterDistance; | ||
1128 | } | ||
1129 | else | ||
1130 | { | ||
1131 | neighboury = ba.TriggerRegionY; | ||
1132 | neighbourx = ba.TriggerRegionX; | ||
1133 | |||
1134 | |||
1135 | Vector3 newposition = pos; | ||
1136 | newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize; | ||
1137 | newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize; | ||
1138 | agent.ControllingClient.SendAgentAlertMessage( | ||
1139 | String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false); | ||
1140 | InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene); | ||
1141 | |||
1142 | |||
1143 | return; | ||
1144 | } | ||
1145 | |||
1146 | } | ||
1147 | else if (scene.TestBorderCross(pos + eastCross, Cardinals.E)) | ||
1148 | { | ||
1149 | Border b = scene.GetCrossedBorder(pos + eastCross, Cardinals.E); | ||
1150 | neighbourx += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize); | ||
1151 | newpos.X = enterDistance; | ||
1152 | |||
1153 | if (scene.TestBorderCross(pos + southCross, Cardinals.S)) | ||
1154 | { | ||
1155 | Border ba = scene.GetCrossedBorder(pos + southCross, Cardinals.S); | ||
1156 | if (ba.TriggerRegionX == 0 && ba.TriggerRegionY == 0) | ||
1157 | { | ||
1158 | neighboury--; | ||
1159 | newpos.Y = Constants.RegionSize - enterDistance; | ||
1160 | } | ||
1161 | else | ||
1162 | { | ||
1163 | neighboury = ba.TriggerRegionY; | ||
1164 | neighbourx = ba.TriggerRegionX; | ||
1165 | Vector3 newposition = pos; | ||
1166 | newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize; | ||
1167 | newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize; | ||
1168 | agent.ControllingClient.SendAgentAlertMessage( | ||
1169 | String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false); | ||
1170 | InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene); | ||
1171 | return; | ||
1172 | } | ||
1173 | } | ||
1174 | else if (scene.TestBorderCross(pos + northCross, Cardinals.N)) | ||
1175 | { | ||
1176 | Border c = scene.GetCrossedBorder(pos + northCross, Cardinals.N); | ||
1177 | neighboury += (uint)(int)(c.BorderLine.Z / (int)Constants.RegionSize); | ||
1178 | newpos.Y = enterDistance; | ||
1179 | } | ||
1180 | |||
1181 | |||
1182 | } | ||
1183 | else if (scene.TestBorderCross(pos + southCross, Cardinals.S)) | ||
1184 | { | ||
1185 | Border b = scene.GetCrossedBorder(pos + southCross, Cardinals.S); | ||
1186 | if (b.TriggerRegionX == 0 && b.TriggerRegionY == 0) | ||
1187 | { | ||
1188 | neighboury--; | ||
1189 | newpos.Y = Constants.RegionSize - enterDistance; | ||
1190 | } | ||
1191 | else | ||
1192 | { | ||
1193 | neighboury = b.TriggerRegionY; | ||
1194 | neighbourx = b.TriggerRegionX; | ||
1195 | Vector3 newposition = pos; | ||
1196 | newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize; | ||
1197 | newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize; | ||
1198 | agent.ControllingClient.SendAgentAlertMessage( | ||
1199 | String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false); | ||
1200 | InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene); | ||
1201 | return; | ||
1202 | } | ||
1203 | } | ||
1204 | else if (scene.TestBorderCross(pos + northCross, Cardinals.N)) | ||
1205 | { | ||
1206 | |||
1207 | Border b = scene.GetCrossedBorder(pos + northCross, Cardinals.N); | ||
1208 | neighboury += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize); | ||
1209 | newpos.Y = enterDistance; | ||
1210 | } | ||
1211 | |||
1212 | /* | ||
1213 | |||
1214 | if (pos.X < boundaryDistance) //West | ||
1215 | { | ||
1216 | neighbourx--; | ||
1217 | newpos.X = Constants.RegionSize - enterDistance; | ||
1218 | } | ||
1219 | else if (pos.X > Constants.RegionSize - boundaryDistance) // East | ||
1220 | { | ||
1221 | neighbourx++; | ||
1222 | newpos.X = enterDistance; | ||
1223 | } | ||
1224 | |||
1225 | if (pos.Y < boundaryDistance) // South | ||
1226 | { | ||
1227 | neighboury--; | ||
1228 | newpos.Y = Constants.RegionSize - enterDistance; | ||
1229 | } | ||
1230 | else if (pos.Y > Constants.RegionSize - boundaryDistance) // North | ||
1231 | { | ||
1232 | neighboury++; | ||
1233 | newpos.Y = enterDistance; | ||
1234 | } | ||
1235 | */ | ||
1236 | |||
1237 | CrossAgentToNewRegionDelegate d = CrossAgentToNewRegionAsync; | ||
1238 | d.BeginInvoke(agent, newpos, neighbourx, neighboury, isFlying, CrossAgentToNewRegionCompleted, d); | ||
1239 | } | ||
1240 | |||
1241 | public delegate void InformClientToInitateTeleportToLocationDelegate(ScenePresence agent, uint regionX, uint regionY, | ||
1242 | Vector3 position, | ||
1243 | Scene initiatingScene); | ||
1244 | |||
1245 | public void InformClientToInitateTeleportToLocation(ScenePresence agent, uint regionX, uint regionY, Vector3 position, | ||
1246 | Scene initiatingScene) | ||
1247 | { | ||
1248 | |||
1249 | // This assumes that we know what our neighbors are. | ||
1250 | |||
1251 | InformClientToInitateTeleportToLocationDelegate d = InformClientToInitiateTeleportToLocationAsync; | ||
1252 | d.BeginInvoke(agent,regionX,regionY,position,initiatingScene, | ||
1253 | InformClientToInitiateTeleportToLocationCompleted, | ||
1254 | d); | ||
1255 | } | ||
1256 | |||
1257 | public void InformClientToInitiateTeleportToLocationAsync(ScenePresence agent, uint regionX, uint regionY, Vector3 position, | ||
1258 | Scene initiatingScene) | ||
1259 | { | ||
1260 | Thread.Sleep(10000); | ||
1261 | IMessageTransferModule im = initiatingScene.RequestModuleInterface<IMessageTransferModule>(); | ||
1262 | if (im != null) | ||
1263 | { | ||
1264 | UUID gotoLocation = Util.BuildFakeParcelID( | ||
1265 | Util.UIntsToLong( | ||
1266 | (regionX * | ||
1267 | (uint)Constants.RegionSize), | ||
1268 | (regionY * | ||
1269 | (uint)Constants.RegionSize)), | ||
1270 | (uint)(int)position.X, | ||
1271 | (uint)(int)position.Y, | ||
1272 | (uint)(int)position.Z); | ||
1273 | GridInstantMessage m = new GridInstantMessage(initiatingScene, UUID.Zero, | ||
1274 | "Region", agent.UUID, | ||
1275 | (byte)InstantMessageDialog.GodLikeRequestTeleport, false, | ||
1276 | "", gotoLocation, false, new Vector3(127, 0, 0), | ||
1277 | new Byte[0]); | ||
1278 | im.SendInstantMessage(m, delegate(bool success) | ||
1279 | { | ||
1280 | m_log.DebugFormat("[CLIENT]: Client Initiating Teleport sending IM success = {0}", success); | ||
1281 | }); | ||
1282 | |||
1283 | } | ||
1284 | } | ||
1285 | |||
1286 | private void InformClientToInitiateTeleportToLocationCompleted(IAsyncResult iar) | ||
1287 | { | ||
1288 | InformClientToInitateTeleportToLocationDelegate icon = | ||
1289 | (InformClientToInitateTeleportToLocationDelegate) iar.AsyncState; | ||
1290 | icon.EndInvoke(iar); | ||
1291 | } | ||
1292 | |||
1293 | public delegate ScenePresence CrossAgentToNewRegionDelegate(ScenePresence agent, Vector3 pos, uint neighbourx, uint neighboury, bool isFlying); | ||
1294 | |||
1295 | /// <summary> | ||
1296 | /// This Closes child agents on neighboring regions | ||
1297 | /// Calls an asynchronous method to do so.. so it doesn't lag the sim. | ||
1298 | /// </summary> | ||
1299 | protected ScenePresence CrossAgentToNewRegionAsync(ScenePresence agent, Vector3 pos, uint neighbourx, uint neighboury, bool isFlying) | ||
1300 | { | ||
1301 | m_log.DebugFormat("[SCENE COMM]: Crossing agent {0} {1} to {2}-{3}", agent.Firstname, agent.Lastname, neighbourx, neighboury); | ||
1302 | |||
1303 | ulong neighbourHandle = Utils.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize)); | ||
1304 | |||
1305 | int x = (int)(neighbourx * Constants.RegionSize), y = (int)(neighboury * Constants.RegionSize); | ||
1306 | GridRegion neighbourRegion = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y); | ||
1307 | |||
1308 | if (neighbourRegion != null && agent.ValidateAttachments()) | ||
1309 | { | ||
1310 | pos = pos + (agent.Velocity); | ||
1311 | |||
1312 | //CachedUserInfo userInfo = m_commsProvider.UserProfileCacheService.GetUserDetails(agent.UUID); | ||
1313 | //if (userInfo != null) | ||
1314 | //{ | ||
1315 | // userInfo.DropInventory(); | ||
1316 | //} | ||
1317 | //else | ||
1318 | //{ | ||
1319 | // m_log.WarnFormat("[SCENE COMM]: No cached user info found for {0} {1} on leaving region {2}", | ||
1320 | // agent.Name, agent.UUID, agent.Scene.RegionInfo.RegionName); | ||
1321 | //} | ||
1322 | |||
1323 | //bool crossingSuccessful = | ||
1324 | // CrossToNeighbouringRegion(neighbourHandle, agent.ControllingClient.AgentId, pos, | ||
1325 | //isFlying); | ||
1326 | |||
1327 | SetInTransit(agent.UUID); | ||
1328 | AgentData cAgent = new AgentData(); | ||
1329 | agent.CopyTo(cAgent); | ||
1330 | cAgent.Position = pos; | ||
1331 | if (isFlying) | ||
1332 | cAgent.ControlFlags |= (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY; | ||
1333 | cAgent.CallbackURI = "http://" + m_regionInfo.ExternalHostName + ":" + m_regionInfo.HttpPort + | ||
1334 | "/agent/" + agent.UUID.ToString() + "/" + agent.Scene.RegionInfo.RegionHandle.ToString() + "/release/"; | ||
1335 | |||
1336 | m_interregionCommsOut.SendChildAgentUpdate(neighbourHandle, cAgent); | ||
1337 | |||
1338 | // Next, let's close the child agent connections that are too far away. | ||
1339 | agent.CloseChildAgents(neighbourx, neighboury); | ||
1340 | |||
1341 | //AgentCircuitData circuitdata = m_controllingClient.RequestClientInfo(); | ||
1342 | agent.ControllingClient.RequestClientInfo(); | ||
1343 | |||
1344 | //m_log.Debug("BEFORE CROSS"); | ||
1345 | //Scene.DumpChildrenSeeds(UUID); | ||
1346 | //DumpKnownRegions(); | ||
1347 | string agentcaps; | ||
1348 | if (!agent.KnownRegions.TryGetValue(neighbourRegion.RegionHandle, out agentcaps)) | ||
1349 | { | ||
1350 | m_log.ErrorFormat("[SCENE COMM]: No CAPS information for region handle {0}, exiting CrossToNewRegion.", | ||
1351 | neighbourRegion.RegionHandle); | ||
1352 | return agent; | ||
1353 | } | ||
1354 | // TODO Should construct this behind a method | ||
1355 | string capsPath = | ||
1356 | "http://" + neighbourRegion.ExternalHostName + ":" + neighbourRegion.HttpPort | ||
1357 | + "/CAPS/" + agentcaps /*circuitdata.CapsPath*/ + "0000/"; | ||
1358 | |||
1359 | m_log.DebugFormat("[CAPS]: Sending new CAPS seed url {0} to client {1}", capsPath, agent.UUID); | ||
1360 | |||
1361 | IEventQueue eq = agent.Scene.RequestModuleInterface<IEventQueue>(); | ||
1362 | if (eq != null) | ||
1363 | { | ||
1364 | eq.CrossRegion(neighbourHandle, pos, agent.Velocity, neighbourRegion.ExternalEndPoint, | ||
1365 | capsPath, agent.UUID, agent.ControllingClient.SessionId); | ||
1366 | } | ||
1367 | else | ||
1368 | { | ||
1369 | agent.ControllingClient.CrossRegion(neighbourHandle, pos, agent.Velocity, neighbourRegion.ExternalEndPoint, | ||
1370 | capsPath); | ||
1371 | } | ||
1372 | |||
1373 | if (!WaitForCallback(agent.UUID)) | ||
1374 | { | ||
1375 | ResetFromTransit(agent.UUID); | ||
1376 | |||
1377 | // Yikes! We should just have a ref to scene here. | ||
1378 | agent.Scene.InformClientOfNeighbours(agent); | ||
1379 | |||
1380 | return agent; | ||
1381 | } | ||
1382 | |||
1383 | agent.MakeChildAgent(); | ||
1384 | // now we have a child agent in this region. Request all interesting data about other (root) agents | ||
1385 | agent.SendInitialFullUpdateToAllClients(); | ||
1386 | |||
1387 | agent.CrossAttachmentsIntoNewRegion(neighbourHandle, true); | ||
1388 | |||
1389 | // m_scene.SendKillObject(m_localId); | ||
1390 | |||
1391 | agent.Scene.NotifyMyCoarseLocationChange(); | ||
1392 | // the user may change their profile information in other region, | ||
1393 | // so the userinfo in UserProfileCache is not reliable any more, delete it | ||
1394 | if (agent.Scene.NeedSceneCacheClear(agent.UUID)) | ||
1395 | { | ||
1396 | agent.Scene.CommsManager.UserProfileCacheService.RemoveUser(agent.UUID); | ||
1397 | m_log.DebugFormat( | ||
1398 | "[SCENE COMM]: User {0} is going to another region, profile cache removed", agent.UUID); | ||
1399 | } | ||
1400 | } | ||
1401 | |||
1402 | //m_log.Debug("AFTER CROSS"); | ||
1403 | //Scene.DumpChildrenSeeds(UUID); | ||
1404 | //DumpKnownRegions(); | ||
1405 | return agent; | ||
1406 | } | ||
1407 | |||
1408 | private void CrossAgentToNewRegionCompleted(IAsyncResult iar) | ||
1409 | { | ||
1410 | CrossAgentToNewRegionDelegate icon = (CrossAgentToNewRegionDelegate)iar.AsyncState; | ||
1411 | ScenePresence agent = icon.EndInvoke(iar); | ||
1412 | |||
1413 | // If the cross was successful, this agent is a child agent | ||
1414 | if (agent.IsChildAgent) | ||
1415 | { | ||
1416 | agent.Reset(); | ||
1417 | } | ||
1418 | else // Not successful | ||
1419 | { | ||
1420 | //CachedUserInfo userInfo = m_commsProvider.UserProfileCacheService.GetUserDetails(agent.UUID); | ||
1421 | //if (userInfo != null) | ||
1422 | //{ | ||
1423 | // userInfo.FetchInventory(); | ||
1424 | //} | ||
1425 | agent.RestoreInCurrentScene(); | ||
1426 | } | ||
1427 | // In any case | ||
1428 | agent.NotInTransit(); | ||
1429 | |||
1430 | //m_log.DebugFormat("[SCENE COMM]: Crossing agent {0} {1} completed.", agent.Firstname, agent.Lastname); | ||
1431 | } | ||
1432 | |||
1433 | |||
1434 | public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat) | ||
1435 | { | ||
1436 | m_commsProvider.LogOffUser(userid, regionid, regionhandle, position, lookat); | ||
1437 | } | ||
1438 | |||
1439 | // deprecated as of 2008-08-27 | ||
1440 | public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz) | ||
1441 | { | ||
1442 | m_commsProvider.LogOffUser(userid, regionid, regionhandle, posx, posy, posz); | ||
1443 | } | ||
1444 | |||
1445 | public void ClearUserAgent(UUID avatarID) | ||
1446 | { | ||
1447 | m_commsProvider.UserService.ClearUserAgent(avatarID); | ||
1448 | } | ||
1449 | |||
1450 | public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms) | ||
1451 | { | ||
1452 | m_commsProvider.AddNewUserFriend(friendlistowner, friend, perms); | ||
1453 | } | ||
1454 | |||
1455 | public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms) | ||
1456 | { | ||
1457 | m_commsProvider.UpdateUserFriendPerms(friendlistowner, friend, perms); | ||
1458 | } | ||
1459 | |||
1460 | public void RemoveUserFriend(UUID friendlistowner, UUID friend) | ||
1461 | { | ||
1462 | m_commsProvider.RemoveUserFriend(friendlistowner, friend); | ||
1463 | } | ||
1464 | |||
1465 | public List<FriendListItem> GetUserFriendList(UUID friendlistowner) | ||
1466 | { | ||
1467 | return m_commsProvider.GetUserFriendList(friendlistowner); | ||
1468 | } | ||
1469 | |||
1470 | public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(UUID queryID, string query) | ||
1471 | { | ||
1472 | return m_commsProvider.GenerateAgentPickerRequestResponse(queryID, query); | ||
1473 | } | ||
1474 | |||
1475 | public List<GridRegion> RequestNamedRegions(string name, int maxNumber) | 304 | public List<GridRegion> RequestNamedRegions(string name, int maxNumber) |
1476 | { | 305 | { |
1477 | return m_scene.GridService.GetRegionsByName(UUID.Zero, name, maxNumber); | 306 | return m_scene.GridService.GetRegionsByName(UUID.Zero, name, maxNumber); |
1478 | } | 307 | } |
1479 | 308 | ||
1480 | //private void Dump(string msg, List<ulong> handles) | ||
1481 | //{ | ||
1482 | // m_log.InfoFormat("-------------- HANDLE DUMP ({0}) ---------", msg); | ||
1483 | // foreach (ulong handle in handles) | ||
1484 | // { | ||
1485 | // uint x, y; | ||
1486 | // Utils.LongToUInts(handle, out x, out y); | ||
1487 | // x = x / Constants.RegionSize; | ||
1488 | // y = y / Constants.RegionSize; | ||
1489 | // m_log.InfoFormat("({0}, {1})", x, y); | ||
1490 | // } | ||
1491 | //} | ||
1492 | } | 309 | } |
1493 | } | 310 | } |