コード例 #1
0
        public bool Authenticate()
        {
            string line;

            try
            {
                line = StreamProvider.StreamReader.ReadLine();
            }
            catch (IOException)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(line))
            {
                return(false);
            }

            var match = Regex.Match(line, "^handshake;pass=(?<password>(.*?));id=(?<id>(.*?))$");

            if (!match.Success)
            {
                StreamProvider.SendLine("authentication;invalidhandshake");
                return(false);
            }

            if (match.Groups["password"].Value != _settings.Password)
            {
                StreamProvider.SendLine("authentication;wrongpassword");
                return(false);
            }

            ID = match.Groups["id"].Value;

            if (_settings.BannedClients.Contains(ID))
            {
                StreamProvider.SendLine("authentication;banned");
                return(false);
            }

            StreamProvider.SendLine("authentication;success");

            var deviceInfo = StreamProvider.StreamReader.ReadLine();

            try
            {
                DeviceInfo = ConnectionDeviceInfo.FromString(deviceInfo);
            }
            catch (Exception)
            {
                StreamProvider.SendLine("authentication:invaliddeviceinfo");
                return(false);
            }

            StreamProvider.SendLine("authentication;accepted");
            return(true);
        }
コード例 #2
0
ファイル: TCPConnection.cs プロジェクト: WELL-E/Hurricane
        public bool Authenticate()
        {
            string line;
            try
            {
                line = StreamProvider.StreamReader.ReadLine();
            }
            catch (IOException)
            {
                return false;
            }

            if (string.IsNullOrEmpty(line)) return false;

            var match = Regex.Match(line, "^handshake;pass=(?<password>(.*?));id=(?<id>(.*?))$");
            if (!match.Success)
            {
                StreamProvider.SendLine("authentication;invalidhandshake");
                return false;
            }

            if (match.Groups["password"].Value != _settings.Password)
            {
                StreamProvider.SendLine("authentication;wrongpassword");
                return false;
            }

            ID = match.Groups["id"].Value;

            if (_settings.BannedClients.Contains(ID))
            {
                StreamProvider.SendLine("authentication;banned");
                return false;
            }

            StreamProvider.SendLine("authentication;success");

            var deviceInfo = StreamProvider.StreamReader.ReadLine();
            try
            {
                DeviceInfo = ConnectionDeviceInfo.FromString(deviceInfo);
            }
            catch (Exception)
            {
                StreamProvider.SendLine("authentication:invaliddeviceinfo");
                return false;
            }

            StreamProvider.SendLine("authentication;accepted");
            return true;
        }