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