diff --git a/atlastools/include/workshop.js b/atlastools/include/workshop.js index 1711973..c818a10 100644 --- a/atlastools/include/workshop.js +++ b/atlastools/include/workshop.js @@ -145,32 +145,60 @@ function readCompressionIndex(reader, sizeUnpacked) { } function downloadMods(modids) { - if (modids.length === 0) return; + // Filter out empty strings and whitespace-only strings + const validModIds = Array.isArray(modids) ? + modids.filter(id => id && id.trim() !== '') : []; + + if (validModIds.length === 0) { + console.log('No valid mod IDs provided. Skipping download.'); + return; + } - console.log('Downloading mods...'); - const modDir = 'server\\ShooterGame'; + console.log(`Downloading ${validModIds.length} mods: ${validModIds.join(', ')}`); const steamCmdPath = `${ - process - .cwd()}\\DumpResources\\server\\Engine\\Binaries\\ThirdParty\\SteamCMD\\Win64\\steamcmd.exe`; + process.cwd()}\\DumpResources\\server\\Engine\\Binaries\\ThirdParty\\SteamCMD\\Win64\\steamcmd.exe`; + + // Check if SteamCMD exists + if (!fs.existsSync(steamCmdPath)) { + console.error(`SteamCMD not found at: ${steamCmdPath}`); + return; + } + const cmd = `${steamCmdPath} +login anonymous +workshop_download_item 834910 ${ - modids.join(' +workshop_download_item 834910 ')} +quit`; + validModIds.join(' +workshop_download_item 834910 ')} +quit`; try { const output = execSync(cmd, {stdio: 'pipe'}).toString(); + console.log('SteamCMD output:', output); + const failedDownloads = (output.match(/Download item (\d+) failed/g) || - []).map(item => item.match(/\d+/)[0]); + []).map(item => item.match(/\d+/)[0]); if (failedDownloads.length > 0) { console.error('Retrying failed downloads:', failedDownloads); - downloadMods(failedDownloads); + // Prevent infinite recursion by checking if we're making progress + if (failedDownloads.length < validModIds.length) { + downloadMods(failedDownloads); + } else { + console.error('All downloads failed. Please check mod IDs and SteamCMD setup.'); + } } } catch (error) { console.error('Error downloading mods:', error); - downloadMods(modids); + + // Prevent infinite recursion + if (validModIds.length > 1) { + console.log('Attempting to download mods individually...'); + // Download one by one instead of retrying the whole batch + validModIds.forEach(id => downloadMods([id])); + } else { + console.error(`Failed to download mod ${validModIds[0]}. Check if the mod ID is valid.`); + } } } + function unpackModMeta(buffer) { const reader = new UnpackReader(buffer); const modMeta = {}; diff --git a/build_json.js b/build_json.js index 4e8b3dd..23954ce 100644 --- a/build_json.js +++ b/build_json.js @@ -56,24 +56,21 @@ async function generateAllGridFiles(pool) { const firstX = 0; const firstY = 0; const firstGrid = helpers.gridName(firstX, firstY); - let firstJsonPath = `../${resourceDir}${firstGrid}.json`; + const firstJsonPath = `../${resourceDir}${firstGrid}.json`; deleteExistingFile(firstJsonPath); - firstJsonPath = `../${resourceDir}${firstGrid}_new.json`; - deleteExistingFile(firstJsonPath); - await runServer(firstGrid, pool, firstX, firstY); // Run remaining servers in parallel const tasks = []; - // Run the first server again because we sometimes have issues loading mods for (let y = 0; y < yGrids; y++) { for (let x = 0; x < xGrids; x++) { + // Skip the first server since we already ran it + if (x === 0 && y === 0) continue; + const grid = helpers.gridName(x, y); - let jsonPath = `../${resourceDir}${grid}.json`; + const jsonPath = `../${resourceDir}${grid}.json`; deleteExistingFile(jsonPath); - jsonPath = `../${resourceDir}${grid}_new.json`; - deleteExistingFile(jsonPath); tasks.push(runServer(grid, pool, x, y)); } } @@ -111,12 +108,23 @@ function deleteExistingFile(filePath) { + async function main() { if (!process.argv.includes('nobuild')) { // Bootstrap mod download if (serverConfig.ModIDs) { - await workshop.downloadMods(serverConfig.ModIDs.split(',')); - await workshop.installMods(serverConfig.ModIDs.split(',')); + const modIds = serverConfig.ModIDs.split(',') + .filter(id => id && id.trim() !== ''); + + if (modIds.length > 0) { + console.log(`Found ${modIds.length} mods to download: ${modIds.join(', ')}`); + await workshop.downloadMods(modIds); + await workshop.installMods(modIds); + } else { + console.log('No valid mod IDs found in ServerGrid.json. Continuing without mods.'); + } + } else { + console.log('No ModIDs field in ServerGrid.json. Continuing without mods.'); } await buildData(); }