Example #1
0
        public void IRCBot(BackgroundWorker bw)
        {
            if (restart == true)
            {
                Thread.Sleep(Convert.ToInt32(Math.Pow(2, Convert.ToDouble(restart_attempts))) * 1000);
            }
            restart = false;
            config = conf;
            try
            {
                connected = true;
                connecting = false;
                IRCConnection = new TcpClient(conf.server, conf.port);
            }
            catch (Exception ex)
            {
                restart = true;
                restart_attempts++;
                connected = false;
                connecting = false;

                lock (ircbot.errorlock)
                {
                    ircbot.log_error(ex);
                }
            }

            if (restart == false)
            {
                try
                {
                    ns = IRCConnection.GetStream();
                    sr = new StreamReader(ns);
                    sw = new StreamWriter(ns);
                    sw.AutoFlush = true;
                    if (conf.pass != "")
                    {
                        sendData("PASS", config.pass);
                    }
                    if (conf.email != "")
                    {
                        sendData("USER", config.nick + " " + conf.email + " " + conf.email + " :" + config.name);
                    }
                    else
                    {
                        sendData("USER", config.nick + " default_host default_server :" + config.name);
                    }

                    IRCWork(bw);
                }
                catch (Exception ex)
                {
                    restart = true;
                    restart_attempts++;

                    lock (ircbot.errorlock)
                    {
                        ircbot.log_error(ex);
                    }
                }
                finally
                {
                    connecting = false;
                    connected = false;
                    if (sr != null)
                        sr.Close();
                    if (sw != null)
                        sw.Close();
                    if (ns != null)
                        ns.Close();
                    if (IRCConnection != null)
                        IRCConnection.Close();
                }
            }
        }
Example #2
0
 public IRCBot(IRCConfig config)
 {
     this.config = config;
 }
Example #3
0
        public void start_bot(Interface main, IRCConfig tmp_conf)
        {
            connecting = true;
            start_time = DateTime.Now;
            ircbot = main;
            conf = tmp_conf;
            string[] tmp_server = conf.server.Split('.');
            if (tmp_server.GetUpperBound(0) > 0)
            {
                server_name = tmp_server[1];
            }
            full_server_name = conf.server;
            cur_dir = ircbot.cur_dir;

            load_modules();

            Spam_Check_Timer.Tick += new EventHandler(spam_tick);
            Spam_Check_Timer.Interval = conf.spam_threshold;
            Spam_Check_Timer.Start();

            Spam_Threshold_Check.Tick += new EventHandler(spam_check);
            Spam_Threshold_Check.Interval = 100;
            Spam_Threshold_Check.Start();

            checkRegisterationTimer.Tick += new EventHandler(checkRegistration);
            checkRegisterationTimer.Interval = 120000;
            checkRegisterationTimer.Enabled = true;

            check_cancel.Tick += new EventHandler(cancel_tick);
            check_cancel.Interval = 500;
            check_cancel.Start();

            BackgroundWorker work = new BackgroundWorker();
            work.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
            work.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
            work.WorkerSupportsCancellation = true;

            worker = work;
            worker.RunWorkerAsync(2000);
        }
Example #4
0
 private static void Main(string[] args)
 {
     IRCConfig conf = new IRCConfig();
     conf.name = "DrPepper";
     conf.nick = "DrPepper";
     conf.port = 6667;
     conf.channel = "#downfall";
     conf.server = "irc.quakenet.org";
     using (var bot = new IRCBot(conf))
     {
         conf.joined = false;
         bot.Connect();
         bot.IRCWork();
     }
     Console.WriteLine("Bot quit/crashed");
     Console.ReadLine();
 }