Пример #1
0
        void connection_Received_NOTICE(IrcUser source, string target, string message)
        {
            string user = "******" + source.Nickname + "-";

            if (target != connection.NickName)
            {
                user += target + "-";
            }
            serverWindow.WriteOutput(Color.DarkRed, user + " " + message);
        }
Пример #2
0
        private void ctcpRequestReceived(IrcUser source, string target, string line)
        {
            string[] args = line.Split(" ".ToCharArray(), 2);
            string   command;
            string   arg;

            if (args.Length == 0)
            {
                command = ""; arg = "";
            }
            else if (args.Length == 1)
            {
                command = args[0]; arg = ""; args = new string[0];
            }
            else
            {
                command = args[0]; arg = args[1]; args = arg.Split(' ');
            }
            switch (command)
            {
            case "VERSION":
                Msg_CTCP_REPLY_VERSION(source.Nickname);
                goto default;

            case "PING":
                if (arg.Length < 17)
                {
                    Msg_CTCP_REPLY_PING(source.Nickname, arg);
                }
                goto default;

            case "TIME":
                Msg_CTCP_REPLY_TIME(source.Nickname);
                goto default;

            case "ACTION":
                if (Received_CTCP_REQUEST_ACTION != null)
                {
                    Received_CTCP_REQUEST_ACTION(source, target, arg);
                }
                else
                {
                    goto default;
                }
                break;

            default:
                if (Received_CTCP_REQUEST != null)
                {
                    Received_CTCP_REQUEST(source, target, line);
                }
                break;
            }
        }
Пример #3
0
        void connection_Received_QUIT(IrcUser source, string message)
        {
            string text = (string.IsNullOrEmpty(message))
                ? string.Format("* {0} ({1}) has quit IRC", source.Nickname, source.Original)
                : string.Format("* {0} ({1}) has quit IRC ({2})", source.Nickname, source.Original, message);

            serverWindow.WriteOutput(Color.DarkBlue, text);
            foreach (IrcEnvChannel channel in envChannels.Values)
            {
                if (channel.HasUser(source.Nickname))
                {
                    channel.Window.WriteOutput(Color.DarkBlue, text);
                }
            }
        }
Пример #4
0
        void connection_Received_NICK(IrcUser source, string target)
        {
            if (connection.NickName == target)
            {
                serverWindow.WriteOutput(Color.Green, "* Your nick is now " + target);
            }

            string text = string.Format("* {0} ({1}) is now known as {2}", source.Nickname, source.Original, target);

            foreach (IrcEnvChannel channel in envChannels.Values)
            {
                if (channel.HasUser(source.Nickname))
                {
                    channel.Window.WriteOutput(Color.Green, text);
                }
            }
        }
Пример #5
0
        void connection_Received_PRIVMSG(IrcUser source, string target, string message)
        {
            string _target = target.ToLower();

            if (envChannels.ContainsKey(_target))
            {
                envChannels[_target].Window.WriteOutput(Color.Black, string.Format("<{0}> {1}", source.Nickname, message));
            }
            else if (target == connection.NickName)
            {
                getQueryWindow(source.Nickname).WriteOutput(Color.Black, string.Format("<{0}> {1}", source.Nickname, message));
            }
            else
            {
                serverWindow.WriteOutput(Color.Black, string.Format("<{0} -> {2}> {1}", source.Nickname, message, target));
            }
        }
Пример #6
0
        void connection_Received_CTCP_REQUEST_ACTION(IrcUser source, string target, string message)
        {
            string _target = target.ToLower();

            if (envChannels.ContainsKey(_target))
            {
                envChannels[_target].Window.WriteOutput(Color.Purple, string.Format("* {0} {1}", source.Nickname, message));
            }
            else if (target == connection.NickName)
            {
                getQueryWindow(source.Nickname).WriteOutput(Color.Purple, string.Format("* {0} {1}", source.Nickname, message));
            }
            else
            {
                serverWindow.WriteOutput(Color.Purple, string.Format("[ACTION] <{0} -> {2}> {1}", source.Nickname, message, target));
            }
        }
Пример #7
0
        private void ctcpReplyReceived(IrcUser source, string target, string line)
        {
            string[] args = line.Split(" ".ToCharArray(), 2);
            string   command;
            string   arg;

            if (args.Length == 0)
            {
                command = ""; arg = "";
            }
            else if (args.Length == 1)
            {
                command = args[0]; arg = ""; args = new string[0];
            }
            else
            {
                command = args[0]; arg = args[1]; args = arg.Split(' ');
            }
            switch (command)
            {
            case "PING":
            case "PONG":
                if (Received_CTCP_REPLY_PING != null)
                {
                    Received_CTCP_REPLY_PING(source, target, arg);
                }
                else
                {
                    goto default;
                }
                break;

            default:
                if (Received_CTCP_REPLY != null)
                {
                    Received_CTCP_REPLY(source, target, line);
                }
                break;
            }
        }
Пример #8
0
 void connection_Received_CTCP_REQUEST(IrcUser source, string target, string message)
 {
     serverWindow.WriteOutput(Color.Red, string.Format(target == connection.NickName ? "[{0}] {1}" : "[{0} -> {2}] {1}", source.Nickname, message, target));
 }
Пример #9
0
 void connection_Received_CTCP_REPLY_PING(IrcUser source, string target, string message)
 {
     try { serverWindow.WriteOutput(Color.Blue, string.Format("[{0}] PING {1} ms.", source.Nickname, System.Environment.TickCount - Convert.ToInt32(message, 10))); }
     catch { connection_Received_CTCP_REPLY(source, target, "PING " + message); }
 }
Пример #10
0
        void lineReceived(byte[] buffer, int from, int length)
        {
            try
            {
                string[] data = SplitByteString(buffer, from, length);
                int      pi   = 1;
                IrcUser  source;
                string   command = data[0];
                if (command[0] != ':')
                {
                    source = new IrcUser();
                }
                else
                {
                    source  = new IrcUser(command);
                    command = data[1];
                    pi      = 2;
                }
                switch (command)
                {
                case "PING":
                    if (data.Length - pi > 0)
                    {
                        Msg_PONG(data[pi]);
                        if (Received_PING != null)
                        {
                            Received_PING(data[pi]);
                        }
                        else
                        {
                            goto default;
                        }
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "NOTICE":     // INCOMPLETE
                    if (isCtcp(data[pi + 1]))
                    {
                        ctcpReplyReceived(source, data[pi], getCtcp(data[pi + 1]));
                    }
                    else if (Received_NOTICE != null)
                    {
                        Received_NOTICE(source, data[pi], data[pi + 1]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "PRIVMSG":     // CTCP NOT IMPLEMENTED
                    if (isCtcp(data[pi + 1]))
                    {
                        ctcpRequestReceived(source, data[pi], getCtcp(data[pi + 1]));
                    }
                    else if (Received_PRIVMSG != null)
                    {
                        Received_PRIVMSG(source, data[pi], data[pi + 1]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "JOIN":
                    if (Received_JOIN != null)
                    {
                        Received_JOIN(source, data[pi]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "PART":
                    if (Received_PART != null)
                    {
                        if (data.Length > pi + 1)
                        {
                            Received_PART(source, data[pi], data[pi + 1]);
                        }
                        else
                        {
                            Received_PART(source, data[pi], null);
                        }
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "QUIT":
                    if (Received_PART != null)
                    {
                        if (data.Length > pi)
                        {
                            Received_QUIT(source, data[pi]);
                        }
                        else
                        {
                            Received_QUIT(source, null);
                        }
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "KICK":
                    if (Received_KICK != null)
                    {
                        if (data.Length > pi + 2)
                        {
                            Received_KICK(source, data[pi], data[pi + 1], data[pi + 2]);
                        }
                        else
                        {
                            Received_KICK(source, data[pi], data[pi + 1], null);
                        }
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "NICK":
                    if (source.Nickname == nickname)
                    {
                        this.NickName = data[pi];
                    }
                    if (Received_NICK != null)
                    {
                        Received_NICK(source, data[pi]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "001":
                    this.NickName = data[pi];
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_WELCOME", data[pi + 1]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "002":
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_YOURHOST", data[pi + 1]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "003":
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_CREATED", data[pi + 1]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "004":
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_MYINFO", string.Join("; ", data, pi + 1, data.Length - pi - 1));
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "005":
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_ISUPPORT", string.Join("; ", data, pi + 1, data.Length - pi - 1));
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "015":
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_MAP", string.Join("; ", data, pi + 1, data.Length - pi - 1));
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "016":
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_MAPMORE", string.Join("; ", data, pi + 1, data.Length - pi - 1));
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "017":
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_MAPEND", string.Join("; ", data, pi + 1, data.Length - pi - 1));
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "042":
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_YOURID", string.Join("; ", data, pi + 1, data.Length - pi - 1));
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "302":     //    RPL_USERHOST
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_USERHOST", data[pi + 1]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "303":     //    RPL_ISON
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_ISON", data[pi + 1]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "301":     //    RPL_AWAY -- own event
                    if (Received_RPL_AWAY != null)
                    {
                        Received_RPL_AWAY(data[pi + 1], data[pi + 2]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "305":     //    RPL_UNAWAY -- one string
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_UNAWAY", data[pi + 1]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "306":     //    RPL_NOWAWAY -- one string
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_NOWAWAY", data[pi + 1]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "375":     // RPL_MOTDSTART
                    Data_MOTD_END = false; Data_MOTD.Clear();
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_MOTDSTART", data[pi + 1]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "372":     // RPL_MOTD
                    if (Data_MOTD_END)
                    {
                        Data_MOTD_END = false; Data_MOTD.Clear();
                    }
                    Data_MOTD.Add(data[pi + 1]);
                    if (Received_RPL != null)
                    {
                        Received_RPL("RPL_MOTD", data[pi + 1]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                case "376":     // RPL_ENDOFMOTD <- SHOULD GET IT'S OWN EVENT!
                    Data_MOTD_END = true;
                    if (Received_RPL_ENDOFMOTD != null)
                    {
                        Received_RPL_ENDOFMOTD(data[pi + 1]);
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                //case "PRIVMSG": // UNFINISHED
                //    string msgtarget = ConvertToString(line[index]);
                //    index++;
                //    string msgtext = ConvertToString(line[index]);
                //    // index++; is not used anymore.
                //    break;
                default:
                    if (UnknownLine != null)
                    {
                        UnknownLine(Encoding.UTF8.GetString(buffer, from, length));
                    }
                    break;
                }
                if (RawLine != null)
                {
                    RawLine(" <- " + Encoding.UTF8.GetString(buffer, from, length));
                }
            }
            catch (Exception ex)
            {
                connectionException(ex.ToString() + "\r\n @ -> " + Encoding.UTF8.GetString(buffer, from, length));
            }
        }