예제 #1
0
        private static string USER = "******"; //Something something standard

        #endregion Fields

        #region Methods

        static void Main(string[] args)
        {
            TcpClient irc;
            string inputLine;
            StreamWriter writer;
            StreamReader reader;
            string[] splitInput;
            ChatHandler handler = new ChatHandler();
            PingSender pingSender;
            List<string> response;

            try
            {
                //Connecting to IRC server and channel
                irc = new TcpClient(SERVER, PORT);
                stream = irc.GetStream();
                reader = new StreamReader(stream);
                writer = new StreamWriter(stream);
                pingSender = new PingSender();
                writer.WriteLine("NICK " + NICK);
                writer.Flush();
                writer.WriteLine(USER);
                writer.Flush();
                writer.WriteLine("JOIN " + CHANNEL);
                writer.Flush();
                pingSender.Start();

                while(true)
                {
                    while((inputLine = reader.ReadLine()) != null)
                    {
                        splitInput = inputLine.Split(new Char[] { ' ' });

                        if(splitInput[0] != "PONG")
                            Console.WriteLine(inputLine);

                        response = handler.Response(inputLine);
                        if (response != null)
                        {

                            if (response[1].Contains("\n"))
                            {
                                string[] multiLineResponse = response[1].Split(new Char[] { '\n' });

                                foreach (string message in multiLineResponse)
                                {
                                    if (message.Contains("/me"))
                                    {
                                    }
                                    else
                                    {
                                        writer.WriteLine(string.Format("PRIVMSG {0} :{1}", response[0], message));
                                        writer.Flush();
                                    }
                                }
                            }

                            else if(response[1].Contains("/me"))
                            {
                                //writer.WriteLine(string.Format("PRIVMSG {0} \x01ACACTION {1}\x01AC"), CHANNEL, response);
                                //writer.Flush();
                            }
                            else
                            {
                                writer.WriteLine(string.Format("PRIVMSG {0} :{1}", response[0], response[1]));
                                writer.Flush();
                            }
                        }
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Thread.Sleep(15000);
                string[] argv = { };
                Main(argv);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            TcpClient    irc;
            string       inputLine;
            StreamWriter writer;
            StreamReader reader;

            string[]      splitInput;
            ChatHandler   handler = new ChatHandler();
            PingSender    pingSender;
            List <string> response;

            try
            {
                //Connecting to IRC server and channel
                irc        = new TcpClient(SERVER, PORT);
                stream     = irc.GetStream();
                reader     = new StreamReader(stream);
                writer     = new StreamWriter(stream);
                pingSender = new PingSender();
                writer.WriteLine("NICK " + NICK);
                writer.Flush();
                writer.WriteLine(USER);
                writer.Flush();
                writer.WriteLine("JOIN " + CHANNEL);
                writer.Flush();
                pingSender.Start();

                while (true)
                {
                    while ((inputLine = reader.ReadLine()) != null)
                    {
                        splitInput = inputLine.Split(new Char[] { ' ' });

                        if (splitInput[0] != "PONG")
                        {
                            Console.WriteLine(inputLine);
                        }

                        response = handler.Response(inputLine);
                        if (response != null)
                        {
                            if (response[1].Contains("\n"))
                            {
                                string[] multiLineResponse = response[1].Split(new Char[] { '\n' });

                                foreach (string message in multiLineResponse)
                                {
                                    if (message.Contains("/me"))
                                    {
                                    }
                                    else
                                    {
                                        writer.WriteLine(string.Format("PRIVMSG {0} :{1}", response[0], message));
                                        writer.Flush();
                                    }
                                }
                            }

                            else if (response[1].Contains("/me"))
                            {
                                //writer.WriteLine(string.Format("PRIVMSG {0} \x01ACACTION {1}\x01AC"), CHANNEL, response);
                                //writer.Flush();
                            }
                            else
                            {
                                writer.WriteLine(string.Format("PRIVMSG {0} :{1}", response[0], response[1]));
                                writer.Flush();
                            }
                        }
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Thread.Sleep(15000);
                string[] argv = { };
                Main(argv);
            }
        }