void gohaIrc_RawMessageReceived(object sender, IrcRawMessageEventArgs e) { if (settings.gohaDebugMessages) { SendMessage(new UbiMessage(e.RawContent, EndPoint.Gohatv, EndPoint.SteamAdmin)); } if (e.Message.Source == null) return; if (e.Message.Source.Name.ToLower() == "nickserv") { if (e.RawContent.Contains("Invalid password for")) { SendMessage(new UbiMessage("Goha login failed! Check settings!", EndPoint.Gohatv, EndPoint.Error)); } else if (e.RawContent.Contains("You are now identified")) { SendMessage(new UbiMessage(String.Format("Goha IRC: logged in!"), EndPoint.Gohatv, EndPoint.Notice)); chatStatusGoha.On = true; } else if (e.RawContent.Contains("is not a registered nickname")) { var email = InputBox.Show("Enter your email to receive Goha confirmation code:"); if (string.IsNullOrEmpty(email)) return; SendRegisterInfoToGohaIRC(email); } else if (e.RawContent.Contains("An email containing nickname activation instructions")) { var confirmCode = InputBox.Show("Check your mail and enter Goha confirmation code:"); if (string.IsNullOrEmpty(confirmCode)) return; SendConfirmCodeToGohaIRC(confirmCode); } else if (e.RawContent.Contains("Verification failed. Invalid key for")) { var confirmCode = InputBox.Show("Wrong confirmation code. Try again:"); if (string.IsNullOrEmpty(confirmCode)) return; SendConfirmCodeToGohaIRC(confirmCode); } else if (e.RawContent.Contains("has now been verified.")) { SendMessage(new UbiMessage(String.Format("Goha IRC: email verified!"), EndPoint.Gohatv, EndPoint.Notice)); } } }
void IrcClient_RawMessageReceived( object sender, IrcRawMessageEventArgs e ) { if (OnNewMessagesArrived != null) { string prefix, command; string[] parameters; ParseIrcMessageWithRegex(e.RawContent, out prefix, out command, out parameters); List<ChatMessage> msgs = new List<ChatMessage>(); string username = getUserName(prefix); dots += "."; if (dots.Length > 3) dots = ""; switch (command) { case "PART": case "JOIN": Header = "http://twitch.tv, " + StreamerNick + dots; break; case "PRIVMSG": Header = "http://twitch.tv, " + StreamerNick; if (username != "Jtv") { msgs.Add(new ChatMessage() { Date = DateTime.Now, Name = username, Text = parameters[1] }); } break; default: //msgs.Add(new ChatMessage() { // Date = DateTime.Now, // Name = prefix, // Text = e.RawContent //}); break; } if( msgs.Count > 0 ) OnNewMessagesArrived(msgs); } }
void twitchIrc_RawMessageReceived(object sender, IrcRawMessageEventArgs e) { lock (lockTwitchMessage) { if (e.RawContent.Contains("Login failed") || e.RawContent.ToLower().Contains("login unsuccessful")) { if (!twitchTriedOAuth && !settings.TwitchPassword.Contains("oauth:")) { TwitchWeb toauth = new TwitchWeb(settings.TwitchUser.ToLower(), settings.TwitchPassword); twitchTriedOAuth = true; if (toauth.Login()) { settings.twitchOAuthKey = toauth.ChatOAuthKey; return; } } SendMessage(new UbiMessage("Twitch login failed! Check settings!", EndPoint.TwitchTV, EndPoint.Error)); } else if (settings.twitchDebugMessages) { SendMessage(new UbiMessage(e.RawContent, EndPoint.TwitchTV, EndPoint.SteamAdmin)); } } }
void IrcClient_RawMessageReceived( object sender, IrcRawMessageEventArgs e ) { if (OnNewMessagesArrived != null) { string prefix, command; string[] parameters; ParseIrcMessageWithRegex(e.RawContent, out prefix, out command, out parameters); List<ChatMessage> msgs = new List<ChatMessage>(); string username = getUserName(prefix); dots += "."; if (dots.Length > 3) dots = ""; //msgs.Add(new ChatMessage() { // Date = DateTime.Now, // Name = "RAW", // Text = e.RawContent //}); // System.IO.File.AppendAllText("x:\\twitch.log", e.RawContent + "\r\n"); switch (command) { case "PART": case "JOIN": Header = "http://twitch.tv, " + StreamerNick + dots; break; case "PRIVMSG": Header = "http://twitch.tv, " + StreamerNick; if (username != "Jtv") { msgs.Add(new ChatMessage() { Date = DateTime.Now, Name = username, Text = parameters[1] }); } else { //msgs.Add(new ChatMessage() { // Date = DateTime.Now, // Name = "SYSTEM", // Text = parameters[1] //}); } break; //case "+": // msgs.Add(new ChatMessage() { // Date = DateTime.Now, // Name = prefix, // Text = "[УДАЛЕНИЕ] " + e.RawContent // }); // break; //default: // msgs.Add(new ChatMessage() { // Date = DateTime.Now, // Name = prefix, // Text = "["+command + "] " + e.RawContent // }); // break; } if( msgs.Count > 0 ) OnNewMessagesArrived(msgs); } }
/// <summary> /// Raises the <see cref="RawMessageReceived"/> event. /// </summary> /// <param name="e">The <see cref="IrcRawMessageEventArgs"/> instance containing the event data.</param> protected virtual void OnRawMessageReceived(IrcRawMessageEventArgs e) { var handler = this.RawMessageReceived; if (handler != null) handler(this, e); }
private void ReceiveCompleted(object sender, SocketAsyncEventArgs e) { lock (receiveLock) { try { if (e.SocketError != SocketError.Success) { HandleSocketError(e.SocketError); return; } // Check if remote host has closed connection. if (e.BytesTransferred == 0) { HandleClientDisconnected(); return; } // Indicate that block of data has been read into receive buffer. this.receiveStream.WritePosition += e.BytesTransferred; this.dataStreamReader.DiscardBufferedData(); // Read each terminated line of characters from data stream. while (true) { // Read next line from data stream. var line = this.dataStreamLineReader.ReadLine(); if (line == null) break; if (line.Length == 0) continue; string prefix = null; string lineAfterPrefix = null; // Extract prefix from message line, if it contains one. if (line[0] == ':') { var firstSpaceIndex = line.IndexOf(' '); Debug.Assert(firstSpaceIndex != -1); prefix = line.Substring(1, firstSpaceIndex - 1); lineAfterPrefix = line.Substring(firstSpaceIndex + 1); } else { lineAfterPrefix = line; } // Extract command from message. var command = ""; var paramsLine = ""; if (lineAfterPrefix.IndexOf(' ') > 0) { command = lineAfterPrefix.Substring(0, lineAfterPrefix.IndexOf(' ')); paramsLine = lineAfterPrefix.Substring(command.Length + 1); } // Extract parameters from message. // Each parameter is separated by single space, except last one, which may contain spaces if it // is prefixed by colon. var parameters = new string[maxParamsCount]; int paramStartIndex, paramEndIndex = -1; int lineColonIndex = paramsLine.IndexOf(" :"); if (lineColonIndex == -1 && !paramsLine.StartsWith(":")) lineColonIndex = paramsLine.Length; for (int i = 0; i < parameters.Length; i++) { paramStartIndex = paramEndIndex + 1; paramEndIndex = paramsLine.IndexOf(' ', paramStartIndex); if (paramEndIndex == -1) paramEndIndex = paramsLine.Length; if (paramEndIndex > lineColonIndex) { paramStartIndex++; paramEndIndex = paramsLine.Length; } parameters[i] = paramsLine.Substring(paramStartIndex, paramEndIndex - paramStartIndex); if (paramEndIndex == paramsLine.Length) break; } // Parse received IRC message. var message = new IrcMessage(this, prefix, command, parameters); var messageReceivedEventArgs = new IrcRawMessageEventArgs(message, line); OnRawMessageReceived(messageReceivedEventArgs); ReadMessage(message, line); #if DEBUG DebugUtilities.WriteIrcRawLine(this, ">>> " + messageReceivedEventArgs.RawContent); #endif } // Continue reading data from socket. ReceiveAsync(); } catch (SocketException exSocket) { HandleSocketError(exSocket); } catch (ObjectDisposedException) { // Ignore. } #if !DEBUG catch (Exception ex) { OnError(new IrcErrorEventArgs(ex)); } #endif finally { e.Dispose(); } } }
/// <inheritdoc cref="WriteMessage(string, object)"/> /// <summary> /// Writes the specified message (prefix, command, and parameters) to the network stream. /// </summary> /// <param name="message">The message to write.</param> /// <exception cref="ArgumentException"><paramref name="message"/> contains more than 15 many parameters. /// </exception> /// <exception cref="ArgumentException">The value of <see cref="IrcMessage.Command"/> of /// <paramref name="message"/> is invalid.</exception> /// <exception cref="ArgumentException">The value of one of the items of <see cref="IrcMessage.Parameters"/> of /// <paramref name="message"/> is invalid.</exception> /// <exception cref="ObjectDisposedException">The current instance has already been disposed.</exception> protected void WriteMessage(IrcMessage message) { CheckDisposed(); if (message.Command == null) throw new ArgumentException(Properties.Resources.MessageInvalidCommand, "message"); if (message.Parameters.Count > maxParamsCount) throw new ArgumentException(Properties.Resources.MessageTooManyParams, "parameters"); var lineBuilder = new StringBuilder(); // Append prefix to line, if specified. if (message.Prefix != null) lineBuilder.Append(":" + CheckPrefix(message.Prefix) + " "); // Append command name to line. lineBuilder.Append(CheckCommand(message.Command).ToUpper()); // Append each parameter to line, adding ':' character before last parameter. for (int i = 0; i < message.Parameters.Count - 1; i++) { if (message.Parameters[i] != null) lineBuilder.Append(" " + CheckMiddleParameter(message.Parameters[i].ToString())); } if (message.Parameters.Count > 0) { var lastParameter = message.Parameters[message.Parameters.Count - 1]; if (lastParameter != null) lineBuilder.Append(" :" + CheckTrailingParameter(lastParameter)); } // Send raw message as line of text. var line = lineBuilder.ToString(); var messageSentEventArgs = new IrcRawMessageEventArgs(message, line); WriteMessage(line, messageSentEventArgs); }