Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 public bool Send(ConnectionRequestPacket packet)
 {
     if (provider.SendPayload(new byte[] { Convert.ToByte(PacketType.ConnectionRequest), packet.options }))
     {
         return(true);
     }
     return(false);
 }