Code Modifications #261

Merged
Sirherobrine23 merged 8 commits from Sirherobrine23Changes into main 2021-12-07 18:50:16 +00:00
10 changed files with 72 additions and 84 deletions
Showing only changes of commit a58e8d7b3b - Show all commits

View File

@@ -1,10 +1,5 @@
node_modules/
Docker/
!Docker/root_path
.git/
Docker.sh
BuildRunDocker.js
docker_config.json
*.log
Test
test

View File

@@ -1,2 +0,0 @@
test/**
Docker/

View File

@@ -11,7 +11,8 @@
# test files
*.test
*test*.js*
*test*.*js
*Test*.*js
test/
Test/

View File

@@ -3,7 +3,7 @@
// Load Root JSON
const BdsManegerCoreJSONs = {
Package: require("./package.json"),
Extra: require("./BdsManegerInfo.json")
Extra: require("./src/BdsManegerInfo.json")
};
// Bds Maneger Core Version

View File

@@ -1,7 +1,7 @@
// Mount Module Oject
const ModuleExport = {}
import package_json from "./package.json";
import BdsManegerInfo from "./BdsManegerInfo.json";
import BdsManegerInfo from "./src/BdsManegerInfo.json";
const BdsManegerCoreJSONs = {
Package: package_json,

View File

@@ -2,23 +2,16 @@ const child_process = require("child_process");
const fs = require("fs");
const path = require("path");
const { randomUUID } = require("crypto");
const { Backup } = require("./BdsBackup");
const BdsBackup = require("./BdsBackup");
const { CronJob } = require("cron");
const BdsSettings = require("../src/lib/BdsSettings");
const PlayerJson = require("./ManegerServer/Players_json");
const BasicCommands = require("./ManegerServer/BasicCommands");
const ServerSessions = {};
module.exports.GetSessions = () => ServerSessions;
module.exports.GetSessionsArray = () => Object.keys(ServerSessions).map(key => ServerSessions[key]);
const PlayersCallbacks = [];
module.exports.RegisterPlayerGlobalyCallbacks = function RegisterPlayerGlobalyCallbacks(callback){
PlayersCallbacks.push(callback);
}
module.exports.StartServer = function start() {
function StartServer() {
const commandExists = require("../src/lib/commandExist");
const io = require("./api").SocketIO;
const CurrentBdsPlatform = BdsSettings.GetPlatform();
@@ -239,28 +232,26 @@ module.exports.StartServer = function start() {
return returnFuntion;
}
module.exports.CronBackups = BdsSettings.GetCronBackup().map(Crron => {
const Cloud_Backup = {
Azure: require("./clouds/Azure").Uploadbackups,
Driver: require("./clouds/GoogleDriver").Uploadbackups,
Oracle: require("./clouds/OracleCI").Uploadbackups,
}
//
return {
CronFunction: new CronJob(Crron.cron, async () => {
console.log("Starting Server and World Backup");
const CurrentBackup = Backup();
// Azure
if (Crron.Azure) Cloud_Backup.Azure(CurrentBackup.file_name, CurrentBackup.file_path);
else console.info("Azure Backup Disabled");
// Google Driver
if (Crron.Driver) Cloud_Backup.Driver(CurrentBackup.file_name, CurrentBackup.file_path);
else console.info("Google Driver Backup Disabled");
// Oracle Bucket
if (Crron.Oracle) Cloud_Backup.Oracle(CurrentBackup.file_name, CurrentBackup.file_path);
else console.info("Oracle Bucket Backup Disabled");
})
}
const CronBackups = BdsSettings.GetCronBackup().map(CronConfig => {
if (!CronConfig.enabled) return;
const BackupUpload = require("@the-bds-maneger/clouds_uploads");
return new CronJob(CronConfig.cron, async () => {
console.log("Starting Backup, Cron:", CronConfig.cron);
const CurrentBackup = BdsBackup.CreateBackup();
const BackupClass = new BackupUpload(CurrentBackup.Buffer, CurrentBackup.file_name);
BackupClass.upload.GoogleDriver = CronConfig.Driver;
BackupClass.upload.OracleCloudInfrastructure = CronConfig.Oracle;
BackupClass.upload.Azure = CronConfig.Azure;
return await BackupClass.Start();
});
});
module.exports = {
GetSessions: () => ServerSessions,
GetSessionsArray: () => Object.keys(ServerSessions).map(key => ServerSessions[key]),
RegisterPlayerGlobalyCallbacks: function RegisterPlayerGlobalyCallbacks(callback){
PlayersCallbacks.push(callback);
},
StartServer: StartServer,
CronBackups: CronBackups
}

View File

@@ -4,7 +4,7 @@ const { writeFileSync, existsSync, readFileSync, readdirSync, rmSync } = fs;
const { join, resolve } = path;
var AdmZip = require("adm-zip");
const { GetServerPaths, GetPlatform } = require("../src/lib/BdsSettings");
const Extra = require("../BdsManegerInfo.json");
const Extra = require("./BdsManegerInfo.json");
const bds = require("../index");
const Request = require("../src/lib/Requests");

View File

@@ -1,21 +1,25 @@
const { join, basename } = require("path");
const { existsSync, writeFileSync, mkdirSync, readFileSync } = require("fs");
const fs = require("fs");
const path = require("path");
const { existsSync, writeFileSync, mkdirSync, readFileSync } = fs;
const { homedir } = require("os");
const yaml = require("js-yaml");
const deepmerge = require("deepmerge");
// PATHs
const home = homedir();
const bds_dir = join(home, "bds_core");
if (!(existsSync(bds_dir))) mkdirSync(bds_dir, {recursive: true})
const home = homedir(),
bds_dir = path.join(home, "bds_core"),
ExternalPlugins = path.join(bds_dir, "plugins");
if (!(existsSync(bds_dir))) fs.mkdirSync(bds_dir, {recursive: true});
if (!(existsSync(ExternalPlugins))) fs.mkdirSync(ExternalPlugins, {recursive: true});
// Config Base to Bds Maneger Core and others Projects
var Config = {
paths: {
servers: join(bds_dir, "Servers"),
backups: join(bds_dir, "Backups"),
log: join(bds_dir, "Logs"),
player: join(bds_dir, "Players.json")
servers: path.join(bds_dir, "Servers"),
backups: path.join(bds_dir, "Backups"),
log: path.join(bds_dir, "Logs"),
player: path.join(bds_dir, "Players.json")
},
bds: {
enable_tmp_host: false
@@ -67,30 +71,6 @@ var Config = {
pocketmine: true,
jsprismarine: true,
spigot: true,
},
{
username: "Alex",
bedrock: true,
java: true,
pocketmine: true,
jsprismarine: true,
spigot: true,
},
{
username: "steve",
bedrock: true,
java: true,
pocketmine: true,
jsprismarine: true,
spigot: true,
},
{
username: "alex",
bedrock: true,
java: true,
pocketmine: true,
jsprismarine: true,
spigot: true,
}
],
telegram: {
@@ -101,7 +81,7 @@ var Config = {
}
// Config
const ConfigPath = join(bds_dir, "BdsConfig.yaml")
const ConfigPath = path.join(bds_dir, "BdsConfig.yaml")
const SaveConfig = () => writeFileSync(ConfigPath, yaml.dump(Config));
process.on("exit", () => SaveConfig());
@@ -121,16 +101,16 @@ if (!(existsSync(Config.paths["servers"]))) mkdirSync(Config.paths["servers"], {
// Server Paths
const ServersPaths = {
bedrock: join(Config.paths.servers, "Bedrock"),
java: join(Config.paths.servers, "Java"),
pocketmine: join(Config.paths.servers, "Pocketmine-MP"),
dragonfly: join(Config.paths.servers, "Dragonfly_go"),
spigot: join(Config.paths.servers, "Spigot")
bedrock: path.join(Config.paths.servers, "Bedrock"),
java: path.join(Config.paths.servers, "Java"),
pocketmine: path.join(Config.paths.servers, "Pocketmine-MP"),
dragonfly: path.join(Config.paths.servers, "Dragonfly_go"),
spigot: path.join(Config.paths.servers, "Spigot")
}
Object.getOwnPropertyNames(ServersPaths).map(Servers => ServersPaths[Servers]).forEach(Servers => {
if (!(existsSync(Servers))) {
console.log(`Creating the ${basename(Servers)} Folder`);
console.log(`Creating the ${path.basename(Servers)} Folder`);
mkdirSync(Servers, {recursive: true})
}
});
@@ -267,6 +247,8 @@ if (!(existsSync(GetPaths("player")))) {
module.exports = {
bds_dir: bds_dir,
BdsDir: bds_dir,
ExternalPlugins: ExternalPlugins,
ServersPaths: ServersPaths,
GetJsonConfig,
GetPaths,

21
src/lib/LoadPlugin.js Normal file
View File

@@ -0,0 +1,21 @@
const fs = require("fs");
const path = require("path");
const BdsSettings = require("./BdsSettings");
function LoadPlugins() {
return fs.readdirSync(BdsSettings.ExternalPlugins).filter(file => fs.fstatSync(path.join(BdsSettings.ExternalPlugins, file)).isFile()).map(files => {
try {
return require(path.join(BdsSettings.ExternalPlugins, files));
} catch (err) {
console.log(err);
return null;
}
}).filter(plugin => plugin);
}
module.exports.plugin = LoadPlugins();
fs.watch(BdsSettings.ExternalPlugins, () => {
module.exports.plugin = LoadPlugins();
});
module.exports.LoadPlugins = LoadPlugins;