/// <summary> /// Sends a command to the users in this channel. /// </summary> /// <param name="sender">The IIrcUser who is sending the command.</param> /// <param name="command">The command being sent.</param> /// <param name="message">The contents of this command.</param> /// <param name="ignoreSender">Whether ignore the sender when sending this command.</param> public void Command(IIrcUser sender, string command, string message, bool ignoreSender = false) { IrcMessage ircMessage = new IrcMessage(); ircMessage.Prefix = sender.Nick; ircMessage.Command = command; string paramaters = message.Split(':')[0].Trim(); string trailing = ""; if (message.Split(':').Length == 2) { trailing = message.Split(':')[1].Trim(); } List <string> paramList = new List <string>(); paramList.AddRange(paramaters.Split(' ')); if (!string.IsNullOrEmpty(trailing)) { paramList.Add(trailing); } ircMessage.Params = paramList.ToArray(); SendMessage(sender, ircMessage, ignoreSender); }
public override void Run(IIrcUser client, IrcMessage message) { IrcChannel[] channels; if (message.Params.Length == 0) { channels = client.IrcServer.Channels.ToArray(); } else { string[] channelList = message.Params[0].ToLower().Split(','); channels = client.IrcServer.Channels.Where(channel => channelList.Contains(channel.Name.Replace(",", "").ToLower()) ).ToArray(); } channels.ForEach(channel => { client.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.RPL_NAMEREPLY, Extra = "= " + channel.Name, Message = string.Join(" ", channel.Users .Where(user => !user.Mode.IsInvisible || channel.Users.Contains(client) || client.Mode.IsOperator) .Select(user => string.Format("{0}{1}", user.ChannelModes[channel].NickPrefix, user.Nick))) }); }); client.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.RPL_ENDOFNAMES, Extra = client.Nick, Message = "End of names" }); }
public override void Run(IIrcUser client, IrcMessage message) { if (message.Params.Length != 1) { SendMessage(IrcNumericResponceId.ERR_NEEDMOREPARAMS, client, "Not enough parameters"); return; } if (IRC.IsChannel(message.Params[0])) { IrcChannel channel = client.IrcServer.Channels.Where(ch => ch.Name == message.Params[0]).FirstOrDefault(); if (channel == null) { return; } channel.Users.ForEach(cli => cli.Write(new IrcNumericResponce() { NumericId = IrcNumericResponceId.RPL_WHOREPLY, Message = cli.UserString })); client.Write(new IrcNumericResponce() { NumericId = IrcNumericResponceId.RPL_ENDOFWHO, Message = "End of who" }); } }
public override void Run(IIrcUser client, IrcMessage message) { if (message.Params.Length != 1) { SendMessage(IrcNumericResponceId.ERR_NONICKNAMEGIVEN, client, "No nickname given"); return; } if (!IRC.CheckString(message.Params[0], IRC.NICKNAME)) { SendMessage(IrcNumericResponceId.ERR_ERRONEUSNICKNAME, client, "Erroneous nickname"); return; } if (!client.IrcServer.CheckNick(message.Params[0])) { SendMessage(IrcNumericResponceId.ERR_NICKNAMEINUSE, client, "Nickname is already in use"); return; } string oldNick = client.Nick; client.Channels.ForEach(channel => channel.Nick(client, message.Params[0])); if (!string.IsNullOrEmpty(client.User)) { Say(client, "NICK", message.Params[0]); } client.Nick = message.Params[0]; }
// Syntax: INVITE <nick> <channel> public override void Run(IIrcUser client, IrcMessage message) { if (message.Params.Length != 2) { NeedMoreParamsError(client); return; } if (client.IrcServer.CheckNick(message.Params[0])) { NotFoundError(client, false); return; } if (!IRC.IsChannel(message.Params[1]) || !client.IrcServer.ChannelExists(message.Params[1])) { NotFoundError(client, true); return; } IrcChannel channel = client.IrcServer.GetChannel(message.Params[1]); IIrcUser user = client.IrcServer.Clients.Find(cli => cli.Nick == message.Params[0]); if (!user.ChannelModes.ContainsKey(channel)) { user.ChannelModes.Add(channel, new IrcChannelUserMode()); } IrcChannelUserMode mode = user.ChannelModes[channel]; mode.IsInvited = true; channel.Command(client, "INVITE", user.Nick); client.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.RPL_INVITING, To = channel.Name, Extra = client.Nick, Message = "invited." }); }
/// <summary> /// Causes a client to part a channel. /// </summary> /// <param name="client"></param> /// <param name="channel"></param> /// <param name="reason"></param> public void LeaveChannel(IIrcUser client, string channel, string reason) { IrcChannel chan = GetChannel(channel); if (chan == null) { if (!ChannelExists(channel)) { client.Write(new IrcNumericResponce() { NumericId = IrcNumericResponceId.ERR_NOTONCHANNEL, Message = "You're not on that channel", To = channel }); } else { client.Write(new IrcNumericResponce() { NumericId = IrcNumericResponceId.ERR_NOSUCHCHANNEL, Message = "No such channel", To = channel }); } return; } Logger.Log(LogLevel.Info, "{0} parted channel {1}", client.Nick, chan.Name); chan.Part(client, reason); client.Channels.Remove(chan); }
private void UpdateChannelMode(IIrcUser sender, string mode) { if (mode.Split(' ')[0].Length <= 1) { return; } Channel.Command(sender, "MODE", Channel.Name + " " + mode); }
public override void Run(IIrcUser client, IrcMessage message) { client.Write(new IrcMessage { Command = "PONG", Params = message.Params }); }
public IrcChannelUserMode GetUserMode(IIrcUser user) { if (!user.ChannelModes.ContainsKey(this)) { user.ChannelModes.Add(this, new IrcChannelUserMode()); } return(user.ChannelModes[this]); }
/// <summary> /// Causes the server to acknowlage a user leaving. /// </summary> /// <param name="ircClient"></param> /// <param name="reason"></param> public void UserLeft(IIrcUser ircClient, string reason) { foreach (IrcChannel channel in ircClient.Channels) { channel.Part(ircClient, reason); } Clients.Remove(ircClient); }
public void PermissionsError(IIrcUser client) { IrcMessage Response = new IrcMessage(); Response.Params = (client.Nick + ":Insufficiant permissions for " + Name.ToUpper()).Split(':'); Response.Prefix = client.IrcServer.Hostname; Response.Command = "NOTICE"; client.Write(Response); }
public void NotFoundError(IIrcUser client, bool isChannel) { IrcNumericResponce Response = new IrcNumericResponce(); Response.Message = (isChannel ? "channel" : "nick") + " not found."; Response.NumericId = isChannel ? IrcNumericResponceId.ERR_NOSUCHCHANNEL : IrcNumericResponceId.ERR_NOSUCHNICK; Response.To = Name.ToUpper(); client.Write(Response); }
public void NeedMoreParamsError(IIrcUser client) { client.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.ERR_NEEDMOREPARAMS, To = Name.ToUpper(), Message = "Need more params" }); }
public void Say(IIrcUser client, string command, string message) { IrcMessage Response = new IrcMessage(); Response.Prefix = client.Nick; Response.Command = command.ToUpper(); Response.Params = new string[] { message }; client.Write(Response); }
public override void Run(IIrcUser client, IrcMessage message) { string name = message.Params[0]; if (IRC.IsChannel(name)) { IrcChannel channel = client.IrcServer.GetChannel(message.Params[0]); if (channel == null) { NotFoundError(client, true); return; } if (message.Params.Length < 1) { NeedMoreParamsError(client); return; } channel.Mode.Parse(client, message); return; } if (message.Params.Length < 2) { NeedMoreParamsError(client); return; } IIrcUser other = client.IrcServer.Clients.Find(user => user.Nick.ToLower() == name.ToLower()); if (other == null) { NotFoundError(client, false); return; } string mode = message.Params[1]; if (!((client == other) || client.Mode.IsOperator)) { PermissionsError(client); return; } other.Mode.Parse(mode); client.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.RPL_UMODEIS, To = other.Nick, Extra = other.Mode.ToString() }); if (other != client) { other.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.RPL_UMODEIS, To = other.Nick, Extra = other.Mode.ToString() }); } }
public void SendMessage(IrcNumericResponceId responceId, IIrcUser client, string message) { IrcNumericResponce Response = new IrcNumericResponce(); Response.Host = client.IrcServer.Hostname; Response.To = client.Nick; Response.NumericId = responceId; Response.Message = message; client.Write(Response); }
private void ParseChannelMode(IIrcUser sender, string mode) { bool setTrue = mode[0] == '+'; if (!setTrue && mode[0] != '-') { return; } IrcChannelUserMode senderMode = sender.ChannelModes[Channel]; string newMode = setTrue ? "+" : "-"; foreach (char ch in mode) { if (ch == 'a' && senderMode.IsOperator) { IsAnnonymous = setTrue; newMode += "a"; } if (ch == 'i' && senderMode.IsOperator) { IsInviteOnly = setTrue; newMode += "i"; } if (ch == 'm' && senderMode.IsHalfOp) { IsVoiceOnly = setTrue; newMode += "m"; } if (ch == 'q' && senderMode.IsAdmin) { IsQuiet = setTrue; newMode += "q"; } // RFC 2811: The channel flags 'p' and 's' MUST NOT both be set at the same time. if (ch == 'p' && senderMode.IsAdmin && !IsSecret) { IsPrivate = setTrue; newMode += "p"; } if (ch == 's' && senderMode.IsAdmin && !IsPrivate) { IsSecret = setTrue; newMode += "s"; } // End RFC 2811. if (ch == 't' && senderMode.IsHalfOp) { OpSetTopic = setTrue; newMode += "t"; } } UpdateChannelMode(sender, newMode); }
/// <summary> /// Broadcasts an <see cref="IRCSharp.IrcMessage"/> to all users listening on this channel. /// </summary> /// <param name="sender">The IIrcUser that sent the message.</param> /// <param name="message">The IrcMessage</param> /// <param name="ignoreSender">Whether to ignore the sender when sending this message.</param> public void SendMessage(IIrcUser sender, IrcMessage message, bool ignoreSender = false) { Users.Where(user => { if (ignoreSender) { return(user != sender); } return(true); }).ForEach(user => user.Write(message)); IrcServer.Logger.Log(LogLevel.Debug, message.ToString()); }
public IrcConnection(ILoggerFactory loggerFactory, IConnectionFactory connectionFactory, string hostname, bool useSsl = true, int port = 6667, string password = null) { _botCount = Interlocked.Increment(ref botCount); _hostname = hostname; _port = port; _password = password; _useSsl = useSsl; _state = State.Offline; _logger = new IrcLogger(this, loggerFactory.GetLogger(this)); _connFactory = connectionFactory; _channelList = new ChannelList(this); _user = new IrcCurrentUser(this); }
public override void Run(IIrcUser client, IrcMessage message) { if (message.Params.Length == 0) { SendMessage(IrcNumericResponceId.ERR_NEEDMOREPARAMS, client, "Not enough parameters"); return; } string[] channels = message.Params[0].Split(','); string reason = message.Params.Length == 2 ? message.Params.Last() : "leaving"; foreach (string chan in channels) { client.IrcServer.LeaveChannel(client, chan, reason); } }
public void Parse(IIrcUser sender, IrcMessage message) { if (message.Params.Length >= 2) { if (message[1].Contains('b') || message[1].Contains('I') || message[1].Contains('e')) { ParseAccessMode(sender, message[1], message.Params.Length == 3 ? message[2] : ""); return; } } if (message.Params.Length >= 3) { if (IRC.CheckString(message.Params[2], IRC.NICKNAME)) { IIrcUser user = sender.IrcServer.Clients.Where(client => client.Nick == message.Params[2]).FirstOrDefault(); if (user == null) { sender.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.ERR_NOSUCHNICK, To = message.Params[2], Message = "No such nick" }); return; } ParseMember(sender, user, message.Params[1]); } else { ParseAccessMode(sender, message.Params[1], message.Params[2]); } } else if (message.Params.Length == 2 && !string.IsNullOrEmpty(message.Params[1])) { ParseChannelMode(sender, message.Params[1]); } else if (message.Params.Length == 1) { sender.Write(new IrcMessage { Prefix = Channel.Name, Command = "MODE", Params = ToString().Split(' ') }); } }
public override void Run(IIrcUser client, IrcMessage message) { string user = ""; if (message.Params.Length != 1) { user = client.Nick; } user = message.Params[0]; if (client.IrcServer.CheckNick(user)) { SendMessage(IrcNumericResponceId.ERR_NOSUCHNICK, client, "No such nick"); return; } IIrcUser other = client.IrcServer.Clients.Where(cli => cli.Nick == user).FirstOrDefault(); SendMessage(IrcNumericResponceId.RPL_USERHOST, client, string.Format("{0}=+{1}@{2}", other.Nick, other.User, other.Host)); }
/// <summary> /// Causes a client to join a channel. /// </summary> /// <param name="client"></param> /// <param name="channel"></param> public void JoinChannel(IIrcUser client, string channel) { IrcChannel chan = GetChannel(channel); if (chan == null) { chan = new IrcChannel(this) { Name = channel }; Channels.Add(chan); } Logger.Log(LogLevel.Info, "{0} joined channel {1}", client.Nick, chan.Name); client.Channels.Add(chan); chan.Join(client); }
public override void Run(IIrcUser client, IrcMessage message) { string command = message.Params[0].ToLower(); if (command == "ls") { client.Write(new IrcMessage { Prefix = client.IrcServer.Hostname, Command = "CAP", Params = new string[] { "*", "LS", "multi-prefix" } }); } else if (command == "list") { } else if (command == "req") { client.Write(new IrcMessage { Prefix = client.IrcServer.Hostname, Command = "CAP", Params = new string[] { "*", "ACK", "multi-prefix" } }); } else if (command == "ack") { } else if (command == "nak") { } else if (command == "clear") { } else if (command == "end") { client.Write(new IrcMessage { Prefix = client.IrcServer.Hostname, Command = "CAP", Params = new string[] { "*", "END" } }); } }
public override void Run(IIrcUser client, IrcMessage message) { if (client.Mode.IsRegistered) { client.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.ERR_ALREADYREGISTERED, Message = "You're already registered.", Extra = "USER" }); return; } client.User = message.Params[0]; if (string.IsNullOrEmpty(client.Nick)) { client.Nick = string.Format("${0}_{1}", client.User, string.Concat(Guid.NewGuid().ToString().Replace("-", "").First(5))); } byte mode = 0; byte.TryParse(message.Params[1], out mode); client.Mode.Parse(mode); client.Name = message.Params.Last(); SendMessage(IrcNumericResponceId.RPL_WELCOME, client, string.Format("Welcome to the Internet Relay Network! You're known as {0}!{1}@{2}", client.Nick, client.User, client.Host)); SendMessage(IrcNumericResponceId.RPL_YOURHOST, client, "Your host is running IRCSharp 0.0.1-DEV"); SendMessage(IrcNumericResponceId.RPL_CREATED, client, "This server was created on 2014-04-04."); SendMessage(IrcNumericResponceId.RPL_MYINFO, client, "127.0.0.1 IRCSharp aiwrOos anipqsvkl"); client.Write(new IrcNumericResponce() { NumericId = IrcNumericResponceId.RPL_ISUPPORT, Extra = "CASEMAPPING=ascii PREFIX=(qaohv)~!@%+ FNC", Message = "are supported by this server" }); client.Write(new IrcNumericResponce() { NumericId = IrcNumericResponceId.RPL_ISUPPORT, Extra = "CHANTYPES=!#&+ INVEX=I RFC2812", Message = "are supported by this server" }); SendMessage(IrcNumericResponceId.ERR_NOMOTD, client, ":)"); if (mode > 0) { Say(client, "MODE", client.Mode.ToString()); } client.Mode.IsRegistered = true; }
public override void Run(IIrcUser client, IrcMessage message) { if (message.Params.Length != 2) { SendMessage(IrcNumericResponceId.ERR_NEEDMOREPARAMS, client, "Need more params."); return; } if (IRC.IsChannel(message.Params[0])) { IrcChannel channel = client.IrcServer.Channels.Where(chan => chan.Name.ToLower() == message.Params[0].ToLower()).FirstOrDefault(); if (channel == null) { client.Write(new IrcNumericResponce() { NumericId = IrcNumericResponceId.ERR_NOSUCHNICK, To = message.Params[0], Message = "No such nick/channel" }); return; } channel.SendMessage(client, message.Params[1]); } else { IIrcUser other = client.IrcServer.Clients.Where(cli => cli.Nick == message.Params[0]).FirstOrDefault(); if (other == null) { client.Write(new IrcNumericResponce() { NumericId = IrcNumericResponceId.ERR_NOSUCHNICK, To = message.Params[0], Message = "No such nick/channel" }); return; } other.Write(new IrcMessage { Prefix = client.UserString, Command = "PRIVMSG", Params = new string[] { other.Nick, " :" + message.Params[1] } }); } }
public override void Run(IIrcUser client, IrcMessage message) { if (message.Params.Length > 2 || message.Params.Length == 0) { SendMessage(IrcNumericResponceId.ERR_NEEDMOREPARAMS, client, "Need more params"); return; } if (message.Params[0] == "0") { // TODO: part all channels. return; } string[] channels = message.Params[0].Split(','); foreach (string chan in channels) { client.IrcServer.JoinChannel(client, chan); } // TODO: channel keys. }
private void ParseMember(IIrcUser sender, IIrcUser user, string mode) { bool setTrue = mode[0] == '+'; if (!setTrue && mode[0] != '-') { return; } IrcChannelUserMode senderMode = Channel.GetUserMode(sender); IrcChannelUserMode userMode = Channel.GetUserMode(user); bool isSelf = (sender == user && !setTrue); string newMode = setTrue ? "+" : "-"; foreach (char ch in mode) { if (ch == 'a' && (senderMode.IsAdmin || isSelf)) { userMode.IsAdmin = setTrue; newMode += 'a'; } if (ch == 'o' && (senderMode.IsOperator || isSelf)) { userMode.IsOperator = setTrue; newMode += 'o'; } if (ch == 'h' && (senderMode.IsHalfOp || isSelf)) { userMode.IsHalfOp = setTrue; newMode += 'h'; } if (ch == 'v' && (senderMode.IsHalfOp || isSelf)) { userMode.IsVoiced = setTrue; newMode += 'v'; } } UpdateChannelMode(sender, newMode + " " + user.Nick); }
public override void Run(IIrcUser client, IrcMessage message) { IIrcUser other = client.IrcServer.Clients.Where(cli => cli.Nick.ToLower() == message.Params[0].ToLower()).FirstOrDefault(); if (other == null) { // TODO: no such nick. return; } client.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.RPL_WHOISUSER, To = other.Nick, Extra = string.Format("{0} {1}", other.User, other.Host), Message = other.Name }); client.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.RPL_WHOISIDLE, To = other.Nick, Extra = ((int)(DateTime.Now - other.Idle).TotalSeconds).ToString(), Message = "seconds idle" }); client.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.RPL_WHOISCHANNELS, To = other.Nick, Message = string.Join(" ", other.Channels.Select(channel => other.ChannelModes[channel].NickPrefix + channel.Name).ToArray()) }); client.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.RPL_ENDOFWHOIS, To = other.Nick, Message = "End of WHOIS list." }); }
/// <summary> /// Sends a PRIVMSG to this channel from a sender. /// </summary> /// <param name="sender">The IIrcUser that sent this message.</param> /// <param name="message">The string contents of the message.</param> public void SendMessage(IIrcUser sender, string message) { Command(sender, "PRIVMSG", Name + " :" + message, true); }
/// <summary> /// Broadcasts an <see cref="IRCSharp.IrcMessage"/> to all users listening on this channel. /// </summary> /// <param name="sender">The IIrcUser that sent the message.</param> /// <param name="message">The IrcMessage</param> /// <param name="ignoreSender">Whether to ignore the sender when sending this message.</param> public void SendMessage(IIrcUser sender, IrcMessage message, bool ignoreSender = false) { Users.Where(user => { if (ignoreSender) { return user != sender; } return true; }).ForEach(user => user.Write(message)); IrcServer.Logger.Log(LogLevel.Debug, message.ToString()); }
public IrcChannelUserMode GetUserMode(IIrcUser user) { if (!user.ChannelModes.ContainsKey(this)) { user.ChannelModes.Add(this, new IrcChannelUserMode()); } return user.ChannelModes[this]; }
/// <summary> /// Joins this IrcChannel, provided the key is correct. /// </summary> public void Join(IIrcUser client, string key = "") { if (Mode.Key != key) { return; } if (!client.ChannelModes.ContainsKey(this)) { client.ChannelModes.Add(this, new IrcChannelUserMode()); } IrcChannelUserMode mode = client.ChannelModes[this]; if (Mode.IsInviteOnly && !mode.IsInvited) { if (Mode.InviteMask.Where(mask => mask.PatternMatch(client.UserString)).Count() == 0) { client.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.ERR_INVITEONLYCHAN, To = Name, Message = "You are not invited." }); return; } } if (Mode.BanMask.Where(mask => mask.PatternMatch(client.UserString)).Count() >= 1) { if (Mode.ExceptionMask.Where(mask => mask.PatternMatch(client.UserString)).Count() == 0) { // TODO: deny access. return; } } if (Users.Count == 0 && (Created - DateTime.Now).TotalSeconds < 5) { // Flag the first member as the channel's creator. mode.IsCreator = true; } Users.Add(client); Command(client, "JOIN", Name); if (string.IsNullOrEmpty(Mode.Topic)) { client.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.RPL_NOTOPIC, To = Name, Message = "No topic" }); } else { client.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.RPL_TOPIC, To = Name, Message = Mode.Topic }); } IrcCommand.Find("names").Run(client, new IrcMessage { Params = new string[]{ Name } }); }
public void SendMessage(IrcNumericResponceId responceId, IIrcUser client, string message) { IrcNumericResponce responce = new IrcNumericResponce(); responce.Host = client.IrcServer.Hostname; responce.To = client.Nick; responce.NumericId = responceId; responce.Message = message; client.Write(responce); }
/// <summary> /// Sends a command to the users in this channel. /// </summary> /// <param name="sender">The IIrcUser who is sending the command.</param> /// <param name="command">The command being sent.</param> /// <param name="message">The contents of this command.</param> /// <param name="ignoreSender">Whether ignore the sender when sending this command.</param> public void Command(IIrcUser sender, string command, string message, bool ignoreSender = false) { IrcMessage ircMessage = new IrcMessage(); ircMessage.Prefix = sender.Nick; ircMessage.Command = command; string paramaters = message.Split(':')[0].Trim(); string trailing = ""; if (message.Split(':').Length == 2) { trailing = message.Split(':')[1].Trim(); } List<string> paramList = new List<string>(); paramList.AddRange(paramaters.Split(' ')); if (!string.IsNullOrEmpty(trailing)) { paramList.Add(trailing); } ircMessage.Params = paramList.ToArray(); SendMessage(sender, ircMessage, ignoreSender); }
public void PermissionsError(IIrcUser client) { IrcMessage responce = new IrcMessage(); responce.Params = (client.Nick + ":Insufficiant permissions for " + Name.ToUpper()).Split(':'); responce.Prefix = client.IrcServer.Hostname; responce.Command = "NOTICE"; client.Write(responce); }
public void NotFoundError(IIrcUser client, bool isChannel) { IrcNumericResponce responce = new IrcNumericResponce(); responce.Message = (isChannel ? "channel" : "nick") + " not found."; responce.NumericId = isChannel ? IrcNumericResponceId.ERR_NOSUCHCHANNEL : IrcNumericResponceId.ERR_NOSUCHNICK; responce.To = Name.ToUpper(); client.Write(responce); }
public int CompareTo(IIrcUser other) { return Name.CompareTo(other.Name); }
public void Parse(IIrcUser sender, IrcMessage message) { if (message.Params.Length >=2) { if (message[1].Contains('b') || message[1].Contains('I') || message[1].Contains('e')) { ParseAccessMode(sender, message[1], message.Params.Length == 3 ? message[2] : ""); return; } } if (message.Params.Length >= 3) { if (IRC.CheckString(message.Params[2], IRC.NICKNAME)) { IIrcUser user = sender.IrcServer.Clients.Where(client => client.Nick == message.Params[2]).FirstOrDefault(); if (user == null) { sender.Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.ERR_NOSUCHNICK, To = message.Params[2], Message = "No such nick" }); return; } ParseMember(sender, user, message.Params[1]); } else { ParseAccessMode(sender, message.Params[1], message.Params[2]); } } else if(message.Params.Length == 2 && !string.IsNullOrEmpty(message.Params[1])) { ParseChannelMode(sender, message.Params[1]); } else if (message.Params.Length == 1) { sender.Write(new IrcMessage { Prefix = Channel.Name, Command = "MODE", Params = ToString().Split(' ') }); } }
public int CompareTo(IIrcUser other) { return(Name.CompareTo(other.Name)); }
private void ParseMember(IIrcUser sender, IIrcUser user, string mode) { bool setTrue = mode[0] == '+'; if (!setTrue && mode[0] != '-') { return; } IrcChannelUserMode senderMode = Channel.GetUserMode(sender); IrcChannelUserMode userMode = Channel.GetUserMode(user); bool isSelf = (sender == user && !setTrue); string newMode = setTrue ? "+" : "-"; foreach (char ch in mode) { if (ch == 'a' && (senderMode.IsAdmin || isSelf)) { userMode.IsAdmin = setTrue; newMode += 'a'; } if (ch == 'o' && (senderMode.IsOperator|| isSelf)) { userMode.IsOperator = setTrue; newMode += 'o'; } if (ch == 'h' && (senderMode.IsHalfOp || isSelf)) { userMode.IsHalfOp = setTrue; newMode += 'h'; } if (ch == 'v' && (senderMode.IsHalfOp || isSelf)) { userMode.IsVoiced = setTrue; newMode += 'v'; } } UpdateChannelMode(sender, newMode + " " + user.Nick); }
private void ParseAccessMode(IIrcUser sender, string mode, string mask) { bool setTrue = mode[0] == '+'; if (!setTrue && mode[0] != '-') { return; } if (string.IsNullOrEmpty(mask)) { if (!setTrue) { return; } List<string> list = null; IrcNumericResponceId numeric; IrcNumericResponceId endNumeric; switch (mode[1]) { case 'b': list = BanMask; numeric = IrcNumericResponceId.RPL_BANLIST; endNumeric = IrcNumericResponceId.RPL_ENDOFBANLIST; break; case 'I': list = InviteMask; numeric = IrcNumericResponceId.RPL_INVITELIST; endNumeric = IrcNumericResponceId.RPL_ENDOFINVITELIST; break; case 'e': list = ExceptionMask; numeric = IrcNumericResponceId.RPL_EXCEPTLIST; endNumeric = IrcNumericResponceId.RPL_ENDOFEXCEPTLIST; break; default: return; } string items = string.Join(" ", list); sender.Write(new IrcNumericResponce { NumericId = numeric, To = Channel.Name, Extra = items }); sender.Write(new IrcNumericResponce { NumericId = endNumeric, To = Channel.Name, Message = "End of list" }); return; } IrcChannelUserMode senderMode = Channel.GetUserMode(sender); if (!senderMode.IsOperator) { return; } List<string> masks = mask.Split(' ').ToList(); Action<IEnumerable<string>> action = null; if (mode[1] == 'b') { if (setTrue) { masks.RemoveGroup(BanMask); } action = setTrue ? BanMask.AddRange : (Action<IEnumerable<string>>)BanMask.RemoveGroup; } if (mode[1] == 'I') { if (setTrue) { masks.RemoveGroup(InviteMask); } action = setTrue ? InviteMask.AddRange : (Action<IEnumerable<string>>)InviteMask.RemoveGroup; } if (mode[1] == 'e') { if (setTrue) { masks.RemoveGroup(ExceptionMask); } action = setTrue ? ExceptionMask.AddRange : (Action<IEnumerable<string>>)ExceptionMask.RemoveGroup; } if (action == null) { return; } if (masks.Count == 0) { return; } action(masks); UpdateChannelMode(sender, mode + " " + string.Join(" ", masks)); }
/// <summary> /// Leaves this IrcChannel with a part message. /// </summary> public void Part(IIrcUser client, string message) { Users.Remove(client); Command(client, "PART", Name + " :" + message); }
/// <summary> /// Updates a client's nickname. /// </summary> /// <param name="client"></param> /// <param name="newNick"></param> public void Nick(IIrcUser client, string newNick) { Command(client, "NICK", newNick, true); }