123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- using System;
- using System.Collections.Generic;
- using System.Net;
- using System.Reflection;
- using System.Threading;
- using log4net;
- using OpenMetaverse;
- using OpenSim.Framework;
- using OpenSim.Framework.Client;
- using OpenSim.Framework.Communications;
- using OpenSim.Framework.Communications.Cache;
- using OpenSim.Framework.Capabilities;
- using OpenSim.Region.Framework.Interfaces;
- namespace OpenSim.Region.Framework.Scenes.Hypergrid
- {
- public class HGSceneCommunicationService : SceneCommunicationService
- {
- private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- public readonly IHyperlink m_hg;
- public HGSceneCommunicationService(CommunicationsManager commsMan, IHyperlink hg) : base(commsMan)
- {
- m_hg = hg;
- }
-
-
-
-
-
-
-
-
- public override void RequestTeleportToLocation(ScenePresence avatar, ulong regionHandle, Vector3 position,
- Vector3 lookAt, uint teleportFlags)
- {
- if (!avatar.Scene.Permissions.CanTeleport(avatar.UUID))
- return;
- bool destRegionUp = true;
- IEventQueue eq = avatar.Scene.RequestModuleInterface<IEventQueue>();
-
- avatar.ResetAnimations();
- if (regionHandle == m_regionInfo.RegionHandle)
- {
-
- if (position.X < 0 || position.X > Constants.RegionSize || position.Y < 0 || position.Y > Constants.RegionSize || position.Z < 0)
- {
- Vector3 emergencyPos = new Vector3(128, 128, 128);
- m_log.WarnFormat(
- "[HGSceneCommService]: RequestTeleportToLocation() was given an illegal position of {0} for avatar {1}, {2}. Substituting {3}",
- position, avatar.Name, avatar.UUID, emergencyPos);
- position = emergencyPos;
- }
-
- float localAVHeight = 1.56f;
-
- float posZLimit = (float)avatar.Scene.Heightmap[(int)position.X, (int)position.Y];
- float newPosZ = posZLimit + localAVHeight;
- if (posZLimit >= (position.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
- {
- position.Z = newPosZ;
- }
-
- if (eq == null)
- avatar.ControllingClient.SendTeleportLocationStart();
- avatar.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags);
- avatar.Teleport(position);
- }
- else
- {
- RegionInfo reg = RequestNeighbouringRegionInfo(regionHandle);
- if (reg != null)
- {
- uint newRegionX = (uint)(reg.RegionHandle >> 40);
- uint newRegionY = (((uint)(reg.RegionHandle)) >> 8);
- uint oldRegionX = (uint)(m_regionInfo.RegionHandle >> 40);
- uint oldRegionY = (((uint)(m_regionInfo.RegionHandle)) >> 8);
-
-
-
-
- bool isHyperLink = m_hg.IsHyperlinkRegion(reg.RegionHandle);
- bool isHomeUser = true;
- ulong realHandle = regionHandle;
- CachedUserInfo uinfo = m_commsProvider.UserProfileCacheService.GetUserDetails(avatar.UUID);
- if (uinfo != null)
- {
- isHomeUser = HGNetworkServersInfo.Singleton.IsLocalUser(uinfo.UserProfile);
- realHandle = m_hg.FindRegionHandle(regionHandle);
- m_log.Debug("XXX ---- home user? " + isHomeUser + " --- hyperlink? " + isHyperLink + " --- real handle: " + realHandle.ToString());
- }
-
-
-
-
- if (eq == null)
- avatar.ControllingClient.SendTeleportLocationStart();
-
-
-
- IPEndPoint endPoint = reg.ExternalEndPoint;
- if (endPoint.Address == null)
- {
-
- destRegionUp = false;
- }
- if (destRegionUp)
- {
-
-
- if (avatar.ParentID != (uint)0)
- avatar.StandUp();
-
- if (!avatar.ValidateAttachments())
- {
- avatar.ControllingClient.SendTeleportFailed("Inconsistent attachment state");
- return;
- }
-
-
-
-
-
-
-
- string capsPath = String.Empty;
- AgentCircuitData agentCircuit = avatar.ControllingClient.RequestClientInfo();
- agentCircuit.BaseFolder = UUID.Zero;
- agentCircuit.InventoryFolder = UUID.Zero;
- agentCircuit.startpos = position;
- agentCircuit.child = true;
- if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY))
- {
-
- agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
- }
- string reason = String.Empty;
-
- if (!m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, agentCircuit, out reason))
- {
- avatar.ControllingClient.SendTeleportFailed(String.Format("Destination is not accepting teleports: {0}",
- reason));
- return;
- }
-
- if (isHyperLink)
- {
- List<ulong> regions = new List<ulong>(avatar.KnownChildRegionHandles);
- regions.Remove(avatar.Scene.RegionInfo.RegionHandle);
- SendCloseChildAgentConnections(avatar.UUID, regions);
- }
- else
- avatar.CloseChildAgents(newRegionX, newRegionY);
- if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY) || isHyperLink)
- {
- capsPath
- = "http://"
- + reg.ExternalHostName
- + ":"
- + reg.HttpPort
- + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
- if (eq != null)
- {
- #region IP Translation for NAT
- IClientIPEndpoint ipepClient;
- if (avatar.ClientView.TryGet(out ipepClient))
- {
- endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
- }
- #endregion
- eq.EnableSimulator(realHandle, endPoint, avatar.UUID);
-
-
-
- Thread.Sleep(2000);
- eq.EstablishAgentCommunication(avatar.UUID, endPoint, capsPath);
- }
- else
- {
- avatar.ControllingClient.InformClientOfNeighbour(realHandle, endPoint);
-
- }
- }
- else
- {
-
- agentCircuit.CapsPath = avatar.Scene.CapsModule.GetChildSeed(avatar.UUID, reg.RegionHandle);
- capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort
- + "/CAPS/" + agentCircuit.CapsPath + "0000/";
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- SetInTransit(avatar.UUID);
-
- AgentData agent = new AgentData();
- avatar.CopyTo(agent);
- agent.Position = position;
- agent.CallbackURI = "http://" + m_regionInfo.ExternalHostName + ":" + m_regionInfo.HttpPort +
- "/agent/" + avatar.UUID.ToString() + "/" + avatar.Scene.RegionInfo.RegionHandle.ToString() + "/release/";
- m_interregionCommsOut.SendChildAgentUpdate(reg.RegionHandle, agent);
- m_log.DebugFormat(
- "[CAPS]: Sending new CAPS seed url {0} to client {1}", agentCircuit.CapsPath, avatar.UUID);
-
-
-
-
- if (eq != null)
- {
- eq.TeleportFinishEvent(realHandle, 13, endPoint,
- 4, teleportFlags, capsPath, avatar.UUID);
- }
- else
- {
- avatar.ControllingClient.SendRegionTeleport(realHandle, 13, endPoint, 4,
- teleportFlags, capsPath);
- }
-
-
-
-
-
-
- if (!WaitForCallback(avatar.UUID))
- {
-
- avatar.ControllingClient.SendTeleportFailed("Problems connecting to destination.");
- ResetFromTransit(avatar.UUID);
-
- avatar.Scene.InformClientOfNeighbours(avatar);
-
- m_interregionCommsOut.SendCloseAgent(reg.RegionHandle, avatar.UUID);
- return;
- }
-
- if (KiPrimitive != null)
- {
- KiPrimitive(avatar.LocalId);
- }
- avatar.MakeChildAgent();
-
- avatar.CrossAttachmentsIntoNewRegion(reg.RegionHandle, true);
-
-
-
-
-
- if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY) || isHyperLink)
- {
- Thread.Sleep(5000);
- avatar.Close();
- CloseConnection(avatar.UUID);
- }
-
-
-
- if (avatar.Scene.NeedSceneCacheClear(avatar.UUID) || isHyperLink)
- {
- m_commsProvider.UserProfileCacheService.RemoveUser(avatar.UUID);
- m_log.DebugFormat(
- "[HGSceneCommService]: User {0} is going to another region, profile cache removed",
- avatar.UUID);
- }
- }
- else
- {
- avatar.ControllingClient.SendTeleportFailed("Remote Region appears to be down");
- }
- }
- else
- {
-
-
- avatar.ControllingClient.SendTeleportFailed("The region you tried to teleport to doesn't exist anymore");
-
- uint regX, regY;
- Utils.LongToUInts(regionHandle, out regX, out regY);
- MapBlockData block = new MapBlockData();
- block.X = (ushort)(regX / Constants.RegionSize);
- block.Y = (ushort)(regY / Constants.RegionSize);
- block.Access = 254;
- List<MapBlockData> blocks = new List<MapBlockData>();
- blocks.Add(block);
- avatar.ControllingClient.SendMapBlock(blocks, 0);
- }
- }
- }
- }
- }
|