Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Jun 30, 2019
2 parents e3fbddb + aabfa67 commit b08af3f
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -93,7 +93,7 @@ If you have any problems with `package-lock.json`, just delete it and try again.
- [ ] Write version bumper script
- [ ] Write resource injector
- [ ] Add custom commands to the config file
- [ ] Config tester check for the modules inside `package.json` (require.resolve?)
- [x] Config tester check for the modules inside `package.json` (require.resolve?)
- [ ] Config tester kill spawned fxserver after 5 seconds
- [ ] Investigate the "fxserver has stopped working" not disappearing when autorestarter kills the server (probably windows detaches it? in that case we would need to PID map and then kill them one by one?)

Expand Down
73 changes: 45 additions & 28 deletions plan.md
@@ -1,35 +1,52 @@

## Instructions
```bash
# Install
$ git clone https://github.com/tabarra/txAdmin && cd txAdmin
$ npm i

//FIXME: change config.json name, cant be both named the same

data/
config.json (web port, admins)
example/
config.json
messages.json
commands.json
data/
players.json
admin.log
FXServer.log
txAdmin_errors.log
extensions/ ?
setup.js
start.js
start.bat


setup.js:
checkup node version
check packages
# Add admin
$ node src/scripts/admin-add.js

# Setup default server
$ node src/scripts/setup.js default

# Start default server
$ node src/index.js default
```

## TODO:
- [x] adapt admin-add
- [ ] adapt config-tester
- [ ] adapt main
- [ ] xxx
- [ ] xxx


## Folder Structure
data/
admins.json
example/
config.json
messages.json
commands.json
data/
players.json
admin.log
FXServer.log
txAdmin_errors.log
extensions/ (?)
start_default.bat



## setup.js
check node version & packages
check for existing settings and --overwrite
start setup webpage asking for:
login/password
first server config (paths & etc)
basic server config (paths & etc)
check if the configs are correct
save data/config.json with password
save the server config as data/default

start.js:
checkup node version
check packages
start txadmin with the 'default' server config (or argv)

2 changes: 1 addition & 1 deletion src/components/authenticator.js
Expand Up @@ -29,7 +29,7 @@ module.exports = class Authenticator {
checkAuth(uname, pwd){
let username = uname.toLowerCase();
let admin = this.admins.find((user) => {
return (username === user.name && bcrypt.compareSync(pwd, user.password_hash))
return (username === user.name.toLowerCase() && bcrypt.compareSync(pwd, user.password_hash))
});
return (admin)? admin : false;
}
Expand Down
56 changes: 56 additions & 0 deletions src/extras/testUtils.js
@@ -0,0 +1,56 @@
//Requires
const fs = require('fs');
const { dir, log, logOk, logWarn, logError, cleanTerminal } = require('./console');
const context = 'TestUtils';


//================================================================
/**
* Check if running on NodeJS v10 LTS
*/
function nodeVersionChecker(){
if(!process.version.startsWith('v10.')){
cleanTerminal();
logError(`FATAL ERROR: txAdmin doesn't support NodeJS ${process.version}, please install NodeJS v10 LTS!`, 'NodeVersionChecker');
process.exit();
}
}


//================================================================
/**
* Check if the packages in package.json were installed
*/
function moduleInstallChecker() {
let errorOut;
try {
let rawFile = fs.readFileSync('package.json');
let parsedFile = JSON.parse(rawFile);
let packages = Object.keys(parsedFile.dependencies)
let missing = [];
packages.forEach(package => {
try {
require.resolve(package);
} catch (error) {
missing.push(package);
}
});
if(missing.length){
errorOut = `Make sure you executed 'npm i'. The following packages are missing:\n` + missing.join(', ');
}
} catch (error) {
errorOut = `Error reading or parsing package.json: ${error.message}`;
}

if(errorOut){
logError(errorOut, 'PackageChecker');
process.exit();
}
}



module.exports = {
nodeVersionChecker,
moduleInstallChecker,
}
14 changes: 8 additions & 6 deletions src/index.js
@@ -1,12 +1,7 @@
//Requires
const { dir, log, logOk, logWarn, logError, cleanTerminal } = require('./extras/console');
const testUtils = require('./extras/testUtils');

//NOTE: temp node version checker
if(!process.version.startsWith('v10.')){
cleanTerminal();
logError(`FATAL ERROR: txAdmin doesn't support NodeJS ${process.version}, please install NodeJS v10 LTS!`);
process.exit();
}

//==============================================================
//FIXME: I should be using dependency injection or something
Expand All @@ -28,6 +23,7 @@ globals = {
resourceNotFound: null //FIXME: temp hack
}


//==============================================================
class txAdmin {
constructor(){
Expand All @@ -40,6 +36,10 @@ class txAdmin {
console.log(motd);
log(">>Starting txAdmin");

//Check node version and packages
testUtils.nodeVersionChecker();
testUtils.moduleInstallChecker();

//Prepare settings
let localConfig = require('./extras/config');
globals.config = localConfig.global;
Expand Down Expand Up @@ -140,9 +140,11 @@ function HandleFatalError(err, context){

process.exit();
}

process.stdin.on('error', (data) => {});
process.stdout.on('error', (data) => {});
process.stderr.on('error', (data) => {});

process.on('unhandledRejection', (err) => {
logError(">>Ohh nooooo - unhandledRejection")
logError(err.message)
Expand Down
6 changes: 5 additions & 1 deletion version.json
@@ -1,5 +1,5 @@
{
"version": "1.0.4",
"version": "1.0.5",
"changelog": "New Interface and too many new features to list here. Please Update.",
"allVersions": [
{
Expand All @@ -21,6 +21,10 @@
{
"version": "1.0.4",
"changelog": "Fixed crashing on fxserver restart."
},
{
"version": "1.0.5",
"changelog": "Hotfix for the login problems. Node version checker"
}
]
}

0 comments on commit b08af3f

Please sign in to comment.