示例#1
0
        // -------- Functions --------

        /// <summary>
        /// Inits this plugin.
        /// </summary>
        /// <param name="pluginPath">Path to the plugin DLL</param>
        /// <param name="ircConfig">The IRC config being used.</param>
        public void Init(string pluginPath, IIrcConfig ircConfig)
        {
            ArgumentChecker.StringIsNotNullOrEmpty(pluginPath, nameof(pluginPath));
            ArgumentChecker.IsNotNull(ircConfig, nameof(ircConfig));

            string configPath = Path.Combine(
                Path.GetDirectoryName(pluginPath),
                "ServerDiagnosticsConfig.xml"
                );

            ServerDiagnosticsConfig config = XmlLoader.LoadConfig(configPath);

            if (string.IsNullOrEmpty(config.UpTimeCmd) == false)
            {
                MessageHandler utimeHandler = new MessageHandler(
                    config.UpTimeCmd.Replace("{%nick%}", ircConfig.Nick),
                    HandleUpTimeCmd,
                    coolDown
                    );
                this.handlerList.Add(utimeHandler);
            }

            if (string.IsNullOrEmpty(config.OsVersionCmd) == false)
            {
                MessageHandler osHandler = new MessageHandler(
                    config.OsVersionCmd.Replace("{%nick%}", ircConfig.Nick),
                    HandleOsVersionCmd,
                    coolDown
                    );
                this.handlerList.Add(osHandler);
            }

            if (string.IsNullOrEmpty(config.ProcessorCountCmd) == false)
            {
                MessageHandler procCoundHandler = new MessageHandler(
                    config.ProcessorCountCmd.Replace("{%nick%}", ircConfig.Nick),
                    HandleProcessorCountCmd,
                    coolDown
                    );
                this.handlerList.Add(procCoundHandler);
            }

            if (string.IsNullOrEmpty(config.TimeCmd) == false)
            {
                MessageHandler timeHandler = new MessageHandler(
                    config.TimeCmd.Replace("{%nick%}", ircConfig.Nick),
                    HandleTimeCmd,
                    coolDown
                    );
                this.handlerList.Add(timeHandler);
            }
        }
示例#2
0
        // -------- Functions --------

        /// <summary>
        /// Loads the server diagnostics config from the
        /// given XML file.
        /// </summary>
        /// <param name="xmlFilePath">The path to the xml file.</param>
        /// <exception cref="XmlException">If the XML is not correct</exception>
        /// <returns>The server diagnostics config from the XML file.</returns>
        public static ServerDiagnosticsConfig LoadConfig(string xmlFilePath)
        {
            if (File.Exists(xmlFilePath) == false)
            {
                throw new FileNotFoundException("Could not find server diagnostics plugin config file " + xmlFilePath);
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(xmlFilePath);

            XmlElement rootNode = doc.DocumentElement;

            if (rootNode.Name != rootNodeName)
            {
                throw new XmlException(
                          "Root XML node should be named \"" + rootNodeName + "\".  Got: " + rootNode.Name
                          );
            }

            ServerDiagnosticsConfig config = new ServerDiagnosticsConfig();

            foreach (XmlNode childNode in rootNode.ChildNodes)
            {
                switch (childNode.Name)
                {
                case "utimecmd":
                    config.UpTimeCmd = childNode.InnerText;
                    break;

                case "osverscmd":
                    config.OsVersionCmd = childNode.InnerText;
                    break;

                case "proccountcmd":
                    config.ProcessorCountCmd = childNode.InnerText;
                    break;

                case "timecmd":
                    config.TimeCmd = childNode.InnerText;
                    break;
                }
            }

            return(config);
        }
示例#3
0
        // -------- Functions --------

        /// <summary>
        /// Inits this plugin.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            string configPath = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "ServerDiagnostics",
                "ServerDiagnosticsConfig.xml"
                );

            this.config    = XmlLoader.LoadConfig(configPath);
            this.ircConfig = initor.IrcConfig;

            if (string.IsNullOrEmpty(config.UpTimeCmd) == false)
            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = config.UpTimeCmd,
                    LineAction = HandleUpTimeCmd,
                    CoolDown   = coolDown
                };

                MessageHandler utimeHandler = new MessageHandler(
                    msgConfig
                    );
                this.handlerList.Add(utimeHandler);
            }

            if (string.IsNullOrEmpty(config.OsVersionCmd) == false)
            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = config.OsVersionCmd,
                    LineAction = HandleOsVersionCmd,
                    CoolDown   = coolDown
                };

                MessageHandler osHandler = new MessageHandler(
                    msgConfig
                    );
                this.handlerList.Add(osHandler);
            }

            if (string.IsNullOrEmpty(config.ProcessorCountCmd) == false)
            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = config.ProcessorCountCmd,
                    LineAction = HandleProcessorCountCmd,
                    CoolDown   = coolDown
                };

                MessageHandler procCoundHandler = new MessageHandler(
                    msgConfig
                    );
                this.handlerList.Add(procCoundHandler);
            }

            if (string.IsNullOrEmpty(config.TimeCmd) == false)
            {
                MessageHandlerConfig msgConfig = new MessageHandlerConfig
                {
                    LineRegex  = config.TimeCmd,
                    LineAction = HandleTimeCmd,
                    CoolDown   = coolDown
                };

                MessageHandler timeHandler = new MessageHandler(
                    msgConfig
                    );
                this.handlerList.Add(timeHandler);
            }
        }