コード例 #1
0
ファイル: IRC.cs プロジェクト: shebang-sl/SLIRC
        public void Process(StreamWriter wtr, IRCCommand ircc, string input, string[] userl)
        {
            var split = String.Join(" ", IRCType.PRIVMSG, Channel, ":");

            if (input.Contains(split))
            {
                var usern = input.Split(':')[1].Split('~')[0];
                var cmd_s = input.Split(new string[] { split }, StringSplitOptions.None)[1];
                var args_ = cmd_s.Split(' ');
                var args  = args_.Skip(1).Take(args_.Length - 1).ToArray();
                var cmd   = args_[0];

                /* Disabled for now.
                 *
                 * if (cmd == "+commands")
                 * {
                 *  foreach (var msg in ircc.Commands(usern)) {
                 *      Send(wtr, msg);
                 *  }
                 * }
                 *
                 */
                var res = ircc.Interpret(cmd, args, userl);
                if (res.Type != IRCType.DONOTHING)
                {
                    Send(wtr, res);
                }
            }
            else if (input.Contains("PING"))
            {
                Send(wtr, new IRCMessage(IRCType.PONG, Server));
            }
        }
コード例 #2
0
ファイル: IRC.cs プロジェクト: shebang-sl/SLIRC
        public void Connect()
        {
            var ircc = new IRCCommand(this.Channel);
            try
            {
                var v_irc = new TcpClient(Server, Port);
                var v_str = v_irc.GetStream();
                var v_rdr = new StreamReader(v_str);
                var v_wtr = new StreamWriter(v_str);

                try
                {
                    Send(v_wtr, new IRCMessage(User));
                    Send(v_wtr, new IRCMessage(IRCType.NICK, Nickname));
                    Send(v_wtr, new IRCMessage(IRCType.JOIN, Channel));

                    while (true)
                    {
                        var input = String.Empty;
                        while ((input = v_rdr.ReadLine()) != String.Empty)
                        {
                            Console.WriteLine(input);
                            if (input.Contains("JOIN :" + Channel))
                            {
                                Send(v_wtr, new IRCMessage(IRCType.NAMES, Channel));
                            }
                            else if (input.Contains(String.Format("{0} = {1} :", Nickname, Channel)))
                            {
                                var users = input.Split(':')[2].Split(' ');
                                UserList.Clear();
                                foreach (var user in users) {
                                    if (user != Nickname) UserList.Add(user);
                                }
                            }
                            else
                            {
                                Process(v_wtr, ircc, input, UserList.ToArray());
                            }
                        }
                        v_rdr.Close();
                        v_wtr.Close();
                        v_irc.Close();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(String.Concat("Unable to join: ", ex.Message));
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(String.Concat("Unable to connect: ", ex.Message));
                return;
            }
        }
コード例 #3
0
ファイル: IRC.cs プロジェクト: shebang-sl/SLIRC
        public void Connect()
        {
            var ircc = new IRCCommand(this.Channel);

            try
            {
                var v_irc = new TcpClient(Server, Port);
                var v_str = v_irc.GetStream();
                var v_rdr = new StreamReader(v_str);
                var v_wtr = new StreamWriter(v_str);

                try
                {
                    Send(v_wtr, new IRCMessage(User));
                    Send(v_wtr, new IRCMessage(IRCType.NICK, Nickname));
                    Send(v_wtr, new IRCMessage(IRCType.JOIN, Channel));

                    while (true)
                    {
                        var input = String.Empty;
                        while ((input = v_rdr.ReadLine()) != String.Empty)
                        {
                            Console.WriteLine(input);
                            if (input.Contains("JOIN :" + Channel))
                            {
                                Send(v_wtr, new IRCMessage(IRCType.NAMES, Channel));
                            }
                            else if (input.Contains(String.Format("{0} = {1} :", Nickname, Channel)))
                            {
                                var users = input.Split(':')[2].Split(' ');
                                UserList.Clear();
                                foreach (var user in users)
                                {
                                    if (user != Nickname)
                                    {
                                        UserList.Add(user);
                                    }
                                }
                            }
                            else
                            {
                                Process(v_wtr, ircc, input, UserList.ToArray());
                            }
                        }
                        v_rdr.Close();
                        v_wtr.Close();
                        v_irc.Close();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(String.Concat("Unable to join: ", ex.Message));
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(String.Concat("Unable to connect: ", ex.Message));
                return;
            }
        }
コード例 #4
0
ファイル: IRC.cs プロジェクト: shebang-sl/SLIRC
        public void Process(StreamWriter wtr, IRCCommand ircc, string input, string[] userl)
        {
            var split = String.Join(" ", IRCType.PRIVMSG, Channel, ":");

            if (input.Contains(split))
            {
                var usern = input.Split(':')[1].Split('~')[0];
                var cmd_s = input.Split(new string[] { split }, StringSplitOptions.None)[1];
                var args_ = cmd_s.Split(' ');
                var args = args_.Skip(1).Take(args_.Length - 1).ToArray();
                var cmd = args_[0];

                /* Disabled for now.

                if (cmd == "+commands")
                {
                    foreach (var msg in ircc.Commands(usern)) {
                        Send(wtr, msg);
                    }
                }

                 */
                var res = ircc.Interpret(cmd, args, userl);
                if (res.Type != IRCType.DONOTHING)
                {
                    Send(wtr, res);
                }
            }
            else if (input.Contains("PING"))
            {
                Send(wtr, new IRCMessage(IRCType.PONG, Server));
            }
        }