Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions atlastools/include/workshop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
28 changes: 18 additions & 10 deletions build_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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();
}
Expand Down