상속: InfoBase
예제 #1
0
 public UserPerChannelInfo(UserInfo userInfo, ChannelInfo channelInfo)
     : base(userInfo.IrcDaemon)
 {
     this.userInfo = userInfo;
     this.channelInfo = channelInfo;
     modes = new RankList(userInfo.IrcDaemon);
 }
예제 #2
0
 public KickArgument(UserInfo sender, InfoBase receiver, ChannelInfo channel, UserInfo user, string message)
     : base(sender, receiver, "KICK")
 {
     this.channel = channel;
     this.user = user;
     this.message = message;
 }
예제 #3
0
        public override bool HandleEvent(CommandBase command, ChannelInfo channel, UserInfo user, List<string> args)
        {
            if (onlyOnce) { return true; }
            onlyOnce = true;

            if (command is Join)
            {
                user.IrcDaemon.Commands.Send(new NoticeArgument(user, user, channel.Name, "This channel automatically translates your messages, use the LANGUAGE command to set your preferred language"));
            }
            if (!channel.Modes.HandleEvent(command, channel, user, args))
            {
                onlyOnce = false;
                return false;
            }
            if (command is PrivateMessage || command is Notice)
            {

                var translateDelegate = new GoogleTranslate.TranslateMultipleDelegate(translator.TranslateText);
                translateDelegate.BeginInvoke(args[1], channel.Users.Select(u => u.Languages.First()).Distinct(), TranslateCallBack, Tuple.Create(channel, user, command));

                onlyOnce = false;
                return false;
            }

            onlyOnce = false;
            return true;
        }
예제 #4
0
 public UserPerChannelInfo(UserInfo userInfo, ChannelInfo channelInfo)
     : base(userInfo.IrcDaemon)
 {
     UserInfo = userInfo;
     ChannelInfo = channelInfo;
     Modes = new RankList(userInfo.IrcDaemon);
 }
예제 #5
0
 public override bool HandleEvent(CommandBase command, ChannelInfo channel, UserInfo user, List<string> args)
 {
     if (command is Join)
     {
         if (!user.Invited.Contains(channel))
         {
             user.IrcDaemon.Replies.SendInviteOnlyChannel(user, channel);
             return false;
         }
         user.Invited.Remove(channel);
     }
     if (command is Invite)
     {
         UserPerChannelInfo upci;
         if (channel.UserPerChannelInfos.TryGetValue(user.Nick, out upci))
         {
             if (upci.Modes.Level < 30)
             {
                 channel.IrcDaemon.Replies.SendChannelOpPrivilegesNeeded(user, channel);
                 return false;
             }
         }
         else
         {
             channel.IrcDaemon.Replies.SendNotOnChannel(user, channel.Name);
             return false;
         }
     }
     return true;
 }
예제 #6
0
 public void SendList(UserInfo info, ChannelInfo chan)
 {
     foreach (var invite in _inviteExceptionList)
     {
         info.IrcDaemon.Replies.SendInviteList(info, chan, invite);
     }
     info.IrcDaemon.Replies.SendEndOfInviteList(info, chan);
 }
예제 #7
0
 public void SendList(UserInfo info, ChannelInfo chan)
 {
     foreach (var banExcpetion in _banExceptionList)
     {
         info.IrcDaemon.Replies.SendExceptionList(info, chan, banExcpetion);
     }
     info.IrcDaemon.Replies.SendEndOfExceptionList(info, chan);
 }
예제 #8
0
 public override bool HandleEvent(CommandBase command, ChannelInfo channel, UserInfo user, List<string> args)
 {
     if (command is List)
     {
         // TODO
     }
     return true;
 }
예제 #9
0
 public override bool HandleEvent(CommandBase command, ChannelInfo channel, UserInfo user, List<string> args)
 {
     if (command is PrivateMessage || command is Notice)
     {
         if (!channel.UserPerChannelInfos.ContainsKey(user.Nick))
         {
             user.IrcDaemon.Replies.SendCannotSendToChannel(user, channel.Name);
             return false;
         }
     }
     return true;
 }
예제 #10
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            if (args[0] == "0")
            {
                PartAll(info);
                return;
            }

            foreach (var channel in from temp in GetSubArgument(args[0])
                                    where info.UserPerChannelInfos.All(upci => upci.ChannelInfo.Name != temp)
                                    select temp)
            {
                ChannelInfo chan;

                if (IrcDaemon.Channels.ContainsKey(channel))
                {
                    chan = IrcDaemon.Channels[channel];

                    if (!chan.Modes.HandleEvent(this, chan, info, args))
                    {
                        continue;
                    }
                }
                else
                {
                    if (IrcDaemon.ValidChannel(channel))
                    {
                        chan = new ChannelInfo(channel, IrcDaemon);
                        IrcDaemon.Channels.Add(chan.Name, chan);
                    }
                    else
                    {
                        IrcDaemon.Replies.SendBadChannelMask(info, channel);
                        return;
                    }
                }

                var chanuser = new UserPerChannelInfo(info, chan);

                // ToDo: this probably should get delegated to the Channel Type specific "NormalChannel" class, because it depends on the channel type.
                if (!chan.Users.Any())
                {
                    chanuser.Modes.Add(IrcDaemon.ModeFactory.GetChannelRank('o'));
                }

                chan.UserPerChannelInfos.Add(info.Nick, chanuser);
                info.UserPerChannelInfos.Add(chanuser);
                Send(new JoinArgument(info, chan, chan));
                SendTopic(info, chan);
                IrcDaemon.Replies.SendNamesReply(chanuser.UserInfo, chan);
                IrcDaemon.Replies.SendEndOfNamesReply(info, chan);
            }
        }
예제 #11
0
 public override bool HandleEvent(CommandBase command, ChannelInfo channel, UserInfo user, List<string> args)
 {
     if (command is PrivateMessage || command is Notice)
     {
         UserPerChannelInfo upci;
         if (!channel.UserPerChannelInfos.TryGetValue(user.Nick, out upci) || upci.Modes.Level < 10)
         {
             user.IrcDaemon.Replies.SendCannotSendToChannel(user, channel.Name);
             return false;
         }
     }
     return true;
 }
예제 #12
0
        public override bool HandleEvent(CommandBase command, ChannelInfo channel, UserInfo user, List<string> args)
        {
            if (command is Join)
            {

                if (_limit <= channel.UserPerChannelInfos.Count)
                {
                    user.IrcDaemon.Replies.SendChannelIsFull(user, channel);
                    return false;
                }
            }
            return true;
        }
예제 #13
0
        public override bool HandleEvent(CommandBase command, ChannelInfo channel, UserInfo user, List<string> args)
        {
            if (command is Join)
            {
                var keys = args.Count > 1 ? (IEnumerable<string>)CommandBase.GetSubArgument(args[1]) : new List<string>();

                if (keys.All(k => k != _key))
                {
                    user.IrcDaemon.Replies.SendBadChannelKey(user, channel);
                    return false;
                }
            }

            return true;
        }
예제 #14
0
 public override bool HandleEvent(CommandBase command, ChannelInfo channel, UserInfo user, List<string> args)
 {
     if (command is PrivateMessage || command is Notice)
     {
         if (args[1].Any(c => c == IrcConstants.IrcColor))
         {
             channel.IrcDaemon.Replies.SendCannotSendToChannel(user, channel.Name, "Color is not permitted in this channel");
             return false;
         }
         if (args[1].Any(c => c == IrcConstants.IrcBold || c == IrcConstants.IrcNormal || c == IrcConstants.IrcUnderline || c == IrcConstants.IrcReverse))
         {
             channel.IrcDaemon.Replies.SendCannotSendToChannel(user, channel.Name, "Control codes (bold/underline/reverse) are not permitted in this channel");
             return false;
         }
     }
     return true;
 }
예제 #15
0
 public override bool HandleEvent(CommandBase command, ChannelInfo channel, UserInfo user, List<string> args)
 {
     if (command is Topic)
     {
         UserPerChannelInfo upci;
         if (!channel.UserPerChannelInfos.TryGetValue(user.Nick, out upci))
         {
             user.IrcDaemon.Replies.SendNotOnChannel(user, channel.Name);
             return false;
         }
         if (upci.Modes.Level < 30)
         {
             user.IrcDaemon.Replies.SendChannelOpPrivilegesNeeded(user, channel);
             return false;
         }
     }
     return true;
 }
예제 #16
0
        public override bool HandleEvent(CommandBase command, ChannelInfo channel, UserInfo user, List<string> args)
        {
            if (command is Join)
            {
                if (_banList.Select(ban => new WildCard(ban, WildcardMatch.Exact)).Any(usermask => usermask.IsMatch(user.Usermask)))
                {
                    user.IrcDaemon.Replies.SendBannedFromChannel(user, channel);
                    return false;
                }
            }

            if (command is PrivateMessage || command is Notice)
            {
                if (_banList.Select(ban => new WildCard(ban, WildcardMatch.Exact)).Any(usermask => usermask.IsMatch(user.Usermask)))
                {
                    user.IrcDaemon.Replies.SendCannotSendToChannel(user, channel.Name, "You are banned from the Channel");
                    return false;
                }
            }

            return true;
        }
예제 #17
0
 public TopicArgument(UserInfo sender, InfoBase receiver, ChannelInfo channel, string newTopic)
     : base(sender, receiver, "TOPIC")
 {
     Channel = channel;
     NewTopic = newTopic;
 }
예제 #18
0
        /// <summary>
        /// Reply Code 366
        /// </summary>
        /// <param name="info"></param>
        /// <param name="chan"></param>
        public void SendEndOfNamesReply(UserInfo info, ChannelInfo chan)
        {
            BuildMessageHeader(info, ReplyCode.EndOfNames);

            response.Append(" ");
            response.Append(chan.Name);
            response.Append(" :End of NAMES list");

            info.WriteLine(response);
        }
예제 #19
0
        /// <summary>
        /// Reply Code 346
        /// </summary>
        /// <param name="info"></param>
        /// <param name="chan"></param>
        /// <param name="mask"></param>
        public void SendInviteList(UserInfo info, ChannelInfo chan, string mask)
        {
            BuildMessageHeader(info, ReplyCode.InviteList);

            response.Append(" ");
            response.Append(chan.Name);
            response.Append(" ");
            response.Append(mask);

            info.WriteLine(response);
        }
예제 #20
0
        /// <summary>
        /// Reply Code 473
        /// </summary>
        /// <param name="info"></param>
        /// <param name="chan"></param>
        public void SendInviteOnlyChannel(UserInfo info, ChannelInfo chan)
        {
            BuildMessageHeader(info, ReplyCode.ErrorInviteOnlyChannel);

            response.Append(" ");
            response.Append(chan.Name);
            response.Append(" :Cannot join channel (+i)");

            info.WriteLine(response);
        }
예제 #21
0
 public override bool HandleEvent(CommandBase command, ChannelInfo channel, UserInfo user, List<string> args)
 {
     // Handling JOIN is done in the ModeBan class
     return true;
 }
예제 #22
0
        /// <summary>
        /// Reply Code 322
        /// </summary>
        /// <param name="info"></param>
        /// <param name="chan"></param>
        public void SendListItem(UserInfo info, ChannelInfo chan)
        {
            BuildMessageHeader(info, ReplyCode.List);

            response.Append(" ");
            response.Append(chan.Name);
            response.Append(" ");
            response.Append(chan.UserPerChannelInfos.Count);
            response.Append(" :");
            response.Append(chan.Topic);

            info.WriteLine(response);
        }
예제 #23
0
        /// <summary>
        /// Reply Code 353
        /// </summary>
        /// <param name="info"></param>
        /// <param name="chan"></param>
        public void SendNamesReply(UserInfo info, ChannelInfo chan)
        {
            BuildMessageHeader(info, ReplyCode.NamesReply);
            response.Append(" ");
            response.Append(chan.NamesPrefix);
            response.Append(" ");
            response.Append(chan.Name);
            response.Append(" :");

            SendSplitted(response.ToString(), info, chan.UserPerChannelInfos.Values.Select(upci => upci.Modes.NickPrefix + upci.UserInfo.Nick), null);
        }
예제 #24
0
        /// <summary>
        /// Reply Code 477
        /// </summary>
        /// <param name="info"></param>
        /// <param name="chan"></param>
        public void SendNoChannelModes(UserInfo info, ChannelInfo chan)
        {
            BuildMessageHeader(info, ReplyCode.ErrorNoChannelModes);

            response.Append(" ");
            response.Append(chan.Name);
            response.Append(" :Channel doesn't support modes");

            info.WriteLine(response);
        }
예제 #25
0
 private void SendTopic(UserInfo info, ChannelInfo chan)
 {
     if (string.IsNullOrEmpty(chan.Topic))
     {
         IrcDaemon.Replies.SendNoTopicReply(info, chan);
     }
     else
     {
         IrcDaemon.Replies.SendTopicReply(info, chan);
     }
 }
예제 #26
0
 public JoinArgument(UserInfo sender, InfoBase receiver, ChannelInfo channel)
     : base(sender, receiver, "JOIN")
 {
     Channel = channel;
 }
예제 #27
0
 public InviteArgument(UserInfo sender, InfoBase receiver, UserInfo invited, ChannelInfo channel)
     : base(sender, receiver, "INVITE")
 {
     this.invited = invited;
     this.channel = channel;
 }
예제 #28
0
 public void SendList(UserInfo info, ChannelInfo chan)
 {
     foreach (var ban in _banList)
     {
         info.IrcDaemon.Replies.SendBanList(info, chan, ban);
     }
     info.IrcDaemon.Replies.SendEndOfBanList(info, chan);
 }
예제 #29
0
 public KnockArgument(UserInfo sender, InfoBase receiver, ChannelInfo channel, string message)
     : base(sender, receiver, "KNOCK")
 {
     this.channel = channel;
     this.message = message;
 }
예제 #30
0
 public PartArgument(UserInfo sender, InfoBase receiver, ChannelInfo channel, string message)
     : base(sender, receiver, "PART")
 {
     Channel = channel;
     Message = message;
 }