예제 #1
0
    public static void Main(string[] args)
    {
        // configure the proxy
        client = new SecondLife("../data/keywords.txt", "../data/message_template.msg");
        protocolManager = client.Protocol;
        ProxyConfig proxyConfig = new ProxyConfig("Analyst", "*****@*****.**", protocolManager, args);
        proxy = new Proxy(proxyConfig);

        // build the table of /command delegates
        InitializeCommandDelegates();

        // add delegates for login
        proxy.SetLoginRequestDelegate(new XmlRpcRequestDelegate(LoginRequest));
        proxy.SetLoginResponseDelegate(new XmlRpcResponseDelegate(LoginResponse));

        // add a delegate for outgoing chat
        proxy.AddDelegate("ChatFromViewer", Direction.Incoming, new PacketDelegate(ChatFromViewerIn));
        proxy.AddDelegate("ChatFromViewer", Direction.Outgoing, new PacketDelegate(ChatFromViewerOut));

        //  handle command line arguments
        foreach (string arg in args)
            if (arg == "--log-all")
                LogAll();
            else if (arg == "--log-login")
                logLogin = true;

        // start the proxy
        proxy.Start();
    }
    public static void Main(string[] args)
    {
        // configure the proxy
        client = new SecondLife("../data/keywords.txt", "../data/message_template.msg");
        protocolManager = client.Protocol;
        ProxyConfig proxyConfig = new ProxyConfig("ChatConsole", "*****@*****.**", protocolManager, args);
        proxy = new Proxy(proxyConfig);

        // set a delegate for when the client logs in
        proxy.SetLoginResponseDelegate(new XmlRpcResponseDelegate(Login));

        // add a delegate for incoming chat
        proxy.AddDelegate("ChatFromSimulator", Direction.Incoming, new PacketDelegate(ChatFromSimulator));

        // start the proxy
        proxy.Start();
    }
예제 #3
0
        /// <summary>
        /// Constructor used for building a packet where the length of the data
        /// is known in advance. This is being phased out in favor of
        /// pre-assembling the data or using PacketBuilder.BuildPacket().
        /// </summary>
        /// <param name="command">The name of the command in the message template</param>
        /// <param name="protocol">A reference to the ProtocolManager instance</param>
        /// <param name="length">The length of the packet data</param>
        public Packet(string command, ProtocolManager protocol, int length)
        {
            Protocol = protocol;
            Data     = new byte[length];
            Layout   = protocol.Command(command);

            if (Layout == null)
            {
                Console.WriteLine("Attempting to build a packet with invalid command \"" + command + "\"");

                // Create an empty Layout
                Layout        = new MapPacket();
                Layout.Blocks = new ArrayList();
                return;
            }

            switch (Layout.Frequency)
            {
            case PacketFrequency.Low:
                // Set the low frequency identifier bits
                byte[] lowHeader = { 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF };
                Array.Copy(lowHeader, 0, Data, 0, 6);

                // Store the packet ID in network order
                Data[6] = (byte)(Layout.ID / 256);
                Data[7] = (byte)(Layout.ID % 256);

                break;

            case PacketFrequency.Medium:
                // Set the medium frequency identifier bits
                byte[] mediumHeader = { 0x00, 0x00, 0x00, 0x00, 0xFF };
                Array.Copy(mediumHeader, 0, Data, 0, 5);
                Data[5] = (byte)Layout.ID;

                break;

            case PacketFrequency.High:
                // Set the high frequency identifier bits
                byte[] highHeader = { 0x00, 0x00, 0x00, 0x00 };
                Array.Copy(highHeader, 0, Data, 0, 4);
                Data[4] = (byte)Layout.ID;

                break;
            }
        }
예제 #4
0
        /// <summary>
        /// This is a special constructor created specifically for optimizing
        /// SLProxy, do not use it under any circumstances.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="length"></param>
        /// <param name="protocol"></param>
        /// <param name="layout"></param>
        /// <param name="copy"></param>
        public Packet(byte[] data, int length, ProtocolManager protocol, MapPacket layout, bool copy)
        {
            Protocol = protocol;
            Layout   = layout;

            if (Layout == null)
            {
                // Create an empty MapPacket
                Layout        = new MapPacket();
                Layout.Blocks = new ArrayList();
            }

            if (copy)
            {
                // Copy the network byte array to this packet's byte array
                Data = new byte[length];
                Array.Copy(data, 0, Data, 0, length);
            }
            else
            {
                // Use the buffer we got for Data
                Data = data;
            }
        }
예제 #5
0
        public static Packet BuildPacket(string name, ProtocolManager protocol, Hashtable blocks, byte flags)
        {
            Hashtable fields;
            byte[] byteArray = new byte[4096];
            int length = 0;
            int blockCount = 0;
            int fieldLength = 0;
            IDictionaryEnumerator blocksEnum;

            MapPacket packetMap = protocol.Command(name);

            // Build the header
            #region Header
            switch (packetMap.Frequency)
            {
                case PacketFrequency.High:
                    byteArray[4] = (byte)packetMap.ID;
                    length = 5;
                    break;
                case PacketFrequency.Medium:
                    byteArray[4] = 0xFF;
                    byteArray[5] = (byte)packetMap.ID;
                    length = 6;
                    break;
                case PacketFrequency.Low:
                    byteArray[4] = 0xFF;
                    byteArray[5] = 0xFF;
                    byteArray[6] = (byte)(packetMap.ID / 256);
                    byteArray[7] = (byte)(packetMap.ID % 256);
                    length = 8;
                    break;
            }
            #endregion Header

            foreach (MapBlock blockMap in packetMap.Blocks)
            {
                // If this is a variable count block, count the number of appearances of this block in the
                // passed in Hashtable and prepend a counter byte
                #region VariableSize
                if (blockMap.Count == -1)
                {
                    blockCount = 0;

                    // Count the number of this type of block in the blocks Hashtable
                    blocksEnum = blocks.GetEnumerator();

                    while (blocksEnum.MoveNext())
                    {
                        if ((string)blocksEnum.Value == blockMap.Name)
                        {
                            blockCount++;
                        }
                    }

                    if (blockCount > 255)
                    {
                        throw new Exception("Trying to put more than 255 blocks in a variable block");
                    }

                    // Prepend the blocks with a count
                    byteArray[length] = (byte)blockCount;
                    length++;
                }
                #endregion VariableSize

                // Reset blockCount
                blockCount = 0;

                // Check for blocks of this type in the Hashtable
                #region BuildBlock
                blocksEnum = blocks.GetEnumerator();

                while (blocksEnum.MoveNext())
                {
                    if ((string)blocksEnum.Value == blockMap.Name)
                    {
                        // Found a match of this block
                        if ((blockMap.Count == -1 && blockCount < 255) || blockCount < blockMap.Count)
                        {
                            blockCount++;

                            #region TryBlockTypecast
                            try
                            {
                                fields = (Hashtable)blocksEnum.Key;
                            }
                            catch (Exception e)
                            {
                                throw new Exception("A block Hashtable did not contain a fields Hashtable", e);
                            }
                            #endregion TryBlockTypecast

                            foreach (MapField fieldMap in blockMap.Fields)
                            {
                                if (fields.ContainsKey(fieldMap.Name))
                                {
                                    object field = fields[fieldMap.Name];

                                    #region AddField
                                    switch (fieldMap.Type)
                                    {
                                        case FieldType.U8:
                                            byteArray[length++] = (byte)field;
                                            break;
                                        case FieldType.U16:
                                            ushort fieldUShort = (ushort)field;
                                            byteArray[length++] = (byte)(fieldUShort % 256);
                                            fieldUShort >>= 8;
                                            byteArray[length++] = (byte)(fieldUShort % 256);
                                            break;
                                        case FieldType.U32:
                                            uint fieldUInt = (uint)field;
                                            byteArray[length++] = (byte)(fieldUInt % 256);
                                            fieldUInt >>= 8;
                                            byteArray[length++] = (byte)(fieldUInt % 256);
                                            fieldUInt >>= 8;
                                            byteArray[length++] = (byte)(fieldUInt % 256);
                                            fieldUInt >>= 8;
                                            byteArray[length++] = (byte)(fieldUInt % 256);
                                            break;
                                        case FieldType.U64:
                                            // FIXME: Apply endianness patch
                                            Array.Copy(((U64)field).GetBytes(), 0, byteArray, length, 8);
                                            length += 8;
                                            break;
                                        case FieldType.S8:
                                            byteArray[length++] = (byte)((sbyte)field);
                                            break;
                                        case FieldType.S16:
                                            // FIXME: Apply endianness patch
                                            Array.Copy(BitConverter.GetBytes((short)field), 0, byteArray, length, 2);
                                            length += 2;
                                            break;
                                        case FieldType.S32:
                                            // FIXME: Apply endianness patch
                                            Array.Copy(BitConverter.GetBytes((int)field), 0, byteArray, length, 4);
                                            length += 4;
                                            break;
                                        case FieldType.S64:
                                            // FIXME: Apply endianness patch
                                            Array.Copy(BitConverter.GetBytes((long)field), 0, byteArray, length, 8);
                                            length += 8;
                                            break;
                                        case FieldType.F32:
                                            Array.Copy(BitConverter.GetBytes((float)field), 0, byteArray, length, 4);
                                            length += 4;
                                            break;
                                        case FieldType.F64:
                                            Array.Copy(BitConverter.GetBytes((double)field), 0, byteArray, length, 8);
                                            length += 8;
                                            break;
                                        case FieldType.LLUUID:
                                            Array.Copy(((LLUUID)field).Data, 0, byteArray, length, 16);
                                            length += 16;
                                            break;
                                        case FieldType.BOOL:
                                            byteArray[length] = (byte)((bool)field == true ? 1 : 0);
                                            length++;
                                            break;
                                        case FieldType.LLVector3:
                                            Array.Copy(((LLVector3)field).GetBytes(), 0, byteArray, length, 12);
                                            length += 12;
                                            break;
                                        case FieldType.LLVector3d:
                                            Array.Copy(((LLVector3d)field).GetBytes(), 0, byteArray, length, 24);
                                            length += 24;
                                            break;
                                        case FieldType.LLVector4:
                                            Array.Copy(((LLVector4)field).GetBytes(), 0, byteArray, length, 16);
                                            length += 16;
                                            break;
                                        case FieldType.LLQuaternion:
                                            Array.Copy(((LLQuaternion)field).GetBytes(), 0, byteArray, length, 16);
                                            length += 16;
                                            break;
                                        case FieldType.IPADDR:
                                            Array.Copy(((IPAddress)field).GetAddressBytes(), 0, byteArray, length, 4);
                                            length += 4;
                                            break;
                                        case FieldType.IPPORT:
                                            ushort fieldIPPort = (ushort)field;
                                            byteArray[length + 1] = (byte)(fieldIPPort % 256);
                                            fieldIPPort >>= 8;
                                            byteArray[length] = (byte)(fieldIPPort % 256);
                                            length += 2;
                                            break;
                                        case FieldType.Variable:
                                            if (field.GetType().IsArray)
                                            {
                                                // Assume this is a byte array
                                                fieldLength = ((byte[])field).Length;
                                            }
                                            else
                                            {
                                                // Assume this is a string, add 1 for the null terminator
                                                fieldLength = ((string)field).Length + 1;
                                            }

                                            if (fieldMap.Count == 1)
                                            {
                                                if (fieldLength > 255)
                                                {
                                                    throw new Exception("Variable byte field longer than 255 characters");
                                                }

                                                byteArray[length] = (byte)(fieldLength);
                                                length++;
                                            }
                                            else if (fieldMap.Count == 2)
                                            {
                                                if (fieldLength > 1024)
                                                {
                                                    throw new Exception("Variable byte field longer than 1024 characters");
                                                }

                                                byteArray[length++] = (byte)(fieldLength % 256);
                                                byteArray[length++] = (byte)(fieldLength / 256);
                                            }
                                            else
                                            {
                                                throw new Exception("Variable field with an unknown count, protocol map error");
                                            }

                                            if (field.GetType().IsArray)
                                            {
                                                // Assume this is a byte array
                                                Array.Copy((byte[])field, 0, byteArray, length, fieldLength);
                                            }
                                            else
                                            {
                                                // Assume this is a string, add 1 for the null terminator
                                                byte[] stringBytes = System.Text.Encoding.UTF8.GetBytes((string)field);
                                                Array.Copy(stringBytes, 0, byteArray, length, stringBytes.Length);
                                                fieldLength = stringBytes.Length + 1;
                                            }

                                            length += fieldLength;

                                            break;
                                        case FieldType.Fixed:
                                            Array.Copy((byte[])field, 0, byteArray, length, fieldMap.Count);
                                            length += fieldMap.Count;
                                            break;
                                        default:
                                            throw new Exception("Unhandled FieldType");
                                    }
                                    #endregion AddField
                                }
                                else
                                {
                                    // This field wasn't passed in, create an empty version
                                    #region EmptyField
                                    if (fieldMap.Type == FieldType.Variable)
                                    {
                                        // Just set the counter to zero and move on
                                        if (fieldMap.Count == 2)
                                        {
                                            length += 2;
                                        }
                                        else
                                        {
                                            if (fieldMap.Count != 1)
                                            {
                                                throw new Exception("Variable length field has an invalid Count");
                                            }

                                            length++;
                                        }
                                    }
                                    else if (fieldMap.Type == FieldType.Fixed)
                                    {
                                        length += fieldMap.Count;
                                    }
                                    else
                                    {
                                        length += (int)protocol.TypeSizes[fieldMap.Type];
                                    }
                                    #endregion EmptyField
                                }
                            }
                        }
                        else
                        {
                            throw new Exception("Too many blocks");
                        }
                    }
                }
                #endregion BuildBlock

                // If this is a fixed count block and it doesn't appear in the Hashtable passed in, create
                // empty filler blocks
                #region EmptyBlock
                if (blockCount == 0 && blockMap.Count != -1)
                {
                    for (int i = 0; i < blockMap.Count; ++i)
                    {
                        foreach (MapField field in blockMap.Fields)
                        {
                            if (field.Type == FieldType.Variable)
                            {
                                length++;
                            }
                            else
                            {
                                length += (int)protocol.TypeSizes[field.Type];
                            }
                        }
                    }
                }
                #endregion EmptyBlock
            }

            Packet packet = new Packet(byteArray, length, protocol);
            packet.Data[0] = flags;
            return packet;
        }
예제 #6
0
        static void Main(string[] args)
        {
            SecondLife client;

            if (args.Length == 0 || (args.Length < 4 && args[0] != "--printmap"))
            {
                Console.WriteLine("Usage: sldump [--printmap] [--decrypt] [inputfile] [outputfile] "
                    + "[--protocol] [firstname] [lastname] [password] [seconds (0 for infinite)]");
                return;
            }

            if (args[0] == "--decrypt")
            {
                try
                {
                    ProtocolManager.DecodeMapFile(args[1], args[2]);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }

                return;
            }

            client = new SecondLife();

            if (args[0] == "--printmap")
            {
                ProtocolManager protocol;

                try
                {
                    protocol = new ProtocolManager("message_template.msg", client);
                }
                catch (Exception e)
                {
                    // Error initializing the client, probably missing file(s)
                    Console.WriteLine(e.ToString());
                    return;
                }

                protocol.PrintMap();
                return;
            }

            // Setup the packet callback and disconnect event handler
            client.Network.RegisterCallback(PacketType.Default, new NetworkManager.PacketCallback(DefaultHandler));
            client.Network.OnDisconnected += new NetworkManager.DisconnectCallback(DisconnectHandler);

            if (!client.Network.Login(args[0], args[1], args[2], "sldump", "*****@*****.**"))
            {
                // Login failed
                Console.WriteLine("Error logging in: " + client.Network.LoginError);
                return;
            }

            // Login was successful
            Console.WriteLine("Message of the day: " + client.Network.LoginValues["message"]);

            // Throttle packets that we don't want all the way down
            client.Throttle.Land = 0;
            client.Throttle.Wind = 0;
            client.Throttle.Cloud = 0;
            client.Throttle.Texture = 0;
            client.Throttle.Set();

            int start = Environment.TickCount;
            int milliseconds = Int32.Parse(args[3]) * 1000;
            bool forever = (milliseconds > 0) ? false : true;

            while (true)
            {
                System.Threading.Thread.Sleep(100);

                if (!forever && Environment.TickCount - start > milliseconds)
                {
                    break;
                }
            }

            client.Network.Logout();
        }
예제 #7
0
        public static Packet BuildPacket(string name, ProtocolManager protocol, Hashtable blocks, byte flags)
        {
            Hashtable fields;

            byte[] byteArray   = new byte[4096];
            int    length      = 0;
            int    blockCount  = 0;
            int    fieldLength = 0;
            IDictionaryEnumerator blocksEnum;

            MapPacket packetMap = protocol.Command(name);

            // Build the header
            #region Header
            switch (packetMap.Frequency)
            {
            case PacketFrequency.High:
                byteArray[4] = (byte)packetMap.ID;
                length       = 5;
                break;

            case PacketFrequency.Medium:
                byteArray[4] = 0xFF;
                byteArray[5] = (byte)packetMap.ID;
                length       = 6;
                break;

            case PacketFrequency.Low:
                byteArray[4] = 0xFF;
                byteArray[5] = 0xFF;
                byteArray[6] = (byte)(packetMap.ID / 256);
                byteArray[7] = (byte)(packetMap.ID % 256);
                length       = 8;
                break;
            }
            #endregion Header

            foreach (MapBlock blockMap in packetMap.Blocks)
            {
                // If this is a variable count block, count the number of appearances of this block in the
                // passed in Hashtable and prepend a counter byte
                #region VariableSize
                if (blockMap.Count == -1)
                {
                    blockCount = 0;

                    // Count the number of this type of block in the blocks Hashtable
                    blocksEnum = blocks.GetEnumerator();

                    while (blocksEnum.MoveNext())
                    {
                        if ((string)blocksEnum.Value == blockMap.Name)
                        {
                            blockCount++;
                        }
                    }

                    if (blockCount > 255)
                    {
                        throw new Exception("Trying to put more than 255 blocks in a variable block");
                    }

                    // Prepend the blocks with a count
                    byteArray[length] = (byte)blockCount;
                    length++;
                }
                #endregion VariableSize

                // Reset blockCount
                blockCount = 0;

                // Check for blocks of this type in the Hashtable
                #region BuildBlock
                blocksEnum = blocks.GetEnumerator();

                while (blocksEnum.MoveNext())
                {
                    if ((string)blocksEnum.Value == blockMap.Name)
                    {
                        // Found a match of this block
                        if ((blockMap.Count == -1 && blockCount < 255) || blockCount < blockMap.Count)
                        {
                            blockCount++;

                            #region TryBlockTypecast
                            try
                            {
                                fields = (Hashtable)blocksEnum.Key;
                            }
                            catch (Exception e)
                            {
                                throw new Exception("A block Hashtable did not contain a fields Hashtable", e);
                            }
                            #endregion TryBlockTypecast

                            foreach (MapField fieldMap in blockMap.Fields)
                            {
                                if (fields.ContainsKey(fieldMap.Name))
                                {
                                    object field = fields[fieldMap.Name];

                                    #region AddField
                                    switch (fieldMap.Type)
                                    {
                                    case FieldType.U8:
                                        byteArray[length++] = (byte)field;
                                        break;

                                    case FieldType.U16:
                                        ushort fieldUShort = (ushort)field;
                                        byteArray[length++] = (byte)(fieldUShort % 256);
                                        fieldUShort       >>= 8;
                                        byteArray[length++] = (byte)(fieldUShort % 256);
                                        break;

                                    case FieldType.U32:
                                        uint fieldUInt = (uint)field;
                                        byteArray[length++] = (byte)(fieldUInt % 256);
                                        fieldUInt         >>= 8;
                                        byteArray[length++] = (byte)(fieldUInt % 256);
                                        fieldUInt         >>= 8;
                                        byteArray[length++] = (byte)(fieldUInt % 256);
                                        fieldUInt         >>= 8;
                                        byteArray[length++] = (byte)(fieldUInt % 256);
                                        break;

                                    case FieldType.U64:
                                        // FIXME: Apply endianness patch
                                        Array.Copy(((U64)field).GetBytes(), 0, byteArray, length, 8);
                                        length += 8;
                                        break;

                                    case FieldType.S8:
                                        byteArray[length++] = (byte)((sbyte)field);
                                        break;

                                    case FieldType.S16:
                                        // FIXME: Apply endianness patch
                                        Array.Copy(BitConverter.GetBytes((short)field), 0, byteArray, length, 2);
                                        length += 2;
                                        break;

                                    case FieldType.S32:
                                        // FIXME: Apply endianness patch
                                        Array.Copy(BitConverter.GetBytes((int)field), 0, byteArray, length, 4);
                                        length += 4;
                                        break;

                                    case FieldType.S64:
                                        // FIXME: Apply endianness patch
                                        Array.Copy(BitConverter.GetBytes((long)field), 0, byteArray, length, 8);
                                        length += 8;
                                        break;

                                    case FieldType.F32:
                                        Array.Copy(BitConverter.GetBytes((float)field), 0, byteArray, length, 4);
                                        length += 4;
                                        break;

                                    case FieldType.F64:
                                        Array.Copy(BitConverter.GetBytes((double)field), 0, byteArray, length, 8);
                                        length += 8;
                                        break;

                                    case FieldType.LLUUID:
                                        Array.Copy(((LLUUID)field).Data, 0, byteArray, length, 16);
                                        length += 16;
                                        break;

                                    case FieldType.BOOL:
                                        byteArray[length] = (byte)((bool)field == true ? 1 : 0);
                                        length++;
                                        break;

                                    case FieldType.LLVector3:
                                        Array.Copy(((LLVector3)field).GetBytes(), 0, byteArray, length, 12);
                                        length += 12;
                                        break;

                                    case FieldType.LLVector3d:
                                        Array.Copy(((LLVector3d)field).GetBytes(), 0, byteArray, length, 24);
                                        length += 24;
                                        break;

                                    case FieldType.LLVector4:
                                        Array.Copy(((LLVector4)field).GetBytes(), 0, byteArray, length, 16);
                                        length += 16;
                                        break;

                                    case FieldType.LLQuaternion:
                                        Array.Copy(((LLQuaternion)field).GetBytes(), 0, byteArray, length, 16);
                                        length += 16;
                                        break;

                                    case FieldType.IPADDR:
                                        Array.Copy(((IPAddress)field).GetAddressBytes(), 0, byteArray, length, 4);
                                        length += 4;
                                        break;

                                    case FieldType.IPPORT:
                                        ushort fieldIPPort = (ushort)field;
                                        byteArray[length + 1] = (byte)(fieldIPPort % 256);
                                        fieldIPPort         >>= 8;
                                        byteArray[length]     = (byte)(fieldIPPort % 256);
                                        length += 2;
                                        break;

                                    case FieldType.Variable:
                                        if (field.GetType().IsArray)
                                        {
                                            // Assume this is a byte array
                                            fieldLength = ((byte[])field).Length;
                                        }
                                        else
                                        {
                                            // Assume this is a string, add 1 for the null terminator
                                            fieldLength = ((string)field).Length + 1;
                                        }

                                        if (fieldMap.Count == 1)
                                        {
                                            if (fieldLength > 255)
                                            {
                                                throw new Exception("Variable byte field longer than 255 characters");
                                            }

                                            byteArray[length] = (byte)(fieldLength);
                                            length++;
                                        }
                                        else if (fieldMap.Count == 2)
                                        {
                                            if (fieldLength > 1024)
                                            {
                                                throw new Exception("Variable byte field longer than 1024 characters");
                                            }

                                            byteArray[length++] = (byte)(fieldLength % 256);
                                            byteArray[length++] = (byte)(fieldLength / 256);
                                        }
                                        else
                                        {
                                            throw new Exception("Variable field with an unknown count, protocol map error");
                                        }

                                        if (field.GetType().IsArray)
                                        {
                                            // Assume this is a byte array
                                            Array.Copy((byte[])field, 0, byteArray, length, fieldLength);
                                        }
                                        else
                                        {
                                            // Assume this is a string, add 1 for the null terminator
                                            byte[] stringBytes = System.Text.Encoding.UTF8.GetBytes((string)field);
                                            Array.Copy(stringBytes, 0, byteArray, length, stringBytes.Length);
                                            fieldLength = stringBytes.Length + 1;
                                        }

                                        length += fieldLength;

                                        break;

                                    case FieldType.Fixed:
                                        Array.Copy((byte[])field, 0, byteArray, length, fieldMap.Count);
                                        length += fieldMap.Count;
                                        break;

                                    default:
                                        throw new Exception("Unhandled FieldType");
                                    }
                                    #endregion AddField
                                }
                                else
                                {
                                    // This field wasn't passed in, create an empty version
                                    #region EmptyField
                                    if (fieldMap.Type == FieldType.Variable)
                                    {
                                        // Just set the counter to zero and move on
                                        if (fieldMap.Count == 2)
                                        {
                                            length += 2;
                                        }
                                        else
                                        {
                                            if (fieldMap.Count != 1)
                                            {
                                                throw new Exception("Variable length field has an invalid Count");
                                            }

                                            length++;
                                        }
                                    }
                                    else if (fieldMap.Type == FieldType.Fixed)
                                    {
                                        length += fieldMap.Count;
                                    }
                                    else
                                    {
                                        length += (int)protocol.TypeSizes[fieldMap.Type];
                                    }
                                    #endregion EmptyField
                                }
                            }
                        }
                        else
                        {
                            throw new Exception("Too many blocks");
                        }
                    }
                }
                #endregion BuildBlock

                // If this is a fixed count block and it doesn't appear in the Hashtable passed in, create
                // empty filler blocks
                #region EmptyBlock
                if (blockCount == 0 && blockMap.Count != -1)
                {
                    for (int i = 0; i < blockMap.Count; ++i)
                    {
                        foreach (MapField field in blockMap.Fields)
                        {
                            if (field.Type == FieldType.Variable)
                            {
                                length++;
                            }
                            else
                            {
                                length += (int)protocol.TypeSizes[field.Type];
                            }
                        }
                    }
                }
                #endregion EmptyBlock
            }

            Packet packet = new Packet(byteArray, length, protocol);
            packet.Data[0] = flags;
            return(packet);
        }
예제 #8
0
 /// <summary>
 /// Constructor used to build a Packet object from incoming data.
 /// </summary>
 /// <param name="data">Byte array containing the full UDP payload</param>
 /// <param name="length">Length of the actual data in the byte array</param>
 /// <param name="protocol">A reference to the ProtocolManager instance</param>
 public Packet(byte[] data, int length, ProtocolManager protocol)
     : this(data, length, protocol, protocol.Command(data), true)
 {
 }
예제 #9
0
        static void Main(string[] args)
        {
            usbcontrol.InitUSBHandle();
            usbcontrol.SetPower(0);
            // configure the proxy
            protocolManager = new ProtocolManager("keywords.txt", "protocol.txt");
            ProxyConfig proxyConfig = new ProxyConfig("ChatConsole", "*****@*****.**", protocolManager, args);
            proxy = new SLProxy.Proxy(proxyConfig);

            // set a delegate for when the client logs in
            proxy.SetLoginResponseDelegate(new XmlRpcResponseDelegate(Login));

            // add a delegate for incoming chat
            proxy.AddDelegate("ChatFromSimulator", Direction.Incoming, new PacketDelegate(ChatFromSimulator));

            // start the proxy
            proxy.Start();
        }
 public SecondLife(string keywordFile, string mapFile)
 {
     Protocol = new ProtocolManager(mapFile, this);
     Debug = true;
 }
예제 #11
0
        /// <summary>
        /// This is a special constructor created specifically for optimizing 
        /// SLProxy, do not use it under any circumstances.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="length"></param>
        /// <param name="protocol"></param>
        /// <param name="layout"></param>
        /// <param name="copy"></param>
        public Packet(byte[] data, int length, ProtocolManager protocol, MapPacket layout, bool copy)
        {
            Protocol = protocol;
            Layout = layout;

            if (Layout == null)
            {
                // Create an empty MapPacket
                Layout = new MapPacket();
                Layout.Blocks = new ArrayList();
            }

            if (copy) {
                // Copy the network byte array to this packet's byte array
                Data = new byte[length];
                Array.Copy(data, 0, Data, 0, length);
            }
            else
            {
                // Use the buffer we got for Data
                Data = data;
            }
        }
예제 #12
0
        static void Main(string[] args)
        {
            SecondLife client;

            if (args.Length == 0 || (args.Length < 3 && args[0] != "--printmap"))
            {
                Console.WriteLine("Usage: sldump [--printmap] [--decrypt] [inputfile] [outputfile] [--protocol] [firstname] " +
                    "[lastname] [password]");
                return;
            }

            if (args[0] == "--decrypt")
            {
                try
                {
                    ProtocolManager.DecodeMapFile(args[1], args[2]);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }

                return;
            }

            client = new SecondLife();

            if (args[0] == "--printmap")
            {
                ProtocolManager protocol;

                try
                {
                    protocol = new ProtocolManager("message_template.msg", client);
                }
                catch (Exception e)
                {
                    // Error initializing the client, probably missing file(s)
                    Console.WriteLine(e.ToString());
                    return;
                }

                protocol.PrintMap();
                return;
            }

            // Setup the packet callback and disconnect event handler
            client.Network.RegisterCallback(PacketType.Default, new PacketCallback(DefaultHandler));
            client.Network.OnDisconnected += new DisconnectCallback(DisconnectHandler);

            Dictionary<string, object> loginParams = NetworkManager.DefaultLoginValues(args[0], args[1], args[2],
                "0", "last", "Win", "0", "sldump", "*****@*****.**");

            // An example of how to pass additional options to the login server
            //loginParams["id0"] = "65e142a8d3c1ee6632259f111cb168c9";
            //loginParams["viewer_digest"] = "0e63550f-0991-a092-3158-b4206e728ffa";

            if (!client.Network.Login(loginParams/*, "http://127.0.0.1:8080/"*/))
            {
                // Login failed
                Console.WriteLine("Error logging in: " + client.Network.LoginError);
                return;
            }

            // Login was successful
            Console.WriteLine("Message of the day: " + client.Network.LoginValues["message"]);

            while (true)
            {
                client.Tick();
            }
        }
예제 #13
0
 /// <summary>
 /// Constructor used to build a Packet object from incoming data.
 /// </summary>
 /// <param name="data">Byte array containing the full UDP payload</param>
 /// <param name="length">Length of the actual data in the byte array</param>
 /// <param name="protocol">A reference to the ProtocolManager instance</param>
 public Packet(byte[] data, int length, ProtocolManager protocol)
     : this(data, length, protocol, protocol.Command(data), true)
 {
 }
예제 #14
0
        /// <summary>
        /// Constructor used for building a packet where the length of the data
        /// is known in advance. This is being phased out in favor of 
        /// pre-assembling the data or using PacketBuilder.BuildPacket().
        /// </summary>
        /// <param name="command">The name of the command in the message template</param>
        /// <param name="protocol">A reference to the ProtocolManager instance</param>
        /// <param name="length">The length of the packet data</param>
        public Packet(string command, ProtocolManager protocol, int length)
        {
            Protocol = protocol;
            Data = new byte[length];
            Layout = protocol.Command(command);

            if (Layout == null)
            {
                Console.WriteLine("Attempting to build a packet with invalid command \"" + command + "\"");

                // Create an empty Layout
                Layout = new MapPacket();
                Layout.Blocks = new ArrayList();
                return;
            }

            switch (Layout.Frequency)
            {
                case PacketFrequency.Low:
                    // Set the low frequency identifier bits
                    byte[] lowHeader = {0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF};
                    Array.Copy(lowHeader, 0, Data, 0, 6);

                    // Store the packet ID in network order
                    Data[6] = (byte)(Layout.ID / 256);
                    Data[7] = (byte)(Layout.ID % 256);

                    break;
                case PacketFrequency.Medium:
                    // Set the medium frequency identifier bits
                    byte[] mediumHeader = {0x00, 0x00, 0x00, 0x00, 0xFF};
                    Array.Copy(mediumHeader, 0, Data, 0, 5);
                    Data[5] = (byte)Layout.ID;

                    break;
                case PacketFrequency.High:
                    // Set the high frequency identifier bits
                    byte[] highHeader = {0x00, 0x00, 0x00, 0x00};
                    Array.Copy(highHeader, 0, Data, 0, 4);
                    Data[4] = (byte)Layout.ID;

                    break;
            }
        }
예제 #15
0
        // ProxyConfig: construct a default proxy configuration, parsing command line arguments (try --proxy-help)
        public ProxyConfig(string userAgent, string author, ProtocolManager protocol, string[] args)
            : this(userAgent, author, protocol)
        {
            Hashtable argumentParsers = new Hashtable();
            argumentParsers["proxy-help"] = new ArgumentParser(ParseHelp);
            argumentParsers["proxy-login-port"] = new ArgumentParser(ParseLoginPort);
            argumentParsers["proxy-client-facing-address"] = new ArgumentParser(ParseClientFacingAddress);
            argumentParsers["proxy-remote-facing-address"] = new ArgumentParser(ParseRemoteFacingAddress);
            argumentParsers["proxy-remote-login-uri"] = new ArgumentParser(ParseRemoteLoginUri);
            argumentParsers["proxy-verbose"] = new ArgumentParser(ParseVerbose);
            argumentParsers["proxy-quiet"] = new ArgumentParser(ParseQuiet);

            foreach (string arg in args)
                foreach (string argument in argumentParsers.Keys) {
                    Match match = (new Regex("^--" + argument + "(?:=(.*))?$")).Match(arg);
                    if (match.Success) {
                        string value;
                        if (match.Groups[1].Captures.Count == 1)
                            value = match.Groups[1].Captures[0].ToString();
                        else
                            value = null;
                        try {
                            ((ArgumentParser)argumentParsers[argument])(value);
                        } catch {
                            Console.WriteLine("invalid value for --" + argument);
                            ParseHelp(null);
                        }
                    }
                }
        }
예제 #16
0
 // ProxyConfig: construct a default proxy configuration with the specified userAgent, author, and protocol
 public ProxyConfig(string userAgent, string author, ProtocolManager protocol)
 {
     this.userAgent = userAgent;
     this.author = author;
     this.protocol = protocol;
 }
예제 #17
0
 public SecondLife(string keywordFile, string mapFile)
 {
     Protocol = new ProtocolManager(mapFile, this);
     Debug    = true;
 }