aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-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
5 files changed, 37 insertions, 1595 deletions
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 }