Example #1
0
        private void MapLayerResponseHandler(CapsClient client, LLSD result, Exception error)
        {
            LLSDMap   body      = (LLSDMap)result;
            LLSDArray layerData = (LLSDArray)body["LayerData"];

            if (OnGridLayer != null)
            {
                for (int i = 0; i < layerData.Count; i++)
                {
                    LLSDMap thisLayerData = (LLSDMap)layerData[i];

                    GridLayer layer;
                    layer.Bottom  = thisLayerData["Bottom"].AsInteger();
                    layer.Left    = thisLayerData["Left"].AsInteger();
                    layer.Top     = thisLayerData["Top"].AsInteger();
                    layer.Right   = thisLayerData["Right"].AsInteger();
                    layer.ImageID = thisLayerData["ImageID"].AsUUID();

                    try { OnGridLayer(layer); }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
                }
            }

            if (body.ContainsKey("MapBlocks"))
            {
                // TODO: At one point this will become activated
                Logger.Log("Got MapBlocks through CAPS, please finish this function!", Helpers.LogLevel.Error, Client);
            }
        }
Example #2
0
            public static TextureEntryFace FromLLSD(LLSD llsd, TextureEntryFace defaultFace, out int faceNumber)
            {
                LLSDMap map = (LLSDMap)llsd;

                TextureEntryFace face = new TextureEntryFace(defaultFace);

                faceNumber = (map.ContainsKey("face_number")) ? map["face_number"].AsInteger() : -1;
                Color4 rgba = face.RGBA;

                rgba            = ((LLSDArray)map["colors"]).AsColor4();
                face.RGBA       = rgba;
                face.RepeatU    = (float)map["scales"].AsReal();
                face.RepeatV    = (float)map["scalet"].AsReal();
                face.OffsetU    = (float)map["offsets"].AsReal();
                face.OffsetV    = (float)map["offsett"].AsReal();
                face.Rotation   = (float)map["imagerot"].AsReal();
                face.Bump       = (Bumpiness)map["bump"].AsInteger();
                face.Shiny      = (Shininess)map["shiny"].AsInteger();
                face.Fullbright = map["fullbright"].AsBoolean();
                face.MediaFlags = map["media_flags"].AsBoolean();
                face.TexMapType = (MappingType)map["mapping"].AsInteger();
                face.Glow       = (float)map["glow"].AsReal();
                face.TextureID  = map["imageid"].AsUUID();

                return(face);
            }
        /// <summary>
        /// Attempts to convert an LLSD structure to a known Packet type
        /// </summary>
        /// <param name="capsEventName">Event name, this must match an actual
        /// packet name for a Packet to be successfully built</param>
        /// <param name="body">LLSD to convert to a Packet</param>
        /// <returns>A Packet on success, otherwise null</returns>
        public static Packet BuildPacket(string capsEventName, LLSDMap body)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            // Check if we have a subclass of packet with the same name as this event
            Type type = assembly.GetType("libsecondlife.Packets." + capsEventName + "Packet", false);

            if (type == null)
            {
                return(null);
            }

            Packet packet = null;

            try
            {
                // Create an instance of the object
                packet = (Packet)Activator.CreateInstance(type);

                // Iterate over all of the fields in the packet class, looking for matches in the LLSD
                foreach (FieldInfo field in type.GetFields())
                {
                    if (body.ContainsKey(field.Name))
                    {
                        Type blockType = field.FieldType;

                        if (blockType.IsArray)
                        {
                            LLSDArray array       = (LLSDArray)body[field.Name];
                            Type      elementType = blockType.GetElementType();
                            object[]  blockArray  = (object[])Array.CreateInstance(elementType, array.Count);

                            for (int i = 0; i < array.Count; i++)
                            {
                                LLSDMap map = (LLSDMap)array[i];
                                blockArray[i] = ParseLLSDBlock(map, elementType);
                            }

                            field.SetValue(packet, blockArray);
                        }
                        else
                        {
                            LLSDMap map = (LLSDMap)((LLSDArray)body[field.Name])[0];
                            field.SetValue(packet, ParseLLSDBlock(map, blockType));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log(e.Message, Helpers.LogLevel.Error, e);
            }

            return(packet);
        }
Example #4
0
        /// <summary>
        /// Attempts to convert an LLSD structure to a known Packet type
        /// </summary>
        /// <param name="capsEventName">Event name, this must match an actual
        /// packet name for a Packet to be successfully built</param>
        /// <param name="body">LLSD to convert to a Packet</param>
        /// <returns>A Packet on success, otherwise null</returns>
        public static Packet BuildPacket(string capsEventName, LLSDMap body)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            // Check if we have a subclass of packet with the same name as this event
            Type type = assembly.GetType("OpenMetaverse.Packets." + capsEventName + "Packet", false);
            if (type == null)
                return null;

            Packet packet = null;

            try
            {
                // Create an instance of the object
                packet = (Packet)Activator.CreateInstance(type);

                // Iterate over all of the fields in the packet class, looking for matches in the LLSD
                foreach (FieldInfo field in type.GetFields())
                {
                    if (body.ContainsKey(field.Name))
                    {
                        Type blockType = field.FieldType;

                        if (blockType.IsArray)
                        {
                            LLSDArray array = (LLSDArray)body[field.Name];
                            Type elementType = blockType.GetElementType();
                            object[] blockArray = (object[])Array.CreateInstance(elementType, array.Count);

                            for (int i = 0; i < array.Count; i++)
                            {
                                LLSDMap map = (LLSDMap)array[i];
                                blockArray[i] = ParseLLSDBlock(map, elementType);
                            }

                            field.SetValue(packet, blockArray);
                        }
                        else
                        {
                            LLSDMap map = (LLSDMap)((LLSDArray)body[field.Name])[0];
                            field.SetValue(packet, ParseLLSDBlock(map, blockType));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log(e.Message, Helpers.LogLevel.Error, e);
            }

            return packet;
        }
Example #5
0
        private void RequiredVoiceVersionEventHandler(string message, LLSD llsd, Simulator simulator)
        {
            LLSDMap body = (LLSDMap)llsd;

            if (body.ContainsKey("major_version"))
            {
                int majorVersion = body["major_version"].AsInteger();

                if (VOICE_MAJOR_VERSION != majorVersion)
                {
                    Logger.Log(String.Format("Voice version mismatch! Got {0}, expecting {1}. Disabling the voice manager",
                                             majorVersion, VOICE_MAJOR_VERSION), Helpers.LogLevel.Error, Client);
                    Enabled = false;
                }
                else
                {
                    Logger.DebugLog("Voice version " + majorVersion + " verified", Client);
                }
            }
        }
Example #6
0
        private static object ParseLLSDBlock(LLSDMap blockData, Type blockType)
        {
            object block = Activator.CreateInstance(blockType);

            // Iterate over each field and set the value if a match was found in the LLSD
            foreach (FieldInfo field in blockType.GetFields())
            {
                if (blockData.ContainsKey(field.Name))
                {
                    Type fieldType = field.FieldType;

                    if (fieldType == typeof(ulong))
                    {
                        // ulongs come in as a byte array, convert it manually here
                        byte[] bytes = blockData[field.Name].AsBinary();
                        ulong value = Utils.BytesToUInt64(bytes);
                        field.SetValue(block, value);
                    }
                    else if (fieldType == typeof(uint))
                    {
                        // uints come in as a byte array, convert it manually here
                        byte[] bytes = blockData[field.Name].AsBinary();
                        uint value = Utils.BytesToUInt(bytes);
                        field.SetValue(block, value);
                    }
                    else if (fieldType == typeof(ushort))
                    {
                        // Just need a bit of manual typecasting love here
                        field.SetValue(block, (ushort)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(byte))
                    {
                        // Just need a bit of manual typecasting love here
                        field.SetValue(block, (byte)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(short))
                    {
                        field.SetValue(block, (short)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(string))
                    {
                        field.SetValue(block, blockData[field.Name].AsString());
                    }
                    else if (fieldType == typeof(bool))
                    {
                        field.SetValue(block, blockData[field.Name].AsBoolean());
                    }
                    else if (fieldType == typeof(float))
                    {
                        field.SetValue(block, (float)blockData[field.Name].AsReal());
                    }
                    else if (fieldType == typeof(double))
                    {
                        field.SetValue(block, blockData[field.Name].AsReal());
                    }
                    else if (fieldType == typeof(int))
                    {
                        field.SetValue(block, blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(UUID))
                    {
                        field.SetValue(block, blockData[field.Name].AsUUID());
                    }
                    else if (fieldType == typeof(Vector3))
                    {
                        Vector3 vec = ((LLSDArray)blockData[field.Name]).AsVector3();
                        field.SetValue(block, vec);
                    }
                    else if (fieldType == typeof(Vector4))
                    {
                        Vector4 vec = ((LLSDArray)blockData[field.Name]).AsVector4();
                        field.SetValue(block, vec);
                    }
                    else if (fieldType == typeof(Quaternion))
                    {
                        Quaternion quat = ((LLSDArray)blockData[field.Name]).AsQuaternion();
                        field.SetValue(block, quat);
                    }
                }
            }

            // Additional fields come as properties, Handle those as well.
            foreach (PropertyInfo property in blockType.GetProperties())
            {
                if (blockData.ContainsKey(property.Name))
                {
                    LLSDType proptype = blockData[property.Name].Type;
                    MethodInfo set = property.GetSetMethod();

                    if (proptype.Equals(LLSDType.Binary))
                    {
                        set.Invoke(block, new object[] { blockData[property.Name].AsBinary() });
                    }
                    else
                        set.Invoke(block, new object[] { Utils.StringToBytes(blockData[property.Name].AsString()) });
                }
            }

            return block;
        }
        private static object ParseLLSDBlock(LLSDMap blockData, Type blockType)
        {
            object block = Activator.CreateInstance(blockType);

            // Iterate over each field and set the value if a match was found in the LLSD
            foreach (FieldInfo field in blockType.GetFields())
            {
                if (blockData.ContainsKey(field.Name))
                {
                    Type fieldType = field.FieldType;

                    if (fieldType == typeof(ulong))
                    {
                        // ulongs come in as a byte array, convert it manually here
                        byte[] bytes = blockData[field.Name].AsBinary();
                        ulong  value = Helpers.BytesToUInt64(bytes);
                        field.SetValue(block, value);
                    }
                    else if (fieldType == typeof(uint))
                    {
                        // uints come in as a byte array, convert it manually here
                        byte[] bytes = blockData[field.Name].AsBinary();
                        uint   value = Helpers.BytesToUIntBig(bytes);
                        field.SetValue(block, value);
                    }
                    else if (fieldType == typeof(ushort))
                    {
                        // Just need a bit of manual typecasting love here
                        field.SetValue(block, (ushort)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(byte))
                    {
                        // Just need a bit of manual typecasting love here
                        field.SetValue(block, (byte)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(short))
                    {
                        field.SetValue(block, (short)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(string))
                    {
                        field.SetValue(block, blockData[field.Name].AsString());
                    }
                    else if (fieldType == typeof(bool))
                    {
                        field.SetValue(block, blockData[field.Name].AsBoolean());
                    }
                    else if (fieldType == typeof(float))
                    {
                        field.SetValue(block, (float)blockData[field.Name].AsReal());
                    }
                    else if (fieldType == typeof(double))
                    {
                        field.SetValue(block, blockData[field.Name].AsReal());
                    }
                    else if (fieldType == typeof(int))
                    {
                        field.SetValue(block, blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(LLUUID))
                    {
                        field.SetValue(block, blockData[field.Name].AsUUID());
                    }
                    else if (fieldType == typeof(LLVector3))
                    {
                        LLVector3 vec = (LLVector3)field.GetValue(block);
                        vec.FromLLSD(blockData[field.Name]);
                        field.SetValue(block, vec);
                    }
                    else if (fieldType == typeof(LLVector4))
                    {
                        LLVector4 vec = (LLVector4)field.GetValue(block);
                        vec.FromLLSD(blockData[field.Name]);
                        field.SetValue(block, vec);
                    }
                    else if (fieldType == typeof(LLQuaternion))
                    {
                        LLQuaternion quat = (LLQuaternion)field.GetValue(block);
                        quat.FromLLSD(blockData[field.Name]);
                        field.SetValue(block, quat);
                    }
                }
            }

            // Additional fields come as properties, Handle those as well.
            foreach (PropertyInfo property in blockType.GetProperties())
            {
                if (blockData.ContainsKey(property.Name))
                {
                    LLSDType   proptype = blockData[property.Name].Type;
                    MethodInfo set      = property.GetSetMethod();

                    if (proptype.Equals(LLSDType.Binary))
                    {
                        byte[] bytes = blockData[property.Name].AsBinary();
                        set.Invoke(block, new object[] { blockData[property.Name].AsBinary() });
                    }
                    else
                    {
                        set.Invoke(block, new object[] { Helpers.StringToField(blockData[property.Name].AsString()) });
                    }
                }
            }

            return(block);
        }
Example #8
0
        private static object ParseLLSDBlock(LLSDMap blockData, Type blockType)
        {
            object block = Activator.CreateInstance(blockType);

            // Iterate over each field and set the value if a match was found in the LLSD
            foreach (FieldInfo field in blockType.GetFields())
            {
                if (blockData.ContainsKey(field.Name))
                {
                    Type fieldType = field.FieldType;

                    if (fieldType == typeof(ulong))
                    {
                        // ulongs come in as a byte array, convert it manually here
                        byte[] bytes = blockData[field.Name].AsBinary();
                        ulong value = Helpers.BytesToUInt64(bytes);
                        field.SetValue(block, value);
                    }
                    else if (fieldType == typeof(uint))
                    {
                        // uints come in as a byte array, convert it manually here
                        byte[] bytes = blockData[field.Name].AsBinary();
                        uint value = Helpers.BytesToUIntBig(bytes);
                        field.SetValue(block, value);
                    }
                    else if (fieldType == typeof(ushort))
                    {
                        // Just need a bit of manual typecasting love here
                        field.SetValue(block, (ushort)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(byte))
                    {
                        // Just need a bit of manual typecasting love here
                        field.SetValue(block, (byte)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(short))
                    {
                        field.SetValue(block, (short)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(LLUUID))
                    {
                        field.SetValue(block, blockData[field.Name].AsUUID());
                    }
                    else if (fieldType == typeof(LLVector3))
                    {
                        field.SetValue(block, LLVector3.FromLLSD(blockData[field.Name]));
                    }
                    else if (fieldType == typeof(LLVector4))
                    {
                        field.SetValue(block, LLVector4.FromLLSD(blockData[field.Name]));
                    }
                    else if (fieldType == typeof(LLQuaternion))
                    {
                        field.SetValue(block, LLQuaternion.FromLLSD(blockData[field.Name]));
                    }
                    else if (fieldType == typeof(string))
                    {
                        field.SetValue(block, blockData[field.Name].AsString());
                    }
                    else if (fieldType == typeof(bool))
                    {
                        field.SetValue(block, blockData[field.Name].AsBoolean());
                    }
                    else if (fieldType == typeof(float))
                    {
                        field.SetValue(block, (float)blockData[field.Name].AsReal());
                    }
                    else if (fieldType == typeof(double))
                    {
                        field.SetValue(block, blockData[field.Name].AsReal());
                    }
                    else if (fieldType == typeof(int))
                    {
                        field.SetValue(block, blockData[field.Name].AsInteger());
                    }
                }
            }

            // String fields are properties, pick those up as well
            foreach (PropertyInfo property in blockType.GetProperties())
            {
                if (blockData.ContainsKey(property.Name))
                {
                    MethodInfo set = property.GetSetMethod();
                    set.Invoke(block, new object[] { Helpers.StringToField(blockData[property.Name].AsString()) });
                }
            }

            return block;
        }