@kzheart_/mc-pilot 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,6 +44,7 @@ export declare class ServerInstanceManager {
44
44
  startedAt: string;
45
45
  logPath: string;
46
46
  instanceDir: string;
47
+ stdinPipe?: string;
47
48
  running: boolean;
48
49
  stale: boolean;
49
50
  } | {
@@ -54,6 +55,7 @@ export declare class ServerInstanceManager {
54
55
  startedAt: string;
55
56
  logPath: string;
56
57
  instanceDir: string;
58
+ stdinPipe?: string;
57
59
  running: boolean;
58
60
  }>;
59
61
  waitReady(serverName: string, timeoutSeconds: number): Promise<{
@@ -1,6 +1,6 @@
1
- import { copyFile, mkdir, readdir, readFile, writeFile } from "node:fs/promises";
1
+ import { copyFile, mkdir, readdir, readFile, writeFile, unlink } from "node:fs/promises";
2
2
  import { mkdirSync, openSync } from "node:fs";
3
- import { spawn } from "node:child_process";
3
+ import { spawn, execSync } from "node:child_process";
4
4
  import path from "node:path";
5
5
  import { resolveProjectDir, resolveServerInstanceDir } from "../util/paths.js";
6
6
  import { MctError } from "../util/errors.js";
@@ -57,17 +57,34 @@ export class ServerInstanceManager {
57
57
  await writeFile(path.join(instanceDir, "eula.txt"), "eula=true\n", "utf8");
58
58
  }
59
59
  const logsDir = path.join(this.globalState.getRootDir(), "logs");
60
+ const stateDir = path.join(this.globalState.getRootDir(), "state");
60
61
  mkdirSync(logsDir, { recursive: true });
62
+ mkdirSync(stateDir, { recursive: true });
61
63
  const logPath = path.join(logsDir, `server-${this.project}-${serverName}.log`);
62
64
  const stdout = openSync(logPath, "a");
63
65
  const jvmArgs = options.jvmArgs ?? meta.jvmArgs;
64
- const child = spawn("java", [...jvmArgs, "-jar", jarFile, "nogui"], {
66
+ // Create a named pipe (FIFO) for stdin so external tools (GUI) can send commands
67
+ const stdinPipe = path.join(stateDir, `stdin-${this.project}-${serverName}.fifo`);
68
+ try {
69
+ await unlink(stdinPipe);
70
+ }
71
+ catch { /* ignore */ }
72
+ execSync(`mkfifo "${stdinPipe}"`);
73
+ // Use bash wrapper: hold FIFO write end open (fd 3) to prevent EOF,
74
+ // then exec java with stdin reading from the FIFO
75
+ const child = spawn("bash", [
76
+ "-c",
77
+ 'exec 3>"$MCT_STDIN_PIPE"; exec java "$@" <"$MCT_STDIN_PIPE"',
78
+ "mct-server",
79
+ ...jvmArgs, "-jar", jarFile, "nogui"
80
+ ], {
65
81
  cwd: instanceDir,
66
82
  detached: true,
67
83
  stdio: ["ignore", stdout, stdout],
68
84
  env: {
69
85
  ...process.env,
70
- MCT_SERVER_PORT: String(meta.port)
86
+ MCT_SERVER_PORT: String(meta.port),
87
+ MCT_STDIN_PIPE: stdinPipe
71
88
  }
72
89
  });
73
90
  child.unref();
@@ -78,7 +95,8 @@ export class ServerInstanceManager {
78
95
  port: meta.port,
79
96
  startedAt: new Date().toISOString(),
80
97
  logPath,
81
- instanceDir
98
+ instanceDir,
99
+ stdinPipe
82
100
  };
83
101
  state.servers[stateKey] = entry;
84
102
  await this.globalState.writeServerState(state);
@@ -94,6 +112,13 @@ export class ServerInstanceManager {
94
112
  if (isProcessRunning(entry.pid)) {
95
113
  killProcessTree(entry.pid);
96
114
  }
115
+ // Clean up FIFO
116
+ if (entry.stdinPipe) {
117
+ try {
118
+ await unlink(entry.stdinPipe);
119
+ }
120
+ catch { /* ignore */ }
121
+ }
97
122
  delete state.servers[stateKey];
98
123
  await this.globalState.writeServerState(state);
99
124
  return { running: false, stopped: true, pid: entry.pid };
@@ -28,6 +28,7 @@ export interface ServerRuntimeEntry {
28
28
  startedAt: string;
29
29
  logPath: string;
30
30
  instanceDir: string;
31
+ stdinPipe?: string;
31
32
  }
32
33
  export interface ClientRuntimeEntry {
33
34
  pid: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kzheart_/mc-pilot",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Minecraft plugin/mod automated testing CLI – control a real Minecraft client to simulate player actions",
5
5
  "type": "module",
6
6
  "bin": {