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GAAW,WAAW,EAAS,OACjD,QAAQ,MAAM,SACR,YAAY,EAAS,SACd,mBAAmB,EAAS,EAAa,EACxD,CACF,CAEA,MAAM,qBACJ,WAAA,CAAa,EAAM,EAAS,GAC1B,KAAK,KAAO,GAAQ,IACpB,KAAK,QAAU,EACf,KAAK,QAAU,EACf,QAAQ,oBAAoB,KAC9B,CAEA,uBAAM,CAAmB,EAAU,KAIjC,OAHA,KAAK,mBAAqB,mBAAmB,KAAK,QAAS,EAAS,KAAK,SACzE,KAAK,aAAa,KAAO,IAAM,KAAK,OACpC,KAAK,aAAa,GAAG,QAAQ,KAAQ,KAAK,aAAe,QAClD,KAAK,YACd,CAEA,UAAM,GACJ,OAAO,IAAI,SAAS,IACd,KAAK,cACP,KAAK,aAAa,GAAG,OAAQ,GAC7B,KAAK,aAAa,MAAM,MAAM,UAC9B,YAAW,KACT,KAAK,aAAa,OAClB,KAAK,aAAe,OACnB,MAEH,GACF,GAEJ,EAGF,eAAe,QAAS,EAAS,GAC/B,MAAM,QAAW,eAAe,EAAS,GAAW,CAAC,GACrD,OAAO,IAAI,qBAAqB,EAAG,KAAM,EAAG,QAAS,GAAW,CAAC,EACnE,CAEA,OAAO,QAAU,CAAE,oCAAmB,8BAAgB,wBAAa,sCAAoB,wCAAqB","file":"/npm/minecraft-bedrock-server@1.5.1/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/minecraft-bedrock-server@1.5.1/src/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","const http = require('https')\nconst fs = require('fs')\nconst cp = require('child_process')\nconst debug = process.env.CI ? console.debug : require('debug')('minecraft-bedrock-server')\nconst https = require('https')\nconst helpers = require('./helper')\n\nconst serversJsonURL = 'https://net-secondary.web.minecraft-services.net/api/v1.0/download/links'\n\nfunction head (url) {\n  return new Promise((resolve, reject) => {\n    const req = http.request(url, { method: 'HEAD', timeout: 1000 }, resolve)\n    req.on('error', reject)\n    req.on('timeout', () => { req.destroy(); debug('HEAD request timeout'); reject(new Error('timeout')) })\n    req.end()\n  })\n}\n\nfunction get (url, outPath) {\n  const file = fs.createWriteStream(outPath)\n  return new Promise((resolve, reject) => {\n    https.get(url, { timeout: 1000 * 20 }, response => {\n      if (response.statusCode !== 200) return reject(new Error('Server returned code ' + response.statusCode))\n      response.pipe(file)\n      file.on('finish', () => {\n        file.close()\n        resolve()\n      })\n    })\n  })\n}\n\nasync function getLatestVersions () {\n  const json = await fetch(serversJsonURL).then(res => res.json())\n  const links = json.result.links\n\n  function forOS (os) {\n    const entry = links.find(link => link.downloadType === os)\n    if (!entry) return null\n    const url = entry.downloadUrl\n    const version4 = url.match(/bedrock-server-(\\d+\\.\\d+\\.\\d+\\.\\d+)\\.zip/)[1]\n    const version3 = version4.split('.').slice(0, 3).join('.')\n    return { version4, version3, url }\n  }\n\n  return {\n    linux: forOS('serverBedrockLinux'),\n    windows: forOS('serverBedrockWindows'),\n    macos: forOS('serverBedrockMacOS'),\n    preview: {\n      linux: forOS('serverBedrockPreviewLinux'),\n      windows: forOS('serverBedrockPreviewWindows'),\n      macos: forOS('serverBedrockPreviewMacOS')\n    }\n  }\n}\n\nlet downloadLock = false\n\n// Download + extract vanilla server and enter the directory\nasync function download (os, version, root, path) {\n  if (downloadLock) {\n    throw Error('Already downloading server')\n  }\n  downloadLock = true\n  process.chdir(root)\n  if (version.split('.').length < 3) {\n    throw new Error('minecraft-bedrock-server: A version string should contain at least 3 dots on Minecraft Bedrock Edition. Please add a .0 suffix: ' + version)\n  }\n  const verStr = version.split('.').slice(0, 3).join('.')\n  const dir = path || 'bds-' + version\n\n  if (fs.existsSync(dir) && fs.readdirSync(dir).length > 1) {\n    process.chdir(dir) // Enter server folder\n    debug('Already downloaded', version)\n    downloadLock = false\n    return { version: verStr, path: process.cwd() }\n  }\n  try { fs.mkdirSync(dir) } catch { }\n\n  process.chdir(dir) // Enter server folder\n  const url = (os, version) => `https://www.minecraft.net/bedrockdedicatedserver/bin-${os}/bedrock-server-${version}.zip`\n\n  let found = false\n\n  // Find the latest server build for version (major.minor.patch.BUILD)\n  const toTry = []\n  for (let i = 0; i < 10; i++) toTry.push(String(i))\n  for (let i = 0; i < 20; i++) toTry.push(String(i).padStart(2, '0'))\n\n  for (const build of toTry) {\n    const u = url(os, `${verStr}.${build}`)\n    debug('Opening', u, Date.now())\n    let ret\n    try { ret = await head(u) } catch (e) { continue }\n    if (ret.statusCode === 200) {\n      found = u\n      debug('Found server', ret.statusCode)\n      break\n    }\n  }\n  if (!found) throw Error('did not find server bin for ' + os + ' ' + version)\n  console.info('🔻 Downloading', found)\n  await get(found, 'bds.zip')\n  console.info('⚡ Unzipping')\n  // Unzip server\n  if (process.platform === 'linux') cp.execSync('unzip -u bds.zip')\n  else cp.execSync('tar -xf bds.zip')\n  downloadLock = false\n  return { version: verStr, path: process.cwd() }\n}\n\nfunction eraseServer (version, options) {\n  downloadLock = false\n  // Remove the server and try again\n  const currentDir = process.cwd()\n  process.chdir(options.root || '.')\n  const path = options.path ? options.path : 'bds-' + version\n  debug('Removing server', path)\n  fs.rmSync(path, { recursive: true, force: true })\n  process.chdir(currentDir)\n}\n\nconst defaultOptions = {\n  'level-generator': '2',\n  'server-port': '19130',\n  'online-mode': 'false'\n}\nconst internalOptions = ['path', 'root']\n\n// Setup the server\nfunction configure (options = {}) {\n  const opts = { ...defaultOptions, ...options }\n  let config = fs.readFileSync('./server.properties', 'utf-8')\n  config = config.split('## node options')[0].trim()\n  config += '\\n## node options'\n  config += '\\nplayer-idle-timeout=1\\nallow-cheats=true\\ndefault-player-permission-level=operator'\n  for (const o in opts) {\n    if (internalOptions.includes(o)) continue\n    config += `\\n${o}=${opts[o]}`\n  }\n  fs.writeFileSync('./server.properties', config)\n  if (process.platform === 'linux') {\n    cp.execSync('chmod +777 ./bedrock_server')\n  }\n}\n\nfunction run (inheritStdout = true) {\n  const exe = process.platform === 'win32' ? 'bedrock_server.exe' : './bedrock_server'\n  return cp.spawn(exe, inheritStdout ? { stdio: 'inherit' } : {})\n}\n\nasync function downloadServer (version, options) {\n  const platFix = {\n    win32: 'win',\n    windows: 'win',\n    linux: 'linux',\n    macos: 'darwin'\n  }\n  if (options.platform && !platFix[options.platform]) {\n    throw new Error('Unsupported specified platform: ' + options.platform)\n  }\n  const platform = options.platform || process.platform\n  const serverOs = platFix[platform] || 'linux'\n  const currentDir = process.cwd()\n  try {\n    const ret = await download(serverOs, version, options.root || '.', options.path)\n    return ret\n  } finally {\n    process.chdir(currentDir)\n    downloadLock = false\n  }\n}\n\nlet lastHandle\n\n// Run the server\nasync function startServer (version, onStart, options = {}) {\n  const os = process.platform === 'win32' ? 'win' : process.platform\n  if (os !== 'win' && os !== 'linux') {\n    throw Error('unsupported os ' + os)\n  }\n\n  const currentDir = process.cwd()\n  // Take the options.path and determine if it's an absolute path or not\n  const path = options.path\n  const pathRoot = options.root || '.'\n\n  let ver\n  try {\n    ver = await download(os, version, pathRoot, path) // and enter the directory\n  } finally {\n    downloadLock = false\n  }\n  debug('Configuring server', ver.version)\n  configure(options)\n  debug('Starting server', ver.version)\n  const handle = lastHandle = run(!onStart)\n  handle.on('error', (...a) => {\n    console.warn('*** THE MINECRAFT PROCESS CRASHED ***', a)\n    handle.kill('SIGKILL')\n  })\n  if (onStart) {\n    let stdout = ''\n    function processLine (data) {\n      stdout += data\n      if (stdout.includes('Server started')) {\n        onStart()\n        handle.stdout.off('data', processLine)\n      }\n    }\n    handle.stdout.on('data', processLine)\n    handle.stdout.pipe(process.stdout)\n    handle.stderr.pipe(process.stdout)\n  }\n  process.chdir(currentDir)\n  return handle\n}\n\n// Start the server and wait for it to be ready, with a timeout\nfunction startServerAndWait (version, withTimeout, options) {\n  if (isNaN(withTimeout)) throw Error('timeout must be a number')\n  let handle\n  return new Promise((resolve, reject) => {\n    const timeout = setTimeout(() => {\n      handle?.kill()\n      reject(new Error(`Server did not start on time (${withTimeout}ms, now ${Date.now()})`))\n    }, withTimeout)\n\n    startServer(version, function onReady () {\n      clearTimeout(timeout)\n      resolve(handle)\n    }, options).then((h) => {\n      handle = h\n    }).catch(reject)\n  })\n}\n\n// Start the server and wait for it to be ready, with a timeout, and retry once\nasync function startServerAndWait2 (version, withTimeout, options) {\n  const currentDir = process.cwd()\n  try {\n    return await startServerAndWait(version, withTimeout, options)\n  } catch (e) {\n    console.log(e)\n    console.log('^ Trying once more to start server in 10 seconds...')\n    lastHandle?.kill()\n    await new Promise(resolve => setTimeout(resolve, 10000))\n    process.chdir(currentDir) // We can't call eraseServer being inside the server directory\n    await eraseServer(version, options)\n    return await startServerAndWait(version, withTimeout, options)\n  }\n}\n\nclass BedrockVanillaServer {\n  constructor (path, version, options) {\n    this.path = path || '.'\n    this.version = version\n    this.options = options\n    helpers.injectServerHelpers(this)\n  }\n\n  async startAndWaitReady (timeout = 1000 * 60 * 5) {\n    this.activeHandle = await startServerAndWait(this.version, timeout, this.options)\n    this.activeHandle.stop = () => this.stop()\n    this.activeHandle.on('exit', () => { this.activeHandle = null })\n    return this.activeHandle\n  }\n\n  async stop () {\n    return new Promise((resolve) => {\n      if (this.activeHandle) {\n        this.activeHandle.on('exit', resolve)\n        this.activeHandle.stdin.write('stop\\n')\n        setTimeout(() => {\n          this.activeHandle.kill()\n          this.activeHandle = null\n        }, 1000)\n      } else {\n        resolve()\n      }\n    })\n  }\n}\n\nasync function prepare (version, options) {\n  const dl = await downloadServer(version, options || {})\n  return new BedrockVanillaServer(dl.path, dl.version, options || {})\n}\n\nmodule.exports = { getLatestVersions, downloadServer, startServer, startServerAndWait, startServerAndWait2, prepare }\n"]}