Sirherobrine23 Dev #157
@ -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");
|
console.log("Send a \"@stop\" command to stop the server and exit\nUse CTRL + C to force exit\n");
|
||||||
// Start Server
|
// Start Server
|
||||||
const bds_server = bds.start();
|
const bds_server = bds.start();
|
||||||
bds_server.log(echo)
|
bds_server.log(data => process.stdout.write(data));
|
||||||
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.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
|
// CLI Commands
|
||||||
const rl = readline.createInterface({input: process.stdin,output: process.stdout});
|
const rl = readline.createInterface({input: process.stdin,output: process.stdout});
|
||||||
@ -207,8 +211,4 @@ if (bds_version){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start server
|
// 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();
|
if (start && !(server || version || SystemCheck || bds_version || help)) StartServer();
|
||||||
|
22
index.js
22
index.js
@ -7,23 +7,6 @@ const { bds_dir } = require("./lib/BdsSettings");
|
|||||||
|
|
||||||
if (typeof fetch === "undefined") global.fetch = require("node-fetch");
|
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")
|
const bds_core_package = resolve(__dirname, "package.json")
|
||||||
module.exports.package_path = bds_core_package
|
module.exports.package_path = bds_core_package
|
||||||
module.exports.package_json = require("./package.json");
|
module.exports.package_json = require("./package.json");
|
||||||
@ -104,11 +87,6 @@ const { config, get_config } = require("./src/ServerSettings");
|
|||||||
const download = require("./src/BdsServersDownload");
|
const download = require("./src/BdsServersDownload");
|
||||||
const { start, stop, BdsCommand, CronBackups } = require("./src/BdsManegerServer")
|
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
|
* sending commands more simply to the server
|
||||||
*
|
*
|
||||||
|
@ -46,6 +46,7 @@ var Config = {
|
|||||||
java: null,
|
java: null,
|
||||||
pocketmine: null,
|
pocketmine: null,
|
||||||
jsprismarine: null,
|
jsprismarine: null,
|
||||||
|
spigot: null,
|
||||||
},
|
},
|
||||||
Settings: {
|
Settings: {
|
||||||
java: {
|
java: {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
const bds = require("../index")
|
|
||||||
const { join, resolve } = require("path");
|
const { join, resolve } = require("path");
|
||||||
const { readdirSync, existsSync, readFileSync, statSync } = require("fs")
|
const { readdirSync, existsSync, readFileSync, statSync } = require("fs")
|
||||||
const AdmZip = require("adm-zip");
|
const AdmZip = require("adm-zip");
|
||||||
@ -14,7 +13,8 @@ function Backup() {
|
|||||||
pocketmine: GetServerPaths("pocketmine"),
|
pocketmine: GetServerPaths("pocketmine"),
|
||||||
jsprismarine: GetServerPaths("jsprismarine")
|
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);
|
const PathBackup = join(GetPaths("backups"), name);
|
||||||
|
|
||||||
// Bedrock
|
// Bedrock
|
||||||
|
@ -101,8 +101,7 @@ function start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Log file
|
// Log file
|
||||||
|
const LogFile = join(GetPaths("log"), `${GetPlatform()}_${new Date().toString()}_Bds_log.log`);
|
||||||
const LogFile = join(GetPaths("log"), `${bds.date()}_${GetPlatform()}_Bds_log.log`);
|
|
||||||
const LatestLog_Path = path.join(GetPaths("log"), "latest.log");
|
const LatestLog_Path = path.join(GetPaths("log"), "latest.log");
|
||||||
const LogSaveFunction = data => {
|
const LogSaveFunction = data => {
|
||||||
fs.appendFileSync(LogFile, data);
|
fs.appendFileSync(LogFile, data);
|
||||||
@ -123,13 +122,8 @@ 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});
|
||||||
|
|
||||||
const returnFuntion = {
|
// sets bds core commands
|
||||||
uuid: randomUUID(),
|
const command = async function (command = "list", callback = function (){}) {
|
||||||
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) => {
|
return new Promise((resolve) => {
|
||||||
ServerExec.stdin.write(`${command}\n`);
|
ServerExec.stdin.write(`${command}\n`);
|
||||||
if (typeof callback === "function") {
|
if (typeof callback === "function") {
|
||||||
@ -143,19 +137,16 @@ function start() {
|
|||||||
}, 2500);
|
}, 2500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
log: function (logCallback = function(data = ""){data.split("\n").filter(d=>{return (d !== "")}).forEach(l=>console.log(l))}){
|
const log = function (logCallback = data => process.stdout.write(data)){
|
||||||
if (typeof logCallback !== "function") {
|
if (typeof logCallback !== "function") throw new Error("Log Callback is not a 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.stdout.on("data", data => logCallback(data));
|
||||||
ServerExec.stderr.on("data", data => logCallback(data));
|
ServerExec.stderr.on("data", data => logCallback(data));
|
||||||
},
|
};
|
||||||
exit: function (exitCallback = process.exit){if (
|
const exit = function (exitCallback = process.exit){if (
|
||||||
typeof exitCallback === "function") ServerExec.on("exit", code => exitCallback(code));
|
typeof exitCallback === "function") ServerExec.on("exit", code => exitCallback(code));
|
||||||
},
|
};
|
||||||
on: function(action = String(), callback = Function) {
|
const on = function(action = String, callback = Function) {
|
||||||
if (!(action === "all" || action === "connect" || action === "disconnect")) throw new Error("Use some valid action: all, connect, disconnect");
|
if (!(action === "all" || action === "connect" || action === "disconnect")) throw new Error("Use some valid action: all, connect, disconnect");
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
@ -167,37 +158,44 @@ function start() {
|
|||||||
});
|
});
|
||||||
ServerExec.stdout.on("data", data);
|
ServerExec.stdout.on("data", data);
|
||||||
ServerExec.stderr.on("data", data);
|
ServerExec.stderr.on("data", data);
|
||||||
},
|
};
|
||||||
op: function (player = "Steve") {
|
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);
|
let command = BdsInfo.Servers[GetPlatform()].op.replace("{{Player}}", player);
|
||||||
ServerExec.stdin.write(command+"\n");
|
ServerExec.stdin.write(command+"\n");
|
||||||
return command;
|
return command;
|
||||||
},
|
};
|
||||||
deop: function (player = "Steve") {
|
const deop = function (player = "Steve") {
|
||||||
let command = BdsInfo.Servers[GetPlatform()].deop.replace("{{Player}}", player);
|
let command = BdsInfo.Servers[GetPlatform()].deop.replace("{{Player}}", player);
|
||||||
ServerExec.stdin.write(command+"\n");
|
ServerExec.stdin.write(command+"\n");
|
||||||
return command;
|
return command;
|
||||||
},
|
};
|
||||||
ban: function (player = "Steve") {
|
const ban = function (player = "Steve") {
|
||||||
let command = BdsInfo.Servers[GetPlatform()].ban.replace("{{Player}}", player);
|
let command = BdsInfo.Servers[GetPlatform()].ban.replace("{{Player}}", player);
|
||||||
ServerExec.stdin.write(command+"\n");
|
ServerExec.stdin.write(command+"\n");
|
||||||
return command;
|
return command;
|
||||||
},
|
};
|
||||||
kick: function (player = "Steve", text = "you got kicked") {
|
const kick = function (player = "Steve", text = "you got kicked") {
|
||||||
let command = BdsInfo.Servers[GetPlatform()].kick.replace("{{Player}}", player).replace("{{Text}}", text);
|
let command = BdsInfo.Servers[GetPlatform()].kick.replace("{{Player}}", player).replace("{{Text}}", text);
|
||||||
ServerExec.stdin.write(command+"\n");
|
ServerExec.stdin.write(command+"\n");
|
||||||
return command;
|
return command;
|
||||||
},
|
};
|
||||||
tp: function (player = "Steve", cord = {x: 0, y: 128, z: 0}) {
|
const tp = function (player = "Steve", cord = {x: 0, y: 128, z: 0}) {
|
||||||
let command = BdsInfo.Servers[GetPlatform()].tp.replace("{{Player}}", player);
|
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.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("{{Y}}", cord.y); else command = command.replace("{{Y}}", 128);
|
||||||
if (cord.y) command = command.replace("{{Z}}", cord.y); else command = command.replace("{{Z}}", 0);
|
if (cord.y) command = command.replace("{{Z}}", cord.y); else command = command.replace("{{Z}}", 0);
|
||||||
ServerExec.stdin.write(command+"\n");
|
ServerExec.stdin.write(command+"\n");
|
||||||
return command;
|
return command;
|
||||||
|
};
|
||||||
|
const returnFuntion = {
|
||||||
|
uuid: randomUUID(),
|
||||||
|
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;
|
global.BdsExecs[returnFuntion.uuid] = returnFuntion;
|
||||||
return returnFuntion;
|
return returnFuntion;
|
||||||
}
|
}
|
||||||
@ -347,6 +345,7 @@ module.exports = {
|
|||||||
start,
|
start,
|
||||||
BdsCommand,
|
BdsCommand,
|
||||||
stop,
|
stop,
|
||||||
|
GetSessions,
|
||||||
CronBackups: CurrentBackups,
|
CronBackups: CurrentBackups,
|
||||||
Player_Search,
|
Player_Search,
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ const bds = require("../../../index");
|
|||||||
const { token_verify, CheckPlayer } = require("../../UsersAndtokenChecks");
|
const { token_verify, CheckPlayer } = require("../../UsersAndtokenChecks");
|
||||||
const { readFileSync } = require("fs");
|
const { readFileSync } = require("fs");
|
||||||
const docs = require("../../../BdsManegerInfo.json").docs;
|
const docs = require("../../../BdsManegerInfo.json").docs;
|
||||||
|
const { GetSessions } = require("../../BdsManegerServer");
|
||||||
|
|
||||||
// Players info and maneger
|
// Players info and maneger
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
@ -35,13 +36,17 @@ app.get("/actions/:TYPE/:TOKEN/:PLAYER*", (req, res) => {
|
|||||||
const { text } = req.query;
|
const { text } = req.query;
|
||||||
// Pre Check
|
// Pre Check
|
||||||
if (!(token_verify(TOKEN) || CheckPlayer(PLAYER))) return res.status(401).send("Check your parameters");
|
if (!(token_verify(TOKEN) || CheckPlayer(PLAYER))) return res.status(401).send("Check your parameters");
|
||||||
|
const bds = GetSessions()
|
||||||
// Post Check
|
// Post Check
|
||||||
if (TYPE === "ban") res.json({ok: bds.command(`ban ${PLAYER}`)});
|
if (TYPE === "ban") res.json({
|
||||||
else if (TYPE === "kick") res.json({ok: bds.command(`kick ${PLAYER} ${text}`)});
|
ok: bds.ban(PLAYER)
|
||||||
else if (TYPE === "op") res.json({ok: bds.command(`op ${PLAYER}`)});
|
}); else if (TYPE === "kick") res.json({
|
||||||
else if (TYPE === "deop") res.json({ok: bds.command(`deop ${PLAYER}`)});
|
ok: bds.kick(PLAYER, text)
|
||||||
else res.sendStatus(422)
|
}); 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
|
// Actions Redirect
|
||||||
|
Reference in New Issue
Block a user