コード例 #1
0
        public TargetProtocolPacket(byte[] data)
        {
            BinaryReader reader = new BinaryReader(new MemoryStream(data), Encoding.UTF8);

            // Remove command code
            reader.ReadByte();
            UserName = reader.ReadString();            
            Packet = ProtocolPacket.FromData(NetworkUtils.ReadBytes(reader));
        }
コード例 #2
0
        private ProtocolPacket DoConnect(TcpClient client, string hostname, bool ssl, string username, bool supportsUpgrade)
        {
            Stream stm;

            _client = client;

            if (ssl)
            {
                SslStream sslStream = new SslStream(_client.GetStream(), false, ValidateRemoteConnection);

                int lastTimeout = sslStream.ReadTimeout;
                sslStream.ReadTimeout = 3000;

                sslStream.AuthenticateAsClient(hostname);

                sslStream.ReadTimeout = lastTimeout;

                stm = sslStream;
            }
            else
            {
                stm = _client.GetStream();
            }

            _baseStream = new XorStream(stm);
            _writer     = new BinaryWriter(_baseStream);
            _reader     = new BinaryReader(_baseStream);

            WritePacket(new HelloProtocolPacket(username, Environment.MachineName, supportsUpgrade, 0));

            ProtocolPacket packet = ReadPacket(3000);

            if (packet is GoodbyeProtocolPacket)
            {
                throw new EndOfStreamException(((GoodbyeProtocolPacket)packet).Message);
            }
            else
            {
                HelloProtocolPacket p = packet as HelloProtocolPacket;
                if (p != null)
                {
                    if (p.SupportsSecurityUpgrade)
                    {
                        UpgradeSecurity(p.XorKey);
                    }
                }

                return(packet);
            }
        }
コード例 #3
0
        public ProtocolPacket ReadPacket(int timeout)
        {
            int lastTimeout = _baseStream.ReadTimeout;

            try
            {
                _baseStream.ReadTimeout = timeout;
                return(ProtocolPacket.FromData(DataPacket.ReadFrom(_reader).Data));
            }
            finally
            {
                _baseStream.ReadTimeout = lastTimeout;
            }
        }
コード例 #4
0
 public ProtocolPacket ReadPacket()
 {
     return(ProtocolPacket.FromData(DataPacket.ReadFrom(_reader).Data));
 }
コード例 #5
0
        public void WritePacket(ProtocolPacket packet)
        {
            DataPacket p = new DataPacket(packet.GetData());

            p.WriteTo(_writer);
        }
コード例 #6
0
 public DataPacket(ProtocolPacket packet) : this(packet.GetData())
 {
 }
コード例 #7
0
 public TargetProtocolPacket(string userName, ProtocolPacket packet)
 {
     UserName = userName;
     Packet = packet;
 }