Bds Maneger Server Modification #248

Merged
Sirherobrine23 merged 8 commits from Socket into main 2021-11-25 00:04:47 +00:00
9 changed files with 1574 additions and 1593 deletions
Showing only changes of commit e312a1ad06 - Show all commits

View File

@ -169,17 +169,17 @@ async function Runner() {
if (!(ProcessArgs.start || ProcessArgs.s)) return; if (!(ProcessArgs.start || ProcessArgs.s)) return;
const BdsManegerServer = BdsCore.BdsManegerServer.StartServer(); const BdsManegerServer = BdsCore.BdsManegerServer.StartServer();
BdsManegerServer.log(data => process.stdout.write(cli_color.blueBright(data))); BdsManegerServer.on("log", data => process.stdout.write(cli_color.blueBright(data)));
if (!(ProcessArgs["no-api"])) BdsCore.BdsManegerAPI.api(); if (!(ProcessArgs["no-api"])) BdsCore.BdsManegerAPI.api();
const __readline = readline.createInterface({input: process.stdin, output: process.stdout}); const __readline = readline.createInterface({input: process.stdin, output: process.stdout});
__readline.on("line", data => BdsManegerServer.command(data)); __readline.on("line", data => BdsManegerServer.SendCommand(data));
__readline.on("close", () => BdsManegerServer.stop()); __readline.on("close", () => BdsManegerServer.stop());
// Get Temporary External Domain // Get Temporary External Domain
if (ProcessArgs.get_domain) { if (ProcessArgs.get_domain) {
try { try {
const HostInfo = await BdsCore.BdsNetwork.GetHost(); const HostInfo = await BdsCore.BdsNetwork.GetHost();
console.log("Domain:", HostInfo.host); console.log("Domain:", HostInfo.host);
BdsManegerServer.exit(async () => await HostInfo.delete_host()); BdsManegerServer.on("exit", async () => await HostInfo.delete_host())
process.on("exit", async () => { process.on("exit", async () => {
await HostInfo.delete_host(); await HostInfo.delete_host();
console.log("Sucess remove host"); console.log("Sucess remove host");
@ -188,8 +188,8 @@ async function Runner() {
console.log("Cannot get domain"); console.log("Cannot get domain");
} }
} }
BdsManegerServer.exit(code => { BdsManegerServer.on("exit", code => {
console.log(cli_color.redBright(`Bds Core Exit with code ${code}, Uptimed: ${BdsManegerServer.uptime}`)); console.log(cli_color.redBright(`Bds Core Exit with code ${code}, Uptimed: ${BdsManegerServer.Uptime}`));
process.exit(code); process.exit(code);
}); });
} }

View File

@ -36,9 +36,9 @@ async function StartServer(){
ShowToken(); ShowToken();
console.log("The entire log can be accessed via the api and/or the docker log"); console.log("The entire log can be accessed via the api and/or the docker log");
const ServerStarted = BdsCore.BdsManegerServer.StartServer(); const ServerStarted = BdsCore.BdsManegerServer.StartServer();
ServerStarted.log(a => process.stdout.write(a));
ServerStarted.exit(code => process.exit(code));
BdsCore.BdsManegerAPI.api(); BdsCore.BdsManegerAPI.api();
ServerStarted.on("log", a => process.stdout.write(a));
ServerStarted.on("exit", code => process.exit(code));
if (process.env.PULL_REQUEST === "true") { if (process.env.PULL_REQUEST === "true") {
console.log((require("cli-color")).red("Pull Request Actived 1 Min to exit")); console.log((require("cli-color")).red("Pull Request Actived 1 Min to exit"));
setTimeout(() => { setTimeout(() => {

View File

@ -1,11 +1,11 @@
const { join, resolve } = require("path"); const path = require("path");
const { join, resolve } = path;
const fs = require("fs"); const fs = require("fs");
const AdmZip = require("adm-zip"); const AdmZip = require("adm-zip");
const { GetServerPaths, GetPaths, bds_dir } = require("../src/lib/BdsSettings"); const { GetServerPaths, GetPaths, bds_dir } = require("../src/lib/BdsSettings");
function Backup() { function CreateBackup() {
const zip = new AdmZip(); const zip = new AdmZip();
console.info("Starting Bds Core Backup Along with the server maps, please wait");
// Names And Path"s // Names And Path"s
const Paths = { const Paths = {
bedrock: GetServerPaths("bedrock"), bedrock: GetServerPaths("bedrock"),
@ -19,28 +19,28 @@ function Backup() {
const PathBackup = join(GetPaths("backups"), ZipName); const PathBackup = join(GetPaths("backups"), ZipName);
// Bedrock // Bedrock
if (fs.readdirSync(Paths.bedrock).filter(a=>/worlds/.test(a)).length >= 1) { if (fs.readdirSync(Paths.bedrock).filter(a => /worlds/.test(a)).length >= 1) {
zip.addLocalFolder(join(Paths.bedrock, "worlds"), join("Servers", "Bedrock", "worlds")); zip.addLocalFolder(join(Paths.bedrock, "worlds"), join("Servers", "Bedrock", "worlds"));
for (let index of ["server.properties", "permissions.json", "whitelist.json"]) {if (fs.existsSync(join(Paths.bedrock, index))) zip.addLocalFile(join(Paths.bedrock, index), join("Servers", "Bedrock"));} for (let index of ["server.properties", "permissions.json", "whitelist.json"]) {if (fs.existsSync(join(Paths.bedrock, index))) zip.addLocalFile(join(Paths.bedrock, index), join("Servers", "Bedrock"));}
} else console.info("Skipping the bedrock as it was not installed"); }
// Java // Java
if (fs.existsSync(join(Paths.java, "MinecraftServerJava.jar"))) { if (fs.existsSync(join(Paths.java, "MinecraftServerJava.jar"))) {
for (let index of fs.readdirSync(Paths.java).filter(value => !/banned-ips.json|banned-players.json|eula.txt|logs|ops.json|server.jar|MinecraftServerJava.jar|server.properties|usercache.json|whitelist.json/.test(value))) zip.addLocalFolder(join(Paths.java, index), join("Servers", "Java", index)); for (let index of fs.readdirSync(Paths.java).filter(value => !/banned-ips.json|banned-players.json|eula.txt|logs|ops.json|server.jar|MinecraftServerJava.jar|server.properties|usercache.json|whitelist.json/.test(value))) zip.addLocalFolder(join(Paths.java, index), join("Servers", "Java", index));
for (let index of ["banned-ips.json", "banned-players.json", "ops.json", "server.properties", "whitelist.json"]) {if (fs.existsSync(join(Paths.java, index))) zip.addLocalFile(join(Paths.java, index), join("Servers", "Java"))} for (let index of ["banned-ips.json", "banned-players.json", "ops.json", "server.properties", "whitelist.json"]) {if (fs.existsSync(join(Paths.java, index))) zip.addLocalFile(join(Paths.java, index), join("Servers", "Java"))}
} else console.info("Skipping the java as it was not installed"); }
// PocketMine // PocketMine
if (fs.existsSync(join(Paths.pocketmine, "PocketMine-MP.phar"))) { if (fs.existsSync(join(Paths.pocketmine, "PocketMine-MP.phar"))) {
if (fs.existsSync(join(Paths.pocketmine, "worlds"))) zip.addLocalFolder(join(Paths.pocketmine, "worlds"), join("Servers", "pocketmine", "worlds")); if (fs.existsSync(join(Paths.pocketmine, "worlds"))) zip.addLocalFolder(join(Paths.pocketmine, "worlds"), join("Servers", "pocketmine", "worlds"));
for (let index of ["pocketmine.yml", "server.properties", "white-list.txt", "ops.txt", "banned-players.txt", "banned-ips.txt"]) if (fs.existsSync(join(Paths.pocketmine, index))) zip.addLocalFile(join(Paths.pocketmine, index), "pocketmine"); for (let index of ["pocketmine.yml", "server.properties", "white-list.txt", "ops.txt", "banned-players.txt", "banned-ips.txt"]) if (fs.existsSync(join(Paths.pocketmine, index))) zip.addLocalFile(join(Paths.pocketmine, index), "pocketmine");
} else console.info("Skipping the pocketmine as it was not installed"); }
// Spigot // Spigot
if (fs.existsSync(join(Paths.spigot, "spigot.jar"))) { if (fs.existsSync(join(Paths.spigot, "spigot.jar"))) {
if (fs.existsSync(join(Paths.spigot, "worlds"))) zip.addLocalFolder(join(Paths.spigot, "worlds"), join("Servers", "spigot", "worlds")); if (fs.existsSync(join(Paths.spigot, "worlds"))) zip.addLocalFolder(join(Paths.spigot, "worlds"), join("Servers", "spigot", "worlds"));
for (let index of ["spigot.yml", "server.properties", "white-list.txt", "ops.txt", "banned-players.txt", "banned-ips.txt"]) if (fs.existsSync(join(Paths.spigot, index))) zip.addLocalFile(join(Paths.spigot, index), "spigot"); for (let index of ["spigot.yml", "server.properties", "white-list.txt", "ops.txt", "banned-players.txt", "banned-ips.txt"]) if (fs.existsSync(join(Paths.spigot, index))) zip.addLocalFile(join(Paths.spigot, index), "spigot");
} else console.info("Skipping the spigot as it was not installed"); }
// Dragonfly // Dragonfly
if (fs.existsSync(join(Paths.dragonfly, "config.toml"))) { if (fs.existsSync(join(Paths.dragonfly, "config.toml"))) {
@ -48,7 +48,7 @@ function Backup() {
if (fs.lstatSync(index).isDirectory()) zip.addLocalFolder(index, join("Servers", "dragonfly")); if (fs.lstatSync(index).isDirectory()) zip.addLocalFolder(index, join("Servers", "dragonfly"));
else if (fs.lstatSync(index).isFile()) zip.addLocalFile(index, join("Servers", "dragonfly")); else if (fs.lstatSync(index).isFile()) zip.addLocalFile(index, join("Servers", "dragonfly"));
} }
} else console.info("Skipping the dragonfly as it was not installed"); }
// The Bds Maneger Core Backup // The Bds Maneger Core Backup
for (let index of ["BdsConfig.yaml", "bds_tokens.json"]) if (fs.existsSync(join(bds_dir, index))) zip.addLocalFile(join(bds_dir, index)); for (let index of ["BdsConfig.yaml", "bds_tokens.json"]) if (fs.existsSync(join(bds_dir, index))) zip.addLocalFile(join(bds_dir, index));
@ -65,7 +65,6 @@ function Backup() {
// Zip Buffer // Zip Buffer
const ZipBuffer = zip.toBuffer(); const ZipBuffer = zip.toBuffer();
fs.writeFileSync(PathBackup, ZipBuffer, "binary"); fs.writeFileSync(PathBackup, ZipBuffer, "binary");
console.log("Backup Complete");
return { return {
file_path: PathBackup, file_path: PathBackup,
Buffer: ZipBuffer, Buffer: ZipBuffer,
@ -74,7 +73,8 @@ function Backup() {
} }
module.exports = { module.exports = {
World_BAckup: Backup, CreateBackup: CreateBackup,
Backup: Backup, Backup: CreateBackup,
Cloud_backup: Backup World_BAckup: CreateBackup,
Cloud_backup: CreateBackup
} }

View File

@ -128,90 +128,102 @@ module.exports.StartServer = function start() {
global.bds_log_string = "" global.bds_log_string = ""
ServerExec.stdout.on("data", data => {if (global.bds_log_string) global.bds_log_string = data; else global.bds_log_string += data}); ServerExec.stdout.on("data", data => {if (global.bds_log_string) global.bds_log_string = data; else global.bds_log_string += data});
// sets bds core commands /**
const log = function (logCallback){ * Emit command in to the server
if (typeof logCallback !== "function") throw new Error("Log Callback is not a function"); *
ServerExec.stdout.on("data", data => logCallback(data)); * @param {string} command
ServerExec.stderr.on("data", data => logCallback(data)); * @param {Array} command
*/
const ServerCommand = function (Command = "list") {
if (!(typeof Command === "string" || typeof Command === "object" && typeof Command.map === "function")) throw new Error("Command must be a string or an array");
if (typeof Command === "string") {
ServerExec.stdin.write(`${Command}\n`);
} else if (typeof Command === "object" && typeof Command.map === "function") {
Command.filter(a => typeof a === "string").forEach(command => ServerExec.stdin.write(`${command}\n`));
}
return;
}; };
const exit = function (exitCallback = process.exit){if ( /**
typeof exitCallback === "function") ServerExec.on("exit", code => exitCallback(code)); * When a player connects or disconnects, the server will issue an event.
}; *
const on = function(action = String, callback = Function) { * @param {string} Action - The event to listen for.
if (!(action === "all" || action === "connect" || action === "disconnect")) throw new Error("Use some valid action: all, connect, disconnect"); * @param {function} Callback - The callback to run when the event is triggered.
*/
// Functions const PlayerAction = function(Action = "all", callback = (PlayerActions = [{Player: "", Action: "connect", Platform: "", xuid: "", Date: ""},{Player: "", Action: "disconnect", Platform: "", xuid: "", Date: ""}]) => console.log(PlayerActions)){
const data = data => PlayerJson.UpdateUserJSON(data, function (array_status){ if (!(Action === "all" || Action === "connect" || Action === "disconnect")) throw new Error("Use some valid Action: all, connect, disconnect");
array_status.filter(On => {if ("all" === action || On.Action === action) return true; else return false;}).forEach(_player => callback(_player)) const { CreatePlayerJson } = PlayerJson;
const RunON = data => CreatePlayerJson(data, (PlayerActions) => {
if (Action !== "all") PlayerActions = PlayerActions.filter(On => On.Action === Action);
return callback(PlayerActions);
}); });
ServerExec.stdout.on("data", data); ServerExec.stdout.on("data", RunON);
ServerExec.stderr.on("data", data); ServerExec.stderr.on("data", RunON);
return;
}; };
const command = function (command = "list") { /**
ServerExec.stdin.write(`${command}\n`); * Register a function to run when the server issues a log or when it exits.
return command; *
}; * @param {string} FunctionAction - Action to Register to run callback
* @callback
const BasicCo = BasicCommands.BasicCommands(ServerExec); */
const ServerOn = function (FunctionAction = "log", callback = (data = FunctionAction === "log" ? "" : 0) => console.log(data)) {
if (!(FunctionAction === "log" || FunctionAction === "exit")) throw new Error("Use some valid FunctionAction: log, exit");
if (FunctionAction === "log") {
ServerExec.stdout.on("data", data => callback(data));
ServerExec.stderr.on("data", data => callback(data));
} else if (FunctionAction === "exit") ServerExec.on("exit", code => callback(code));
else throw new Error("Use some valid FunctionAction: log, exit");
return;
}
// Mount commands to Return // Mount commands to Return
const returnFuntion = { const returnFuntion = {
uuid: randomUUID(), uuid: randomUUID(),
LogPath: LogFile, LogPath: LogFile,
pid: ServerExec.pid, PID: ServerExec.pid,
uptime: 0, Uptime: 0,
StartTime: (new Date()), StartTime: new Date(),
...BasicCo, on: ServerOn,
command, log, exit, on PlayerAction: PlayerAction,
SendCommand: ServerCommand,
...(BasicCommands.BasicCommands(ServerExec))
} }
// Uptime Server // Uptime Server
const OnStop = setInterval(() => returnFuntion.uptime = (new Date().getTime() - returnFuntion.StartTime.getTime()) / 1000, 1000); const UptimeCount = setInterval(() => returnFuntion.Uptime++, 1000);
ServerExec.on("exit", () => { ServerExec.on("exit", code => {
delete ServerSessions[returnFuntion.uuid] delete ServerSessions[returnFuntion.uuid]
clearInterval(OnStop); io.emit("ServerExit", {
UUID: returnFuntion.uuid,
exitCode: code
})
clearInterval(UptimeCount);
}); });
// Socket.io // Socket.io
io.on("connection", socket => { io.on("connection", socket => {
socket.on("ServerCommand", (data) => { socket.on("ServerCommand", (data) => {
if (typeof data === "string") return returnFuntion.command(data); if (typeof data === "string") return returnFuntion.SendCommand(data);
else if (typeof data === "object") { else if (typeof data === "object") {
if (typeof data.uuid === "string") { if (typeof data.uuid === "string") {
if (data.uuid === returnFuntion.uuid) return returnFuntion.command(data.command); if (data.uuid === returnFuntion.uuid) return returnFuntion.SendCommand(data.command);
} }
} }
return; return;
}); });
}); });
ServerExec.on("exit", code => io.emit("ServerExit", {
UUID: returnFuntion.uuid,
exitCode: code
}));
ServerExec.stdout.on("data", (data = "") => {
io.emit("ServerLog", {
UUID: returnFuntion.uuid,
data: data,
IsStderr: false
});
});
ServerExec.stderr.on("data", (data = "") => {
io.emit("ServerLog", {
UUID: returnFuntion.uuid,
data: data,
IsStderr: true
});
});
// Player JSON File ServerOn("log", data => {
ServerExec.stdout.on("data", data => PlayerJson.CreatePlayerJson(data, Actions => { io.emit("ServerLog", {
PlayerJson.UpdateUserJSON(Actions); UUID: returnFuntion.uuid,
io.emit("PlayerAction", Actions); data: data
})); });
ServerExec.stderr.on("data", data => PlayerJson.CreatePlayerJson(data, Actions => { PlayerJson.CreatePlayerJson(data, Actions => {
PlayerJson.UpdateUserJSON(Actions); if (Actions.length === 0) return;
io.emit("PlayerAction", Actions); PlayerJson.UpdateUserJSON(Actions);
})); io.emit("PlayerAction", Actions);
});
});
// Return // Return
ServerSessions[returnFuntion.uuid] = returnFuntion; ServerSessions[returnFuntion.uuid] = returnFuntion;

View File

@ -6,59 +6,49 @@ function LocalInterfaces() {
const interfaces = os.networkInterfaces(); const interfaces = os.networkInterfaces();
const localInterfaces = []; const localInterfaces = [];
for (const name of Object.getOwnPropertyNames(interfaces)) { for (const name of Object.getOwnPropertyNames(interfaces)) {
const Inter = { const Inter = {
interfaceName: name, interfaceName: name,
mac: "", mac: "",
v4: { v4: {
addresses: "", addresses: "",
netmask: "", netmask: "",
cidr: "" cidr: ""
}, },
v6: { v6: {
addresses: "", addresses: "",
netmask: "", netmask: "",
cidr: "" cidr: ""
}, },
}; };
for (let iface of interfaces[name]) { for (let iface of interfaces[name]) {
if (!Inter.mac && iface.mac) Inter.mac = iface.mac; if (!Inter.mac && iface.mac) Inter.mac = iface.mac;
if (iface.family === "IPv4") { if (iface.family === "IPv4") {
Inter.v4.addresses = iface.address; Inter.v4.addresses = iface.address;
Inter.v4.netmask = iface.netmask; Inter.v4.netmask = iface.netmask;
Inter.v4.cidr = iface.cidr; Inter.v4.cidr = iface.cidr;
} else if (iface.family === "IPv6") { } else if (iface.family === "IPv6") {
Inter.v6.addresses = iface.address; Inter.v6.addresses = iface.address;
Inter.v6.netmask = iface.netmask; Inter.v6.netmask = iface.netmask;
Inter.v6.cidr = iface.cidr; Inter.v6.cidr = iface.cidr;
}
} }
} if (!(interfaces[name][0].internal)) localInterfaces.push(Inter);
if (!(interfaces[name][0].internal)) localInterfaces.push(Inter);
} }
return localInterfaces; return localInterfaces;
} }
async function GetExternalPublicAddress() { async function GetExternalPublicAddress() {
const ExternlIPs = { const ExternlIPs = {
ipv4: null, ipv4: null,
ipv6: null ipv6: null
} }
ExternlIPs["ipv4"] = (await Request.TEXT("https://api.ipify.org")).replace("\n", "") ExternlIPs["ipv4"] = (await Request.TEXT("https://api.ipify.org/")).replace("\n", "")
ExternlIPs["ipv6"] = (await Request.TEXT("https://api64.ipify.org/")).replace("\n", "") ExternlIPs["ipv6"] = (await Request.TEXT("https://api64.ipify.org/")).replace("\n", "")
if (ExternlIPs["ipv6"] === ExternlIPs["ipv4"]) ExternlIPs["ipv6"] = null; if (ExternlIPs["ipv6"] === ExternlIPs["ipv4"]) ExternlIPs["ipv6"] = null;
return ExternlIPs; return ExternlIPs;
} }
module.exports.externalIP = {ipv4: "", ipv6: ""};
Request.TEXT("https://api.ipify.org").then(external_ipv4 => { GetExternalPublicAddress().then(ExternlIPs => module.exports.externalIP = ExternlIPs);
Request.TEXT("https://api64.ipify.org/").then(external_ipv6 => {
const externalIP = {
ipv4: external_ipv4.replace("\n", ""),
ipv6: external_ipv6.replace("\n", "")
}
module.exports.externalIP = externalIP;
module.exports.ip = externalIP;
});
});
// Internal ip user // Internal ip user
const interfaces = os.networkInterfaces(); const interfaces = os.networkInterfaces();
@ -99,24 +89,24 @@ async function GetHost() {
const ExternalAddress = (await GetExternalPublicAddress()).ipv4; const ExternalAddress = (await GetExternalPublicAddress()).ipv4;
const RequestUpstream = await fetch(`https://upstream.bdsmaneger.com/v1/public_domain?MacAddress=${JSON.stringify(MacAddr)}&ExternalAdress=${ExternalAddress}`, {mode: "cors"}); const RequestUpstream = await fetch(`https://upstream.bdsmaneger.com/v1/public_domain?MacAddress=${JSON.stringify(MacAddr)}&ExternalAdress=${ExternalAddress}`, {mode: "cors"});
if (!RequestUpstream.ok) { if (!RequestUpstream.ok) {
throw { throw {
Backend: await RequestUpstream.json() Backend: await RequestUpstream.json()
} }
} }
const HostInfo = await RequestUpstream.json(); const HostInfo = await RequestUpstream.json();
const _toReturn = { const _toReturn = {
host: "", host: "",
UpstreamID: "", UpstreamID: "",
delete_host: async () => { delete_host: async () => {
const RequestDeleteHost = await fetch("https://upstream.bdsmaneger.com/v1/public_domain", { const RequestDeleteHost = await fetch("https://upstream.bdsmaneger.com/v1/public_domain", {
method: "DELETE", method: "DELETE",
mode: "cors", mode: "cors",
body: JSON.stringify({ body: JSON.stringify({
UUID: HostInfo.ID UUID: HostInfo.ID
}) })
}); });
return await RequestDeleteHost.json(); return await RequestDeleteHost.json();
} }
} }
_toReturn["host"] = HostInfo.host.host _toReturn["host"] = HostInfo.host.host
_toReturn["UpstreamID"] = HostInfo.ID _toReturn["UpstreamID"] = HostInfo.ID
@ -128,6 +118,5 @@ module.exports = {
Interfaces, Interfaces,
LocalInterfaces, LocalInterfaces,
GetExternalPublicAddress, GetExternalPublicAddress,
host: null,
GetHost GetHost
} }

View File

@ -160,7 +160,7 @@ app.get(["/bds/log", "/log"], CheckToken, (req, res) => {
try { try {
return { return {
UUID: session, UUID: session,
data: fs.readFileSync(Sessions[session].LogPath, "utf8").replaceAll("\r\n", "\n").split("\n") data: fs.readFileSync(Sessions[session].LogPath, "utf8").replace(/\r\n/gi, "\n").split("\n")
}; };
} catch (err) { } catch (err) {
return { return {
@ -173,34 +173,39 @@ app.get(["/bds/log", "/log"], CheckToken, (req, res) => {
// Server Info // Server Info
app.get("/bds/info/server", ({res}) => { app.get("/bds/info/server", ({res}) => {
let ServerRunner = require("./BdsManegerServer").BdsRun; const ServerSessions = require("./BdsManegerServer").GetSessions();
if (!ServerRunner)ServerRunner = {}; const ServerRunner = Object.keys(ServerSessions).map(session => ServerSessions[session]).map(a => ({
try { UUID: a.uuid || "",
const BdsConfig = BdsManegerCore.BdsSettings.GetJsonConfig(); PID: a.PID || 0,
const Players = JSON.parse(fs.readFileSync(BdsManegerCore.BdsSettings.GetPaths("player"), "utf8"))[BdsSettings.GetPlatform()]; Uptime: a.Uptime || 0,
const Offline = Players.filter(player => player.Action === "disconnect").filter((thing, index, self) => index === self.findIndex((t) => (t.place === thing.place && t.Player === thing.Player))); StartTime: a.StartTime || NaN
const Online = Players.filter(player => player.Action === "connect").filter((thing, index, self) => index === self.findIndex((t) => (t.place === thing.place && t.Player === thing.Player && Offline.findIndex((t) => (t.place === thing.place && t.Player === thing.Player)) === -1))) }));
const Info = { const BdsConfig = BdsManegerCore.BdsSettings.GetJsonConfig();
version: BdsConfig.server.versions[BdsSettings.GetPlatform()], const Players = JSON.parse(fs.readFileSync(BdsManegerCore.BdsSettings.GetPaths("player"), "utf8"))[BdsSettings.GetPlatform()];
Platform: BdsSettings.GetPlatform(), const Offline = Players.filter(player => player.Action === "disconnect").filter((thing, index, self) => index === self.findIndex((t) => (t.place === thing.place && t.Player === thing.Player)));
players: { const Online = Players.filter(player => player.Action === "connect").filter((thing, index, self) => index === self.findIndex((t) => (t.place === thing.place && t.Player === thing.Player && Offline.findIndex((t) => (t.place === thing.place && t.Player === thing.Player)) === -1)))
online: Online.length,
offline: Offline.length, // Delete Info
}, delete BdsConfig.telegram;
Config: BdsManegerCore.BdsSettings.GetJsonConfig(), delete BdsConfig.cloud;
Process: {
PID: ServerRunner.pid || 0, const Info = {
Uptime: ServerRunner.uptime || 0, version: BdsConfig.server.versions[BdsSettings.GetPlatform()],
StartTime: ServerRunner.StartTime || NaN, Platform: BdsSettings.GetPlatform(),
} players: {
} online: Online.length,
res.json(Info); offline: Offline.length,
} catch (error) { },
res.status(500).json({ Config: BdsConfig,
error: "Backend Error", Process: ServerRunner
message: `${error}`
});
} }
return res.json(Info);
});
// Create Backup
app.get("/bds/backup", CheckToken, ({res}) => {
const BackupBuffer = BdsManegerCore.BdsBackup.CreateBackup();
return res.send(BackupBuffer.Buffer);
}); });
// Download Server // Download Server