Esempio n. 1
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args)
        {
            // DEBUG ON
            m_log.WarnFormat("[CHILDAGENTDATAUPDATE] Unpack data");
            // DEBUG OFF

            if (args.ContainsKey("region_id"))
                UUID.TryParse(args["region_id"].AsString(), out RegionID);

            if (args["circuit_code"] != null)
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);

            if (args["agent_uuid"] != null)
                AgentID = args["agent_uuid"].AsUUID();

            if (args["session_uuid"] != null)
                SessionID = args["session_uuid"].AsUUID();

            if (args["position"] != null)
                Vector3.TryParse(args["position"].AsString(), out Position);

            if (args["velocity"] != null)
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);

            if (args["center"] != null)
                Vector3.TryParse(args["center"].AsString(), out Center);

            if (args["size"] != null)
                Vector3.TryParse(args["size"].AsString(), out Size);

            if (args["at_axis"] != null)
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);

            if (args["left_axis"] != null)
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);

            if (args["up_axis"] != null)
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);

            if (args["changed_grid"] != null)
                ChangedGrid = args["changed_grid"].AsBoolean();

            if (args["far"] != null)
                Far = (float)(args["far"].AsReal());

            if (args["aspect"] != null)
                Aspect = (float)args["aspect"].AsReal();

            if (args["throttles"] != null)
                Throttles = args["throttles"].AsBinary();

            if (args["locomotion_state"] != null)
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);

            if (args["head_rotation"] != null)
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);

            if (args["body_rotation"] != null)
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);

            if (args["control_flags"] != null)
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);

            if (args["energy_level"] != null)
                EnergyLevel = (float)(args["energy_level"].AsReal());

            //This IS checked later
            if (args["god_level"] != null)
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);

            if (args["speed"] != null)
                float.TryParse(args["speed"].AsString(), out Speed);
            else
                Speed = 1;

            if (args["draw_distance"] != null)
                float.TryParse(args["draw_distance"].AsString(), out DrawDistance);
            else
                DrawDistance = 0;

            //Reset this to fix movement... since regions are being bad about this
            if (Speed == 0)
                Speed = 1;

            if (args["always_run"] != null)
                AlwaysRun = args["always_run"].AsBoolean();

            if (args["sent_initial_wearables"] != null)
                SentInitialWearables = args["sent_initial_wearables"].AsBoolean();
            else
                SentInitialWearables = false;

            if (args["prey_agent"] != null)
                PreyAgent = args["prey_agent"].AsUUID();

            if (args["agent_access"] != null)
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);

            if (args["active_group_id"] != null)
                ActiveGroupID = args["active_group_id"].AsUUID();

            if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
            //{
            //    OSDArray textures = (OSDArray)(args["agent_textures"]);
            //    AgentTextures = new UUID[textures.Count];
            //    int i = 0;
            //    foreach (OSD o in textures)
            //        AgentTextures[i++] = o.AsUUID();
            //}

            Appearance = new AvatarAppearance(AgentID);

            // The code to unpack textures, visuals, wearables and attachments
            // should be removed; packed appearance contains the full appearance
            // This is retained for backward compatibility only
            if (args["texture_entry"] != null)
            {
                byte[] rawtextures = args["texture_entry"].AsBinary();
                Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length);
                List<UUID> changed = new List<UUID>();
                Appearance.SetTextureEntries(textures, out changed);
            }

            if (args["visual_params"] != null)
                Appearance.SetVisualParams(args["visual_params"].AsBinary());

            if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
            {
                OSDArray wears = (OSDArray)(args["wearables"]);
                for (int i = 0; i < wears.Count / 2; i++)
                {
                    AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]);
                    Appearance.SetWearable(i, awear);
                }
            }

            if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
            {
                OSDArray attachs = (OSDArray)(args["attachments"]);
                foreach (OSD o in attachs)
                {
                    if (o.Type == OSDType.Map)
                    {
                        // We know all of these must end up as attachments so we
                        // append rather than replace to ensure multiple attachments
                        // per point continues to work
                        Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
                    }
                }
            }
            // end of code to remove

            if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
                Appearance = new AvatarAppearance(AgentID, (OSDMap)args["packed_appearance"]);
            // DEBUG ON
            else
                m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
            // DEBUG OFF

            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray)(args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;
                foreach (OSD o in controls)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Controllers[i++] = new ControllerData((OSDMap)o);
                    }
                }
            }

            if (args["callback_uri"] != null)
                CallbackURI = args["callback_uri"].AsString();
        }
Esempio n. 2
0
 public void SetActiveGroupInfo(AgentGroupData activeGroup)
 {
 }
Esempio n. 3
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args)
        {
            if (args.ContainsKey("region_handle"))
                UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle);

            if (args["circuit_code"] != null)
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);

            if (args["agent_uuid"] != null)
                AgentID = args["agent_uuid"].AsUUID();

            if (args["session_uuid"] != null)
                SessionID = args["session_uuid"].AsUUID();

            if (args["position"] != null)
                Vector3.TryParse(args["position"].AsString(), out Position);

            if (args["velocity"] != null)
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);

            if (args["center"] != null)
                Vector3.TryParse(args["center"].AsString(), out Center);

            if (args["size"] != null)
                Vector3.TryParse(args["size"].AsString(), out Size);

            if (args["at_axis"] != null)
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);

            if (args["left_axis"] != null)
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);

            if (args["up_axis"] != null)
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);

            if (args["changed_grid"] != null)
                ChangedGrid = args["changed_grid"].AsBoolean();

            if (args["far"] != null)
                Far = (float)(args["far"].AsReal());

            if (args["aspect"] != null)
                Aspect = (float)args["aspect"].AsReal();

            if (args["throttles"] != null)
                Throttles = args["throttles"].AsBinary();

            if (args["locomotion_state"] != null)
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);

            if (args["head_rotation"] != null)
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);

            if (args["body_rotation"] != null)
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);

            if (args["control_flags"] != null)
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);

            if (args["energy_level"] != null)
                EnergyLevel = (float)(args["energy_level"].AsReal());

            if (args["god_level"] != null)
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);

            if (args["always_run"] != null)
                AlwaysRun = args["always_run"].AsBoolean();

            if (args["prey_agent"] != null)
                PreyAgent = args["prey_agent"].AsUUID();

            if (args["agent_access"] != null)
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);

            if (args["active_group_id"] != null)
                ActiveGroupID = args["active_group_id"].AsUUID();

            if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
            //{
            //    OSDArray textures = (OSDArray)(args["agent_textures"]);
            //    AgentTextures = new UUID[textures.Count];
            //    int i = 0;
            //    foreach (OSD o in textures)
            //        AgentTextures[i++] = o.AsUUID();
            //}

            if (args["texture_entry"] != null)
                AgentTextures = args["texture_entry"].AsBinary();

            if (args["visual_params"] != null)
                VisualParams = args["visual_params"].AsBinary();

            if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
            {
                OSDArray wears = (OSDArray)(args["wearables"]);
                Wearables = new UUID[wears.Count];
                int i = 0;
                foreach (OSD o in wears)
                    Wearables[i++] = o.AsUUID();
            }
            
            if (args["callback_uri"] != null)
                CallbackURI = args["callback_uri"].AsString();
        }
Esempio n. 4
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args)
        {
            if (args.ContainsKey("region_id"))
            {
                UUID.TryParse(args["region_id"].AsString(), out RegionID);
            }

            if (args["circuit_code"] != null)
            {
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
            }

            if (args["agent_uuid"] != null)
            {
                AgentID = args["agent_uuid"].AsUUID();
            }

            if (args["session_uuid"] != null)
            {
                SessionID = args["session_uuid"].AsUUID();
            }

            if (args["position"] != null)
            {
                Vector3.TryParse(args["position"].AsString(), out Position);
            }

            if (args["velocity"] != null)
            {
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);
            }

            if (args["center"] != null)
            {
                Vector3.TryParse(args["center"].AsString(), out Center);
            }

            if (args["size"] != null)
            {
                Vector3.TryParse(args["size"].AsString(), out Size);
            }

            if (args["at_axis"] != null)
            {
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
            }

            if (args["left_axis"] != null)
            {
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
            }

            if (args["up_axis"] != null)
            {
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
            }

            if (args["changed_grid"] != null)
            {
                ChangedGrid = args["changed_grid"].AsBoolean();
            }

            if (args["far"] != null)
            {
                Far = (float)(args["far"].AsReal());
            }

            if (args["aspect"] != null)
            {
                Aspect = (float)args["aspect"].AsReal();
            }

            if (args["throttles"] != null)
            {
                Throttles = args["throttles"].AsBinary();
            }

            if (args["locomotion_state"] != null)
            {
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
            }

            if (args["head_rotation"] != null)
            {
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
            }

            if (args["body_rotation"] != null)
            {
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
            }

            if (args["control_flags"] != null)
            {
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
            }

            if (args["energy_level"] != null)
            {
                EnergyLevel = (float)(args["energy_level"].AsReal());
            }

            if (args["god_level"] != null)
            {
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);
            }

            if (args["always_run"] != null)
            {
                AlwaysRun = args["always_run"].AsBoolean();
            }

            if (args["prey_agent"] != null)
            {
                PreyAgent = args["prey_agent"].AsUUID();
            }

            if (args["agent_access"] != null)
            {
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
            }

            if (args["active_group_id"] != null)
            {
                ActiveGroupID = args["active_group_id"].AsUUID();
            }

            if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
            //{
            //    OSDArray textures = (OSDArray)(args["agent_textures"]);
            //    AgentTextures = new UUID[textures.Count];
            //    int i = 0;
            //    foreach (OSD o in textures)
            //        AgentTextures[i++] = o.AsUUID();
            //}

            if (args["texture_entry"] != null)
            {
                AgentTextures = args["texture_entry"].AsBinary();
            }

            if (args["visual_params"] != null)
            {
                VisualParams = args["visual_params"].AsBinary();
            }

            if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
            {
                OSDArray wears = (OSDArray)(args["wearables"]);
                Wearables = new UUID[wears.Count];
                int i = 0;
                foreach (OSD o in wears)
                {
                    Wearables[i++] = o.AsUUID();
                }
            }

            if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
            {
                OSDArray attachs = (OSDArray)(args["attachments"]);
                Attachments = new AttachmentData[attachs.Count];
                int i = 0;
                foreach (OSD o in attachs)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Attachments[i++] = new AttachmentData((OSDMap)o);
                    }
                }
            }

            if (args["callback_uri"] != null)
            {
                CallbackURI = args["callback_uri"].AsString();
            }
        }
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args, IScene scene, EntityTransferContext ctx)
        {
            //m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Unpack data");

            if (args.ContainsKey("region_id"))
            {
                UUID.TryParse(args["region_id"].AsString(), out RegionID);
            }

            if (args["circuit_code"] != null)
            {
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
            }

            if (args["agent_uuid"] != null)
            {
                AgentID = args["agent_uuid"].AsUUID();
            }

            if (args["session_uuid"] != null)
            {
                SessionID = args["session_uuid"].AsUUID();
            }

            if (args["position"] != null)
            {
                Vector3.TryParse(args["position"].AsString(), out Position);
            }

            if (args["velocity"] != null)
            {
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);
            }

            if (args["center"] != null)
            {
                Vector3.TryParse(args["center"].AsString(), out Center);
            }

            if (args["size"] != null)
            {
                Vector3.TryParse(args["size"].AsString(), out Size);
            }

            if (args["at_axis"] != null)
            {
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
            }

            if (args["left_axis"] != null)
            {
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
            }

            if (args["up_axis"] != null)
            {
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
            }

            if (args.ContainsKey("wait_for_root") && args["wait_for_root"] != null)
            {
                SenderWantsToWaitForRoot = args["wait_for_root"].AsBoolean();
            }

            if (args["far"] != null)
            {
                Far = (float)(args["far"].AsReal());
            }

            if (args["aspect"] != null)
            {
                Aspect = (float)args["aspect"].AsReal();
            }

            if (args["throttles"] != null)
            {
                Throttles = args["throttles"].AsBinary();
            }

            if (args["locomotion_state"] != null)
            {
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
            }

            if (args["head_rotation"] != null)
            {
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
            }

            if (args["body_rotation"] != null)
            {
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
            }

            if (args["control_flags"] != null)
            {
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
            }

            if (args["energy_level"] != null)
            {
                EnergyLevel = (float)(args["energy_level"].AsReal());
            }

            if (args["god_level"] != null)
            {
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);
            }

            if (args["always_run"] != null)
            {
                AlwaysRun = args["always_run"].AsBoolean();
            }

            if (args["prey_agent"] != null)
            {
                PreyAgent = args["prey_agent"].AsUUID();
            }

            if (args["agent_access"] != null)
            {
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
            }

            if (args["active_group_id"] != null)
            {
                ActiveGroupID = args["active_group_id"].AsUUID();
            }

            if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if (args.ContainsKey("children_seeds") && (args["children_seeds"] != null) &&
                (args["children_seeds"].Type == OSDType.Array))
            {
                OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
                ChildrenCapSeeds = new Dictionary <ulong, string>();
                foreach (OSD o in childrenSeeds)
                {
                    if (o.Type == OSDType.Map)
                    {
                        ulong  handle = 0;
                        string seed   = "";
                        OSDMap pair   = (OSDMap)o;
                        if (pair["handle"] != null)
                        {
                            if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
                            {
                                continue;
                            }
                        }
                        if (pair["seed"] != null)
                        {
                            seed = pair["seed"].AsString();
                        }
                        if (!ChildrenCapSeeds.ContainsKey(handle))
                        {
                            ChildrenCapSeeds.Add(handle, seed);
                        }
                    }
                }
            }

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            if (args["default_animation"] != null)
            {
                try
                {
                    DefaultAnim = new Animation((OSDMap)args["default_animation"]);
                }
                catch
                {
                    DefaultAnim = null;
                }
            }

            if (args["animation_state"] != null)
            {
                try
                {
                    AnimState = new Animation((OSDMap)args["animation_state"]);
                }
                catch
                {
                    AnimState = null;
                }
            }

            MovementAnimationOverRides.Clear();

            if (args["movementAO"] != null && args["movementAO"].Type == OSDType.Array)
            {
                OSDArray AOs   = (OSDArray)(args["movementAO"]);
                int      count = AOs.Count;

                for (int i = 0; i < count; i++)
                {
                    OSDMap ao = (OSDMap)AOs[i];
                    if (ao["state"] != null && ao["uuid"] != null)
                    {
                        string state = ao["state"].AsString();
                        UUID   id    = ao["uuid"].AsUUID();
                        MovementAnimationOverRides[state] = id;
                    }
                }
            }

            if (args.ContainsKey("motion_state"))
            {
                MotionState = (byte)args["motion_state"].AsInteger();
            }

            //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
            //{
            //    OSDArray textures = (OSDArray)(args["agent_textures"]);
            //    AgentTextures = new UUID[textures.Count];
            //    int i = 0;
            //    foreach (OSD o in textures)
            //        AgentTextures[i++] = o.AsUUID();
            //}


            // packed_appearence should contain all appearance information
            if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
            {
                m_log.WarnFormat("[CHILDAGENTDATAUPDATE] got packed appearance");
                Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]);
            }
            else
            {
                // if missing try the old pack method
                m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance, checking old method");

                Appearance = new AvatarAppearance();

                // The code to unpack textures, visuals, wearables and attachments
                // should be removed; packed appearance contains the full appearance
                // This is retained for backward compatibility only
                if (args["texture_entry"] != null)
                {
                    byte[] rawtextures = args["texture_entry"].AsBinary();
                    Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length);
                    Appearance.SetTextureEntries(textures);
                }

                if (args["visual_params"] != null)
                {
                    Appearance.SetVisualParams(args["visual_params"].AsBinary());
                }

                if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
                {
                    OSDArray wears = (OSDArray)(args["wearables"]);

                    for (int i = 0; i < wears.Count / 2; i++)
                    {
                        AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]);
                        Appearance.SetWearable(i, awear);
                    }
                }

                if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
                {
                    OSDArray attachs = (OSDArray)(args["attachments"]);
                    foreach (OSD o in attachs)
                    {
                        if (o.Type == OSDType.Map)
                        {
                            // We know all of these must end up as attachments so we
                            // append rather than replace to ensure multiple attachments
                            // per point continues to work
                            //                        m_log.DebugFormat("[CHILDAGENTDATAUPDATE]: Appending attachments for {0}", AgentID);
                            Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
                        }
                    }
                }
                // end of code to remove
            }

/* moved above
 *          if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
 *              Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]);
 *          else
 *              m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
 */
            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray)(args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;
                foreach (OSD o in controls)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Controllers[i++] = new ControllerData((OSDMap)o);
                    }
                }
            }

            if (args["callback_uri"] != null)
            {
                CallbackURI = args["callback_uri"].AsString();
            }

            // Attachment objects
            if (args["attach_objects"] != null && args["attach_objects"].Type == OSDType.Array)
            {
                OSDArray attObjs = (OSDArray)(args["attach_objects"]);
                AttachmentObjects      = new List <ISceneObject>();
                AttachmentObjectStates = new List <string>();
                foreach (OSD o in attObjs)
                {
                    if (o.Type == OSDType.Map)
                    {
                        OSDMap       info = (OSDMap)o;
                        ISceneObject so   = scene.DeserializeObject(info["sog"].AsString());
                        so.ExtraFromXmlString(info["extra"].AsString());
                        so.HasGroupChanged = info["modified"].AsBoolean();
                        AttachmentObjects.Add(so);
                        AttachmentObjectStates.Add(info["state"].AsString());
                    }
                }
            }

            if (args["parent_part"] != null)
            {
                ParentPart = args["parent_part"].AsUUID();
            }
            if (args["sit_offset"] != null)
            {
                Vector3.TryParse(args["sit_offset"].AsString(), out SitOffset);
            }
        }
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args)
        {
// DEBUG ON
            m_log.WarnFormat("[CHILDAGENTDATAUPDATE] Unpack data");
// DEBUG OFF

            if (args.ContainsKey("region_id"))
            {
                UUID.TryParse(args["region_id"].AsString(), out RegionID);
            }

            if (args["circuit_code"] != null)
            {
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
            }

            if (args["agent_uuid"] != null)
            {
                AgentID = args["agent_uuid"].AsUUID();
            }

            if (args["session_uuid"] != null)
            {
                SessionID = args["session_uuid"].AsUUID();
            }

            if (args["position"] != null)
            {
                Vector3.TryParse(args["position"].AsString(), out Position);
            }

            if (args["velocity"] != null)
            {
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);
            }

            if (args["center"] != null)
            {
                Vector3.TryParse(args["center"].AsString(), out Center);
            }

            if (args["size"] != null)
            {
                Vector3.TryParse(args["size"].AsString(), out Size);
            }

            if (args["at_axis"] != null)
            {
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
            }

            if (args["left_axis"] != null)
            {
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
            }

            if (args["up_axis"] != null)
            {
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
            }

            if (args["changed_grid"] != null)
            {
                ChangedGrid = args["changed_grid"].AsBoolean();
            }

            if (args["far"] != null)
            {
                Far = (float)(args["far"].AsReal());
            }

            if (args["aspect"] != null)
            {
                Aspect = (float)args["aspect"].AsReal();
            }

            if (args["throttles"] != null)
            {
                Throttles = args["throttles"].AsBinary();
            }

            if (args["locomotion_state"] != null)
            {
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
            }

            if (args["head_rotation"] != null)
            {
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
            }

            if (args["body_rotation"] != null)
            {
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
            }

            if (args["control_flags"] != null)
            {
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
            }

            if (args["energy_level"] != null)
            {
                EnergyLevel = (float)(args["energy_level"].AsReal());
            }

            if (args["god_level"] != null)
            {
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);
            }

            if (args["always_run"] != null)
            {
                AlwaysRun = args["always_run"].AsBoolean();
            }

            if (args["prey_agent"] != null)
            {
                PreyAgent = args["prey_agent"].AsUUID();
            }

            if (args["agent_access"] != null)
            {
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
            }

            if (args["active_group_id"] != null)
            {
                ActiveGroupID = args["active_group_id"].AsUUID();
            }

            if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
            //{
            //    OSDArray textures = (OSDArray)(args["agent_textures"]);
            //    AgentTextures = new UUID[textures.Count];
            //    int i = 0;
            //    foreach (OSD o in textures)
            //        AgentTextures[i++] = o.AsUUID();
            //}

            Appearance = new AvatarAppearance(AgentID);

            // The code to unpack textures, visuals, wearables and attachments
            // should be removed; packed appearance contains the full appearance
            // This is retained for backward compatibility only
            if (args["texture_entry"] != null)
            {
                byte[] rawtextures = args["texture_entry"].AsBinary();
                Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length);
                Appearance.SetTextureEntries(textures);
            }

            if (args["visual_params"] != null)
            {
                Appearance.SetVisualParams(args["visual_params"].AsBinary());
            }

            if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
            {
                OSDArray wears = (OSDArray)(args["wearables"]);
                for (int i = 0; i < wears.Count / 2; i++)
                {
                    AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]);
                    Appearance.SetWearable(i, awear);
                }
            }

            if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
            {
                OSDArray attachs = (OSDArray)(args["attachments"]);
                foreach (OSD o in attachs)
                {
                    if (o.Type == OSDType.Map)
                    {
                        // We know all of these must end up as attachments so we
                        // append rather than replace to ensure multiple attachments
                        // per point continues to work
                        Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
                    }
                }
            }
            // end of code to remove

            if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
            {
                Appearance = new AvatarAppearance(AgentID, (OSDMap)args["packed_appearance"]);
            }
// DEBUG ON
            else
            {
                m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
            }
// DEBUG OFF

            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray)(args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;
                foreach (OSD o in controls)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Controllers[i++] = new ControllerData((OSDMap)o);
                    }
                }
            }

            if (args["callback_uri"] != null)
            {
                CallbackURI = args["callback_uri"].AsString();
            }
        }
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args, IScene scene, EntityTransferContext ctx)
        {
            //m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Unpack data");

            if (args.ContainsKey("region_id"))
                UUID.TryParse(args["region_id"].AsString(), out RegionID);

            if (args["circuit_code"] != null)
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);

            if (args["agent_uuid"] != null)
                AgentID = args["agent_uuid"].AsUUID();

            if (args["session_uuid"] != null)
                SessionID = args["session_uuid"].AsUUID();

            if (args["position"] != null)
                Vector3.TryParse(args["position"].AsString(), out Position);

            if (args["velocity"] != null)
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);

            if (args["center"] != null)
                Vector3.TryParse(args["center"].AsString(), out Center);

            if (args["size"] != null)
                Vector3.TryParse(args["size"].AsString(), out Size);

            if (args["at_axis"] != null)
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);

            if (args["left_axis"] != null)
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);

            if (args["up_axis"] != null)
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);

            if (args.ContainsKey("wait_for_root") && args["wait_for_root"] != null)
                SenderWantsToWaitForRoot = args["wait_for_root"].AsBoolean();

            if (args["far"] != null)
                Far = (float)(args["far"].AsReal());

            if (args["aspect"] != null)
                Aspect = (float)args["aspect"].AsReal();

            if (args["throttles"] != null)
                Throttles = args["throttles"].AsBinary();

            if (args["locomotion_state"] != null)
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);

            if (args["head_rotation"] != null)
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);

            if (args["body_rotation"] != null)
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);

            if (args["control_flags"] != null)
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);

            if (args["energy_level"] != null)
                EnergyLevel = (float)(args["energy_level"].AsReal());

            if (args["god_level"] != null)
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);

            if (args["always_run"] != null)
                AlwaysRun = args["always_run"].AsBoolean();

            if (args["prey_agent"] != null)
                PreyAgent = args["prey_agent"].AsUUID();

            if (args["agent_access"] != null)
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);

            if (args.ContainsKey("agent_cof") && args["agent_cof"] != null)
                agentCOF = args["agent_cof"].AsUUID();

            if (args.ContainsKey("crossingflags") && args["crossingflags"] != null)
                CrossingFlags = (byte)args["crossingflags"].AsInteger();

            if (args.ContainsKey("active_group_id") && args["active_group_id"] != null)
                ActiveGroupID = args["active_group_id"].AsUUID();

            if (args.ContainsKey("active_group_name") && args["active_group_name"] != null)
                ActiveGroupName = args["active_group_name"].AsString();
            
            if(args.ContainsKey("active_group_title") && args["active_group_title"] != null)
                ActiveGroupTitle = args["active_group_title"].AsString();

            if (args.ContainsKey("groups") && (args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if (args.ContainsKey("children_seeds") && (args["children_seeds"] != null) &&
                            (args["children_seeds"].Type == OSDType.Array))
            {
                OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
                ChildrenCapSeeds = new Dictionary<ulong, string>();
                foreach (OSD o in childrenSeeds)
                {
                    if (o.Type == OSDType.Map)
                    {
                        ulong handle = 0;
                        string seed = "";
                        OSDMap pair = (OSDMap)o;
                        if (pair["handle"] != null)
                            if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
                                continue;
                        if (pair["seed"] != null)
                            seed = pair["seed"].AsString();
                        if (!ChildrenCapSeeds.ContainsKey(handle))
                            ChildrenCapSeeds.Add(handle, seed);
                    }
                }
            }

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            if (args["default_animation"] != null)
            {
                try
                {
                    DefaultAnim = new Animation((OSDMap)args["default_animation"]);
                }
                catch
                {
                    DefaultAnim = null;
                }
            }

            if (args["animation_state"] != null)
            {
                try
                {
                    AnimState = new Animation((OSDMap)args["animation_state"]);
                }
                catch
                {
                    AnimState = null;
                }
            }

            MovementAnimationOverRides.Clear();

            if (args["movementAO"] != null && args["movementAO"].Type == OSDType.Array)
            {
                OSDArray AOs = (OSDArray)(args["movementAO"]);
                int count = AOs.Count;

                for (int i = 0; i < count; i++)
                {
                    OSDMap ao = (OSDMap)AOs[i];
                    if (ao["state"] != null && ao["uuid"] != null)
                    {
                        string state = ao["state"].AsString();
                        UUID id = ao["uuid"].AsUUID();
                        MovementAnimationOverRides[state] = id;
                    }
                }
            }

            if (args.ContainsKey("motion_state"))
                MotionState = (byte)args["motion_state"].AsInteger();

            //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
            //{
            //    OSDArray textures = (OSDArray)(args["agent_textures"]);
            //    AgentTextures = new UUID[textures.Count];
            //    int i = 0;
            //    foreach (OSD o in textures)
            //        AgentTextures[i++] = o.AsUUID();
            //}


            // packed_appearence should contain all appearance information
            if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
            {
                m_log.WarnFormat("[CHILDAGENTDATAUPDATE] got packed appearance");
                Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]);
            }
            else
            {
                // if missing try the old pack method
                m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance, checking old method");

                Appearance = new AvatarAppearance();

                // The code to unpack textures, visuals, wearables and attachments
                // should be removed; packed appearance contains the full appearance
                // This is retained for backward compatibility only
                if (args["texture_entry"] != null)
                {
                    byte[] rawtextures = args["texture_entry"].AsBinary();
                    Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length);
                    Appearance.SetTextureEntries(textures);
                }

                if (args["visual_params"] != null)
                    Appearance.SetVisualParams(args["visual_params"].AsBinary());

                if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
                {
                    OSDArray wears = (OSDArray)(args["wearables"]);

                    for (int i = 0; i < wears.Count / 2; i++)
                    {
                        AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]);
                        Appearance.SetWearable(i, awear);
                    }
                }

                if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
                {
                    OSDArray attachs = (OSDArray)(args["attachments"]);
                    foreach (OSD o in attachs)
                    {
                        if (o.Type == OSDType.Map)
                        {
                            // We know all of these must end up as attachments so we
                            // append rather than replace to ensure multiple attachments
                            // per point continues to work
                            //                        m_log.DebugFormat("[CHILDAGENTDATAUPDATE]: Appending attachments for {0}", AgentID);
                            Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
                        }
                    }
                }
                // end of code to remove
            }
/* moved above
            if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
                Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]);
            else
                m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
*/
            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray)(args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;
                foreach (OSD o in controls)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Controllers[i++] = new ControllerData((OSDMap)o);
                    }
                }
            }

            if (args["callback_uri"] != null)
                CallbackURI = args["callback_uri"].AsString();

            // Attachment objects
            if (args["attach_objects"] != null && args["attach_objects"].Type == OSDType.Array)
            {
                OSDArray attObjs = (OSDArray)(args["attach_objects"]);
                AttachmentObjects = new List<ISceneObject>();
                AttachmentObjectStates = new List<string>();
                foreach (OSD o in attObjs)
                {
                    if (o.Type == OSDType.Map)
                    {
                        OSDMap info = (OSDMap)o;
                        ISceneObject so = scene.DeserializeObject(info["sog"].AsString());
                        so.ExtraFromXmlString(info["extra"].AsString());
                        so.HasGroupChanged = info["modified"].AsBoolean();
                        AttachmentObjects.Add(so);
                        AttachmentObjectStates.Add(info["state"].AsString());
                    }
                }
            }

            if (args["parent_part"] != null)
                ParentPart = args["parent_part"].AsUUID();
            if (args["sit_offset"] != null)
                Vector3.TryParse(args["sit_offset"].AsString(), out SitOffset);
        }
Esempio n. 8
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args)
        {
            if (args.ContainsKey("region_handle"))
            {
                UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle);
            }

            if (args.ContainsKey("circuit_code"))
            {
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
            }

            if (args.ContainsKey("agent_uuid"))
            {
                AgentID = args["agent_uuid"].AsUUID();
            }

            if (args.ContainsKey("session_uuid"))
            {
                SessionID = args["session_uuid"].AsUUID();
            }

            if (args.ContainsKey("position"))
            {
                Vector3.TryParse(args["position"].AsString(), out Position);
            }

            if (args.ContainsKey("velocity"))
            {
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);
            }

            if (args.ContainsKey("center"))
            {
                Vector3.TryParse(args["center"].AsString(), out Center);
            }

            if (args.ContainsKey("size"))
            {
                Vector3.TryParse(args["size"].AsString(), out Size);
            }

            if (args.ContainsKey("at_axis"))
            {
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
            }

            if (args.ContainsKey("left_axis"))
            {
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
            }

            if (args.ContainsKey("up_axis"))
            {
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
            }

            if (args.ContainsKey("changed_grid"))
            {
                ChangedGrid = args["changed_grid"].AsBoolean();
            }

            if (args.ContainsKey("far"))
            {
                Far = (float)(args["far"].AsReal());
            }

            if (args.ContainsKey("aspect"))
            {
                Aspect = (float)args["aspect"].AsReal();
            }

            if (args.ContainsKey("throttles"))
            {
                Throttles = args["throttles"].AsBinary();
            }

            if (args.ContainsKey("locomotion_state"))
            {
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
            }

            if (args.ContainsKey("head_rotation"))
            {
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
            }

            if (args.ContainsKey("body_rotation"))
            {
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
            }

            if (args.ContainsKey("control_flags"))
            {
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
            }

            if (args.ContainsKey("energy_level"))
            {
                EnergyLevel = (float)(args["energy_level"].AsReal());
            }

            if (args.ContainsKey("god_level"))
            {
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);
            }

            if (args.ContainsKey("always_run"))
            {
                AlwaysRun = args["always_run"].AsBoolean();
            }

            if (args.ContainsKey("prey_agent"))
            {
                PreyAgent = args["prey_agent"].AsUUID();
            }

            if (args.ContainsKey("agent_access"))
            {
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
            }

            if (args.ContainsKey("active_group_id"))
            {
                ActiveGroupID = args["active_group_id"].AsUUID();
            }

            if ((args.ContainsKey("groups")) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args.ContainsKey("animations")) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            // Initialize an Appearance
            Appearance = new AvatarAppearance(AgentID);

            if (args.ContainsKey("texture_entry"))
            {
                byte[] data = args["texture_entry"].AsBinary();
                Primitive.TextureEntry textureEntries = new Primitive.TextureEntry(data, 0, data.Length);
                Appearance.SetTextureEntries(textureEntries);
            }

            if (args.ContainsKey("visual_params"))
            {
                byte[] visualParams = args["visual_params"].AsBinary();
                Appearance.SetVisualParams(visualParams);
            }

            if ((args.ContainsKey("wearables")) && (args["wearables"]).Type == OSDType.Array)
            {
                OSDArray wears = (OSDArray)(args["wearables"]);
                List <AvatarWearable> wearables = new List <AvatarWearable>();

                int offset = 0;
                for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++)
                {
                    if ((offset + 1) < wears.Count)
                    {
                        UUID itemID  = wears[offset++].AsUUID();
                        UUID assetID = wears[offset++].AsUUID();
                        wearables.Add(new AvatarWearable(i, itemID, assetID));
                    }
                    else
                    {
                        break;
                    }
                }

                Appearance.SetWearables(wearables);
            }

            if (args.ContainsKey("callback_uri"))
            {
                CallbackURI = args["callback_uri"].AsString();
            }

            if (args.ContainsKey("sat_on_group"))
            {
                SatOnGroup = args["sat_on_group"].AsUUID();
                SatOnPrim  = args["sat_on_prim"].AsUUID();
                try
                {
                    // "sit_offset" previously used OSD.FromVector3(vec) was used to store the data.
                    // Other Vector3 storage uses OSD.FromString(vec.ToString()).
                    // If originating from old region code, that will still be the case
                    // and the TryParse will trigger a format exception.
                    Vector3.TryParse(args["sit_offset"].ToString(), out SatOnPrimOffset);
                }
                catch (Exception)
                {
                    // The following is compatible with OSD.FromVector3(vec), since Vector3.TryParse is not.
                    SatOnPrimOffset = args["sit_offset"].AsVector3();
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args, IScene scene)
        {
            //m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Unpack data");

            if (args.ContainsKey("region_id"))
                UUID.TryParse(args["region_id"].AsString(), out RegionID);

            if (args["circuit_code"] != null)
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);

            if (args["agent_uuid"] != null)
                AgentID = args["agent_uuid"].AsUUID();

            if (args["session_uuid"] != null)
                SessionID = args["session_uuid"].AsUUID();

            if (args["position"] != null)
                Vector3.TryParse(args["position"].AsString(), out Position);

            if (args["velocity"] != null)
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);

            if (args["center"] != null)
                Vector3.TryParse(args["center"].AsString(), out Center);

            if (args["size"] != null)
                Vector3.TryParse(args["size"].AsString(), out Size);

            if (args["at_axis"] != null)
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);

            if (args["left_axis"] != null)
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);

            if (args["up_axis"] != null)
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);

            if (args["changed_grid"] != null)
                ChangedGrid = args["changed_grid"].AsBoolean();

            if (args["far"] != null)
                Far = (float)(args["far"].AsReal());

            if (args["aspect"] != null)
                Aspect = (float)args["aspect"].AsReal();

            if (args["throttles"] != null)
                Throttles = args["throttles"].AsBinary();

            if (args["locomotion_state"] != null)
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);

            if (args["head_rotation"] != null)
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);

            if (args["body_rotation"] != null)
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);

            if (args["control_flags"] != null)
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);

            if (args["energy_level"] != null)
                EnergyLevel = (float)(args["energy_level"].AsReal());

            if (args["god_level"] != null)
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);

            if (args["always_run"] != null)
                AlwaysRun = args["always_run"].AsBoolean();

            if (args["prey_agent"] != null)
                PreyAgent = args["prey_agent"].AsUUID();

            if (args["agent_access"] != null)
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);

            if (args["active_group_id"] != null)
                ActiveGroupID = args["active_group_id"].AsUUID();

            if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
            //{
            //    OSDArray textures = (OSDArray)(args["agent_textures"]);
            //    AgentTextures = new UUID[textures.Count];
            //    int i = 0;
            //    foreach (OSD o in textures)
            //        AgentTextures[i++] = o.AsUUID();
            //}

            Appearance = new AvatarAppearance();

            // The code to unpack textures, visuals, wearables and attachments
            // should be removed; packed appearance contains the full appearance
            // This is retained for backward compatibility only
            if (args["texture_entry"] != null)
            {
                byte[] rawtextures = args["texture_entry"].AsBinary();
                Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures,0,rawtextures.Length);
                Appearance.SetTextureEntries(textures);
            }

            if (args["visual_params"] != null)
                Appearance.SetVisualParams(args["visual_params"].AsBinary());

            if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array)
            {
                OSDArray wears = (OSDArray)(args["wearables"]);
                for (int i = 0; i < wears.Count / 2; i++) 
                {
                    AvatarWearable awear = new AvatarWearable((OSDArray)wears[i]);
                    Appearance.SetWearable(i,awear);
                }
            }

            if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
            {
                OSDArray attachs = (OSDArray)(args["attachments"]);
                foreach (OSD o in attachs)
                {
                    if (o.Type == OSDType.Map)
                    {
                        // We know all of these must end up as attachments so we
                        // append rather than replace to ensure multiple attachments
                        // per point continues to work
//                        m_log.DebugFormat("[CHILDAGENTDATAUPDATE]: Appending attachments for {0}", AgentID);
                        Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
                    }
                }
            }
            // end of code to remove

            if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
                Appearance = new AvatarAppearance((OSDMap)args["packed_appearance"]);
            else
                m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");

            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray)(args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;
                foreach (OSD o in controls)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Controllers[i++] = new ControllerData((OSDMap)o);
                    }
                }
            }

            if (args["callback_uri"] != null)
                CallbackURI = args["callback_uri"].AsString();

            // Attachment objects
            if (args["attach_objects"] != null && args["attach_objects"].Type == OSDType.Array)
            {
                OSDArray attObjs = (OSDArray)(args["attach_objects"]);
                AttachmentObjects = new List<ISceneObject>();
                AttachmentObjectStates = new List<string>();
                foreach (OSD o in attObjs)
                {
                    if (o.Type == OSDType.Map)
                    {
                        OSDMap info = (OSDMap)o;
                        ISceneObject so = scene.DeserializeObject(info["sog"].AsString());
                        so.ExtraFromXmlString(info["extra"].AsString());
                        so.HasGroupChanged = info["modified"].AsBoolean();
                        AttachmentObjects.Add(so);
                        AttachmentObjectStates.Add(info["state"].AsString());
                    }
                }
            }
        }
Esempio n. 10
0
        public void CopyTo(AgentData cAgent, bool isCrossUpdate)
        {
            cAgent.CallbackURI = m_callbackURI;

            cAgent.AgentID = UUID;
            cAgent.RegionID = Scene.RegionInfo.RegionID;
            cAgent.SessionID = ControllingClient.SessionId;

            cAgent.Position = AbsolutePosition;
            cAgent.Velocity = m_velocity;
            cAgent.Center = CameraPosition;
            cAgent.AtAxis = CameraAtAxis;
            cAgent.LeftAxis = CameraLeftAxis;
            cAgent.UpAxis = CameraUpAxis;

            cAgent.Far = DrawDistance;

            // Throttles 
            cAgent.Throttles = ControllingClient.GetThrottlesPacked(1);

            cAgent.HeadRotation = m_headrotation;
            cAgent.BodyRotation = Rotation;
            cAgent.ControlFlags = (uint)m_AgentControlFlags;

            if (m_scene.Permissions.IsGod(new UUID(cAgent.AgentID)))
                cAgent.GodLevel = (byte)GodLevel;
            else
                cAgent.GodLevel = (byte)0;

            cAgent.AlwaysRun = SetAlwaysRun;

            // make clear we want the all thing
            cAgent.Appearance = new AvatarAppearance(Appearance, true, true);

            cAgent.ParentPart = ParentUUID;
            cAgent.SitOffset = PrevSitOffset;

            lock (scriptedcontrols)
            {
                ControllerData[] controls = new ControllerData[scriptedcontrols.Count];
                int i = 0;

                foreach (ScriptControllers c in scriptedcontrols.Values)
                {
                    controls[i++] = new ControllerData(c.objectID, c.itemID, (uint)c.ignoreControls, (uint)c.eventControls);
                }
                cAgent.Controllers = controls;
            }

            // Animations
            try
            {
                cAgent.Anims = Animator.Animations.ToArray();
            }
            catch { }
            cAgent.DefaultAnim = Animator.Animations.DefaultAnimation;
            cAgent.AnimState = Animator.Animations.ImplicitDefaultAnimation;

            cAgent.MovementAnimationOverRides = Overrides.CloneAOPairs();

            cAgent.MotionState = (byte)Animator.currentControlState;

            if (Scene.AttachmentsModule != null)
                Scene.AttachmentsModule.CopyAttachments(this, cAgent);

            if (isCrossUpdate)
            {
                cAgent.CrossingFlags = crossingFlags;
                cAgent.CrossingFlags |= 1;
            }
            else
                cAgent.CrossingFlags = 0;

            if (isCrossUpdate && haveGroupInformation)
            {
                cAgent.agentCOF = COF;
                cAgent.ActiveGroupID = ControllingClient.ActiveGroupId;
                cAgent.ActiveGroupName = ControllingClient.ActiveGroupName;
                cAgent.ActiveGroupTitle = Grouptitle;
                Dictionary<UUID, ulong> gpowers = ControllingClient.GetGroupPowers();
                if (gpowers.Count > 0)
                {
                    cAgent.Groups = new AgentGroupData[gpowers.Count];
                    int i = 0;
                    foreach (UUID gid in gpowers.Keys)
                    {
                        // WARNING we dont' have AcceptNotices in cache.. sending as true mb no one notices ;)
                        AgentGroupData agd = new AgentGroupData(gid, gpowers[gid], true);
                        cAgent.Groups[i++] = agd;
                    }
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args)
        {
            // DEBUG ON
            //m_log.WarnFormat("[CHILDAGENTDATAUPDATE] Unpack data");
            // DEBUG OFF

            if (args.ContainsKey("region_id"))
                UUID.TryParse(args["region_id"].AsString(), out RegionID);

            if (args["circuit_code"] != null)
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);

            if (args["agent_uuid"] != null)
                AgentID = args["agent_uuid"].AsUUID();

            if (args["session_uuid"] != null)
                SessionID = args["session_uuid"].AsUUID();

            if (args["position"] != null)
                Vector3.TryParse(args["position"].AsString(), out Position);

            if (args["velocity"] != null)
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);

            if (args["center"] != null)
                Vector3.TryParse(args["center"].AsString(), out Center);

            if (args["size"] != null)
                Vector3.TryParse(args["size"].AsString(), out Size);

            if (args["at_axis"] != null)
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);

            if (args["left_axis"] != null)
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);

            if (args["up_axis"] != null)
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);

            if (args["far"] != null)
                Far = (float)(args["far"].AsReal());

            if (args["aspect"] != null)
                Aspect = (float)args["aspect"].AsReal();

            if (args["throttles"] != null)
                Throttles = args["throttles"].AsBinary();

            if (args["locomotion_state"] != null)
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);

            if (args["head_rotation"] != null)
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);

            if (args["body_rotation"] != null)
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);

            if (args["control_flags"] != null)
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);

            if (args["energy_level"] != null)
                EnergyLevel = (float)(args["energy_level"].AsReal());

            //This IS checked later
            if (args["god_level"] != null)
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);

            if (args["speed"] != null)
                float.TryParse(args["speed"].AsString(), out Speed);
            else
                Speed = 1;

            if (args["draw_distance"] != null)
                float.TryParse(args["draw_distance"].AsString(), out DrawDistance);
            else
                DrawDistance = 0;

            //Reset this to fix movement... since regions are being bad about this
            if (Speed == 0)
                Speed = 1;

            if (args["always_run"] != null)
                AlwaysRun = args["always_run"].AsBoolean();

            if (args["sent_initial_wearables"] != null)
                SentInitialWearables = args["sent_initial_wearables"].AsBoolean();
            else
                SentInitialWearables = false;

            if (args["prey_agent"] != null)
                PreyAgent = args["prey_agent"].AsUUID();

            if (args["callback_uri"] != null)
                CallbackURI = args["callback_uri"].AsString();

            if (args["agent_access"] != null)
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);

            if (args["active_group_id"] != null)
                ActiveGroupID = args["active_group_id"].AsUUID();

            if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            Appearance = new AvatarAppearance(AgentID);

            try
            {
                if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
                    Appearance = new AvatarAppearance(AgentID, (OSDMap)args["packed_appearance"]);
                // DEBUG ON
                else
                    m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
                // DEBUG OFF
            }
            catch
            {
            }

            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray)(args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;
                foreach (OSD o in controls)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Controllers[i++] = new ControllerData((OSDMap)o);
                    }
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args)
        {
            if (args.ContainsKey("region_handle"))
                UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle);

            if (args.ContainsKey("circuit_code"))
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);

            if (args.ContainsKey("agent_uuid"))
                AgentID = args["agent_uuid"].AsUUID();

            if (args.ContainsKey("session_uuid"))
                SessionID = args["session_uuid"].AsUUID();

            if (args.ContainsKey("position"))
                Vector3.TryParse(args["position"].AsString(), out Position);

            if (args.ContainsKey("velocity"))
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);

            if (args.ContainsKey("center"))
                Vector3.TryParse(args["center"].AsString(), out Center);

            if (args.ContainsKey("size"))
                Vector3.TryParse(args["size"].AsString(), out Size);

            if (args.ContainsKey("at_axis"))
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);

            if (args.ContainsKey("left_axis"))
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);

            if (args.ContainsKey("up_axis"))
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);

            if (args.ContainsKey("changed_grid"))
                ChangedGrid = args["changed_grid"].AsBoolean();

            if (args.ContainsKey("far"))
                Far = (float)(args["far"].AsReal());

            if (args.ContainsKey("aspect"))
                Aspect = (float)args["aspect"].AsReal();

            if (args.ContainsKey("throttles"))
                Throttles = args["throttles"].AsBinary();

            if (args.ContainsKey("locomotion_state"))
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);

            if (args.ContainsKey("head_rotation"))
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);

            if (args.ContainsKey("body_rotation"))
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);

            if (args.ContainsKey("control_flags"))
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);

            if (args.ContainsKey("energy_level"))
                EnergyLevel = (float)(args["energy_level"].AsReal());

            if (args.ContainsKey("god_level"))
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);

            if (args.ContainsKey("always_run"))
                AlwaysRun = args["always_run"].AsBoolean();

            if (args.ContainsKey("prey_agent"))
                PreyAgent = args["prey_agent"].AsUUID();

            if (args.ContainsKey("agent_access"))
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);

            if (args.ContainsKey("active_group_id"))
                ActiveGroupID = args["active_group_id"].AsUUID();

            if ((args.ContainsKey("groups")) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args.ContainsKey("animations")) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            // Initialize an Appearance
            Appearance = new AvatarAppearance(AgentID);

            if (args.ContainsKey("texture_entry"))
            {
                byte[] data = args["texture_entry"].AsBinary();
                Primitive.TextureEntry textureEntries = new Primitive.TextureEntry(data, 0, data.Length);
                Appearance.SetTextureEntries(textureEntries);
            }

            if (args.ContainsKey("visual_params"))
            {
                byte[] visualParams = args["visual_params"].AsBinary();
                Appearance.SetVisualParams(visualParams);
            }

            if ((args.ContainsKey("wearables")) && (args["wearables"]).Type == OSDType.Array)
            {
                OSDArray wears = (OSDArray)(args["wearables"]);
                List<AvatarWearable> wearables = new List<AvatarWearable>();

                int offset = 0;
                for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++)
                {
                    if ((offset + 1) < wears.Count)
                    {
                        UUID itemID = wears[offset++].AsUUID();
                        UUID assetID = wears[offset++].AsUUID();
                        wearables.Add(new AvatarWearable(i, itemID, assetID));
                    }
                    else
                    {
                        break;
                    }
                }

                Appearance.SetWearables(wearables);
            }

            if (args.ContainsKey("callback_uri"))
                CallbackURI = args["callback_uri"].AsString();

            if (args.ContainsKey("avatar_as_a_prim"))
                AvatarAsAPrim = args["avatar_as_a_prim"].AsBoolean();

            if (args.ContainsKey("sat_on_group"))
            {
                SatOnGroup = args["sat_on_group"].AsUUID();
                SatOnPrim = args["sat_on_prim"].AsUUID();
                try
                {
                    // "sit_offset" previously used OSD.FromVector3(vec) was used to store the data.
                    // Other Vector3 storage uses OSD.FromString(vec.ToString()).
                    // If originating from old region code, that will still be the case
                    // and the TryParse will trigger a format exception.
                    Vector3.TryParse(args["sit_offset"].ToString(), out SatOnPrimOffset);
                }
                catch (Exception)
                {
                    // The following is compatible with OSD.FromVector3(vec), since Vector3.TryParse is not.
                    SatOnPrimOffset = args["sit_offset"].AsVector3();
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args, IScene scene)
        {
            if (m_log.IsDebugEnabled)
            {
                m_log.DebugFormat("{0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
            }

            if (args.ContainsKey("region_id"))
            {
                UUID.TryParse(args ["region_id"].AsString(), out RegionID);
            }

            if (args ["circuit_code"] != null)
            {
                UInt32.TryParse((string)args ["circuit_code"].AsString(), out CircuitCode);
            }

            if (args ["agent_uuid"] != null)
            {
                AgentID = args ["agent_uuid"].AsUUID();
            }

            if (args ["session_uuid"] != null)
            {
                SessionID = args ["session_uuid"].AsUUID();
            }

            if (args ["position"] != null)
            {
                Vector3.TryParse(args ["position"].AsString(), out Position);
            }

            if (args ["velocity"] != null)
            {
                Vector3.TryParse(args ["velocity"].AsString(), out Velocity);
            }

            if (args ["center"] != null)
            {
                Vector3.TryParse(args ["center"].AsString(), out Center);
            }

            if (args ["size"] != null)
            {
                Vector3.TryParse(args ["size"].AsString(), out Size);
            }

            if (args ["at_axis"] != null)
            {
                Vector3.TryParse(args ["at_axis"].AsString(), out AtAxis);
            }

            if (args ["left_axis"] != null)
            {
                Vector3.TryParse(args ["left_axis"].AsString(), out AtAxis);
            }

            if (args ["up_axis"] != null)
            {
                Vector3.TryParse(args ["up_axis"].AsString(), out AtAxis);
            }

            if (args.ContainsKey("wait_for_root") && args ["wait_for_root"] != null)
            {
                SenderWantsToWaitForRoot = args ["wait_for_root"].AsBoolean();
            }

            if (args ["far"] != null)
            {
                Far = (float)(args ["far"].AsReal());
            }

            if (args ["aspect"] != null)
            {
                Aspect = (float)args ["aspect"].AsReal();
            }

            if (args ["throttles"] != null)
            {
                Throttles = args ["throttles"].AsBinary();
            }

            if (args ["locomotion_state"] != null)
            {
                UInt32.TryParse(args ["locomotion_state"].AsString(), out LocomotionState);
            }

            if (args ["head_rotation"] != null)
            {
                Quaternion.TryParse(args ["head_rotation"].AsString(), out HeadRotation);
            }

            if (args ["body_rotation"] != null)
            {
                Quaternion.TryParse(args ["body_rotation"].AsString(), out BodyRotation);
            }

            if (args ["control_flags"] != null)
            {
                UInt32.TryParse(args ["control_flags"].AsString(), out ControlFlags);
            }

            if (args ["energy_level"] != null)
            {
                EnergyLevel = (float)(args ["energy_level"].AsReal());
            }

            if (args ["god_level"] != null)
            {
                Byte.TryParse(args ["god_level"].AsString(), out GodLevel);
            }

            if (args ["always_run"] != null)
            {
                AlwaysRun = args ["always_run"].AsBoolean();
            }

            if (args ["prey_agent"] != null)
            {
                PreyAgent = args ["prey_agent"].AsUUID();
            }

            if (args ["agent_access"] != null)
            {
                Byte.TryParse(args ["agent_access"].AsString(), out AgentAccess);
            }

            if (args ["active_group_id"] != null)
            {
                ActiveGroupID = args ["active_group_id"].AsUUID();
            }

            if ((args ["groups"] != null) && (args ["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args ["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups [i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args ["animations"] != null) && (args ["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args ["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims [i++] = new Animation((OSDMap)o);
                    }
                }
            }

            if (args ["default_animation"] != null)
            {
                try {
                    DefaultAnim = new Animation((OSDMap)args ["default_animation"]);
                } catch {
                    DefaultAnim = null;
                }
            }

            if (args ["animation_state"] != null)
            {
                try {
                    AnimState = new Animation((OSDMap)args ["animation_state"]);
                } catch {
                    AnimState = null;
                }
            }

            //if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array)
            //{
            //    OSDArray textures = (OSDArray)(args["agent_textures"]);
            //    AgentTextures = new UUID[textures.Count];
            //    int i = 0;
            //    foreach (OSD o in textures)
            //        AgentTextures[i++] = o.AsUUID();
            //}

            Appearance = new AvatarAppearance();

            // The code to unpack textures, visuals, wearables and attachments
            // should be removed; packed appearance contains the full appearance
            // This is retained for backward compatibility only
            if (args ["texture_entry"] != null)
            {
                byte[] rawtextures = args ["texture_entry"].AsBinary();
                Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures, 0, rawtextures.Length);
                Appearance.SetTextureEntries(textures);
            }

            if (args ["visual_params"] != null)
            {
                Appearance.SetVisualParams(args ["visual_params"].AsBinary());
            }

            if ((args ["wearables"] != null) && (args ["wearables"]).Type == OSDType.Array)
            {
                OSDArray wears = (OSDArray)(args ["wearables"]);
                for (int i = 0; i < wears.Count / 2; i++)
                {
                    AvatarWearable awear = new AvatarWearable((OSDArray)wears [i]);
                    Appearance.SetWearable(i, awear);
                }
            }

            if ((args ["attachments"] != null) && (args ["attachments"]).Type == OSDType.Array)
            {
                OSDArray attachs = (OSDArray)(args ["attachments"]);
                foreach (OSD o in attachs)
                {
                    if (o.Type == OSDType.Map)
                    {
                        // We know all of these must end up as attachments so we
                        // append rather than replace to ensure multiple attachments
                        // per point continues to work
//                        m_log.DebugFormat("[CHILDAGENTDATAUPDATE]: Appending attachments for {0}", AgentID);
                        Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
                    }
                }
            }
            // end of code to remove

            if (args.ContainsKey("packed_appearance") && (args ["packed_appearance"]).Type == OSDType.Map)
            {
                Appearance = new AvatarAppearance((OSDMap)args ["packed_appearance"]);
            }
            else
            {
                m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
            }

            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray)(args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;
                foreach (OSD o in controls)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Controllers[i++] = new ControllerData((OSDMap)o);
                    }
                }
            }

            if (args["callback_uri"] != null)
            {
                CallbackURI = args["callback_uri"].AsString();
            }

            // Attachment objects
            if (args["attach_objects"] != null && args["attach_objects"].Type == OSDType.Array)
            {
                OSDArray attObjs = (OSDArray)(args["attach_objects"]);
                AttachmentObjects      = new List <ISceneObject>();
                AttachmentObjectStates = new List <string>();
                foreach (OSD o in attObjs)
                {
                    if (o.Type == OSDType.Map)
                    {
                        OSDMap       info = (OSDMap)o;
                        ISceneObject so   = scene.DeserializeObject(info["sog"].AsString());
                        so.ExtraFromXmlString(info["extra"].AsString());
                        so.HasGroupChanged = info["modified"].AsBoolean();
                        AttachmentObjects.Add(so);
                        AttachmentObjectStates.Add(info["state"].AsString());
                    }
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Deserialization of agent data.
        /// Avoiding reflection makes it painful to write, but that's the price!
        /// </summary>
        /// <param name="hash"></param>
        public virtual void Unpack(OSDMap args)
        {
            // DEBUG ON
            //m_log.WarnFormat("[CHILDAGENTDATAUPDATE] Unpack data");
            // DEBUG OFF

            if (args.ContainsKey("region_id"))
            {
                UUID.TryParse(args["region_id"].AsString(), out RegionID);
            }

            if (args["circuit_code"] != null)
            {
                UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode);
            }

            if (args["agent_uuid"] != null)
            {
                AgentID = args["agent_uuid"].AsUUID();
            }

            if (args["session_uuid"] != null)
            {
                SessionID = args["session_uuid"].AsUUID();
            }

            if (args["position"] != null)
            {
                Vector3.TryParse(args["position"].AsString(), out Position);
            }

            if (args["velocity"] != null)
            {
                Vector3.TryParse(args["velocity"].AsString(), out Velocity);
            }

            if (args["center"] != null)
            {
                Vector3.TryParse(args["center"].AsString(), out Center);
            }

            if (args["size"] != null)
            {
                Vector3.TryParse(args["size"].AsString(), out Size);
            }

            if (args["at_axis"] != null)
            {
                Vector3.TryParse(args["at_axis"].AsString(), out AtAxis);
            }

            if (args["left_axis"] != null)
            {
                Vector3.TryParse(args["left_axis"].AsString(), out AtAxis);
            }

            if (args["up_axis"] != null)
            {
                Vector3.TryParse(args["up_axis"].AsString(), out AtAxis);
            }

            if (args["far"] != null)
            {
                Far = (float)(args["far"].AsReal());
            }

            if (args["aspect"] != null)
            {
                Aspect = (float)args["aspect"].AsReal();
            }

            if (args["throttles"] != null)
            {
                Throttles = args["throttles"].AsBinary();
            }

            if (args["locomotion_state"] != null)
            {
                UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState);
            }

            if (args["head_rotation"] != null)
            {
                Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation);
            }

            if (args["body_rotation"] != null)
            {
                Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation);
            }

            if (args["control_flags"] != null)
            {
                UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags);
            }

            if (args["energy_level"] != null)
            {
                EnergyLevel = (float)(args["energy_level"].AsReal());
            }

            //This IS checked later
            if (args["god_level"] != null)
            {
                Byte.TryParse(args["god_level"].AsString(), out GodLevel);
            }

            if (args["speed"] != null)
            {
                float.TryParse(args["speed"].AsString(), out Speed);
            }
            else
            {
                Speed = 1;
            }

            if (args["draw_distance"] != null)
            {
                float.TryParse(args["draw_distance"].AsString(), out DrawDistance);
            }
            else
            {
                DrawDistance = 0;
            }

            //Reset this to fix movement... since regions are being bad about this
            if (Speed == 0)
            {
                Speed = 1;
            }

            if (args["always_run"] != null)
            {
                AlwaysRun = args["always_run"].AsBoolean();
            }

            if (args["sent_initial_wearables"] != null)
            {
                SentInitialWearables = args["sent_initial_wearables"].AsBoolean();
            }
            else
            {
                SentInitialWearables = false;
            }

            if (args["prey_agent"] != null)
            {
                PreyAgent = args["prey_agent"].AsUUID();
            }

            if (args["callback_uri"] != null)
            {
                CallbackURI = args["callback_uri"].AsString();
            }

            if (args["agent_access"] != null)
            {
                Byte.TryParse(args["agent_access"].AsString(), out AgentAccess);
            }

            if (args["active_group_id"] != null)
            {
                ActiveGroupID = args["active_group_id"].AsUUID();
            }

            if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array)
            {
                OSDArray groups = (OSDArray)(args["groups"]);
                Groups = new AgentGroupData[groups.Count];
                int i = 0;
                foreach (OSD o in groups)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Groups[i++] = new AgentGroupData((OSDMap)o);
                    }
                }
            }

            if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array)
            {
                OSDArray anims = (OSDArray)(args["animations"]);
                Anims = new Animation[anims.Count];
                int i = 0;
                foreach (OSD o in anims)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Anims[i++] = new Animation((OSDMap)o);
                    }
                }
            }

            Appearance = new AvatarAppearance(AgentID);

            try
            {
                if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
                {
                    Appearance = new AvatarAppearance(AgentID, (OSDMap)args["packed_appearance"]);
                }
                // DEBUG ON
                else
                {
                    m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
                }
                // DEBUG OFF
            }
            catch
            {
            }

            if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
            {
                OSDArray controls = (OSDArray)(args["controllers"]);
                Controllers = new ControllerData[controls.Count];
                int i = 0;
                foreach (OSD o in controls)
                {
                    if (o.Type == OSDType.Map)
                    {
                        Controllers[i++] = new ControllerData((OSDMap)o);
                    }
                }
            }
        }