aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDiva Canto2010-01-15 15:11:58 -0800
committerDiva Canto2010-01-15 15:11:58 -0800
commitf1c30784ac767bf5f62e81748984b76d85d71f6a (patch)
tree5aa635eadb534f30cd8aa2b9a1803f637e9b95a6
parentAdded a UserAccountCache to the UserAccountServiceConnectors. Uses a CenomeCa... (diff)
downloadopensim-SC_OLD-f1c30784ac767bf5f62e81748984b76d85d71f6a.zip
opensim-SC_OLD-f1c30784ac767bf5f62e81748984b76d85d71f6a.tar.gz
opensim-SC_OLD-f1c30784ac767bf5f62e81748984b76d85d71f6a.tar.bz2
opensim-SC_OLD-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
-rw-r--r--OpenSim/Region/Application/HGCommands.cs2
-rw-r--r--OpenSim/Region/Application/OpenSim.cs4
-rw-r--r--OpenSim/Region/CoreModules/Agent/AgentTransfer/AgentTransferModule.cs1188
-rw-r--r--OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml1
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs4
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs17
-rw-r--r--OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs7
-rw-r--r--OpenSim/Region/Framework/Interfaces/IAgentTransferModule.cs (renamed from OpenSim/Region/Framework/Interfaces/ITeleportModule.cs)17
-rw-r--r--OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs387
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs67
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs1149
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneManager.cs4
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs25
-rw-r--r--bin/config-include/Grid.ini1
-rw-r--r--bin/config-include/GridHypergrid.ini1
-rw-r--r--bin/config-include/Standalone.ini1
-rw-r--r--bin/config-include/StandaloneHypergrid.ini3
17 files changed, 1266 insertions, 1612 deletions
diff --git a/OpenSim/Region/Application/HGCommands.cs b/OpenSim/Region/Application/HGCommands.cs
index a863697..5b99d7d 100644
--- a/OpenSim/Region/Application/HGCommands.cs
+++ b/OpenSim/Region/Application/HGCommands.cs
@@ -47,7 +47,7 @@ namespace OpenSim
47 public static Scene CreateScene(RegionInfo regionInfo, AgentCircuitManager circuitManager, 47 public static Scene CreateScene(RegionInfo regionInfo, AgentCircuitManager circuitManager,
48 StorageManager storageManager, ModuleLoader m_moduleLoader, ConfigSettings m_configSettings, OpenSimConfigSource m_config, string m_version) 48 StorageManager storageManager, ModuleLoader m_moduleLoader, ConfigSettings m_configSettings, OpenSimConfigSource m_config, string m_version)
49 { 49 {
50 HGSceneCommunicationService sceneGridService = new HGSceneCommunicationService(); 50 SceneCommunicationService sceneGridService = new SceneCommunicationService();
51 51
52 return 52 return
53 new HGScene( 53 new HGScene(
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
index 9f5e173..546a1d1 100644
--- a/OpenSim/Region/Application/OpenSim.cs
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -414,7 +414,7 @@ namespace OpenSim
414 414
415 foreach (ScenePresence presence in agents) 415 foreach (ScenePresence presence in agents)
416 { 416 {
417 RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle); 417 RegionInfo regionInfo = presence.Scene.RegionInfo;
418 418
419 if (presence.Firstname.ToLower().Contains(cmdparams[2].ToLower()) && 419 if (presence.Firstname.ToLower().Contains(cmdparams[2].ToLower()) &&
420 presence.Lastname.ToLower().Contains(cmdparams[3].ToLower())) 420 presence.Lastname.ToLower().Contains(cmdparams[3].ToLower()))
@@ -908,7 +908,7 @@ namespace OpenSim
908 908
909 foreach (ScenePresence presence in agents) 909 foreach (ScenePresence presence in agents)
910 { 910 {
911 RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle); 911 RegionInfo regionInfo = presence.Scene.RegionInfo;
912 string regionName; 912 string regionName;
913 913
914 if (regionInfo == null) 914 if (regionInfo == null)
diff --git a/OpenSim/Region/CoreModules/Agent/AgentTransfer/AgentTransferModule.cs b/OpenSim/Region/CoreModules/Agent/AgentTransfer/AgentTransferModule.cs
new file mode 100644
index 0000000..8e3d041
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Agent/AgentTransfer/AgentTransferModule.cs
@@ -0,0 +1,1188 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Net;
31using System.Reflection;
32using System.Threading;
33
34using OpenSim.Framework;
35using OpenSim.Framework.Capabilities;
36using OpenSim.Framework.Client;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Services.Interfaces;
40
41using GridRegion = OpenSim.Services.Interfaces.GridRegion;
42
43using OpenMetaverse;
44using log4net;
45using Nini.Config;
46
47namespace OpenSim.Region.CoreModules.Agent.AgentTransfer
48{
49 public class AgentTransferModule : ISharedRegionModule, IAgentTransferModule
50 {
51 #region ISharedRegionModule
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53
54 private bool m_Enabled = false;
55 protected Scene m_aScene;
56 protected List<UUID> m_agentsInTransit;
57
58 public Type ReplaceableInterface
59 {
60 get { return null; }
61 }
62
63 public string Name
64 {
65 get { return "AgentTransferModule"; }
66 }
67
68 public virtual void Initialise(IConfigSource source)
69 {
70 IConfig moduleConfig = source.Configs["Modules"];
71 if (moduleConfig != null)
72 {
73 string name = moduleConfig.GetString("AgentTransferModule", "");
74 if (name == Name)
75 {
76 m_agentsInTransit = new List<UUID>();
77 m_Enabled = true;
78 m_log.Info("[AGENT TRANSFER MODULE]: Enabled.");
79 }
80 }
81 }
82
83 public virtual void PostInitialise()
84 {
85 }
86
87 public virtual void AddRegion(Scene scene)
88 {
89 if (!m_Enabled)
90 return;
91
92 if (m_aScene == null)
93 m_aScene = scene;
94
95 scene.RegisterModuleInterface<IAgentTransferModule>(this);
96 }
97
98 public virtual void Close()
99 {
100 if (!m_Enabled)
101 return;
102 }
103
104
105 public virtual void RemoveRegion(Scene scene)
106 {
107 if (!m_Enabled)
108 return;
109 if (scene == m_aScene)
110 m_aScene = null;
111 }
112
113 public virtual void RegionLoaded(Scene scene)
114 {
115 if (!m_Enabled)
116 return;
117
118 }
119
120
121 #endregion
122
123 #region Teleports
124
125 public void Teleport(ScenePresence sp, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags)
126 {
127 if (!sp.Scene.Permissions.CanTeleport(sp.UUID))
128 return;
129
130 bool destRegionUp = true;
131
132 IEventQueue eq = sp.Scene.RequestModuleInterface<IEventQueue>();
133
134 // Reset animations; the viewer does that in teleports.
135 sp.Animator.ResetAnimations();
136
137 if (regionHandle == sp.Scene.RegionInfo.RegionHandle)
138 {
139 m_log.DebugFormat(
140 "[AGENT TRANSFER MODULE]: RequestTeleportToLocation {0} within {1}",
141 position, sp.Scene.RegionInfo.RegionName);
142
143 // Teleport within the same region
144 if (IsOutsideRegion(sp.Scene, position) || position.Z < 0)
145 {
146 Vector3 emergencyPos = new Vector3(128, 128, 128);
147
148 m_log.WarnFormat(
149 "[AGENT TRANSFER MODULE]: RequestTeleportToLocation() was given an illegal position of {0} for avatar {1}, {2}. Substituting {3}",
150 position, sp.Name, sp.UUID, emergencyPos);
151 position = emergencyPos;
152 }
153
154 // TODO: Get proper AVG Height
155 float localAVHeight = 1.56f;
156 float posZLimit = 22;
157
158 // TODO: Check other Scene HeightField
159 if (position.X > 0 && position.X <= (int)Constants.RegionSize && position.Y > 0 && position.Y <= (int)Constants.RegionSize)
160 {
161 posZLimit = (float)sp.Scene.Heightmap[(int)position.X, (int)position.Y];
162 }
163
164 float newPosZ = posZLimit + localAVHeight;
165 if (posZLimit >= (position.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
166 {
167 position.Z = newPosZ;
168 }
169
170 // Only send this if the event queue is null
171 if (eq == null)
172 sp.ControllingClient.SendTeleportLocationStart();
173
174 sp.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags);
175 sp.Teleport(position);
176 }
177 else
178 {
179 uint x = 0, y = 0;
180 Utils.LongToUInts(regionHandle, out x, out y);
181 GridRegion reg = m_aScene.GridService.GetRegionByPosition(sp.Scene.RegionInfo.ScopeID, (int)x, (int)y);
182
183 if (reg != null)
184 {
185 m_log.DebugFormat(
186 "[AGENT TRANSFER MODULE]: RequestTeleportToLocation to {0} in {1}",
187 position, reg.RegionName);
188
189 uint newRegionX = (uint)(reg.RegionHandle >> 40);
190 uint newRegionY = (((uint)(reg.RegionHandle)) >> 8);
191 uint oldRegionX = (uint)(sp.Scene.RegionInfo.RegionHandle >> 40);
192 uint oldRegionY = (((uint)(sp.Scene.RegionInfo.RegionHandle)) >> 8);
193
194 ulong destinationHandle = GetRegionHandle(reg);
195
196 if (eq == null)
197 sp.ControllingClient.SendTeleportLocationStart();
198
199 // Let's do DNS resolution only once in this process, please!
200 // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field,
201 // it's actually doing a lot of work.
202 IPEndPoint endPoint = reg.ExternalEndPoint;
203 if (endPoint.Address == null)
204 {
205 // Couldn't resolve the name. Can't TP, because the viewer wants IP addresses.
206 destRegionUp = false;
207 }
208
209 if (destRegionUp)
210 {
211 // Fixing a bug where teleporting while sitting results in the avatar ending up removed from
212 // both regions
213 if (sp.ParentID != (uint)0)
214 sp.StandUp();
215
216 if (!sp.ValidateAttachments())
217 {
218 sp.ControllingClient.SendTeleportFailed("Inconsistent attachment state");
219 return;
220 }
221
222 // the avatar.Close below will clear the child region list. We need this below for (possibly)
223 // closing the child agents, so save it here (we need a copy as it is Clear()-ed).
224 //List<ulong> childRegions = new List<ulong>(avatar.GetKnownRegionList());
225 // Compared to ScenePresence.CrossToNewRegion(), there's no obvious code to handle a teleport
226 // failure at this point (unlike a border crossing failure). So perhaps this can never fail
227 // once we reach here...
228 //avatar.Scene.RemoveCapsHandler(avatar.UUID);
229
230 string capsPath = String.Empty;
231 AgentCircuitData agentCircuit = sp.ControllingClient.RequestClientInfo();
232 agentCircuit.BaseFolder = UUID.Zero;
233 agentCircuit.InventoryFolder = UUID.Zero;
234 agentCircuit.startpos = position;
235 agentCircuit.child = true;
236 agentCircuit.Appearance = sp.Appearance;
237
238 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY))
239 {
240 // brand new agent, let's create a new caps seed
241 agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
242 }
243
244 string reason = String.Empty;
245
246 // Let's create an agent there if one doesn't exist yet.
247 //if (!m_commsProvider.InterRegion.InformRegionOfChildAgent(reg.RegionHandle, agentCircuit))
248 if (!m_aScene.SimulationService.CreateAgent(reg, agentCircuit, teleportFlags, out reason))
249 {
250 sp.ControllingClient.SendTeleportFailed(String.Format("Destination is not accepting teleports: {0}",
251 reason));
252 return;
253 }
254
255 // OK, it got this agent. Let's close some child agents
256 sp.CloseChildAgents(newRegionX, newRegionY);
257
258 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY))
259 {
260 #region IP Translation for NAT
261 IClientIPEndpoint ipepClient;
262 if (sp.ClientView.TryGet(out ipepClient))
263 {
264 capsPath
265 = "http://"
266 + NetworkUtil.GetHostFor(ipepClient.EndPoint, reg.ExternalHostName)
267 + ":"
268 + reg.HttpPort
269 + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
270 }
271 else
272 {
273 capsPath
274 = "http://"
275 + reg.ExternalHostName
276 + ":"
277 + reg.HttpPort
278 + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
279 }
280 #endregion
281
282 if (eq != null)
283 {
284 #region IP Translation for NAT
285 // Uses ipepClient above
286 if (sp.ClientView.TryGet(out ipepClient))
287 {
288 endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
289 }
290 #endregion
291
292 eq.EnableSimulator(destinationHandle, endPoint, sp.UUID);
293
294 // ES makes the client send a UseCircuitCode message to the destination,
295 // which triggers a bunch of things there.
296 // So let's wait
297 Thread.Sleep(2000);
298
299 eq.EstablishAgentCommunication(sp.UUID, endPoint, capsPath);
300
301 }
302 else
303 {
304 sp.ControllingClient.InformClientOfNeighbour(destinationHandle, endPoint);
305 }
306 }
307 else
308 {
309 agentCircuit.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, reg.RegionHandle);
310 capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort
311 + "/CAPS/" + agentCircuit.CapsPath + "0000/";
312 }
313
314 // Expect avatar crossing is a heavy-duty function at the destination.
315 // That is where MakeRoot is called, which fetches appearance and inventory.
316 // Plus triggers OnMakeRoot, which spawns a series of asynchronous updates.
317 //m_commsProvider.InterRegion.ExpectAvatarCrossing(reg.RegionHandle, avatar.ControllingClient.AgentId,
318 // position, false);
319
320 //{
321 // avatar.ControllingClient.SendTeleportFailed("Problem with destination.");
322 // // We should close that agent we just created over at destination...
323 // List<ulong> lst = new List<ulong>();
324 // lst.Add(reg.RegionHandle);
325 // SendCloseChildAgentAsync(avatar.UUID, lst);
326 // return;
327 //}
328
329 SetInTransit(sp.UUID);
330
331 // Let's send a full update of the agent. This is a synchronous call.
332 AgentData agent = new AgentData();
333 sp.CopyTo(agent);
334 agent.Position = position;
335 agent.CallbackURI = "http://" + sp.Scene.RegionInfo.ExternalHostName + ":" + sp.Scene.RegionInfo.HttpPort +
336 "/agent/" + sp.UUID.ToString() + "/" + sp.Scene.RegionInfo.RegionID.ToString() + "/release/";
337
338 m_aScene.SimulationService.UpdateAgent(reg, agent);
339
340 m_log.DebugFormat(
341 "[AGENT TRANSFER MODULE]: Sending new AGENT TRANSFER MODULE seed url {0} to client {1}", capsPath, sp.UUID);
342
343
344 if (eq != null)
345 {
346 eq.TeleportFinishEvent(destinationHandle, 13, endPoint,
347 0, teleportFlags, capsPath, sp.UUID);
348 }
349 else
350 {
351 sp.ControllingClient.SendRegionTeleport(destinationHandle, 13, endPoint, 4,
352 teleportFlags, capsPath);
353 }
354
355 // TeleportFinish makes the client send CompleteMovementIntoRegion (at the destination), which
356 // trigers a whole shebang of things there, including MakeRoot. So let's wait for confirmation
357 // that the client contacted the destination before we send the attachments and close things here.
358 if (!WaitForCallback(sp.UUID))
359 {
360 // Client never contacted destination. Let's restore everything back
361 sp.ControllingClient.SendTeleportFailed("Problems connecting to destination.");
362
363 ResetFromTransit(sp.UUID);
364
365 // Yikes! We should just have a ref to scene here.
366 //sp.Scene.InformClientOfNeighbours(sp);
367 EnableChildAgents(sp);
368
369 // Finally, kill the agent we just created at the destination.
370 m_aScene.SimulationService.CloseAgent(reg, sp.UUID);
371
372 return;
373 }
374
375 KillEntity(sp.Scene, sp.LocalId);
376
377 sp.MakeChildAgent();
378
379 // CrossAttachmentsIntoNewRegion is a synchronous call. We shouldn't need to wait after it
380 sp.CrossAttachmentsIntoNewRegion(reg, true);
381
382 // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone
383
384 if (NeedsClosing(oldRegionX, newRegionX, oldRegionY, newRegionY, reg))
385 {
386 Thread.Sleep(5000);
387 sp.Close();
388 sp.Scene.IncomingCloseAgent(sp.UUID);
389 }
390 else
391 // now we have a child agent in this region.
392 sp.Reset();
393
394
395 // REFACTORING PROBLEM. Well, not a problem, but this method is HORRIBLE!
396 if (sp.Scene.NeedSceneCacheClear(sp.UUID))
397 {
398 m_log.DebugFormat(
399 "[AGENT TRANSFER MODULE]: User {0} is going to another region, profile cache removed",
400 sp.UUID);
401 }
402 }
403 else
404 {
405 sp.ControllingClient.SendTeleportFailed("Remote Region appears to be down");
406 }
407 }
408 else
409 {
410 // TP to a place that doesn't exist (anymore)
411 // Inform the viewer about that
412 sp.ControllingClient.SendTeleportFailed("The region you tried to teleport to doesn't exist anymore");
413
414 // and set the map-tile to '(Offline)'
415 uint regX, regY;
416 Utils.LongToUInts(regionHandle, out regX, out regY);
417
418 MapBlockData block = new MapBlockData();
419 block.X = (ushort)(regX / Constants.RegionSize);
420 block.Y = (ushort)(regY / Constants.RegionSize);
421 block.Access = 254; // == not there
422
423 List<MapBlockData> blocks = new List<MapBlockData>();
424 blocks.Add(block);
425 sp.ControllingClient.SendMapBlock(blocks, 0);
426 }
427 }
428 }
429
430 #endregion
431
432 #region Enable Child Agent
433 /// <summary>
434 /// This informs a single neighboring region about agent "avatar".
435 /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
436 /// </summary>
437 public void EnableChildAgent(ScenePresence sp, GridRegion region)
438 {
439 AgentCircuitData agent = sp.ControllingClient.RequestClientInfo();
440 agent.BaseFolder = UUID.Zero;
441 agent.InventoryFolder = UUID.Zero;
442 agent.startpos = new Vector3(128, 128, 70);
443 agent.child = true;
444 agent.Appearance = sp.Appearance;
445
446 InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync;
447 d.BeginInvoke(sp, agent, region, region.ExternalEndPoint, true,
448 InformClientOfNeighbourCompleted,
449 d);
450 }
451 #endregion
452
453 #region Crossings
454
455 public void Cross(ScenePresence agent, bool isFlying)
456 {
457 Scene scene = agent.Scene;
458 Vector3 pos = agent.AbsolutePosition;
459 Vector3 newpos = new Vector3(pos.X, pos.Y, pos.Z);
460 uint neighbourx = scene.RegionInfo.RegionLocX;
461 uint neighboury = scene.RegionInfo.RegionLocY;
462 const float boundaryDistance = 1.7f;
463 Vector3 northCross = new Vector3(0, boundaryDistance, 0);
464 Vector3 southCross = new Vector3(0, -1 * boundaryDistance, 0);
465 Vector3 eastCross = new Vector3(boundaryDistance, 0, 0);
466 Vector3 westCross = new Vector3(-1 * boundaryDistance, 0, 0);
467
468 // distance to edge that will trigger crossing
469
470
471 // distance into new region to place avatar
472 const float enterDistance = 0.5f;
473
474 if (scene.TestBorderCross(pos + westCross, Cardinals.W))
475 {
476 if (scene.TestBorderCross(pos + northCross, Cardinals.N))
477 {
478 Border b = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
479 neighboury += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
480 }
481 else if (scene.TestBorderCross(pos + southCross, Cardinals.S))
482 {
483 Border b = scene.GetCrossedBorder(pos + southCross, Cardinals.S);
484 if (b.TriggerRegionX == 0 && b.TriggerRegionY == 0)
485 {
486 neighboury--;
487 newpos.Y = Constants.RegionSize - enterDistance;
488 }
489 else
490 {
491 neighboury = b.TriggerRegionY;
492 neighbourx = b.TriggerRegionX;
493
494 Vector3 newposition = pos;
495 newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
496 newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
497 agent.ControllingClient.SendAgentAlertMessage(
498 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
499 InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
500 return;
501 }
502 }
503
504 Border ba = scene.GetCrossedBorder(pos + westCross, Cardinals.W);
505 if (ba.TriggerRegionX == 0 && ba.TriggerRegionY == 0)
506 {
507 neighbourx--;
508 newpos.X = Constants.RegionSize - enterDistance;
509 }
510 else
511 {
512 neighboury = ba.TriggerRegionY;
513 neighbourx = ba.TriggerRegionX;
514
515
516 Vector3 newposition = pos;
517 newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
518 newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
519 agent.ControllingClient.SendAgentAlertMessage(
520 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
521 InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
522
523
524 return;
525 }
526
527 }
528 else if (scene.TestBorderCross(pos + eastCross, Cardinals.E))
529 {
530 Border b = scene.GetCrossedBorder(pos + eastCross, Cardinals.E);
531 neighbourx += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
532 newpos.X = enterDistance;
533
534 if (scene.TestBorderCross(pos + southCross, Cardinals.S))
535 {
536 Border ba = scene.GetCrossedBorder(pos + southCross, Cardinals.S);
537 if (ba.TriggerRegionX == 0 && ba.TriggerRegionY == 0)
538 {
539 neighboury--;
540 newpos.Y = Constants.RegionSize - enterDistance;
541 }
542 else
543 {
544 neighboury = ba.TriggerRegionY;
545 neighbourx = ba.TriggerRegionX;
546 Vector3 newposition = pos;
547 newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
548 newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
549 agent.ControllingClient.SendAgentAlertMessage(
550 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
551 InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
552 return;
553 }
554 }
555 else if (scene.TestBorderCross(pos + northCross, Cardinals.N))
556 {
557 Border c = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
558 neighboury += (uint)(int)(c.BorderLine.Z / (int)Constants.RegionSize);
559 newpos.Y = enterDistance;
560 }
561
562
563 }
564 else if (scene.TestBorderCross(pos + southCross, Cardinals.S))
565 {
566 Border b = scene.GetCrossedBorder(pos + southCross, Cardinals.S);
567 if (b.TriggerRegionX == 0 && b.TriggerRegionY == 0)
568 {
569 neighboury--;
570 newpos.Y = Constants.RegionSize - enterDistance;
571 }
572 else
573 {
574 neighboury = b.TriggerRegionY;
575 neighbourx = b.TriggerRegionX;
576 Vector3 newposition = pos;
577 newposition.X += (scene.RegionInfo.RegionLocX - neighbourx) * Constants.RegionSize;
578 newposition.Y += (scene.RegionInfo.RegionLocY - neighboury) * Constants.RegionSize;
579 agent.ControllingClient.SendAgentAlertMessage(
580 String.Format("Moving you to region {0},{1}", neighbourx, neighboury), false);
581 InformClientToInitateTeleportToLocation(agent, neighbourx, neighboury, newposition, scene);
582 return;
583 }
584 }
585 else if (scene.TestBorderCross(pos + northCross, Cardinals.N))
586 {
587
588 Border b = scene.GetCrossedBorder(pos + northCross, Cardinals.N);
589 neighboury += (uint)(int)(b.BorderLine.Z / (int)Constants.RegionSize);
590 newpos.Y = enterDistance;
591 }
592
593 /*
594
595 if (pos.X < boundaryDistance) //West
596 {
597 neighbourx--;
598 newpos.X = Constants.RegionSize - enterDistance;
599 }
600 else if (pos.X > Constants.RegionSize - boundaryDistance) // East
601 {
602 neighbourx++;
603 newpos.X = enterDistance;
604 }
605
606 if (pos.Y < boundaryDistance) // South
607 {
608 neighboury--;
609 newpos.Y = Constants.RegionSize - enterDistance;
610 }
611 else if (pos.Y > Constants.RegionSize - boundaryDistance) // North
612 {
613 neighboury++;
614 newpos.Y = enterDistance;
615 }
616 */
617
618 CrossAgentToNewRegionDelegate d = CrossAgentToNewRegionAsync;
619 d.BeginInvoke(agent, newpos, neighbourx, neighboury, isFlying, CrossAgentToNewRegionCompleted, d);
620
621 }
622
623
624 public delegate void InformClientToInitateTeleportToLocationDelegate(ScenePresence agent, uint regionX, uint regionY,
625 Vector3 position,
626 Scene initiatingScene);
627
628 private void InformClientToInitateTeleportToLocation(ScenePresence agent, uint regionX, uint regionY, Vector3 position, Scene initiatingScene)
629 {
630
631 // This assumes that we know what our neighbors are.
632
633 InformClientToInitateTeleportToLocationDelegate d = InformClientToInitiateTeleportToLocationAsync;
634 d.BeginInvoke(agent, regionX, regionY, position, initiatingScene,
635 InformClientToInitiateTeleportToLocationCompleted,
636 d);
637 }
638
639 public void InformClientToInitiateTeleportToLocationAsync(ScenePresence agent, uint regionX, uint regionY, Vector3 position,
640 Scene initiatingScene)
641 {
642 Thread.Sleep(10000);
643 IMessageTransferModule im = initiatingScene.RequestModuleInterface<IMessageTransferModule>();
644 if (im != null)
645 {
646 UUID gotoLocation = Util.BuildFakeParcelID(
647 Util.UIntsToLong(
648 (regionX *
649 (uint)Constants.RegionSize),
650 (regionY *
651 (uint)Constants.RegionSize)),
652 (uint)(int)position.X,
653 (uint)(int)position.Y,
654 (uint)(int)position.Z);
655 GridInstantMessage m = new GridInstantMessage(initiatingScene, UUID.Zero,
656 "Region", agent.UUID,
657 (byte)InstantMessageDialog.GodLikeRequestTeleport, false,
658 "", gotoLocation, false, new Vector3(127, 0, 0),
659 new Byte[0]);
660 im.SendInstantMessage(m, delegate(bool success)
661 {
662 m_log.DebugFormat("[AGENT TRANSFER MODULE]: Client Initiating Teleport sending IM success = {0}", success);
663 });
664
665 }
666 }
667
668 private void InformClientToInitiateTeleportToLocationCompleted(IAsyncResult iar)
669 {
670 InformClientToInitateTeleportToLocationDelegate icon =
671 (InformClientToInitateTeleportToLocationDelegate)iar.AsyncState;
672 icon.EndInvoke(iar);
673 }
674
675 public delegate ScenePresence CrossAgentToNewRegionDelegate(ScenePresence agent, Vector3 pos, uint neighbourx, uint neighboury, bool isFlying);
676
677 /// <summary>
678 /// This Closes child agents on neighboring regions
679 /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
680 /// </summary>
681 protected ScenePresence CrossAgentToNewRegionAsync(ScenePresence agent, Vector3 pos, uint neighbourx, uint neighboury, bool isFlying)
682 {
683 m_log.DebugFormat("[AGENT TRANSFER MODULE]: Crossing agent {0} {1} to {2}-{3}", agent.Firstname, agent.Lastname, neighbourx, neighboury);
684
685 Scene m_scene = agent.Scene;
686 ulong neighbourHandle = Utils.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize));
687
688 int x = (int)(neighbourx * Constants.RegionSize), y = (int)(neighboury * Constants.RegionSize);
689 GridRegion neighbourRegion = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
690
691 if (neighbourRegion != null && agent.ValidateAttachments())
692 {
693 pos = pos + (agent.Velocity);
694
695 SetInTransit(agent.UUID);
696 AgentData cAgent = new AgentData();
697 agent.CopyTo(cAgent);
698 cAgent.Position = pos;
699 if (isFlying)
700 cAgent.ControlFlags |= (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;
701 cAgent.CallbackURI = "http://" + m_scene.RegionInfo.ExternalHostName + ":" + m_scene.RegionInfo.HttpPort +
702 "/agent/" + agent.UUID.ToString() + "/" + m_scene.RegionInfo.RegionID.ToString() + "/release/";
703
704 m_scene.SimulationService.UpdateAgent(neighbourRegion, cAgent);
705
706 // Next, let's close the child agent connections that are too far away.
707 agent.CloseChildAgents(neighbourx, neighboury);
708
709 //AgentCircuitData circuitdata = m_controllingClient.RequestClientInfo();
710 agent.ControllingClient.RequestClientInfo();
711
712 //m_log.Debug("BEFORE CROSS");
713 //Scene.DumpChildrenSeeds(UUID);
714 //DumpKnownRegions();
715 string agentcaps;
716 if (!agent.KnownRegions.TryGetValue(neighbourRegion.RegionHandle, out agentcaps))
717 {
718 m_log.ErrorFormat("[AGENT TRANSFER MODULE]: No AGENT TRANSFER MODULE information for region handle {0}, exiting CrossToNewRegion.",
719 neighbourRegion.RegionHandle);
720 return agent;
721 }
722 // TODO Should construct this behind a method
723 string capsPath =
724 "http://" + neighbourRegion.ExternalHostName + ":" + neighbourRegion.HttpPort
725 + "/CAPS/" + agentcaps /*circuitdata.CapsPath*/ + "0000/";
726
727 m_log.DebugFormat("[AGENT TRANSFER MODULE]: Sending new AGENT TRANSFER MODULE seed url {0} to client {1}", capsPath, agent.UUID);
728
729 IEventQueue eq = agent.Scene.RequestModuleInterface<IEventQueue>();
730 if (eq != null)
731 {
732 eq.CrossRegion(neighbourHandle, pos, agent.Velocity, neighbourRegion.ExternalEndPoint,
733 capsPath, agent.UUID, agent.ControllingClient.SessionId);
734 }
735 else
736 {
737 agent.ControllingClient.CrossRegion(neighbourHandle, pos, agent.Velocity, neighbourRegion.ExternalEndPoint,
738 capsPath);
739 }
740
741 if (!WaitForCallback(agent.UUID))
742 {
743 m_log.Debug("[AGENT TRANSFER MODULE]: Callback never came in crossing agent");
744 ResetFromTransit(agent.UUID);
745
746 // Yikes! We should just have a ref to scene here.
747 //agent.Scene.InformClientOfNeighbours(agent);
748 EnableChildAgents(agent);
749
750 return agent;
751 }
752
753 agent.MakeChildAgent();
754 // now we have a child agent in this region. Request all interesting data about other (root) agents
755 agent.SendInitialFullUpdateToAllClients();
756
757 agent.CrossAttachmentsIntoNewRegion(neighbourRegion, true);
758
759 // m_scene.SendKillObject(m_localId);
760
761 agent.Scene.NotifyMyCoarseLocationChange();
762 // the user may change their profile information in other region,
763 // so the userinfo in UserProfileCache is not reliable any more, delete it
764 // REFACTORING PROBLEM. Well, not a problem, but this method is HORRIBLE!
765 if (agent.Scene.NeedSceneCacheClear(agent.UUID))
766 {
767 m_log.DebugFormat(
768 "[AGENT TRANSFER MODULE]: User {0} is going to another region", agent.UUID);
769 }
770 }
771
772 //m_log.Debug("AFTER CROSS");
773 //Scene.DumpChildrenSeeds(UUID);
774 //DumpKnownRegions();
775 return agent;
776 }
777
778 private void CrossAgentToNewRegionCompleted(IAsyncResult iar)
779 {
780 CrossAgentToNewRegionDelegate icon = (CrossAgentToNewRegionDelegate)iar.AsyncState;
781 ScenePresence agent = icon.EndInvoke(iar);
782
783 // If the cross was successful, this agent is a child agent
784 if (agent.IsChildAgent)
785 agent.Reset();
786 else // Not successful
787 agent.RestoreInCurrentScene();
788
789 // In any case
790 agent.NotInTransit();
791
792 //m_log.DebugFormat("[AGENT TRANSFER MODULE]: Crossing agent {0} {1} completed.", agent.Firstname, agent.Lastname);
793 }
794
795 #endregion
796
797
798 #region Enable Child Agents
799
800 private delegate void InformClientOfNeighbourDelegate(
801 ScenePresence avatar, AgentCircuitData a, GridRegion reg, IPEndPoint endPoint, bool newAgent);
802
803 /// <summary>
804 /// This informs all neighboring regions about agent "avatar".
805 /// Calls an asynchronous method to do so.. so it doesn't lag the sim.
806 /// </summary>
807 public void EnableChildAgents(ScenePresence sp)
808 {
809 List<GridRegion> neighbours = new List<GridRegion>();
810 RegionInfo m_regionInfo = sp.Scene.RegionInfo;
811
812 if (m_regionInfo != null)
813 {
814 neighbours = RequestNeighbours(sp.Scene, m_regionInfo.RegionLocX, m_regionInfo.RegionLocY);
815 }
816 else
817 {
818 m_log.Debug("[AGENT TRANSFER MODULE]: m_regionInfo was null in EnableChildAgents, is this a NPC?");
819 }
820
821 /// We need to find the difference between the new regions where there are no child agents
822 /// and the regions where there are already child agents. We only send notification to the former.
823 List<ulong> neighbourHandles = NeighbourHandles(neighbours); // on this region
824 neighbourHandles.Add(sp.Scene.RegionInfo.RegionHandle); // add this region too
825 List<ulong> previousRegionNeighbourHandles;
826
827 if (sp.Scene.CapsModule != null)
828 {
829 previousRegionNeighbourHandles =
830 new List<ulong>(sp.Scene.CapsModule.GetChildrenSeeds(sp.UUID).Keys);
831 }
832 else
833 {
834 previousRegionNeighbourHandles = new List<ulong>();
835 }
836
837 List<ulong> newRegions = NewNeighbours(neighbourHandles, previousRegionNeighbourHandles);
838 List<ulong> oldRegions = OldNeighbours(neighbourHandles, previousRegionNeighbourHandles);
839
840 //Dump("Current Neighbors", neighbourHandles);
841 //Dump("Previous Neighbours", previousRegionNeighbourHandles);
842 //Dump("New Neighbours", newRegions);
843 //Dump("Old Neighbours", oldRegions);
844
845 /// Update the scene presence's known regions here on this region
846 sp.DropOldNeighbours(oldRegions);
847
848 /// Collect as many seeds as possible
849 Dictionary<ulong, string> seeds;
850 if (sp.Scene.CapsModule != null)
851 seeds
852 = new Dictionary<ulong, string>(sp.Scene.CapsModule.GetChildrenSeeds(sp.UUID));
853 else
854 seeds = new Dictionary<ulong, string>();
855
856 //m_log.Debug(" !!! No. of seeds: " + seeds.Count);
857 if (!seeds.ContainsKey(sp.Scene.RegionInfo.RegionHandle))
858 seeds.Add(sp.Scene.RegionInfo.RegionHandle, sp.ControllingClient.RequestClientInfo().CapsPath);
859
860 /// Create the necessary child agents
861 List<AgentCircuitData> cagents = new List<AgentCircuitData>();
862 foreach (GridRegion neighbour in neighbours)
863 {
864 if (neighbour.RegionHandle != sp.Scene.RegionInfo.RegionHandle)
865 {
866
867 AgentCircuitData agent = sp.ControllingClient.RequestClientInfo();
868 agent.BaseFolder = UUID.Zero;
869 agent.InventoryFolder = UUID.Zero;
870 agent.startpos = new Vector3(128, 128, 70);
871 agent.child = true;
872 agent.Appearance = sp.Appearance;
873
874 if (newRegions.Contains(neighbour.RegionHandle))
875 {
876 agent.CapsPath = CapsUtil.GetRandomCapsObjectPath();
877 sp.AddNeighbourRegion(neighbour.RegionHandle, agent.CapsPath);
878 seeds.Add(neighbour.RegionHandle, agent.CapsPath);
879 }
880 else
881 agent.CapsPath = sp.Scene.CapsModule.GetChildSeed(sp.UUID, neighbour.RegionHandle);
882
883 cagents.Add(agent);
884 }
885 }
886
887 /// Update all child agent with everyone's seeds
888 foreach (AgentCircuitData a in cagents)
889 {
890 a.ChildrenCapSeeds = new Dictionary<ulong, string>(seeds);
891 }
892
893 if (sp.Scene.CapsModule != null)
894 {
895 sp.Scene.CapsModule.SetChildrenSeed(sp.UUID, seeds);
896 }
897 sp.KnownRegions = seeds;
898 //avatar.Scene.DumpChildrenSeeds(avatar.UUID);
899 //avatar.DumpKnownRegions();
900
901 bool newAgent = false;
902 int count = 0;
903 foreach (GridRegion neighbour in neighbours)
904 {
905 //m_log.WarnFormat("--> Going to send child agent to {0}", neighbour.RegionName);
906 // Don't do it if there's already an agent in that region
907 if (newRegions.Contains(neighbour.RegionHandle))
908 newAgent = true;
909 else
910 newAgent = false;
911
912 if (neighbour.RegionHandle != sp.Scene.RegionInfo.RegionHandle)
913 {
914 InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync;
915 try
916 {
917 d.BeginInvoke(sp, cagents[count], neighbour, neighbour.ExternalEndPoint, newAgent,
918 InformClientOfNeighbourCompleted,
919 d);
920 }
921
922 catch (ArgumentOutOfRangeException)
923 {
924 m_log.ErrorFormat(
925 "[AGENT TRANSFER MODULE]: Neighbour Regions response included the current region in the neighbor list. The following region will not display to the client: {0} for region {1} ({2}, {3}).",
926 neighbour.ExternalHostName,
927 neighbour.RegionHandle,
928 neighbour.RegionLocX,
929 neighbour.RegionLocY);
930 }
931 catch (Exception e)
932 {
933 m_log.ErrorFormat(
934 "[AGENT TRANSFER MODULE]: Could not resolve external hostname {0} for region {1} ({2}, {3}). {4}",
935 neighbour.ExternalHostName,
936 neighbour.RegionHandle,
937 neighbour.RegionLocX,
938 neighbour.RegionLocY,
939 e);
940
941 // FIXME: Okay, even though we've failed, we're still going to throw the exception on,
942 // since I don't know what will happen if we just let the client continue
943
944 // XXX: Well, decided to swallow the exception instead for now. Let us see how that goes.
945 // throw e;
946
947 }
948 }
949 count++;
950 }
951 }
952
953 private void InformClientOfNeighbourCompleted(IAsyncResult iar)
954 {
955 InformClientOfNeighbourDelegate icon = (InformClientOfNeighbourDelegate)iar.AsyncState;
956 icon.EndInvoke(iar);
957 //m_log.WarnFormat(" --> InformClientOfNeighbourCompleted");
958 }
959
960 /// <summary>
961 /// Async component for informing client of which neighbours exist
962 /// </summary>
963 /// <remarks>
964 /// This needs to run asynchronously, as a network timeout may block the thread for a long while
965 /// </remarks>
966 /// <param name="remoteClient"></param>
967 /// <param name="a"></param>
968 /// <param name="regionHandle"></param>
969 /// <param name="endPoint"></param>
970 private void InformClientOfNeighbourAsync(ScenePresence sp, AgentCircuitData a, GridRegion reg,
971 IPEndPoint endPoint, bool newAgent)
972 {
973 // Let's wait just a little to give time to originating regions to catch up with closing child agents
974 // after a cross here
975 Thread.Sleep(500);
976
977 Scene m_scene = sp.Scene;
978
979 uint x, y;
980 Utils.LongToUInts(reg.RegionHandle, out x, out y);
981 x = x / Constants.RegionSize;
982 y = y / Constants.RegionSize;
983 m_log.Info("[AGENT TRANSFER MODULE]: Starting to inform client about neighbour " + x + ", " + y + "(" + endPoint.ToString() + ")");
984
985 string capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort
986 + "/CAPS/" + a.CapsPath + "0000/";
987
988 string reason = String.Empty;
989
990
991 bool regionAccepted = m_scene.SimulationService.CreateAgent(reg, a, 0, out reason); // m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, a, 0, out reason);
992
993 if (regionAccepted && newAgent)
994 {
995 IEventQueue eq = sp.Scene.RequestModuleInterface<IEventQueue>();
996 if (eq != null)
997 {
998 #region IP Translation for NAT
999 IClientIPEndpoint ipepClient;
1000 if (sp.ClientView.TryGet(out ipepClient))
1001 {
1002 endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
1003 }
1004 #endregion
1005
1006 eq.EnableSimulator(reg.RegionHandle, endPoint, sp.UUID);
1007 eq.EstablishAgentCommunication(sp.UUID, endPoint, capsPath);
1008 m_log.DebugFormat("[AGENT TRANSFER MODULE]: Sending new AGENT TRANSFER MODULE seed url {0} to client {1} in region {2}",
1009 capsPath, sp.UUID, sp.Scene.RegionInfo.RegionName);
1010 }
1011 else
1012 {
1013 sp.ControllingClient.InformClientOfNeighbour(reg.RegionHandle, endPoint);
1014 // TODO: make Event Queue disablable!
1015 }
1016
1017 m_log.Info("[AGENT TRANSFER MODULE]: Completed inform client about neighbour " + endPoint.ToString());
1018
1019 }
1020
1021 }
1022
1023 protected List<GridRegion> RequestNeighbours(Scene pScene, uint pRegionLocX, uint pRegionLocY)
1024 {
1025 RegionInfo m_regionInfo = pScene.RegionInfo;
1026
1027 Border[] northBorders = pScene.NorthBorders.ToArray();
1028 Border[] southBorders = pScene.SouthBorders.ToArray();
1029 Border[] eastBorders = pScene.EastBorders.ToArray();
1030 Border[] westBorders = pScene.WestBorders.ToArray();
1031
1032 // Legacy one region. Provided for simplicity while testing the all inclusive method in the else statement.
1033 if (northBorders.Length <= 1 && southBorders.Length <= 1 && eastBorders.Length <= 1 && westBorders.Length <= 1)
1034 {
1035 return pScene.GridService.GetNeighbours(m_regionInfo.ScopeID, m_regionInfo.RegionID);
1036 }
1037 else
1038 {
1039 Vector2 extent = Vector2.Zero;
1040 for (int i = 0; i < eastBorders.Length; i++)
1041 {
1042 extent.X = (eastBorders[i].BorderLine.Z > extent.X) ? eastBorders[i].BorderLine.Z : extent.X;
1043 }
1044 for (int i = 0; i < northBorders.Length; i++)
1045 {
1046 extent.Y = (northBorders[i].BorderLine.Z > extent.Y) ? northBorders[i].BorderLine.Z : extent.Y;
1047 }
1048
1049 // Loss of fraction on purpose
1050 extent.X = ((int)extent.X / (int)Constants.RegionSize) + 1;
1051 extent.Y = ((int)extent.Y / (int)Constants.RegionSize) + 1;
1052
1053 int startX = (int)(pRegionLocX - 1) * (int)Constants.RegionSize;
1054 int startY = (int)(pRegionLocY - 1) * (int)Constants.RegionSize;
1055
1056 int endX = ((int)pRegionLocX + (int)extent.X) * (int)Constants.RegionSize;
1057 int endY = ((int)pRegionLocY + (int)extent.Y) * (int)Constants.RegionSize;
1058
1059 List<GridRegion> neighbours = pScene.GridService.GetRegionRange(m_regionInfo.ScopeID, startX, endX, startY, endY);
1060 neighbours.RemoveAll(delegate(GridRegion r) { return r.RegionID == m_regionInfo.RegionID; });
1061
1062 return neighbours;
1063 }
1064 }
1065
1066 private List<ulong> NewNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours)
1067 {
1068 return currentNeighbours.FindAll(delegate(ulong handle) { return !previousNeighbours.Contains(handle); });
1069 }
1070
1071 // private List<ulong> CommonNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours)
1072 // {
1073 // return currentNeighbours.FindAll(delegate(ulong handle) { return previousNeighbours.Contains(handle); });
1074 // }
1075
1076 private List<ulong> OldNeighbours(List<ulong> currentNeighbours, List<ulong> previousNeighbours)
1077 {
1078 return previousNeighbours.FindAll(delegate(ulong handle) { return !currentNeighbours.Contains(handle); });
1079 }
1080
1081 private List<ulong> NeighbourHandles(List<GridRegion> neighbours)
1082 {
1083 List<ulong> handles = new List<ulong>();
1084 foreach (GridRegion reg in neighbours)
1085 {
1086 handles.Add(reg.RegionHandle);
1087 }
1088 return handles;
1089 }
1090
1091 private void Dump(string msg, List<ulong> handles)
1092 {
1093 m_log.InfoFormat("-------------- HANDLE DUMP ({0}) ---------", msg);
1094 foreach (ulong handle in handles)
1095 {
1096 uint x, y;
1097 Utils.LongToUInts(handle, out x, out y);
1098 x = x / Constants.RegionSize;
1099 y = y / Constants.RegionSize;
1100 m_log.InfoFormat("({0}, {1})", x, y);
1101 }
1102 }
1103
1104 #endregion
1105
1106
1107 #region Agent Arrived
1108 public void AgentArrivedAtDestination(UUID id)
1109 {
1110 //m_log.Debug(" >>> ReleaseAgent called <<< ");
1111 ResetFromTransit(id);
1112 }
1113
1114 #endregion
1115
1116
1117 #region Misc
1118 protected bool IsOutsideRegion(Scene s, Vector3 pos)
1119 {
1120
1121 if (s.TestBorderCross(pos, Cardinals.N))
1122 return true;
1123 if (s.TestBorderCross(pos, Cardinals.S))
1124 return true;
1125 if (s.TestBorderCross(pos, Cardinals.E))
1126 return true;
1127 if (s.TestBorderCross(pos, Cardinals.W))
1128 return true;
1129
1130 return false;
1131 }
1132
1133 protected bool WaitForCallback(UUID id)
1134 {
1135 int count = 200;
1136 while (m_agentsInTransit.Contains(id) && count-- > 0)
1137 {
1138 //m_log.Debug(" >>> Waiting... " + count);
1139 Thread.Sleep(100);
1140 }
1141
1142 if (count > 0)
1143 return true;
1144 else
1145 return false;
1146 }
1147
1148 protected void SetInTransit(UUID id)
1149 {
1150 lock (m_agentsInTransit)
1151 {
1152 if (!m_agentsInTransit.Contains(id))
1153 m_agentsInTransit.Add(id);
1154 }
1155 }
1156
1157 protected bool ResetFromTransit(UUID id)
1158 {
1159 lock (m_agentsInTransit)
1160 {
1161 if (m_agentsInTransit.Contains(id))
1162 {
1163 m_agentsInTransit.Remove(id);
1164 return true;
1165 }
1166 }
1167 return false;
1168 }
1169
1170 protected void KillEntity(Scene scene, uint localID)
1171 {
1172 scene.SendKillObject(localID);
1173 }
1174
1175 protected virtual ulong GetRegionHandle(GridRegion region)
1176 {
1177 return region.RegionHandle;
1178 }
1179
1180 protected virtual bool NeedsClosing(uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY, GridRegion reg)
1181 {
1182 return Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY);
1183 }
1184
1185 #endregion
1186
1187 }
1188}
diff --git a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
index 1cc8ca9..f980c24 100644
--- a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
+++ b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
@@ -8,6 +8,7 @@
8 </Dependencies> 8 </Dependencies>
9 9
10 <Extension path = "/OpenSim/RegionModules"> 10 <Extension path = "/OpenSim/RegionModules">
11 <RegionModule id="AgentTransferModule" type="OpenSim.Region.CoreModules.Agent.AgentTransfer.AgentTransferModule" />
11 <RegionModule id="LandManagementModule" type="OpenSim.Region.CoreModules.World.Land.LandManagementModule" /> 12 <RegionModule id="LandManagementModule" type="OpenSim.Region.CoreModules.World.Land.LandManagementModule" />
12 <RegionModule id="ExportSerialisationModule" type="OpenSim.Region.CoreModules.World.Serialiser.SerialiserModule" /> 13 <RegionModule id="ExportSerialisationModule" type="OpenSim.Region.CoreModules.World.Serialiser.SerialiserModule" />
13 <RegionModule id="ArchiverModule" type="OpenSim.Region.CoreModules.World.Archiver.ArchiverModule" /> 14 <RegionModule id="ArchiverModule" type="OpenSim.Region.CoreModules.World.Archiver.ArchiverModule" />
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
index 592991b..fa705be 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
@@ -385,7 +385,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
385 385
386 private static Random random = new Random(); 386 private static Random random = new Random();
387 387
388 388 // From the command line link-region
389 public GridRegion TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, int xloc, int yloc) 389 public GridRegion TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, int xloc, int yloc)
390 { 390 {
391 string host = "127.0.0.1"; 391 string host = "127.0.0.1";
@@ -441,6 +441,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
441 return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0); 441 return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0);
442 } 442 }
443 443
444 // From the command line and the 2 above
444 public bool TryCreateLink(Scene m_scene, IClientAPI client, int xloc, int yloc, 445 public bool TryCreateLink(Scene m_scene, IClientAPI client, int xloc, int yloc,
445 string externalRegionName, uint externalPort, string externalHostName, out GridRegion regInfo) 446 string externalRegionName, uint externalPort, string externalHostName, out GridRegion regInfo)
446 { 447 {
@@ -572,6 +573,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
572 return TryLinkRegion((Scene)client.Scene, client, regionDescriptor); 573 return TryLinkRegion((Scene)client.Scene, client, regionDescriptor);
573 } 574 }
574 575
576 // From the map and secondlife://blah
575 public GridRegion GetHyperlinkRegion(ulong handle) 577 public GridRegion GetHyperlinkRegion(ulong handle)
576 { 578 {
577 foreach (GridRegion r in m_HyperlinkRegions.Values) 579 foreach (GridRegion r in m_HyperlinkRegions.Values)
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs
index a341f2f..f4383f1 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs
@@ -43,6 +43,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 private List<Scene> m_sceneList = new List<Scene>(); 44 private List<Scene> m_sceneList = new List<Scene>();
45 45
46 private IAgentTransferModule m_AgentTransferModule;
47 protected IAgentTransferModule AgentTransferModule
48 {
49 get
50 {
51 if (m_AgentTransferModule == null)
52 m_AgentTransferModule = m_sceneList[0].RequestModuleInterface<IAgentTransferModule>();
53 return m_AgentTransferModule;
54 }
55 }
56
46 private bool m_ModuleEnabled = false; 57 private bool m_ModuleEnabled = false;
47 58
48 #region IRegionModule 59 #region IRegionModule
@@ -247,8 +258,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
247 { 258 {
248 if (s.RegionInfo.RegionID == origin) 259 if (s.RegionInfo.RegionID == origin)
249 { 260 {
250 //m_log.Debug("[LOCAL COMMS]: Found region to SendReleaseAgent"); 261 m_log.Debug("[LOCAL COMMS]: Found region to SendReleaseAgent");
251 return s.IncomingReleaseAgent(id); 262 AgentTransferModule.AgentArrivedAtDestination(id);
263 return true;
264// return s.IncomingReleaseAgent(id);
252 } 265 }
253 } 266 }
254 //m_log.Debug("[LOCAL COMMS]: region not found in SendReleaseAgent " + origin); 267 //m_log.Debug("[LOCAL COMMS]: region not found in SendReleaseAgent " + origin);
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs
index be46fa5..42b4632 100644
--- a/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs
+++ b/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs
@@ -104,7 +104,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
104 if (info != null) regionInfos.Add(info); 104 if (info != null) regionInfos.Add(info);
105 } 105 }
106 106
107 if ((regionInfos.Count == 0) && IsHypergridOn()) 107 if ((regionInfos.Count == 0))
108 { 108 {
109 // OK, we tried but there are no regions matching that name. 109 // OK, we tried but there are no regions matching that name.
110 // Let's check quickly if this is a domain name, and if so link to it 110 // Let's check quickly if this is a domain name, and if so link to it
@@ -158,11 +158,6 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
158 remoteClient.SendMapBlock(blocks, 0); 158 remoteClient.SendMapBlock(blocks, 0);
159 } 159 }
160 160
161 private bool IsHypergridOn()
162 {
163 return (m_scene.SceneGridService is HGSceneCommunicationService);
164 }
165
166 private Scene GetClientScene(IClientAPI client) 161 private Scene GetClientScene(IClientAPI client)
167 { 162 {
168 foreach (Scene s in m_scenes) 163 foreach (Scene s in m_scenes)
diff --git a/OpenSim/Region/Framework/Interfaces/ITeleportModule.cs b/OpenSim/Region/Framework/Interfaces/IAgentTransferModule.cs
index 5f9129d..76745d6 100644
--- a/OpenSim/Region/Framework/Interfaces/ITeleportModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IAgentTransferModule.cs
@@ -26,16 +26,25 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using OpenSim.Services.Interfaces;
30using System.Text; 30using GridRegion = OpenSim.Services.Interfaces.GridRegion;
31
31using OpenMetaverse; 32using OpenMetaverse;
32using OpenSim.Region.Framework.Scenes; 33using OpenSim.Region.Framework.Scenes;
33 34
34namespace OpenSim.Region.Framework.Interfaces 35namespace OpenSim.Region.Framework.Interfaces
35{ 36{
36 public interface ITeleportModule 37 public interface IAgentTransferModule
37 { 38 {
38 void RequestTeleportToLocation(ScenePresence avatar, ulong regionHandle, Vector3 position, 39 void Teleport(ScenePresence agent, ulong regionHandle, Vector3 position,
39 Vector3 lookAt, uint teleportFlags); 40 Vector3 lookAt, uint teleportFlags);
41
42 void Cross(ScenePresence agent, bool isFlying);
43
44 void AgentArrivedAtDestination(UUID agent);
45
46 void EnableChildAgents(ScenePresence agent);
47
48 void EnableChildAgent(ScenePresence agent, GridRegion region);
40 } 49 }
41} 50}
diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs
deleted file mode 100644
index b27be80..0000000
--- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs
+++ /dev/null
@@ -1,387 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Net;
31using System.Reflection;
32using System.Threading;
33using log4net;
34using OpenMetaverse;
35using OpenSim.Framework;
36using OpenSim.Framework.Client;
37using OpenSim.Framework.Communications;
38using OpenSim.Framework.Capabilities;
39using OpenSim.Region.Framework.Interfaces;
40using OpenSim.Services.Interfaces;
41using GridRegion = OpenSim.Services.Interfaces.GridRegion;
42
43namespace OpenSim.Region.Framework.Scenes.Hypergrid
44{
45 public class HGSceneCommunicationService : SceneCommunicationService
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private IHyperlinkService m_hg;
50 IHyperlinkService HyperlinkService
51 {
52 get
53 {
54 if (m_hg == null)
55 m_hg = m_scene.RequestModuleInterface<IHyperlinkService>();
56 return m_hg;
57 }
58 }
59
60 public HGSceneCommunicationService() : base()
61 {
62 }
63
64
65 /// <summary>
66 /// Try to teleport an agent to a new region.
67 /// </summary>
68 /// <param name="remoteClient"></param>
69 /// <param name="RegionHandle"></param>
70 /// <param name="position"></param>
71 /// <param name="lookAt"></param>
72 /// <param name="flags"></param>
73 public override void RequestTeleportToLocation(ScenePresence avatar, ulong regionHandle, Vector3 position,
74 Vector3 lookAt, uint teleportFlags)
75 {
76 if (!avatar.Scene.Permissions.CanTeleport(avatar.UUID))
77 return;
78
79 bool destRegionUp = true;
80
81 IEventQueue eq = avatar.Scene.RequestModuleInterface<IEventQueue>();
82
83 // Reset animations; the viewer does that in teleports.
84 avatar.Animator.ResetAnimations();
85
86 if (regionHandle == m_regionInfo.RegionHandle)
87 {
88 // Teleport within the same region
89 if (IsOutsideRegion(avatar.Scene, position) || position.Z < 0)
90 {
91 Vector3 emergencyPos = new Vector3(128, 128, 128);
92
93 m_log.WarnFormat(
94 "[HGSceneCommService]: RequestTeleportToLocation() was given an illegal position of {0} for avatar {1}, {2}. Substituting {3}",
95 position, avatar.Name, avatar.UUID, emergencyPos);
96 position = emergencyPos;
97 }
98 // TODO: Get proper AVG Height
99 float localAVHeight = 1.56f;
100
101 float posZLimit = 22;
102
103 if (position.X > 0 && position.X <= (int)Constants.RegionSize && position.Y > 0 && position.Y <= (int)Constants.RegionSize)
104 {
105 posZLimit = (float) avatar.Scene.Heightmap[(int) position.X, (int) position.Y];
106 }
107
108 float newPosZ = posZLimit + localAVHeight;
109 if (posZLimit >= (position.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
110 {
111 position.Z = newPosZ;
112 }
113
114 // Only send this if the event queue is null
115 if (eq == null)
116 avatar.ControllingClient.SendTeleportLocationStart();
117
118
119 avatar.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags);
120 avatar.Teleport(position);
121 }
122 else
123 {
124 uint x = 0, y = 0;
125 Utils.LongToUInts(regionHandle, out x, out y);
126 GridRegion reg = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
127
128 if (reg != null)
129 {
130
131 uint newRegionX = (uint)(reg.RegionHandle >> 40);
132 uint newRegionY = (((uint)(reg.RegionHandle)) >> 8);
133 uint oldRegionX = (uint)(m_regionInfo.RegionHandle >> 40);
134 uint oldRegionY = (((uint)(m_regionInfo.RegionHandle)) >> 8);
135
136 ///
137 /// Hypergrid mod start
138 ///
139 ///
140 bool isHyperLink = (HyperlinkService.GetHyperlinkRegion(reg.RegionHandle) != null);
141 bool isHomeUser = true;
142 ulong realHandle = regionHandle;
143 isHomeUser = HyperlinkService.IsLocalUser(avatar.UUID);
144 realHandle = m_hg.FindRegionHandle(regionHandle);
145 m_log.Debug("XXX ---- home user? " + isHomeUser + " --- hyperlink? " + isHyperLink + " --- real handle: " + realHandle.ToString());
146 ///
147 /// Hypergrid mod stop
148 ///
149 ///
150
151 if (eq == null)
152 avatar.ControllingClient.SendTeleportLocationStart();
153
154
155 // Let's do DNS resolution only once in this process, please!
156 // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field,
157 // it's actually doing a lot of work.
158 IPEndPoint endPoint = reg.ExternalEndPoint;
159 if (endPoint.Address == null)
160 {
161 // Couldn't resolve the name. Can't TP, because the viewer wants IP addresses.
162 destRegionUp = false;
163 }
164
165 if (destRegionUp)
166 {
167 // Fixing a bug where teleporting while sitting results in the avatar ending up removed from
168 // both regions
169 if (avatar.ParentID != (uint)0)
170 avatar.StandUp();
171
172 if (!avatar.ValidateAttachments())
173 {
174 avatar.ControllingClient.SendTeleportFailed("Inconsistent attachment state");
175 return;
176 }
177
178 // the avatar.Close below will clear the child region list. We need this below for (possibly)
179 // closing the child agents, so save it here (we need a copy as it is Clear()-ed).
180 //List<ulong> childRegions = new List<ulong>(avatar.GetKnownRegionList());
181 // Compared to ScenePresence.CrossToNewRegion(), there's no obvious code to handle a teleport
182 // failure at this point (unlike a border crossing failure). So perhaps this can never fail
183 // once we reach here...
184 //avatar.Scene.RemoveCapsHandler(avatar.UUID);
185
186 string capsPath = String.Empty;
187 AgentCircuitData agentCircuit = avatar.ControllingClient.RequestClientInfo();
188 agentCircuit.BaseFolder = UUID.Zero;
189 agentCircuit.InventoryFolder = UUID.Zero;
190 agentCircuit.startpos = position;
191 agentCircuit.child = true;
192 agentCircuit.Appearance = avatar.Appearance;
193
194 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY))
195 {
196 // brand new agent, let's create a new caps seed
197 agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
198 }
199
200 string reason = String.Empty;
201
202 if (!m_scene.SimulationService.CreateAgent(reg, agentCircuit, teleportFlags, out reason))
203 {
204 avatar.ControllingClient.SendTeleportFailed(String.Format("Destination is not accepting teleports: {0}",
205 reason));
206 return;
207 }
208
209 // Let's close some agents
210 if (isHyperLink) // close them all except this one
211 {
212 List<ulong> regions = new List<ulong>(avatar.KnownChildRegionHandles);
213 regions.Remove(avatar.Scene.RegionInfo.RegionHandle);
214 SendCloseChildAgentConnections(avatar.UUID, regions);
215 }
216 else // close just a few
217 avatar.CloseChildAgents(newRegionX, newRegionY);
218
219 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY) || isHyperLink)
220 {
221 capsPath
222 = "http://"
223 + reg.ExternalHostName
224 + ":"
225 + reg.HttpPort
226 + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
227
228 if (eq != null)
229 {
230 #region IP Translation for NAT
231 IClientIPEndpoint ipepClient;
232 if (avatar.ClientView.TryGet(out ipepClient))
233 {
234 endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
235 }
236 #endregion
237
238 eq.EnableSimulator(realHandle, endPoint, avatar.UUID);
239
240 // ES makes the client send a UseCircuitCode message to the destination,
241 // which triggers a bunch of things there.
242 // So let's wait
243 Thread.Sleep(2000);
244
245 eq.EstablishAgentCommunication(avatar.UUID, endPoint, capsPath);
246 }
247 else
248 {
249 avatar.ControllingClient.InformClientOfNeighbour(realHandle, endPoint);
250 // TODO: make Event Queue disablable!
251 }
252 }
253 else
254 {
255 // child agent already there
256 agentCircuit.CapsPath = avatar.Scene.CapsModule.GetChildSeed(avatar.UUID, reg.RegionHandle);
257 capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort
258 + "/CAPS/" + agentCircuit.CapsPath + "0000/";
259 }
260
261 //m_commsProvider.InterRegion.ExpectAvatarCrossing(reg.RegionHandle, avatar.ControllingClient.AgentId,
262 // position, false);
263
264 //if (!m_commsProvider.InterRegion.ExpectAvatarCrossing(reg.RegionHandle, avatar.ControllingClient.AgentId,
265 // position, false))
266 //{
267 // avatar.ControllingClient.SendTeleportFailed("Problem with destination.");
268 // // We should close that agent we just created over at destination...
269 // List<ulong> lst = new List<ulong>();
270 // lst.Add(realHandle);
271 // SendCloseChildAgentAsync(avatar.UUID, lst);
272 // return;
273 //}
274
275 SetInTransit(avatar.UUID);
276 // Let's send a full update of the agent. This is a synchronous call.
277 AgentData agent = new AgentData();
278 avatar.CopyTo(agent);
279 agent.Position = position;
280 agent.CallbackURI = "http://" + m_regionInfo.ExternalHostName + ":" + m_regionInfo.HttpPort +
281 "/agent/" + avatar.UUID.ToString() + "/" + avatar.Scene.RegionInfo.RegionID.ToString() + "/release/";
282
283 m_scene.SimulationService.UpdateAgent(reg, agent);
284
285 m_log.DebugFormat(
286 "[CAPS]: Sending new CAPS seed url {0} to client {1}", capsPath, avatar.UUID);
287
288
289 ///
290 /// Hypergrid mod: realHandle instead of reg.RegionHandle
291 ///
292 ///
293 if (eq != null)
294 {
295 eq.TeleportFinishEvent(realHandle, 13, endPoint,
296 4, teleportFlags, capsPath, avatar.UUID);
297 }
298 else
299 {
300 avatar.ControllingClient.SendRegionTeleport(realHandle, 13, endPoint, 4,
301 teleportFlags, capsPath);
302 }
303 ///
304 /// Hypergrid mod stop
305 ///
306
307
308 // TeleportFinish makes the client send CompleteMovementIntoRegion (at the destination), which
309 // trigers a whole shebang of things there, including MakeRoot. So let's wait for confirmation
310 // that the client contacted the destination before we send the attachments and close things here.
311 if (!WaitForCallback(avatar.UUID))
312 {
313 // Client never contacted destination. Let's restore everything back
314 avatar.ControllingClient.SendTeleportFailed("Problems connecting to destination.");
315
316 ResetFromTransit(avatar.UUID);
317 // Yikes! We should just have a ref to scene here.
318 avatar.Scene.InformClientOfNeighbours(avatar);
319
320 // Finally, kill the agent we just created at the destination.
321 m_scene.SimulationService.CloseAgent(reg, avatar.UUID);
322 return;
323 }
324
325 // Can't go back from here
326 if (KiPrimitive != null)
327 {
328 KiPrimitive(avatar.LocalId);
329 }
330
331 avatar.MakeChildAgent();
332
333 // CrossAttachmentsIntoNewRegion is a synchronous call. We shouldn't need to wait after it
334 avatar.CrossAttachmentsIntoNewRegion(reg, true);
335
336
337 // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone
338 ///
339 /// Hypergrid mod: extra check for isHyperLink
340 ///
341 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY) || isHyperLink)
342 {
343 Thread.Sleep(5000);
344 avatar.Close();
345 CloseConnection(avatar.UUID);
346 }
347 // if (teleport success) // seems to be always success here
348 // the user may change their profile information in other region,
349 // so the userinfo in UserProfileCache is not reliable any more, delete it
350 if (avatar.Scene.NeedSceneCacheClear(avatar.UUID) || isHyperLink)
351 {
352 // REFACTORING PROBLEM!!!!
353 //m_commsProvider.UserProfileCacheService.RemoveUser(avatar.UUID);
354 m_log.DebugFormat(
355 "[HGSceneCommService]: User {0} is going to another region, profile cache removed",
356 avatar.UUID);
357 }
358 }
359 else
360 {
361 avatar.ControllingClient.SendTeleportFailed("Remote Region appears to be down");
362 }
363 }
364 else
365 {
366 // TP to a place that doesn't exist (anymore)
367 // Inform the viewer about that
368 avatar.ControllingClient.SendTeleportFailed("The region you tried to teleport to doesn't exist anymore");
369
370 // and set the map-tile to '(Offline)'
371 uint regX, regY;
372 Utils.LongToUInts(regionHandle, out regX, out regY);
373
374 MapBlockData block = new MapBlockData();
375 block.X = (ushort)(regX / Constants.RegionSize);
376 block.Y = (ushort)(regY / Constants.RegionSize);
377 block.Access = 254; // == not there
378
379 List<MapBlockData> blocks = new List<MapBlockData>();
380 blocks.Add(block);
381 avatar.ControllingClient.SendMapBlock(blocks, 0);
382 }
383 }
384 }
385
386 }
387}
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 48f0331..dcbbe08 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -315,7 +315,7 @@ namespace OpenSim.Region.Framework.Scenes
315 protected IConfigSource m_config; 315 protected IConfigSource m_config;
316 protected IRegionSerialiserModule m_serialiser; 316 protected IRegionSerialiserModule m_serialiser;
317 protected IDialogModule m_dialogModule; 317 protected IDialogModule m_dialogModule;
318 protected ITeleportModule m_teleportModule; 318 protected IAgentTransferModule m_teleportModule;
319 319
320 protected ICapabilitiesModule m_capsModule; 320 protected ICapabilitiesModule m_capsModule;
321 public ICapabilitiesModule CapsModule 321 public ICapabilitiesModule CapsModule
@@ -901,7 +901,7 @@ namespace OpenSim.Region.Framework.Scenes
901 regInfo.RegionName = otherRegion.RegionName; 901 regInfo.RegionName = otherRegion.RegionName;
902 regInfo.ScopeID = otherRegion.ScopeID; 902 regInfo.ScopeID = otherRegion.ScopeID;
903 regInfo.ExternalHostName = otherRegion.ExternalHostName; 903 regInfo.ExternalHostName = otherRegion.ExternalHostName;
904 904 GridRegion r = new GridRegion(regInfo);
905 try 905 try
906 { 906 {
907 ForEachScenePresence(delegate(ScenePresence agent) 907 ForEachScenePresence(delegate(ScenePresence agent)
@@ -915,7 +915,8 @@ namespace OpenSim.Region.Framework.Scenes
915 List<ulong> old = new List<ulong>(); 915 List<ulong> old = new List<ulong>();
916 old.Add(otherRegion.RegionHandle); 916 old.Add(otherRegion.RegionHandle);
917 agent.DropOldNeighbours(old); 917 agent.DropOldNeighbours(old);
918 InformClientOfNeighbor(agent, regInfo); 918 if (m_teleportModule != null)
919 m_teleportModule.EnableChildAgent(agent, r);
919 } 920 }
920 } 921 }
921 ); 922 );
@@ -1063,6 +1064,7 @@ namespace OpenSim.Region.Framework.Scenes
1063 { 1064 {
1064 foreach (RegionInfo region in m_regionRestartNotifyList) 1065 foreach (RegionInfo region in m_regionRestartNotifyList)
1065 { 1066 {
1067 GridRegion r = new GridRegion(region);
1066 try 1068 try
1067 { 1069 {
1068 ForEachScenePresence(delegate(ScenePresence agent) 1070 ForEachScenePresence(delegate(ScenePresence agent)
@@ -1070,9 +1072,8 @@ namespace OpenSim.Region.Framework.Scenes
1070 // If agent is a root agent. 1072 // If agent is a root agent.
1071 if (!agent.IsChildAgent) 1073 if (!agent.IsChildAgent)
1072 { 1074 {
1073 //agent.ControllingClient.new 1075 if (m_teleportModule != null)
1074 //this.CommsManager.InterRegion.InformRegionOfChildAgent(otherRegion.RegionHandle, agent.ControllingClient.RequestClientInfo()); 1076 m_teleportModule.EnableChildAgent(agent, r);
1075 InformClientOfNeighbor(agent, region);
1076 } 1077 }
1077 } 1078 }
1078 ); 1079 );
@@ -1217,7 +1218,7 @@ namespace OpenSim.Region.Framework.Scenes
1217 m_serialiser = RequestModuleInterface<IRegionSerialiserModule>(); 1218 m_serialiser = RequestModuleInterface<IRegionSerialiserModule>();
1218 m_dialogModule = RequestModuleInterface<IDialogModule>(); 1219 m_dialogModule = RequestModuleInterface<IDialogModule>();
1219 m_capsModule = RequestModuleInterface<ICapabilitiesModule>(); 1220 m_capsModule = RequestModuleInterface<ICapabilitiesModule>();
1220 m_teleportModule = RequestModuleInterface<ITeleportModule>(); 1221 m_teleportModule = RequestModuleInterface<IAgentTransferModule>();
1221 } 1222 }
1222 1223
1223 #endregion 1224 #endregion
@@ -3783,17 +3784,6 @@ namespace OpenSim.Region.Framework.Scenes
3783 return false; 3784 return false;
3784 } 3785 }
3785 3786
3786 public virtual bool IncomingReleaseAgent(UUID id)
3787 {
3788 return m_sceneGridService.ReleaseAgent(id);
3789 }
3790
3791 public void SendReleaseAgent(UUID origin, UUID id, string uri)
3792 {
3793 //m_interregionCommsOut.SendReleaseAgent(regionHandle, id, uri);
3794 SimulationService.ReleaseAgent(origin, id, uri);
3795 }
3796
3797 /// <summary> 3787 /// <summary>
3798 /// Tell a single agent to disconnect from the region. 3788 /// Tell a single agent to disconnect from the region.
3799 /// </summary> 3789 /// </summary>
@@ -3838,30 +3828,6 @@ namespace OpenSim.Region.Framework.Scenes
3838 } 3828 }
3839 3829
3840 /// <summary> 3830 /// <summary>
3841 /// Tell neighboring regions about this agent
3842 /// When the regions respond with a true value,
3843 /// tell the agents about the region.
3844 ///
3845 /// We have to tell the regions about the agents first otherwise it'll deny them access
3846 ///
3847 /// </summary>
3848 /// <param name="presence"></param>
3849 public void InformClientOfNeighbours(ScenePresence presence)
3850 {
3851 m_sceneGridService.EnableNeighbourChildAgents(presence, m_neighbours);
3852 }
3853
3854 /// <summary>
3855 /// Tell a neighboring region about this agent
3856 /// </summary>
3857 /// <param name="presence"></param>
3858 /// <param name="region"></param>
3859 public void InformClientOfNeighbor(ScenePresence presence, RegionInfo region)
3860 {
3861 m_sceneGridService.EnableNeighbourChildAgents(presence, m_neighbours);
3862 }
3863
3864 /// <summary>
3865 /// Tries to teleport agent to other region. 3831 /// Tries to teleport agent to other region.
3866 /// </summary> 3832 /// </summary>
3867 /// <param name="remoteClient"></param> 3833 /// <param name="remoteClient"></param>
@@ -3936,16 +3902,12 @@ namespace OpenSim.Region.Framework.Scenes
3936 } 3902 }
3937 3903
3938 if (m_teleportModule != null) 3904 if (m_teleportModule != null)
3939 { 3905 m_teleportModule.Teleport(sp, regionHandle, position, lookAt, teleportFlags);
3940 m_teleportModule.RequestTeleportToLocation(sp, regionHandle,
3941 position, lookAt, teleportFlags);
3942 }
3943 else 3906 else
3944 { 3907 {
3945 m_sceneGridService.RequestTeleportToLocation(sp, regionHandle, 3908 m_log.DebugFormat("[SCENE]: Unable to perform teleports: no AgentTransferModule is active");
3946 position, lookAt, teleportFlags); 3909 sp.ControllingClient.SendTeleportFailed("Unable to perform teleports on this simulator.");
3947 } 3910 }
3948
3949 } 3911 }
3950 } 3912 }
3951 3913
@@ -3971,7 +3933,12 @@ namespace OpenSim.Region.Framework.Scenes
3971 3933
3972 public void CrossAgentToNewRegion(ScenePresence agent, bool isFlying) 3934 public void CrossAgentToNewRegion(ScenePresence agent, bool isFlying)
3973 { 3935 {
3974 m_sceneGridService.CrossAgentToNewRegion(this, agent, isFlying); 3936 if (m_teleportModule != null)
3937 m_teleportModule.Cross(agent, isFlying);
3938 else
3939 {
3940 m_log.DebugFormat("[SCENE]: Unable to cross agent to neighbouring region, because there is no AgentTransferModule");
3941 }
3975 } 3942 }
3976 3943
3977 public void SendOutChildAgentUpdates(AgentPosition cadu, ScenePresence presence) 3944 public void SendOutChildAgentUpdates(AgentPosition cadu, ScenePresence presence)
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}
diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs
index c2e3370..6395d98 100644
--- a/OpenSim/Region/Framework/Scenes/SceneManager.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs
@@ -468,11 +468,11 @@ namespace OpenSim.Region.Framework.Scenes
468 return presences; 468 return presences;
469 } 469 }
470 470
471 public RegionInfo GetRegionInfo(ulong regionHandle) 471 public RegionInfo GetRegionInfo(UUID regionID)
472 { 472 {
473 foreach (Scene scene in m_localScenes) 473 foreach (Scene scene in m_localScenes)
474 { 474 {
475 if (scene.RegionInfo.RegionHandle == regionHandle) 475 if (scene.RegionInfo.RegionID == regionID)
476 { 476 {
477 return scene.RegionInfo; 477 return scene.RegionInfo;
478 } 478 }
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 4ead60c..711f9d9 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -1072,6 +1072,8 @@ namespace OpenSim.Region.Framework.Scenes
1072 /// </summary> 1072 /// </summary>
1073 public void CompleteMovement() 1073 public void CompleteMovement()
1074 { 1074 {
1075 //m_log.Debug("[SCENE PRESENCE]: CompleteMovement");
1076
1075 Vector3 look = Velocity; 1077 Vector3 look = Velocity;
1076 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) 1078 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
1077 { 1079 {
@@ -1096,7 +1098,7 @@ namespace OpenSim.Region.Framework.Scenes
1096 if ((m_callbackURI != null) && !m_callbackURI.Equals("")) 1098 if ((m_callbackURI != null) && !m_callbackURI.Equals(""))
1097 { 1099 {
1098 m_log.DebugFormat("[SCENE PRESENCE]: Releasing agent in URI {0}", m_callbackURI); 1100 m_log.DebugFormat("[SCENE PRESENCE]: Releasing agent in URI {0}", m_callbackURI);
1099 Scene.SendReleaseAgent(m_originRegionID, UUID, m_callbackURI); 1101 Scene.SimulationService.ReleaseAgent(m_originRegionID, UUID, m_callbackURI);
1100 m_callbackURI = null; 1102 m_callbackURI = null;
1101 } 1103 }
1102 1104
@@ -1104,6 +1106,17 @@ namespace OpenSim.Region.Framework.Scenes
1104 1106
1105 m_controllingClient.MoveAgentIntoRegion(m_regionInfo, AbsolutePosition, look); 1107 m_controllingClient.MoveAgentIntoRegion(m_regionInfo, AbsolutePosition, look);
1106 SendInitialData(); 1108 SendInitialData();
1109
1110 // Create child agents in neighbouring regions
1111 if (!m_isChildAgent)
1112 {
1113 IAgentTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IAgentTransferModule>();
1114 if (m_agentTransfer != null)
1115 m_agentTransfer.EnableChildAgents(this);
1116 else
1117 m_log.DebugFormat("[SCENE PRESENCE]: Unable to create child agents in neighbours, because AgentTransferModule is not active");
1118 }
1119
1107 } 1120 }
1108 1121
1109 /// <summary> 1122 /// <summary>
@@ -2156,6 +2169,7 @@ namespace OpenSim.Region.Framework.Scenes
2156 { 2169 {
2157 if (m_isChildAgent) 2170 if (m_isChildAgent)
2158 { 2171 {
2172 // WHAT???
2159 m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!"); 2173 m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!");
2160 2174
2161 // we have to reset the user's child agent connections. 2175 // we have to reset the user's child agent connections.
@@ -2179,7 +2193,9 @@ namespace OpenSim.Region.Framework.Scenes
2179 2193
2180 if (m_scene.SceneGridService != null) 2194 if (m_scene.SceneGridService != null)
2181 { 2195 {
2182 m_scene.SceneGridService.EnableNeighbourChildAgents(this, new List<RegionInfo>()); 2196 IAgentTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IAgentTransferModule>();
2197 if (m_agentTransfer != null)
2198 m_agentTransfer.EnableChildAgents(this);
2183 } 2199 }
2184 2200
2185 return; 2201 return;
@@ -2476,11 +2492,6 @@ namespace OpenSim.Region.Framework.Scenes
2476 m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId, 2492 m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId,
2477 pos, m_appearance.Texture.GetBytes(), m_parentID, m_bodyRot)); 2493 pos, m_appearance.Texture.GetBytes(), m_parentID, m_bodyRot));
2478 2494
2479 if (!m_isChildAgent)
2480 {
2481 m_scene.InformClientOfNeighbours(this);
2482 }
2483
2484 SendInitialFullUpdateToAllClients(); 2495 SendInitialFullUpdateToAllClients();
2485 SendAppearanceToAllOtherAgents(); 2496 SendAppearanceToAllOtherAgents();
2486 } 2497 }
diff --git a/bin/config-include/Grid.ini b/bin/config-include/Grid.ini
index 4892306..1a9ac72 100644
--- a/bin/config-include/Grid.ini
+++ b/bin/config-include/Grid.ini
@@ -17,6 +17,7 @@
17 PresenceServices = "RemotePresenceServicesConnector" 17 PresenceServices = "RemotePresenceServicesConnector"
18 UserAccountServices = "RemoteUserAccountServicesConnector" 18 UserAccountServices = "RemoteUserAccountServicesConnector"
19 SimulationServices = "RemoteSimulationConnectorModule" 19 SimulationServices = "RemoteSimulationConnectorModule"
20 AgentTransferModule = "AgentTransferModule"
20 LandServiceInConnector = true 21 LandServiceInConnector = true
21 NeighbourServiceInConnector = true 22 NeighbourServiceInConnector = true
22 SimulationServiceInConnector = true 23 SimulationServiceInConnector = true
diff --git a/bin/config-include/GridHypergrid.ini b/bin/config-include/GridHypergrid.ini
index 9077e73..1275a60 100644
--- a/bin/config-include/GridHypergrid.ini
+++ b/bin/config-include/GridHypergrid.ini
@@ -20,6 +20,7 @@
20 PresenceServices = "RemotePresenceServicesConnector" 20 PresenceServices = "RemotePresenceServicesConnector"
21 UserAccountServices = "RemoteUserAccountServicesConnector" 21 UserAccountServices = "RemoteUserAccountServicesConnector"
22 SimulationServices = "RemoteSimulationConnectorModule" 22 SimulationServices = "RemoteSimulationConnectorModule"
23 AgentTransferModule = "AgentTransferModule"
23 LandServiceInConnector = true 24 LandServiceInConnector = true
24 NeighbourServiceInConnector = true 25 NeighbourServiceInConnector = true
25 HypergridServiceInConnector = true 26 HypergridServiceInConnector = true
diff --git a/bin/config-include/Standalone.ini b/bin/config-include/Standalone.ini
index bf3237b..c9d483b 100644
--- a/bin/config-include/Standalone.ini
+++ b/bin/config-include/Standalone.ini
@@ -16,6 +16,7 @@
16 PresenceServices = "LocalPresenceServicesConnector" 16 PresenceServices = "LocalPresenceServicesConnector"
17 UserAccountServices = "LocalUserAccountServicesConnector" 17 UserAccountServices = "LocalUserAccountServicesConnector"
18 SimulationServices = "LocalSimulationConnectorModule" 18 SimulationServices = "LocalSimulationConnectorModule"
19 AgentTransferModule = "AgentTransferModule"
19 LibraryModule = true 20 LibraryModule = true
20 LLLoginServiceInConnector = true 21 LLLoginServiceInConnector = true
21 22
diff --git a/bin/config-include/StandaloneHypergrid.ini b/bin/config-include/StandaloneHypergrid.ini
index 682170c..20c5d10 100644
--- a/bin/config-include/StandaloneHypergrid.ini
+++ b/bin/config-include/StandaloneHypergrid.ini
@@ -19,7 +19,8 @@
19 PresenceServices = "LocalPresenceServicesConnector" 19 PresenceServices = "LocalPresenceServicesConnector"
20 UserAccountServices = "LocalUserAccountServicesConnector" 20 UserAccountServices = "LocalUserAccountServicesConnector"
21 SimulationServices = "RemoteSimulationConnectorModule" 21 SimulationServices = "RemoteSimulationConnectorModule"
22 AvatarServices = "LocalAvatarServicesConnector"; 22 AvatarServices = "LocalAvatarServicesConnector"
23 AgentTransferModule = "AgentTransferModule"
23 InventoryServiceInConnector = true 24 InventoryServiceInConnector = true
24 AssetServiceInConnector = true 25 AssetServiceInConnector = true
25 HGAuthServiceInConnector = true 26 HGAuthServiceInConnector = true