Ejemplo n.º 1
0
        /// <summary>
        /// Adding a New Client and Create a Presence for it.
        /// Called by the LLClientView when the UseCircuitCode packet comes in
        /// Used by NPCs to add themselves to the Scene
        /// </summary>
        /// <param name="client"></param>
        public void AddNewClient(IClientAPI client)
        {
            try
            {
                System.Net.IPEndPoint ep       = (System.Net.IPEndPoint)client.GetClientEP();
                AgentCircuitData      aCircuit = AuthenticateHandler.AuthenticateSession(client.SessionId, client.AgentId, client.CircuitCode, ep);

                if (aCircuit == null) // no good, didn't pass NewUserConnection successfully
                {
                    return;
                }

                m_clientManager.Add(client);

                //Create the scenepresence
                IScenePresence sp = m_sceneGraph.CreateAndAddChildScenePresence(client);
                sp.IsChildAgent = aCircuit.child;


                //Trigger events
                m_eventManager.TriggerOnNewPresence(sp);

                //Make sure the appearanace is updated
                if (aCircuit != null)
                {
                    IAvatarAppearanceModule appearance = sp.RequestModuleInterface <IAvatarAppearanceModule> ();
                    if (appearance != null)
                    {
                        appearance.Appearance = aCircuit.Appearance;
                    }
                }

                if (GetScenePresence(client.AgentId) != null)
                {
                    EventManager.TriggerOnNewClient(client);
                    if ((aCircuit.teleportFlags & (uint)TeleportFlags.ViaLogin) != 0)
                    {
                        EventManager.TriggerOnClientLogin(client);
                    }
                }

                //Add the client to login stats
                ILoginMonitor monitor = (ILoginMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor("", "LoginMonitor");
                if ((aCircuit.teleportFlags & (uint)TeleportFlags.ViaLogin) != 0 && monitor != null)
                {
                    monitor.AddSuccessfulLogin();
                }
            }
            catch (Exception ex)
            {
                m_log.Warn("[Scene]: Error in AddNewClient: " + ex.ToString());
            }
        }