public static BanInfo Parse(IrcMessageData data) { BanInfo info = new BanInfo(); // :magnet.oftc.net 367 meebey #smuxi test!test@test [email protected] 1216309801.. info.f_Channel = data.RawMessageArray[3]; info.f_Mask= data.RawMessageArray[4]; return info; }
internal TopicEventArgs(IrcMessageData data, string channel, string topic) : base(data) { this._Channel = channel; this._Topic = topic; }
internal MotdEventArgs(IrcMessageData data, string motdmsg) : base(data) { this._MotdMessage = motdmsg; }
/// <summary> /// Event handler for invite messages /// </summary> /// <param name="ircdata">Message data containing invite information</param> private void _Event_INVITE(IrcMessageData ircdata) { string channel = ircdata.Channel; string inviter = ircdata.Nick; if (AutoJoinOnInvite) { if (channel.Trim() != "0") { RfcJoin(channel); } } if (OnInvite != null) { OnInvite(this, new InviteEventArgs(ircdata, channel, inviter)); } }
/// <summary> /// Event handler for error messages /// </summary> /// <param name="ircdata">Message data containing error information</param> private void _Event_ERROR(IrcMessageData ircdata) { string message = ircdata.Message; #if LOG4NET Logger.Connection.Info("received ERROR from IRC server"); #endif if (OnError != null) { OnError(this, new ErrorEventArgs(ircdata, message)); } }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <param name="message"></param> public void SendReply(IrcMessageData data, string message) { SendReply(data, message, Priority.Medium); }
public static BanInfo Parse(IrcMessageData data) { // :magnet.oftc.net 367 meebey #smuxi test!test@test [email protected] 1216309801.. return(new BanInfo(data.RawMessageArray[3], data.RawMessageArray[4])); }
internal CtcpEventArgs(IrcMessageData data, string ctcpcmd, string ctcpparam) : base(data) { this._CtcpCommand = ctcpcmd; this._CtcpParameter = ctcpparam; }
/// <summary> /// Event handler for channel mode reply messages /// </summary> /// <param name="ircdata">Message data containing reply information</param> private void _Event_RPL_CHANNELMODEIS(IrcMessageData ircdata) { if (ActiveChannelSyncing && IsJoined(ircdata.Channel)) { string mode = ircdata.RawMessageArray[4]; string parameter = String.Join(" ", ircdata.RawMessageArray, 5, ircdata.RawMessageArray.Length-5); _InterpretChannelMode(ircdata, mode, parameter); } }
// TODO, need to sync with the banlist! private void _Event_RPL_BANLIST(IrcMessageData ircdata) { }
/// <summary> /// Event handler for away messages /// </summary> /// <param name="ircdata">Message data containing away reply information</param> private void _Event_RPL_AWAY(IrcMessageData ircdata) { string who = ircdata.RawMessageArray[3]; string awaymessage = ircdata.Message; if (ActiveChannelSyncing) { IrcUser ircuser = GetIrcUser(who); if (ircuser != null) { #if LOG4NET Logger.ChannelSyncing.Debug("setting away flag for user: "+who); #endif ircuser.IsAway = true; } } if (OnAway != null) { OnAway(this, new AwayEventArgs(ircdata, who, awaymessage)); } }
/// <summary> /// Event handler for quit messages /// </summary> /// <param name="ircdata">Message data containing quit information</param> private void _Event_QUIT(IrcMessageData ircdata) { string who = ircdata.Nick; string reason = ircdata.Message; // no need to handle if we quit, disconnect event will take care if (ActiveChannelSyncing) { // sanity checks, freshirc is very broken about RFC IrcUser user = GetIrcUser(who); if (user != null) { string[] joined_channels = user.JoinedChannels; if (joined_channels != null) { foreach (string channel in joined_channels) { _RemoveChannelUser(channel, who); } _RemoveIrcUser(who); #if LOG4NET } else { Logger.ChannelSyncing.Error("user.JoinedChannels (for: '"+who+"') returned null in _Event_QUIT! Ignoring..."); #endif } #if LOG4NET } else { Logger.ChannelSyncing.Error("GetIrcUser("+who+") returned null in _Event_QUIT! Ignoring..."); #endif } } if (OnQuit != null) { OnQuit(this, new QuitEventArgs(ircdata, who, reason)); } }
/// <summary> /// Event handler for private messages /// </summary> /// <param name="ircdata">Message data containing private message information</param> private void _Event_PRIVMSG(IrcMessageData ircdata) { if (ircdata.Type == ReceiveType.CtcpRequest) { if (ircdata.Message.StartsWith("\x1"+"PING")) { if (ircdata.Message.Length > 7) { SendMessage(SendType.CtcpReply, ircdata.Nick, "PING "+ircdata.Message.Substring(6, (ircdata.Message.Length-7))); } else { SendMessage(SendType.CtcpReply, ircdata.Nick, "PING"); } } else if (ircdata.Message.StartsWith("\x1"+"VERSION")) { string versionstring; if (_CtcpVersion == null) { versionstring = VersionString; } else { versionstring = _CtcpVersion; } SendMessage(SendType.CtcpReply, ircdata.Nick, "VERSION "+versionstring); } else if (ircdata.Message.StartsWith("\x1"+"CLIENTINFO")) { SendMessage(SendType.CtcpReply, ircdata.Nick, "CLIENTINFO PING VERSION CLIENTINFO"); } } switch (ircdata.Type) { case ReceiveType.ChannelMessage: if (OnChannelMessage != null) { OnChannelMessage(this, new IrcEventArgs(ircdata)); } break; case ReceiveType.ChannelAction: if (OnChannelAction != null) { string action = ircdata.Message.Substring(7, ircdata.Message.Length-8); OnChannelAction(this, new ActionEventArgs(ircdata, action)); } break; case ReceiveType.QueryMessage: if (OnQueryMessage != null) { OnQueryMessage(this, new IrcEventArgs(ircdata)); } break; case ReceiveType.QueryAction: if (OnQueryAction != null) { string action = ircdata.Message.Substring(7, ircdata.Message.Length-8); OnQueryAction(this, new ActionEventArgs(ircdata, action)); } break; case ReceiveType.CtcpRequest: if (OnCtcpRequest != null) { int space_pos = ircdata.Message.IndexOf(' '); string cmd = ""; string param = ""; if (space_pos != -1) { cmd = ircdata.Message.Substring(1, space_pos - 1); param = ircdata.Message.Substring(space_pos + 1, ircdata.Message.Length - space_pos - 2); } else { cmd = ircdata.Message.Substring(1, ircdata.Message.Length - 2); } OnCtcpRequest(this, new CtcpEventArgs(ircdata, cmd, param)); } break; } }
/// <summary> /// Event handler for PONG messages /// </summary> /// <param name="ircdata">Message data containing pong information</param> private void _Event_PONG(IrcMessageData ircdata) { if (OnPong != null) { OnPong(this, new PongEventArgs(ircdata, ircdata.Irc.Lag)); } }
// <internal messagehandler> /// <summary> /// Event handler for ping messages /// </summary> /// <param name="ircdata">Message data containing ping information</param> private void _Event_PING(IrcMessageData ircdata) { string server = ircdata.RawMessageArray[1].Substring(1); #if LOG4NET Logger.Connection.Debug("Ping? Pong!"); #endif RfcPong(server, Priority.Critical); if (OnPing != null) { OnPing(this, new PingEventArgs(ircdata, server)); } }
internal AwayEventArgs(IrcMessageData data, string who, string awaymessage) : base(data) { this._Who = who; this._AwayMessage = awaymessage; }
public void SendReply(IrcMessageData data, string message) { SendReply(data, message, Priority.Medium); }
private void _Event_RPL_ENDOFBANLIST(IrcMessageData ircdata) { string channelname = ircdata.Channel; if (ActiveChannelSyncing && IsJoined(channelname)) { Channel channel = GetChannel(channelname); channel.ActiveSyncStop = DateTime.Now; #if LOG4NET Logger.ChannelSyncing.Debug("active synced: "+channelname+ " (in "+channel.ActiveSyncTime.TotalSeconds+" sec)"); #endif if (OnChannelActiveSynced != null) { OnChannelActiveSynced(this, new IrcEventArgs(ircdata)); } } }
internal ListEventArgs(IrcMessageData data, ChannelInfo listInfo) : base(data) { this.f_ListInfo = listInfo; }
/// <summary> /// Event handler for end of mesage of the day reply messages /// </summary> /// <param name="ircdata">Message data containing end of mesage of the day information</param> private void _Event_RPL_ENDOFMOTD(IrcMessageData ircdata) { _MotdReceived = true; }
public static void HandleDownloadFile(IrcClient client, IrcMessageData messageData) { if (!Scanner.Configuration.Proxy.Enabled) { client.SendReply(messageData, "Command disabled."); return; } if (!RemoteBuildManager.IsBuildKnown(messageData.MessageArray[1])) { client.SendReply(messageData, "Unknown build."); return; } CheckFileExists(messageData.MessageArray[1], buildInfo => { var remoteFileName = string.Join(" ", messageData.MessageArray.Skip(2)); var indexEntry = buildInfo.GetEntry(remoteFileName); if (indexEntry == null) { client.SendReply(messageData, $"{messageData.Nick}: File does not exist."); return; } // Give out link // Disable resharper for readability // ReSharper disable once UseStringInterpolation var response = string.Format("http://{0}/{1}/{2}/{3}", Scanner.Proxy.PublicDomain, buildInfo.VersionName, JenkinsHashing.Instance.ComputeHash(messageData.MessageArray[2]), Path.GetFileName(remoteFileName.Replace('\\', '/'))); client.SendReply(messageData, $"{messageData.Nick}: {response}"); }, buildInfo => { client.SendReply(messageData, $"{messageData.Nick}: Loading {buildInfo.VersionName} ..."); }, () => { var buildInfo = RemoteBuildManager.GetBuild(messageData.MessageArray[1]); if (buildInfo.Loading) { client.SendReply(messageData, $"{messageData.Nick}: Build {buildInfo.VersionName} is currently loading."); return; } client.SendReply(messageData, $"{messageData.Nick}: Build {buildInfo.VersionName} has been loaded."); if (!buildInfo.Install.Loaded) { client.SendReply(messageData, $"{messageData.Nick}: Install file could not be downloaded, expect erroneous results."); } Task.Delay(10 * 60 * 1000).ContinueWith(t => { buildInfo.Expired = true; }); }); }
/// <summary> /// Event handler for end of names reply messages /// </summary> /// <param name="ircdata">Message data containing end of names reply information</param> private void _Event_RPL_ENDOFNAMES(IrcMessageData ircdata) { string channelname = ircdata.RawMessageArray[3]; if (ActiveChannelSyncing && IsJoined(channelname)) { #if LOG4NET Logger.ChannelSyncing.Debug("passive synced: "+channelname); #endif if (OnChannelPassiveSynced != null) { OnChannelPassiveSynced(this, new IrcEventArgs(ircdata)); } } }
/// <summary> /// Event handler for part messages /// </summary> /// <param name="ircdata">Message data containing part information</param> private void _Event_PART(IrcMessageData ircdata) { string who = ircdata.Nick; string channel = ircdata.Channel; string partmessage = ircdata.Message; if (IsMe(who)) { _JoinedChannels.Remove(channel); } if (ActiveChannelSyncing) { if (IsMe(who)) { #if LOG4NET Logger.ChannelSyncing.Debug("parting channel: "+channel); #endif _Channels.Remove(channel); } else { #if LOG4NET Logger.ChannelSyncing.Debug(who+" parts channel: "+channel); #endif _RemoveChannelUser(channel, who); _RemoveIrcUser(who); } } if (OnPart != null) { OnPart(this, new PartEventArgs(ircdata, channel, who, partmessage)); } }
/// <summary> /// Event handler for mesage of the day reply messages /// </summary> /// <param name="ircdata">Message data containing mesage of the day information</param> private void _Event_RPL_MOTD(IrcMessageData ircdata) { if (!_MotdReceived) { _Motd.Add(ircdata.Message); } if (OnMotd != null) { OnMotd(this, new MotdEventArgs(ircdata, ircdata.Message)); } }
/// <summary> /// Event handler for nickname in use error messages /// </summary> /// <param name="ircdata">Message data containing nickname in use error information</param> private void _Event_ERR_NICKNAMEINUSE(IrcMessageData ircdata) { #if LOG4NET Logger.Connection.Warn("nickname collision detected, changing nickname"); #endif if (!AutoNickHandling) { return; } string nickname; // if a nicklist has been given loop through the nicknames // if the upper limit of this list has been reached and still no nickname has registered // then generate a random nick if (_CurrentNickname == NicknameList.Length-1) { Random rand = new Random(); int number = rand.Next(999); if (Nickname.Length > 5) { nickname = Nickname.Substring(0, 5)+number; } else { nickname = Nickname.Substring(0, Nickname.Length-1)+number; } } else { nickname = _NextNickname(); } // change the nickname RfcNick(nickname, Priority.Critical); }
/// <summary> /// Event handler for name reply messages /// </summary> /// <param name="ircdata">Message data containing name reply information</param> private void _Event_RPL_NAMREPLY(IrcMessageData ircdata) { string channelname = ircdata.Channel; string[] userlist = ircdata.MessageArray; if (ActiveChannelSyncing && IsJoined(channelname)) { string nickname; bool op; bool halfop; bool voice; foreach (string user in userlist) { if (user.Length <= 0) { continue; } op = false; halfop = false; voice = false; switch (user[0]) { case '@': op = true; nickname = user.Substring(1); break; case '+': voice = true; nickname = user.Substring(1); break; // RFC VIOLATION // some IRC network do this and break our channel sync... case '&': nickname = user.Substring(1); break; case '%': halfop = true; nickname = user.Substring(1); break; case '~': nickname = user.Substring(1); break; default: nickname = user; break; } IrcUser ircuser = GetIrcUser(nickname); ChannelUser channeluser = GetChannelUser(channelname, nickname); if (ircuser == null) { #if LOG4NET Logger.ChannelSyncing.Debug("creating IrcUser: "******" because he doesn't exist yet"); #endif ircuser = new IrcUser(nickname, this); _IrcUsers.Add(nickname, ircuser); } if (channeluser == null) { #if LOG4NET Logger.ChannelSyncing.Debug("creating ChannelUser: "******" for Channel: "+channelname+" because he doesn't exist yet"); #endif if (SupportNonRfc) { channeluser = new NonRfcChannelUser(channelname, ircuser); } else { channeluser = new ChannelUser(channelname, ircuser); } Channel channel = GetChannel(channelname); channel.UnsafeUsers.Add(nickname, channeluser); if (op) { channel.UnsafeOps.Add(nickname, channeluser); #if LOG4NET Logger.ChannelSyncing.Debug("added op: "+nickname+" to: "+channelname); #endif } if (SupportNonRfc && halfop) { ((NonRfcChannel)channel).UnsafeHalfops.Add(nickname, channeluser); #if LOG4NET Logger.ChannelSyncing.Debug("added halfop: "+nickname+" to: "+channelname); #endif } if (voice) { channel.UnsafeVoices.Add(nickname, channeluser); #if LOG4NET Logger.ChannelSyncing.Debug("added voice: "+nickname+" to: "+channelname); #endif } } channeluser.IsOp = op; channeluser.IsVoice = voice; if (SupportNonRfc) { ((NonRfcChannelUser)channeluser).IsHalfop = halfop; } } } if (OnNames != null) { OnNames(this, new NamesEventArgs(ircdata, channelname, userlist)); } }
/// <summary> /// Event handler for join messages /// </summary> /// <param name="ircdata">Message data containing join information</param> private void _Event_JOIN(IrcMessageData ircdata) { string who = ircdata.Nick; string channelname = ircdata.Channel; if (IsMe(who)) { _JoinedChannels.Add(channelname); } if (ActiveChannelSyncing) { Channel channel; if (IsMe(who)) { // we joined the channel #if LOG4NET Logger.ChannelSyncing.Debug("joining channel: "+channelname); #endif if (SupportNonRfc) { channel = new NonRfcChannel(channelname); } else { channel = new Channel(channelname); } _Channels.Add(channelname, channel); // request channel mode RfcMode(channelname); // request wholist RfcWho(channelname); // request banlist Ban(channelname); } else { // someone else joined the channel // request the who data RfcWho(who); } #if LOG4NET Logger.ChannelSyncing.Debug(who+" joins channel: "+channelname); #endif channel = GetChannel(channelname); IrcUser ircuser = GetIrcUser(who); if (ircuser == null) { ircuser = new IrcUser(who, this); ircuser.Ident = ircdata.Ident; ircuser.Host = ircdata.Host; _IrcUsers.Add(who, ircuser); } ChannelUser channeluser; if (SupportNonRfc) { channeluser = new NonRfcChannelUser(channelname, ircuser); } else { channeluser = new ChannelUser(channelname, ircuser); } channel.UnsafeUsers.Add(who, channeluser); } if (OnJoin != null) { OnJoin(this, new JoinEventArgs(ircdata, channelname, who)); } }
/// <summary> /// Event handler for nowaway messages /// </summary> /// <param name="ircdata">Message data containing nowaway reply information</param> private void _Event_RPL_NOWAWAY(IrcMessageData ircdata) { _IsAway = true; if (OnNowAway != null) { OnNowAway(this, new IrcEventArgs(ircdata)); } }
internal ActionEventArgs(IrcMessageData data, string actionmsg) : base(data, "ACTION", actionmsg) { this._ActionMessage = actionmsg; }
/// <summary> /// Event handler for topic reply messages /// </summary> /// <param name="ircdata">Message data containing topic information</param> private void _Event_RPL_TOPIC(IrcMessageData ircdata) { string topic = ircdata.Message; string channel = ircdata.Channel; if (ActiveChannelSyncing && IsJoined(channel)) { GetChannel(channel).Topic = topic; #if LOG4NET Logger.ChannelSyncing.Debug("stored topic for channel: "+channel); #endif } if (OnTopic != null) { OnTopic(this, new TopicEventArgs(ircdata, channel, topic)); } }
internal InviteEventArgs(IrcMessageData data, string channel, string who) : base(data) { this._Channel = channel; this._Who = who; }
/// <summary> /// Event handler for unaway messages /// </summary> /// <param name="ircdata">Message data containing unaway reply information</param> private void _Event_RPL_UNAWAY(IrcMessageData ircdata) { _IsAway = false; if (OnUnAway != null) { OnUnAway(this, new IrcEventArgs(ircdata)); } }
public ChannelMessageEventArgs([NotNull] IrcMessageData ircData) { IrcData = ircData; RawMessage = new RawMessageEventArgs(IrcData); }
/// <summary> /// Event handler for welcome reply messages /// </summary> /// <remark> /// Upon success, the client will receive an RPL_WELCOME (for users) or /// RPL_YOURESERVICE (for services) message indicating that the /// connection is now registered and known the to the entire IRC network. /// The reply message MUST contain the full client identifier upon which /// it was registered. /// </remark> /// <param name="ircdata">Message data containing reply information</param> private void _Event_RPL_WELCOME(IrcMessageData ircdata) { // updating our nickname, that we got (maybe cutted...) _Nickname = ircdata.RawMessageArray[2]; if (OnRegistered != null) { OnRegistered(this, EventArgs.Empty); } }
internal PingEventArgs(IrcMessageData data, string pingdata) : base(data) { this._PingData = pingdata; }
/// <summary> /// Event handler for who reply messages /// </summary> /// <param name="ircdata">Message data containing who reply information</param> private void _Event_RPL_WHOREPLY(IrcMessageData ircdata) { string channel = ircdata.Channel; string ident = ircdata.RawMessageArray[4]; string host = ircdata.RawMessageArray[5]; string server = ircdata.RawMessageArray[6]; string nick = ircdata.RawMessageArray[7]; string usermode = ircdata.RawMessageArray[8]; string realname = ircdata.Message.Substring(2); int hopcount = 0; string temp = ircdata.RawMessageArray[9].Substring(1); try { hopcount = int.Parse(temp); } catch (FormatException) { #if LOG4NET Logger.MessageParser.Warn("couldn't parse (as int): '"+temp+"'"); #endif } bool op = false; bool voice = false; bool ircop = false; bool away = false; int usermodelength = usermode.Length; for (int i = 0; i < usermodelength; i++) { switch (usermode[i]) { case 'H': away = false; break; case 'G': away = true; break; case '@': op = true; break; case '+': voice = true; break; case '*': ircop = true; break; } } if (ActiveChannelSyncing && IsJoined(channel)) { // checking the irc and channel user I only do for sanity! // according to RFC they must be known to us already via RPL_NAMREPLY // psyBNC is not very correct with this... maybe other bouncers too IrcUser ircuser = GetIrcUser(nick); ChannelUser channeluser = GetChannelUser(channel, nick); #if LOG4NET if (ircuser == null) { Logger.ChannelSyncing.Error("GetIrcUser("+nick+") returned null in _Event_WHOREPLY! Ignoring..."); } #endif #if LOG4NET if (channeluser == null) { Logger.ChannelSyncing.Error("GetChannelUser("+nick+") returned null in _Event_WHOREPLY! Ignoring..."); } #endif if (ircuser != null) { #if LOG4NET Logger.ChannelSyncing.Debug("updating userinfo (from whoreply) for user: "******" channel: "+channel); #endif ircuser.Ident = ident; ircuser.Host = host; ircuser.Server = server; ircuser.Nick = nick; ircuser.HopCount = hopcount; ircuser.Realname = realname; ircuser.IsAway = away; ircuser.IsIrcOp = ircop; switch (channel[0]) { case '#': case '!': case '&': case '+': // this channel may not be where we are joined! // see RFC 1459 and RFC 2812, it must return a channelname // we use this channel info when possible... if (channeluser != null) { channeluser.IsOp = op; channeluser.IsVoice = voice; } break; } } } if (OnWho != null) { OnWho(this, new WhoEventArgs(ircdata, channel, nick, ident, host, realname, away, op, voice, ircop, server, hopcount)); } }
internal NickChangeEventArgs(IrcMessageData data, string oldnick, string newnick) : base(data) { this._OldNickname = oldnick; this._NewNickname = newnick; }
/// <summary> /// Event handler for topic messages /// </summary> /// <param name="ircdata">Message data containing topic information</param> private void _Event_TOPIC(IrcMessageData ircdata) { string who = ircdata.Nick; string channel = ircdata.Channel; string newtopic = ircdata.Message; if (ActiveChannelSyncing && IsJoined(channel)) { GetChannel(channel).Topic = newtopic; #if LOG4NET Logger.ChannelSyncing.Debug("stored topic for channel: "+channel); #endif } if (OnTopicChange != null) { OnTopicChange(this, new TopicChangeEventArgs(ircdata, channel, who, newtopic)); } }
public static string GetAlias(IrcMessage theMessage) { List <string> SplitString = new List <string>(theMessage.Message.TrimStart('!', ' ').Split(' ')); if (SplitString[0] == "alias" || SplitString[0] == "a") { SplitString.RemoveAt(0); } string thealias; using (var context = new BotContext()) { string key = SplitString[0]; AliasEntry entry = context.AliasEntries.FirstOrDefault(x => x.Key == key); if (entry != null && !String.IsNullOrEmpty(entry.Text)) { thealias = entry.Text; } else { return(String.Empty); } } for (int i = 0; thealias.Contains("$") && i < 99; i++) { if (SplitString.Count > 1) { string commandline = SplitString.Skip(1).Join(" "); thealias = thealias.Replace("$x", commandline).Replace("$X", commandline); } else { thealias = thealias.Replace("$x", "").Replace("$X", ""); } while (true) { int index = thealias.IndexOf("$" + (i + 1)); if (index == -1) { break; } thealias = thealias.Remove(index, 2); if (SplitString.Count - 1 > i) { thealias = thealias.Insert(index, SplitString[i + 1]); } else { thealias = thealias.Insert(index, ""); } } } while (thealias.Contains("encode(")) { int start = thealias.LastIndexOf("encode("); int end = thealias.Remove(0, start).IndexOf(')') + 1 + start; string second = thealias.Substring(start + 7, end - (start + 8)); second = Toolbox.UrlEncode(second); second = second.Replace("%23", "#").Replace("%3a", ":").Replace("%2f", "/").Replace("%3f", "?"); thealias = thealias.Substring(0, start) + second + thealias.Substring(end); } if (thealias[0] == '!') { StackTrace trace = new StackTrace(); StackFrame[] frames = trace.GetFrames(); int recursion = frames.Count(x => x.GetMethod() == frames[0].GetMethod()); if (recursion > 4) { theMessage.Answer("Einen moment mal... das scheint rekursiv zu sein. Ich beende das mal"); return(String.Empty); } IrcMessageData data = new IrcMessageData(theMessage.Data.Irc, theMessage.Data.From, theMessage.Data.Nick, theMessage.Data.Ident, theMessage.Data.Host, theMessage.Data.Channel, thealias, thealias, theMessage.Data.Type, theMessage.Data.ReplyCode, theMessage.Data.Tags); IrcMessage fake = new IrcMessage(data, theMessage.ServerConnetion); Program.HandleCommand(fake); theMessage.Hidden = fake.Hidden; theMessage.ProcessedByCommand = fake.ProcessedByCommand; for (int i = 0; i < fake.UnloggedMessages.Count; i++) { theMessage.UnloggedMessages.Enqueue(fake.UnloggedMessages.Dequeue()); } return(String.Empty); } return(thealias); }
private void _HandleEvents(IrcMessageData ircdata) { if (OnRawMessage != null) { OnRawMessage(this, new IrcEventArgs(ircdata)); } string code; // special IRC messages code = ircdata.RawMessageArray[0]; switch (code) { case "PING": _Event_PING(ircdata); break; case "ERROR": _Event_ERROR(ircdata); break; } code = ircdata.RawMessageArray[1]; switch (code) { case "PRIVMSG": _Event_PRIVMSG(ircdata); break; case "NOTICE": _Event_NOTICE(ircdata); break; case "JOIN": _Event_JOIN(ircdata); break; case "PART": _Event_PART(ircdata); break; case "KICK": _Event_KICK(ircdata); break; case "QUIT": _Event_QUIT(ircdata); break; case "TOPIC": _Event_TOPIC(ircdata); break; case "NICK": _Event_NICK(ircdata); break; case "INVITE": _Event_INVITE(ircdata); break; case "MODE": _Event_MODE(ircdata); break; case "PONG": _Event_PONG(ircdata); break; } if (ircdata.ReplyCode != ReplyCode.Null) { switch (ircdata.ReplyCode) { case ReplyCode.Welcome: _Event_RPL_WELCOME(ircdata); break; case ReplyCode.Topic: _Event_RPL_TOPIC(ircdata); break; case ReplyCode.NoTopic: _Event_RPL_NOTOPIC(ircdata); break; case ReplyCode.NamesReply: _Event_RPL_NAMREPLY(ircdata); break; case ReplyCode.EndOfNames: _Event_RPL_ENDOFNAMES(ircdata); break; case ReplyCode.WhoReply: _Event_RPL_WHOREPLY(ircdata); break; case ReplyCode.ChannelModeIs: _Event_RPL_CHANNELMODEIS(ircdata); break; case ReplyCode.BanList: _Event_RPL_BANLIST(ircdata); break; case ReplyCode.EndOfBanList: _Event_RPL_ENDOFBANLIST(ircdata); break; case ReplyCode.Motd: _Event_RPL_MOTD(ircdata); break; case ReplyCode.EndOfMotd: _Event_RPL_ENDOFMOTD(ircdata); break; case ReplyCode.Away: _Event_RPL_AWAY(ircdata); break; case ReplyCode.UnAway: _Event_RPL_UNAWAY(ircdata); break; case ReplyCode.NowAway: _Event_RPL_NOWAWAY(ircdata); break; case ReplyCode.ErrorNicknameInUse: _Event_ERR_NICKNAMEINUSE(ircdata); break; } } if (ircdata.Type == ReceiveType.ErrorMessage) { _Event_ERR(ircdata); } }
internal QuitEventArgs(IrcMessageData data, string who, string quitmessage) : base(data) { this._Who = who; this._QuitMessage = quitmessage; }
/// <summary> /// /// </summary> /// <param name="ircdata">Message data containing channel mode information</param> /// <param name="mode">Channel mode</param> /// <param name="parameter">List of supplied paramaters</param> private void _InterpretChannelMode(IrcMessageData ircdata, string mode, string parameter) { string[] parameters = parameter.Split(new char[] {' '}); bool add = false; bool remove = false; int modelength = mode.Length; string temp; Channel channel = null; if (ActiveChannelSyncing) { channel = GetChannel(ircdata.Channel); } IEnumerator parametersEnumerator = parameters.GetEnumerator(); // bring the enumerator to the 1. element parametersEnumerator.MoveNext(); for (int i = 0; i < modelength; i++) { switch(mode[i]) { case '-': add = false; remove = true; break; case '+': add = true; remove = false; break; case 'o': temp = (string)parametersEnumerator.Current; parametersEnumerator.MoveNext(); if (add) { if (ActiveChannelSyncing) { // sanity check if (GetChannelUser(ircdata.Channel, temp) != null) { // update the op list try { channel.UnsafeOps.Add(temp, GetIrcUser(temp)); #if LOG4NET Logger.ChannelSyncing.Debug("added op: "+temp+" to: "+ircdata.Channel); #endif } catch (ArgumentException) { #if LOG4NET Logger.ChannelSyncing.Debug("duplicate op: "+temp+" in: "+ircdata.Channel+" not added"); #endif } // update the user op status ChannelUser cuser = GetChannelUser(ircdata.Channel, temp); cuser.IsOp = true; #if LOG4NET Logger.ChannelSyncing.Debug("set op status: " + temp + " for: "+ircdata.Channel); #endif } else { #if LOG4NET Logger.ChannelSyncing.Error("_InterpretChannelMode(): GetChannelUser(" + ircdata.Channel + "," + temp + ") returned null! Ignoring..."); #endif } } if (OnOp != null) { OnOp(this, new OpEventArgs(ircdata, ircdata.Channel, ircdata.Nick, temp)); } } if (remove) { if (ActiveChannelSyncing) { // sanity check if (GetChannelUser(ircdata.Channel, temp) != null) { // update the op list channel.UnsafeOps.Remove(temp); #if LOG4NET Logger.ChannelSyncing.Debug("removed op: "+temp+" from: "+ircdata.Channel); #endif // update the user op status ChannelUser cuser = GetChannelUser(ircdata.Channel, temp); cuser.IsOp = false; #if LOG4NET Logger.ChannelSyncing.Debug("unset op status: " + temp + " for: "+ircdata.Channel); #endif } else { #if LOG4NET Logger.ChannelSyncing.Error("_InterpretChannelMode(): GetChannelUser(" + ircdata.Channel + "," + temp + ") returned null! Ignoring..."); #endif } } if (OnDeop != null) { OnDeop(this, new DeopEventArgs(ircdata, ircdata.Channel, ircdata.Nick, temp)); } } break; case 'h': if (SupportNonRfc) { temp = (string)parametersEnumerator.Current; parametersEnumerator.MoveNext(); if (add) { if (ActiveChannelSyncing) { // sanity check if (GetChannelUser(ircdata.Channel, temp) != null) { // update the halfop list try { ((NonRfcChannel)channel).UnsafeHalfops.Add(temp, GetIrcUser(temp)); #if LOG4NET Logger.ChannelSyncing.Debug("added halfop: "+temp+" to: "+ircdata.Channel); #endif } catch (ArgumentException) { #if LOG4NET Logger.ChannelSyncing.Debug("duplicate halfop: "+temp+" in: "+ircdata.Channel+" not added"); #endif } // update the user halfop status NonRfcChannelUser cuser = (NonRfcChannelUser)GetChannelUser(ircdata.Channel, temp); cuser.IsHalfop = true; #if LOG4NET Logger.ChannelSyncing.Debug("set halfop status: " + temp + " for: "+ircdata.Channel); #endif } else { #if LOG4NET Logger.ChannelSyncing.Error("_InterpretChannelMode(): GetChannelUser(" + ircdata.Channel + "," + temp + ") returned null! Ignoring..."); #endif } } if (OnHalfop != null) { OnHalfop(this, new HalfopEventArgs(ircdata, ircdata.Channel, ircdata.Nick, temp)); } } if (remove) { if (ActiveChannelSyncing) { // sanity check if (GetChannelUser(ircdata.Channel, temp) != null) { // update the halfop list ((NonRfcChannel)channel).UnsafeHalfops.Remove(temp); #if LOG4NET Logger.ChannelSyncing.Debug("removed halfop: "+temp+" from: "+ircdata.Channel); #endif // update the user halfop status NonRfcChannelUser cuser = (NonRfcChannelUser)GetChannelUser(ircdata.Channel, temp); cuser.IsHalfop = false; #if LOG4NET Logger.ChannelSyncing.Debug("unset halfop status: " + temp + " for: "+ircdata.Channel); #endif } else { #if LOG4NET Logger.ChannelSyncing.Error("_InterpretChannelMode(): GetChannelUser(" + ircdata.Channel + "," + temp + ") returned null! Ignoring..."); #endif } } if (OnDehalfop != null) { OnDehalfop(this, new DehalfopEventArgs(ircdata, ircdata.Channel, ircdata.Nick, temp)); } } } break; case 'v': temp = (string)parametersEnumerator.Current; parametersEnumerator.MoveNext(); if (add) { if (ActiveChannelSyncing) { // sanity check if (GetChannelUser(ircdata.Channel, temp) != null) { // update the voice list try { channel.UnsafeVoices.Add(temp, GetIrcUser(temp)); #if LOG4NET Logger.ChannelSyncing.Debug("added voice: "+temp+" to: "+ircdata.Channel); #endif } catch (ArgumentException) { #if LOG4NET Logger.ChannelSyncing.Debug("duplicate voice: "+temp+" in: "+ircdata.Channel+" not added"); #endif } // update the user voice status ChannelUser cuser = GetChannelUser(ircdata.Channel, temp); cuser.IsVoice = true; #if LOG4NET Logger.ChannelSyncing.Debug("set voice status: " + temp + " for: "+ircdata.Channel); #endif } else { #if LOG4NET Logger.ChannelSyncing.Error("_InterpretChannelMode(): GetChannelUser(" + ircdata.Channel + "," + temp + ") returned null! Ignoring..."); #endif } } if (OnVoice != null) { OnVoice(this, new VoiceEventArgs(ircdata, ircdata.Channel, ircdata.Nick, temp)); } } if (remove) { if (ActiveChannelSyncing) { // sanity check if (GetChannelUser(ircdata.Channel, temp) != null) { // update the voice list channel.UnsafeVoices.Remove(temp); #if LOG4NET Logger.ChannelSyncing.Debug("removed voice: "+temp+" from: "+ircdata.Channel); #endif // update the user voice status ChannelUser cuser = GetChannelUser(ircdata.Channel, temp); cuser.IsVoice = false; #if LOG4NET Logger.ChannelSyncing.Debug("unset voice status: " + temp + " for: "+ircdata.Channel); #endif } else { #if LOG4NET Logger.ChannelSyncing.Error("_InterpretChannelMode(): GetChannelUser(" + ircdata.Channel + "," + temp + ") returned null! Ignoring..."); #endif } } if (OnDevoice != null) { OnDevoice(this, new DevoiceEventArgs(ircdata, ircdata.Channel, ircdata.Nick, temp)); } } break; case 'b': temp = (string)parametersEnumerator.Current; parametersEnumerator.MoveNext(); if (add) { if (ActiveChannelSyncing) { try { channel.Bans.Add(temp); #if LOG4NET Logger.ChannelSyncing.Debug("added ban: "+temp+" to: "+ircdata.Channel); #endif } catch (ArgumentException) { #if LOG4NET Logger.ChannelSyncing.Debug("duplicate ban: "+temp+" in: "+ircdata.Channel+" not added"); #endif } } if (OnBan != null) { OnBan(this, new BanEventArgs(ircdata, ircdata.Channel, ircdata.Nick, temp)); } } if (remove) { if (ActiveChannelSyncing) { channel.Bans.Remove(temp); #if LOG4NET Logger.ChannelSyncing.Debug("removed ban: "+temp+" from: "+ircdata.Channel); #endif } if (OnUnban != null) { OnUnban(this, new UnbanEventArgs(ircdata, ircdata.Channel, ircdata.Nick, temp)); } } break; case 'l': temp = (string)parametersEnumerator.Current; parametersEnumerator.MoveNext(); if (add) { if (ActiveChannelSyncing) { try { channel.UserLimit = int.Parse(temp); #if LOG4NET Logger.ChannelSyncing.Debug("stored user limit for: "+ircdata.Channel); #endif } catch (FormatException) { #if LOG4NET Logger.ChannelSyncing.Error("could not parse user limit: "+temp+" channel: "+ircdata.Channel); #endif } } } if (remove) { if (ActiveChannelSyncing) { channel.UserLimit = 0; #if LOG4NET Logger.ChannelSyncing.Debug("removed user limit for: "+ircdata.Channel); #endif } } break; case 'k': temp = (string)parametersEnumerator.Current; parametersEnumerator.MoveNext(); if (add) { if (ActiveChannelSyncing) { channel.Key = temp; #if LOG4NET Logger.ChannelSyncing.Debug("stored channel key for: "+ircdata.Channel); #endif } } if (remove) { if (ActiveChannelSyncing) { channel.Key = ""; #if LOG4NET Logger.ChannelSyncing.Debug("removed channel key for: "+ircdata.Channel); #endif } } break; default: if (add) { if (ActiveChannelSyncing) { channel.Mode += mode[i]; #if LOG4NET Logger.ChannelSyncing.Debug("added channel mode ("+mode[i]+") for: "+ircdata.Channel); #endif } } if (remove) { if (ActiveChannelSyncing) { channel.Mode = channel.Mode.Replace(mode[i], new char()); #if LOG4NET Logger.ChannelSyncing.Debug("removed channel mode ("+mode[i]+") for: "+ircdata.Channel); #endif } } break; } } }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <param name="message"></param> /// <param name="priority"></param> public void SendReply(IrcMessageData data, string message, Priority priority) { switch (data.Type) { case ReceiveType.ChannelMessage: SendMessage(SendType.Message, data.Channel, message, priority); break; case ReceiveType.QueryMessage: SendMessage(SendType.Message, data.Nick, message, priority); break; case ReceiveType.QueryNotice: SendMessage(SendType.Notice, data.Nick, message, priority); break; } }
public IrcMessageData MessageParser(string rawline) { string line; string[] linear; string messagecode; string from; string nick = null; string ident = null; string host = null; string channel = null; string message = null; ReceiveType type; ReplyCode replycode; int exclamationpos; int atpos; int colonpos; if (rawline[0] == ':') { line = rawline.Substring(1); } else { line = rawline; } linear = line.Split(new char[] {' '}); // conform to RFC 2812 from = linear[0]; messagecode = linear[1]; exclamationpos = from.IndexOf("!"); atpos = from.IndexOf("@"); colonpos = line.IndexOf(" :"); if (colonpos != -1) { // we want the exact position of ":" not beginning from the space colonpos += 1; } if (exclamationpos != -1) { nick = from.Substring(0, exclamationpos); } if ((atpos != -1) && (exclamationpos != -1)) { ident = from.Substring(exclamationpos+1, (atpos - exclamationpos)-1); } if (atpos != -1) { host = from.Substring(atpos+1); } try { replycode = (ReplyCode)int.Parse(messagecode); } catch (FormatException) { replycode = ReplyCode.Null; } type = _GetMessageType(rawline); if (colonpos != -1) { message = line.Substring(colonpos+1); } switch (type) { case ReceiveType.Join: case ReceiveType.Kick: case ReceiveType.Part: case ReceiveType.TopicChange: case ReceiveType.ChannelModeChange: case ReceiveType.ChannelMessage: case ReceiveType.ChannelAction: case ReceiveType.ChannelNotice: channel = linear[2]; break; case ReceiveType.Who: case ReceiveType.Topic: case ReceiveType.Invite: case ReceiveType.BanList: case ReceiveType.ChannelMode: channel = linear[3]; break; case ReceiveType.Name: channel = linear[4]; break; } if ((channel != null) && (channel[0] == ':')) { channel = channel.Substring(1); } IrcMessageData data; data = new IrcMessageData(this, from, nick, ident, host, channel, message, rawline, type, replycode); #if LOG4NET Logger.MessageParser.Debug("IrcMessageData "+ "nick: '"+data.Nick+"' "+ "ident: '"+data.Ident+"' "+ "host: '"+data.Host+"' "+ "type: '"+data.Type.ToString()+"' "+ "from: '"+data.From+"' "+ "channel: '"+data.Channel+"' "+ "message: '"+data.Message+"' " ); #endif return data; }
/// <summary> /// Event handler for error messages /// </summary> /// <param name="ircdata">Message data containing error information</param> private void _Event_ERR(IrcMessageData ircdata) { if (OnErrorMessage != null) { OnErrorMessage(this, new IrcEventArgs(ircdata)); } }
public PrivateMessageEventArgs([NotNull] IrcMessageData ircData) { IrcData = ircData; RawMessage = new RawMessageEventArgs(IrcData); }