Exemplo n.º 1
0
        private void ParseWHOIS(MessageInfo messageInfo)
        {
            UserInfo userInfo;

            switch (messageInfo.Command)
            {
            case "311":     //:sendak.freenode.net 311 Jaex ShareX ~ShareX unaffiliated/sharex * :realname
                if (messageInfo.Parameters.Count >= 4)
                {
                    userInfo = new UserInfo
                    {
                        Nickname = messageInfo.Parameters[1],
                        Username = messageInfo.Parameters[2][1] == '~' ? messageInfo.Parameters[2].Substring(1) : messageInfo.Parameters[2],
                        Host     = messageInfo.Parameters[3],
                        Realname = messageInfo.Message
                    };
                    _userList.Add(userInfo);
                }
                break;

            case "319":     //:sendak.freenode.net 319 Jaex ShareX :@#ShareX @#ShareX_Test
                if (messageInfo.Parameters.Count >= 2)
                {
                    userInfo = FindUser(messageInfo.Parameters[1]);

                    if (userInfo != null)
                    {
                        userInfo.Channels.Clear();
                        userInfo.Channels.AddRange(messageInfo.Message.Split());
                    }
                }
                break;

            case "312":     //:sendak.freenode.net 312 Jaex ShareX sendak.freenode.net :Vilnius, Lithuania, EU
                if (messageInfo.Parameters.Count >= 3)
                {
                    userInfo = FindUser(messageInfo.Parameters[1]);

                    if (userInfo != null)
                    {
                        userInfo.Server = messageInfo.Parameters[2];
                    }
                }
                break;

            case "671":     //:sendak.freenode.net 671 Jaex ShareX :is using a secure connection
                if (messageInfo.Parameters.Count >= 2)
                {
                    userInfo = FindUser(messageInfo.Parameters[1]);

                    if (userInfo != null)
                    {
                        userInfo.SecureConnection = true;
                    }
                }
                break;

            case "317":     //:sendak.freenode.net 317 Jaex ShareX 39110 1440201914 :seconds idle, signon time
                if (messageInfo.Parameters.Count >= 4)
                {
                    userInfo = FindUser(messageInfo.Parameters[1]);

                    if (userInfo != null)
                    {
                        if (int.TryParse(messageInfo.Parameters[2], out var idleTime))
                        {
                            userInfo.IdleTime = TimeSpan.FromSeconds(idleTime);
                        }

                        if (int.TryParse(messageInfo.Parameters[3], out var signOnTime))
                        {
                            userInfo.SignOnDate = Helpers.Helpers.UnixToDateTime(signOnTime).ToLocalTime();
                        }
                    }
                }
                break;

            case "330":     //:sendak.freenode.net 330 Jaex ShareX ShareX :is logged in as
                if (messageInfo.Parameters.Count >= 3)
                {
                    userInfo = FindUser(messageInfo.Parameters[1]);

                    if (userInfo != null)
                    {
                        userInfo.Identity = messageInfo.Parameters[2];
                    }
                }
                break;

            case "318":     //:sendak.freenode.net 318 Jaex ShareX :End of /WHOIS list.
                if (messageInfo.Parameters.Count >= 2)
                {
                    userInfo = FindUser(messageInfo.Parameters[1]);

                    if (userInfo != null)
                    {
                        _userList.Remove(userInfo);
                        OnWhoisResult(userInfo);
                    }
                }
                break;
            }
        }
Exemplo n.º 2
0
 protected void OnOutput(MessageInfo messageInfo)
 {
     Output?.Invoke(messageInfo);
 }
Exemplo n.º 3
0
        private async Task <bool> CheckCommand(string message)
        {
            var messageInfo = MessageInfo.Parse(message);

            if (messageInfo.User.UserType == IRCUserType.Me)
            {
                messageInfo.User.Nickname = CurrentNickname;
            }

            var suppressOutput = (Settings.IrcModule.SuppressMOTD && messageInfo.CheckCommand("375",    //:sendak.freenode.net 375 Jaex :- sendak.freenode.net Message of the Day -
                                                                                              "372",    //:sendak.freenode.net 372 Jaex :- Welcome to sendak.freenode.net in Vilnius, Lithuania, EU.
                                                                                              "376")) || //:sendak.freenode.net 376 Jaex :End of /MOTD command.
                                 (Settings.IrcModule.SuppressPing && messageInfo.CheckCommand("PING",   //PING :sendak.freenode.net
                                                                                              "PONG")); //PONG :sendak.freenode.net

            if (!suppressOutput)
            {
                OnOutput(messageInfo);
            }

            if (messageInfo.CheckCommand("PING")) //PING :sendak.freenode.net
            {
                _lastPingServer = messageInfo.Message;
                await SendPong(messageInfo.Message);
            }
            else if (messageInfo.CheckCommand("376")) //:sendak.freenode.net 376 Jaex :End of /MOTD command.
            {
                IsConnected = true;

                OnConnected();

                foreach (var command in Settings.IrcModule.ConnectCommands)
                {
                    await SendRawMessage(command);
                }

                if (!Settings.IrcModule.AutoJoinWaitIdentify)
                {
                    await AutoJoinChannels();
                }
            }
            else if (messageInfo.CheckCommand("433")) //:sendak.freenode.net 433 * ShareX :Nickname is already in use.
            {
                if (!IsConnected && messageInfo.Parameters.Count >= 2)
                {
                    var nickname = !string.IsNullOrEmpty(Settings.IrcModule.Nickname2) ? Settings.IrcModule.Nickname2 : Settings.IrcModule.Nickname + "_";

                    if (!messageInfo.Parameters[1].Equals(nickname, StringComparison.InvariantCultureIgnoreCase))
                    {
                        await ChangeNickname(nickname);
                    }
                }
            }
            else if (messageInfo.CheckCommand("PRIVMSG")) //:Jaex!Jaex@unaffiliated/jaex PRIVMSG #ShareX :test
            {
                await CheckMessage(messageInfo);
            }
            else if (messageInfo.CheckCommand("JOIN")) //:Jaex!Jaex@unaffiliated/jaex JOIN #ShareX or :Jaex!Jaex@unaffiliated/jaex JOIN :#ShareX
            {
                OnUserJoined(messageInfo.User, messageInfo.Parameters.Count > 0 ? messageInfo.Parameters[0] : messageInfo.Message);
            }
            else if (messageInfo.CheckCommand("PART")) //:Jaex!Jaex@unaffiliated/jaex PART #ShareX :"Leaving"
            {
                OnUserLeft(messageInfo.User, messageInfo.Parameters[0]);
            }
            else if (messageInfo.CheckCommand("QUIT")) //:Jaex!Jaex@unaffiliated/jaex QUIT :Client Quit
            {
                OnUserQuit(messageInfo.User);
            }
            else if (messageInfo.CheckCommand("NICK")) //:Jaex!Jaex@unaffiliated/jaex NICK :Jaex2
            {
                OnUserNickChanged(messageInfo.User, messageInfo.Message);
            }
            else if (messageInfo.CheckCommand("KICK")) //:Jaex!Jaex@unaffiliated/jaex KICK #ShareX Jaex2 :Jaex2
            {
                OnUserKicked(messageInfo.User, messageInfo.Parameters[0], messageInfo.Parameters[1]);

                if (Settings.IrcModule.AutoRejoinOnKick && messageInfo.Parameters[1].Equals(CurrentNickname, StringComparison.InvariantCultureIgnoreCase))
                {
                    await JoinChannel(messageInfo.Parameters[0]);
                }
            }
            else if (messageInfo.CheckCommand("311",  //:sendak.freenode.net 311 Jaex ShareX ~ShareX unaffiliated/sharex * :realname
                                              "319",  //:sendak.freenode.net 319 Jaex ShareX :@#ShareX @#ShareX_Test
                                              "312",  //:sendak.freenode.net 312 Jaex ShareX sendak.freenode.net :Vilnius, Lithuania, EU
                                              "671",  //:sendak.freenode.net 671 Jaex ShareX :is using a secure connection
                                              "317",  //:sendak.freenode.net 317 Jaex ShareX 39110 1440201914 :seconds idle, signon time
                                              "330",  //:sendak.freenode.net 330 Jaex ShareX ShareX :is logged in as
                                              "318")) //:sendak.freenode.net 318 Jaex ShareX :End of /WHOIS list.
            {
                ParseWHOIS(messageInfo);
            }
            else if (messageInfo.CheckCommand("396")) //:sendak.freenode.net 396 Jaex unaffiliated/jaex :is now your hidden host (set by services.)
            {
                if (Settings.IrcModule.AutoJoinWaitIdentify)
                {
                    await AutoJoinChannels();
                }
            }
            else if (messageInfo.CheckCommand("ERROR"))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        private async Task CheckMessage(MessageInfo messageInfo)
        {
            var channel = messageInfo.Parameters[0];

            OnMessage(messageInfo.User, channel, messageInfo.Message);
        }
Exemplo n.º 5
0
        public static MessageInfo Parse(string content)
        {
            MessageInfo messageInfo = new MessageInfo(content);

            int    index;
            string nickname = ParseSection(content, out index);

            // Is it not my message?
            if (nickname.StartsWith(":"))
            {
                nickname = nickname.Substring(1);
                int usernameIndex = nickname.IndexOf("!", StringComparison.Ordinal);

                // Is it not server?
                if (usernameIndex > -1)
                {
                    //nickname!~username@host
                    messageInfo.User.UserType = IRCUserType.User;
                    messageInfo.User.Nickname = nickname.Remove(usernameIndex);

                    nickname = nickname.Substring(usernameIndex + 1);

                    if (nickname[0] == '~') // Remove Ident character
                    {
                        nickname = nickname.Substring(1);
                    }

                    int hostIndex = nickname.IndexOf("@", StringComparison.Ordinal);
                    messageInfo.User.Username = nickname.Remove(hostIndex);
                    messageInfo.User.Host     = nickname.Substring(hostIndex + 1);
                }
                else
                {
                    //irc.freenode.net
                    messageInfo.User.UserType = IRCUserType.Server;
                    messageInfo.User.Host     = nickname;
                }

                content             = content.Substring(index + 1);
                messageInfo.Command = ParseSection(content, out index);
            }
            else
            {
                // It is my command
                messageInfo.User.UserType = IRCUserType.Me;
                messageInfo.Command       = nickname;
            }

            while (index > -1)
            {
                content = content.Substring(index + 1);
                string check = ParseSection(content, out index);

                // Is it parameter?
                if (!check.StartsWith(":"))
                {
                    messageInfo.Parameters.Add(check);
                }
                else
                {
                    // It is message
                    messageInfo.Message = content.Substring(1);
                    break;
                }
            }

            return(messageInfo);
        }