Sirherobrine23 Dev #157

Merged
Sirherobrine23 merged 14 commits from Sirherobrine23_dev into main 2021-08-16 03:55:17 +00:00
16 changed files with 475 additions and 525 deletions
Showing only changes of commit 7a2be7eb4f - Show all commits

View File

@ -54,8 +54,12 @@ function StartServer(){
console.log("Send a \"@stop\" command to stop the server and exit\nUse CTRL + C to force exit\n");
// Start Server
const bds_server = bds.start();
bds_server.log(echo)
bds_server.exit(function (code){if (code === 3221225781) return open("https://docs.the-bds-maneger.org/Bds Maneger core/WindowsFixDll");console.log("leaving the server, status code: ", code);process.exit(code)});
bds_server.log(data => process.stdout.write(data));
bds_server.exit(function (code){
if (code === 3221225781 && process.platform === "win32") return open("https://docs.the-bds-maneger.org/Bds Maneger core/WindowsFixDll");
console.log("leaving the server, status code:", code);
process.exit(code)
});
// CLI Commands
const rl = readline.createInterface({input: process.stdin,output: process.stdout});
@ -207,8 +211,4 @@ if (bds_version){
}
// Start server
function echo(data = ""){
data = data.split("\n").filter(data => {return (data !== "")})
data.forEach(data => console.log(data))
}
if (start && !(server || version || SystemCheck || bds_version || help)) StartServer();

View File

@ -7,23 +7,6 @@ const { bds_dir } = require("./lib/BdsSettings");
if (typeof fetch === "undefined") global.fetch = require("node-fetch");
function date(format) {
const today = new Date(),
yaer = today.getFullYear(),
day = String(today.getDate()).padStart(2, "0"),
month = String(today.getMonth() + 1).padStart(2, "0"),
hour = today.getHours(),
minute = today.getMinutes();
// ---------------------------------------------------------
if (format === "year") return yaer
else if (format === "day") return day
else if (format === "month") return month
else if (format === "hour") return hour
else if (format === "minute") return minute
else if (format === "hour_minu") return `${hour}-${minute}`
else return `${day}-${month}-${yaer}_${hour}-${minute}`
}
const bds_core_package = resolve(__dirname, "package.json")
module.exports.package_path = bds_core_package
module.exports.package_json = require("./package.json");
@ -104,11 +87,6 @@ const { config, get_config } = require("./src/ServerSettings");
const download = require("./src/BdsServersDownload");
const { start, stop, BdsCommand, CronBackups } = require("./src/BdsManegerServer")
/**
* Take the current date
*/
module.exports.BdsDate = module.exports.date = date
/**
* sending commands more simply to the server
*

View File

@ -46,6 +46,7 @@ var Config = {
java: null,
pocketmine: null,
jsprismarine: null,
spigot: null,
},
Settings: {
java: {

View File

@ -1,4 +1,3 @@
const bds = require("../index")
const { join, resolve } = require("path");
const { readdirSync, existsSync, readFileSync, statSync } = require("fs")
const AdmZip = require("adm-zip");
@ -14,7 +13,8 @@ function Backup() {
pocketmine: GetServerPaths("pocketmine"),
jsprismarine: GetServerPaths("jsprismarine")
}
const name = `Bds_Maneger-Backups_${bds.date()}.zip`
const CurrentDate = new Date();
const name = `Bds_Maneger_Core_Backups_${CurrentDate.getDate()}-${CurrentDate.getMonth()}-${CurrentDate.getFullYear()}.zip`
const PathBackup = join(GetPaths("backups"), name);
// Bedrock

View File

@ -101,8 +101,7 @@ function start() {
}
// Log file
const LogFile = join(GetPaths("log"), `${bds.date()}_${GetPlatform()}_Bds_log.log`);
const LogFile = join(GetPaths("log"), `${GetPlatform()}_${new Date().toString()}_Bds_log.log`);
const LatestLog_Path = path.join(GetPaths("log"), "latest.log");
const LogSaveFunction = data => {
fs.appendFileSync(LogFile, data);
@ -123,81 +122,80 @@ 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 command = async function (command = "list", callback = function (){}) {
return new Promise((resolve) => {
ServerExec.stdin.write(`${command}\n`);
if (typeof callback === "function") {
const TempLog = []
const ControlTempHost = data => {TempLog.push(data); return data;}
ServerExec.stdout.on("data", data => ControlTempHost(data));
ServerExec.stderr.on("data", data => ControlTempHost(data));
setTimeout(() => {
callback(TempLog.join("\n"));
resolve(TempLog.join("\n"));
}, 2500);
}
});
};
const log = function (logCallback = data => process.stdout.write(data)){
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));
};
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 => Player_Json(data, function (array_status){
for (let _player of array_status) {
if (action === "all") callback(_player);
else if (_player.Action === action) callback(_player)
}
});
ServerExec.stdout.on("data", data);
ServerExec.stderr.on("data", data);
};
const stop = function (){
ServerExec.stdin.write(BdsInfo.Servers[GetPlatform()].stop+"\n");
return BdsInfo.Servers[GetPlatform()].stop;
};
const op = function (player = "Steve") {
let command = BdsInfo.Servers[GetPlatform()].op.replace("{{Player}}", player);
ServerExec.stdin.write(command+"\n");
return command;
};
const deop = function (player = "Steve") {
let command = BdsInfo.Servers[GetPlatform()].deop.replace("{{Player}}", player);
ServerExec.stdin.write(command+"\n");
return command;
};
const ban = function (player = "Steve") {
let command = BdsInfo.Servers[GetPlatform()].ban.replace("{{Player}}", player);
ServerExec.stdin.write(command+"\n");
return command;
};
const kick = function (player = "Steve", text = "you got kicked") {
let command = BdsInfo.Servers[GetPlatform()].kick.replace("{{Player}}", player).replace("{{Text}}", text);
ServerExec.stdin.write(command+"\n");
return command;
};
const tp = function (player = "Steve", cord = {x: 0, y: 128, z: 0}) {
let command = BdsInfo.Servers[GetPlatform()].tp.replace("{{Player}}", player);
if (cord.x) command = command.replace("{{X}}", cord.x); else command = command.replace("{{X}}", 0);
if (cord.y) command = command.replace("{{Y}}", cord.y); else command = command.replace("{{Y}}", 128);
if (cord.y) command = command.replace("{{Z}}", cord.y); else command = command.replace("{{Z}}", 0);
ServerExec.stdin.write(command+"\n");
return command;
};
const returnFuntion = {
uuid: randomUUID(),
stop: function (){
ServerExec.stdin.write(BdsInfo.Servers[GetPlatform()].stop+"\n");
return BdsInfo.Servers[GetPlatform()].stop;
},
command: async function (command = "list", callback = data => console.log(data)){
return new Promise((resolve) => {
ServerExec.stdin.write(`${command}\n`);
if (typeof callback === "function") {
const TempLog = []
const ControlTempHost = data => {TempLog.push(data); return data;}
ServerExec.stdout.on("data", data => ControlTempHost(data));
ServerExec.stderr.on("data", data => ControlTempHost(data));
setTimeout(() => {
callback(TempLog.join("\n"));
resolve(TempLog.join("\n"));
}, 2500);
}
});
},
log: function (logCallback = function(data = ""){data.split("\n").filter(d=>{return (d !== "")}).forEach(l=>console.log(l))}){
if (typeof logCallback !== "function") {
console.warn("The log callback is not a function using console.log");
logCallback = function(data = ""){data.split("\n").filter(d=>{return (d !== "")}).forEach(l=>console.log(l))}
}
ServerExec.stdout.on("data", data => logCallback(data));
ServerExec.stderr.on("data", data => logCallback(data));
},
exit: function (exitCallback = process.exit){if (
typeof exitCallback === "function") ServerExec.on("exit", code => exitCallback(code));
},
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 => Player_Json(data, function (array_status){
for (let _player of array_status) {
if (action === "all") callback(_player);
else if (_player.Action === action) callback(_player)
}
});
ServerExec.stdout.on("data", data);
ServerExec.stderr.on("data", data);
},
op: function (player = "Steve") {
let command = BdsInfo.Servers[GetPlatform()].op.replace("{{Player}}", player);
ServerExec.stdin.write(command+"\n");
return command;
},
deop: function (player = "Steve") {
let command = BdsInfo.Servers[GetPlatform()].deop.replace("{{Player}}", player);
ServerExec.stdin.write(command+"\n");
return command;
},
ban: function (player = "Steve") {
let command = BdsInfo.Servers[GetPlatform()].ban.replace("{{Player}}", player);
ServerExec.stdin.write(command+"\n");
return command;
},
kick: function (player = "Steve", text = "you got kicked") {
let command = BdsInfo.Servers[GetPlatform()].kick.replace("{{Player}}", player).replace("{{Text}}", text);
ServerExec.stdin.write(command+"\n");
return command;
},
tp: function (player = "Steve", cord = {x: 0, y: 128, z: 0}) {
let command = BdsInfo.Servers[GetPlatform()].tp.replace("{{Player}}", player);
if (cord.x) command = command.replace("{{X}}", cord.x); else command = command.replace("{{X}}", 0);
if (cord.y) command = command.replace("{{Y}}", cord.y); else command = command.replace("{{Y}}", 128);
if (cord.y) command = command.replace("{{Z}}", cord.y); else command = command.replace("{{Z}}", 0);
ServerExec.stdin.write(command+"\n");
return command;
}
command, log, exit, on, stop, op, deop, ban, kick, tp
}
ServerExec.on("exit", ()=>{delete global.BdsExecs[returnFuntion.uuid]});
ServerExec.on("exit", () => delete global.BdsExecs[returnFuntion.uuid]);
global.BdsExecs[returnFuntion.uuid] = returnFuntion;
return returnFuntion;
}
@ -347,6 +345,7 @@ module.exports = {
start,
BdsCommand,
stop,
GetSessions,
CronBackups: CurrentBackups,
Player_Search,
}

View File

@ -5,6 +5,7 @@ const bds = require("../../../index");
const { token_verify, CheckPlayer } = require("../../UsersAndtokenChecks");
const { readFileSync } = require("fs");
const docs = require("../../../BdsManegerInfo.json").docs;
const { GetSessions } = require("../../BdsManegerServer");
// Players info and maneger
app.get("/", (req, res) => {
@ -35,13 +36,17 @@ app.get("/actions/:TYPE/:TOKEN/:PLAYER*", (req, res) => {
const { text } = req.query;
// Pre Check
if (!(token_verify(TOKEN) || CheckPlayer(PLAYER))) return res.status(401).send("Check your parameters");
const bds = GetSessions()
// Post Check
if (TYPE === "ban") res.json({ok: bds.command(`ban ${PLAYER}`)});
else if (TYPE === "kick") res.json({ok: bds.command(`kick ${PLAYER} ${text}`)});
else if (TYPE === "op") res.json({ok: bds.command(`op ${PLAYER}`)});
else if (TYPE === "deop") res.json({ok: bds.command(`deop ${PLAYER}`)});
else res.sendStatus(422)
if (TYPE === "ban") res.json({
ok: bds.ban(PLAYER)
}); else if (TYPE === "kick") res.json({
ok: bds.kick(PLAYER, text)
}); else if (TYPE === "op") res.json({
ok: bds.op(PLAYER)
}); else if (TYPE === "deop") res.json({
ok: bds.deop(PLAYER)
}); else res.sendStatus(422);
});
// Actions Redirect