Skip to content

Commit

Permalink
Added txDataPath convar + reorganized global config
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Mar 1, 2020
1 parent b3203b8 commit c2bcadb
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 180 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@

## Installing & Running (Windows/Linux)

If your copy of fxserver doesn't come with txAdmin (`citizen/system_resources/txAdmin`), you can install with the following steps:
If your copy of FXServer doesn't come with txAdmin (`citizen/system_resources/txAdmin`), you can install with the following steps:

```bash
#Inside your fxserver folder, execute:
#Inside your FXServer folder, execute:
cd citizen/system_resources
mv monitor monitorOld
git clone -b conversion https://github.com/tabarra/txAdmin monitor
Expand All @@ -59,10 +59,15 @@ An `txData` folder will be created in your current working directory.
### ConVars
- **serverProfile:** The name of the server profile to start. Profiles are saved/loaded from the current directory inside the `txData` folder.
- **txAdminPort:** The TCP port to use as HTTP Server.
- **txDataPath:** The path of the data folder. The default on Windows is `<citizen_root>/../txData` and on Linux `<citizen_root>/../../../txData`.

ConVar usage example on Windows:
ConVar usage **example** on Windows:
```bash
./run.cmd +set serverProfile dev_server +set txAdminPort 40125
# Windows
./run.cmd +set serverProfile dev_server +set txAdminPort 40125 +set txDataPath "%userprofile%/Desktop/txData"

# Linux
./run.sh +set serverProfile dev_server +set txAdminPort 40125 +set txDataPath "~/fxserver/txData"
```

## License, Credits and Thanks
Expand Down
7 changes: 4 additions & 3 deletions dev_roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ Minor stuff:
- [ ] do I still need the clientCompatVersion convar?
- [ ] clean up the resource injector?
- [x] build path to the global info - check for globals.fxRunner.something
- [ ] add txDataPath convar + docs
- [x] add txDataPath convar + docs
- [x] reorganize globals.info.xxx
- [ ] disable editing the master admin by other admins
- [x] remover messages.json temporariamente
- [x] add the stdout sniffer for wrong port and hangs (didn't tested tho)
- [x] add the stdout sniffer for wrong port and hangs (*must* be improved tho)
- [ ] hide memory usage on linux?
- [ ] clean this dumb file
- [ ] perform end2end test
- [ ] improve monitor?


/e/FiveM/builds/tmpRoot
npx nodemon --watch "../2083/citizen/system_resources/monitor/src/*" --exec "../2083/run.cmd"
npx nodemon --watch "../2116/citizen/system_resources/monitor/src/*" --exec "../2116/run.cmd"

### Feature tasks for collaborators:
- Logger:
Expand Down
2 changes: 1 addition & 1 deletion src/components/authenticator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = class Authenticator {
constructor(config) {
logOk('::Started');
this.config = config;
this.adminsFile = `${globals.info.dataPath}/admins.json`;
this.adminsFile = `${GlobalData.dataPath}/admins.json`;
this.admins = null;
this.registeredPermissions = [
"all_permissions",
Expand Down
7 changes: 2 additions & 5 deletions src/components/configVault.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ module.exports = class ConfigVault {
//NOTE: the bool trick in global.verbose and fxRunner.autostart won't work if we want the default to be true
try {
//Global
cfg.global.verbose = (cfg.global.verbose === 'true' || cfg.global.verbose === true);
cfg.global.verbose = (cfg.global.verbose === 'true' || cfg.global.verbose === true); //TODO: move to GlobalData
cfg.global.publicIP = cfg.global.publicIP || "change-me";
cfg.global.serverName = cfg.global.serverName || "change-me";
cfg.global.language = cfg.global.language || "en";
cfg.global.language = cfg.global.language || "en"; //TODO: move to GlobalData

//Logger
cfg.logger.logPath = cfg.logger.logPath || `${this.serverProfilePath}/logs/admin.log`; //not in template
Expand All @@ -191,9 +191,6 @@ module.exports = class ConfigVault {
cfg.discordBot.commandCooldown = parseInt(cfg.discordBot.commandCooldown) || 30; //not in template

//FXRunner
let buildPath = GetConvar("citizen_root", 'null');
if(buildPath == 'null') throw new Error('citizen_root convar not set')
cfg.fxRunner.buildPath = slash(path.normalize(buildPath+'/'));
cfg.fxRunner.logPath = cfg.fxRunner.logPath || `${this.serverProfilePath}/logs/fxserver.log`; //not in template
cfg.fxRunner.setPriority = cfg.fxRunner.setPriority || "NORMAL";
cfg.fxRunner.onesync = (cfg.fxRunner.onesync === 'true' || cfg.fxRunner.onesync === true);
Expand Down
2 changes: 1 addition & 1 deletion src/components/discordBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ module.exports = class DiscordBot {
}else if(message.content.startsWith('/txadmin')){
//Prepare object
out = new Discord.RichEmbed();
out.setTitle(`${globals.config.serverName} uses txAdmin v${globals.version.current}!`);
out.setTitle(`${globals.config.serverName} uses txAdmin v${GlobalData.txAdminVersion}!`);
out.setColor(0x4DEEEA);
out.setDescription(`Checkout the project:\n GitHub: https://github.com/tabarra/txAdmin\n Discord: https://discord.gg/f3TsfvD`);

Expand Down
20 changes: 10 additions & 10 deletions src/components/fxRunner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ module.exports = class FXRunner {
setupVariables(){
//Defaults
let toExec = [
`+sets txAdmin-version "${globals.version.current}"`,
`+set txAdmin-apiPort "${globals.info.txAdminPort}"`,
`+sets txAdmin-version "${GlobalData.txAdminVersion}"`,
`+set txAdmin-apiPort "${GlobalData.txAdminPort}"`,
`+set txAdmin-apiToken "${globals.webServer.intercomToken}"`,
`+set txAdmin-clientCompatVersion "${globals.version.current}"`,
`+set txAdmin-clientCompatVersion "${GlobalData.txAdminVersion}"`,
];

//Commands
Expand All @@ -73,18 +73,18 @@ module.exports = class FXRunner {

const cliString = cliArgs.join(' ');

if(globals.info.osType === 'Linux'){
if(GlobalData.osType === 'Linux'){
this.spawnVariables = {
shell: '/bin/sh',
cmdArgs: [`${globals.info.buildPath}/run.sh`, cliString]
cmdArgs: [`${GlobalData.fxServerPath}/run.sh`, cliString]
};
}else if(globals.info.osType === 'Windows_NT'){
}else if(GlobalData.osType === 'Windows_NT'){
this.spawnVariables = {
shell: 'cmd.exe',
cmdArgs: ['/c', `${globals.info.buildPath}/run.cmd ${cliString}`]
cmdArgs: ['/c', `${GlobalData.fxServerPath}/run.cmd ${cliString}`]
};
}else{
logError(`OS type not supported: ${globals.info.osType}`);
logError(`OS type not supported: ${GlobalData.osType}`);
process.exit();
}

Expand Down Expand Up @@ -115,7 +115,7 @@ module.exports = class FXRunner {
}
//If the any FXServer configuration is missing
if(this.config.basePath === null || this.config.cfgPath === null){
return logError('Cannot start the server with missing configuration (buildPath || basePath || cfgPath).');
return logError('Cannot start the server with missing configuration (basePath || cfgPath).');
}
//If the server is already alive
if(this.fxChild !== null){
Expand Down Expand Up @@ -159,7 +159,7 @@ module.exports = class FXRunner {
{cwd: this.config.basePath}
);
if(typeof this.fxChild.pid === 'undefined'){
const platformComplaint = (globals.info.osType === 'Windows_NT') ? 'Make sure you have "C:/windows/system32" in your system PATH variables.' : '';
const platformComplaint = (GlobalData.osType === 'Windows_NT') ? 'Make sure you have "C:/windows/system32" in your system PATH variables.' : '';
throw new Error(`Executon of "${this.spawnVariables.shell}" failed. ${platformComplaint}`);
}
pid = this.fxChild.pid.toString();
Expand Down
2 changes: 1 addition & 1 deletion src/components/fxRunner/resourceInjector.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function resetCacheFolder(basePath) {
*/
function getResourcesList() {
try {
let rootDir = globals.info.txAdminResourcePath + '/extensions/';
let rootDir = GlobalData.txAdminResourcePath + '/extensions/';
var paths = fs.readdirSync(rootDir);
let resources = [];
paths.forEach((path)=>{
Expand Down
2 changes: 1 addition & 1 deletion src/components/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module.exports = class Translator {
//If its a custom language
try {
return JSON.parse(fs.readFileSync(
`${globals.info.dataPath}/locale/${lang}.json`,
`${GlobalData.dataPath}/locale/${lang}.json`,
'utf8'
));
} catch (error) {
Expand Down
10 changes: 5 additions & 5 deletions src/components/webServer/ctxUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const getRenderErrorText = (view, error, data) => {
}
const getWebViewPath = (view) => {
if(view.includes('..')) throw new Error('Path Traversal?');
return path.join(globals.info.txAdminResourcePath, 'web/', view+'.html');
return path.join(GlobalData.txAdminResourcePath, 'web/', view+'.html');
}

//Squirrelly Filters
Expand All @@ -46,8 +46,8 @@ sqrl.defineFilter("n2br", (x)=>{
async function renderMasterView(view, reqSess, data){
if(isUndefined(data)) data = {};
data.headerTitle = (!isUndefined(data.headerTitle))? `${data.headerTitle} - txAdmin` : 'txAdmin';
data.txAdminVersion = globals.version.current;
data.fxserverVersion = `FXServer ${globals.info.fxserverVersion}`;
data.txAdminVersion = GlobalData.txAdminVersion;
data.fxserverVersion = `FXServer ${GlobalData.fxServerVersion}`;
data.adminUsername = (reqSess && reqSess.auth && reqSess.auth.username)? reqSess.auth.username : 'unknown user';
data.profilePicture = (reqSess && reqSess.auth && reqSess.auth.picture)? reqSess.auth.picture : 'img/default_avatar.png';
data.isTempPassword = (reqSess && reqSess.auth && reqSess.auth.isTempPassword);
Expand Down Expand Up @@ -87,8 +87,8 @@ async function renderLoginView(data){
// data.template = 'normal';
// data.template = 'justMessage';
data.config = globals.info.serverProfile;
data.txAdminVersion = globals.version.current;
data.fxserverVersion = globals.info.fxserverVersion;
data.txAdminVersion = GlobalData.txAdminVersion;
data.fxserverVersion = GlobalData.fxServerVersion;

let out;
try {
Expand Down
8 changes: 4 additions & 4 deletions src/components/webServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module.exports = class WebServer {
}
});
//Setting up additional middlewares:
this.app.use(KoaServe(path.join(globals.info.txAdminResourcePath, 'web/public'), {index: false, defer: false}));
this.app.use(KoaServe(path.join(GlobalData.txAdminResourcePath, 'web/public'), {index: false, defer: false}));
this.app.use(this.sessionInstance);
this.app.use(KoaBodyParser({jsonLimit}));

Expand Down Expand Up @@ -151,7 +151,7 @@ module.exports = class WebServer {
let urlConvar = GetConvar('web_baseUrl', 'false');
if(validUrlRegex.test(urlConvar)){
logOk(`::Listening at https://${urlConvar}/`);
globals.info.cfxUrl = urlConvar;
GlobalData.cfxUrl = urlConvar;
clearInterval(getUrlInterval);
}
} catch (error) {}
Expand All @@ -173,8 +173,8 @@ module.exports = class WebServer {
logError(`Failed to start HTTP server, port ${error.port} already in use.`);
process.exit();
});
this.httpServer.listen(globals.info.txAdminPort, '0.0.0.0', () => {
logOk(`::Listening at http://localhost:${globals.info.txAdminPort}/`);
this.httpServer.listen(GlobalData.txAdminPort, '0.0.0.0', () => {
logOk(`::Listening at http://localhost:${GlobalData.txAdminPort}/`);
});
} catch (error) {
logError('::Failed to start HTTP server with error:');
Expand Down
41 changes: 0 additions & 41 deletions src/extras/globalInfo.js

This file was deleted.

27 changes: 9 additions & 18 deletions src/extras/setup.js → src/extras/setupProfile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//Requires
const modulename = 'Setup';
const modulename = 'SetupProfile';
const ac = require('ansi-colors');
const fs = require('fs-extra');
const path = require('path');
const slash = require('slash');
const { dir, log, logOk, logWarn, logError} = require('./console')(modulename);
const osType = require('os').type();

//Helpers
const printDivider = () => { log('='.repeat(64)) };
Expand Down Expand Up @@ -48,21 +47,14 @@ let defaultConfig = {


//================================================================
module.exports = (serverRoot, serverProfile, profilePath) => {
module.exports = (osType, fxServerPath, fxServerVersion, serverProfile, profilePath) => {
printDivider();
//Sanity check presence of profile
if (fs.existsSync(profilePath)) {
logError(`There is already a profile named '${serverProfile}'.`);
process.exit();
}

let citizenRootConvar = GetConvar('citizen_root', 'false');
if(citizenRootConvar == 'false'){
logError(`citizen_root convar not set`);
process.exit();
}
const citizenRoot = cleanPath(citizenRootConvar);

//Create new profile folder
log('Creating new profile folder...');
try {
Expand All @@ -78,20 +70,19 @@ module.exports = (serverRoot, serverProfile, profilePath) => {
process.exit();
}
logOk(`Server profile was saved in '${profilePath}'`);


//Saving start.bat
if(osType == 'Windows_NT'){
try {
let batch = `@echo off\r\n${citizenRoot}/run.cmd +set serverProfile "${serverProfile}"\r\npause`;
fs.writeFileSync(`${serverRoot}/start_${serverProfile}.bat`, batch);
let batName = `start_${fxServerVersion}_${serverProfile}.bat`;
let batFolder = path.resolve(fxServerPath, '..');
let batData = `@echo off\r\n${fxServerPath}/run.cmd +set serverProfile "${serverProfile}"\r\npause`;
fs.writeFileSync(path.join(batFolder, batName), batData);
logOk(`You can use ${batFolder}\\${ac.inverse(batName)} to start this profile.`);
} catch (error) {
logWarn(`Failed to create 'start_${serverProfile}.bat' in the current folder.`);
logWarn(`Failed to create '${batName}' in ${batFolder}.`);
}
}

logOk(`To start with this profile add the following argument: +set serverProfile "${serverProfile}"`);
if(osType == 'Windows_NT'){
logOk(`You can also run ` + ac.inverse(` start_${serverProfile}.bat `) + ` added to this folder.`);
}
printDivider();
}
2 changes: 1 addition & 1 deletion src/extras/updateChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = async () => {
globals.version.latest = rVer.version;
globals.version.changelog = rVer.changelog;
globals.version.allVersions = rVer.allVersions || [{version: rVer.version, changelog: rVer.changelog}];
if(globals.version.current !== rVer.version){
if(GlobalData.txAdminVersion !== rVer.version){
logWarn(`A new version (v${rVer.version}) is available for txAdmin - https://github.com/tabarra/txAdmin`, 'UpdateChecker');
}
} catch (error) {
Expand Down
Loading

0 comments on commit c2bcadb

Please sign in to comment.