Пример #1
0
        public void Execute(MessageSender source, IrcMessage message, CommandParameters parameters)
        {
            if (parameters.Count == 0 || parameters.Count > 1)
                throw new ParameterException();

            bot.PartChannel(parameters[0]);
        }
Пример #2
0
        public void Execute(MessageSender executor, IrcMessage message, CommandParameters parameters)
        {
            var commands = bot.GetAllCommands();

            foreach (var command in commands)
            {
                bot.SayTo(executor.Channel, command.GetKeyWord());
            }
        }
Пример #3
0
        public void Execute(MessageSender source, IrcMessage message, CommandParameters parameters)
        {
            if (parameters == null || parameters.Count == 0)
                return;

            var sayToMessage = GetMessageFromParameters(parameters);

            bot.SayTo(source.Channel, sayToMessage);
        }
Пример #4
0
        public void Execute(MessageSender executor, IrcMessage message, CommandParameters parameters)
        {
            if (parameters.Count == 0)
                return;

            var sendToServerMessage = GetParametersInOneSentence(parameters);

            bot.SendToServer(sendToServerMessage);
        }
Пример #5
0
        public void Execute(MessageSender executor, IrcMessage message, CommandParameters parameters)
        {
            if (parameters.Count == 0 || parameters.Count > 2)
            {
                var invalidParametersMessage = string.Format("Invalid amount of parameters. Usage: {0} {1} [{2}]",
                                                             GetKeyWord(), "#channel", "password");
                bot.SayTo(executor.Channel, invalidParametersMessage);
                return;
            }

            var channel = parameters[0];
            var password = GetPassword(parameters);

            bot.JoinChannel(channel, password);
        }
        public void Execute(MessageSender source, IrcMessage message, CommandParameters parameters)
        {
            var users = bot.GetAuthenticatedUsers();
            if (users.Count == 0)
            {
                bot.SayTo(source.Channel, "No authenticated users");
                return;
            }

            bot.SayTo(source.Channel, "Authenticated users:");
            bot.SayTo(source.Channel, "----");

            foreach (var user in users.GetLoggedInUsers())
            {
                var userInformationMessage = string.Format("{0}({1}) - {2}",
                    user.Name, user.HostMask, user.SecurityLevelInformation.SecurityLevelDescription);

                bot.SayTo(source.Channel, userInformationMessage);
            }
        }
Пример #7
0
        public void Execute(MessageSender executor, IrcMessage message, CommandParameters parameters)
        {
            if (parameters.Count != 2)
            {
                bot.SayTo(executor.Channel, "You must give username and password when authenticating");
                return;
            }

            var users = bot.GetAuthenticatedUsers();
            // First we check that the user who tries to log in isn't already logged in
            if (users.IsLoggedInHostMask(message.Sender.HostMask))
            {
                bot.SayTo(executor.Channel, "You have already authenticated");
                return;
            }

            // Lets continue by checking the login-information.
            var user = dataSource.LogInUser(parameters[0], parameters[1]);
            if (!user.Name.Equals(""))
            {
                // Lets check that user isn't already logged in
                if (users.IsLoggedInUserName(user.Name))
                {
                    var alreadyAuthenticatedMessage = string.Format("User {0} has already authenticated", user.Name);
                    bot.SayTo(executor.Channel, alreadyAuthenticatedMessage);
                }
                else
                {
                    user.HostMask = message.Sender.HostMask;
                    user.NickName = message.Sender.Name;

                    // We get user's permissions to different channels
                    user.ChannelSecurityLevelCollection = dataSource.GetChannelSecurityLevelsForUser(user.Id);

                    users.AddUser(user);
                    bot.SayTo(executor.Channel, "Authenticated succesfully");
                }
            }
            else
                bot.SayTo(executor.Channel, "Wrong username or password");
        }
Пример #8
0
        public void Execute(MessageSender executor, IrcMessage message, CommandParameters parameters)
        {
            if (parameters.Count == 0)
            {
                bot.SayTo(executor.Channel, "Usage: help commandname");
                return;
            }

            var commands = bot.GetAllCommands();
            foreach (var command in commands)
            {
                if (command.GetKeyWord() != parameters[0]) continue;

                var help = command.GetHelp();

                this.ShowHelpTo(help, executor.Channel);
                return;
            }

            var unknownCommandMessage = string.Format("Unknown command {0}", parameters[0]);
            bot.SayTo(executor.Channel, unknownCommandMessage);
        }
Пример #9
0
 private void MessageManager(string message)
 {
     Log(message, MessageLevel.Debug);
     if (message.StartsWith("PING"))
     {
         string[] splitLine = message.Split(' ');
         SendLine("PONG {0}", splitLine[1]);
     }
     else if (message.StartsWith("ERROR"))
     {
         Quit(message);
     }
     else
     {
         IrcMessage _message = new IrcMessage(message);
         switch (_message.Command)
         {
             case "005": // Server configuration
                 break;
             case "333": // Topic who time
                 break;
             case "353": // List of names
                 RcvListOfNames(_message);
                 break;
             case "366": // End of list of names
                 RcvEndOfListOfNames(_message);
                 break;
             case "375": // Start of MOTD
                 break;
             case "376": // End of MOTD
                 Perform();
                 break;
             case "433": // Nickname already used
                 break;
             case "422": // No MOTD
                 Perform();
                 break;
             case "WHISPER":
             case "PRIVMSG": // Private message
                 RcvPrivMsg(_message);
                 break;
             case "JOIN": // Joining channel
                 RcvJoin(_message);
                 break;
             case "KICK": // Kicked from channel
                 break;
             case "PART": // Part from channel
                 RcvPart(_message);
                 break;
             case "NOTICE": // Notice
                 RcvNotice(_message);
                 break;
             case "MODE": // MODE
                 RcvMode(_message);
                 break;
             case "CAP": // Capabilities
                 //System.Diagnostics.Debugger.Break();
                 break;
             default : // Unknown command
                 if (OnUnknownCommand != null)
                     OnUnknownCommand(this, _message);
                 break;
         }
     }
 }
Пример #10
0
        // Recive methods
        private void RcvPrivMsg(IrcMessage message)
        {
            if (message.Parameters[1][0] == 0x01)
            {
                RcvCTCP(message);
            }
            else
            {
                string channel = message.Parameters[0];
                string msg = message.Parameters[1];
                string userid = "", userhost = "";
                string[] split = message.Prefix.Split(USERHOST_SIGNS);

                string nick = split[0];
                if (split.Length > 1)
                    userid = split[1];
                if (split.Length > 2)
                    userhost = split[2];

                bool isforme = (channel.ToLowerInvariant() == myNickname.ToLowerInvariant());

                if (OnPrivateMessage != null)
                {
                    OnPrivateMessage(this, new IrcClientOnPrivateMessageEventArgs(msg, nick, userid, userhost, channel, isforme, message.Tags));
                }
            }
        }
Пример #11
0
        private void RcvPart(IrcMessage message)
        {
            if (OnPart != null)
            {
                string channel = message.Parameters[0];
                string userid = "", userhost = "";
                string[] split = message.Prefix.Split(USERHOST_SIGNS);

                string nick = split[0];
                if (split.Length > 1)
                    userid = split[1];
                if (split.Length > 2)
                    userhost = split[2];

                bool isforme = (nick.ToLowerInvariant() == myNickname.ToLowerInvariant());

                OnPart(this, new IrcClientOnPartEventArgs(nick, userid, userhost, channel, isforme));
            }
        }
Пример #12
0
 private void RcvNotice(IrcMessage message)
 {
     if (OnNotice != null)
         OnNotice(this, message);
 }
Пример #13
0
        private void RcvMode(IrcMessage message)
        {
            string channel = message.Parameters[0];
            string userid = "", userhost = "";
            string[] split = message.Prefix.Split(USERHOST_SIGNS);

            string nick = split[0];
            if (split.Length > 1)
                userid = split[1];
            if (split.Length > 2)
                userhost = split[2];

            int number_of_targets = message.Parameters.Length - 2;
            if (number_of_targets == 0)
            {
                string modes = message.Parameters[1];
                List<ModeChange> changes = new List<ModeChange>(modes.Length - 1);
                bool adding = false;
                foreach (char mode in modes)
                {
                    switch (mode)
                    {
                        case '+': adding = true;
                            break;
                        case '-': adding = false;
                            break;
                        default:
                            changes.Add(new ModeChange()
                            {
                                IsAdded = adding,
                                IsGlobalMode = true,
                                Mode = mode,
                                Name = message.Parameters[0]
                            });
                            break;
                    }
                }

                if(this.OnMode != null)
                    OnMode(this, new IrcClientOnModeEventArgs(userid, nick, userhost, channel, changes.ToArray()));
            }
            else
            {
                ModeChange[] changes = new ModeChange[number_of_targets];
                string modes = message.Parameters[1];
                int modeslength = modes.Length;
                bool adding = false;
                int modecursor = 0;
                foreach(char mode in modes)
                {
                    switch (mode)
                    {
                        case '+': adding = true;
                            break;
                        case '-': adding = false;
                            break;
                        default:
                            changes[modecursor].IsAdded = adding;
                            changes[modecursor].Mode = mode;
                            changes[modecursor].Name = message.Parameters[2 + modecursor];
                            changes[modecursor].IsGlobalMode = false;
                            modecursor++;
                            break;
                    }
                }
                if(this.OnMode != null)
                    OnMode(this, new IrcClientOnModeEventArgs(userid, nick, userhost, channel, changes));
            }
        }
Пример #14
0
 private void RcvListOfNames(IrcMessage message)
 {
     if (OnChannelNickListRecived != null)
     {
         if (message.Parameters.Length > 3)
         {
             if (!channelNickList.ContainsKey(message.Parameters[2]))
             {
                 channelNickList.Add(message.Parameters[2], new List<string>());
             }
             channelNickList[message.Parameters[2]]
                 .AddRange(message.Parameters[3].Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries));
         }
     }
 }
Пример #15
0
 private void RcvEndOfListOfNames(IrcMessage message)
 {
     if (OnChannelNickListRecived != null)
     {
         string channel = message.Parameters[1];
         if (channelNickList.ContainsKey(channel))
         {
             OnChannelNickListRecived(this, new IrcClientOnChannelNickListReceivedEventArgs(channel, channelNickList[channel].ToArray()));
         }
         else
         {
             OnChannelNickListRecived(this, new IrcClientOnChannelNickListReceivedEventArgs(channel, new string[] {}));
         }
     }
 }
Пример #16
0
 void m_client_OnNotice(IrcClient sender, IrcMessage args)
 {
     //throw new NotImplementedException();
 }
 public void Execute(MessageSender executor, IrcMessage message, CommandParameters parameters)
 {
     bot.DisconnectFromServer();
 }
Пример #18
0
        /// <summary>
        /// Parses a line of text from an IRC server into its message parts as defined by RFC2812.
        /// </summary>
        /// <param name="input">A line of text to parse.</param>
        /// <returns>An IRC message.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if input is null.</exception>
        /// <exception cref="System.FormatException">Thrown if there is a problem parsing the input string.
        /// The input string can be found in the Data dictionary with the "input" key.</exception>
        /// <example>[ ":" prefix ] command [ params*14 ] [ [ ":" ] message ] crlf</example>
        public static IrcMessage Parse(string input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            input = RemoveIllegalChars(input);

            try
            {
                string[]   parts      = input.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                IrcMessage message    = new IrcMessage();
                int        tokenIndex = 0;

                if (parts[tokenIndex][0] == ':')
                {
                    message.Prefix = parts[tokenIndex++].Substring(1);
                }

                message.Command = parts[tokenIndex++];

                /**
                 * If the message has a trailing component, the trailing end starts with a colon.
                 * However, we can't simply perform a substring operation ending at the next colon
                 * because some messages may contain IP6 addresses which would f**k it up.
                 * (Willing to bet the original RFC expected a substring indexed against a colon would be possible)
                 *
                 * So instead, we have to go word by word until we find one that starts with a colon.
                 */
                int paramCount = 0;
                while (tokenIndex < parts.Length && parts[tokenIndex][0] != ':' && paramCount < MAXPARAMSPERLINE)
                {
                    paramCount++;
                    tokenIndex++;
                }

                message.Parameters = new string[paramCount];
                Array.Copy(parts, tokenIndex - paramCount, message.Parameters, 0, paramCount);

                while (tokenIndex < parts.Length)
                {
                    message.Trailing = string.Concat(message.Trailing, parts[tokenIndex++], " ");
                }

                if (!string.IsNullOrEmpty(message.Trailing))
                {
                    message.Trailing = message.Trailing.Substring(1).TrimEnd();
                }

                message._stringRepresentation = input;

                return(message);
            }
            catch (IndexOutOfRangeException)
            {
                FormatException ex = new FormatException(Properties.Resources.IrcMessageFormatError);
                ex.Data["input"] = input;
                throw ex;
            }
        }
Пример #19
0
 void m_client_OnUnknownCommand(IrcClient sender, IrcMessage message)
 {
     /*
     switch (message.Command)
     {
         default:
             Console.ForegroundColor = ConsoleColor.Yellow;
             Console.WriteLine(message);
             Console.ForegroundColor = ConsoleColor.Gray;
             break;
     }*/
 }
Пример #20
0
        private void RcvCTCP(IrcMessage message)
        {
            string msg = message.Parameters[1];
            string[] split = message.Prefix.Split(USERHOST_SIGNS);
            string sender = split[0];

            string[] s = msg.Split(CTCP_SIGN, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length > 0)
            {
                switch (s[0])
                {
                    case "VERSION":
                        SendLine("NOTICE {0} :{1}VERSION {2}{1}", sender, (char)0x01, VersionString);
                        break;
                    case "PING":
                        if(s.Length > 1)
                            SendLine("NOTICE {0} :{1}PING {2}{1}", sender, (char)0x01, s[1]);
                        break;
                    case "TIME":
                        SendLine("NOTICE {0} :{1}TIME {2}{1}", sender, (char)0x01, DateTime.Now.ToString("ddd MMM d HH:mm:ss yyyy", CultureInfo.CreateSpecificCulture("en-US")));
                        break;
                }
            }
        }