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