Pocketmine init #79
@ -2,7 +2,7 @@ const { existsSync, mkdirSync, writeFileSync, chmodSync } = require("fs")
|
||||
const { resolve, join } = require("path")
|
||||
const binFolder = resolve((process.env.USERPROFILE||process.env.HOME), "bds_core", "bin")
|
||||
|
||||
if (typeof fetch === "undefined") {var fetch = require("node-fetch")}
|
||||
if (typeof fetch === "undefined") {global.fetch = require("node-fetch")}
|
||||
(function (){
|
||||
if (require("command-exists").sync("curl")) {console.log("Curl is already installed.");process.exit(0)}
|
||||
else {
|
||||
|
@ -4,7 +4,7 @@ const {exec, execSync} = require("child_process");
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
const {CheckBan} = require("./check");
|
||||
const { resolve } = require("path");
|
||||
const { resolve, join } = require("path");
|
||||
const commandExists = require("command-exists").sync
|
||||
|
||||
module.exports.start = () => {
|
||||
@ -41,6 +41,68 @@ module.exports.start = () => {
|
||||
...process.env,
|
||||
LD_LIBRARY_PATH: bds.bds_dir_bedrock
|
||||
}, cwd: bds.bds_dir_bedrock});
|
||||
start_server.stdout.on("data", function(data){
|
||||
data = data.split("\n")
|
||||
var username;
|
||||
for (let line in data){
|
||||
const value = data[line].split(" ")
|
||||
// const list_player = value
|
||||
const status = value[2]
|
||||
if (status === "connected:"){
|
||||
if (value[3].includes(",")) username = value[3]
|
||||
else username = `${value[3]} ${value[4]}`
|
||||
if (username.slice(-1) === ",") username = username.slice(0, -1)
|
||||
//------------------
|
||||
if (CheckBan(username)) KickPlayer(username)
|
||||
else {
|
||||
console.log("Server Username connected: "+username);
|
||||
const file_users = fs.readFileSync(bds.players_files);
|
||||
const users = JSON.parse(file_users, "utf-8")
|
||||
if (file_users.includes(username)){
|
||||
for (let rem in users){
|
||||
if (users[rem].player === username) {
|
||||
users[rem].connected = true
|
||||
users[rem].date = new Date()
|
||||
users[rem].update.push({
|
||||
date: new Date(),
|
||||
connected: true
|
||||
})
|
||||
}
|
||||
}
|
||||
} else users.push({
|
||||
player: username,
|
||||
date: new Date(),
|
||||
connected: true,
|
||||
update: [
|
||||
{
|
||||
date: new Date(),
|
||||
connected: true,
|
||||
}
|
||||
]
|
||||
})
|
||||
fs.writeFileSync(bds.players_files, JSON.stringify(users, null, 2))
|
||||
}
|
||||
|
||||
} else if (status === "disconnected:"){
|
||||
if (value[3].includes(",")) username = value[3]
|
||||
else username = `${value[3]} ${value[4]}`
|
||||
if (username.slice(-1) === ",") username = username.slice(0, -1)
|
||||
console.log("Server Username disconnected: "+username);
|
||||
const users = JSON.parse(fs.readFileSync(bds.players_files, "utf-8"))
|
||||
for (let rem in users){
|
||||
if (users[rem].player === username) {
|
||||
users[rem].connected = false
|
||||
users[rem].date = new Date()
|
||||
users[rem].update.push({
|
||||
date: new Date(),
|
||||
connected: false
|
||||
})
|
||||
}
|
||||
}
|
||||
fs.writeFileSync(bds.players_files, JSON.stringify(users, null, 2))
|
||||
}
|
||||
}
|
||||
})
|
||||
} else if (process.platform === "darwin") throw Error("We don't have MacOS support yet")
|
||||
else process.exit(210)
|
||||
} else if (plat === "java") {
|
||||
@ -71,7 +133,7 @@ module.exports.start = () => {
|
||||
}
|
||||
else throw Error("Reinstall Pocketmine-MP, PHP binaries not found")
|
||||
console.log(childPorcessEnv.PATH);
|
||||
start_server = exec(`php ${resolve(bds.bds_dir_pocketmine, "PocketMine-MP.phar")}`, {env: {
|
||||
start_server = exec(`php ${join(bds.bds_dir_pocketmine, "PocketMine-MP.phar")}`, {env: {
|
||||
...childPorcessEnv
|
||||
}, cwd: bds.bds_dir_pocketmine});
|
||||
} else throw Error("")
|
||||
@ -89,77 +151,9 @@ module.exports.start = () => {
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
})
|
||||
var logConsoleStream = require("fs").createWriteStream(bds.log_file, {flags: "a"});
|
||||
var latestLog = require("fs").createWriteStream(path.join(bds.bds_dir, "log", "latest.log"), {flags: "w"});
|
||||
start_server.stdout.pipe(logConsoleStream);
|
||||
start_server.stdout.pipe(latestLog);
|
||||
if (bds.bds_config.bds_platform === "bedrock"){
|
||||
start_server.stdout.on("data", function(data){
|
||||
data = data.split("\n")
|
||||
var username;
|
||||
for (let line in data){
|
||||
const value = data[line].split(" ")
|
||||
// const list_player = value
|
||||
const status = value[2]
|
||||
if (status === "connected:"){
|
||||
if (value[3].includes(",")) username = value[3]
|
||||
else username = `${value[3]} ${value[4]}`
|
||||
if (username.slice(-1) === ",") username = username.slice(0, -1)
|
||||
//------------------
|
||||
if (CheckBan(username)) KickPlayer(username)
|
||||
else {
|
||||
console.log("Server Username connected: "+username);
|
||||
const file_users = fs.readFileSync(bds.players_files);
|
||||
const users = JSON.parse(file_users, "utf-8")
|
||||
if (file_users.includes(username)){
|
||||
for (let rem in users){
|
||||
if (users[rem].player === username) {
|
||||
users[rem].connected = true
|
||||
users[rem].date = new Date()
|
||||
users[rem].update.push({
|
||||
date: new Date(),
|
||||
connected: true
|
||||
})
|
||||
}
|
||||
}
|
||||
} else users.push({
|
||||
player: username,
|
||||
date: new Date(),
|
||||
connected: true,
|
||||
update: [
|
||||
{
|
||||
date: new Date(),
|
||||
connected: true,
|
||||
}
|
||||
]
|
||||
})
|
||||
fs.writeFileSync(bds.players_files, JSON.stringify(users, null, 2))
|
||||
}
|
||||
|
||||
} else if (status === "disconnected:"){
|
||||
if (value[3].includes(",")) username = value[3]
|
||||
else username = `${value[3]} ${value[4]}`
|
||||
if (username.slice(-1) === ",") username = username.slice(0, -1)
|
||||
console.log("Server Username disconnected: "+username);
|
||||
const users = JSON.parse(fs.readFileSync(bds.players_files, "utf-8"))
|
||||
for (let rem in users){
|
||||
if (users[rem].player === username) {
|
||||
users[rem].connected = false
|
||||
users[rem].date = new Date()
|
||||
users[rem].update.push({
|
||||
date: new Date(),
|
||||
connected: false
|
||||
})
|
||||
}
|
||||
}
|
||||
fs.writeFileSync(bds.players_files, JSON.stringify(users, null, 2))
|
||||
}
|
||||
}
|
||||
})
|
||||
} else if (bds.bds_config.bds_platform === "java"){
|
||||
console.log("Java is not yet supported the user list");
|
||||
}
|
||||
});
|
||||
start_server.stdout.pipe(fs.createWriteStream(bds.log_file, {flags: "a"}));
|
||||
start_server.stdout.pipe(fs.createWriteStream(path.join(bds.bds_dir, "log", "latest.log"), {flags: "w"}));
|
||||
if (typeof bds_log_string !== "undefined"){bds_log_string = ""}
|
||||
start_server.stdout.on("data", function(data){if (global.bds_log_string === undefined) global.bds_log_string = data;else global.bds_log_string += data})
|
||||
Storage.setItem("bds_status", true);
|
||||
|
@ -96,9 +96,7 @@ server-authoritative-block-breaking=false
|
||||
|
||||
} else if (bds.platform === "java") {
|
||||
hardcore = "false"
|
||||
if (gamemode === "survival") null
|
||||
else if (gamemode === "creative") null
|
||||
else {gamemode = 0;hardcore = "true"}
|
||||
if (gamemode === "hardcore") {gamemode = 0;hardcore = "true"}
|
||||
config_file_content = `enable-jmx-monitoring=false
|
||||
rcon.port=25575
|
||||
level-seed=
|
||||
|
@ -116,7 +116,7 @@ module.exports = function (version, force_install) {
|
||||
if (test.includes("extension_dir")) check_extension_dir = true;
|
||||
console.log(test);
|
||||
}
|
||||
if (check_extension_dir) console.log("Pulando configuração do php.ini");
|
||||
if (check_extension_dir) console.log("Skipping php.ini configuration");
|
||||
else {
|
||||
const phpExtensiosnsDir = resolve(bds_dir_pocketmine, "bin/php7/lib/php/extensions")
|
||||
const phpExtensiosns = readdirSync(phpExtensiosnsDir)
|
||||
|
Reference in New Issue
Block a user