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