/**
         * Agent-related communications
         */
        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 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;
 }
        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);

            if (!response.Success)
                return false;
            return response.Success;
        }
        public virtual void EnableChildAgents(UUID AgentID, UUID requestingRegion, int DrawDistance, AgentCircuitData circuit)
        {
            Util.FireAndForget((o) =>
                                   {
                                       int count = 0;
                                       IClientCapsService clientCaps = m_capsService.GetClientCapsService(AgentID);
                                       GridRegion ourRegion =
                                           m_registry.RequestModuleInterface<IGridService>().GetRegionByUUID(
                                               clientCaps.AccountInfo.AllScopeIDs, requestingRegion);
                                       if (ourRegion == null)
                                       {
                                           MainConsole.Instance.Info(
                                               "[AgentProcessing]: Failed to inform neighbors about new agent, could not find our region.");
                                           return;
                                       }
                                       List<GridRegion> neighbors = GetNeighbors(clientCaps.AccountInfo.AllScopeIDs,
                                                                                 ourRegion, DrawDistance);

                                       //Fix the root agents dd
                                       foreach (GridRegion neighbor in neighbors)
                                       {
                                           if (neighbor.RegionID != requestingRegion &&
                                               clientCaps.GetCapsService(neighbor.RegionID) == null)
                                           {
                                               string reason;
                                               AgentCircuitData regionCircuitData =
                                                   clientCaps.GetRootCapsService().CircuitData.Copy();
                                               GridRegion nCopy = neighbor;
                                               regionCircuitData.IsChildAgent = true;
                                               InformClientOfNeighbor(AgentID, requestingRegion, regionCircuitData,
                                                                      ref nCopy,
                                                                      (uint) TeleportFlags.Default, null, out reason);
                                           }
                                           count++;
                                       }
                                   });
        }
        /// <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;
            }
            /*if ((neighbor.Flags & (int)WhiteCore.Framework.RegionFlags.RegionOnline) == 0 &&
                (neighbor.Flags & (int)(WhiteCore.Framework.RegionFlags.Foreign | WhiteCore.Framework.RegionFlags.Hyperlink)) == 0)
            {
                reason = "The region you are attempting to teleport to is offline";
                return false;
            }*/
            MainConsole.Instance.Info("[AgentProcessing]: 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 an WhiteCore 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("[AgentProcessing]: Completed inform client about neighbor " +
                                              neighbor.RegionName);
                }
                else
                {
                    clientCaps.RemoveCAPS(neighbor.RegionID);
                    reason = "Could not contact simulator";
                    MainConsole.Instance.Error("[AgentProcessing]: Failed to inform client about neighbor " +
                                               neighbor.RegionName +
                                               ", reason: " + reason);
                    return false;
                }
                return true;
            }
            reason = "SimulationService does not exist";
            MainConsole.Instance.Error("[AgentProcessing]: Failed to inform client about neighbor " +
                                       neighbor.RegionName +
                                       ", reason: " + reason + "!");
            return false;
        }
 /// <summary>
 ///     Find, or create if one does not exist, a Caps Service for the given region
 /// </summary>
 /// <param name="regionID"></param>
 /// <param name="CAPSBase"></param>
 /// <param name="circuitData"></param>
 /// <param name="port"></param>
 /// <returns></returns>
 public IRegionClientCapsService GetOrCreateCapsService(UUID regionID, string CAPSBase,
     AgentCircuitData circuitData, uint port)
 {
     //If one already exists, don't add a new one
     if (m_RegionCapsServices.ContainsKey(regionID))
     {
         if (port == 0 || m_RegionCapsServices[regionID].Server.Port == port)
         {
             m_RegionCapsServices[regionID].InformModulesOfRequest();
             return m_RegionCapsServices[regionID];
         }
         else
             RemoveCAPS(regionID);
     }
     //Create a new one, and then call Get to find it
     AddCapsServiceForRegion(regionID, CAPSBase, circuitData, port);
     return GetCapsService(regionID);
 }
 public override void FromOSD(OSDMap map)
 {
     Destination = new GridRegion();
     Destination.FromOSD((OSDMap)map["Destination"]);
     TeleportFlags = map["TeleportFlags"];
     CircuitData = new AgentCircuitData();
     CircuitData.FromOSD((OSDMap)map["CircuitData"]);
 }
        /// <summary>
        ///     Do the work necessary to initiate a new user connection for a particular scene.
        ///     At the moment, this consists of setting up the caps infrastructure
        ///     The return bool should allow for connections to be refused, but as not all calling paths
        ///     take proper notice of it let, we allowed banned users in still.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="agent">CircuitData of the agent who is connecting</param>
        /// <param name="UDPPort"></param>
        /// <param name="reason">
        ///     Outputs the reason for the false response on this string,
        ///     If the agent was accepted, this will be the Caps SEED for the region
        /// </param>
        /// <param name="teleportFlags"></param>
        /// <returns>
        ///     True if the region accepts this agent.  False if it does not.  False will
        ///     also return a reason.
        /// </returns>
        public bool NewUserConnection(IScene scene, AgentCircuitData agent, uint teleportFlags, out CreateAgentResponse response)
        {
            response = new CreateAgentResponse();
            response.RequestedUDPPort = scene.RegionInfo.RegionPort;
            IScenePresence sp = scene.GetScenePresence(agent.AgentID);

            // Don't disable this log message - it's too helpful
            MainConsole.Instance.TraceFormat(
                "[ConnectionBegin]: Region {0} told of incoming {1} agent {2} (circuit code {3}, teleportflags {4})",
                scene.RegionInfo.RegionName, agent.IsChildAgent ? "child" : "root", agent.AgentID,
                agent.CircuitCode, teleportFlags);

            CacheUserInfo(scene, agent.CachedUserInfo);

            string reason;
            if (!AuthorizeUser(scene, agent, out reason))
            {
                response.Reason = reason;
                response.Success = false;
                return false;
            }

            if (sp != null && !sp.IsChildAgent)
            {
                // We have a zombie from a crashed session.
                // Or the same user is trying to be root twice here, won't work.
                // Kill it.
                MainConsole.Instance.InfoFormat("[Scene]: Zombie scene presence detected for {0} in {1}", agent.AgentID,
                                                scene.RegionInfo.RegionName);
                //Tell everyone about it
                scene.WhiteCoreEventManager.FireGenericEventHandler("AgentIsAZombie", sp.UUID);
                //Send the killing message (DisableSimulator)
                scene.RemoveAgent(sp, true);
                sp = null;
            }

            response.CapsURIs = scene.EventManager.TriggerOnRegisterCaps(agent.AgentID);
            response.OurIPForClient = MainServer.Instance.HostName;

            scene.WhiteCoreEventManager.FireGenericEventHandler("NewUserConnection", agent);

            //Add the circuit at the end
            scene.AuthenticateHandler.AddNewCircuit(agent.CircuitCode, agent);

            MainConsole.Instance.InfoFormat(
                "[ConnectionBegin]: Region {0} authenticated and authorized incoming {1} agent {2} (circuit code {3})",
                scene.RegionInfo.RegionName, agent.IsChildAgent ? "child" : "root", agent.AgentID,
                agent.CircuitCode);

            response.Success = true;
            return true;
        }
        /// <summary>
        ///     Create a Caps URL for the given user/region. Called normally by the EventQueueService or the LLLoginService on login
        /// </summary>
        /// <param name="AgentID"></param>
        /// <param name="CAPSBase"></param>
        /// <param name="regionID"></param>
        /// <param name="IsRootAgent">Will this child be a root agent</param>
        /// <param name="circuitData"></param>
        /// <param name="port">The port to use for the CAPS service</param>
        /// <returns></returns>
        public string CreateCAPS(UUID AgentID, string CAPSBase, UUID regionID, bool IsRootAgent,
            AgentCircuitData circuitData, uint port)
        {
            //Now make sure we didn't use an old one or something
            IClientCapsService service = GetOrCreateClientCapsService(AgentID);
            IRegionClientCapsService clientService = service.GetOrCreateCapsService(regionID, CAPSBase, circuitData,
                                                                                    port);

            //Fix the root agent status
            clientService.RootAgent = IsRootAgent;

            MainConsole.Instance.Debug("[CapsService]: Adding Caps URL " + clientService.CapsUrl + " for agent " +
                                       AgentID);
            return clientService.CapsUrl;
        }
示例#10
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 (message["Method"] == "LogoutRegionAgents")
            {
                LogOutAllAgentsForRegion(requestingRegion);
            }
            else if (message["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
                //LogOutAllAgentsForRegion(requestingRegion);
                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 (message["Method"] == "ArrivedAtDestination")
            {
                if (regionCaps == null || clientCaps == null)
                    return null;
                //Recieved 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 (message["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 (message["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 (message["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 (message["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 (message["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;
                }
                else if (clientCaps.InTeleport)
                {
                    OSDMap result = new OSDMap();
                    result["success"] = false;
                    result["Note"] = false;
                    return result;
                }
                else
                {
                    OSDMap result = new OSDMap();
                    result["success"] = false;
                    result["Note"] = false;
                    return result;
                }
            }
            return null;
        }
 public override void FromOSD(OSDMap map)
 {
     Success = map["Success"];
     if (map.ContainsKey("AgentData"))
     {
         AgentData = new AgentData();
         AgentData.FromOSD((OSDMap)map["AgentData"]);
     }
     if (map.ContainsKey("CircuitData"))
     {
         CircuitData = new AgentCircuitData();
         CircuitData.FromOSD((OSDMap)map["CircuitData"]);
     }
 }
示例#12
0
        /// <summary>
        ///     Creates a new bot inworld
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="scene"></param>
        /// <param name="cloneAppearanceFrom">UUID of the avatar whos appearance will be copied to give this bot an appearance</param>
        /// <param name="creatorID"></param>
        /// <param name="startPos"></param>
        /// <returns>ID of the bot</returns>
        public UUID CreateAvatar(string firstName, string lastName, IScene scene, UUID cloneAppearanceFrom,
            UUID creatorID, Vector3 startPos)
        {
            AgentCircuitData m_aCircuitData = new AgentCircuitData
            {
                IsChildAgent = false,
                CircuitCode = (uint) Util.RandomClass.Next()
            };

            //Add the circuit data so they can login

            //Sets up appearance
            AvatarAppearance app = GetAppearance(cloneAppearanceFrom, scene) ?? new AvatarAppearance { Wearables = AvatarWearable.DefaultWearables };
            //Create the new bot data
            BotClientAPI m_character = new BotClientAPI(scene, m_aCircuitData);

            m_character.Name = firstName + " " + lastName;
            m_aCircuitData.AgentID = m_character.AgentId;
            app.Owner = m_character.AgentId;
            List<AvatarAttachment> attachments = app.GetAttachments();

            app.ClearAttachments();
            foreach (AvatarAttachment t in attachments)
            {
                InventoryItemBase item = scene.InventoryService.GetItem(cloneAppearanceFrom, t.ItemID);
                if (item != null)
                {
                    item.ID = UUID.Random();
                    item.Owner = m_character.AgentId;
                    item.Folder = UUID.Zero;
                    scene.InventoryService.AddItemAsync(item, null);
                    //Now fix the ItemID
                    app.SetAttachment(t.AttachPoint, item.ID, t.AssetID);
                }
            }

            scene.AuthenticateHandler.AgentCircuits.Add(m_character.CircuitCode, m_aCircuitData);
            //This adds them to the scene and sets them inworld
            AddAndWaitUntilAgentIsAdded(scene, m_character);

            IScenePresence SP = scene.GetScenePresence(m_character.AgentId);
            if (SP == null)
                return UUID.Zero; //Failed!

            IAvatarAppearanceModule appearance = SP.RequestModuleInterface<IAvatarAppearanceModule>();
            appearance.Appearance = app;
            appearance.InitialHasWearablesBeenSent = true;
            Bot bot = new Bot();
            bot.Initialize(SP, creatorID);
            SP.MakeRootAgent(startPos, false, true);
            //Move them
            SP.Teleport(startPos);

            foreach (var presence in scene.GetScenePresences())
                presence.SceneViewer.QueuePresenceForUpdate(SP, PrimUpdateFlags.ForcedFullUpdate);
            IAttachmentsModule attModule = SP.Scene.RequestModuleInterface<IAttachmentsModule>();
            if (attModule != null)
                foreach (AvatarAttachment att in attachments)
                    attModule.RezSingleAttachmentFromInventory(SP.ControllingClient, att.ItemID, att.AssetID, 0, true);

            //Save them in the bots list
            m_bots.Add(m_character.AgentId, bot);
            AddTagToBot(m_character.AgentId, "AllBots", bot.AvatarCreatorID);

            MainConsole.Instance.Info("[BotManager]: Added bot " + m_character.Name + " to scene.");
            //Return their UUID
            return m_character.AgentId;
        }
        private void DeserializeUsers()
        {
            if (!File.Exists(BuildSaveFileName()))
                return;
            foreach (OSD o in ((OSDMap)OSDParser.DeserializeJson(File.ReadAllText(BuildSaveFileName()))).Values)
            {
                AgentCircuitData data = new AgentCircuitData();
                OSDMap user = (OSDMap)o;
                data.FromOSD((OSDMap)user["ClientInfo"]);
                m_scene.AuthenticateHandler.AddNewCircuit(data.CircuitCode, data);
                OSDMap remoteIP = (OSDMap)user["RemoteEndPoint"];
                IPEndPoint ep = new IPEndPoint(IPAddress.Parse(remoteIP["Address"].AsString()), remoteIP["Port"].AsInteger());
                m_scene.ClientServers[0].AddClient(data.CircuitCode, data.AgentID, data.SessionID, ep, data);
                IScenePresence sp = m_scene.GetScenePresence(data.AgentID);
                sp.MakeRootAgent(user["Position"].AsVector3(), user["IsFlying"].AsBoolean(), true);
                sp.SceneViewer.SendPresenceFullUpdate(sp);
            }

            File.Delete(BuildSaveFileName());
        }
        void DeserializeUsers(IScene scene)
        {
            var regionName = scene.RegionInfo.RegionName;
            var readFile = BuildSaveFileName (regionName);
            if (!File.Exists (readFile))
                return;

            var regionUsers = 0;
            OSDMap sceneAgents = (OSDMap)OSDParser.DeserializeJson (File.ReadAllText (readFile));
            foreach (OSD o in sceneAgents.Values)
            {
                AgentCircuitData data = new AgentCircuitData ();
                OSDMap user = (OSDMap)o;

                data.FromOSD ((OSDMap)user ["ClientInfo"]);
                m_scene.AuthenticateHandler.AddNewCircuit (data.CircuitCode, data);
                OSDMap remoteIP = (OSDMap)user ["RemoteEndPoint"];
                IPEndPoint ep = new IPEndPoint (IPAddress.Parse (remoteIP ["Address"].AsString ()), remoteIP ["Port"].AsInteger ());

                m_scene.ClientServers [0].AddClient (data.CircuitCode, data.AgentID, data.SessionID, ep, data);
                IScenePresence sp = m_scene.GetScenePresence (data.AgentID);
                sp.MakeRootAgent (user ["Position"].AsVector3 (), user ["IsFlying"].AsBoolean (), true);
                sp.SceneViewer.SendPresenceFullUpdate (sp);

                regionUsers += 1;
            }

            File.Delete (readFile);
            MainConsole.Instance.InfoFormat ("[Restart]: {0} users loaded into {1}", regionUsers, regionName);
        }
示例#15
0
 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
     //endPoint = Util.ResolveAddressForClient (endPoint, circuitData.ClientIPEndPoint);
     SimAddress = endPoint.Address.ToString();
     SimPort = (uint) circuitData.RegionUDPPort;
     RegionX = (uint) destination.RegionLocX;
     RegionY = (uint) destination.RegionLocY;
     RegionSizeX = destination.RegionSizeX;
     RegionSizeY = destination.RegionSizeY;
 }
示例#16
0
        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;
            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;
        }
示例#17
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 params 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 (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 WhiteCore 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("[AgentProcessing]: No simulation service found! Could not log in user!");
            return new LoginAgentArgs {Success = success, CircuitData = aCircuit, Reason = reason, SeedCap = seedCap};
        }
示例#18
0
        private bool OnAllowedIncomingAgent(IScene scene, AgentCircuitData agent, bool isRootAgent, out string reason)
        {
            #region Incoming Agent Checks

            UserAccount account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.AllScopeIDs, agent.AgentID);
            if (account == null)
            {
                reason = "No account exists";
                return false;
            }
            IScenePresence Sp = scene.GetScenePresence(agent.AgentID);

            if (LoginsDisabled)
            {
                reason = "Logins are currently Disabled";
                return false;
            }

            //Check how long its been since the last TP
            if (m_enabledBlockTeleportSeconds && Sp != null && !Sp.IsChildAgent)
            {
                if (TimeSinceLastTeleport.ContainsKey(Sp.Scene.RegionInfo.RegionID))
                {
                    if (TimeSinceLastTeleport[Sp.Scene.RegionInfo.RegionID] > Util.UnixTimeSinceEpoch())
                    {
                        reason = "Too many teleports. Please try again soon.";
                        return false; // Too soon since the last TP
                    }
                }
                TimeSinceLastTeleport[Sp.Scene.RegionInfo.RegionID] = Util.UnixTimeSinceEpoch() +
                                                                      ((int) (SecondsBeforeNextTeleport));
            }

            //Gods tp freely
            if ((Sp != null && Sp.GodLevel != 0) || (account != null && account.UserLevel != 0))
            {
                reason = "";
                return true;
            }

            //Check whether they fit any ban criteria
            if (Sp != null)
            {
                foreach (string banstr in BanCriteria)
                {
                    if (Sp.Name.Contains(banstr))
                    {
                        reason = "You have been banned from this region.";
                        return false;
                    }
                    else if (((IPEndPoint) Sp.ControllingClient.GetClientEP()).Address.ToString().Contains(banstr))
                    {
                        reason = "You have been banned from this region.";
                        return false;
                    }
                }
                //Make sure they exist in the grid right now
                IAgentInfoService presence = scene.RequestModuleInterface<IAgentInfoService>();
                if (presence == null)
                {
                    reason =
                        String.Format(
                            "Failed to verify user presence in the grid for {0} in region {1}. Presence service does not exist.",
                            account.Name, scene.RegionInfo.RegionName);
                    return false;
                }

                UserInfo pinfo = presence.GetUserInfo(agent.AgentID.ToString());

                if (pinfo == null || (!pinfo.IsOnline && ((agent.TeleportFlags & (uint) TeleportFlags.ViaLogin) == 0)))
                {
                    reason =
                        String.Format(
                            "Failed to verify user presence in the grid for {0}, access denied to region {1}.",
                            account.Name, scene.RegionInfo.RegionName);
                    return false;
                }
            }

            EstateSettings ES = scene.RegionInfo.EstateSettings;

            IEntityCountModule entityCountModule = scene.RequestModuleInterface<IEntityCountModule>();
            if (entityCountModule != null && scene.RegionInfo.RegionSettings.AgentLimit
                                             < entityCountModule.RootAgents + 1 &&
                scene.RegionInfo.RegionSettings.AgentLimit > 0)
            {
                reason = "Too many agents at this time. Please come back later.";
                return false;
            }

            List<EstateBan> EstateBans = new List<EstateBan>(ES.EstateBans);
            int i = 0;
            //Check bans
            foreach (EstateBan ban in EstateBans)
            {
                if (ban.BannedUserID == agent.AgentID)
                {
                    if (Sp != null)
                    {
                        string banIP = ((IPEndPoint) Sp.ControllingClient.GetClientEP()).Address.ToString();

                        if (ban.BannedHostIPMask != banIP) //If it changed, ban them again
                        {
                            //Add the ban with the new hostname
                            ES.AddBan(new EstateBan
                                          {
                                              BannedHostIPMask = banIP,
                                              BannedUserID = ban.BannedUserID,
                                              EstateID = ban.EstateID,
                                              BannedHostAddress = ban.BannedHostAddress,
                                              BannedHostNameMask = ban.BannedHostNameMask
                                          });
                            //Update the database
                            WhiteCore.Framework.Utilities.DataManager.RequestPlugin<IEstateConnector>().
                                SaveEstateSettings(ES);
                        }
                    }

                    reason = "Banned from this region.";
                    return false;
                }
                if (Sp != null)
                {
                    IPAddress end = Sp.ControllingClient.EndPoint;
                    IPHostEntry rDNS = null;
                    try
                    {
                        rDNS = Dns.GetHostEntry(end);
                    }
                    catch (SocketException)
                    {
                        MainConsole.Instance.WarnFormat("[IPBAN] IP address \"{0}\" cannot be resolved via DNS", end);
                        rDNS = null;
                    }
                    if (ban.BannedHostIPMask == agent.IPAddress ||
                        (rDNS != null && rDNS.HostName.Contains(ban.BannedHostIPMask)) ||
                        end.ToString().StartsWith(ban.BannedHostIPMask))
                    {
                        //Ban the new user
                        ES.AddBan(new EstateBan
                                      {
                                          EstateID = ES.EstateID,
                                          BannedHostIPMask = agent.IPAddress,
                                          BannedUserID = agent.AgentID,
                                          BannedHostAddress = agent.IPAddress,
                                          BannedHostNameMask = agent.IPAddress
                                      });
                        WhiteCore.Framework.Utilities.DataManager.RequestPlugin<IEstateConnector>().
                            SaveEstateSettings(ES);

                        reason = "Banned from this region.";
                        return false;
                    }
                }
                i++;
            }

            //Estate owners/managers/access list people/access groups tp freely as well
            if (ES.EstateOwner == agent.AgentID ||
                new List<UUID>(ES.EstateManagers).Contains(agent.AgentID) ||
                new List<UUID>(ES.EstateAccess).Contains(agent.AgentID) ||
                CheckEstateGroups(ES, agent))
            {
                reason = "";
                return true;
            }

            if (ES.DenyAnonymous &&
                ((account.UserFlags & (int) IUserProfileInfo.ProfileFlags.NoPaymentInfoOnFile) ==
                 (int) IUserProfileInfo.ProfileFlags.NoPaymentInfoOnFile))
            {
                reason = "You may not enter this region.";
                return false;
            }

            if (ES.DenyIdentified &&
                ((account.UserFlags & (int) IUserProfileInfo.ProfileFlags.PaymentInfoOnFile) ==
                 (int) IUserProfileInfo.ProfileFlags.PaymentInfoOnFile))
            {
                reason = "You may not enter this region.";
                return false;
            }

            if (ES.DenyTransacted &&
                ((account.UserFlags & (int) IUserProfileInfo.ProfileFlags.PaymentInfoInUse) ==
                 (int) IUserProfileInfo.ProfileFlags.PaymentInfoInUse))
            {
                reason = "You may not enter this region.";
                return false;
            }

            const long m_Day = 25*60*60; //Find out day length in seconds
            if (scene.RegionInfo.RegionSettings.MinimumAge != 0 &&
                (account.Created - Util.UnixTimeSinceEpoch()) < (scene.RegionInfo.RegionSettings.MinimumAge*m_Day))
            {
                reason = "You may not enter this region.";
                return false;
            }

            if (!ES.PublicAccess)
            {
                reason = "You may not enter this region, Public access has been turned off.";
                return false;
            }

            IAgentConnector AgentConnector = Framework.Utilities.DataManager.RequestPlugin<IAgentConnector>();
            IAgentInfo agentInfo = null;
            if (AgentConnector != null)
            {
                agentInfo = AgentConnector.GetAgent(agent.AgentID);
                if (agentInfo == null)
                {
                    AgentConnector.CreateNewAgent(agent.AgentID);
                    agentInfo = AgentConnector.GetAgent(agent.AgentID);
                }
            }

            if (m_checkMaturityLevel)
            {
                if (agentInfo != null &&
                    scene.RegionInfo.AccessLevel > Util.ConvertMaturityToAccessLevel((uint) agentInfo.MaturityRating))
                {
                    reason = "The region has too high of a maturity level. Blocking teleport.";
                    return false;
                }

                if (agentInfo != null && ES.DenyMinors && (agentInfo.Flags & IAgentFlags.Minor) == IAgentFlags.Minor)
                {
                    reason = "The region has too high of a maturity level. Blocking teleport.";
                    return false;
                }
            }

            #endregion

            reason = "";
            return true;
        }
示例#19
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
                    // trigers 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("[AgentProcessing]: 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
                        // 7/22 -- Kill the agent no matter what, it obviously is having issues getting there
                        //if (IsOutsideView (regionCaps.RegionX, destination.RegionLocX, regionCaps.Region.RegionSizeX, destination.RegionSizeX,
                        //    regionCaps.RegionY, destination.RegionLocY, regionCaps.Region.RegionSizeY, destination.RegionSizeY))
                        {
                            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.
                        //if (useCallbacks || oldRegion != destination)//Only close it if we are using callbacks (WhiteCore region)
                        //Why? OpenSim regions need closed too, even if the protocol is kinda 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("[AgentProcessing]: Exception occured during agent teleport, {0}", ex);
                reason = "Exception occured.";
                if (SimulationService != null)
                    SimulationService.FailedToTeleportAgent(regionCaps.Region, destination.RegionID,
                                                            AgentID, reason, false);
            }
            //All done
            ResetFromTransit(AgentID);
            return result;
        }
        public bool RetrieveAgent(GridRegion destination, UUID agentID, bool agentIsLeaving, out AgentData agentData,
            out AgentCircuitData circuitData)
        {
            agentData = null;
            circuitData = null;

            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.IncomingRetrieveRootAgent(Scene, agentID, agentIsLeaving, out agentData,
                                                                out circuitData);
            return false;
            //MainConsole.Instance.Debug("[LOCAL COMMS]: region not found for ChildAgentUpdate");
        }
示例#21
0
 private bool CheckEstateGroups(EstateSettings ES, AgentCircuitData agent)
 {
     IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
     if (gm != null && ES.EstateGroups.Count > 0)
     {
         GroupMembershipData[] gmds = gm.GetMembershipData(agent.AgentID);
         return gmds.Any(gmd => ES.EstateGroups.Contains(gmd.GroupID));
     }
     return false;
 }
        public virtual AgentCircuitData Copy()
        {
            AgentCircuitData Copy = new AgentCircuitData
            {
                AgentID = AgentID,
                IsChildAgent = IsChildAgent,
                CircuitCode = CircuitCode,
                IPAddress = IPAddress,
                SecureSessionID = SecureSessionID,
                SessionID = SessionID,
                StartingPosition = StartingPosition,
                TeleportFlags = TeleportFlags,
                CachedUserInfo = CachedUserInfo
            };

            return Copy;
        }
        public virtual bool IncomingRetrieveRootAgent(IScene scene, UUID id, bool agentIsLeaving, out AgentData agent,
            out AgentCircuitData circuitData)
        {
            agent = null;
            circuitData = null;
            IScenePresence sp = scene.GetScenePresence(id);
            if ((sp != null) && (!sp.IsChildAgent))
            {
                AgentData data = new AgentData();
                sp.CopyTo(data);
                agent = data;
                circuitData = BuildCircuitDataForPresence(sp, sp.AbsolutePosition);
                //if (agentIsLeaving)
                //    sp.SetAgentLeaving(null);//We arn't sure where they are going
                return true;
            }

            return false;
        }
示例#24
0
        private bool IsClientAuthorized(UseCircuitCodePacket useCircuitCode, IPEndPoint remoteEndPoint,
            out AgentCircuitData sessionInfo)
        {
            UUID agentID = useCircuitCode.CircuitCode.ID;
            UUID sessionID = useCircuitCode.CircuitCode.SessionID;
            uint circuitCode = useCircuitCode.CircuitCode.Code;

            return (sessionInfo = m_circuitManager.AuthenticateSession(sessionID, agentID, circuitCode, remoteEndPoint)) != null;
        }
        /// <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(
                        "[ConnectionBegin]: 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;
        }
示例#26
0
        public virtual bool AddClient(uint circuitCode, UUID agentID, UUID sessionID, IPEndPoint remoteEndPoint,
            AgentCircuitData sessionInfo)
        {
            MainConsole.Instance.Debug("[LLUDPServer] AddClient-" + circuitCode + "-" + agentID + "-" + sessionID + "-" +
                                       remoteEndPoint +
                                       "-" + sessionInfo);
            IScenePresence SP;
            if (!m_scene.TryGetScenePresence(agentID, out SP))
            {
                // Create the LLUDPClient
                LLUDPClient udpClient = new LLUDPClient(this, m_throttleRates, m_throttle, circuitCode, agentID,
                                                        remoteEndPoint, m_defaultRTO, m_maxRTO);
                // Create the LLClientView
                LLClientView client = new LLClientView(remoteEndPoint, m_scene, this, udpClient, sessionInfo, agentID,
                                                       sessionID, circuitCode);
                client.OnLogout += LogoutHandler;

                // Start the IClientAPI
                m_scene.AddNewClient(client, null);
                m_currentClients.Add(client);
            }
            else
            {
                MainConsole.Instance.DebugFormat(
                    "[LLUDPSERVER]: Ignoring a repeated UseCircuitCode ({0}) from {1} at {2} ",
                    circuitCode, agentID, remoteEndPoint);
            }
            return true;
        }
示例#27
0
 protected bool TryFindGridRegionForAgentLogin(List<GridRegion> regions, UserAccount account,
     UUID session, UUID secureSession,
     uint circuitCode, Vector3 position,
     IPEndPoint clientIP, AgentCircuitData aCircuit, List<UUID> friendsToInform,
     out string seedCap, out string reason, out GridRegion destination)
 {
     LoginAgentArgs args = null;
     foreach (GridRegion r in regions)
     {
         if (r == null)
             continue;
         MainConsole.Instance.DebugFormat("[LoginService]: Attempting to log {0} into {1} at {2}...", account.Name, r.RegionName, r.ServerURI);
         args = m_registry.RequestModuleInterface<IAgentProcessing>().
                           LoginAgent(r, aCircuit, friendsToInform);
         if (args.Success)
         {
             aCircuit = MakeAgent(r, account, session, secureSession, circuitCode, position, clientIP);
             destination = r;
             reason = args.Reason;
             seedCap = args.SeedCap;
             return true;
         }
         m_GridService.SetRegionUnsafe(r.RegionID);
     }
     if (args != null)
     {
         seedCap = args.SeedCap;
         reason = args.Reason;
     }
     else
     {
         seedCap = "";
         reason = "";
     }
     destination = null;
     return false;
 }
示例#28
0
        private 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);
            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);
        }
        /// <summary>
        ///     Add a new Caps Service for the given region if one does not already exist
        /// </summary>
        /// <param name="regionID"></param>
        /// <param name="CAPSBase"></param>
        /// <param name="circuitData"></param>
        /// <param name="port"></param>
        protected void AddCapsServiceForRegion(UUID regionID, string CAPSBase, AgentCircuitData circuitData,
            uint port)
        {
            if (!m_RegionCapsServices.ContainsKey(regionID))
            {
                //Now add this client to the region caps
                //Create if needed
                m_CapsService.AddCapsForRegion(regionID);
                IRegionCapsService regionCaps = m_CapsService.GetCapsForRegion(regionID);

                PerRegionClientCapsService regionClient = new PerRegionClientCapsService();
                regionClient.Initialise(this, regionCaps, CAPSBase, circuitData, port);
                m_RegionCapsServices[regionID] = regionClient;

                //Now get and add them
                regionCaps.AddClientToRegion(regionClient);
            }
        }
示例#30
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;
                        }
                        else
                            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("[AgentProcessing]: 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;
                }
                else
                    reason = "Could not find the SimulationService";
            }
            catch (Exception ex)
            {
                MainConsole.Instance.WarnFormat("[AgentProcessing]: Failed to cross an agent into a new region. {0}", ex);
                if (SimulationService != null)
                    SimulationService.FailedToTeleportAgent(requestingRegionCaps.Region, crossingRegion.RegionID,
                                                            AgentID, "Exception occured", true);
            }
            ResetFromTransit(AgentID);
            reason = "Exception occured";
            return false;
        }