Example #1
0
        private bool HandleClientQueryGreeting(string greeting)
        {
            if (!greeting.StartsWith(CLIENT_GREETING, StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            greeting = greeting.Substring(CLIENT_GREETING.Length);

            const string PATTERN_STATIC_PART = "selected schandlerid=";
            const string PATTERN             = PATTERN_STATIC_PART + @"(?<id>\d+)" + Ts3Util.QUERY_REGEX_LINE_BREAK;

            while (true)
            {
                if (!PATTERN_STATIC_PART.StartsWith(greeting, StringComparison.InvariantCultureIgnoreCase) && !greeting.StartsWith(PATTERN_STATIC_PART, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(false);
                }

                if (!greeting.Contains(Ts3Util.QUERY_LINE_BREAK))
                {
                    KeyValuePair <SocketError, string> receiveResult = ReceiveMessage(SocketAsyncEventArgs);

                    if (receiveResult.Key != SocketError.Success)
                    {
                        Disconnect();
                        throw new SocketException((int)receiveResult.Key);
                    }

                    greeting = string.Concat(greeting, receiveResult.Value);
                    continue;
                }

                Match match = Regex.Match(greeting, PATTERN, RegexOptions.IgnoreCase | RegexOptions.Singleline);

                if (!match.Success)
                {
                    return(false);
                }

                LastServerConnectionHandlerId = Convert.ToInt32(match.Groups["id"].Value);

                break;
            }

            return(true);
        }
Example #2
0
        private bool HandleClientQueryGreeting(string greeting)
        {
            if (!greeting.StartsWith(CLIENT_GREETING, StringComparison.InvariantCultureIgnoreCase))
            {
                _greetingReceived = true;
                return(false);
            }

            greeting = greeting.Substring(CLIENT_GREETING.Length);

            const string PATTERN_STATIC_PART = "selected schandlerid=";
            const string PATTERN             = PATTERN_STATIC_PART + @"(?<id>\d+)" + Ts3Util.QUERY_REGEX_LINE_BREAK;

            if (!PATTERN_STATIC_PART.StartsWith(greeting, StringComparison.InvariantCultureIgnoreCase) && !greeting.StartsWith(PATTERN_STATIC_PART, StringComparison.InvariantCultureIgnoreCase))
            {
                _greetingReceived = true;
                return(false);
            }

            if (!greeting.Contains(Ts3Util.QUERY_LINE_BREAK))
            {
                return(false);
            }

            _greetingReceived = true;
            Match match = Regex.Match(greeting, PATTERN, RegexOptions.IgnoreCase | RegexOptions.Singleline);

            if (!match.Success)
            {
                return(false);
            }

            LastServerConnectionHandlerId = Convert.ToInt32(match.Groups["id"].Value);
            // greeting was correct!
            _receiveRepository.Remove(0, CLIENT_GREETING.Length + match.Length);
            ThreadPool.QueueUserWorkItem(x => OnReadyForSendingCommands());

            return(true);
        }