Bds Maneger Server Modification #248
@ -169,17 +169,17 @@ async function Runner() {
|
||||
if (!(ProcessArgs.start || ProcessArgs.s)) return;
|
||||
|
||||
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();
|
||||
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());
|
||||
// Get Temporary External Domain
|
||||
if (ProcessArgs.get_domain) {
|
||||
try {
|
||||
const HostInfo = await BdsCore.BdsNetwork.GetHost();
|
||||
console.log("Domain:", HostInfo.host);
|
||||
BdsManegerServer.exit(async () => await HostInfo.delete_host());
|
||||
BdsManegerServer.on("exit", async () => await HostInfo.delete_host())
|
||||
process.on("exit", async () => {
|
||||
await HostInfo.delete_host();
|
||||
console.log("Sucess remove host");
|
||||
@ -188,8 +188,8 @@ async function Runner() {
|
||||
console.log("Cannot get domain");
|
||||
}
|
||||
}
|
||||
BdsManegerServer.exit(code => {
|
||||
console.log(cli_color.redBright(`Bds Core Exit with code ${code}, Uptimed: ${BdsManegerServer.uptime}`));
|
||||
BdsManegerServer.on("exit", code => {
|
||||
console.log(cli_color.redBright(`Bds Core Exit with code ${code}, Uptimed: ${BdsManegerServer.Uptime}`));
|
||||
process.exit(code);
|
||||
});
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ async function StartServer(){
|
||||
ShowToken();
|
||||
console.log("The entire log can be accessed via the api and/or the docker log");
|
||||
const ServerStarted = BdsCore.BdsManegerServer.StartServer();
|
||||
ServerStarted.log(a => process.stdout.write(a));
|
||||
ServerStarted.exit(code => process.exit(code));
|
||||
BdsCore.BdsManegerAPI.api();
|
||||
ServerStarted.on("log", a => process.stdout.write(a));
|
||||
ServerStarted.on("exit", code => process.exit(code));
|
||||
if (process.env.PULL_REQUEST === "true") {
|
||||
console.log((require("cli-color")).red("Pull Request Actived 1 Min to exit"));
|
||||
setTimeout(() => {
|
||||
|
@ -1,11 +1,11 @@
|
||||
const { join, resolve } = require("path");
|
||||
const path = require("path");
|
||||
const { join, resolve } = path;
|
||||
const fs = require("fs");
|
||||
const AdmZip = require("adm-zip");
|
||||
const { GetServerPaths, GetPaths, bds_dir } = require("../src/lib/BdsSettings");
|
||||
|
||||
function Backup() {
|
||||
function CreateBackup() {
|
||||
const zip = new AdmZip();
|
||||
console.info("Starting Bds Core Backup Along with the server maps, please wait");
|
||||
// Names And Path"s
|
||||
const Paths = {
|
||||
bedrock: GetServerPaths("bedrock"),
|
||||
@ -19,28 +19,28 @@ function Backup() {
|
||||
const PathBackup = join(GetPaths("backups"), ZipName);
|
||||
|
||||
// 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"));
|
||||
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
|
||||
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 ["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
|
||||
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"));
|
||||
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
|
||||
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"));
|
||||
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
|
||||
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"));
|
||||
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
|
||||
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
|
||||
const ZipBuffer = zip.toBuffer();
|
||||
fs.writeFileSync(PathBackup, ZipBuffer, "binary");
|
||||
console.log("Backup Complete");
|
||||
return {
|
||||
file_path: PathBackup,
|
||||
Buffer: ZipBuffer,
|
||||
@ -74,7 +73,8 @@ function Backup() {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
World_BAckup: Backup,
|
||||
Backup: Backup,
|
||||
Cloud_backup: Backup
|
||||
CreateBackup: CreateBackup,
|
||||
Backup: CreateBackup,
|
||||
World_BAckup: CreateBackup,
|
||||
Cloud_backup: CreateBackup
|
||||
}
|
@ -128,90 +128,102 @@ module.exports.StartServer = function start() {
|
||||
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});
|
||||
|
||||
// sets bds core commands
|
||||
const log = function (logCallback){
|
||||
if (typeof logCallback !== "function") throw new Error("Log Callback is not a function");
|
||||
ServerExec.stdout.on("data", data => logCallback(data));
|
||||
ServerExec.stderr.on("data", data => logCallback(data));
|
||||
/**
|
||||
* Emit command in to the server
|
||||
*
|
||||
* @param {string} command
|
||||
* @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));
|
||||
};
|
||||
const on = function(action = String, callback = Function) {
|
||||
if (!(action === "all" || action === "connect" || action === "disconnect")) throw new Error("Use some valid action: all, connect, disconnect");
|
||||
|
||||
// Functions
|
||||
const data = data => PlayerJson.UpdateUserJSON(data, function (array_status){
|
||||
array_status.filter(On => {if ("all" === action || On.Action === action) return true; else return false;}).forEach(_player => callback(_player))
|
||||
/**
|
||||
* When a player connects or disconnects, the server will issue an event.
|
||||
*
|
||||
* @param {string} Action - The event to listen for.
|
||||
* @param {function} Callback - The callback to run when the event is triggered.
|
||||
*/
|
||||
const PlayerAction = function(Action = "all", callback = (PlayerActions = [{Player: "", Action: "connect", Platform: "", xuid: "", Date: ""},{Player: "", Action: "disconnect", Platform: "", xuid: "", Date: ""}]) => console.log(PlayerActions)){
|
||||
if (!(Action === "all" || Action === "connect" || Action === "disconnect")) throw new Error("Use some valid Action: all, connect, disconnect");
|
||||
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.stderr.on("data", data);
|
||||
ServerExec.stdout.on("data", RunON);
|
||||
ServerExec.stderr.on("data", RunON);
|
||||
return;
|
||||
};
|
||||
const command = function (command = "list") {
|
||||
ServerExec.stdin.write(`${command}\n`);
|
||||
return command;
|
||||
};
|
||||
|
||||
const BasicCo = BasicCommands.BasicCommands(ServerExec);
|
||||
/**
|
||||
* Register a function to run when the server issues a log or when it exits.
|
||||
*
|
||||
* @param {string} FunctionAction - Action to Register to run callback
|
||||
* @callback
|
||||
*/
|
||||
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
|
||||
const returnFuntion = {
|
||||
uuid: randomUUID(),
|
||||
LogPath: LogFile,
|
||||
pid: ServerExec.pid,
|
||||
uptime: 0,
|
||||
StartTime: (new Date()),
|
||||
...BasicCo,
|
||||
command, log, exit, on
|
||||
PID: ServerExec.pid,
|
||||
Uptime: 0,
|
||||
StartTime: new Date(),
|
||||
on: ServerOn,
|
||||
PlayerAction: PlayerAction,
|
||||
SendCommand: ServerCommand,
|
||||
...(BasicCommands.BasicCommands(ServerExec))
|
||||
}
|
||||
|
||||
// Uptime Server
|
||||
const OnStop = setInterval(() => returnFuntion.uptime = (new Date().getTime() - returnFuntion.StartTime.getTime()) / 1000, 1000);
|
||||
ServerExec.on("exit", () => {
|
||||
const UptimeCount = setInterval(() => returnFuntion.Uptime++, 1000);
|
||||
ServerExec.on("exit", code => {
|
||||
delete ServerSessions[returnFuntion.uuid]
|
||||
clearInterval(OnStop);
|
||||
io.emit("ServerExit", {
|
||||
UUID: returnFuntion.uuid,
|
||||
exitCode: code
|
||||
})
|
||||
clearInterval(UptimeCount);
|
||||
});
|
||||
|
||||
// Socket.io
|
||||
io.on("connection", socket => {
|
||||
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") {
|
||||
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;
|
||||
});
|
||||
});
|
||||
ServerExec.on("exit", code => io.emit("ServerExit", {
|
||||
UUID: returnFuntion.uuid,
|
||||
exitCode: code
|
||||
}));
|
||||
ServerExec.stdout.on("data", (data = "") => {
|
||||
|
||||
ServerOn("log", data => {
|
||||
io.emit("ServerLog", {
|
||||
UUID: returnFuntion.uuid,
|
||||
data: data,
|
||||
IsStderr: false
|
||||
data: data
|
||||
});
|
||||
PlayerJson.CreatePlayerJson(data, Actions => {
|
||||
if (Actions.length === 0) return;
|
||||
PlayerJson.UpdateUserJSON(Actions);
|
||||
io.emit("PlayerAction", Actions);
|
||||
});
|
||||
});
|
||||
ServerExec.stderr.on("data", (data = "") => {
|
||||
io.emit("ServerLog", {
|
||||
UUID: returnFuntion.uuid,
|
||||
data: data,
|
||||
IsStderr: true
|
||||
});
|
||||
});
|
||||
|
||||
// Player JSON File
|
||||
ServerExec.stdout.on("data", data => PlayerJson.CreatePlayerJson(data, Actions => {
|
||||
PlayerJson.UpdateUserJSON(Actions);
|
||||
io.emit("PlayerAction", Actions);
|
||||
}));
|
||||
ServerExec.stderr.on("data", data => PlayerJson.CreatePlayerJson(data, Actions => {
|
||||
PlayerJson.UpdateUserJSON(Actions);
|
||||
io.emit("PlayerAction", Actions);
|
||||
}));
|
||||
|
||||
// Return
|
||||
ServerSessions[returnFuntion.uuid] = returnFuntion;
|
||||
|
@ -6,59 +6,49 @@ function LocalInterfaces() {
|
||||
const interfaces = os.networkInterfaces();
|
||||
const localInterfaces = [];
|
||||
for (const name of Object.getOwnPropertyNames(interfaces)) {
|
||||
const Inter = {
|
||||
interfaceName: name,
|
||||
mac: "",
|
||||
v4: {
|
||||
addresses: "",
|
||||
netmask: "",
|
||||
cidr: ""
|
||||
},
|
||||
v6: {
|
||||
addresses: "",
|
||||
netmask: "",
|
||||
cidr: ""
|
||||
},
|
||||
};
|
||||
for (let iface of interfaces[name]) {
|
||||
if (!Inter.mac && iface.mac) Inter.mac = iface.mac;
|
||||
if (iface.family === "IPv4") {
|
||||
Inter.v4.addresses = iface.address;
|
||||
Inter.v4.netmask = iface.netmask;
|
||||
Inter.v4.cidr = iface.cidr;
|
||||
} else if (iface.family === "IPv6") {
|
||||
Inter.v6.addresses = iface.address;
|
||||
Inter.v6.netmask = iface.netmask;
|
||||
Inter.v6.cidr = iface.cidr;
|
||||
const Inter = {
|
||||
interfaceName: name,
|
||||
mac: "",
|
||||
v4: {
|
||||
addresses: "",
|
||||
netmask: "",
|
||||
cidr: ""
|
||||
},
|
||||
v6: {
|
||||
addresses: "",
|
||||
netmask: "",
|
||||
cidr: ""
|
||||
},
|
||||
};
|
||||
for (let iface of interfaces[name]) {
|
||||
if (!Inter.mac && iface.mac) Inter.mac = iface.mac;
|
||||
if (iface.family === "IPv4") {
|
||||
Inter.v4.addresses = iface.address;
|
||||
Inter.v4.netmask = iface.netmask;
|
||||
Inter.v4.cidr = iface.cidr;
|
||||
} else if (iface.family === "IPv6") {
|
||||
Inter.v6.addresses = iface.address;
|
||||
Inter.v6.netmask = iface.netmask;
|
||||
Inter.v6.cidr = iface.cidr;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(interfaces[name][0].internal)) localInterfaces.push(Inter);
|
||||
if (!(interfaces[name][0].internal)) localInterfaces.push(Inter);
|
||||
}
|
||||
return localInterfaces;
|
||||
}
|
||||
|
||||
async function GetExternalPublicAddress() {
|
||||
const ExternlIPs = {
|
||||
ipv4: null,
|
||||
ipv6: null
|
||||
ipv4: 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", "")
|
||||
if (ExternlIPs["ipv6"] === ExternlIPs["ipv4"]) ExternlIPs["ipv6"] = null;
|
||||
return ExternlIPs;
|
||||
}
|
||||
|
||||
Request.TEXT("https://api.ipify.org").then(external_ipv4 => {
|
||||
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;
|
||||
});
|
||||
});
|
||||
module.exports.externalIP = {ipv4: "", ipv6: ""};
|
||||
GetExternalPublicAddress().then(ExternlIPs => module.exports.externalIP = ExternlIPs);
|
||||
|
||||
// Internal ip user
|
||||
const interfaces = os.networkInterfaces();
|
||||
@ -99,24 +89,24 @@ async function GetHost() {
|
||||
const ExternalAddress = (await GetExternalPublicAddress()).ipv4;
|
||||
const RequestUpstream = await fetch(`https://upstream.bdsmaneger.com/v1/public_domain?MacAddress=${JSON.stringify(MacAddr)}&ExternalAdress=${ExternalAddress}`, {mode: "cors"});
|
||||
if (!RequestUpstream.ok) {
|
||||
throw {
|
||||
Backend: await RequestUpstream.json()
|
||||
}
|
||||
throw {
|
||||
Backend: await RequestUpstream.json()
|
||||
}
|
||||
}
|
||||
const HostInfo = await RequestUpstream.json();
|
||||
const _toReturn = {
|
||||
host: "",
|
||||
UpstreamID: "",
|
||||
delete_host: async () => {
|
||||
const RequestDeleteHost = await fetch("https://upstream.bdsmaneger.com/v1/public_domain", {
|
||||
method: "DELETE",
|
||||
mode: "cors",
|
||||
body: JSON.stringify({
|
||||
UUID: HostInfo.ID
|
||||
})
|
||||
});
|
||||
return await RequestDeleteHost.json();
|
||||
}
|
||||
host: "",
|
||||
UpstreamID: "",
|
||||
delete_host: async () => {
|
||||
const RequestDeleteHost = await fetch("https://upstream.bdsmaneger.com/v1/public_domain", {
|
||||
method: "DELETE",
|
||||
mode: "cors",
|
||||
body: JSON.stringify({
|
||||
UUID: HostInfo.ID
|
||||
})
|
||||
});
|
||||
return await RequestDeleteHost.json();
|
||||
}
|
||||
}
|
||||
_toReturn["host"] = HostInfo.host.host
|
||||
_toReturn["UpstreamID"] = HostInfo.ID
|
||||
@ -128,6 +118,5 @@ module.exports = {
|
||||
Interfaces,
|
||||
LocalInterfaces,
|
||||
GetExternalPublicAddress,
|
||||
host: null,
|
||||
GetHost
|
||||
}
|
||||
|
61
src/api.js
61
src/api.js
@ -160,7 +160,7 @@ app.get(["/bds/log", "/log"], CheckToken, (req, res) => {
|
||||
try {
|
||||
return {
|
||||
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) {
|
||||
return {
|
||||
@ -173,34 +173,39 @@ app.get(["/bds/log", "/log"], CheckToken, (req, res) => {
|
||||
|
||||
// Server Info
|
||||
app.get("/bds/info/server", ({res}) => {
|
||||
let ServerRunner = require("./BdsManegerServer").BdsRun;
|
||||
if (!ServerRunner)ServerRunner = {};
|
||||
try {
|
||||
const BdsConfig = BdsManegerCore.BdsSettings.GetJsonConfig();
|
||||
const Players = JSON.parse(fs.readFileSync(BdsManegerCore.BdsSettings.GetPaths("player"), "utf8"))[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)));
|
||||
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 = {
|
||||
version: BdsConfig.server.versions[BdsSettings.GetPlatform()],
|
||||
Platform: BdsSettings.GetPlatform(),
|
||||
players: {
|
||||
online: Online.length,
|
||||
offline: Offline.length,
|
||||
},
|
||||
Config: BdsManegerCore.BdsSettings.GetJsonConfig(),
|
||||
Process: {
|
||||
PID: ServerRunner.pid || 0,
|
||||
Uptime: ServerRunner.uptime || 0,
|
||||
StartTime: ServerRunner.StartTime || NaN,
|
||||
}
|
||||
}
|
||||
res.json(Info);
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
error: "Backend Error",
|
||||
message: `${error}`
|
||||
});
|
||||
const ServerSessions = require("./BdsManegerServer").GetSessions();
|
||||
const ServerRunner = Object.keys(ServerSessions).map(session => ServerSessions[session]).map(a => ({
|
||||
UUID: a.uuid || "",
|
||||
PID: a.PID || 0,
|
||||
Uptime: a.Uptime || 0,
|
||||
StartTime: a.StartTime || NaN
|
||||
}));
|
||||
const BdsConfig = BdsManegerCore.BdsSettings.GetJsonConfig();
|
||||
const Players = JSON.parse(fs.readFileSync(BdsManegerCore.BdsSettings.GetPaths("player"), "utf8"))[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)));
|
||||
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)))
|
||||
|
||||
// Delete Info
|
||||
delete BdsConfig.telegram;
|
||||
delete BdsConfig.cloud;
|
||||
|
||||
const Info = {
|
||||
version: BdsConfig.server.versions[BdsSettings.GetPlatform()],
|
||||
Platform: BdsSettings.GetPlatform(),
|
||||
players: {
|
||||
online: Online.length,
|
||||
offline: Offline.length,
|
||||
},
|
||||
Config: BdsConfig,
|
||||
Process: ServerRunner
|
||||
}
|
||||
return res.json(Info);
|
||||
});
|
||||
|
||||
// Create Backup
|
||||
app.get("/bds/backup", CheckToken, ({res}) => {
|
||||
const BackupBuffer = BdsManegerCore.BdsBackup.CreateBackup();
|
||||
return res.send(BackupBuffer.Buffer);
|
||||
});
|
||||
|
||||
// Download Server
|
||||
|
Reference in New Issue
Block a user