Skip to content

Commit

Permalink
rebuild on server failure
Browse files Browse the repository at this point in the history
  • Loading branch information
antihax committed Mar 5, 2023
1 parent 253e87b commit ab877bd
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 41 deletions.
22 changes: 18 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\build_json.js"
"program": "${workspaceFolder}\\build_json.js",
"args": ["manualmanagedmods"],
"runtimeArgs": [
"--max-old-space-size=8096"
]
},
{
"type": "pwa-node",
Expand All @@ -21,7 +25,10 @@
"<node_internals>/**"
],
"program": "${workspaceFolder}\\build_json.js",
"args": ["nobuild"]
"args": ["nobuild"],
"runtimeArgs": [
"--max-old-space-size=8096"
]
},
{
"type": "pwa-node",
Expand All @@ -31,7 +38,11 @@
"<node_internals>/**"
],
"program": "${workspaceFolder}\\build_json.js",
"args": ["nobuild", "debug"]
"args": ["nobuild", "debug"],
"runtimeArgs": [
"--max-old-space-size=8096",
"--trace-warnings"
]
},
{
"type": "pwa-node",
Expand All @@ -41,7 +52,10 @@
"<node_internals>/**"
],
"program": "${workspaceFolder}\\${file}",
"args": ["nobuild", "debug"]
"args": ["nobuild", "debug"],
"runtimeArgs": [
"--max-old-space-size=8096"
]
}
]
}
Binary file modified DumpResources/x64/Release/DumpResources.dll
Binary file not shown.
Binary file modified DumpResources/x64/Release/DumpResources.pdb
Binary file not shown.
6 changes: 6 additions & 0 deletions apihelper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


\W([a-zA-Z-_<>]+) (.*)?;


$1& $2Field() { return *GetNativePointerField<$1*>(this, "APrimalModularShip.$2"); }
108 changes: 71 additions & 37 deletions build_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,69 @@ const yGrids = serverConfig.totalGridsY;
const worldUnitsX = xGrids * serverConfig.gridSize;
const worldUnitsY = yGrids * serverConfig.gridSize;

async function buildData() {
const pool = new WorkerPool(os.cpus().length / 3, "./build_worker.js");
async function runServer(grid, pool, x, y) {
pool.setMaxListeners(250);
let extraArgs = "";
if (process.argv.includes("manualmanagedmods")) {
extraArgs += " -manualmanagedmods";
}

extraArgs += " -culture=en";

let cmd =
"start /min " +
process.cwd() +
`\\server\\ShooterGame\\Binaries\\Win64\\ShooterGameServer.exe Ocean?ServerX=${x}?ServerY=${y}?AltSaveDirectoryName=${x}${y}?ServerAdminPassword=123?QueryPort=5${x}${y}?Port=6${x}${y}?MapPlayerLocation=true -NoBattlEye -log -server -NoSeamlessServer ${extraArgs}`;

// Run in the background
let task = new Promise((resolve) => {
pool.runTask({cmd, grid}, (err, result) => {
return resolve(result);
});
});
return task;
}

async function buildData() {
const pool = new WorkerPool(os.cpus().length / 3, "./build_worker.js");

process.chdir("DumpResources");

let tasks = [];

// First pass, run all servers to generate the json files
for (let y = 0; y < yGrids; y++) {
for (let x = 0; x < xGrids; x++) {
let cmd =
"start /min " +
process.cwd() +
`\\server\\ShooterGame\\Binaries\\Win64\\ShooterGameServer.exe Ocean?ServerX=${x}?ServerY=${y}?AltSaveDirectoryName=${x}${y}?ServerAdminPassword=123?QueryPort=5${x}${y}?Port=6${x}${y}?MapPlayerLocation=true -NoBattlEye -log -server -NoSeamlessServer ${extraArgs}`;
let grid = helpers.gridName(x, y);
let task = new Promise((resolve) => {
pool.runTask({cmd, grid}, (err, result) => {
return resolve(result);
});
let file = "../" + resourceDir + grid + ".json";

// Delete file so we can verify it was created by the extractor
fs.stat(file, (err) => {
if (!err) fs.unlinkSync(file);
});
tasks.push(task);

tasks.push(runServer(grid, pool, x, y));
}
}
await Promise.all(tasks);

let missingFiles = true;
while (missingFiles) {
missingFiles = false;
for (let y = 0; y < yGrids; y++) {
for (let x = 0; x < xGrids; x++) {
let grid = helpers.gridName(x, y);
let file = "../" + resourceDir + grid + ".json";
if (!fs.existsSync(file)) {
missingFiles = true;
console.log(`Missing file ${file}, restarting server`);
tasks.push(runServer(grid, pool, x, y));
}
}
}
await Promise.all(tasks);
}

process.chdir(workDir);
pool.close();
}
Expand Down Expand Up @@ -166,7 +200,7 @@ async function main() {
islandWidth: cp.islandWidth,
islandHeight: cp.islandHeight,
isControlPoint: cp.isControlPoint,
islandPoints: islandInfo[cp.id] ? islandInfo[cp.id].islandPoints || 0 : 0,
islandPoints: islandInfo[cp.id] ? islandInfo[cp.id].islandPoints || 0 : 0
};
i.sublevels = [];
for (let sl in s.sublevels) {
Expand Down Expand Up @@ -310,29 +344,29 @@ async function main() {
// save everything
fs.writeFileSync(
"./json/config.js",
JSON.stringify(
sortObjByKey({
ServersX: serverConfig.totalGridsX,
ServersY: serverConfig.totalGridsY,
GridSize: serverConfig.gridSize,
GPSBounds: gpsBounds,
XRange: Math.abs(gpsBounds.min[0] - gpsBounds.max[0]),
YRange: Math.abs(gpsBounds.min[1] - gpsBounds.max[1]),
XScale: 200 / Math.abs(gpsBounds.min[0] - gpsBounds.max[0]),
YScale: 200 / Math.abs(gpsBounds.min[1] - gpsBounds.max[1]),
NodesPerAxis: nodesPerAxis,
GridOffset: gridOffset,
KofiLink: true,
ItemLink: true,
PathFinder: true,
PinTool: true,
AtlasMapServer: false,
WarehouseTool: false
}),
null,
"\t"
)

JSON.stringify(
sortObjByKey({
ServersX: serverConfig.totalGridsX,
ServersY: serverConfig.totalGridsY,
GridSize: serverConfig.gridSize,
GPSBounds: gpsBounds,
XRange: Math.abs(gpsBounds.min[0] - gpsBounds.max[0]),
YRange: Math.abs(gpsBounds.min[1] - gpsBounds.max[1]),
XScale: 200 / Math.abs(gpsBounds.min[0] - gpsBounds.max[0]),
YScale: 200 / Math.abs(gpsBounds.min[1] - gpsBounds.max[1]),
NodesPerAxis: nodesPerAxis,
GridOffset: gridOffset,
KofiLink: true,
ItemLink: true,
PathFinder: true,
PinTool: true,
AtlasMapServer: false,
WarehouseTool: false
}),
null,
"\t"
)
);

fs.copyFileSync(resourceDir + "animals.json", "./json/animals.json");
Expand Down Expand Up @@ -373,9 +407,9 @@ async function main() {
continue nodeSearch;
}
}

if (lastY !== undefined) {
// g.addNode(worldToGPS(x, y, gpsBounds).toString(), {});
// g.addNode(worldToGPS(x, y, gpsBounds).toString(), {});
g.addLink(worldToGPS(x, y, gpsBounds).toString(), worldToGPS(x, lastY, gpsBounds).toString());
g.addLink(worldToGPS(x, lastY, gpsBounds).toString(), worldToGPS(x, y, gpsBounds).toString());
if (x > s.gridX * gridSize + gridOffset * 10)
Expand Down

0 comments on commit ab877bd

Please sign in to comment.