Move files from Scripts/ to src/ and add 'on' to start server. #144

Merged
Sirherobrine23 merged 8 commits from Changes-and-move-Scripts-dir into main 2021-08-02 22:33:21 +00:00
4 changed files with 68 additions and 42 deletions
Showing only changes of commit e987876261 - Show all commits

View File

@ -32,7 +32,7 @@ if (kill) bds.kill();
if (server) UpdatePlatform(server); if (server) UpdatePlatform(server);
function StartServer(){ function StartServer(){
const { Servers } = require("../../lib/ServerURL"); const { Servers } = require("../lib/ServerURL");
// Check Server Update // Check Server Update
if (Versions[GetPlatform()] !== null) { if (Versions[GetPlatform()] !== null) {
if (Versions[GetPlatform()] !== Servers.latest[GetPlatform()]) { if (Versions[GetPlatform()] !== Servers.latest[GetPlatform()]) {

View File

@ -27,10 +27,12 @@ module.exports.package_json = require("./package.json");
module.exports.extra_json = require("./BdsManegerInfo.json"); module.exports.extra_json = require("./BdsManegerInfo.json");
const { bds_dir } = require("./lib/BdsSettings"); const { bds_dir } = require("./lib/BdsSettings");
const { arch } = require("./lib/BdsSystemInfo");
const { GetPaths, GetJsonConfig, UpdatePlatform, UpdateTelegramToken, GetTelegramToken } = require("./lib/BdsSettings") // Inport and Export Arch
const { arch } = require("./lib/BdsSystemInfo");
module.exports.arch = arch module.exports.arch = arch
const { GetJsonConfig, UpdatePlatform, UpdateTelegramToken, GetTelegramToken } = require("./lib/BdsSettings");
if (typeof fetch === "undefined") global.fetch = require("node-fetch"); if (typeof fetch === "undefined") global.fetch = require("node-fetch");
const maneger_ips = require("./src/external_ip") const maneger_ips = require("./src/external_ip")
@ -42,26 +44,7 @@ module.exports.change_platform = module.exports.platform_update = UpdatePlatform
module.exports.telegram_token_save = UpdateTelegramToken module.exports.telegram_token_save = UpdateTelegramToken
module.exports.api = require("./src/rest/api"); module.exports.api = require("./src/rest/api");
// ------------ // Telegram
const user_file_connected = GetPaths("player");
module.exports.players_files = user_file_connected
if (!(fs.existsSync(user_file_connected))) {
let config = {};
config["bedrock"] = {};
config["java"] = {};
config["pocketmine"] = {};
config["jsprismarine"] = {};
let NewJson = JSON.stringify(config, null, 4);
fs.writeFileSync(user_file_connected, NewJson);
}
const file_user_check = fs.readFileSync(user_file_connected, "utf8");
try {
JSON.parse(file_user_check)
} catch (error) {
fs.renameSync(user_file_connected, `${user_file_connected}_old_${Math.random()}_${new Date().getDate()}_${new Date().getMonth()}_${new Date().getFullYear()}.json`)
}
module.exports.telegram_token = GetTelegramToken(); module.exports.telegram_token = GetTelegramToken();
function token_register() { function token_register() {

View File

@ -77,11 +77,11 @@ function GetKernel() {
else return `Amazon AWS Cloud ${process.arch}: ${require("os").cpus()[0].model}`; else return `Amazon AWS Cloud ${process.arch}: ${require("os").cpus()[0].model}`;
// Windows WSL 1 // Windows WSL 1
case /WSL2|microsft/.test(str):
return "Microsoft WSL 2";
// Windows WSL 2
case /microsoft/.test(str): case /microsoft/.test(str):
return "Microsoft WSL 1"; return "Microsoft WSL 1";
// Windows WSL 2
case /Microsoft/.test(str):
return "Microsoft WSL 2";
// Azure Virtual Machinime (VM) // Azure Virtual Machinime (VM)
case /[aA]zure/.test(str): case /[aA]zure/.test(str):

View File

@ -7,7 +7,6 @@ const { randomUUID } = require("crypto");
// Bds Maneger Inports // Bds Maneger Inports
const commandExists = require("../lib/commandExist"); const commandExists = require("../lib/commandExist");
const BdsDetect = require("./CheckKill").Detect; const BdsDetect = require("./CheckKill").Detect;
const saveUser = require("./PlayersSave");
const bds = require("../index"); const bds = require("../index");
const { GetServerPaths, GetPaths, GetServerSettings, GetPlatform } = require("../lib/BdsSettings"); const { GetServerPaths, GetPaths, GetServerSettings, GetPlatform } = require("../lib/BdsSettings");
const BdsInfo = require("../BdsManegerInfo.json"); const BdsInfo = require("../BdsManegerInfo.json");
@ -15,19 +14,36 @@ const BdsInfo = require("../BdsManegerInfo.json");
// Set bdsexec functions // Set bdsexec functions
global.BdsExecs = {}; global.BdsExecs = {};
const UpdateUserJSON = function (Object = Object){} const UpdateUserJSON = function (New_Object = new Array()){
const Player_Json_path = GetPaths("player");
const Player_Actions = function (data = "aaaaaa\n\n\naa", action = "connect", callback = Function){
const Current_platorm = GetPlatform(); const Current_platorm = 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
}
const Player_Json = function (data = "aaaaaa\n\n\naa"){
const Current_platorm = GetPlatform();
// Bedrock
if (Current_platorm === "bedrock") { if (Current_platorm === "bedrock") {
// "[INFO] Player connected: Sirherobrine, xuid: 2535413418839840", // "[INFO] Player connected: Sirherobrine, xuid: 2535413418839840",
// "[INFO] Player disconnected: Sirherobrine, xuid: 2535413418839840", // "[INFO] Player disconnected: Sirherobrine, xuid: 2535413418839840",
let newdata = data.split(/\n|\r/gi).map(line => { let BedrockMap = data.split(/\n|\r/gi).map(line => {
if (line.includes("connected:")) { if (line.includes("connected:")) {
let SplitLine = line.replace(/\[INFO\]\s+Player/, "").trim().split(/\s+/gi); let SplitLine = line.replace(/\[INFO\]\s+Player/, "").trim().split(/\s+/gi);
// player // player
let Player = line.trim().replace(/disconnected\:|connected\:/, "").trim().split(/,\s+xuid\:/).filter(a=>a).map(a=>a.trim()).filter(a=>a); let Player = line.trim().replace(/disconnected:|connected:/, "").trim().split(/,\s+xuid:/).filter(a=>a).map(a=>a.trim()).filter(a=>a);
// Object Map // Object Map
const ObjectReturn = { const ObjectReturn = {
@ -41,6 +57,30 @@ const Player_Actions = function (data = "aaaaaa\n\n\naa", action = "connect", ca
return ObjectReturn; return ObjectReturn;
} else return false; } else return false;
}).filter(a=>a); }).filter(a=>a);
UpdateUserJSON(BedrockMap);
}
// Java
else if (Current_platorm === "java") {
let 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 = "disconect";
// 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);
UpdateUserJSON(JavaMap);
} }
} }
@ -119,11 +159,12 @@ function start() {
// Post Start // Post Start
if (GetPlatform() === "java") { if (GetPlatform() === "java") {
ServerExec.stdout.on("data", function(data){
const eula_file = path.join(GetServerPaths("java"), "eula.txt"); const eula_file = path.join(GetServerPaths("java"), "eula.txt");
if (data.includes("agree") && data.includes("EULA")) fs.writeFileSync(eula_file, fs.readFileSync(eula_file, "utf8").split("eula=false").join("eula=true")); console.log(fs.readFileSync(eula_file, "utf8"));
if (fs.readFileSync(eula_file, "utf8").includes("eula=false")) {
fs.writeFileSync(eula_file, fs.readFileSync(eula_file, "utf8").replaceAll("eula=false", "eula=true"));
throw new Error("Restart application/CLI") throw new Error("Restart application/CLI")
}); }
} }
// Log file // Log file
@ -137,11 +178,13 @@ function start() {
} }
fs.writeFileSync(LatestLog_Path, ""); fs.writeFileSync(LatestLog_Path, "");
// save User in Json // Player JSON File
ServerExec.stdout.on("data", data => saveUser(data)); ServerExec.stderr.on("data", data => saveUser(data)); ServerExec.stdout.on("data", Player_Json);
ServerExec.stderr.on("data", Player_Json);
// Log File // Log File
ServerExec.stdout.on("data", LogSaveFunction); ServerExec.stderr.on("data", LogSaveFunction); ServerExec.stdout.on("data", LogSaveFunction);
ServerExec.stderr.on("data", LogSaveFunction);
// Global and Run // Global and Run
global.bds_log_string = "" global.bds_log_string = ""
@ -154,13 +197,13 @@ function start() {
return BdsInfo.Servers[GetPlatform()].stop; return BdsInfo.Servers[GetPlatform()].stop;
}, },
command: async function (command = "list", callback = data => console.log(data)){ command: async function (command = "list", callback = data => console.log(data)){
return new Promise((resolve, reject) => { return new Promise((resolve) => {
ServerExec.stdin.write(`${command}\n`); ServerExec.stdin.write(`${command}\n`);
if (typeof callback === "function") { if (typeof callback === "function") {
const TempLog = [] const TempLog = []
const ControlTempHost = data => {TempLog.push(data); return data;} const ControlTempHost = data => {TempLog.push(data); return data;}
ServerExec.stdout.on(data, data => ControlTempHost(data)); ServerExec.stdout.on("data", data => ControlTempHost(data));
ServerExec.stderr.on(data, data => ControlTempHost(data)); ServerExec.stderr.on("data", data => ControlTempHost(data));
setTimeout(() => { setTimeout(() => {
callback(TempLog.join("\n")); callback(TempLog.join("\n"));
resolve(TempLog.join("\n")); resolve(TempLog.join("\n"));