Skip to content

Commit

Permalink
fix: remove debug log, send /stop on SIGINT
Browse files Browse the repository at this point in the history
  • Loading branch information
MKRhere committed Jan 28, 2024
1 parent 4ad8b92 commit f1010e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
14 changes: 7 additions & 7 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ export default ({

// detached so that Minecraft gets to terminate gracefully on SIGINT
// child process should be exited by @telecraft/core instead of OS
const minecraft = spawn(launch, options, {
const game = spawn(launch, options, {
cwd: config.workdir,
detached: true,
});

const readers: Reader[] = [];
const inputReaders: Reader[] = [];

const { stdin } = minecraft;
const stdout = decode(minecraft.stdout);
const stderr = decode(minecraft.stderr);
const { stdin } = game;
const stdout = decode(game.stdout);
const stderr = decode(game.stderr);

stdout.pipe(io.stdout);
stderr.pipe(io.stderr);
Expand Down Expand Up @@ -171,9 +171,9 @@ export default ({
);
io.stdin.pause();
cliInput.close();
if (!minecraft.killed) {
if (!game.killed) {
console.log("Stopping server.");
server.send("stop");
server.send("/stop");
alreadyExiting = true;
}
events.emit("core:close", {});
Expand All @@ -188,7 +188,7 @@ export default ({
cleanup();
});

minecraft.once("exit", () => {
game.once("exit", () => {
console.log("Game server exited.");
if (alreadyExiting) console.log("Core is already exiting.");
else cleanup();
Expand Down
12 changes: 1 addition & 11 deletions packages/parser/vintagestory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,27 +165,17 @@ const parts = sequenceOf([
]),
]).map(([timestamp, , event]) => ({ ...timestamp, ...event }));

const stream = Deno.openSync("./test.log", {
create: true,
write: true,
truncate: true,
});
const log = (line: string) =>
stream.writeSync(new TextEncoder().encode(line + "\n"));
// const log = console.log;

const sleep = (ms: number) => new Promise(r => setTimeout(r, ms));
// Get 4 random numbers
const rand = () => String(Math.floor(1000 + Math.random() * 9000));

const V119: Parser = (server, emit) => {
let buf = "";
let timer: number | undefined = undefined;
// let timer: number | undefined = undefined;
let waiting = "";

const parse = (line: string) => {
buf = "";
log("> " + line);
const result = parts.run(line);
if (!result.isError)
return emit("vs:" + result.result.event, result.result);
Expand Down

0 comments on commit f1010e2

Please sign in to comment.