All pastes #934565 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-03-08 22:41 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;

namespace XenuBot
{
    class Program
    {
        public static string SERVER = "irc.gamesurge.net";
        public static int PORT = 6667;
        public static string USERSTR = "";
        public static string NICK = "XenuBot";

        public const int FloodTime=500;

        //public static string CHANNEL="#luahelp";

        public static StreamWriter sWriter;
        public static StreamReader sReader;

        public static PingSender pingr;

        public enum BotModes
        {
            Radio,
            ServerQuery
        }
        public static bool[] Modes = {false,true};


        public static string[] BadWords ={""};
        public static string[] CHANNELS ={ "#luahelp" };

        static void Init()
        {
            sWriter.WriteLine("USER XenuBot 0 * :Heil Xenu!");
            sWriter.Flush();
            sWriter.WriteLine("MODE XenuBot +x");
            sWriter.Flush();
            foreach (string chan in CHANNELS)
            {
                sWriter.WriteLine("JOIN " + chan);
                sWriter.Flush();
            }

            pingr = new PingSender();
            pingr.Start();
        }

        static void DoProgram()
        {
          NetworkStream stream;
            TcpClient IRC;
            string inputline;

            //try
            //{
                IRC = new TcpClient(SERVER,PORT);
                stream=IRC.GetStream();
                sReader = new StreamReader(stream);
                sWriter = new StreamWriter(stream);

                bool SentInfo = false;

                sWriter.WriteLine("NICK " + NICK);
                sWriter.Flush();

                while (true)
                {
                    while ((inputline = sReader.ReadLine()) != null)
                    {
                        string[] command = new string[inputline.Split(' ').Length];
                        command = inputline.Split(' ');
                        if (command[0]=="PING")
                        {
                            sWriter.WriteLine("PONG " + command[1]);
                            Console.WriteLine("PONG " + command[1]);
                            if (!SentInfo)
                            {
                                Program.Init();
                                SentInfo = true;
                            }
                        }
                        if (command[1] == "KICK")
                        {
                            string CHANNEL = command[2];
                            string usr = command[3];

                            if (usr == NICK)
                            {
                                sWriter.WriteLine("JOIN " + CHANNEL);
                                sWriter.Flush();
                            }
                        }
                        if (command[1] == "PRIVMSG")
                        {
                            string CHANNEL = command[2];

                            if (CHANNEL == NICK)
                            {
                                string usr = inputline.Split('!')[0].Remove(0, 1);

                                if (command[3].StartsWith(":"+Convert.ToChar(1)+"VERSION"))
                                {
                                    sWriter.WriteLine("NOTICE " + usr + " :" + Convert.ToChar(1) + "XENUBOT (entirely) by Catdaemon - HEIL XENU!"+ Convert.ToChar(1));
                                    sWriter.Flush();
                                }
                                if (command[3].StartsWith(":" + Convert.ToChar(1) + "TIME"))
                                {
                                    sWriter.WriteLine("NOTICE " + usr + " :" + Convert.ToChar(1) + "TIME to release me and collect thetans!" + Convert.ToChar(1));
                                    sWriter.Flush();
                                }
                            }

                            if (command[3].Remove(0, 1) == "!set")
                            {
                                if (command[0] == ":Catdaemon`!catdaemon@enjoying.the.leet.speed.of.internet2.org.uk" && command.Length>4)
                                {
                                    short mode;
                                    if (Int16.TryParse(command[5], out mode))
                                    {
                                        switch (command[4])
                                        {
                                            case "radio":
                                                Modes[(int)BotModes.Radio] = mode == 1;
                                                break;
                                            case "query":
                                                Modes[(int)BotModes.ServerQuery] = mode == 1;
                                                break;
                                        }
                                    }
                                }
                            }

                            if (command[3].Remove(0, 1) == "!raw")
                            {
                                if (command[0] == ":Catdaemon`!catdaemon@enjoying.the.leet.speed.of.internet2.org.uk")
                                {
                                    string lstr = command[0] + " " + command[1] + " " + command[2] + " " + command[3];
                                    string msg = inputline.Remove(0, lstr.Length);
                                    sWriter.WriteLine(msg);
                                    sWriter.Flush();
                                }
                            }

                            if (command[3].Remove(0, 1) == "!shout" && Modes[(int)BotModes.Radio])
                            {
//
                            }
                            if (command[3].Remove(0, 1) == "!request" && Modes[(int)BotModes.Radio])
                            {
//
                            }

                            if (CHANNEL.StartsWith("#"))
                            {
                                string usr = inputline.Split('!')[0].Remove(0, 1);
                                foreach (string s in BadWords)
                                {
                                    if (inputline.ToLower().Contains(s))
                                    {
                                        sWriter.WriteLine("KICK " + CHANNEL + " " + usr + " " + s);
                                        sWriter.Flush();
                                        break;
                                    }
                                }
                                if (command[3].Remove(0, 1) == "!server" && Modes[(int)BotModes.ServerQuery])
                                {
                                    sWriter.WriteLine("PRIVMSG " + CHANNEL + " :Getting server info (may take a few seconds)...");
                                    sWriter.Flush();

                                    QuerySender query;
                                    IPAddress ip;
                                    short port;
                                    if (command.Length > 5)
                                    {
                                        if (IPAddress.TryParse(command[4], out ip) && Int16.TryParse(command[5], out port))
                                        {
                                            query = new QuerySender(ip, port,CHANNEL);
                                            new Thread(new ThreadStart(query.Run)).Start();
                                        }
                                        else
                                        {
                                            sWriter.WriteLine("PRIVMSG " + CHANNEL + " :Bad IP/port.");
                                            sWriter.Flush();
                                        }
                                    }
                                    else
                                    {
                                        query = new QuerySender(IPAddress.Parse("78.129.175.49"), 27075, CHANNEL);
                                        new Thread(new ThreadStart(query.Run)).Start();
                                    }

                                }

                            }
                        }
                        Console.WriteLine(inputline);
                    }
                }
                //}
            //catch (Exception e)
            //{
                //DoProgram();
            //}
        }

        static void Main(string[] args)
        {
            DoProgram();
        }
  
    }
}