internal static Task HandleModeMessage(IrcClient client, IrcMessage message) { if (message.Parameters.Length < 2) { throw new IrcProtocolException("Received MODE message with an invalid amount of parameters."); } string target = message.Parameters[0]; string flags = message.Parameters[1]; if (target.StartsWith("#")) { string channelName = target.Substring(1); // Handle all mode messages related to channels. if (client.Channels.ContainsKey(channelName)) { IrcChannel channel = client.Channels[channelName]; bool grant = flags[0] == '+'; char[] modes = flags.Substring(1).ToCharArray(); foreach (char mode in modes) { // Operator status if (mode == 'o') { if (message.Parameters.Length == 3) { string nickName = message.Parameters[2]; IrcUser user = new IrcUser(client, nickName); // Check if the local user has been granted operator status and update the channel's IsOperator property if necessary. if (user.IsClientUser()) { channel.IsOperator = true; } client.OnUserOperatorStatusUpdated(new IrcOperatorEventArgs(channel, user, grant)); } else { throw new IrcProtocolException("Received granting operator MODE message with an invalid amount of parameters."); } } } } else { throw new IrcProtocolException(string.Format("Received mode message from a channel the client has not joined. (Channel: {0}", channelName)); } } return(Task.CompletedTask); }
internal static Task HandleJoinMessage(IrcClient client, IrcMessage message) { if (message.Parameters.Length > 0) { string channelName = message.Parameters[0].Substring(1); var hostMask = IrcHostMask.Parse(message.Prefix); if (hostMask != null) { IrcChannel channel; var user = new IrcUser(client, hostMask); if (!client.Channels.ContainsKey(channelName)) { // The client joined the channel. if (client is TwitchIrcClient) { channel = new TwitchChannel(client, channelName); client.Channels.Add(channelName, channel); // Return to not fire the ChannelJoined event and let the ROOMSTATE message handler handle it. return(Task.CompletedTask); } channel = new IrcChannel(client, channelName); client.Channels.Add(channelName, channel); client.User.Update(hostMask); } else { channel = client.Channels[channelName]; } var e = new IrcUserEventArgs(channel, user); client.OnChannelJoined(e); } else { throw new IrcProtocolException("Invalid source."); } } else { throw new IrcProtocolException("1 parameter is required to determine the channel."); } return(Task.CompletedTask); }
public IrcOperatorEventArgs(IrcChannel channel, IrcUser user, bool statusGranted) : base(channel, user) { StatusGranted = statusGranted; }