Example #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)
        {
            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();
                }
            }
        }
Example #2
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();
                }
            }
        }