Bds Maneger Server Modification #248
@ -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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -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(() => {
|
||||||
|
@ -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"),
|
||||||
@ -22,25 +22,25 @@ function Backup() {
|
|||||||
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
|
||||||
}
|
}
|
@ -6,6 +6,9 @@ const { Backup } = require("./BdsBackup");
|
|||||||
const { CronJob } = require("cron");
|
const { CronJob } = require("cron");
|
||||||
const BdsSettings = require("../src/lib/BdsSettings");
|
const BdsSettings = require("../src/lib/BdsSettings");
|
||||||
|
|
||||||
|
const PlayerJson = require("./ManegerServer/Players_json");
|
||||||
|
const BasicCommands = require("./ManegerServer/BasicCommands");
|
||||||
|
|
||||||
const ServerSessions = {};
|
const ServerSessions = {};
|
||||||
module.exports.GetSessions = () => ServerSessions;
|
module.exports.GetSessions = () => ServerSessions;
|
||||||
|
|
||||||
@ -117,10 +120,6 @@ module.exports.StartServer = function start() {
|
|||||||
}
|
}
|
||||||
fs.writeFileSync(LatestLog_Path, "");
|
fs.writeFileSync(LatestLog_Path, "");
|
||||||
|
|
||||||
// Player JSON File
|
|
||||||
ServerExec.stdout.on("data", data => Player_Json(data, UpdateUserJSON));
|
|
||||||
ServerExec.stderr.on("data", data => Player_Json(data, UpdateUserJSON));
|
|
||||||
|
|
||||||
// Log File
|
// Log File
|
||||||
ServerExec.stdout.on("data", LogSaveFunction);
|
ServerExec.stdout.on("data", LogSaveFunction);
|
||||||
ServerExec.stderr.on("data", LogSaveFunction);
|
ServerExec.stderr.on("data", LogSaveFunction);
|
||||||
@ -129,194 +128,100 @@ 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 => Player_Json(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
|
||||||
const stop = function (){
|
* @callback
|
||||||
if (CurrentBdsPlatform === "bedrock") {
|
*/
|
||||||
ServerExec.stdin.write("stop\n");
|
const ServerOn = function (FunctionAction = "log", callback = (data = FunctionAction === "log" ? "" : 0) => console.log(data)) {
|
||||||
return "stop";
|
if (!(FunctionAction === "log" || FunctionAction === "exit")) throw new Error("Use some valid FunctionAction: log, exit");
|
||||||
} else if (CurrentBdsPlatform === "dragonfly") {
|
if (FunctionAction === "log") {
|
||||||
ServerExec.kill("SIGKILL");
|
ServerExec.stdout.on("data", data => callback(data));
|
||||||
return "process";
|
ServerExec.stderr.on("data", data => callback(data));
|
||||||
} else if (CurrentBdsPlatform === "java") {
|
} else if (FunctionAction === "exit") ServerExec.on("exit", code => callback(code));
|
||||||
ServerExec.stdin.write("stop\n");
|
else throw new Error("Use some valid FunctionAction: log, exit");
|
||||||
return "stop";
|
return;
|
||||||
} else if (CurrentBdsPlatform === "pocketmine") {
|
|
||||||
ServerExec.stdin.write("stop\n");
|
|
||||||
return "stop";
|
|
||||||
} else if (CurrentBdsPlatform === "spigot") {
|
|
||||||
ServerExec.stdin.write("stop\n");
|
|
||||||
return "stop";
|
|
||||||
} else throw new Error("Bds Core Bad Config Error");
|
|
||||||
};
|
|
||||||
const op = function (player = "Steve") {
|
|
||||||
if (CurrentBdsPlatform === "bedrock") {
|
|
||||||
ServerExec.stdin.write(`op "${player}"\n`);
|
|
||||||
return "op";
|
|
||||||
} else if (CurrentBdsPlatform === "dragonfly") {
|
|
||||||
throw new Error("Dragonfly does not support commands");
|
|
||||||
} else if (CurrentBdsPlatform === "java") {
|
|
||||||
ServerExec.stdin.write(`op ${player}\n`);
|
|
||||||
return "op";
|
|
||||||
} else if (CurrentBdsPlatform === "pocketmine") {
|
|
||||||
ServerExec.stdin.write(`op ${player}\n`);
|
|
||||||
return "op";
|
|
||||||
} else if (CurrentBdsPlatform === "spigot") {
|
|
||||||
ServerExec.stdin.write(`op ${player}\n`);
|
|
||||||
return "op";
|
|
||||||
} else throw new Error("Bds Core Bad Config Error");
|
|
||||||
};
|
|
||||||
const deop = function (player = "Steve") {
|
|
||||||
if (CurrentBdsPlatform === "bedrock") {
|
|
||||||
ServerExec.stdin.write(`deop "${player}"\n`);
|
|
||||||
return "deop";
|
|
||||||
} else if (CurrentBdsPlatform === "dragonfly") {
|
|
||||||
throw new Error("Dragonfly does not support commands");
|
|
||||||
} else if (CurrentBdsPlatform === "java") {
|
|
||||||
ServerExec.stdin.write(`deop ${player}\n`);
|
|
||||||
return "deop";
|
|
||||||
} else if (CurrentBdsPlatform === "pocketmine") {
|
|
||||||
ServerExec.stdin.write(`deop ${player}\n`);
|
|
||||||
return "deop";
|
|
||||||
} else if (CurrentBdsPlatform === "spigot") {
|
|
||||||
ServerExec.stdin.write(`deop ${player}\n`);
|
|
||||||
return "deop";
|
|
||||||
} else throw new Error("Bds Core Bad Config Error");
|
|
||||||
};
|
|
||||||
const ban = function (player = "Steve") {
|
|
||||||
if (CurrentBdsPlatform === "bedrock") {
|
|
||||||
ServerExec.stdin.write(`kick "${player}"\n`);
|
|
||||||
return "kick";
|
|
||||||
} else if (CurrentBdsPlatform === "dragonfly") {
|
|
||||||
throw new Error("Dragonfly does not support commands");
|
|
||||||
} else if (CurrentBdsPlatform === "java") {
|
|
||||||
ServerExec.stdin.write(`ban ${player}\n`);
|
|
||||||
return "ban";
|
|
||||||
} else if (CurrentBdsPlatform === "pocketmine") {
|
|
||||||
ServerExec.stdin.write(`ban ${player}\n`);
|
|
||||||
return "ban";
|
|
||||||
} else if (CurrentBdsPlatform === "spigot") {
|
|
||||||
ServerExec.stdin.write(`ban ${player}\n`);
|
|
||||||
return "ban";
|
|
||||||
} else throw new Error("Bds Core Bad Config Error");
|
|
||||||
};
|
|
||||||
const kick = function (player = "Steve", text = "you got kicked") {
|
|
||||||
if (CurrentBdsPlatform === "bedrock") {
|
|
||||||
ServerExec.stdin.write(`kick "${player}" ${text}\n`);
|
|
||||||
return "kick";
|
|
||||||
} else if (CurrentBdsPlatform === "dragonfly") {
|
|
||||||
throw new Error("Dragonfly does not support commands");
|
|
||||||
} else if (CurrentBdsPlatform === "java") {
|
|
||||||
ServerExec.stdin.write(`kick ${player} ${text}\n`);
|
|
||||||
return "kick";
|
|
||||||
} else if (CurrentBdsPlatform === "pocketmine") {
|
|
||||||
ServerExec.stdin.write(`kick ${player} ${text}\n`);
|
|
||||||
return "kick";
|
|
||||||
} else if (CurrentBdsPlatform === "spigot") {
|
|
||||||
ServerExec.stdin.write(`kick ${player} ${text}\n`);
|
|
||||||
return "kick";
|
|
||||||
} else throw new Error("Bds Core Bad Config Error");
|
|
||||||
};
|
|
||||||
const tp = function (player = "Steve", cord = {x: 0, y: 128, z: 0}) {
|
|
||||||
if (CurrentBdsPlatform === "bedrock") {
|
|
||||||
ServerExec.stdin.write(`tp ${player} ${cord.x} ${cord.y} ${cord.z}\n`);
|
|
||||||
return "tp";
|
|
||||||
} else if (CurrentBdsPlatform === "dragonfly") {
|
|
||||||
throw new Error("Dragonfly does not support commands");
|
|
||||||
} else if (CurrentBdsPlatform === "java") {
|
|
||||||
ServerExec.stdin.write(`tp ${player} ${cord.x} ${cord.y} ${cord.z}\n`);
|
|
||||||
return "tp";
|
|
||||||
} else if (CurrentBdsPlatform === "pocketmine") {
|
|
||||||
ServerExec.stdin.write(`tp ${player} ${cord.x} ${cord.y} ${cord.z}\n`);
|
|
||||||
return "tp";
|
|
||||||
} else if (CurrentBdsPlatform === "spigot") {
|
|
||||||
ServerExec.stdin.write(`tp ${player} ${cord.x} ${cord.y} ${cord.z}\n`);
|
|
||||||
return "tp";
|
|
||||||
} else throw new Error("Bds Core Bad Config Error");
|
|
||||||
};
|
|
||||||
function say(text = ""){
|
|
||||||
if (CurrentBdsPlatform === "bedrock") {
|
|
||||||
ServerExec.stdin.write(`say ${text}\n`);
|
|
||||||
return "say";
|
|
||||||
} else if (CurrentBdsPlatform === "dragonfly") {
|
|
||||||
throw new Error("Dragonfly does not support commands");
|
|
||||||
} else if (CurrentBdsPlatform === "java") {
|
|
||||||
ServerExec.stdin.write(`say ${text}\n`);
|
|
||||||
return "say";
|
|
||||||
} else if (CurrentBdsPlatform === "pocketmine") {
|
|
||||||
ServerExec.stdin.write(`say ${text}\n`);
|
|
||||||
return "say";
|
|
||||||
} else if (CurrentBdsPlatform === "spigot") {
|
|
||||||
ServerExec.stdin.write(`say ${text}\n`);
|
|
||||||
return "say";
|
|
||||||
} else throw new Error("Bds Core Bad Config Error");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mount commands to Return
|
// Mount commands to Return
|
||||||
const returnFuntion = {
|
const returnFuntion = {
|
||||||
uuid: randomUUID(),
|
uuid: randomUUID(),
|
||||||
pid: ServerExec.pid,
|
LogPath: LogFile,
|
||||||
uptime: 0,
|
PID: ServerExec.pid,
|
||||||
StartTime: (new Date()),
|
Uptime: 0,
|
||||||
command, log, exit, on, stop, op, deop, ban, kick, tp, say
|
StartTime: new Date(),
|
||||||
|
on: ServerOn,
|
||||||
|
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, callback) => {
|
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,
|
ServerOn("log", data => {
|
||||||
exitCode: code
|
|
||||||
}));
|
|
||||||
ServerExec.stdout.on("data", (data = "") => {
|
|
||||||
io.emit("ServerLog", {
|
io.emit("ServerLog", {
|
||||||
UUID: returnFuntion.uuid,
|
UUID: returnFuntion.uuid,
|
||||||
data: data,
|
data: data
|
||||||
IsStderr: false
|
|
||||||
});
|
});
|
||||||
});
|
PlayerJson.CreatePlayerJson(data, Actions => {
|
||||||
ServerExec.stderr.on("data", (data = "") => {
|
if (Actions.length === 0) return;
|
||||||
io.emit("ServerLog", {
|
PlayerJson.UpdateUserJSON(Actions);
|
||||||
UUID: returnFuntion.uuid,
|
io.emit("PlayerAction", Actions);
|
||||||
data: data,
|
|
||||||
IsStderr: true
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -326,80 +231,6 @@ module.exports.StartServer = function start() {
|
|||||||
return returnFuntion;
|
return returnFuntion;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Player_Json(data = "", callback = () => {}){
|
|
||||||
const Current_platorm = BdsSettings.GetPlatform();
|
|
||||||
// Bedrock
|
|
||||||
if (Current_platorm === "bedrock") {
|
|
||||||
// "[INFO] Player connected: Sirherobrine, xuid: 2535413418839840",
|
|
||||||
// "[INFO] Player disconnected: Sirherobrine, xuid: 2535413418839840",
|
|
||||||
const BedrockMap = data.split(/\n|\r/gi).map(line => {
|
|
||||||
if (line.includes("connected") || line.includes("disconnected")) {
|
|
||||||
let SplitLine = line.replace(/\[.+\]\s+Player/gi, "").trim().split(/\s+/gi);
|
|
||||||
|
|
||||||
// player
|
|
||||||
let Player = line.trim().replace(/\[.+\]\s+Player/gi, "").trim().replace(/disconnected:|connected:/, "").trim().split(/,\s+xuid:/).filter(a=>a).map(a=>a.trim()).filter(a=>a);
|
|
||||||
|
|
||||||
//
|
|
||||||
let Actions = null;
|
|
||||||
if (/^disconnected/.test(SplitLine[0].trim())) Actions = "disconnect";
|
|
||||||
else if (/^connected/.test(SplitLine[0].trim())) Actions = "connect";
|
|
||||||
|
|
||||||
// Object Map
|
|
||||||
const ObjectReturn = {
|
|
||||||
Player: Player[0],
|
|
||||||
Action: Actions,
|
|
||||||
xuid: Player[1] || null,
|
|
||||||
Date: new Date(),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return
|
|
||||||
return ObjectReturn
|
|
||||||
} else return false;
|
|
||||||
}).filter(a=>a);
|
|
||||||
callback(BedrockMap);
|
|
||||||
}
|
|
||||||
// Java and Pocketmine-MP
|
|
||||||
else if (Current_platorm === "java" || Current_platorm === "pocketmine") {
|
|
||||||
const JavaMap = data.split(/\n|\r/gi).map(line => {
|
|
||||||
if (line.trim().includes("joined the game") || line.includes("left the game")) {
|
|
||||||
line = line.replace(/^\[.+\] \[.+\/.+\]:/, "").trim();
|
|
||||||
let Actions = null;
|
|
||||||
if (/joined/.test(line)) Actions = "connect";
|
|
||||||
else if (/left/.test(line)) Actions = "disconnect";
|
|
||||||
|
|
||||||
// Player Object
|
|
||||||
const JavaObject = {
|
|
||||||
Player: line.replace(/joined the game|left the game/gi, "").trim(),
|
|
||||||
Action: Actions,
|
|
||||||
Date: new Date(),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return JSON
|
|
||||||
return JavaObject
|
|
||||||
} else return false;
|
|
||||||
}).filter(a=>a);
|
|
||||||
callback(JavaMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const UpdateUserJSON = function (New_Object = []){
|
|
||||||
const Player_Json_path = BdsSettings.GetPaths("player");
|
|
||||||
const Current_platorm = BdsSettings.GetPlatform();
|
|
||||||
let Players_Json = {
|
|
||||||
bedrock: [],
|
|
||||||
java: [],
|
|
||||||
pocketmine: [],
|
|
||||||
jsprismarine: [],
|
|
||||||
}
|
|
||||||
if (fs.existsSync(Player_Json_path)) Players_Json = JSON.parse(fs.readFileSync(Player_Json_path, "utf8"));
|
|
||||||
|
|
||||||
// Array
|
|
||||||
Players_Json[Current_platorm] = Players_Json[Current_platorm].concat(New_Object)
|
|
||||||
|
|
||||||
fs.writeFileSync(Player_Json_path, JSON.stringify(Players_Json, null, 2));
|
|
||||||
return Players_Json
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search player in JSON
|
// Search player in JSON
|
||||||
module.exports.Player_Search = function Player_Search(player = "dontSteve") {
|
module.exports.Player_Search = function Player_Search(player = "dontSteve") {
|
||||||
const Player_Json_path = BdsSettings.GetPaths("player"), Current_platorm = BdsSettings.GetPlatform();
|
const Player_Json_path = BdsSettings.GetPaths("player"), Current_platorm = BdsSettings.GetPlatform();
|
||||||
|
@ -42,23 +42,13 @@ async function GetExternalPublicAddress() {
|
|||||||
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();
|
||||||
@ -128,6 +118,5 @@ module.exports = {
|
|||||||
Interfaces,
|
Interfaces,
|
||||||
LocalInterfaces,
|
LocalInterfaces,
|
||||||
GetExternalPublicAddress,
|
GetExternalPublicAddress,
|
||||||
host: null,
|
|
||||||
GetHost
|
GetHost
|
||||||
}
|
}
|
||||||
|
127
src/ManegerServer/BasicCommands.js
Normal file
127
src/ManegerServer/BasicCommands.js
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
const BdsSettings = require("../lib/BdsSettings");
|
||||||
|
const child_process = require("child_process");
|
||||||
|
|
||||||
|
module.exports.BasicCommands = function BasicCommands(ServerExec = child_process.exec("exit 0")) {
|
||||||
|
const CurrentBdsPlatform = BdsSettings.GetPlatform();
|
||||||
|
const stop = function (){
|
||||||
|
if (CurrentBdsPlatform === "bedrock") {
|
||||||
|
ServerExec.stdin.write("stop\n");
|
||||||
|
return "stop";
|
||||||
|
} else if (CurrentBdsPlatform === "dragonfly") {
|
||||||
|
ServerExec.kill("SIGKILL");
|
||||||
|
return "process";
|
||||||
|
} else if (CurrentBdsPlatform === "java") {
|
||||||
|
ServerExec.stdin.write("stop\n");
|
||||||
|
return "stop";
|
||||||
|
} else if (CurrentBdsPlatform === "pocketmine") {
|
||||||
|
ServerExec.stdin.write("stop\n");
|
||||||
|
return "stop";
|
||||||
|
} else if (CurrentBdsPlatform === "spigot") {
|
||||||
|
ServerExec.stdin.write("stop\n");
|
||||||
|
return "stop";
|
||||||
|
} else throw new Error("Bds Core Bad Config Error");
|
||||||
|
};
|
||||||
|
const op = function (player = "Steve") {
|
||||||
|
if (CurrentBdsPlatform === "bedrock") {
|
||||||
|
ServerExec.stdin.write(`op "${player}"\n`);
|
||||||
|
return "op";
|
||||||
|
} else if (CurrentBdsPlatform === "dragonfly") {
|
||||||
|
throw new Error("Dragonfly does not support commands");
|
||||||
|
} else if (CurrentBdsPlatform === "java") {
|
||||||
|
ServerExec.stdin.write(`op ${player}\n`);
|
||||||
|
return "op";
|
||||||
|
} else if (CurrentBdsPlatform === "pocketmine") {
|
||||||
|
ServerExec.stdin.write(`op ${player}\n`);
|
||||||
|
return "op";
|
||||||
|
} else if (CurrentBdsPlatform === "spigot") {
|
||||||
|
ServerExec.stdin.write(`op ${player}\n`);
|
||||||
|
return "op";
|
||||||
|
} else throw new Error("Bds Core Bad Config Error");
|
||||||
|
};
|
||||||
|
const deop = function (player = "Steve") {
|
||||||
|
if (CurrentBdsPlatform === "bedrock") {
|
||||||
|
ServerExec.stdin.write(`deop "${player}"\n`);
|
||||||
|
return "deop";
|
||||||
|
} else if (CurrentBdsPlatform === "dragonfly") {
|
||||||
|
throw new Error("Dragonfly does not support commands");
|
||||||
|
} else if (CurrentBdsPlatform === "java") {
|
||||||
|
ServerExec.stdin.write(`deop ${player}\n`);
|
||||||
|
return "deop";
|
||||||
|
} else if (CurrentBdsPlatform === "pocketmine") {
|
||||||
|
ServerExec.stdin.write(`deop ${player}\n`);
|
||||||
|
return "deop";
|
||||||
|
} else if (CurrentBdsPlatform === "spigot") {
|
||||||
|
ServerExec.stdin.write(`deop ${player}\n`);
|
||||||
|
return "deop";
|
||||||
|
} else throw new Error("Bds Core Bad Config Error");
|
||||||
|
};
|
||||||
|
const ban = function (player = "Steve") {
|
||||||
|
if (CurrentBdsPlatform === "bedrock") {
|
||||||
|
ServerExec.stdin.write(`kick "${player}"\n`);
|
||||||
|
return "kick";
|
||||||
|
} else if (CurrentBdsPlatform === "dragonfly") {
|
||||||
|
throw new Error("Dragonfly does not support commands");
|
||||||
|
} else if (CurrentBdsPlatform === "java") {
|
||||||
|
ServerExec.stdin.write(`ban ${player}\n`);
|
||||||
|
return "ban";
|
||||||
|
} else if (CurrentBdsPlatform === "pocketmine") {
|
||||||
|
ServerExec.stdin.write(`ban ${player}\n`);
|
||||||
|
return "ban";
|
||||||
|
} else if (CurrentBdsPlatform === "spigot") {
|
||||||
|
ServerExec.stdin.write(`ban ${player}\n`);
|
||||||
|
return "ban";
|
||||||
|
} else throw new Error("Bds Core Bad Config Error");
|
||||||
|
};
|
||||||
|
const kick = function (player = "Steve", text = "you got kicked") {
|
||||||
|
if (CurrentBdsPlatform === "bedrock") {
|
||||||
|
ServerExec.stdin.write(`kick "${player}" ${text}\n`);
|
||||||
|
return "kick";
|
||||||
|
} else if (CurrentBdsPlatform === "dragonfly") {
|
||||||
|
throw new Error("Dragonfly does not support commands");
|
||||||
|
} else if (CurrentBdsPlatform === "java") {
|
||||||
|
ServerExec.stdin.write(`kick ${player} ${text}\n`);
|
||||||
|
return "kick";
|
||||||
|
} else if (CurrentBdsPlatform === "pocketmine") {
|
||||||
|
ServerExec.stdin.write(`kick ${player} ${text}\n`);
|
||||||
|
return "kick";
|
||||||
|
} else if (CurrentBdsPlatform === "spigot") {
|
||||||
|
ServerExec.stdin.write(`kick ${player} ${text}\n`);
|
||||||
|
return "kick";
|
||||||
|
} else throw new Error("Bds Core Bad Config Error");
|
||||||
|
};
|
||||||
|
const tp = function (player = "Steve", cord = {x: 0, y: 128, z: 0}) {
|
||||||
|
if (CurrentBdsPlatform === "bedrock") {
|
||||||
|
ServerExec.stdin.write(`tp ${player} ${cord.x} ${cord.y} ${cord.z}\n`);
|
||||||
|
return "tp";
|
||||||
|
} else if (CurrentBdsPlatform === "dragonfly") {
|
||||||
|
throw new Error("Dragonfly does not support commands");
|
||||||
|
} else if (CurrentBdsPlatform === "java") {
|
||||||
|
ServerExec.stdin.write(`tp ${player} ${cord.x} ${cord.y} ${cord.z}\n`);
|
||||||
|
return "tp";
|
||||||
|
} else if (CurrentBdsPlatform === "pocketmine") {
|
||||||
|
ServerExec.stdin.write(`tp ${player} ${cord.x} ${cord.y} ${cord.z}\n`);
|
||||||
|
return "tp";
|
||||||
|
} else if (CurrentBdsPlatform === "spigot") {
|
||||||
|
ServerExec.stdin.write(`tp ${player} ${cord.x} ${cord.y} ${cord.z}\n`);
|
||||||
|
return "tp";
|
||||||
|
} else throw new Error("Bds Core Bad Config Error");
|
||||||
|
};
|
||||||
|
function say(text = ""){
|
||||||
|
if (CurrentBdsPlatform === "bedrock") {
|
||||||
|
ServerExec.stdin.write(`say ${text}\n`);
|
||||||
|
return "say";
|
||||||
|
} else if (CurrentBdsPlatform === "dragonfly") {
|
||||||
|
throw new Error("Dragonfly does not support commands");
|
||||||
|
} else if (CurrentBdsPlatform === "java") {
|
||||||
|
ServerExec.stdin.write(`say ${text}\n`);
|
||||||
|
return "say";
|
||||||
|
} else if (CurrentBdsPlatform === "pocketmine") {
|
||||||
|
ServerExec.stdin.write(`say ${text}\n`);
|
||||||
|
return "say";
|
||||||
|
} else if (CurrentBdsPlatform === "spigot") {
|
||||||
|
ServerExec.stdin.write(`say ${text}\n`);
|
||||||
|
return "say";
|
||||||
|
} else throw new Error("Bds Core Bad Config Error");
|
||||||
|
}
|
||||||
|
return { stop, op, deop, ban, kick, tp, say };
|
||||||
|
}
|
109
src/ManegerServer/Players_json.js
Normal file
109
src/ManegerServer/Players_json.js
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
const fs = require("fs");
|
||||||
|
const BdsSettings = require("../lib/BdsSettings");
|
||||||
|
|
||||||
|
function CreatePlayerJson(data = "", callback = (d = [{Player: "", Action: "connect", Platform: "", xuid: "", Date: ""},{Player: "", Action: "disconnect", Platform: "", xuid: "", Date: ""}]) => console.log(d)){
|
||||||
|
const Current_platorm = BdsSettings.GetPlatform();
|
||||||
|
// Bedrock
|
||||||
|
if (Current_platorm === "bedrock") {
|
||||||
|
// "[INFO] Player connected: Sirherobrine, xuid: 2535413418839840",
|
||||||
|
// "[INFO] Player disconnected: Sirherobrine, xuid: 2535413418839840",
|
||||||
|
const BedrockMap = data.split(/\n|\r/gi).map(line => {
|
||||||
|
if (line.includes("connected")) {
|
||||||
|
let SplitLine = line.replace(/\[.+\]\s+Player/gi, "").trim().split(/\s+/gi);
|
||||||
|
let Actions = "";
|
||||||
|
if (/^disconnected/.test(SplitLine[0].trim())) Actions = "disconnect"; else Actions = "connect";
|
||||||
|
|
||||||
|
// Object Map
|
||||||
|
const ObjectReturn = {
|
||||||
|
Player: line.replace(/^.*connected:/gi, "").replace(/, xuid:.*$/gi, "").trim(),
|
||||||
|
Action: Actions,
|
||||||
|
Platform: Current_platorm,
|
||||||
|
xuid: line.replace(/^.*,.*xuid:/gi, "").trim(),
|
||||||
|
Date: (new Date()).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return ObjectReturn
|
||||||
|
} else return false;
|
||||||
|
}).filter(a=>a);
|
||||||
|
return callback(BedrockMap);
|
||||||
|
}
|
||||||
|
// Java and Pocketmine-MP
|
||||||
|
else if (Current_platorm === "java" || Current_platorm === "pocketmine") {
|
||||||
|
const JavaMap = data.split(/\n|\r/gi).map(line => {
|
||||||
|
if (line.trim().includes("joined the game") || line.includes("left the game")) {
|
||||||
|
line = line.replace(/^\[.+\] \[.+\/.+\]:/, "").trim();
|
||||||
|
let Actions = "";
|
||||||
|
if (/joined/.test(line)) Actions = "connect";
|
||||||
|
else if (/left/.test(line)) Actions = "disconnect";
|
||||||
|
else Actions = null;
|
||||||
|
|
||||||
|
// Player Object
|
||||||
|
const JavaObject = {
|
||||||
|
Player: line.replace(/joined the game|left the game/gi, "").trim(),
|
||||||
|
Action: Actions,
|
||||||
|
Platform: Current_platorm,
|
||||||
|
Date: (new Date()).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return JSON
|
||||||
|
return JavaObject
|
||||||
|
} else return false;
|
||||||
|
}).filter(a=>a);
|
||||||
|
return callback(JavaMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.exports.CreatePlayerJson = CreatePlayerJson;
|
||||||
|
|
||||||
|
function UpdateUserJSON(New_Object = []){
|
||||||
|
const Player_Json_path = BdsSettings.GetPaths("player");
|
||||||
|
const Current_platorm = BdsSettings.GetPlatform();
|
||||||
|
let Players_Json = [
|
||||||
|
{
|
||||||
|
Player: "Steve",
|
||||||
|
Action: "connect",
|
||||||
|
Platform: Current_platorm,
|
||||||
|
Date: (new Date()).toString()
|
||||||
|
}
|
||||||
|
];
|
||||||
|
Players_Json = [];
|
||||||
|
if (fs.existsSync(Player_Json_path)) Players_Json = JSON.parse(fs.readFileSync(Player_Json_path, "utf8"));
|
||||||
|
if (typeof Players_Json.map !== "function") {
|
||||||
|
let OldPlayers_Json = Players_Json;
|
||||||
|
Players_Json = [];
|
||||||
|
OldPlayers_Json.bedrock.forEach(a=>Players_Json.push({
|
||||||
|
Player: a.Player,
|
||||||
|
Action: a.Action,
|
||||||
|
Platform: "bedrock",
|
||||||
|
Date: a.Date
|
||||||
|
}));
|
||||||
|
OldPlayers_Json.java.forEach(a=>Players_Json.push({
|
||||||
|
Player: a.Player,
|
||||||
|
Action: a.Action,
|
||||||
|
Platform: "java",
|
||||||
|
Date: a.Date
|
||||||
|
}));
|
||||||
|
OldPlayers_Json.pocketmine.forEach(a=>Players_Json.push({
|
||||||
|
Player: a.Player,
|
||||||
|
Action: a.Action,
|
||||||
|
Platform: "pocketmine",
|
||||||
|
Date: a.Date
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
// Array
|
||||||
|
Players_Json = Players_Json.concat(New_Object)
|
||||||
|
|
||||||
|
fs.writeFileSync(Player_Json_path, JSON.stringify(Players_Json, null, 2));
|
||||||
|
return Players_Json;
|
||||||
|
}
|
||||||
|
module.exports.UpdateUserJSON = UpdateUserJSON;
|
||||||
|
|
||||||
|
// Search player in JSON
|
||||||
|
module.exports.Player_Search = function Player_Search(player = "dontSteve") {
|
||||||
|
const Player_Json_path = BdsSettings.GetPaths("player");
|
||||||
|
const Players_Json = JSON.parse(fs.readFileSync(Player_Json_path, "utf8"))
|
||||||
|
for (let Player of Players_Json) {
|
||||||
|
if (Player.Player === player.trim()) return Player;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
317
src/api.js
317
src/api.js
@ -55,6 +55,59 @@ app.all(["/v2", "/v2/*"], ({res}) => res.status(401).json({
|
|||||||
Error: "v2 route moved to root routes"
|
Error: "v2 route moved to root routes"
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Check Token
|
||||||
|
function CheckToken (req, res, next) {
|
||||||
|
if (req.method === "GET") {
|
||||||
|
if (req.query.token) {
|
||||||
|
if (BdsChecks.token_verify(req.query.token)) {
|
||||||
|
req.token = req.query.token;
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
} else if (req.headers.token) {
|
||||||
|
if (BdsChecks.token_verify(req.headers.token)) {
|
||||||
|
req.token = req.headers.token;
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
} else if (req.query.Token) {
|
||||||
|
if (BdsChecks.token_verify(req.query.Token)) {
|
||||||
|
req.token = req.query.Token;
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
} else if (req.headers.Token) {
|
||||||
|
if (BdsChecks.token_verify(req.headers.Token)) {
|
||||||
|
req.token = req.headers.token;
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (req.body.token) {
|
||||||
|
if (BdsChecks.token_verify(req.body.token)) {
|
||||||
|
req.token = req.body.token;
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
} else if (req.headers.token) {
|
||||||
|
if (BdsChecks.token_verify(req.headers.token)) {
|
||||||
|
req.token = req.headers.token;
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
} else if (req.body.Token) {
|
||||||
|
if (BdsChecks.token_verify(req.body.Token)) {
|
||||||
|
req.token = req.body.Token;
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
} else if (req.headers.Token) {
|
||||||
|
if (BdsChecks.token_verify(req.headers.Token)) {
|
||||||
|
req.token = req.headers.Token;
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res.status(401).json({
|
||||||
|
error: "Unauthorized",
|
||||||
|
message: "Token is not valid"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ? /bds/
|
// ? /bds/
|
||||||
app.get(["/bds/info", "/bds", "/"], ({res}) => {
|
app.get(["/bds/info", "/bds", "/"], ({res}) => {
|
||||||
try {
|
try {
|
||||||
@ -100,15 +153,42 @@ app.get(["/bds/info", "/bds", "/"], ({res}) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Get Server Log
|
||||||
|
app.get(["/bds/log", "/log"], CheckToken, (req, res) => {
|
||||||
|
const Sessions = BdsManegerCore.BdsManegerServer.GetSessions();
|
||||||
|
return res.json(Object.keys(Sessions).map(session => {
|
||||||
|
try {
|
||||||
|
return {
|
||||||
|
UUID: session,
|
||||||
|
data: fs.readFileSync(Sessions[session].LogPath, "utf8").replace(/\r\n/gi, "\n").split("\n")
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
return {
|
||||||
|
UUID: session,
|
||||||
|
Error: String(err)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
// 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 || "",
|
||||||
|
PID: a.PID || 0,
|
||||||
|
Uptime: a.Uptime || 0,
|
||||||
|
StartTime: a.StartTime || NaN
|
||||||
|
}));
|
||||||
const BdsConfig = BdsManegerCore.BdsSettings.GetJsonConfig();
|
const BdsConfig = BdsManegerCore.BdsSettings.GetJsonConfig();
|
||||||
const Players = JSON.parse(fs.readFileSync(BdsManegerCore.BdsSettings.GetPaths("player"), "utf8"))[BdsSettings.GetPlatform()];
|
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 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 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 = {
|
const Info = {
|
||||||
version: BdsConfig.server.versions[BdsSettings.GetPlatform()],
|
version: BdsConfig.server.versions[BdsSettings.GetPlatform()],
|
||||||
Platform: BdsSettings.GetPlatform(),
|
Platform: BdsSettings.GetPlatform(),
|
||||||
@ -116,144 +196,21 @@ app.get("/bds/info/server", ({res}) => {
|
|||||||
online: Online.length,
|
online: Online.length,
|
||||||
offline: Offline.length,
|
offline: Offline.length,
|
||||||
},
|
},
|
||||||
Config: BdsManegerCore.BdsSettings.GetJsonConfig(),
|
Config: BdsConfig,
|
||||||
Process: {
|
Process: ServerRunner
|
||||||
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}`
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
return res.json(Info);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check Token
|
// Create Backup
|
||||||
// app.all("*", (req, res, next) => {
|
app.get("/bds/backup", CheckToken, ({res}) => {
|
||||||
// if (req.method === "GET") {
|
const BackupBuffer = BdsManegerCore.BdsBackup.CreateBackup();
|
||||||
// if (req.query.token) {
|
return res.send(BackupBuffer.Buffer);
|
||||||
// if (BdsChecks.token_verify(req.query.token)) {
|
|
||||||
// req.token = req.query.token;
|
|
||||||
// return next();
|
|
||||||
// }
|
|
||||||
// } else if (req.headers.token) {
|
|
||||||
// if (BdsChecks.token_verify(req.headers.token)) {
|
|
||||||
// req.token = req.headers.token;
|
|
||||||
// return next();
|
|
||||||
// }
|
|
||||||
// } else if (req.query.Token) {
|
|
||||||
// if (BdsChecks.token_verify(req.query.Token)) {
|
|
||||||
// req.token = req.query.Token;
|
|
||||||
// return next();
|
|
||||||
// }
|
|
||||||
// } else if (req.headers.Token) {
|
|
||||||
// if (BdsChecks.token_verify(req.headers.Token)) {
|
|
||||||
// req.token = req.headers.token;
|
|
||||||
// return next();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// if (req.body.token) {
|
|
||||||
// if (BdsChecks.token_verify(req.body.token)) {
|
|
||||||
// req.token = req.body.token;
|
|
||||||
// return next();
|
|
||||||
// }
|
|
||||||
// } else if (req.headers.token) {
|
|
||||||
// if (BdsChecks.token_verify(req.headers.token)) {
|
|
||||||
// req.token = req.headers.token;
|
|
||||||
// return next();
|
|
||||||
// }
|
|
||||||
// } else if (req.body.Token) {
|
|
||||||
// if (BdsChecks.token_verify(req.body.Token)) {
|
|
||||||
// req.token = req.body.Token;
|
|
||||||
// return next();
|
|
||||||
// }
|
|
||||||
// } else if (req.headers.Token) {
|
|
||||||
// if (BdsChecks.token_verify(req.headers.Token)) {
|
|
||||||
// req.token = req.headers.Token;
|
|
||||||
// return next();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return res.status(401).json({
|
|
||||||
// error: "Unauthorized",
|
|
||||||
// message: "Token is not valid"
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// Whitelist
|
|
||||||
app.get("/bds/info/server/whitelist", (req, res) => {
|
|
||||||
const ServerConfig = BdsManegerCore.BdsSettings.GetJsonConfig();
|
|
||||||
if (ServerConfig.whitelist) {
|
|
||||||
const { Token = null , Action = null } = req.query;
|
|
||||||
const WgiteList = BdsSettings.get_whitelist();
|
|
||||||
if (Action) {
|
|
||||||
if (Action === "add") {
|
|
||||||
if (WgiteList.findIndex(WL => WL.Token === Token) === -1) {
|
|
||||||
WgiteList.push({
|
|
||||||
Token: Token,
|
|
||||||
Time: Date.now()
|
|
||||||
});
|
|
||||||
fs.writeFileSync(BdsManegerCore.BdsSettings.GetPaths("whitelist"), JSON.stringify(WgiteList));
|
|
||||||
res.json({
|
|
||||||
success: true,
|
|
||||||
message: "Whitelist Added"
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
res.json({
|
|
||||||
success: false,
|
|
||||||
message: "Whitelist Already Exist"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (Action === "remove") {
|
|
||||||
if (WgiteList.findIndex(WL => WL.Token === Token) !== -1) {
|
|
||||||
WgiteList.splice(WgiteList.findIndex(WL => WL.Token === Token), 1);
|
|
||||||
fs.writeFileSync(BdsManegerCore.BdsSettings.GetPaths("whitelist"), JSON.stringify(WgiteList));
|
|
||||||
res.json({
|
|
||||||
success: true,
|
|
||||||
message: "Whitelist Removed"
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
res.json({
|
|
||||||
success: false,
|
|
||||||
message: "Whitelist Not Found"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
res.json({
|
|
||||||
success: false,
|
|
||||||
message: "Invalid Action"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
res.json(WgiteList);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
res.status(400).json({
|
|
||||||
error: "Whitelist Not Enabled"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Download Server
|
// Download Server
|
||||||
app.get("/bds/download_server", (req, res) => {
|
app.get("/bds/download_server", CheckToken, (req, res) => {
|
||||||
const { Token = null, Version = "latest" } = req.query;
|
const { Version = "latest" } = req.query;
|
||||||
|
|
||||||
// Check is Token is String
|
|
||||||
if (!Token) return res.status(400).json({
|
|
||||||
error: "Bad Request",
|
|
||||||
message: "Token is required"
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check Token
|
|
||||||
if (!(BdsChecks.token_verify(Token))) return res.status(400).json({
|
|
||||||
error: "Bad Request",
|
|
||||||
message: "Token is invalid"
|
|
||||||
});
|
|
||||||
|
|
||||||
// Download Server
|
// Download Server
|
||||||
BdsManegerCore.download(Version, true).then(() => {
|
BdsManegerCore.download(Version, true).then(() => {
|
||||||
@ -269,8 +226,8 @@ app.get("/bds/download_server", (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Update/Set Server Settings
|
// Update/Set Server Settings
|
||||||
app.post("/bds/save_settings", (req, res) => {
|
app.post("/bds/save_settings", CheckToken, (req, res) => {
|
||||||
const { Token = null,
|
const {
|
||||||
WorldName = "Bds Maneger",
|
WorldName = "Bds Maneger",
|
||||||
ServerDescription = "The Bds Maneger",
|
ServerDescription = "The Bds Maneger",
|
||||||
DefaultGamemode = "creative",
|
DefaultGamemode = "creative",
|
||||||
@ -284,18 +241,6 @@ app.post("/bds/save_settings", (req, res) => {
|
|||||||
port_v6 = "19133",
|
port_v6 = "19133",
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
// Check is Token is String
|
|
||||||
if (!Token) return res.status(400).json({
|
|
||||||
error: "Bad Request",
|
|
||||||
message: "Token is required"
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check Token
|
|
||||||
if (!(BdsChecks.token_verify(Token))) return res.status(400).json({
|
|
||||||
error: "Bad Request",
|
|
||||||
message: "Token is invalid"
|
|
||||||
});
|
|
||||||
|
|
||||||
// Save Settings
|
// Save Settings
|
||||||
try {
|
try {
|
||||||
BdsManegerCore.set_config({
|
BdsManegerCore.set_config({
|
||||||
@ -346,31 +291,21 @@ app.get("/bds/bridge", (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ? /player
|
// ? /player
|
||||||
const GetPlayerJson = (Platform = BdsManegerCore.BdsSettings.GetJsonConfig().server.platform) => ([...{...JSON.parse(fs.readFileSync(BdsManegerCore.BdsSettings.GetPaths("player"), "utf8"))}[Platform]]);
|
app.get("/players", CheckToken, (req, res) => {
|
||||||
app.get("/players", (req, res) => {
|
let PlayerList = JSON.parse(fs.readFileSync(BdsManegerCore.BdsSettings.GetPaths("player"), "utf8"))
|
||||||
const { Platform = BdsSettings.GetPlatform(), Player = null, Action = null } = req.query;
|
const { Platform = null, Player = null, Action = null } = req.query;
|
||||||
let PlayerList = GetPlayerJson(Platform);
|
|
||||||
|
if (Platform) PlayerList = PlayerList.filter(PLS => PLS.Platform === Platform);
|
||||||
if (Player) PlayerList = PlayerList.filter(PLS => PLS.Player === Player);
|
if (Player) PlayerList = PlayerList.filter(PLS => PLS.Player === Player);
|
||||||
if (Action) PlayerList = PlayerList.filter(PLS => PLS.Action === Action);
|
if (Action) PlayerList = PlayerList.filter(PLS => PLS.Action === Action);
|
||||||
|
|
||||||
if (Player || Action) {
|
return res.json(PlayerList);
|
||||||
if (PlayerList.length > 0) res.json(PlayerList);
|
|
||||||
else res.status(404).json({
|
|
||||||
Error: "Player not found",
|
|
||||||
querys: req.query
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
res.json(PlayerList);
|
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Players Actions in Backside Manager
|
// Players Actions in Backside Manager
|
||||||
// kick player
|
// kick player
|
||||||
app.get("/players/kick", (req, res) => {
|
app.get("/players/kick", CheckToken, (req, res) => {
|
||||||
const { Token = null, Player = "Sirherobrine", Text = "You have been removed from the Server" } = req.query;
|
const { Player = "Sirherobrine", Text = "You have been removed from the Server" } = req.query;
|
||||||
if (!Token) return res.status(400).json({ error: "Token is required" });
|
|
||||||
if (!BdsChecks.token_verify(Token)) return res.status(400).json({ error: "Token is invalid" });
|
|
||||||
|
|
||||||
// Kick player
|
// Kick player
|
||||||
const RunnerServer = require("./BdsManegerServer").BdsRun;
|
const RunnerServer = require("./BdsManegerServer").BdsRun;
|
||||||
@ -386,10 +321,8 @@ app.get("/players/kick", (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Ban player
|
// Ban player
|
||||||
app.get("/players/ban", (req, res) => {
|
app.get("/players/ban", CheckToken, (req, res) => {
|
||||||
const { Token = null, Player = "Sirherobrine" } = req.query;
|
const { Player = "Sirherobrine" } = req.query;
|
||||||
if (!Token) return res.status(400).json({ error: "Token is required" });
|
|
||||||
if (!BdsChecks.token_verify(Token)) return res.status(400).json({ error: "Token is invalid" });
|
|
||||||
|
|
||||||
// Ban player
|
// Ban player
|
||||||
const RunnerServer = require("./BdsManegerServer").BdsRun;
|
const RunnerServer = require("./BdsManegerServer").BdsRun;
|
||||||
@ -405,10 +338,8 @@ app.get("/players/ban", (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Op player
|
// Op player
|
||||||
app.get("/players/op", (req, res) => {
|
app.get("/players/op", CheckToken, CheckToken, (req, res) => {
|
||||||
const { Token = null, Player = "Sirherobrine" } = req.query;
|
const { Player = "Sirherobrine" } = req.query;
|
||||||
if (!Token) return res.status(400).json({ error: "Token is required" });
|
|
||||||
if (!BdsChecks.token_verify(Token)) return res.status(400).json({ error: "Token is invalid" });
|
|
||||||
|
|
||||||
// Op player
|
// Op player
|
||||||
const RunnerServer = require("./BdsManegerServer").BdsRun;
|
const RunnerServer = require("./BdsManegerServer").BdsRun;
|
||||||
@ -425,9 +356,7 @@ app.get("/players/op", (req, res) => {
|
|||||||
|
|
||||||
// Deop player
|
// Deop player
|
||||||
app.get("/players/deop", (req, res) => {
|
app.get("/players/deop", (req, res) => {
|
||||||
const { Token = null, Player = "Sirherobrine" } = req.query;
|
const { Player = "Sirherobrine" } = req.query;
|
||||||
if (!Token) return res.status(400).json({ error: "Token is required" });
|
|
||||||
if (!BdsChecks.token_verify(Token)) return res.status(400).json({ error: "Token is invalid" });
|
|
||||||
|
|
||||||
// Deop player
|
// Deop player
|
||||||
const RunnerServer = require("./BdsManegerServer").BdsRun;
|
const RunnerServer = require("./BdsManegerServer").BdsRun;
|
||||||
@ -443,10 +372,8 @@ app.get("/players/deop", (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Say to Server
|
// Say to Server
|
||||||
app.get("/players/say", (req, res) => {
|
app.get("/players/say", CheckToken, (req, res) => {
|
||||||
const { Token = null, Text = "Hello Server" } = req.query;
|
const { Text = "Hello Server" } = req.query;
|
||||||
if (!Token) return res.status(400).json({ error: "Token is required" });
|
|
||||||
if (!BdsChecks.token_verify(Token)) return res.status(400).json({ error: "Token is invalid" });
|
|
||||||
|
|
||||||
// Say to Server
|
// Say to Server
|
||||||
const RunnerServer = require("./BdsManegerServer").BdsRun;
|
const RunnerServer = require("./BdsManegerServer").BdsRun;
|
||||||
@ -463,9 +390,7 @@ app.get("/players/say", (req, res) => {
|
|||||||
|
|
||||||
// Tp player
|
// Tp player
|
||||||
app.get("/players/tp", (req, res) => {
|
app.get("/players/tp", (req, res) => {
|
||||||
const { Token = null, Player = "Sirherobrine", X = 0, Y = 0, Z = 0 } = req.query;
|
const { Player = "Sirherobrine", X = 0, Y = 0, Z = 0 } = req.query;
|
||||||
if (!Token) return res.status(400).json({ error: "Token is required" });
|
|
||||||
if (!BdsChecks.token_verify(Token)) return res.status(400).json({ error: "Token is invalid" });
|
|
||||||
|
|
||||||
// Tp player
|
// Tp player
|
||||||
const RunnerServer = require("./BdsManegerServer").BdsRun;
|
const RunnerServer = require("./BdsManegerServer").BdsRun;
|
||||||
@ -485,6 +410,12 @@ app.get("/players/tp", (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Export API Routes
|
// Export API Routes
|
||||||
|
/**
|
||||||
|
* @param {Number} port_api - Port of API, default is 1932
|
||||||
|
* @callback {Function} callback - Callback function when API is ready
|
||||||
|
*
|
||||||
|
* Launch an API To manage the server Remotely, some features are limited.
|
||||||
|
*/
|
||||||
function API(port_api = 1932, callback = port => {console.log("Bds Maneger Core REST API, http port", port)}){
|
function API(port_api = 1932, callback = port => {console.log("Bds Maneger Core REST API, http port", port)}){
|
||||||
const MapRoutes = app._router.stack.map(d => {if (d.route) {if (d.route.path) return d.route.path;else return d.route.regexp.source;} else return null;}).filter(d => d);
|
const MapRoutes = app._router.stack.map(d => {if (d.route) {if (d.route.path) return d.route.path;else return d.route.regexp.source;} else return null;}).filter(d => d);
|
||||||
app.all("*", (req, res) => {
|
app.all("*", (req, res) => {
|
||||||
@ -503,6 +434,13 @@ function API(port_api = 1932, callback = port => {console.log("Bds Maneger Core
|
|||||||
|
|
||||||
// Bds Maneger Core API token Register
|
// Bds Maneger Core API token Register
|
||||||
const path_tokens = path.join(BdsSettings.bds_dir, "bds_tokens.json");
|
const path_tokens = path.join(BdsSettings.bds_dir, "bds_tokens.json");
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Register new Token to API and more features in the Bds Maneger Core.
|
||||||
|
*
|
||||||
|
* @param {Array} Admin_Scoper - Array of Admin Scoper (Soon will be implemented)
|
||||||
|
* @returns {String} Token - Token of the API
|
||||||
|
*/
|
||||||
function token_register(Admin_Scoper = ["web_admin", "admin"]) {
|
function token_register(Admin_Scoper = ["web_admin", "admin"]) {
|
||||||
Admin_Scoper = Array.from(Admin_Scoper).filter(scoper => /admin/.test(scoper));
|
Admin_Scoper = Array.from(Admin_Scoper).filter(scoper => /admin/.test(scoper));
|
||||||
let tokens = [];
|
let tokens = [];
|
||||||
@ -520,7 +458,14 @@ function token_register(Admin_Scoper = ["web_admin", "admin"]) {
|
|||||||
return bdsuid;
|
return bdsuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bds Maneger Core API Delet token
|
// Bds Maneger Core API Delete token
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Delete Token of the API
|
||||||
|
*
|
||||||
|
* @param {String} Token - Token of the API to delete
|
||||||
|
* @returns {Boolean} - True if the token is deleted
|
||||||
|
*/
|
||||||
function delete_token(Token = "") {
|
function delete_token(Token = "") {
|
||||||
if (!Token) return false;
|
if (!Token) return false;
|
||||||
if (typeof Token !== "string") return false;
|
if (typeof Token !== "string") return false;
|
||||||
|
Reference in New Issue
Block a user