Example #1
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            if (!IrcDaemon.Channels.ContainsKey(args[0]))
            {
                IrcDaemon.Replies.SendNoSuchChannel(info, args[0]);
                return;
            }
            var chan = IrcDaemon.Channels[args[0]];

            if (args.Count == 1)
            {
                if (string.IsNullOrEmpty(chan.Topic))
                {
                    IrcDaemon.Replies.SendNoTopicReply(info, chan);
                }
                else
                {
                    IrcDaemon.Replies.SendTopicReply(info, chan);
                }
                return;
            }

            chan.Topic = args[1];

            // Some Mode might want to handle the command
            if (!chan.Modes.HandleEvent(this, chan, info, args))
            {
                return;
            }

            foreach (var user in chan.Users)
            {
                Send(new TopicArgument(info, user, chan, chan.Topic));
            }
        }
Example #2
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;
        }
Example #3
0
 protected override void PrivateHandle(UserInfo info, List<string> args)
 {
     if (info.Modes.Exist<ModeOperator>() || info.Modes.Exist<ModeLocalOperator>())
     {
         IrcDaemon.OnRehashEvent(this, new RehashEventArgs(IrcDaemon, info));
     }
 }
Example #4
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            UserInfo invited;
            if (!IrcDaemon.Nicks.TryGetValue(args[0], out invited))
            {
                IrcDaemon.Replies.SendNoSuchNick(info, args[0]);
            }

            var channel = args[1];
            ChannelInfo chan;
            if (IrcDaemon.Channels.TryGetValue(channel, out chan))
            {
                if (chan.UserPerChannelInfos.ContainsKey(invited.Nick))
                {
                    IrcDaemon.Replies.SendUserOnChannel(info, invited, chan);
                    return;
                }

                if (!chan.Modes.HandleEvent(this, chan, info, args))
                {
                    return;
                }

                if (!invited.Invited.Contains(chan))
                {
                    invited.Invited.Add(chan);
                }
            }

            //TODO channel does not exist? ... clean up below

            IrcDaemon.Replies.SendInviting(info, invited, channel);
            Send(new InviteArgument(info, invited, invited, chan));
        }
Example #5
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            var message = (args.Count > 1) ? args[1] : IrcDaemon.Options.StandardPartMessage;

            foreach (string channelName in GetSubArgument(args[0]))
            {
                if (IrcDaemon.Channels.ContainsKey(channelName))
                {
                    var chan = IrcDaemon.Channels[channelName];

                    if (info.Channels.Contains(chan))
                    {
                        Send(new PartArgument(info, chan, chan, message));
                        chan.RemoveUser(info);
                    }
                    else
                    {
                        IrcDaemon.Replies.SendNotOnChannel(info, channelName);
                    }
                }
                else
                {
                    IrcDaemon.Replies.SendNoSuchChannel(info, channelName);
                }
            }
        }
Example #6
0
        public IrcDaemon(IrcMode ircMode = IrcMode.Modern)
        {
            Capabilities = new List<string>();

            // Create Optionobject & Set the proper IRC Protocol Version
            // The protocol version cannot be changed after construction,
            // because the construction methods below use this Option
            Options = new ServerOptions(ircMode);

            //Clean Interface to statistics, it needs the IrcDaemon Object to gather this information.
            Stats = new ServerStats(this);

            // Setup Modes Infrastructure
            ModeFactory = new ModeFactory();
            SupportedChannelModes = new ChannelModeList(this);
            SupportedRanks = new RankList(this);
            SupportedUserModes = new UserModeList(this);

            // The Protocol Objects
            Commands = new CommandList(this);
            Replies = new ServerReplies.ServerReplies(this);
            ServerCreated = DateTime.Now;

            // Add Commands
            SetupCommands();
            // Add Modes
            SetupModes();
            //Add ChannelTypes
            SetupChannelTypes();
        }
Example #7
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            if (args.Count == 0)
            {
                info.AwayMessage = null;
                info.Modes.RemoveMode<ModeAway>();
                IrcDaemon.Replies.SendUnAway(info);
            }
            else
            {
                info.AwayMessage = args [0];
                info.Modes.Add (new ModeAway());
                IrcDaemon.Replies.SendNowAway(info);
            }

            foreach (var channel in info.Channels)
            {
                foreach (var user in  channel.Users)
                {
                    if (user.Capabilities.Contains("away-notify"))
                    {

                        Send (new AwayArgument (info, user, (args.Count == 0) ? null : args[0]));
                    }
                }
            }
        }
Example #8
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;
 }
Example #9
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            if (!IrcDaemon.Nicks.ContainsKey(args[0]))
            {
                IrcDaemon.Replies.SendNoSuchNick(info, args[0]);
                return;
            }

            var user = IrcDaemon.Nicks[args[0]];
            IrcDaemon.Replies.SendWhoIsUser(info, user);
            if (info.UserPerChannelInfos.Count > 0)
            {
                IrcDaemon.Replies.SendWhoIsChannels(info, user);
            }
            IrcDaemon.Replies.SendWhoIsServer(info, user);
            if (user.AwayMessage != null)
            {
                IrcDaemon.Replies.SendAwayMessage(info, user);
            }

            if (IrcDaemon.Options.IrcMode == IrcMode.Modern)
            {
                IrcDaemon.Replies.SendWhoIsLanguage(info, user);
            }

            if (user.Modes.Exist<ModeOperator>() || user.Modes.Exist<ModeLocalOperator>())
            {
                IrcDaemon.Replies.SendWhoIsOperator(info, user);
            }

            IrcDaemon.Replies.SendWhoIsIdle(info, user);
            IrcDaemon.Replies.SendEndOfWhoIs(info, user);
        }
Example #10
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            if (!info.PassAccepted)
            {
                IrcDaemon.Replies.SendPasswordMismatch(info);
                return;
            }
            if (info.UserExists)
            {
                IrcDaemon.Replies.SendAlreadyRegistered(info);
                return;
            }

            int flags;
            int.TryParse(args[1], out flags);

            if ((flags & 8) > 0)
            {
                info.Modes.Add(new ModeInvisible());
            }
            if ((flags & 4) > 0)
            {
                info.Modes.Add(new ModeWallops());
            }

            info.InitUser(args[0], args[3]);
        }
Example #11
0
 protected override void PrivateHandle(UserInfo info, List<string> args)
 {
     IrcDaemon.Replies.SendListUserClient(info);
     IrcDaemon.Replies.SendListUserOp(info);
     IrcDaemon.Replies.SendListUserUnknown(info);
     IrcDaemon.Replies.SendListUserChannels(info);
     IrcDaemon.Replies.SendListUserMe(info);
 }
Example #12
0
 public override bool HandleEvent(CommandBase command, ChannelInfo channel, UserInfo user, List<string> args)
 {
     if (command is List)
     {
         // TODO
     }
     return true;
 }
Example #13
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            if (args.Count < 1)
            {
                IrcDaemon.Replies.SendNoRecipient(info, Name);
                return;
            }
            if (args.Count < 2)
            {
                IrcDaemon.Replies.SendNoTextToSend(info);
                return;
            }

            // Only Private Messages set this
            info.LastAction = DateTime.Now;

            if (IrcDaemon.ValidChannel(args[0]))
            {
                if (IrcDaemon.Channels.ContainsKey(args[0]))
                {
                    var chan = IrcDaemon.Channels[args[0]];

                    if (!chan.Modes.HandleEvent(this, chan, info, args))
                    {
                        return;
                    }

                    // Send Channel Message
                    Send(new PrivateMessageArgument(info, chan, chan.Name, args[1]));
                }
                else
                {
                    IrcDaemon.Replies.SendCannotSendToChannel(info, args[0]);
                }
            }
            else if (IrcDaemon.ValidNick(args[0]))
            {
                UserInfo user;
                if (IrcDaemon.Nicks.TryGetValue(args[0], out user))
                {
                    if (user.Modes.Exist<ModeAway>())
                    {
                        IrcDaemon.Replies.SendAwayMessage(info, user);
                    }

                    // Send Private Message
                    Send(new PrivateMessageArgument(info, user, user.Nick, args[1]));
                }
                else
                {
                    IrcDaemon.Replies.SendNoSuchNick(info, args[0]);
                }
            }
            else
            {
                IrcDaemon.Replies.SendNoSuchNick(info, args[0]);
            }
        }
Example #14
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            //ToDo: parse target parameter

            IrcDaemon.Replies.SendAdminMe(info);
            IrcDaemon.Replies.SendAdminLocation1(info);
            IrcDaemon.Replies.SendAdminLocation2(info);
            IrcDaemon.Replies.SendAdminEmail(info);
        }
Example #15
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            if (args.Count < 1)
            {
                IrcDaemon.Replies.SendNoRecipient(info, Name);
                return;
            }
            if (args.Count < 2)
            {
                IrcDaemon.Replies.SendNoTextToSend(info);
                return;
            }

            if (IrcDaemon.ValidChannel(args[0]))
            {
                if (IrcDaemon.Channels.ContainsKey(args[0]))
                {
                    var chan = IrcDaemon.Channels[args[0]];

                    if (!chan.Modes.HandleEvent(this, chan, info, args))
                    {
                        return;
                    }

                    // Send Channel Message
                    Send(new NoticeArgument(info, chan, chan.Name, args[1]));
                }
                else
                {
                    IrcDaemon.Replies.SendCannotSendToChannel(info, args[0]);
                }
            }
            else if (IrcDaemon.ValidNick(args[0]))
            {
                if (IrcDaemon.Nicks.ContainsKey(args[0]))
                {
                    var user = IrcDaemon.Nicks[args[0]];

                    if (user.AwayMessage != null)
                    {
                        IrcDaemon.Replies.SendAwayMessage(info, user);
                    }

                    // Send PM
                    Send(new NoticeArgument(info, user, user.Nick, args[1]));
                }
                else
                {
                    IrcDaemon.Replies.SendNoSuchNick(info, args[0]);
                }
            }
            else
            {
                IrcDaemon.Replies.SendNoSuchNick(info, args[0]);
            }
        }
Example #16
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            if (!info.Modes.Exist<ModeOperator>() && !info.Modes.Exist<ModeLocalOperator>())
            {
                IrcDaemon.Replies.SendNoPrivileges(info);
                return;
            }

            IrcDaemon.Stop(false);
        }
Example #17
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);
            }
        }
Example #18
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            if (info.IrcDaemon.Options.IrcMode == IrcMode.Rfc1459)
                IrcDaemon.Replies.SendListStart(info);

            // TODO: special List commands (if RfcModern)
            foreach (var ci in IrcDaemon.Channels.Values.Where(ci => !ci.Modes.IsPrivate() && !ci.Modes.IsSecret()))
            {
                IrcDaemon.Replies.SendListItem(info, ci);
            }
            IrcDaemon.Replies.SendListEnd(info);
        }
Example #19
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;
 }
Example #20
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;
 }
Example #21
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;
        }
Example #22
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            var users = new List<UserInfo>();
            foreach (var arg in args)
            {
                UserInfo user;
                if (IrcDaemon.Nicks.TryGetValue(arg, out user))
                {
                    users.Add(user);
                }
            }

            IrcDaemon.Replies.SendUserHost(info, users);
        }
Example #23
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            IEnumerable<UserPerChannelInfo> whoList;
            var filterInvisible = true;

            if (!info.PassAccepted)
            {
                IrcDaemon.Replies.SendPasswordMismatch(info);
                return;
            }

            ChannelInfo channel;
            var mask = string.Empty;

            if (args.Count < 1 || args[0] == "0")
            {
                whoList = IrcDaemon.Nicks.SelectMany(n => n.Value.UserPerChannelInfos);
            }
            else if (args.Count > 0 && IrcDaemon.Channels.TryGetValue(args[0], out channel))
            {
                whoList = channel.UserPerChannelInfos.Values;
                if (!channel.UserPerChannelInfos.ContainsKey(info.Nick))
                {
                    filterInvisible = false;
                }
            }
            else
            {
                mask = args[0];
                var wildCard = new WildCard(mask, WildcardMatch.Anywhere);
                whoList = IrcDaemon.Nicks.Values.Where(u => wildCard.IsMatch(u.Usermask)).SelectMany(n => n.UserPerChannelInfos);
            }

            if (filterInvisible)
            {
                whoList = whoList.Where(w => !w.UserInfo.Modes.Exist<ModeInvisible>());
            }

            if (args.Count > 1 && args[1] == "o")
            {
                whoList = whoList.Where(w => w.UserInfo.Modes.Exist<ModeOperator>() || w.UserInfo.Modes.Exist<ModeLocalOperator>());
            }

            foreach (var who in whoList)
            {
                IrcDaemon.Replies.SendWhoReply(info, who);
            }
            IrcDaemon.Replies.SendEndOfWho(info, mask);
        }
Example #24
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            if (args.Count < 1)
            {
                // TODO: list all visible users
                return;
            }

            //TODO: taget parameter
            foreach (var ch in GetSubArgument(args[0]).Where(ch => IrcDaemon.Channels.ContainsKey(ch)))
            {
                IrcDaemon.Replies.SendNamesReply(info, IrcDaemon.Channels[ch]);
                IrcDaemon.Replies.SendEndOfNamesReply(info, IrcDaemon.Channels[ch]);
            }
        }
Example #25
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            // TODO: parameter 1 parsing

            if (string.IsNullOrEmpty(IrcDaemon.Options.MessageOfTheDay))
            {
                IrcDaemon.Replies.SendNoMotd(info);
            }
            else
            {
                IrcDaemon.Replies.SendMotdStart(info);
                IrcDaemon.Replies.SendMotd(info);
                IrcDaemon.Replies.SendMotdEnd(info);
            }
        }
Example #26
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;
        }
Example #27
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            if (!info.Modes.Exist<ModeOperator>() && !info.Modes.Exist<ModeLocalOperator>())
            {
                IrcDaemon.Replies.SendNoPrivileges(info);
                return;
            }

            int port;
            if (int.TryParse(args[1], out port))
            {
                IrcDaemon.Connect(args[0], port);
            }

            IrcDaemon.Replies.SendNoSuchServer(info, "Connect failed");
        }
Example #28
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;
 }
Example #29
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            var message = (args.Count > 2) ? args[2] : null;

            foreach (var subarg in GetSubArgument(args[0]).Zip(GetSubArgument(args[1]), (c, n) => new { Channel = c, Nick = n }))
            {

                if (!IrcDaemon.Channels.ContainsKey(subarg.Channel))
                {
                    IrcDaemon.Replies.SendNoSuchChannel(info, args[0]);
                    continue;
                }

                var chan = IrcDaemon.Channels[subarg.Channel];
                UserPerChannelInfo upci;

                if (chan.UserPerChannelInfos.TryGetValue(info.Nick, out upci))
                {
                    if (upci.Modes.Level < ModeHalfOp.HalfOpLevel)
                    {
                        IrcDaemon.Replies.SendChannelOpPrivilegesNeeded(info, chan);
                        continue;
                    }
                }
                else
                {
                    IrcDaemon.Replies.SendNotOnChannel(info, chan.Name);
                    continue;
                }

                UserPerChannelInfo kickUser;
                if (chan.UserPerChannelInfos.TryGetValue(subarg.Nick, out kickUser))
                {
                    Send(new KickArgument(info, chan, chan, kickUser.UserInfo, message));

                    chan.UserPerChannelInfos.Remove(kickUser.UserInfo.Nick);
                    kickUser.UserInfo.UserPerChannelInfos.Remove(kickUser);

                }
                else
                {
                    IrcDaemon.Replies.SendUserNotInChannel(info, subarg.Channel, subarg.Nick);
                }
            }
        }
Example #30
0
        protected override void PrivateHandle(UserInfo info, List<string> args)
        {
            if (!info.PassAccepted)
            {
                IrcDaemon.Replies.SendPasswordMismatch(info);
                return;
            }
            if (args.Count < 1)
            {
                IrcDaemon.Replies.SendNoNicknameGiven(info);
                return;
            }
            if (IrcDaemon.Nicks.ContainsKey(args[0]))
            {
                IrcDaemon.Replies.SendNicknameInUse(info, args[0]);
                return;
            }
            if (!IrcDaemon.ValidNick(args[0]))
            {
                IrcDaemon.Replies.SendErroneousNickname(info, args[0]);
                return;
            }

            // *** NICK command valid after this point ***

            if (!info.NickExists)
            {
                //First Nick Command
                IrcDaemon.Nicks.Add(args[0], info);
                info.InitNick(args[0]);
                return;
            }

            // Announce nick change to itself

            Send(new NickArgument(info, info, args[0]));

            // Announce nick change to all channels it is in
            foreach (var channelInfo in info.Channels)
            {
                Send(new NickArgument(info, channelInfo, args[0]));
            }

            info.Rename(args[0]);
        }