...
 
Commits (2)
# **licence:** MIT
>Copyright 2019 Family Friendly
>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{"swe":["Startar server...","dina inställningar","server startad!"],"en":["starting server...","your settings","server started!"]}
\ No newline at end of file
{"swe":["Startar server...","dina inställningar","server startad!","laddar plugins..."],"en":["starting server...","your settings","server started!","loading plugins..."]}
\ No newline at end of file
......@@ -2,43 +2,63 @@ const { spawn } = require('child_process');
var fs = require('fs')
, ini = require('ini')
var config = ini.parse(fs.readFileSync('./script/settings.ini', 'utf-8'))
var util = require("./util.js")
var lang = require("./lang.json")
var chalk = require("chalk")
var commands = require("./commands.js")
// testa om valda språket existerar och skicka ett felmedellande om den inte finns
// Check if the selected locale exist and send an error if not
if(!lang[config.main.locale]) return console.log(`lang "${config.main.locale}" does not exist\npermitted: ${Object.keys(lang).join(", ")}`);
// starta alla nödvändaiga proccesser
//send the config to cmd log
console.log(`${lang[config.main.locale][1]}:\n${chalk.blue.underline("MAIN:")}\n${Object.keys(config.main).map(ob=> `${chalk.underline(ob)}:${config.main[ob]}`).join("\n")}\n${chalk.blue.underline("config:")}\n${Object.keys(config.config).map(ob=> `${chalk.underline(ob)}:${config.config[ob]}`).join("\n")}`)
console.log(chalk.green.underline(lang[config.main.locale][0]))
console.time(`startup`)
util.updates(config)
//start child proccess
var mc = spawn("java",['-jar', '-Xms1G','-Xmx1G', '-Dfile.encoding=utf8', config.main.path, config.config.gui ? null:"nogui"])
let userinf = {};
let done = false;
//reload config every set time
setInterval(() => {
try {
var config = ini.parse(fs.readFileSync('./script/settings.ini', 'utf-8'))
} catch(err){
console.log(`${chalk.red("Error in loading INI file:")} ${err}`)
}
},900000)
},config.main.reloadTime)
//child proccess stdout event
mc.stdout.on("data", stdout => {
//buffer => string
let data = stdout.toString();
//if data includes "Done" we will set the done bool to true
if(data.includes("Done")) {
console.timeEnd(`startup`)
console.log(`${chalk.blue(lang[config.main.locale][2])}`)
done=true
}
if(done) {
if(config.main.debug) console.log(data)
//get the user
let user = data.match(/(?<=\<).+(?=\>)/)
user[0] = user[0].toLowerCase()
//get chat msg
let chat = data.match(/(?<=\<.+\>\s).+/gi)
//get IP and username
let ustring = data.match(/(?<=\[.+\]: ).+(?=\[.+\])|(?<=\[.+\]: .+\[\/).+(?=\])/gi)
if(ustring != null && ustring[0] != null && ustring[1] != null) {
if(!userinf[ustring[0]]) userinf[ustring[0]] = {infractions:0, ip:ustring[1]}
......
version=2
[main]
; swe/en
locale=en
......@@ -5,6 +6,10 @@ locale=en
path=notSet
;enbales debug features
debug=false
; time between reload of this ini file
reloadTime=50000
; auto update
aupdate=true
[config]
;prefix for in-game interaction with the client
......
const https = require('https');
const chalk = require("chalk")
exports.load = (_map) => {
let _loadedinf = []
fs.readdirSync("../commands").map(f => {
try {
//require file
let fr = require(`../commands/${f}`)
_loadedinf.push({
name: fr.config.name,
info: fr.config.info,
})
//add command to the map
_map.set(fr.config.name,fr)
} catch(err) {
//lol thats not my problem friendo. deal with it yourself
throw err
}
})
return _loadedinf
}
let vercntrl = `https://gitlab.com/api/v4/projects/12756686/repository/tags`
exports.updates = (conf) => {
https.get(vercntrl, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
data = JSON.parse(data)
if(data[0].release.description > conf.version) {
console.log(`${chalk.green(`new update found (${data[0].release.description})`)}`)
if(conf.main.aupdate) {
console.log(`auto update: ${chalk.green("true : updating")}`)
exec(`git pull https://gitlab.com/familyfriendly/mcutil.git`)
} else {
console.log(`auto update: ${chalk.red("false : not updating")}`)
}
}
});
})
}