예제 #1
0
        public static void Main(string[] args)
        {
            try {
                connections = new List <IrcConnection>();
                threads     = new List <Thread>();

                config = LumbricusConfiguration.GetConfig();

                logger.Info("Lumbricus v{0}", CoreAssembly.Version);
                logger.Info("==========={0}\n", new String('=', CoreAssembly.Version.ToString().Length));

                Initialise();

                while (threads.Count > 0)
                {
                    foreach (Thread thread in threads)
                    {
                        if (!thread.IsAlive)
                        {
                            threads.Remove(thread);
                        }
                    }
                    Thread.Sleep(1000);
                }

                LumbricusContext.Obliterate();

                logger.Info("All connections closed, threads finished. BAIBAI! :D");
            } catch (Exception e) {
                logger.Fatal(e);
            }
        }
예제 #2
0
        public static void Initialise()
        {
            InitialisePlugins(config);

            LumbricusContext.Initialise(config);

            logger.Debug("Initialising server connections");
            var servers = Server.Fetch();

            foreach (Server server in servers)
            {
                IrcConnection conn = new IrcConnection(server, config);
                connections.Add(conn);
            }

            foreach (IrcConnection conn in connections)
            {
                var channels = Channel.Fetch(conn.Server);
                conn.Server.SetChannels(channels.ToList());
            }

            logger.Debug("Starting connections");
            foreach (IrcConnection conn in connections)
            {
                Thread t = new Thread(() => RunThread(conn));
                t.Start();

                threads.Add(t);
            }
        }
예제 #3
0
        public static void Main(string[] args)
        {
            if (args.Length < 3 || args.Length > 4)
            {
                DoUsage();
            }

            try {
                type = args[0].ToEnum <LogType>();
            } catch (Exception e) {
                logger.Error(e);
                DoUsage(string.Format("Invalid log type `{0}`", args[0]));
            }
            switch (type)
            {
            case LogType.znc:
                if (args.Length < 4)
                {
                    DoUsage("Date in YYYY-MM-DD format is required for ZNC logs.");
                }
                break;

            case LogType.irssi:
                break;

            default:
                DoUsage(string.Format("Invalid type `{0}`", type));
                break;
            }

            long channelId = Int64.Parse(args[1]);

            if (channelId < 1)
            {
                DoUsage(string.Format("Invalid channel id `{0}`; must be > 0", args[1]));
            }

            config = LumbricusConfiguration.GetConfig();
            LumbricusContext.Initialise(config);

            channel = Channel.Fetch(channelId);
            if (channel == null)
            {
                DoUsage(string.Format("Channel id `{0}` does not exist.", channelId));
            }
            server = channel.Server;
            if (server == null)
            {
                throw new Exception(string.Format("Channel `{0}` is linked to a server id which does not exist or is deleted.", channelId));
            }

            string filename = args[2];

            if (string.IsNullOrWhiteSpace(filename))
            {
                DoUsage(string.Format("Invalid filename `{0}`", args[2]));
            }
            else if (!File.Exists(filename))
            {
                DoUsage(string.Format("File `{0}` does not exist", filename));
            }

            date = null;
            if (args.Length == 4 && !string.IsNullOrWhiteSpace(args[3]))
            {
                try {
                    date = DateTime.Parse(args[3]);
                } catch (Exception e) {
                    logger.Error(e);
                    DoUsage(string.Format("Invalid date `{0}`", args[3]));
                }
            }

            int i = 0;

            foreach (string line in File.ReadLines(filename))
            {
                ProcessLine(line);

                if (i % 100 == 0)
                {
                    Console.Write(".");
                }
                i++;
            }

            logger.Info("Done.");
        }