Beispiel #1
0
        /// <summary>
        /// Introduce an agent into the scene by adding a new client.
        /// </summary>
        /// <returns>The scene presence added</returns>
        /// <param name='scene'></param>
        /// <param name='testClient'></param>
        /// <param name='agentData'></param>
        /// <param name='tf'></param>
        private static ScenePresence IntroduceClientToScene(
            Scene scene, IClientAPI client, AgentCircuitData agentData, TeleportFlags tf)
        {
            string reason;

            // Stage 1: tell the scene to expect a new user connection
            if (!scene.NewUserConnection(agentData, (uint)tf, null, out reason))
                Console.WriteLine("NewUserConnection failed: " + reason);

            // Stage 2: add the new client as a child agent to the scene
            scene.AddNewAgent(client, PresenceType.User);

            return scene.GetScenePresence(client.AgentId);
        }
Beispiel #2
0
        public UUID CreateNPC(string firstname, string lastname,
                Vector3 position, UUID owner, bool senseAsAgent, Scene scene,
                AvatarAppearance appearance)
        {
            NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position,
                    owner, senseAsAgent, scene);
            npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0,
                    int.MaxValue);

            m_log.DebugFormat(
                "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}",
                firstname, lastname, npcAvatar.AgentId, owner,
                senseAsAgent, position, scene.RegionInfo.RegionName);

            AgentCircuitData acd = new AgentCircuitData();
            acd.AgentID = npcAvatar.AgentId;
            acd.firstname = firstname;
            acd.lastname = lastname;
            acd.ServiceURLs = new Dictionary<string, object>();

            AvatarAppearance npcAppearance = new AvatarAppearance(appearance,
                    true);
            acd.Appearance = npcAppearance;

            /*
            for (int i = 0;
                    i < acd.Appearance.Texture.FaceTextures.Length; i++)
            {
                m_log.DebugFormat(
                        "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}",
                        acd.AgentID, i,
                        acd.Appearance.Texture.FaceTextures[i]);
            }
            */

            lock (m_avatars)
            {
                scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode,
                        acd);
                scene.AddNewAgent(npcAvatar, PresenceType.Npc);

                ScenePresence sp;
                if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
                {
                    /*
                    m_log.DebugFormat(
                            "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}",
                            sp.Name, sp.UUID);
                    */

                    sp.CompleteMovement(npcAvatar, false);
                    m_avatars.Add(npcAvatar.AgentId, npcAvatar);
                    m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name);

                    return npcAvatar.AgentId;
                }
                else
                {
                    m_log.WarnFormat(
                        "[NPC MODULE]: Could not find scene presence for NPC {0} {1}",
                        sp.Name, sp.UUID);

                    return UUID.Zero;
                }
            }
        }
        public UUID CreateNPC(string firstname, string lastname,
                Vector3 position, UUID agentID, UUID owner, string groupTitle, UUID groupID, bool senseAsAgent, Scene scene,
                AvatarAppearance appearance)
        {
            NPCAvatar npcAvatar = null;

            try
            {
                if (agentID == UUID.Zero)
                    npcAvatar = new NPCAvatar(firstname, lastname, position,
                            owner, senseAsAgent, scene);
                else
                    npcAvatar = new NPCAvatar(firstname, lastname, agentID, position,
                        owner, senseAsAgent, scene);
            }
            catch (Exception e)
            {
                m_log.Info("[NPC MODULE]: exception creating NPC avatar: " + e.ToString());
                return UUID.Zero;
            }

            npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0,
                    int.MaxValue);

//            m_log.DebugFormat(
//                "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}",
//                firstname, lastname, npcAvatar.AgentId, owner, senseAsAgent, position, scene.RegionInfo.RegionName);

            AgentCircuitData acd = new AgentCircuitData();
            acd.AgentID = npcAvatar.AgentId;
            acd.firstname = firstname;
            acd.lastname = lastname;
            acd.ServiceURLs = new Dictionary<string, object>();

            AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true);
            acd.Appearance = npcAppearance;

            /*
            for (int i = 0;
                    i < acd.Appearance.Texture.FaceTextures.Length; i++)
            {
                m_log.DebugFormat(
                        "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}",
                        acd.AgentID, i,
                        acd.Appearance.Texture.FaceTextures[i]);
            }
            */

//            ManualResetEvent ev = new ManualResetEvent(false);

//            Util.FireAndForget(delegate(object x) {
                lock (m_avatars)
                {
                    scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd);
                    scene.AddNewAgent(npcAvatar, PresenceType.Npc);

                    ScenePresence sp;
                    if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
                    {
                        npcAvatar.ActiveGroupId = groupID;
                        sp.CompleteMovement(npcAvatar, false);
                        sp.Grouptitle = groupTitle;
                        m_avatars.Add(npcAvatar.AgentId, npcAvatar);
//                        m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name);
                    }
                }
//                ev.Set();
//            });

//            ev.WaitOne();

//            m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", npcAvatar.AgentId);

            return npcAvatar.AgentId;
        }