This repository has been archived on 2024-01-16. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Maneger/index.js
Matheus Sampaio Queiroga 314c25c3a8 Remove Jsprismarine and add spigot Basic support
* Moved Azure Deploy files to Azure repositories and removed core files

* jsprismarine was removed due to lack of use and integration with Bds Maneger Core and its applications.

* Updates to Github Actions Workflows.

* It is now possible to run java Servers on Android, but with limitations.

* Modifications in the nexe for the creation of the Bds Maneger Core binaries.

* Now the Docker works as before version 1.1.0 of Bds Maneger Core.

* The docker image has returned to support for arm/v7

* the docker image now uses the `testing` version of Debian and no longer `latest`.

* Basic modifications in cli.

* removed obsolete functions from index.js.
2021-08-16 00:55:17 -03:00

186 lines
5.1 KiB
JavaScript

/* eslint-disable no-irregular-whitespace */
const { resolve } = require("path");
const path = require("path")
const fs = require("fs");
const randomUUID = require("uuid").v4;
const { bds_dir } = require("./lib/BdsSettings");
if (typeof fetch === "undefined") global.fetch = require("node-fetch");
const bds_core_package = resolve(__dirname, "package.json")
module.exports.package_path = bds_core_package
module.exports.package_json = require("./package.json");
module.exports.extra_json = require("./BdsManegerInfo.json");
// Inport and Export Arch
const { arch } = require("./lib/BdsSystemInfo");
module.exports.arch = arch
const { GetJsonConfig, UpdatePlatform, UpdateTelegramToken } = require("./lib/BdsSettings");
// Bds Maneger Core Network
const maneger_ips = require("./src/BdsNetwork")
module.exports.internal_ip = maneger_ips.internal_ip
module.exports.external_ip = maneger_ips.external_ip
module.exports.tmphost = {
host: maneger_ips.host,
Response: maneger_ips.HostResponse
}
// Get Old Method Config
module.exports.getBdsConfig = GetJsonConfig;
/**
* Update Current Platform
*/
module.exports.change_platform = module.exports.platform_update = UpdatePlatform;
/**
* Save Telegram token in Settings File
*/
module.exports.telegram_token_save = UpdateTelegramToken
/**
* The Bds Maneger Core Internal API REST
*
* @param {number} port - The port number, default is 1932
*
* @param {function} callback - The callback function after start API
*/
module.exports.api = require("./src/rest/api");
function token_register(Admin_Scoper = ["web_admin", "admin"]) {
Admin_Scoper = Array.from(Admin_Scoper).filter(scoper => /admin/.test(scoper));
const bds_token_path = path.join(bds_dir, "bds_tokens.json");
let tokens = []
if (fs.existsSync(bds_token_path)) tokens = JSON.parse(fs.readFileSync(bds_token_path, "utf8"));
// Get UUID
const getBdsUUId = randomUUID().split("-");
const bdsuid = "bds_" + (getBdsUUId[0]+getBdsUUId[2].slice(0, 15));
// Save BdsUUID
tokens.push({
token: bdsuid,
date: new Date(),
scopers: Admin_Scoper
});
fs.writeFileSync(bds_token_path, JSON.stringify(tokens, null, 4), "utf8");
console.log(`Bds Maneger API REST token: "${bdsuid}"`);
return bdsuid;
}
/**
* Register tokens to use in Bds Maneger REST and other supported applications
*
* @example token_register()
*/
module.exports.token_register = token_register
/**
* Register tokens to use in Bds Maneger REST and other supported applications
*
* @example token_register()
*/
module.exports.bds_maneger_token_register = token_register
/**
* Update, Get and more to Modifications Bds Settings File
*/
module.exports.BdsSettigs = require("./lib/BdsSettings");
// Requires
const { World_BAckup } = require("./src/BdsBackup");
const { config, get_config } = require("./src/ServerSettings");
const download = require("./src/BdsServersDownload");
const { start, stop, BdsCommand, CronBackups } = require("./src/BdsManegerServer")
/**
* sending commands more simply to the server
*
* @example bds.command("say hello from Bds Maneger")
*/
module.exports.command = BdsCommand
// New management method
// Start Server
/**
* to start the server here in the sera script with child_process, then you will have to use the return function for your log custumization or anything else
*
* @example const server = bds.start();
* server.log(function (log){console.log(log)})
*/
module.exports.start = start
// Stop Server
/**
* use this command for the server, that's all
*/
module.exports.stop = stop
// Create Backup of Bds Maneger Core and Servers along with your maps and settings
/**
* backup your map locally
*/
module.exports.backup = World_BAckup
const { Kill, Detect } = require("./src/CheckKill")
/**
* identify if there are any servers running in the background
*
* @example bds.detect()
* true: if the server is running
* false: if not already
*/
module.exports.detect = Detect
module.exports.bds_detect = Detect
/**
* this function will be used to kill the server in the background
*/
module.exports.kill = Kill
/**
* download some version of the java and Bedrock servers in the highest possible form
*
* use download( version, boolean ) // the boolean is for if you want to force the installation of the server
*
* @example
* bedrock: download("1.16.201.02")
*
* java: download("1.16.5")
*
* any platform: download("latest") || download(true) // It will download the latest version available for download
*/
module.exports.download = download
/**
* use this command to modify server settings
*
* @example set_config({
world: "Bds Maneger",
description: "The Bds Maneger",
gamemode: "creative",
difficulty: "normal",
players: 10,
commands: true,
account: true,
whitelist: true,
port: 19132,
portv6: 19133,
seed: ""
});
*/
module.exports.set_config = config
/**
* takes the server settings in JSON format
*/
module.exports.get_config = get_config
/**
* Load Crontab Backup
*/
module.exports.Cron_Loaded = CronBackups;