Beispiel #1
0
        static void Main(string[] args)
        {
            IApplicationContext context = new XmlApplicationContext("IrcBot-applicationContext.xml");

            XmlConfigurator.Configure(new System.IO.FileInfo("log4net.xml"));

            botResponders = (List <Responder>)context.GetObject("responderList");
            pollers       = (List <Poller>)context.GetObject("pollerList");
            managers      = (Dictionary <String, AbstractManager>)context.GetObject("managers");
            connection    = ((IrcConnectionManager)getManager(IrcConnectionManager.MANAGER_NAME)).connection;
            CHANNEL       = (String)context.GetObject("IrcChannel");

            NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
            config.Configure();
            config.AddAssembly(typeof(User).Assembly);
            ISessionFactory sessionFactory = config.BuildSessionFactory();

            //var schema = new SchemaExport(config);
            //schema.Create(true, true);
            mySession = sessionFactory.OpenSession();
            List <User> savedUsers = (List <User>)mySession.CreateCriteria <User>().List <User>();

            users.AddRange(savedUsers);

            //Start pollers

            //set the channel and connection objects.
            foreach (Poller poller in pollers)
            {
                poller.connection = connection;
                poller.channel    = CHANNEL;
            }
            pollerManager = new PollerManager(pollers);


            log.Debug("Starting Skill Enumeration");
            skillList = getSkillList();
            foreach (SkillTree.Skill skill in skillList)
            {
                try
                {
                    skillIds.Add(skill.TypeName.ToLower(), skill.TypeId);
                }
                catch (ArgumentException ae)
                {
                    log.Warn("Argument exception: " + ae.Message);
                }
            }

            foreach (User user in users)
            {
                log.Debug("Adding user " + user.userName);
                nickDict.Add(user.userName, user);
            }
            string inputLine;

            while (true)
            {
                try {
                    PingSender ping = new PingSender(connection);
                    ping.setServer(connection.server);
                    ping.start();

                    ActionThread actionThread = new ActionThread();
                    actionThread.start();

                    connection.joinChannel(CHANNEL);

                    connection.privmsg(CHANNEL, "Reporting for duty!");
                    ArrayList results = new ArrayList();

                    while (true)
                    {
                        while ((inputLine = connection.ReadLine()) != null)
                        {
                            inputQueue.Enqueue(inputLine);
                        }
                    }
                }
                catch (Exception e) {
                    log.Error("Caught exception in operation: " + e.Message);
                    Thread.Sleep(5000);

                    string[] argv = { };
                }
            }
        }
Beispiel #2
0
 public PingSender(IrcConnection connection)
 {
     this.connection = connection;
     pingSender      = new Thread(new ThreadStart(this.run));
 }