Exemple #1
0
        public bool Send(TargetDefinitionPacket packet)
        {
            byte[] width  = BitConverter.GetBytes(packet.width);
            byte[] height = BitConverter.GetBytes(packet.height);

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(width);
                Array.Reverse(height);
            }

            byte[] payload = new[]
            {
                Convert.ToByte(PacketType.TargetDefinition),
                width[0],
                width[1],
                height[0],
                height[1]
            };

            if (provider.SendPayload(payload))
            {
                return(true);
            }
            return(false);
        }
Exemple #2
0
        public static PacketType GetPacket(byte[] packetData, int byteCount, out object packet)
        {
            PacketType type = (PacketType)packetData[0];

            switch (type)
            {
            case PacketType.ConnectionRequest:
                packet = new ConnectionRequestPacket()
                {
                    options = packetData[1]
                };
                break;

            case PacketType.ClientDefinition:
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(packetData, 1, 2);
                    Array.Reverse(packetData, 3, 2);
                }
                packet = new ClientDefinitionPacket()
                {
                    width = BitConverter.ToUInt16(packetData, 1), height = BitConverter.ToUInt16(packetData, 3)
                };
                break;

            case PacketType.TargetDefinition:
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(packetData, 1, 2);
                    Array.Reverse(packetData, 3, 2);
                }
                packet = new TargetDefinitionPacket()
                {
                    width = BitConverter.ToUInt16(packetData, 1), height = BitConverter.ToUInt16(packetData, 3)
                };
                break;

            case PacketType.StreamRequest:
                packet = new StreamRequestPacket()
                {
                    options = packetData[1]
                };
                break;

            case PacketType.Stream:
                //TODO: Do the packet shit
                packet = new StreamPacket()
                {
                };
                break;

            default:
                type   = PacketType.Unknown;
                packet = null;
                break;
            }

            return(type);
        }