Show MineGeo console output and release plugin 0.1.2

This commit is contained in:
2026-10-05 18:37:32 +05:00
parent 891de77a10
commit b33db48b63
7 changed files with 60 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
import { createServer } from "node:http";
import { connect } from "node:net";
import { spawn } from "node:child_process";
import { mkdir, copyFile, writeFile, readFile } from "node:fs/promises";
import { createHash } from "node:crypto";
@@ -17,7 +18,7 @@ await copyFile(
await writeFile(`${directory}/eula.txt`, "eula=true\n");
await writeFile(
`${directory}/server.properties`,
'server-ip=127.0.0.1\nserver-port=25580\nonline-mode=true\nlevel-type=minecraft:flat\ngenerator-settings={"layers":[{"block":"minecraft:bedrock","height":1},{"block":"minecraft:dirt","height":2},{"block":"minecraft:grass_block","height":1}],"biome":"minecraft:plains"}\ngenerate-structures=false\nview-distance=2\nsimulation-distance=2\nspawn-protection=0\nmax-players=1\n',
'server-ip=127.0.0.1\nserver-port=25580\nenable-rcon=true\nrcon.port=25581\nrcon.password=minegeo-fixture\nonline-mode=true\nlevel-type=minecraft:flat\ngenerator-settings={"layers":[{"block":"minecraft:bedrock","height":1},{"block":"minecraft:dirt","height":2},{"block":"minecraft:grass_block","height":1}],"biome":"minecraft:plains"}\ngenerate-structures=false\nview-distance=2\nsimulation-distance=2\nspawn-protection=0\nmax-players=1\n',
);
let manifest: any,
received = Buffer.alloc(0),
@@ -164,8 +165,52 @@ const command = async (text: string, pattern: RegExp) => {
child.stdin.write(text + "\n");
await pending;
};
const rconCommand = (text: string, expected: RegExp) => new Promise<void>((resolve, reject) => {
const socket = connect(25581, "127.0.0.1");
let buffer = Buffer.alloc(0);
let authenticated = false;
const timeout = setTimeout(() => finish(new Error(`RCON timed out waiting for ${expected}`)), 10000);
const finish = (error?: Error) => {
clearTimeout(timeout);
socket.destroy();
if (error) reject(error);
else resolve();
};
const packet = (id: number, type: number, body: string) => {
const payload = Buffer.from(body);
const frame = Buffer.alloc(payload.length + 14);
frame.writeInt32LE(payload.length + 10, 0);
frame.writeInt32LE(id, 4);
frame.writeInt32LE(type, 8);
payload.copy(frame, 12);
return frame;
};
socket.on("connect", () => socket.write(packet(1, 3, "minegeo-fixture")));
socket.on("error", finish);
socket.on("data", (chunk) => {
buffer = Buffer.concat([buffer, chunk]);
while (buffer.length >= 4 && buffer.length >= buffer.readInt32LE(0) + 4) {
const length = buffer.readInt32LE(0);
const frame = buffer.subarray(0, length + 4);
buffer = buffer.subarray(length + 4);
const id = frame.readInt32LE(4);
const type = frame.readInt32LE(8);
if (id === -1) return finish(new Error("RCON authentication failed"));
if (id === 1 && type === 2 && !authenticated) {
authenticated = true;
socket.write(packet(2, 2, text));
} else if (id === 2 && expected.test(frame.toString("utf8", 12, length + 2))) {
return finish();
}
}
});
});
try {
await wait(/Done \(/, 0, 180000);
await command("minegeo help", /MineGeo commands:/);
await command("minegeo status", /MineGeo: Idle/);
await command("minegeo unknown", /Unknown command\. Use \/minegeo help/);
await rconCommand("minegeo help", /MineGeo commands:/);
await command("minegeo upload", /No completed export/);
await command(
"minegeo area world 100000 100000 100032 100032",
@@ -266,6 +311,8 @@ try {
{
passed: true,
checks: [
"local console help, status and errors produce visible output",
"remote console help produces visible output",
"missing export guidance",
"empty area failure",
"real Paper export without a player",