Reewrite project #430
@ -6,8 +6,9 @@ import { getBedrockZip } from "@the-bds-maneger/server_versions";
|
||||
import admZip from "adm-zip";
|
||||
import { exec, execAsync } from "./childPromisses";
|
||||
import { serverRoot } from "./pathControl";
|
||||
import { actions, actionConfig } from "./globalPlatfroms"
|
||||
export const serverPath = path.join(serverRoot, "Bedrock")
|
||||
import { actions, actionConfig } from "./globalPlatfroms";
|
||||
export const serverPath = path.join(serverRoot, "Bedrock");
|
||||
export { bedrockServerWorld, bedrockWorld, linkBedrock } from "./linkWorlds/bedrock_pocketmine";
|
||||
|
||||
// RegExp
|
||||
export const saveFf = /^(worlds|server\.properties|config|((permissions|allowlist|valid_known_packs)\.json)|(development_.*_packs))$/;
|
||||
|
@ -1,5 +1,3 @@
|
||||
export default parse;
|
||||
|
||||
/**
|
||||
* Parse Proprieties files and return a map of properties.
|
||||
*
|
83
src/config/bedrock.ts
Normal file
83
src/config/bedrock.ts
Normal file
@ -0,0 +1,83 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import {} from "prismarine-nbt";
|
||||
import { serverPath } from "../bedrock";
|
||||
import * as Proprieties from "./Proprieties";
|
||||
import * as path from 'node:path';
|
||||
|
||||
export type bedrockParseProprieties = {
|
||||
"server-name": string,
|
||||
gamemode: "survival"|"creative"|"adventure",
|
||||
"force-gamemode": boolean,
|
||||
difficulty: "peaceful"|"easy"|"normal"|"hard",
|
||||
"allow-cheats": boolean,
|
||||
"max-players": number,
|
||||
"online-mode": boolean,
|
||||
"allow-list": boolean,
|
||||
"server-port": number,
|
||||
"server-portv6": number,
|
||||
"view-distance": number,
|
||||
"tick-distance": 4|6|8|10|12,
|
||||
"player-idle-timeout": number,
|
||||
"max-threads": number,
|
||||
"level-name": string,
|
||||
"level-seed": string|number|bigint|null,
|
||||
"default-player-permission-level": "visitor"|"member"|"operator",
|
||||
"texturepack-required": boolean,
|
||||
"content-log-file-enabled": boolean,
|
||||
"compression-threshold": number,
|
||||
"server-authoritative-movement": "client-auth"|"server-auth"|"server-auth-with-rewind",
|
||||
"player-movement-score-threshold": number,
|
||||
"player-movement-action-direction-threshold": number,
|
||||
"player-movement-distance-threshold": number,
|
||||
"player-movement-duration-threshold-in-ms": number,
|
||||
"correct-player-movement": boolean,
|
||||
"server-authoritative-block-breaking": boolean,
|
||||
"chat-restriction": "None"|"Dropped"|"Disabled",
|
||||
"disable-player-interaction": boolean
|
||||
};
|
||||
|
||||
export async function getConfig(): Promise<bedrockParseProprieties> {
|
||||
return Proprieties.parse(await readFile(path.join(serverPath, "server.proprieties"), "utf8")) as bedrockParseProprieties;
|
||||
}
|
||||
|
||||
const keys = RegExp("("+(["server-name", "gamemode", "force-gamemode", "difficulty", "allow-cheats", "max-players", "online-mode", "allow-list", "server-port", "server-portv6", "view-distance", "tick-distance", "player-idle-timeout", "max-threads", "level-name", "level-seed", "default-player-permission-level", "texturepack-required", "content-log-file-enabled", "compression-threshold", "server-authoritative-movement", "player-movement-score-threshold", "player-movement-action-direction-threshold", "player-movement-distance-threshold", "player-movement-duration-threshold-in-ms", "correct-player-movement", "server-authoritative-block-breaking", "chat-restriction", "disable-player-interaction"]).join("|")+")")
|
||||
|
||||
export function createConfig(config: bedrockParseProprieties): string {
|
||||
let configString = "";
|
||||
for (const key of Object.keys(config).filter(a => keys.test(a))) configString += `${key}=${config[key]}\n`;
|
||||
return configString.trim();
|
||||
}
|
||||
|
||||
/*
|
||||
console.log(createConfig({
|
||||
"server-name": "string",
|
||||
gamemode: "survival",
|
||||
"force-gamemode": true,
|
||||
difficulty: "easy",
|
||||
"allow-cheats": false,
|
||||
"max-players": 20,
|
||||
"online-mode": false,
|
||||
"allow-list": true,
|
||||
"server-port": 19135,
|
||||
"server-portv6": 19136,
|
||||
"view-distance": 32,
|
||||
"tick-distance": 8,
|
||||
"player-idle-timeout": 0,
|
||||
"max-threads": 16,
|
||||
"level-name": "string",
|
||||
"level-seed": null,
|
||||
"default-player-permission-level": "member",
|
||||
"texturepack-required": true,
|
||||
"content-log-file-enabled": false,
|
||||
"compression-threshold": 0,
|
||||
"server-authoritative-movement": "server-auth-with-rewind",
|
||||
"player-movement-score-threshold": 0.9,
|
||||
"player-movement-action-direction-threshold": 0.6,
|
||||
"player-movement-distance-threshold": 0.6,
|
||||
"player-movement-duration-threshold-in-ms": 0.6,
|
||||
"correct-player-movement": false,
|
||||
"server-authoritative-block-breaking": false,
|
||||
"chat-restriction": "Disabled",
|
||||
"disable-player-interaction": false
|
||||
}));
|
||||
*/
|
32
src/linkWorlds/bedrock_pocketmine.ts
Normal file
32
src/linkWorlds/bedrock_pocketmine.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import * as path from "node:path";
|
||||
import * as fs from "node:fs/promises";
|
||||
import { existsSync as fsExistsSync } from "node:fs";
|
||||
import { worldFolder } from "../pathControl";
|
||||
import { serverPath as bedrockServerPath } from "../bedrock";
|
||||
import { serverPath as pocketmineServerPath } from "../pocketmine";
|
||||
|
||||
export const bedrockWorld = path.join(worldFolder, "bedrock");
|
||||
export const bedrockServerWorld = path.join(bedrockServerPath, "worlds");
|
||||
export async function linkBedrock() {
|
||||
if (!fsExistsSync(bedrockWorld)) await fs.mkdir(bedrockWorld, {recursive: true});
|
||||
if (fsExistsSync(bedrockServerWorld)) {
|
||||
if (await fs.realpath(bedrockWorld) === bedrockServerWorld) return;
|
||||
for (const folder of await fs.readdir(bedrockServerWorld)) await fs.cp(path.join(bedrockServerWorld, folder), path.join(bedrockWorld, folder), {recursive: true, force: true, preserveTimestamps: true, verbatimSymlinks: true});
|
||||
if (!fsExistsSync(bedrockServerWorld+"_backup")) await fs.rename(bedrockServerWorld, bedrockServerWorld+"_backup");
|
||||
}
|
||||
await fs.symlink(bedrockWorld, bedrockServerWorld);
|
||||
return;
|
||||
}
|
||||
|
||||
export const pocketmineWorld = path.join(worldFolder, "pocketmine");
|
||||
export const pocketmineServerWorld = path.join(pocketmineServerPath, "worlds");
|
||||
export async function linkPocketmine() {
|
||||
if (!fsExistsSync(pocketmineWorld)) await fs.mkdir(pocketmineWorld, {recursive: true});
|
||||
if (fsExistsSync(pocketmineServerWorld)) {
|
||||
if (await fs.realpath(pocketmineWorld) === pocketmineServerWorld) return;
|
||||
for (const folder of await fs.readdir(pocketmineServerWorld)) await fs.cp(path.join(pocketmineServerWorld, folder), path.join(pocketmineWorld, folder), {recursive: true, force: true, preserveTimestamps: true, verbatimSymlinks: true});
|
||||
if (!fsExistsSync(pocketmineServerWorld+"_backup")) await fs.rename(pocketmineServerWorld, pocketmineServerWorld+"_backup");
|
||||
}
|
||||
await fs.symlink(pocketmineWorld, pocketmineServerWorld);
|
||||
return;
|
||||
}
|
@ -11,6 +11,10 @@ if (!fsOld.existsSync(bdsRoot)) fs.mkdir(bdsRoot, {recursive: true}).then(() =>
|
||||
export const serverRoot = path.join(bdsRoot, "Servers");
|
||||
if (!fsOld.existsSync(serverRoot)) fs.mkdir(serverRoot, {recursive: true});
|
||||
|
||||
// Worlds Folder
|
||||
export const worldFolder = path.join(bdsRoot, "Worlds");
|
||||
if (!fsOld.existsSync(worldFolder)) fs.mkdir(serverRoot, {recursive: true});
|
||||
|
||||
// Bds backup
|
||||
export const backupFolder = path.join(bdsRoot, "Backup");
|
||||
if (!fsOld.existsSync(backupFolder)) fs.mkdir(backupFolder, {recursive: true});
|
@ -10,17 +10,15 @@ import { getBuffer } from "./httpRequest";
|
||||
import { actionConfig, actions } from './globalPlatfroms';
|
||||
import AdmZip from "adm-zip";
|
||||
import { promisify } from 'node:util';
|
||||
export { pocketmineServerWorld, pocketmineWorld, linkPocketmine } from "./linkWorlds/bedrock_pocketmine";
|
||||
export const serverPath = path.join(serverRoot, "pocketmine");
|
||||
export const serverPhar = path.join(serverPath, "pocketmine.phar");
|
||||
export const phpBinPath = path.join(serverPath, "bin", (process.platform === "win32"?"php":"bin"), "php");
|
||||
|
||||
async function Readdir(pathRead: string, filter?: Array<RegExp>) {
|
||||
async function Readdir(pathRead: string, filter?: RegExp[]) {
|
||||
if (!filter) filter = [/.*/];
|
||||
const fixedPath = path.resolve(pathRead);
|
||||
const files: Array<{
|
||||
path: string,
|
||||
name: string
|
||||
}> = [];
|
||||
const files: {path: string, name: string}[] = [];
|
||||
for (const file of await fs.readdir(fixedPath)) {
|
||||
const FullFilePath = path.join(fixedPath, file);
|
||||
const stats = await fs.stat(FullFilePath);
|
||||
@ -115,6 +113,12 @@ const serverConfig: actionConfig[] = [
|
||||
if (started.test(data)) done(new Date());
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "playerConnect",
|
||||
callback(data, done) {
|
||||
data;
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "serverStop",
|
||||
run: (child) => child.writeStdin("stop")
|
||||
|
@ -1,5 +1,3 @@
|
||||
import { createWriteStream, writeFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { installServer, startServer } from "../src/pocketmine";
|
||||
|
||||
describe("Pocketmine", () => {
|
||||
@ -19,9 +17,6 @@ describe("Pocketmine", () => {
|
||||
}
|
||||
});
|
||||
serverManeger.on("serverStarted", () => serverManeger.stopServer());
|
||||
writeFileSync(resolve(__dirname, "../server.log"), "");
|
||||
const log = createWriteStream(resolve(__dirname, "../server.log"), {flags: "a"});
|
||||
serverManeger.childProcess.child?.stdout?.pipe(log);
|
||||
return new Promise((done, reject) => serverManeger.on("exit", ({code}) => code === 0?done():reject(new Error("Exit another code "+code))));
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user