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Q,SAAS,GAC/C,OAAI,SACS,EAAQ,QAAQ,EACjC,CAAE,MAAO,GAEL,OADA,KAAK,OAAO,MAAM,6BAA6B,QAAoB,EAAI,SAChE,2CACX,CACJ","file":"/npm/@ecurrah/valheim-manager@1.0.12/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@ecurrah/valheim-manager@1.0.12/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\r\nrequire('./src/types/typedef');\r\n\r\nconst path = require('path');\r\nconst fs = require('fs-extra');\r\nconst Logger = require('chegs-simple-logger');\r\n\r\nconst Backups = require('./src/backups');\r\nconst Discord = require('./src/discord');\r\nconst Installer = require('./src/installer');\r\nconst Launcher = require('./src/launcher');\r\nconst System = require('./src/system');\r\nconst ValFiles = require('./src/valheimFiles');\r\nconst defConfig = require('./src/types/defaultConfig');\r\n\r\nmodule.exports = class ValheimManager {\r\n\r\n    /** @param {Configuration} config - The configuration for the manager */\r\n    constructor(config) {\r\n\r\n        // Validate the configuration file\r\n        const configValidation = validateConfiguration(config);\r\n        if (configValidation !== 'ok') throw new Error(configValidation);\r\n\r\n        // Check operating system and add to the config\r\n        const os = process.platform; \r\n        if (os !== 'win32' && os !== 'linux') {\r\n            let error = `This operating system, ${os}, is not supported!\\n`;\r\n            error += `You can set manager.operatingSystem to either win32 or linux to ignore this warning.`;\r\n            if (!config.manager.operatingSystem) throw new Error(error);\r\n        } else {\r\n            config.manager.operatingSystem = os;\r\n        }\r\n\r\n        // Create instances of all tools and dependencies\r\n        this.config = config;\r\n        this.validateConfig = validateConfiguration;\r\n        this.logger = new Logger(config.logging);\r\n        this.backups = new Backups(this);\r\n        this.installer = new Installer(this);\r\n        this.launcher = new Launcher(this);\r\n        this.system = new System(this);\r\n        this.valFiles = new ValFiles(this);\r\n        this.discord = new Discord(this);\r\n\r\n        // Prepare the commands\r\n        /**@type {Map<String, Command>} */\r\n        this.commands = new Map();\r\n        const commandsPath = path.resolve(__dirname, './src/commands/');\r\n        for (const file of fs.readdirSync(commandsPath)) {\r\n            if (file == 'command.js' || !file.endsWith('.js') || file.startsWith('old_')) continue;\r\n            const commandPath = path.join(commandsPath, file);\r\n            const command = new (require(commandPath))(this);\r\n            this.commands.set(command.name, command);\r\n        }\r\n\r\n        // Monitor for SIGINT and stop server\r\n        const manager = this;\r\n        process.on('SIGINT', async function() {\r\n            manager.logger.general('Signal interrupt detected');\r\n            await manager.launcher.stopValheim();\r\n            process.exit();\r\n        });\r\n    }\r\n\r\n    \r\n    /**\r\n     * Processes a user executed command\r\n     * @param {String} commandString - The command including arguments\r\n     * @param {Function<String>} update - A callback function for providing updates in case of long execution time \r\n     * @returns {String} a user ready result from the command execution\r\n     */\r\n    async execute(commandString, update) {\r\n\r\n        // Validate the command string and break it down to its components\r\n        if (!commandString || typeof(commandString) != 'string') throw new Error('Execute expects a command string as the first argument.');\r\n        const args = commandString.split(' ');\r\n        const commandName = args.shift();\r\n\r\n        // If this is a request for the command list, display all available commands\r\n        if (commandName && commandName.toLowerCase() == 'command-list') {\r\n            let list = '\\n== COMMAND NAME == == DESCRIPTION ==';\r\n            for (const command of this.commands.values()) list += `\\n ${command.name} - ${command.description}`;\r\n            return list;\r\n        }\r\n\r\n        // Identify the command being called \r\n        const command = this.commands.get(commandName);\r\n        if (!command) return `${commandName} is not a valid command. Try command-list.`;\r\n\r\n        // Validate and execute the command\r\n        try {\r\n            if (update && command.acknowledgment) update(command.acknowledgment);\r\n            const validationError = await command.validate(args);\r\n            if (validationError) return validationError;\r\n            return await command.execute(args);\r\n        } catch (err) {\r\n            this.logger.error(`Error executing command - ${commandString}. \\n${err.stack}`);\r\n            return 'There was an error executing this command';\r\n        }\r\n    }\r\n    \r\n}\r\n\r\n/**\r\n * Synchronous / thread blocking validation of the config which can be used in the modules constructor.\r\n * @param {Configuration} config - The user provided configuration to be validated.\r\n * @returns {String} - A fully detailed error message to help an average user troubleshoot, or \"ok\".\r\n */\r\nfunction validateConfiguration(config) {\r\n    const errors = [];\r\n\r\n    // Validate the main components are present\r\n    if (!config.manager) errors.push('The manager portion of this config is missing. Maybe this is not a config file?');\r\n    if (!config.launcher) errors.push('The launcher portion of this config is missing.');\r\n    if (!config.logging) errors.push('The logging portion of this config is missing.');\r\n    if (!config.discord) errors.push('The discord portion of this config is missing.');\r\n    if (errors.length > 0) return errors.join('\\n');\r\n\r\n    // Validate the existence and types of required properties\r\n    const ignoreProperties = ['operatingSystem'];\r\n    for (const component of ['manager', 'launcher', 'discord', 'logging']) {\r\n        for (const [key, value] of Object.entries(defConfig[component])) {\r\n            if (ignoreProperties.includes(key)) continue;\r\n            if (config[component][key] == undefined) {\r\n                errors.push(`The ${component}.${key} property is required but does not seem to exist.`);\r\n            } else {\r\n                const propType = typeof(config[component][key]);\r\n                const expectedType = typeof(value);\r\n                if (propType != expectedType) {\r\n                    errors.push(`The ${component}.${key} property is expected to be a ${expectedType}. It is currently ${config[component][key]}(${propType}).`);\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    // Validate the parent directory is accessible. Create the child directory if needed. \r\n    const validatePaths = [config.manager.configLocation, config.manager.serverLocation];\r\n    if (config.logging.writeLog) validatePaths.push(config.logging.filePath);\r\n    for (const location of validatePaths) {\r\n        const fullPath = path.resolve(location);\r\n        const parentPath = path.dirname(fullPath);\r\n        if (!fs.existsSync(parentPath)) {\r\n            errors.push(`The path ${parentPath} is not accessible.`);\r\n            continue;\r\n        } \r\n        if (!fs.existsSync(fullPath)) {\r\n            const creationMethod = fullPath.includes('.') ? fs.createFileSync : fs.mkdirSync;\r\n            creationMethod(fullPath);\r\n        } \r\n    }\r\n\r\n    // Check for spaces in the server path\r\n    if (config.manager.serverLocation.includes(' ')) {\r\n        const noSpaces = config.manager.serverLocation.replace(' ', '-');\r\n        errors.push(`Steam does not work with spaces in file paths.\\n  Current Path: ${config.manager.serverLocation}\\n Recommended change: ${noSpaces}`);\r\n    }\r\n\r\n    // Validate the specifics of some property values\r\n    if (config.manager.backupFrequency < 0) errors.push('The backup frequency should be greater than 0.');\r\n    if (config.manager.backupRetention < 0) errors.push('The backup retention should be greater than 0.');\r\n    if (config.launcher.port < 1024 || config.launcher.port > 65535) errors.push('The port should be between 1024 and 65535.');\r\n    if (config.logging.writeLog) {\r\n        if (!config.logging.fileSize.match(/[BKMG]$/)) errors.push('The logging file size should end with B, K, M, or G. This letters represent the byte measurement options.');\r\n        if (config.logging.fileAge < 0) errors.push('The logging file age should be more than 0 days.');\r\n        if (config.logging.fileCount < 0) errors.push('The logging file max count should be more than 0.');\r\n    }\r\n    if (config.discord.token != '') {\r\n        let discordIdMinLength = 17;\r\n        let discordIdMaxLength = 19;\r\n        if (config.discord.token.length < 20) errors.push('The discord token should be longer.');\r\n        if (config.discord.serverId.length < discordIdMinLength || config.discord.serverId.length > discordIdMaxLength) errors.push(`The discord server id should be between ${discordIdMinLength} and ${discordIdMaxLength} characters long (inclusive).`);\r\n        if (config.discord.adminRoleId.length < discordIdMinLength || config.discord.serverId.length > discordIdMaxLength) errors.push(`The discord admin role id should be between ${discordIdMinLength} and ${discordIdMaxLength} characters long (inclusive).`);\r\n        if (config.discord.serverLogChannel.length < discordIdMinLength || config.discord.serverId.length > discordIdMaxLength) errors.push(`The discord server log channel id should be between ${discordIdMinLength} and ${discordIdMaxLength} characters long (inclusive).`);\r\n        if (config.discord.commandLogChannel.length < discordIdMinLength || config.discord.commandLogChannel.length > discordIdMaxLength) errors.push(`The discord command log channel id should be between ${discordIdMinLength} and ${discordIdMaxLength} characters long (inclusive).`);\r\n    }\r\n\r\n    if (errors.length > 0) return errors.join('\\n');\r\n    return 'ok';\r\n}"]}