From 74b375db0f44375c616da52780ad2afa0af628ed Mon Sep 17 00:00:00 2001 From: Matheus Sampaio Queiroga Date: Wed, 7 Sep 2022 05:55:42 -0300 Subject: [PATCH 1/2] Initial Powernukkit implemention --- src/pwnuukit.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/pwnuukit.ts diff --git a/src/pwnuukit.ts b/src/pwnuukit.ts new file mode 100644 index 0000000..fc1ea10 --- /dev/null +++ b/src/pwnuukit.ts @@ -0,0 +1,26 @@ +import * as path from "node:path"; +import * as fsOld from "node:fs"; +import { serverRoot, logRoot } from './pathControl'; +import { exec } from "./childPromisses"; +import { actions, actionConfig } from './globalPlatfroms'; +export const serverPath = path.join(serverRoot, "power_nukkit"); +const jarPath = path.join(serverPath, "pwnukkit.jar"); + +const serverConfig: actionConfig[] = [ + { + name: "serverStop", + run: (child) => child.writeStdin("stop") + } +]; + +export async function startServer(Config?: {maxMemory?: number, minMemory?: number}) { + if (!fsOld.existsSync(jarPath)) throw new Error("Install server fist."); + const args = ["-jar", "-XX:+UseG1GC", "-XX:+ParallelRefProcEnabled", "-XX:MaxGCPauseMillis=200", "-XX:+UnlockExperimentalVMOptions", "-XX:+DisableExplicitGC", "-XX:+AlwaysPreTouch", "-XX:G1NewSizePercent=30", "-XX:G1MaxNewSizePercent=40", "-XX:G1HeapRegionSize=8M", "-XX:G1ReservePercent=20", "-XX:G1HeapWastePercent=5", "-XX:G1MixedGCCountTarget=4", "-XX:InitiatingHeapOccupancyPercent=15", "-XX:G1MixedGCLiveThresholdPercent=90", "-XX:G1RSetUpdatingPauseTimePercent=5", "-XX:SurvivorRatio=32", "-XX:+PerfDisableSharedMem", "-XX:MaxTenuringThreshold=1", "-Dusing.aikars.flags=https://mcflags.emc.gs", "-Daikars.new.flags=true"]; + if (Config) { + if (Config?.minMemory) args.push(`-Xms${Config?.minMemory}m`); + if (Config?.maxMemory) args.push(`-Xmx${Config?.maxMemory}m`); + } + args.push(jarPath); + const logFileOut = path.join(logRoot, `bdsManeger_${Date.now()}_pwnukkit_${process.platform}_${process.arch}.stdout.log`); + return new actions(exec("java", args, {cwd: serverPath, maxBuffer: Infinity, logPath: {stdout: logFileOut}}), serverConfig); +} -- 2.45.2 From b824cd82a1f6d0efb09461fe60065a72ba0ab921 Mon Sep 17 00:00:00 2001 From: Matheus Sampaio Queiroga Date: Tue, 13 Sep 2022 17:48:22 +0000 Subject: [PATCH 2/2] Update --- src/pwnuukit.ts | 86 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 82 insertions(+), 4 deletions(-) diff --git a/src/pwnuukit.ts b/src/pwnuukit.ts index fc1ea10..1e43c0f 100644 --- a/src/pwnuukit.ts +++ b/src/pwnuukit.ts @@ -1,26 +1,104 @@ import * as path from "node:path"; import * as fsOld from "node:fs"; +import * as fs from "node:fs/promises"; import { serverRoot, logRoot } from './pathControl'; import { exec } from "./childPromisses"; import { actions, actionConfig } from './globalPlatfroms'; +import { platformManeger } from "@the-bds-maneger/server_versions"; export const serverPath = path.join(serverRoot, "power_nukkit"); const jarPath = path.join(serverPath, "pwnukkit.jar"); +export const portListen = /Opening\s+server\s+on\s+(([A-Za-z0-9:\.]+):([0-9]+))/; +// 14:19:28 [INFO ] Sirherobrine joined the game +// 14:25:10 [INFO ] Sirherobrine left the game +export const playerAction = /^.*\[.*\]\s(\S+)\s+(left|joined)\s+the\s+game$/; + const serverConfig: actionConfig[] = [ { name: "serverStop", run: (child) => child.writeStdin("stop") - } + }, + { + name: "serverStarted", + callback(data, done) { + // 16:57:15 [INFO ] Done (2.122s)! For help, type "help" or "?" + if (/^.*\[.*\]\s+Done\s+\([0-9\.]+s\)!/.test(data)) done(new Date()); + }, + }, + { + name: "portListening", + callback(data, done) { + if (portListen.test(data)) { + const [,, host, port] = data.match(portListen); + done({ + port: parseInt(port), + type: "UDP", + protocol: /::/.test(host?.trim())?"IPv6":/[0-9]+\.[0-9]+/.test(host?.trim())?"IPv4":"IPV4/IPv6", + host: host + }) + } + }, + }, + { + name: "playerConnect", + callback(data, done) { + if (playerAction.test(data)) { + const [,playerName, action] = data.match(playerAction); + if (action === "joined") done({ + connectTime: new Date(), + playerName, + }) + } + }, + }, + { + name: "playerDisconnect", + callback(data, done) { + if (playerAction.test(data)) { + const [,playerName, action] = data.match(playerAction); + if (action === "left") done({ + connectTime: new Date(), + playerName, + }) + } + }, + }, ]; +export async function installServer(version: string|boolean) { + if (!fsOld.existsSync(serverPath)) await fs.mkdir(serverPath, {recursive: true}); + await fs.writeFile(jarPath, await platformManeger.powernukkit.getJar(version)) +} + export async function startServer(Config?: {maxMemory?: number, minMemory?: number}) { if (!fsOld.existsSync(jarPath)) throw new Error("Install server fist."); - const args = ["-jar", "-XX:+UseG1GC", "-XX:+ParallelRefProcEnabled", "-XX:MaxGCPauseMillis=200", "-XX:+UnlockExperimentalVMOptions", "-XX:+DisableExplicitGC", "-XX:+AlwaysPreTouch", "-XX:G1NewSizePercent=30", "-XX:G1MaxNewSizePercent=40", "-XX:G1HeapRegionSize=8M", "-XX:G1ReservePercent=20", "-XX:G1HeapWastePercent=5", "-XX:G1MixedGCCountTarget=4", "-XX:InitiatingHeapOccupancyPercent=15", "-XX:G1MixedGCLiveThresholdPercent=90", "-XX:G1RSetUpdatingPauseTimePercent=5", "-XX:SurvivorRatio=32", "-XX:+PerfDisableSharedMem", "-XX:MaxTenuringThreshold=1", "-Dusing.aikars.flags=https://mcflags.emc.gs", "-Daikars.new.flags=true"]; + const args = [ + "-XX:+UseG1GC", + "-XX:+ParallelRefProcEnabled", + "-XX:MaxGCPauseMillis=200", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+DisableExplicitGC", + "-XX:+AlwaysPreTouch", + "-XX:G1NewSizePercent=30", + "-XX:G1MaxNewSizePercent=40", + "-XX:G1HeapRegionSize=8M", + "-XX:G1ReservePercent=20", + "-XX:G1HeapWastePercent=5", + "-XX:G1MixedGCCountTarget=4", + "-XX:InitiatingHeapOccupancyPercent=15", + "-XX:G1MixedGCLiveThresholdPercent=90", + "-XX:G1RSetUpdatingPauseTimePercent=5", + "-XX:SurvivorRatio=32", + "-XX:+PerfDisableSharedMem", + "-XX:MaxTenuringThreshold=1", + "-Dusing.aikars.flags=https://mcflags.emc.gs", + "-Daikars.new.flags=true" + ]; if (Config) { if (Config?.minMemory) args.push(`-Xms${Config?.minMemory}m`); if (Config?.maxMemory) args.push(`-Xmx${Config?.maxMemory}m`); } - args.push(jarPath); + args.push("-jar", jarPath, "--language", "eng"); const logFileOut = path.join(logRoot, `bdsManeger_${Date.now()}_pwnukkit_${process.platform}_${process.arch}.stdout.log`); return new actions(exec("java", args, {cwd: serverPath, maxBuffer: Infinity, logPath: {stdout: logFileOut}}), serverConfig); -} +} \ No newline at end of file -- 2.45.2