protected async void ReadLoop() { while (Client != null && Client.Connected) { string message = await ReadLineAsync(false).ConfigureAwait(false); if (message == null) { continue; } if (message.StartsWith("error", StringComparison.CurrentCultureIgnoreCase)) { if (!AtLeastOneResponseReceived) { AtLeastOneResponseReceived = true; // Remove welcome messages after connect ReceivedLines.Clear(); } string responseText = string.Join("\n\r", ReceivedLines.Concat(new[] { message })); MessageResponses.Enqueue(responseText); ReceivedLines.Clear(); SimpleResponse response = SimpleResponse.Parse(responseText); if (response.IsBanned) { BanDetected?.Invoke(this, new EventArgs <SimpleResponse>(response)); DisconnectForced("Banned!"); return; } } else if (message.StartsWith("notify", StringComparison.CurrentCultureIgnoreCase)) { ThreadPool.QueueUserWorkItem(OnNotificationReceived, message); } else { if (!AtLeastOneResponseReceived) { const string LastServerConnectionHandlerIdText = "selected schandlerid="; if (message.StartsWith(LastServerConnectionHandlerIdText, StringComparison.InvariantCultureIgnoreCase) && int.TryParse(message.Substring(LastServerConnectionHandlerIdText.Length).Trim(), out int handlerId)) { LastServerConnectionHandlerId = handlerId; } } ReceivedLines.Add(message); } } }