Reewrite project #430
@ -1,2 +1,3 @@
|
|||||||
export * as bedrock from "./bedrock";
|
export * as bedrock from "./bedrock";
|
||||||
export * as java from "./java";
|
export * as java from "./java";
|
||||||
|
export * as spigot from "./spigot";
|
||||||
|
49
src/spigot.ts
Normal file
49
src/spigot.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import * as path from "node:path";
|
||||||
|
import * as fs from "node:fs/promises";
|
||||||
|
import * as fsOld from "node:fs";
|
||||||
|
import { getSpigotJar } from "@the-bds-maneger/server_versions";
|
||||||
|
import { serverRoot } from "./pathControl";
|
||||||
|
import { exec } from "./childPromisses";
|
||||||
|
import { actions, actionConfig } from './globalPlatfroms';
|
||||||
|
export const serverPath = path.join(serverRoot, "spigot");
|
||||||
|
const jarPath = path.join(serverPath, "server.jar");
|
||||||
|
export const started = /\[.*\].*\s+Done\s+\(.*\)\!.*/;
|
||||||
|
export const portListen = /Starting\s+Minecraft\s+server\s+on\s+(.*)\:(\d+)/;
|
||||||
|
|
||||||
|
export async function installServer(version: string|boolean) {
|
||||||
|
if (!fsOld.existsSync(serverPath)) await fs.mkdir(serverPath, {recursive: true});
|
||||||
|
await fs.writeFile(jarPath, await getSpigotJar(version));
|
||||||
|
}
|
||||||
|
|
||||||
|
const serverConfig: actionConfig[] = [
|
||||||
|
{
|
||||||
|
name: "serverStarted",
|
||||||
|
callback(data, done) {
|
||||||
|
// [22:35:26] [Server thread/INFO]: Done (6.249s)! For help, type "help"
|
||||||
|
if (started.test(data)) done(new Date());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "portListening",
|
||||||
|
callback(data, done) {
|
||||||
|
const portParse = data.match(portListen);
|
||||||
|
if (!!portParse) done({port: parseInt(portParse[2]), host: (portParse[1]||"").trim()||undefined, type: "TCP", protocol: "IPV4/IPv6",});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
export async function startServer(Config?: {maxMemory?: number, minMemory?: number}) {
|
||||||
|
if (!fsOld.existsSync(jarPath)) throw new Error("Install server fist.");
|
||||||
|
const command = "java";
|
||||||
|
const args = ["-jar"];
|
||||||
|
if (Config) {
|
||||||
|
if (Config?.minMemory) args.push(`-Xms${Config?.minMemory}m`);
|
||||||
|
if (Config?.maxMemory) args.push(`-Xmx${Config?.maxMemory}m`);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
args.push(jarPath);
|
||||||
|
const serverProcess = exec(command, args, {cwd: serverPath, maxBuffer: Infinity});
|
||||||
|
const serverActions = new actions(serverProcess, serverConfig);
|
||||||
|
return {serverProcess, serverActions};
|
||||||
|
}
|
Reference in New Issue
Block a user