Inheritance: AllScopeIDImpl
        public bool CreateAgent (GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out CreateAgentResponse response)
        {
            response = null;
            if (destination == null) {
                response = new CreateAgentResponse ();
                response.Reason = "Could not connect to destination";
                response.Success = false;
                return false;
            }
            CreateAgentRequest request = new CreateAgentRequest ();
            request.CircuitData = aCircuit;
            request.Destination = destination;
            request.TeleportFlags = teleportFlags;

            AutoResetEvent resetEvent = new AutoResetEvent (false);
            OSDMap result = null;
            MainConsole.Instance.DebugFormat ("[SimulationServiceConnector]: Sending Create Agent to " + destination.ServerURI);
            m_syncMessagePoster.Get (destination.ServerURI, request.ToOSD (), osdresp => {
                result = osdresp;
                resetEvent.Set ();
            });
            bool success = resetEvent.WaitOne (10000);
            if (!success || result == null) {
                response = new CreateAgentResponse ();
                response.Reason = "Could not connect to destination";
                response.Success = false;
                return false;
            }

            response = new CreateAgentResponse ();
            response.FromOSD (result);

            return response.Success;
        }
Esempio n. 2
0
        OSDMap GetRegion(OSDMap map)
        {
            OSDMap      resp       = new OSDMap();
            IRegionData regiondata = DataPlugins.RequestPlugin <IRegionData> ();

            if (regiondata != null && (map.ContainsKey("RegionID") || map.ContainsKey("Region")))
            {
                string regionName = map.ContainsKey("Region") ? map ["Region"].ToString().Trim() : "";
                UUID   regionID   = map.ContainsKey("RegionID") ? UUID.Parse(map ["RegionID"].ToString()) : UUID.Zero;
                // not used?? // UUID scopeID = map.ContainsKey ("ScopeID") ? UUID.Parse (map ["ScopeID"].ToString ()) : UUID.Zero;
                GridRegion region = null;
                if (regionID != UUID.Zero)
                {
                    region = regiondata.Get(regionID, null);
                }
                else if (regionName != string.Empty)
                {
                    region = regiondata.Get(regionName, null, null, null) [0];
                }
                if (region != null)
                {
                    resp ["Region"] = region.ToOSD();
                }
            }
            return(resp);
        }
        public virtual void InternalCross(IScenePresence agent, Vector3 attemptedPos, bool isFlying,
                                          GridRegion crossingRegion)
        {
            MainConsole.Instance.DebugFormat("[Entity transfer]: Crossing agent {0} to region {1}",
                                             agent.Name, crossingRegion.RegionName);

            try {
                agent.SetAgentLeaving(crossingRegion);

                AgentData cAgent = new AgentData();
                agent.CopyTo(cAgent);
                cAgent.Position = attemptedPos;
                if (isFlying)
                {
                    cAgent.ControlFlags |= (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;
                }

                AgentCircuitData agentCircuit = BuildCircuitDataForPresence(agent, attemptedPos);
                agentCircuit.TeleportFlags = (uint)TeleportFlags.ViaRegionID;

                //This does UpdateAgent and closing of child agents
                //  messages if they need to be called
                ISyncMessagePosterService syncPoster =
                    agent.Scene.RequestModuleInterface <ISyncMessagePosterService> ();
                if (syncPoster != null)
                {
                    syncPoster.PostToServer(SyncMessageHelper.CrossAgent(crossingRegion, attemptedPos,
                                                                         agent.Velocity, agentCircuit, cAgent,
                                                                         agent.Scene.RegionInfo.RegionID));
                }
            } catch (Exception ex) {
                MainConsole.Instance.Warn("[Entity transfer]: Exception in crossing: " + ex);
            }
        }
Esempio n. 4
0
 /// <summary>
 ///     Server side
 /// </summary>
 /// <param name="FunctionName"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 protected object OnGenericEvent(string FunctionName, object parameters)
 {
     if (FunctionName == "EstateUpdated")
     {
         EstateSettings            es = (EstateSettings)parameters;
         IEstateConnector          estateConnector = Framework.Utilities.DataManager.RequestPlugin <IEstateConnector>();
         ISyncMessagePosterService asyncPoster     =
             m_registry.RequestModuleInterface <ISyncMessagePosterService>();
         IGridService gridService = m_registry.RequestModuleInterface <IGridService>();
         if (estateConnector != null)
         {
             List <UUID> regions = estateConnector.GetRegions((int)es.EstateID);
             if (regions != null)
             {
                 foreach (UUID region in regions)
                 {
                     //Send the message to update all regions that are in this estate, as a setting changed
                     if (gridService != null && asyncPoster != null)
                     {
                         GridRegion r = gridService.GetRegionByUUID(null, region);
                         if (r != null)
                         {
                             asyncPoster.Post(r.ServerURI,
                                              SyncMessageHelper.UpdateEstateInfo(es.EstateID, region));
                         }
                     }
                 }
             }
         }
     }
     return(null);
 }
Esempio n. 5
0
        public void Close(IScene scene)
        {
            //Deregister the interface
            scene.UnregisterModuleInterface <IGridRegisterModule>(this);
            m_scene = null;

            MainConsole.Instance.InfoFormat("[RegisterRegionWithGrid]: Deregistering region {0} from the grid...",
                                            scene.RegionInfo.RegionName);

            //Deregister from the grid server
            GridRegion r = new GridRegion(scene.RegionInfo);

            r.IsOnline = false;
            string error = "";

            if (scene.RegionInfo.HasBeenDeleted || !m_markRegionsAsOffline)
            {
                scene.GridService.DeregisterRegion(r);
            }
            else if ((error = scene.GridService.UpdateMap(r, false)) != "")
            {
                MainConsole.Instance.WarnFormat(
                    "[RegisterRegionWithGrid]: Deregister from grid failed for region {0}, {1}",
                    scene.RegionInfo.RegionName, error);
            }
        }
        public virtual void Cross(IScenePresence agent, bool isFlying, GridRegion crossingRegion)
        {
            Vector3 pos = new Vector3(agent.AbsolutePosition.X, agent.AbsolutePosition.Y, agent.AbsolutePosition.Z);

            pos.X = (agent.Scene.RegionInfo.RegionLocX + pos.X) - crossingRegion.RegionLocX;
            pos.Y = (agent.Scene.RegionInfo.RegionLocY + pos.Y) - crossingRegion.RegionLocY;

            //Make sure that they are within bounds (velocity can push it out of bounds)
            if (pos.X < 0)
            {
                pos.X = 1;
            }
            if (pos.Y < 0)
            {
                pos.Y = 1;
            }

            if (pos.X > crossingRegion.RegionSizeX)
            {
                pos.X = crossingRegion.RegionSizeX - 1;
            }
            if (pos.Y > crossingRegion.RegionSizeY)
            {
                pos.Y = crossingRegion.RegionSizeY - 1;
            }
            InternalCross(agent, pos, isFlying, crossingRegion);
        }
        public void TrackAgent(IClientAPI client, UUID hunter, UUID target)
        {
            bool isFriend = IsFriendOfUser(target, hunter);

            if (isFriend)
            {
                IFriendsModule module = m_Scene.RequestModuleInterface <IFriendsModule>();
                if (module != null)
                {
                    int perms = module.GetFriendPerms(hunter, target);
                    if ((perms & (int)FriendRights.CanSeeOnMap) == (int)FriendRights.CanSeeOnMap)
                    {
                        UserInfo GUI =
                            client.Scene.RequestModuleInterface <IAgentInfoService>().GetUserInfo(target.ToString());
                        if (GUI != null && GUI.IsOnline)
                        {
                            GridRegion region = m_Scene.GridService.GetRegionByUUID(
                                client.AllScopeIDs, GUI.CurrentRegionID);

                            client.SendScriptTeleportRequest(client.Name, region.RegionName,
                                                             GUI.CurrentPosition,
                                                             GUI.CurrentLookAt);
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        protected MapBlockData MapBlockFromGridRegion(GridRegion r, int flag)
        {
            MapBlockData block = new MapBlockData();

            if (r == null)
            {
                block.Access     = (byte)SimAccess.Down;
                block.MapImageID = UUID.Zero;
                return(block);
            }
            block.Access = r.Access;
            if ((flag & 0xffff) == 0)
            {
                block.MapImageID = r.TerrainImage;
            }
            if ((flag & 0xffff) == 1)
            {
                block.MapImageID = r.TerrainMapImage;
            }
            if ((flag & 0xffff) == 2)
            {
                block.MapImageID = r.ParcelMapImage;
            }
            block.Name  = r.RegionName;
            block.X     = (ushort)(r.RegionLocX / Constants.RegionSize);
            block.Y     = (ushort)(r.RegionLocY / Constants.RegionSize);
            block.SizeX = (ushort)(r.RegionSizeX);
            block.SizeY = (ushort)(r.RegionSizeY);
            return(block);
        }
        /// <summary>
        ///     Tries to teleport agent to landmark.
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="position"></param>
        /// <param name="regionID"></param>
        public void RequestTeleportLandmark(IClientAPI remoteClient, UUID regionID, Vector3 position)
        {
            GridRegion info = null;

            try
            {
                info =
                    remoteClient.Scene.RequestModuleInterface <IGridService>()
                    .GetRegionByUUID(remoteClient.AllScopeIDs, regionID);
            }
            catch (Exception ex)
            {
                MainConsole.Instance.Warn("[EntityTransferModule]: Error finding landmark's region for user " +
                                          remoteClient.Name + ", " + ex);
            }
            if (info == null)
            {
                // can't find the region: Tell viewer and abort
                remoteClient.SendTeleportFailed("The teleport destination could not be found.");
                return;
            }

            RequestTeleportLocation(remoteClient, info, position, Vector3.Zero,
                                    (uint)(TeleportFlags.SetLastToTarget | TeleportFlags.ViaLandmark));
        }
Esempio n. 10
0
        public bool RetrieveAgent(GridRegion destination, UUID agentID, bool agentIsLeaving, out AgentData agentData,
                                  out AgentCircuitData circuitData)
        {
            agentData   = null;
            circuitData = null;

            RetrieveAgentRequest request = new RetrieveAgentRequest();

            request.AgentID        = agentID;
            request.Destination    = destination;
            request.AgentIsLeaving = agentIsLeaving;

            AutoResetEvent resetEvent = new AutoResetEvent(false);
            OSDMap         result     = null;

            m_syncMessagePoster.Get(destination.ServerURI, request.ToOSD(), (osdresp) =>
            {
                result = osdresp;
                resetEvent.Set();
            });
            bool success = resetEvent.WaitOne(10000);

            if (!success)
            {
                return(false);
            }

            RetrieveAgentResponse response = new RetrieveAgentResponse();

            response.FromOSD(result);

            circuitData = response.CircuitData;
            agentData   = response.AgentData;
            return(response.Success);
        }
        protected List <GridRegion> ParseQuery(List <UUID> scopeIDs, List <string> query)
        {
            List <GridRegion> regionData = new List <GridRegion>();

            if ((query.Count % 14) == 0)
            {
                for (int i = 0; i < query.Count; i += 14)
                {
                    GridRegion data = new GridRegion();
                    OSDMap     map  = (OSDMap)OSDParser.DeserializeJson(query[i + 13]);
                    map["owner_uuid"] = (!map.ContainsKey("owner_uuid") || map["owner_uuid"].AsUUID() == UUID.Zero)
                                            ? OSD.FromUUID(UUID.Parse(query[i + 6]))
                                            : map["owner_uuid"];
                    map["EstateOwner"] = (!map.ContainsKey("EstateOwner") || map["EstateOwner"].AsUUID() == UUID.Zero)
                                             ? OSD.FromUUID(UUID.Parse(query[i + 6]))
                                             : map["EstateOwner"];
                    data.FromOSD(map);

                    if (!regionData.Contains(data))
                    {
                        regionData.Add(data);
                    }
                }
            }

            return(AllScopeIDImpl.CheckScopeIDs(scopeIDs, regionData));
        }
        /// <summary>
        /// Agent-related communications
        /// </summary>
        public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out CreateAgentResponse response)
        {
            response = new CreateAgentResponse();
            IScene Scene = destination == null ? null : GetScene(destination.RegionID);
            if (destination == null || Scene == null)
            {
                response.Reason = "Given destination was null";
                response.Success = false;
                return false;
            }

            if (Scene.RegionInfo.RegionID != destination.RegionID)
            {
                response.Reason = "Did not find region " + destination.RegionName;;
                response.Success = false;
                return false;
            }
            IEntityTransferModule transferModule = Scene.RequestModuleInterface<IEntityTransferModule>();
            if (transferModule != null)
                return transferModule.NewUserConnection(Scene, aCircuit, teleportFlags, out response);

            response.Reason = "Did not find region " + destination.RegionName;
            response.Success = false;
            return false;
        }
Esempio n. 13
0
        /// <summary>
        /// Agent-related communications
        /// </summary>

        public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out CreateAgentResponse response)
        {
            response = new CreateAgentResponse();
            IScene Scene = destination == null ? null : GetScene(destination.RegionID);

            if (destination == null || Scene == null)
            {
                response.Reason  = "Given destination was null";
                response.Success = false;
                return(false);
            }

            if (Scene.RegionInfo.RegionID != destination.RegionID)
            {
                response.Reason  = "Did not find region " + destination.RegionName;;
                response.Success = false;
                return(false);
            }
            IEntityTransferModule transferModule = Scene.RequestModuleInterface <IEntityTransferModule>();

            if (transferModule != null)
            {
                return(transferModule.NewUserConnection(Scene, aCircuit, teleportFlags, out response));
            }

            response.Reason  = "Did not find region " + destination.RegionName;
            response.Success = false;
            return(false);
        }
        public virtual void Teleport(IScenePresence sp, GridRegion finalDestination, Vector3 position, Vector3 lookAt,
                                     uint teleportFlags)
        {
            sp.ControllingClient.SendTeleportStart(teleportFlags);
            sp.ControllingClient.SendTeleportProgress(teleportFlags, "requesting");

            // Reset animations; the viewer does that in teleports.
            if (sp.Animator != null)
            {
                sp.Animator.ResetAnimations();
            }

            try
            {
                string reason = "";
                if (finalDestination.RegionHandle == sp.Scene.RegionInfo.RegionHandle)
                {
                    //First check whether the user is allowed to move at all
                    if (!sp.Scene.Permissions.AllowedOutgoingLocalTeleport(sp.UUID, out reason))
                    {
                        sp.ControllingClient.SendTeleportFailed(reason);
                        return;
                    }
                    //Now respect things like parcel bans with this
                    if (
                        !sp.Scene.Permissions.AllowedIncomingTeleport(sp.UUID, position, teleportFlags, out position,
                                                                      out reason))
                    {
                        sp.ControllingClient.SendTeleportFailed(reason);
                        return;
                    }
                    MainConsole.Instance.DebugFormat(
                        "[ENTITY TRANSFER MODULE]: RequestTeleportToLocation {0} within {1}",
                        position, sp.Scene.RegionInfo.RegionName);

                    sp.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags);
                    sp.RequestModuleInterface <IScriptControllerModule>()
                    .HandleForceReleaseControls(sp.ControllingClient, sp.UUID);
                    sp.Teleport(position);
                }
                else // Another region possibly in another simulator
                {
                    // Make sure the user is allowed to leave this region
                    if (!sp.Scene.Permissions.AllowedOutgoingRemoteTeleport(sp.UUID, out reason))
                    {
                        sp.ControllingClient.SendTeleportFailed(reason);
                        return;
                    }

                    DoTeleport(sp, finalDestination, position, lookAt, teleportFlags);
                }
            }
            catch (Exception e)
            {
                MainConsole.Instance.ErrorFormat("[ENTITY TRANSFER MODULE]: Exception on teleport: {0}\n{1}", e.Message,
                                                 e.StackTrace);
                sp.ControllingClient.SendTeleportFailed("Internal error");
            }
        }
Esempio n. 15
0
        public virtual void CloseNeighborAgents(GridRegion oldRegion, GridRegion destination, UUID agentID)
        {
            CloseNeighborCall++;
            int CloseNeighborCallNum = CloseNeighborCall;
            Util.FireAndForget(delegate
            {
                //Sleep for 10 seconds to give the agents a chance to cross and get everything right
                Thread.Sleep(10000);
                if (CloseNeighborCall != CloseNeighborCallNum)
                    return; //Another was enqueued, kill this one

                //Now do a sanity check on the avatar
                IClientCapsService clientCaps = m_capsService.GetClientCapsService(agentID);

                if (clientCaps == null)
                    return;
                IRegionClientCapsService rootRegionCaps = clientCaps.GetRootCapsService();

                if (rootRegionCaps == null)
                    return;
                IRegionClientCapsService ourRegionCaps = clientCaps.GetCapsService(destination.RegionID);

                if (ourRegionCaps == null)
                    return;
                //If they handles aren't the same, the agent moved, and we can't be sure that we should close these agents
                if (rootRegionCaps.RegionHandle != ourRegionCaps.RegionHandle && !clientCaps.InTeleport)
                    return;

                IGridService service = m_registry.RequestModuleInterface<IGridService>();
                if (service != null)
                {
                    List<GridRegion> NeighborsOfOldRegion =
                        service.GetNeighbors(clientCaps.AccountInfo.AllScopeIDs, oldRegion);
                    List<GridRegion> NeighborsOfDestinationRegion =
                        service.GetNeighbors(clientCaps.AccountInfo.AllScopeIDs, destination);

                    List<GridRegion> byebyeRegions = new List<GridRegion>(NeighborsOfOldRegion)
                                                                                {oldRegion};
                    //Add the old region, because it might need closed too

                    byebyeRegions.RemoveAll(delegate (GridRegion r)
                    {
                        if (r.RegionID == destination.RegionID)
                            return true;

                        if (NeighborsOfDestinationRegion.Contains(r))
                            return true;
                        return false;
                    });

                    if (byebyeRegions.Count > 0)
                    {
                        MainConsole.Instance.Info("[Agent Processing]: Closing " + byebyeRegions.Count +
                                                  " child agents around " + oldRegion.RegionName);
                        SendCloseChildAgent(agentID, byebyeRegions);
                    }
                }
            });
        }
 public bool CloseAgent(GridRegion destination, UUID agentID)
 {
     CloseAgentRequest request = new CloseAgentRequest();
     request.AgentID = agentID;
     request.Destination = destination;
     m_syncMessagePoster.Post(destination.ServerURI, request.ToOSD());
     return true;
 }
 public override void FromOSD(OSDMap map)
 {
     AgentID     = map["AgentID"];
     Destination = new GridRegion();
     Destination.FromOSD((OSDMap)map["Destination"]);
     IsCrossing     = map["IsCrossing"];
     Reason         = map["Reason"];
     FailedRegionID = map["FailedRegionID"];
 }
Esempio n. 18
0
 /// <summary>
 ///     Define equality as two regions having the same, non-zero UUID.
 /// </summary>
 public bool Equals(GridRegion region)
 {
     if (region == null)
     {
         return(false);
     }
     // Return true if the non-zero UUIDs are equal:
     return((RegionID != UUID.Zero) && RegionID.Equals(region.RegionID));
 }
Esempio n. 19
0
        public bool CloseAgent(GridRegion destination, UUID agentID)
        {
            CloseAgentRequest request = new CloseAgentRequest();

            request.AgentID     = agentID;
            request.Destination = destination;
            m_syncMessagePoster.Post(destination.ServerURI, request.ToOSD());
            return(true);
        }
        public virtual void Teleport(IScenePresence sp, ulong regionHandle, Vector3 position, Vector3 lookAt,
                                     uint teleportFlags)
        {
            int x = 0, y = 0;

            Util.UlongToInts(regionHandle, out x, out y);

            GridRegion reg = sp.Scene.GridService.GetRegionByPosition(sp.ControllingClient.AllScopeIDs, x, y);

            if (reg == null)
            {
                List <GridRegion> regions = sp.Scene.GridService.GetRegionRange(
                    sp.ControllingClient.AllScopeIDs,
                    x - (sp.Scene.GridService.GetRegionViewSize() * sp.Scene.RegionInfo.RegionSizeX),
                    x + (sp.Scene.GridService.GetRegionViewSize() * sp.Scene.RegionInfo.RegionSizeX),
                    y - (sp.Scene.GridService.GetRegionViewSize() * sp.Scene.RegionInfo.RegionSizeY),
                    y + (sp.Scene.GridService.GetRegionViewSize() * sp.Scene.RegionInfo.RegionSizeY)
                    );
                foreach (GridRegion r in regions)
                {
                    if (r.RegionLocX <= x && r.RegionLocX + r.RegionSizeX > x &&
                        r.RegionLocY <= y && r.RegionLocY + r.RegionSizeY > y)
                    {
                        reg         = r;
                        position.X += x - reg.RegionLocX;
                        position.Y += y - reg.RegionLocY;
                        break;
                    }
                }
                if (reg == null)
                {
                    // TP to a place that doesn't exist (anymore)
                    // Inform the viewer about that
                    sp.ControllingClient.SendTeleportFailed("The region you tried to teleport to doesn't exist anymore");

                    // and set the map-tile to '(Offline)'
                    int regX, regY;
                    Util.UlongToInts(regionHandle, out regX, out regY);

                    MapBlockData block = new MapBlockData {
                        X      = (ushort)(regX / Constants.RegionSize),
                        Y      = (ushort)(regY / Constants.RegionSize),
                        Access = 254
                    };
                    // == not there

                    List <MapBlockData> blocks = new List <MapBlockData> {
                        block
                    };
                    sp.ControllingClient.SendMapBlock(blocks, 0);

                    return;
                }
            }
            Teleport(sp, reg, position, lookAt, teleportFlags);
        }
Esempio n. 21
0
        public bool UpdateAgent(GridRegion destination, AgentPosition data)
        {
            if (m_blackListedRegions.ContainsKey(destination.ServerURI))
            {
                //Check against time
                if (m_blackListedRegions[destination.ServerURI] > 3 &&
                    Util.EnvironmentTickCountSubtract(m_blackListedRegions[destination.ServerURI]) > 0)
                {
                    MainConsole.Instance.Warn("[Sim Service Connector]: Blacklisted region " + destination.RegionName +
                                              " requested");
                    //Still blacklisted
                    return(false);
                }
            }

            UpdateAgentPositionRequest request = new UpdateAgentPositionRequest();

            request.Update      = data;
            request.Destination = destination;

            AutoResetEvent resetEvent = new AutoResetEvent(false);
            OSDMap         result     = null;

            m_syncMessagePoster.Get(destination.ServerURI, request.ToOSD(), (response) =>
            {
                result = response;
                resetEvent.Set();
            });
            bool success = resetEvent.WaitOne(10000) && result != null;

            if (!success)
            {
                if (m_blackListedRegions.ContainsKey(destination.ServerURI))
                {
                    if (m_blackListedRegions[destination.ServerURI] == 3)
                    {
                        //add it to the blacklist as the request completely failed 3 times
                        m_blackListedRegions[destination.ServerURI] = Util.EnvironmentTickCount() + 60 * 1000; //60 seconds
                    }
                    else if (m_blackListedRegions[destination.ServerURI] == 0)
                    {
                        m_blackListedRegions[destination.ServerURI]++;
                    }
                }
                else
                {
                    m_blackListedRegions[destination.ServerURI] = 0;
                }
                return(false);
            }

            //Clear out the blacklist if it went through
            m_blackListedRegions.Remove(destination.ServerURI);

            return(result["Success"].AsBoolean());
        }
Esempio n. 22
0
        public bool FailedToMoveAgentIntoNewRegion(UUID AgentID, GridRegion destination)
        {
            FailedToMoveAgentIntoNewRegionRequest request = new FailedToMoveAgentIntoNewRegionRequest();

            request.AgentID  = AgentID;
            request.RegionID = destination.RegionID;

            m_syncMessagePoster.Post(destination.ServerURI, request.ToOSD());
            return(true);
        }
        /// <summary>
        ///     Tries to teleport agent to other region.
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="reg"></param>
        /// <param name="position"></param>
        /// <param name="lookAt"></param>
        /// <param name="teleportFlags"></param>
        public void RequestTeleportLocation(IClientAPI remoteClient, GridRegion reg, Vector3 position,
                                            Vector3 lookAt, uint teleportFlags)
        {
            IScenePresence sp = remoteClient.Scene.GetScenePresence(remoteClient.AgentId);

            if (sp != null)
            {
                Teleport(sp, reg, position, lookAt, teleportFlags);
            }
        }
        public bool CloseAgent(GridRegion destination, UUID agentID)
        {
            IScene Scene = destination == null ? null : GetScene(destination.RegionID);
            if (Scene == null || destination == null)
                return false;

            IEntityTransferModule transferModule = Scene.RequestModuleInterface<IEntityTransferModule>();
            if (transferModule != null)
                return transferModule.IncomingCloseAgent(Scene, agentID);
            return false;
        }
 public bool IsAuthorizedForRegion(GridRegion region, AgentCircuitData agent, bool isRootAgent, out string reason)
 {
     ISceneManager manager = m_registry.RequestModuleInterface<ISceneManager>();
     IScene scene = manager == null ? null : manager.Scenes.Find((s) => s.RegionInfo.RegionID == region.RegionID);
     if (scene != null)
     {
         //Found the region, check permissions
         return scene.Permissions.AllowedIncomingAgent(agent, isRootAgent, out reason);
     }
     reason = "Not Authorized as region does not exist.";
     return false;
 }
Esempio n. 26
0
        public bool MakeChildAgent(UUID AgentID, GridRegion oldRegion, GridRegion destination, bool isCrossing)
        {
            MakeChildAgentRequest request = new MakeChildAgentRequest();

            request.AgentID     = AgentID;
            request.OldRegion   = oldRegion;
            request.Destination = destination;
            request.IsCrossing  = isCrossing;

            m_syncMessagePoster.Post(oldRegion.ServerURI, request.ToOSD());
            return(true);
        }
        private void FillOutRegionData(AgentCircuitData circuitData, GridRegion destination)
        {
            IPEndPoint endPoint = destination.ExternalEndPoint;

            //We don't need this anymore, we set this from what we get from the region
            SimAddress  = endPoint.Address.ToString();
            SimPort     = (uint)circuitData.RegionUDPPort;
            RegionX     = (uint)destination.RegionLocX;
            RegionY     = (uint)destination.RegionLocY;
            RegionSizeX = destination.RegionSizeX;
            RegionSizeY = destination.RegionSizeY;
        }
        public void IncomingCapsRequest (UUID agentID, GridRegion region, ISimulationBase simbase, ref OSDMap capURLs)
        {
            m_syncMessage = simbase.ApplicationRegistry.RequestModuleInterface<ISyncMessagePosterService> ();
            m_appearanceService = simbase.ApplicationRegistry.RequestModuleInterface<IAgentAppearanceService> ();
            m_region = region;
            m_agentID = agentID;

            if (m_appearanceService == null)
                return;//Can't bake!
            
            m_uri = "/CAPS/UpdateAvatarAppearance/" + UUID.Random () + "/";
            MainServer.Instance.AddStreamHandler (new GenericStreamHandler ("POST", m_uri, UpdateAvatarAppearance));
            capURLs ["UpdateAvatarAppearance"] = MainServer.Instance.ServerURI + m_uri;
        }
Esempio n. 29
0
        public bool FailedToTeleportAgent(GridRegion destination, UUID failedRegionID, UUID AgentID, string reason,
                                          bool isCrossing)
        {
            FailedToTeleportAgentRequest request = new FailedToTeleportAgentRequest();

            request.AgentID        = AgentID;
            request.Destination    = destination;
            request.IsCrossing     = isCrossing;
            request.FailedRegionID = failedRegionID;
            request.Reason         = reason;

            m_syncMessagePoster.Post(destination.ServerURI, request.ToOSD());
            return(true);
        }
        public virtual bool TeleportHome(UUID id, IClientAPI client)
        {
            //MainConsole.Instance.DebugFormat[Entity transfer]r]: Request to teleport {0} {1} home", client.FirstName, client.LastName);

            UserInfo uinfo =
                client.Scene.RequestModuleInterface <IAgentInfoService> ().GetUserInfo(client.AgentId.ToString());

            if (uinfo != null)
            {
                GridRegion regionInfo = client.Scene.GridService.GetRegionByUUID(client.AllScopeIDs, uinfo.HomeRegionID);
                if (regionInfo == null)
                {
                    //can't find the Home region: Tell viewer and abort
                    client.SendTeleportFailed("Your home region could not be found.");
                    return(false);
                }
                MainConsole.Instance.DebugFormat("[Entity transfer]: User's home region is {0} {1} ({2}-{3})",
                                                 regionInfo.RegionName, regionInfo.RegionID,
                                                 regionInfo.RegionLocX / Constants.RegionSize,
                                                 regionInfo.RegionLocY / Constants.RegionSize);

                RequestTeleportLocation(
                    client, regionInfo, uinfo.HomePosition, uinfo.HomeLookAt,
                    (uint)(TeleportFlags.SetLastToTarget | TeleportFlags.ViaHome));
            }
            else
            {
                //Default region time...
                List <GridRegion> Regions = client.Scene.GridService.GetDefaultRegions(client.AllScopeIDs);
                if (Regions.Count != 0)
                {
                    MainConsole.Instance.DebugFormat("[Entity transfer]: User's home region was not found, using {0} {1} ({2}-{3})",
                                                     Regions [0].RegionName,
                                                     Regions [0].RegionID,
                                                     Regions [0].RegionLocX / Constants.RegionSize,
                                                     Regions [0].RegionLocY / Constants.RegionSize);

                    RequestTeleportLocation(
                        client, Regions [0], new Vector3(128, 128, 25), new Vector3(128, 128, 128),
                        (uint)(TeleportFlags.SetLastToTarget | TeleportFlags.ViaHome));
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
        public List <GridRegion> GetNeighbours(UUID regionID, List <UUID> scopeIDs, uint squareRangeFromCenterInMeters)
        {
            List <GridRegion> regions = new List <GridRegion>(0);
            GridRegion        region  = Get(regionID, scopeIDs);

            if (region != null)
            {
                int centerX = region.RegionLocX + (region.RegionSizeX / 2); // calculate center of region
                int centerY = region.RegionLocY + (region.RegionSizeY / 2); // calculate center of region

                regions = Get(scopeIDs, region.RegionID, centerX, centerY, squareRangeFromCenterInMeters);
            }

            return(regions);
        }
Esempio n. 32
0
        public void IncomingCapsRequest(UUID agentID, GridRegion region, ISimulationBase simbase, ref OSDMap capURLs)
        {
            m_syncMessage       = simbase.ApplicationRegistry.RequestModuleInterface <ISyncMessagePosterService> ();
            m_appearanceService = simbase.ApplicationRegistry.RequestModuleInterface <IAgentAppearanceService> ();
            m_region            = region;
            m_agentID           = agentID;

            if (m_appearanceService == null)
            {
                return;//Can't bake!
            }
            m_uri = "/CAPS/UpdateAvatarAppearance/" + UUID.Random() + "/";
            MainServer.Instance.AddStreamHandler(new GenericStreamHandler("POST", m_uri, UpdateAvatarAppearance));
            capURLs ["UpdateAvatarAppearance"] = MainServer.Instance.ServerURI + m_uri;
        }
        public OSDMap GetExternalCaps(UUID agentID, GridRegion region)
        {
            if (m_registry == null)
            {
                return(new OSDMap());
            }
            OSDMap resp = new OSDMap();

            if (m_registry.RequestModuleInterface <IGridServerInfoService>() != null)
            {
                m_servers = m_registry.RequestModuleInterface <IGridServerInfoService>().GetGridURIs("SyncMessageServerURI");
                OSDMap req = new OSDMap();
                req["AgentID"] = agentID;
                req["Region"]  = region.ToOSD();
                req["Method"]  = "GetCaps";

                List <ManualResetEvent> events = new List <ManualResetEvent>();
                foreach (string uri in m_servers.Where((u) => (!u.Contains(MainServer.Instance.Port.ToString()))))
                {
                    ManualResetEvent even = new ManualResetEvent(false);
                    m_syncPoster.Get(uri, req, (r) =>
                    {
                        if (r == null)
                        {
                            return;
                        }
                        foreach (KeyValuePair <string, OSD> kvp in r)
                        {
                            resp.Add(kvp.Key, kvp.Value);
                        }
                        even.Set();
                    });
                    events.Add(even);
                }
                if (events.Count > 0)
                {
                    ManualResetEvent.WaitAll(events.ToArray());
                }
            }
            foreach (var h in GetHandlers(agentID, region.RegionID))
            {
                if (m_allowedCapsModules.Contains(h.Name))
                {
                    h.IncomingCapsRequest(agentID, region, m_registry.RequestModuleInterface <ISimulationBase>(), ref resp);
                }
            }
            return(resp);
        }
        /// <summary>
        ///     Tries to teleport agent to other region.
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="regionName"></param>
        /// <param name="position"></param>
        /// <param name="lookat"></param>
        /// <param name="teleportFlags"></param>
        public void RequestTeleportLocation(IClientAPI remoteClient, string regionName, Vector3 position,
                                            Vector3 lookat, uint teleportFlags)
        {
            GridRegion regionInfo =
                remoteClient.Scene.RequestModuleInterface <IGridService>()
                .GetRegionByName(remoteClient.AllScopeIDs, regionName);

            if (regionInfo == null)
            {
                // can't find the region: Tell viewer and abort
                remoteClient.SendTeleportFailed("The region '" + regionName + "' could not be found.");
                return;
            }

            RequestTeleportLocation(remoteClient, regionInfo, position, lookat, teleportFlags);
        }
        private void FillOutHomeData(Framework.Services.UserInfo pinfo, GridRegion home)
        {
            int x = 1000 * Constants.RegionSize, y = 1000 * Constants.RegionSize;

            if (home != null)
            {
                x = home.RegionLocX;
                y = home.RegionLocY;
            }

            Home = string.Format(
                "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
                x,
                y,
                pinfo.HomePosition.X, pinfo.HomePosition.Y, pinfo.HomePosition.Z,
                pinfo.HomeLookAt.X, pinfo.HomeLookAt.Y, pinfo.HomeLookAt.Z);
        }
Esempio n. 36
0
        public bool CloseAgent(GridRegion destination, UUID agentID)
        {
            IScene Scene = destination == null ? null : GetScene(destination.RegionID);

            if (Scene == null || destination == null)
            {
                return(false);
            }

            IEntityTransferModule transferModule = Scene.RequestModuleInterface <IEntityTransferModule>();

            if (transferModule != null)
            {
                return(transferModule.IncomingCloseAgent(Scene, agentID));
            }
            return(false);
        }
        public LLLoginResponse(UserAccount account, AgentCircuitData aCircuit, Framework.Services.UserInfo pinfo,
                               GridRegion destination, List <InventoryFolderBase> invSkel, FriendInfo[] friendsList,
                               IInventoryService invService, ILibraryService libService,
                               string where, string startlocation, Vector3 position, Vector3 lookAt,
                               List <InventoryItemBase> gestures,
                               GridRegion home, IPEndPoint clientIP, string AdultMax, string AdultRating,
                               ArrayList eventValues, ArrayList eventNotificationValues, ArrayList classifiedValues,
                               string seedCap, IConfigSource source,
                               string DisplayName, string cofversion, IGridInfo info)
            : this()
        {
            m_source       = source;
            m_gridInfo     = info;
            SeedCapability = seedCap;

            FillOutInventoryData(invSkel, libService, invService);

            FillOutActiveGestures(gestures);

            CircuitCode          = (int)aCircuit.CircuitCode;
            Lastname             = account.LastName;
            Firstname            = account.FirstName;
            this.DisplayName     = DisplayName;
            AgentID              = account.PrincipalID;
            SessionID            = aCircuit.SessionID;
            SecureSessionID      = aCircuit.SecureSessionID;
            BuddList             = ConvertFriendListItem(friendsList);
            StartLocation        = where;
            AgentAccessMax       = AdultMax;
            AgentAccess          = AdultRating;
            AgentRegionAccess    = AgentRegionAccess;
            AOTransition         = AOTransition;
            AgentFlag            = AgentFlag;
            eventCategories      = eventValues;
            eventNotifications   = eventNotificationValues;
            classifiedCategories = classifiedValues;
            COFVersion           = cofversion;

            FillOutHomeData(pinfo, home);
            LookAt = string.Format("[r{0},r{1},r{2}]", lookAt.X, lookAt.Y, lookAt.Z);

            FillOutRegionData(aCircuit, destination);
            login        = "******";
            ErrorMessage = "";
            ErrorReason  = LoginResponseEnum.OK;
        }
Esempio n. 38
0
        public void IncomingCapsRequest (UUID agentID, GridRegion region, ISimulationBase simbase, ref OSDMap capURLs)
        {
            m_agentID = agentID;
            m_region = region;
            m_userScopeIDs = simbase.ApplicationRegistry.RequestModuleInterface<IUserAccountService> ().GetUserAccount (null, m_agentID).AllScopeIDs;

            m_gridService = simbase.ApplicationRegistry.RequestModuleInterface<IGridService> ();
            IConfig config = simbase.ConfigSource.Configs ["MapCAPS"];
            if (config != null)
                m_allowCapsMessage = config.GetBoolean ("AllowCapsMessage", m_allowCapsMessage);

            HttpServerHandle method = (path, request, httpRequest, httpResponse) => MapLayerRequest (HttpServerHandlerHelpers.ReadString (request), httpRequest, httpResponse);
            m_uri = "/CAPS/MapLayer/" + UUID.Random () + "/";
            capURLs ["MapLayer"] = MainServer.Instance.ServerURI + m_uri;
            capURLs ["MapLayerGod"] = MainServer.Instance.ServerURI + m_uri;

            MainServer.Instance.AddStreamHandler (new GenericStreamHandler ("POST", m_uri, method));
        }
        public void Close(IScene scene)
        {
            //Deregister the interface
            scene.UnregisterModuleInterface<IGridRegisterModule>(this);
            m_scene = null;

            MainConsole.Instance.InfoFormat("[RegisterRegionWithGrid]: Deregistering region {0} from the grid...",
                                            scene.RegionInfo.RegionName);

            //Deregister from the grid server
            GridRegion r = new GridRegion(scene.RegionInfo);
            r.IsOnline = false;
            string error = "";
            if (scene.RegionInfo.HasBeenDeleted || !m_markRegionsAsOffline)
                scene.GridService.DeregisterRegion(r);
            else if ((error = scene.GridService.UpdateMap(r, false)) != "")
                MainConsole.Instance.WarnFormat(
                    "[RegisterRegionWithGrid]: Deregister from grid failed for region {0}, {1}",
                    scene.RegionInfo.RegionName, error);
        }
        public OSDMap GetExternalCaps(UUID agentID, GridRegion region)
        {
            if (m_registry == null) return new OSDMap();
            OSDMap resp = new OSDMap();
            if (m_registry.RequestModuleInterface<IGridServerInfoService>() != null)
            {
                m_servers = m_registry.RequestModuleInterface<IGridServerInfoService>().GetGridURIs("SyncMessageServerURI");
                OSDMap req = new OSDMap();
                req["AgentID"] = agentID;
                req["Region"] = region.ToOSD();
                req["Method"] = "GetCaps";

                List<ManualResetEvent> events = new List<ManualResetEvent>();
                foreach (string uri in m_servers.Where((u)=>(!u.Contains(MainServer.Instance.Port.ToString()))))
                {
                    ManualResetEvent even = new ManualResetEvent(false);
                    m_syncPoster.Get(uri, req, (r) =>
                    {
                        if (r == null)
                            return;
                        foreach (KeyValuePair<string, OSD> kvp in r)
                            resp.Add(kvp.Key, kvp.Value);
                        even.Set();
                    });
                    events.Add(even);
                }
                if(events.Count > 0)
                    ManualResetEvent.WaitAll(events.ToArray());
            }
            foreach (var h in GetHandlers(agentID, region.RegionID))
            {
                if (m_allowedCapsModules.Contains(h.Name))
                    h.IncomingCapsRequest(agentID, region, m_registry.RequestModuleInterface<ISimulationBase>(), ref resp);
            }
            return resp;
        }
        public virtual void Cross (IScenePresence agent, bool isFlying, GridRegion crossingRegion)
        {
            Vector3 pos = new Vector3 (agent.AbsolutePosition.X, agent.AbsolutePosition.Y, agent.AbsolutePosition.Z);
            pos.X = (agent.Scene.RegionInfo.RegionLocX + pos.X) - crossingRegion.RegionLocX;
            pos.Y = (agent.Scene.RegionInfo.RegionLocY + pos.Y) - crossingRegion.RegionLocY;

            //Make sure that they are within bounds (velocity can push it out of bounds)
            if (pos.X < 0)
                pos.X = 1;
            if (pos.Y < 0)
                pos.Y = 1;

            if (pos.X > crossingRegion.RegionSizeX)
                pos.X = crossingRegion.RegionSizeX - 1;
            if (pos.Y > crossingRegion.RegionSizeY)
                pos.Y = crossingRegion.RegionSizeY - 1;
            InternalCross (agent, pos, isFlying, crossingRegion);
        }
        public void MakeChildAgent (IScenePresence sp, GridRegion finalDestination, bool isCrossing)
        {
            if (sp == null)
                return;

            sp.SetAgentLeaving (finalDestination);

            //Kill the groups here, otherwise they will become ghost attachments 
            //  and stay in the sim, they'll get re-added below into the new sim
            //KillAttachments(sp);

            // Well, this is it. The agent is over there.
            KillEntity (sp.Scene, sp);

            //Make it a child agent for now... the grid will kill us later if we need to close
            sp.MakeChildAgent (finalDestination);

            if (isCrossing)
                sp.SuccessfulCrossingTransit (finalDestination);
        }
 /// <summary>
 ///     Tries to teleport agent to other region.
 /// </summary>
 /// <param name="remoteClient"></param>
 /// <param name="reg"></param>
 /// <param name="position"></param>
 /// <param name="lookAt"></param>
 /// <param name="teleportFlags"></param>
 public void RequestTeleportLocation (IClientAPI remoteClient, GridRegion reg, Vector3 position,
                                     Vector3 lookAt, uint teleportFlags)
 {
     IScenePresence sp = remoteClient.Scene.GetScenePresence (remoteClient.AgentId);
     if (sp != null) {
         Teleport (sp, reg, position, lookAt, teleportFlags);
     }
 }
        public virtual void DoTeleport (IScenePresence sp, GridRegion finalDestination, Vector3 position, Vector3 lookAt,
                                       uint teleportFlags)
        {
            sp.ControllingClient.SendTeleportProgress (teleportFlags, "sending_dest");
            if (finalDestination == null) {
                sp.ControllingClient.SendTeleportFailed ("Unable to locate destination");
                return;
            }

            MainConsole.Instance.DebugFormat ("[Entity transfer]: Request Teleport to {0}:{1}/{2}",
                finalDestination.ServerURI, finalDestination.RegionName, position);

            sp.ControllingClient.SendTeleportProgress (teleportFlags, "arriving");
            sp.SetAgentLeaving (finalDestination);

            // Fixing a bug where teleporting while sitting results in the avatar ending up removed from
            // both regions
            if (sp.ParentID != UUID.Zero)
                sp.StandUp ();

            AgentCircuitData agentCircuit = BuildCircuitDataForPresence (sp, position);

            AgentData agent = new AgentData ();
            sp.CopyTo (agent);
            //Fix the position
            agent.Position = position;

            ISyncMessagePosterService syncPoster = sp.Scene.RequestModuleInterface<ISyncMessagePosterService> ();
            if (syncPoster != null) {
                //This does CreateAgent and sends the EnableSimulator/EstablishAgentCommunication/TeleportFinish
                //  messages if they need to be called and deals with the callback
                syncPoster.PostToServer (SyncMessageHelper.TeleportAgent ((int)sp.DrawDistance,
                                                                        agentCircuit, agent, teleportFlags,
                                                                        finalDestination, sp.Scene.RegionInfo.RegionID));
            }
        }
        public void FailedToTeleportAgent (GridRegion failedCrossingRegion, UUID agentID, string reason, bool isCrossing)
        {
            IScenePresence sp = m_scene.GetScenePresence (agentID);
            if (sp == null)
                return;

            sp.IsChildAgent = false;
            //Tell modules about it
            sp.AgentFailedToLeave ();
            sp.ControllingClient.SendTeleportFailed (reason);
            if (isCrossing)
                sp.FailedCrossingTransit (failedCrossingRegion);
        }
Esempio n. 46
0
        protected virtual OSDMap OnMessageReceived(OSDMap message)
        {
            if (!message.ContainsKey("Method"))
                return null;

            if (m_capsService == null)
                return null;

            string method = message["Method"].AsString();
            if (method != "RegionIsOnline" &&
                method != "LogoutRegionAgents" &&
                method != "ArrivedAtDestination" &&
                method != "CancelTeleport" &&
                method != "AgentLoggedOut" &&
                method != "SendChildAgentUpdate" &&
                method != "TeleportAgent" &&
                method != "CrossAgent")
                return null;

            UUID AgentID = message["AgentID"].AsUUID();
            UUID requestingRegion = message["RequestingRegion"].AsUUID();

            IClientCapsService clientCaps = m_capsService.GetClientCapsService(AgentID);

            IRegionClientCapsService regionCaps = null;
            if (clientCaps != null)
                regionCaps = clientCaps.GetCapsService(requestingRegion);

            if (method == "LogoutRegionAgents")
            {
                LogOutAllAgentsForRegion(requestingRegion);
            }
            else if (method == "RegionIsOnline")
            //This gets fired when the scene is fully finished starting up
            {
                //Log out all the agents first, then add any child agents that should be in this region
                //Don't do this, we don't need to kill all the clients right now
                IGridService GridService = m_registry.RequestModuleInterface<IGridService>();

                if (GridService != null)
                {
                    GridRegion requestingGridRegion = GridService.GetRegionByUUID(null, requestingRegion);
                    if (requestingGridRegion != null)
                        Util.FireAndForget(o => EnableChildAgentsForRegion(requestingGridRegion));
                }
            }
            else if (method == "ArrivedAtDestination")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                //Received a callback
                if (clientCaps.InTeleport) //Only set this if we are in a teleport,
                    //  otherwise (such as on login), this won't check after the first tp!
                    clientCaps.CallbackHasCome = true;

                regionCaps.Disabled = false;

                //The agent is getting here for the first time (eg. login)
                OSDMap body = ((OSDMap)message["Message"]);

                //Parse the OSDMap
                int DrawDistance = body["DrawDistance"].AsInteger();

                AgentCircuitData circuitData = new AgentCircuitData();
                circuitData.FromOSD((OSDMap)body["Circuit"]);

                //Now do the creation
                EnableChildAgents(AgentID, requestingRegion, DrawDistance, circuitData);
            }
            else if (method == "CancelTeleport")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                //Only the region the client is root in can do this
                IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService();
                if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle)
                {
                    //The user has requested to cancel the teleport, stop them.
                    clientCaps.RequestToCancelTeleport = true;
                    regionCaps.Disabled = false;
                }
            }
            else if (method == "AgentLoggedOut")
            {
                //ONLY if the agent is root do we even consider it
                if (regionCaps != null && regionCaps.RootAgent)
                {
                    OSDMap body = ((OSDMap)message["Message"]);

                    AgentPosition pos = new AgentPosition();
                    pos.FromOSD((OSDMap)body["AgentPos"]);

                    regionCaps.Disabled = true;

                    Util.FireAndForget(o =>
                    {
                        LogoutAgent(regionCaps, false); //The root is killing itself
                        SendChildAgentUpdate(pos, regionCaps);
                    });
                }
            }
            else if (method == "SendChildAgentUpdate")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService();

                if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle) //Has to be root
                {
                    OSDMap body = ((OSDMap)message["Message"]);

                    AgentPosition pos = new AgentPosition();
                    pos.FromOSD((OSDMap)body["AgentPos"]);

                    SendChildAgentUpdate(pos, regionCaps);
                    regionCaps.Disabled = false;
                }
            }
            else if (method == "TeleportAgent")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService();
                if (rootCaps != null && rootCaps.RegionHandle == regionCaps.RegionHandle)
                {
                    OSDMap body = ((OSDMap)message["Message"]);

                    GridRegion destination = new GridRegion();
                    destination.FromOSD((OSDMap)body["Region"]);

                    uint TeleportFlags = body["TeleportFlags"].AsUInteger();

                    AgentCircuitData Circuit = new AgentCircuitData();
                    Circuit.FromOSD((OSDMap)body["Circuit"]);

                    AgentData AgentData = new AgentData();
                    AgentData.FromOSD((OSDMap)body["AgentData"]);
                    regionCaps.Disabled = false;

                    //Don't need to wait for this to finish on the main http thread
                    Util.FireAndForget(o =>
                    {
                        string reason;
                        TeleportAgent(ref destination, TeleportFlags,
                            Circuit, AgentData, AgentID, requestingRegion, out reason);
                    });
                    return null;
                }
            }
            else if (method == "CrossAgent")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                IRegionClientCapsService rootCaps = clientCaps.GetRootCapsService();
                if (rootCaps == null || rootCaps.RegionHandle == regionCaps.RegionHandle)
                {
                    //This is a simulator message that tells us to cross the agent
                    OSDMap body = ((OSDMap)message["Message"]);

                    Vector3 pos = body["Pos"].AsVector3();
                    Vector3 Vel = body["Vel"].AsVector3();
                    GridRegion Region = new GridRegion();
                    Region.FromOSD((OSDMap)body["Region"]);
                    AgentCircuitData Circuit = new AgentCircuitData();
                    Circuit.FromOSD((OSDMap)body["Circuit"]);
                    AgentData AgentData = new AgentData();
                    AgentData.FromOSD((OSDMap)body["AgentData"]);
                    regionCaps.Disabled = false;

                    Util.FireAndForget(o =>
                    {
                        string reason;
                        CrossAgent(Region, pos, Vel, Circuit, AgentData,
                            AgentID, requestingRegion, out reason);
                    });

                    return null;
                }

                OSDMap result = new OSDMap();
                result["success"] = false;
                result["Note"] = false;
                return result;
            }

            return null;
        }
        public virtual void Teleport (IScenePresence sp, GridRegion finalDestination, Vector3 position, Vector3 lookAt,
                                     uint teleportFlags)
        {
            sp.ControllingClient.SendTeleportStart (teleportFlags);
            sp.ControllingClient.SendTeleportProgress (teleportFlags, "requesting");

            // Reset animations; the viewer does that in teleports.
            if (sp.Animator != null)
                sp.Animator.ResetAnimations ();

            try {
                string reason = "";
                if (finalDestination.RegionHandle == sp.Scene.RegionInfo.RegionHandle) {
                    //First check whether the user is allowed to move at all
                    if (!sp.Scene.Permissions.AllowedOutgoingLocalTeleport (sp.UUID, out reason)) {
                        sp.ControllingClient.SendTeleportFailed (reason);
                        return;
                    }
                    //Now respect things like parcel bans with this
                    if (
                        !sp.Scene.Permissions.AllowedIncomingTeleport (sp.UUID, position, teleportFlags, out position,
                                                                      out reason)) {
                        sp.ControllingClient.SendTeleportFailed (reason);
                        return;
                    }
                    MainConsole.Instance.DebugFormat ( "[Entity transfer]: RequestTeleportToLocation {0} within {1}",
                        position, sp.Scene.RegionInfo.RegionName);

                    sp.ControllingClient.SendLocalTeleport (position, lookAt, teleportFlags);
                    sp.RequestModuleInterface<IScriptControllerModule> ()
                      .HandleForceReleaseControls (sp.ControllingClient, sp.UUID);
                    sp.Teleport (position);
                } else // Another region possibly in another simulator
                  {
                    // Make sure the user is allowed to leave this region
                    if (!sp.Scene.Permissions.AllowedOutgoingRemoteTeleport (sp.UUID, out reason)) {
                        sp.ControllingClient.SendTeleportFailed (reason);
                        return;
                    }

                    DoTeleport (sp, finalDestination, position, lookAt, teleportFlags);
                }
            } catch (Exception e) {
                MainConsole.Instance.ErrorFormat ("[Entity transfer]: Exception on teleport: {0}\n{1}",
                                                  e.Message, e.StackTrace);
                sp.ControllingClient.SendTeleportFailed ("Internal error");
            }
        }
        public bool UpdateAgent(GridRegion destination, AgentPosition agentData)
        {
            IScene Scene = destination == null ? null : GetScene(destination.RegionID);
            if (Scene == null || destination == null)
                return false;

            //MainConsole.Instance.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate");
            IEntityTransferModule transferModule = Scene.RequestModuleInterface<IEntityTransferModule>();
            if (transferModule != null)
                return transferModule.IncomingChildAgentDataUpdate(Scene, agentData);

            return false;
        }
Esempio n. 49
0
        public virtual bool TeleportAgent(ref GridRegion destination, uint teleportFlags,
            AgentCircuitData circuit, AgentData agentData, UUID agentID,
            UUID requestingRegion,
            out string reason)
        {
            IClientCapsService clientCaps = m_capsService.GetClientCapsService(agentID);
            IRegionClientCapsService regionCaps = clientCaps.GetCapsService(requestingRegion);
            ISimulationService SimulationService = m_registry.RequestModuleInterface<ISimulationService>();

            if (regionCaps == null || !regionCaps.RootAgent)
            {
                reason = "";
                ResetFromTransit(agentID);
                return false;
            }

            bool result = false;
            try
            {
                bool callWasCanceled = false;

                if (SimulationService != null)
                {
                    //Set the user in transit so that we block duplicate tps and reset any cancelations
                    if (!SetUserInTransit(agentID))
                    {
                        reason = "Already in a teleport";
                        SimulationService.FailedToTeleportAgent(regionCaps.Region, destination.RegionID,
                                                                agentID, reason, false);
                        return false;
                    }

                    IGridService GridService = m_registry.RequestModuleInterface<IGridService>();
                    if (GridService != null)
                    {
                        //Inform the client of the neighbor if needed
                        circuit.IsChildAgent = false; //Force child status to the correct type
                        if (!InformClientOfNeighbor(agentID, requestingRegion, circuit, ref destination, teleportFlags,
                                                    agentData, out reason))
                        {
                            ResetFromTransit(agentID);
                            SimulationService.FailedToTeleportAgent(regionCaps.Region, destination.RegionID,
                                                                    agentID, reason, false);
                            return false;
                        }
                    }
                    else
                    {
                        reason = "Could not find the grid service";
                        ResetFromTransit(agentID);
                        SimulationService.FailedToTeleportAgent(regionCaps.Region, destination.RegionID,
                                                                agentID, reason, false);
                        return false;
                    }

                    IEventQueueService EQService = m_registry.RequestModuleInterface<IEventQueueService>();

                    IRegionClientCapsService otherRegion = clientCaps.GetCapsService(destination.RegionID);

                    EQService.TeleportFinishEvent(destination.RegionHandle, destination.Access,
                                                  otherRegion.LoopbackRegionIP,
                                                  otherRegion.CircuitData.RegionUDPPort,
                                                  otherRegion.CapsUrl,
                                                  4, agentID, teleportFlags,
                                                  destination.RegionSizeX, destination.RegionSizeY,
                                                  otherRegion.Region.RegionID);

                    // TeleportFinish makes the client send CompleteMovementIntoRegion (at the destination), which
                    // triggers a whole shebang of things there, including MakeRoot. So let's wait for confirmation
                    // that the client contacted the destination before we send the attachments and close things here.

                    result = WaitForCallback(agentID, out callWasCanceled);
                    if (!result)
                    {
                        reason = !callWasCanceled ? "The teleport timed out" : "Cancelled";
                        if (!callWasCanceled)
                        {
                            MainConsole.Instance.Warn("[Agent Processing]: Callback never came for teleporting agent " +
                                                      agentID + ". Resetting.");
                            //Tell the region about it as well
                            SimulationService.FailedToTeleportAgent(regionCaps.Region, destination.RegionID, agentID, reason, false);
                        }
                        //Close the agent at the place we just created if it isn't a neighbor
                        {
                            SimulationService.CloseAgent(destination, agentID);
                            clientCaps.RemoveCAPS(destination.RegionID);
                        }
                    }
                    else
                    {
                        //Fix the root agent status
                        otherRegion.RootAgent = true;
                        regionCaps.RootAgent = false;

                        // Next, let's close the child agent connections that are too far away
                        //Why? OpenSim regions need closed too, even if the protocol is kind of stupid
                        CloseNeighborAgents(regionCaps.Region, destination, agentID);
                        IAgentInfoService agentInfoService = m_registry.RequestModuleInterface<IAgentInfoService>();
                        if (agentInfoService != null)
                            agentInfoService.SetLastPosition(agentID.ToString(), destination.RegionID,
                                                             agentData.Position, Vector3.Zero, destination.ServerURI);

                        SimulationService.MakeChildAgent(agentID, regionCaps.Region, destination, false);
                        reason = "";
                    }
                }
                else
                    reason = "No SimulationService found!";
            }
            catch (Exception ex)
            {
                MainConsole.Instance.WarnFormat("[Agent Processing]: Exception occurred during agent teleport, {0}", ex);
                reason = "Exception occurred.";

                if (SimulationService != null)
                    SimulationService.FailedToTeleportAgent(regionCaps.Region, destination.RegionID, agentID, reason, false);
            }
            //All done
            ResetFromTransit(agentID);
            return result;
        }
Esempio n. 50
0
        public virtual LoginAgentArgs LoginAgent(GridRegion region, AgentCircuitData aCircuit, List<UUID> friendsToInform)
        {
            bool success = false;
            string seedCap = "";
            string reason = "Could not find the simulation service";
            ISimulationService SimulationService = m_registry.RequestModuleInterface<ISimulationService>();

            if (SimulationService != null)
            {
                // The client is in the region, we need to make sure it gets the right Caps
                // If CreateAgent is successful, it passes back a OSDMap of parameters that the client
                //    wants to inform us about, and it includes the Caps SEED url for the region
                IRegionClientCapsService regionClientCaps = null;
                IClientCapsService clientCaps = null;

                //?? if we do not have a capservice then probably we should not allow logins??
                // - greythane - 20160411
                if (m_capsService != null)
                {
                    //Remove any previous users
                    seedCap = m_capsService.CreateCAPS(aCircuit.AgentID,
                                                       CapsUtil.GetCapsSeedPath(CapsUtil.GetRandomCapsObjectPath()),
                                                       region.RegionID, true, aCircuit, 0);

                    clientCaps = m_capsService.GetClientCapsService(aCircuit.AgentID);
                    regionClientCaps = clientCaps.GetCapsService(region.RegionID);
                }

                int requestedUDPPort = 0;
                CreateAgentResponse createAgentResponse;
                // As we are creating the agent, we must also initialize the CapsService for the agent
                success = CreateAgent(region, regionClientCaps, ref aCircuit, SimulationService, friendsToInform,
                                      out createAgentResponse);

                reason = createAgentResponse.Reason;

                if (!success) // If it failed, do not set up any CapsService for the client
                {
                    //Delete the Caps!
                    IAgentProcessing agentProcessor = m_registry.RequestModuleInterface<IAgentProcessing>();

                    if (agentProcessor != null && m_capsService != null)
                        agentProcessor.LogoutAgent(regionClientCaps, true);
                    else if (m_capsService != null)
                        m_capsService.RemoveCAPS(aCircuit.AgentID);
                    return new LoginAgentArgs
                    {
                        Success = success,
                        CircuitData = aCircuit,
                        Reason = reason,
                        SeedCap = seedCap
                    };
                }

                requestedUDPPort = createAgentResponse.RequestedUDPPort;

                if (requestedUDPPort == 0)
                    requestedUDPPort = region.ExternalEndPoint.Port;
                aCircuit.RegionUDPPort = requestedUDPPort;

                IPAddress ipAddress = regionClientCaps.Region.ExternalEndPoint.Address;

                if (m_capsService != null)
                {
                    //If the region accepted us, we should get a CAPS url back as the reason, if not, its not updated or not an Virtual Universe region, so don't touch it.
                    string ip = createAgentResponse.OurIPForClient;
                    if (!IPAddress.TryParse(ip, out ipAddress))
            #pragma warning disable 618
                        ipAddress = Dns.GetHostByName(ip).AddressList[0];
            #pragma warning restore 618
                    region.ExternalEndPoint.Address = ipAddress;
                    //Fix this so that it gets sent to the client that way
                    regionClientCaps.AddCAPS(createAgentResponse.CapsURIs);
                    regionClientCaps = clientCaps.GetCapsService(region.RegionID);

                    if (regionClientCaps != null)
                    {
                        regionClientCaps.LoopbackRegionIP = ipAddress;
                        regionClientCaps.CircuitData.RegionUDPPort = requestedUDPPort;
                        regionClientCaps.RootAgent = true;
                    }
                    else
                    {
                        success = false;
                        reason = "Timeout error";
                    }
                }
            }
            else
                MainConsole.Instance.ErrorFormat("[Agent Processing]: No simulation service found! Could not log in user!");

            return new LoginAgentArgs { Success = success, CircuitData = aCircuit, Reason = reason, SeedCap = seedCap };
        }
Esempio n. 51
0
        /// <summary>
        ///     Async component for informing client of which neighbors exist
        /// </summary>
        /// <remarks>
        ///     This needs to run asynchronously, as a network timeout may block the thread for a long while
        /// </remarks>
        /// <param name="agentID"></param>
        /// <param name="requestingRegion"></param>
        /// <param name="circuitData"></param>
        /// <param name="neighbor"></param>
        /// <param name="teleportFlags"></param>
        /// <param name="agentData"></param>
        /// <param name="reason"></param>
        public virtual bool InformClientOfNeighbor(UUID agentID, UUID requestingRegion, AgentCircuitData circuitData,
            ref GridRegion neighbor,
            uint teleportFlags, AgentData agentData, out string reason)
        {
            if (neighbor == null || neighbor.RegionHandle == 0)
            {
                reason = "Could not find neighbor to inform";
                return false;
            }

            MainConsole.Instance.Info("[Agent Processing]: Starting to inform client about neighbor " + neighbor.RegionName);

            //Notes on this method
            // 1) the SimulationService.CreateAgent MUST have a fixed CapsUrl for the region, so we have to create (if needed)
            //       a new Caps handler for it.
            // 2) Then we can call the methods (EnableSimulator and EstatablishAgentComm) to tell the client the new Urls
            // 3) This allows us to make the Caps on the grid server without telling any other regions about what the
            //       Urls are.

            ISimulationService SimulationService = m_registry.RequestModuleInterface<ISimulationService>();
            if (SimulationService != null)
            {
                IClientCapsService clientCaps = m_capsService.GetClientCapsService(agentID);

                IRegionClientCapsService oldRegionService = clientCaps.GetCapsService(neighbor.RegionID);

                //If its disabled, it should be removed, so kill it!
                if (oldRegionService != null && oldRegionService.Disabled)
                {
                    clientCaps.RemoveCAPS(neighbor.RegionID);
                    oldRegionService = null;
                }

                bool newAgent = oldRegionService == null;
                IRegionClientCapsService otherRegionService =
                    clientCaps.GetOrCreateCapsService(neighbor.RegionID,
                                                      CapsUtil.GetCapsSeedPath
                                                      (CapsUtil.GetRandomCapsObjectPath()),
                                                      circuitData, 0);

                if (!newAgent)
                {
                    //Note: if the agent is already there, send an agent update then
                    bool result = true;
                    if (agentData != null)
                    {
                        agentData.IsCrossing = false;
                        result = SimulationService.UpdateAgent(neighbor, agentData);
                    }

                    if (result)
                        oldRegionService.Disabled = false;
                    else
                    {
                        clientCaps.RemoveCAPS(neighbor.RegionID);//Kill the bad client!
                    }

                    reason = "";
                    return result;
                }

                int requestedPort = 0;
                CreateAgentResponse createAgentResponse;
                bool regionAccepted = CreateAgent(neighbor,
                                                  otherRegionService,
                                                  ref circuitData,
                                                  SimulationService,
                                                  new List<UUID>(),
                                                  out createAgentResponse);
                reason = createAgentResponse.Reason;
                if (regionAccepted)
                {
                    IPAddress ipAddress = neighbor.ExternalEndPoint.Address;
                    //If the region accepted us, we should get a CAPS url back as the reason, if not, its not updated or not a Virtual Universe region, so don't touch it.
                    string ip = createAgentResponse.OurIPForClient;
                    if (!IPAddress.TryParse(ip, out ipAddress))
            #pragma warning disable 618
                        ipAddress = Dns.GetHostByName(ip).AddressList[0];
            #pragma warning restore 618
                    otherRegionService.AddCAPS(createAgentResponse.CapsURIs);

                    if (ipAddress == null)
                        ipAddress = neighbor.ExternalEndPoint.Address;
                    if (requestedPort == 0)
                        requestedPort = neighbor.ExternalEndPoint.Port;
                    otherRegionService = clientCaps.GetCapsService(neighbor.RegionID);
                    otherRegionService.LoopbackRegionIP = ipAddress;
                    otherRegionService.CircuitData.RegionUDPPort = requestedPort;
                    circuitData.RegionUDPPort = requestedPort; //Fix the port

                    IEventQueueService EQService = m_registry.RequestModuleInterface<IEventQueueService>();

                    EQService.EnableSimulator(neighbor.RegionHandle,
                                              ipAddress.GetAddressBytes(),
                                              requestedPort, agentID,
                                              neighbor.RegionSizeX, neighbor.RegionSizeY, requestingRegion);

                    // EnableSimulator makes the client send a UseCircuitCode message to the destination,
                    // which triggers a bunch of things there.
                    // So let's wait
                    Thread.Sleep(300);
                    EQService.EstablishAgentCommunication(agentID, neighbor.RegionHandle,
                                                          ipAddress.GetAddressBytes(),
                                                          requestedPort, otherRegionService.CapsUrl,
                                                          neighbor.RegionSizeX,
                                                          neighbor.RegionSizeY,
                                                          requestingRegion);

                    MainConsole.Instance.Info("[Agent Processing]: Completed inform client about neighbor " +
                                              neighbor.RegionName);
                }
                else
                {
                    clientCaps.RemoveCAPS(neighbor.RegionID);
                    reason = "Could not contact simulator";
                    MainConsole.Instance.Error("[Agent Processing]: Failed to inform client about neighbor " +
                                               neighbor.RegionName +
                                               ", reason: " + reason);
                    return false;
                }
                return true;
            }
            reason = "SimulationService does not exist";
            MainConsole.Instance.Error("[Agent Processing]: Failed to inform client about neighbor " +
                                       neighbor.RegionName +
                                       ", reason: " + reason + "!");
            return false;
        }
        public virtual void InternalCross (IScenePresence agent, Vector3 attemptedPos, bool isFlying,
                                          GridRegion crossingRegion)
        {
            MainConsole.Instance.DebugFormat ("[Entity transfer]: Crossing agent {0} to region {1}",
                                              agent.Name, crossingRegion.RegionName);

            try {
                agent.SetAgentLeaving (crossingRegion);

                AgentData cAgent = new AgentData ();
                agent.CopyTo (cAgent);
                cAgent.Position = attemptedPos;
                if (isFlying)
                    cAgent.ControlFlags |= (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;

                AgentCircuitData agentCircuit = BuildCircuitDataForPresence (agent, attemptedPos);
                agentCircuit.TeleportFlags = (uint)TeleportFlags.ViaRegionID;

                //This does UpdateAgent and closing of child agents
                //  messages if they need to be called
                ISyncMessagePosterService syncPoster =
                    agent.Scene.RequestModuleInterface<ISyncMessagePosterService> ();
                if (syncPoster != null) {
                    syncPoster.PostToServer (SyncMessageHelper.CrossAgent (crossingRegion, attemptedPos,
                                                                         agent.Velocity, agentCircuit, cAgent,
                                                                         agent.Scene.RegionInfo.RegionID));
                }
            } catch (Exception ex) {
                MainConsole.Instance.Warn ("[Entity transfer]: Exception in crossing: " + ex);
            }
        }
 private void EventManager_OnMakeChildAgent(IScenePresence presence, GridRegion destination)
 {
     m_authorizedParticipants.Remove(presence.UUID);
     m_userLogLevel.Remove(presence.UUID);
 }
        /// <summary>
        ///     Move the given scene object into a new region
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="grp">Scene Object Group that we're crossing</param>
        /// <param name="attemptedPos"></param>
        /// <returns>
        ///     true if the crossing itself was successful, false on failure
        /// </returns>
        protected bool CrossPrimGroupIntoNewRegion (GridRegion destination, ISceneEntity grp, Vector3 attemptedPos)
        {
            bool successYN = false;
            if (destination != null) {
                if (grp.SitTargetAvatar.Count != 0) {
                    foreach (UUID avID in grp.SitTargetAvatar) {
                        IScenePresence SP = grp.Scene.GetScenePresence (avID);
                        SP.Velocity = grp.RootChild.PhysActor.Velocity;
                        InternalCross (SP, attemptedPos, false, destination);
                    }
                    foreach (ISceneChildEntity part in grp.ChildrenEntities ())
                        part.SitTargetAvatar = new List<UUID> ();

                    IBackupModule backup = grp.Scene.RequestModuleInterface<IBackupModule> ();
                    if (backup != null)
                        return backup.DeleteSceneObjects (new [] { grp }, false, false);
                    return true; //They do all the work adding the prim in the other region
                }

                ISceneEntity copiedGroup = grp.Copy (false);
                copiedGroup.SetAbsolutePosition (true, attemptedPos);
                if (grp.Scene != null)
                    successYN = grp.Scene.RequestModuleInterface<ISimulationService> ()
                                   .CreateObject (destination, copiedGroup);

                if (successYN) {
                    // We remove the object here
                    try {
                        IBackupModule backup = grp.Scene.RequestModuleInterface<IBackupModule> ();
                        if (backup != null)
                            return backup.DeleteSceneObjects (new [] { grp }, false, true);
                    } catch (Exception e) {
                        MainConsole.Instance.ErrorFormat (
                           "[Entity transfer]: Exception deleting the old object left behind on a border crossing for {0}, {1}",
                            grp, e);
                    }
                } else {
                    if (!grp.IsDeleted) {
                        if (grp.RootChild.PhysActor != null) {
                            grp.RootChild.PhysActor.CrossingFailure ();
                        }
                    }

                    MainConsole.Instance.ErrorFormat("[Entity transfer]r]: Prim crossing failed for {0}", grp);
                }
            } else {
                MainConsole.Instance.Error (
                   "[Entity transfer]: destination was unexpectedly null in Scene.CrossPrimGroupIntoNewRegion()");
            }

            return successYN;
        }
        /// <summary>
        ///     Move the given scene object into a new region depending on which region its absolute position has moved
        ///     into.
        ///     This method locates the new region handle and offsets the prim position for the new region
        /// </summary>
        /// <param name="attemptedPosition">the attempted out of region position of the scene object</param>
        /// <param name="grp">the scene object that we're crossing</param>
        /// <param name="destination"></param>
        public bool CrossGroupToNewRegion (ISceneEntity grp, Vector3 attemptedPosition, GridRegion destination)
        {
            if (grp == null)
                return false;
            if (grp.IsDeleted)
                return false;

            if (grp.Scene == null)
                return false;
            if (grp.RootChild.DIE_AT_EDGE) {
                // We remove the object here
                try {
                    IBackupModule backup = grp.Scene.RequestModuleInterface<IBackupModule> ();
                    if (backup != null)
                        return backup.DeleteSceneObjects (new [] { grp }, true, true);
                } catch (Exception) {
                    MainConsole.Instance.Warn (
                        "[Database]: exception when trying to remove the prim that crossed the border.");
                }
                return false;
            }

            if (grp.RootChild.RETURN_AT_EDGE) {
                // We remove the object here
                try {
                    List<ISceneEntity> objects = new List<ISceneEntity> { grp };
                    ILLClientInventory inventoryModule = grp.Scene.RequestModuleInterface<ILLClientInventory> ();
                    if (inventoryModule != null)
                        return inventoryModule.ReturnObjects (objects.ToArray (), UUID.Zero);
                } catch (Exception) {
                    MainConsole.Instance.Warn (
                        "[Scene]: exception when trying to return the prim that crossed the border.");
                }
                return false;
            }

            Vector3 oldGroupPosition = grp.RootChild.GroupPosition;
            // If we fail to cross the border, then reset the position of the scene object on that border.
            if (destination != null && !CrossPrimGroupIntoNewRegion (destination, grp, attemptedPosition)) {
                grp.OffsetForNewRegion (oldGroupPosition);
                grp.ScheduleGroupUpdate (PrimUpdateFlags.ForcedFullUpdate);
                return false;
            }
            return true;
        }
Esempio n. 56
0
        public virtual bool CrossAgent(GridRegion crossingRegion, Vector3 pos,
            Vector3 velocity, AgentCircuitData circuit, AgentData cAgent, UUID agentID,
            UUID requestingRegion, out string reason)
        {
            IClientCapsService clientCaps = m_capsService.GetClientCapsService(agentID);
            IRegionClientCapsService requestingRegionCaps = clientCaps.GetCapsService(requestingRegion);
            ISimulationService SimulationService = m_registry.RequestModuleInterface<ISimulationService>();
            IGridService GridService = m_registry.RequestModuleInterface<IGridService>();
            try
            {
                if (SimulationService != null && GridService != null)
                {
                    //Set the user in transit so that we block duplicate tps and reset any cancelations
                    if (!SetUserInTransit(agentID))
                    {
                        reason = "Already in a teleport";
                        SimulationService.FailedToTeleportAgent(requestingRegionCaps.Region, crossingRegion.RegionID,
                            agentID, reason, true);
                        return false;
                    }

                    bool result = false;

                    IRegionClientCapsService otherRegion = clientCaps.GetCapsService(crossingRegion.RegionID);

                    if (otherRegion == null)
                    {
                        //If we failed before, attempt again
                        if (!InformClientOfNeighbor(agentID, requestingRegion, circuit, ref crossingRegion, 0,
                                cAgent, out reason))
                        {
                            ResetFromTransit(agentID);
                            SimulationService.FailedToTeleportAgent(requestingRegionCaps.Region,
                                crossingRegion.RegionID,
                                agentID, reason, true);
                            return false;
                        }

                        otherRegion = clientCaps.GetCapsService(crossingRegion.RegionID);
                    }

                    //We need to get it from the grid service again so that we can get the simulation service urls correctly
                    // as regions don't get that info
                    crossingRegion = GridService.GetRegionByUUID(clientCaps.AccountInfo.AllScopeIDs,
                        crossingRegion.RegionID);
                    cAgent.IsCrossing = true;

                    if (!SimulationService.UpdateAgent(crossingRegion, cAgent))
                    {
                        MainConsole.Instance.Warn("[Agent Processing]: Failed to cross agent " + agentID +
                        " because region did not accept it. Resetting.");
                        reason = "Failed to update an agent";
                        SimulationService.FailedToTeleportAgent(requestingRegionCaps.Region, crossingRegion.RegionID,
                            agentID, reason, true);
                    }
                    else
                    {
                        IEventQueueService EQService = m_registry.RequestModuleInterface<IEventQueueService>();

                        //Add this for the viewer, but not for the sim, seems to make the viewer happier
                        int XOffset = crossingRegion.RegionLocX - requestingRegionCaps.RegionX;
                        pos.X += XOffset;

                        int YOffset = crossingRegion.RegionLocY - requestingRegionCaps.RegionY;
                        pos.Y += YOffset;

                        //Tell the client about the transfer
                        EQService.CrossRegion(crossingRegion.RegionHandle, pos, velocity,
                            otherRegion.LoopbackRegionIP,
                            otherRegion.CircuitData.RegionUDPPort,
                            otherRegion.CapsUrl,
                            agentID,
                            circuit.SessionID,
                            crossingRegion.RegionSizeX,
                            crossingRegion.RegionSizeY,
                            requestingRegionCaps.Region.RegionID);

                        result = WaitForCallback(agentID);

                        if (!result)
                        {
                            MainConsole.Instance.Warn("[AgentProcessing]: Callback never came in crossing agent " +
                            circuit.AgentID +
                            ". Resetting.");
                            reason = "Crossing timed out";
                            SimulationService.FailedToTeleportAgent(requestingRegionCaps.Region, crossingRegion.RegionID,
                                agentID, reason, true);
                        }
                        else
                        {
                            // Next, let's close the child agent connections that are too far away.
                            //Fix the root agent status
                            otherRegion.RootAgent = true;
                            requestingRegionCaps.RootAgent = false;

                            CloseNeighborAgents(requestingRegionCaps.Region, crossingRegion, agentID);
                            reason = "";
                            IAgentInfoService agentInfoService = m_registry.RequestModuleInterface<IAgentInfoService>();

                            if (agentInfoService != null)
                                agentInfoService.SetLastPosition(agentID.ToString(), crossingRegion.RegionID,
                                    pos, Vector3.Zero, crossingRegion.ServerURI);
                            SimulationService.MakeChildAgent(agentID, requestingRegionCaps.Region, crossingRegion, true);
                        }
                    }

                    //All done
                    ResetFromTransit(agentID);
                    return result;
                }

                reason = "Could not find the SimulationService";
            }

            catch (Exception ex)
            {
                MainConsole.Instance.WarnFormat("[Agent Processing]: Failed to cross an agent into a new region. {0}", ex);
                if (SimulationService != null)
                    SimulationService.FailedToTeleportAgent(requestingRegionCaps.Region, crossingRegion.RegionID,
                        agentID, "Exception occurred", true);
            }

            ResetFromTransit(agentID);
            reason = "Exception occurred";
            return false;
        }
        /// <summary>
        ///     Verify if the user can connect to this region.  Checks the banlist and ensures that the region is set for public access
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="agent">The circuit data for the agent</param>
        /// <param name="reason">outputs the reason to this string</param>
        /// <returns>
        ///     True if the region accepts this agent.  False if it does not.  False will
        ///     also return a reason.
        /// </returns>
        protected bool AuthorizeUser (IScene scene, AgentCircuitData agent, out string reason)
        {
            reason = string.Empty;

            IAuthorizationService AuthorizationService = scene.RequestModuleInterface<IAuthorizationService> ();
            if (AuthorizationService != null) {
                GridRegion ourRegion = new GridRegion (scene.RegionInfo);
                if (!AuthorizationService.IsAuthorizedForRegion (ourRegion, agent, !agent.IsChildAgent, out reason)) {
                    MainConsole.Instance.WarnFormat (
                        "[Connection begin]: Denied access to {0} at {1} because the user does not have access to the region, reason: {2}",
                        agent.AgentID, scene.RegionInfo.RegionName, reason);
                    reason = string.Format ("You do not have access to the region {0}, reason: {1}",
                                           scene.RegionInfo.RegionName, reason);
                    return false;
                }
            }

            return true;
        }
Esempio n. 58
0
        public virtual bool EnableChildAgentsForRegion(GridRegion requestingRegion)
        {
            int count = 0;
            bool informed = true;
            List<GridRegion> neighbors = GetNeighbors(null, requestingRegion, 0);

            if (neighbors != null)
            {
                foreach (GridRegion neighbor in neighbors)
                {
                    IRegionCapsService regionCaps = m_capsService.GetCapsForRegion(neighbor.RegionID);
                    if (regionCaps == null) //If there isn't a region caps, there isn't an agent in this sim
                        continue;
                    List<UUID> usersInformed = new List<UUID>();
                    foreach (IRegionClientCapsService regionClientCaps in regionCaps.GetClients())
                    {
                        if (usersInformed.Contains(regionClientCaps.AgentID) || !regionClientCaps.RootAgent ||
                        AllScopeIDImpl.CheckScopeIDs(regionClientCaps.ClientCaps.AccountInfo.AllScopeIDs, neighbor) == null)
                            //Only inform agents once
                            continue;

                        AgentCircuitData regionCircuitData = regionClientCaps.CircuitData.Copy();
                        regionCircuitData.IsChildAgent = true;
                        string reason; //Tell the region about it
                        if (!InformClientOfNeighbor(regionClientCaps.AgentID, regionClientCaps.Region.RegionID,
                            regionCircuitData, ref requestingRegion, (uint)TeleportFlags.Default,
                            null, out reason))
                            informed = false;
                        else
                            usersInformed.Add(regionClientCaps.AgentID);
                    }
                    count++;
                }
            }

            return informed;
        }
Esempio n. 59
0
        bool CreateAgent(GridRegion region, IRegionClientCapsService regionCaps, ref AgentCircuitData aCircuit,
            ISimulationService SimulationService, List<UUID> friendsToInform, out CreateAgentResponse response)
        {
            CachedUserInfo info = new CachedUserInfo();
            IAgentConnector con = Framework.Utilities.DataManager.RequestPlugin<IAgentConnector>();

            if (con != null)
                info.AgentInfo = con.GetAgent(aCircuit.AgentID);

            if (regionCaps != null)
                info.UserAccount = regionCaps.ClientCaps.AccountInfo;

            IGroupsServiceConnector groupsConn = Framework.Utilities.DataManager.RequestPlugin<IGroupsServiceConnector>();

            if (groupsConn != null)
            {
                info.ActiveGroup = groupsConn.GetGroupMembershipData(aCircuit.AgentID, UUID.Zero, aCircuit.AgentID);
                info.GroupMemberships = groupsConn.GetAgentGroupMemberships(aCircuit.AgentID, aCircuit.AgentID);
            }

            IOfflineMessagesConnector offlineMessConn =
                Framework.Utilities.DataManager.RequestPlugin<IOfflineMessagesConnector>();

            if (offlineMessConn != null)
                info.OfflineMessages = offlineMessConn.GetOfflineMessages(aCircuit.AgentID);

            IMuteListConnector muteConn = Framework.Utilities.DataManager.RequestPlugin<IMuteListConnector>();

            if (muteConn != null)
                info.MuteList = muteConn.GetMuteList(aCircuit.AgentID);

            IAvatarService avatarService = m_registry.RequestModuleInterface<IAvatarService>();

            if (avatarService != null)
                info.Appearance = avatarService.GetAppearance(aCircuit.AgentID);

            info.FriendOnlineStatuses = friendsToInform;
            IFriendsService friendsService = m_registry.RequestModuleInterface<IFriendsService>();

            if (friendsService != null)
                info.Friends = friendsService.GetFriends(aCircuit.AgentID);

            aCircuit.CachedUserInfo = info;
            return SimulationService.CreateAgent(region, aCircuit, aCircuit.TeleportFlags, out response);
        }
Esempio n. 60
0
        public virtual List<GridRegion> GetNeighbors(List<UUID> scopeIDs, GridRegion region, int userDrawDistance)
        {
            var neighbors = new List<GridRegion>();
            var gridService = m_registry.RequestModuleInterface<IGridService>();
            if (gridService == null)
                return neighbors;       // no grid service??

            if (VariableRegionSight && userDrawDistance != 0)
            {
                //Enforce the max draw distance
                if (userDrawDistance > MaxVariableRegionSight)
                    userDrawDistance = MaxVariableRegionSight;

                //Query how many regions fit in this size
                int xMin = (region.RegionLocX) - (userDrawDistance);
                int xMax = (region.RegionLocX) + (userDrawDistance);
                int yMin = (region.RegionLocY) - (userDrawDistance);
                int yMax = (region.RegionLocY) + (userDrawDistance);

                //Ask the grid service about the range
                neighbors = gridService.GetRegionRange(scopeIDs, xMin, xMax, yMin, yMax);
            }
            else
                neighbors = gridService.GetNeighbors(scopeIDs, region);

            return neighbors;
        }