private void ProcessError(IrcLine line) { if (OnErrorReceived != null) { Task.Run(() => OnErrorReceived(line.FinalArgument)); } }
private void ProcessEndOfNames(IrcLine line) { if (OnNamesKnown != null) { Task.Run(() => OnNamesKnown(channels[line.Arguments[1]])); } }
protected void ProcessIrcLine(IrcLine line) { switch (line.Command) { case "PRIVMSG": ProcessPm(line); break; case "NOTICE": ProcessNotice(line); break; case "NICK": ProcessNickChange(line); break; case "KICK": ProcessKick(line); break; case "JOIN": ProcessJoin(line); break; case "353": ProcessNameReply(line); break; case "PART": ProcessPart(line); break; case "QUIT": ProcessQuit(line); break; case "332": ProcessTopic(line); break; case "333": ProcessTopicSet(line); break; case "366": ProcessEndOfNames(line); break; case "433": Nick = Nick + "_"; Authenticate(Nick); break; case "ERROR": ProcessError(line); break; default: if (OnFormattedLineReceived != null) { Task.Run(() => OnFormattedLineReceived(line)); } break; } }
private void ProcessQuit(IrcLine line) { if (OnQuit != null) { Task.Run(() => OnQuit(parser.GetUserFromSender(line.Sender), line.FinalArgument)); } }
private void ProcessTopic(IrcLine line) { if (OnTopicReceived != null) { Task.Run(() => OnTopicReceived(line.Arguments[1], line.FinalArgument)); } }
private void ProcessPart(IrcLine line) { var sender = parser.GetUserFromSender(line.Sender); if (sender.Nick == Nick) { channels.Remove(line.Arguments[0]); if (OnPartedChannel != null) { Task.Run(() => OnPartedChannel(line.Arguments[0])); } } else { channels[line.Arguments[0]].RemoveUser(sender.Nick); if (OnPartChannel != null) { Task.Run(() => OnPartChannel(sender, line.Arguments[0])); } } }
private void ProcessPm(IrcLine line) { const string actionSequence = "\u0001ACTION"; var action = false; if (line.FinalArgument.StartsWith(actionSequence)) { action = true; var message = line.FinalArgument; message = message.Substring(8, message.Length - 9); line.FinalArgument = message; } if (OnMessageReceived == null) return; var sender = parser.GetUserFromSender(line.Sender); var channel = line.Arguments[0] == Nick ? sender.Nick : line.Arguments[0]; var msg = new IrcMessage(sender, channel, line.FinalArgument, action); Task.Run(() => OnMessageReceived(msg)); }
private void ProcessNickChange(IrcLine line) { if (line.User.Nick == Nick) { Nick = line.FinalArgument; if (OnNickChanged != null) { Task.Run(() => OnNickChanged(line.FinalArgument)); } } else { if (OnNickChange != null) { Task.Run(() => OnNickChange(parser.GetUserFromSender(line.Sender), line.FinalArgument)); } } }
private void ProcessNotice(IrcLine line) { if (OnNoticeReceived != null) { Task.Run(() => OnNoticeReceived(parser.GetUserFromSender(line.Sender), line.FinalArgument)); } }
private void ProcessJoin(IrcLine line) { var sender = IrcProtocolParser.GetUserFromSender(line.Sender); if (sender.Nick == client.Nick) { if (client.Ident != sender.Ident) { Log($"Warning: Real ident ({sender.Ident}) differs from requested ident ({client.Ident}). Ident field changed to match ident assigned by the server."); client.Ident = sender.Ident; } if (client.LocalHost == null) { Log("Hostmask detected as " + sender.Hostmask); client.LocalHost = sender.Hostmask; } if (client.ChannelDict.ContainsKey(line.Arguments[0])) { throw new InvalidOperationException("Received a JOIN for " + line.Arguments[0] + " while already in this channel."); } client.ChannelDict.Add(line.Arguments[0], new IrcChannel(line.Arguments[0])); OnJoinedChannel?.Invoke(line.Arguments[0]); } else { client.ChannelDict[line.Arguments[0]].AddUser(sender.Nick, IrcPermissionLevel.Default); OnJoinChannel?.Invoke(sender, line.Arguments[0]); } }
private void ProcessNickChange(IrcLine line) { if (line.User.Nick == client.Nick) { client.Nick = line.FinalArgument; OnNickChanged?.Invoke(line.FinalArgument); } else { OnNickChange?.Invoke(IrcProtocolParser.GetUserFromSender(line.Sender), line.FinalArgument); } }
public virtual IrcLine PostProcessLine(IrcLine line) { return line; }
private void ProcessKick(IrcLine line) { var sender = parser.GetUserFromSender(line.Sender); if (line.Arguments[1].Equals(Nick)) { channels.Remove(line.Arguments[0]); if (OnKicked != null) { Task.Run(() => OnKicked(line.Arguments[0], line.FinalArgument, sender)); } } else if (OnKick != null) { Task.Run(() => OnKick(line.Arguments[1], line.Arguments[0], line.FinalArgument, sender)); } }
private void ProcessTopicSet(IrcLine line) { int seconds; if (!int.TryParse(line.Arguments[3], out seconds)) { Log("Failed to parse topic set time, defaulting to Unix epoch"); } OnTopicSet?.Invoke(line.Arguments[1], IrcProtocolParser.GetUserFromSender(line.Arguments[2]), new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(seconds)); }
private void ProcessPm(IrcLine line) { var parsedMessage = line.FinalArgument; var action = IrcProtocolParser.ParseAction(ref parsedMessage); var sender = IrcProtocolParser.GetUserFromSender(line.Sender); // If it's a private message, the target field will be the client's client.Nick. Otherwise, it will be a channel name. var channel = line.Arguments[0] == client.Nick ? sender.Nick : line.Arguments[0]; var message = new IrcMessage(sender, channel, parsedMessage, action); foreach (var processor in client.DataProcessors) { message = processor.ProcessMessage(message); } OnMessageReceived?.Invoke(message); }
private void ProcessPart(IrcLine line) { var sender = IrcProtocolParser.GetUserFromSender(line.Sender); if (sender.Nick != client.Nick) { client.ChannelDict.Remove(line.Arguments[0]); OnPartedChannel?.Invoke(line.Arguments[0]); } else { client.ChannelDict[line.Arguments[0]].RemoveUser(sender.Nick); OnPartChannel?.Invoke(sender, line.Arguments[0]); } }
private void ProcessTopicSet(IrcLine line) { int seconds; int.TryParse(line.Arguments[3], out seconds); if (OnTopicSet != null) { Task.Run(() => OnTopicSet(line.Arguments[1], parser.GetUserFromSender(line.Arguments[2]), new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(seconds))); } }
private void ProcessIrcLine(IrcLine line) { switch (line.Command) { case "001": client.SetConnectionState(true); OnFormattedLineReceived?.Invoke(line); break; case "PRIVMSG": ProcessPm(line); break; case "NOTICE": ProcessNotice(IrcProtocolParser.GetUserFromSender(line.Sender), line.FinalArgument); break; case "NICK": ProcessNickChange(line); break; case "KICK": ProcessKick(line); break; case "JOIN": ProcessJoin(line); break; case "353": ProcessNameReply(line); break; case "PART": ProcessPart(line); break; case "QUIT": OnQuit?.Invoke(IrcProtocolParser.GetUserFromSender(line.Sender), line.FinalArgument); break; case "311": OnWhoisResultReceived?.Invoke(new IrcUser(line.Arguments[1], line.Arguments[2], line.Arguments[3])); break; case "332": OnTopicReceived?.Invoke(line.Arguments[1], line.FinalArgument); break; case "333": ProcessTopicSet(line); break; case "366": OnNamesKnown?.Invoke(client.ChannelDict[line.Arguments[1]]); break; case "ERROR": OnErrorReceived?.Invoke(line.FinalArgument); break; default: OnFormattedLineReceived?.Invoke(line); break; } }
private void ProcessNameReply(IrcLine line) { var channelName = line.Arguments[2]; IrcChannel channel; try { channel = channels[channelName]; } catch (KeyNotFoundException) { Log(this, "Unable to process name reply: channel not found"); return; } var users = line.FinalArgument.Split(' '); foreach (var user in users) { if (user.StartsWith("@")) { channel.AddUser(user.Substring(1), IrcPermissionLevel.Operator); } else if (user.StartsWith("+")) { channel.AddUser(user.Substring(1), IrcPermissionLevel.Voiced); } else { channel.AddUser(user, IrcPermissionLevel.Default); } } }
private void ProcessKick(IrcLine line) { var sender = IrcProtocolParser.GetUserFromSender(line.Sender); if (line.Arguments[1].Equals(client.Nick)) { client.ChannelDict.Remove(line.Arguments[0]); OnKicked?.Invoke(line.Arguments[0], line.FinalArgument, sender); } else { OnKick?.Invoke(line.Arguments[1], line.Arguments[0], line.FinalArgument, sender); } }
private void ProcessJoin(IrcLine line) { var sender = parser.GetUserFromSender(line.Sender); if (sender.Nick == Nick) { if (Ident != sender.Ident) { Log(this, string.Format("Warning: Real ident ({0}) differs from requested ident ({1}). Ident field changed according to real ident", sender.Ident, Ident)); Ident = sender.Ident; } if (LocalHost == null) { Log(this, "Hostmask detected as " + sender.Hostmask); LocalHost = sender.Hostmask; } if (channels.ContainsKey(line.Arguments[0])) { throw new InvalidOperationException("Received a JOIN for " + line.Arguments[0] + " whil already in this channel."); } channels.Add(line.Arguments[0], new IrcChannel(line.Arguments[0])); if (OnJoinedChannel != null) { Task.Run(() => OnJoinedChannel(line.Arguments[0])); } } else { channels[line.Arguments[0]].AddUser(sender.Nick, IrcPermissionLevel.Default); if (OnJoinChannel != null) { Task.Run(() => OnJoinChannel(sender, line.Arguments[0])); } } }
/// <summary> /// Custom code for checking whether a user has registered with NickServ. Ugly, but it works. /// </summary> internal void ProcessFormattedLine(IrcLine line) { // This IRC server does not have a NickServ service. /*if (line.Command.Equals("401") && ircInterface.HasNickservCall && line.FinalArgument.ToLower().Contains("nickserv: no such nick")) { ircInterface.DisableNickservCalls(); // Proess reply to WHOIS call. }*/ /*else if (line.Command.Equals("464")) { //throw new NotImplementedException("Unable to supply the password from the IRC Event Handler."); Logger.Log(this, "Password required by server.", LogLevel.Info); var msg = "PASS " + ircInterface.Password; Logger.Log(this, "Replying with " + msg, LogLevel.Info); ircInterface.SendRaw(msg); }*/ if (!ignoredCommands.Contains(line.Command)) { switch (line.Command) { case "001": // RPL_WELCOME case "002": // RPL_YOURHOST Logger.Log(this, $"{line.FinalArgument}", LogLevel.Irc); break; case "003": // RPL_CREATED Logger.Log(this, $"{line.Sender}: {line.FinalArgument}", LogLevel.Irc); break; case "332": // RPL_TOPIC Logger.Log(this, $"Topic for {line.Arguments[1]}: {line.FinalArgument}", LogLevel.Irc); break; case "333": // Ignore names list case "366": break; case "253": // RPL_LUSERUNKNOWN break; case "375": // RPL_MOTDSTART case "376": // RPL_ENDOFMOTD case "372": // RPL_MOTD case "451": // ERR_NOTREGISTERED Logger.Log(this, $"{line.FinalArgument}", LogLevel.Irc); break; case "MODE": // TODO: Figure out the difference between these two and document it. Probably channel/user if (line.FinalArgument != null) { Logger.Log(this, $"{line.Sender} sets mode {line.FinalArgument} for {line.Arguments[0]}", LogLevel.Irc); } else { Logger.Log(this, $"{line.Sender} sets mode {line.Arguments[1]} for {line.Arguments[0]}"); } break; default: Debugger.Break(); Logger.Log(this, line.ToString(), LogLevel.Irc); break; } } }