From 0080d68ea45687c9b7cec6211bc28b3472ccaadb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Tabarra?= Date: Wed, 22 May 2019 22:57:19 -0300 Subject: [PATCH] linux support --- README.md | 3 ++- data/server-template.json | 2 +- src/components/fxRunner.js | 31 +++++++++++++++++++++++-------- version.json | 4 ++-- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7d1d1133f..30b2fa36c 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ One of the problems I noticed with the servers out there is that the "bases" are - Monitor server’s CPU/RAM consumption - Real-time playerlist with ping + steam-linked accounts (when available) - OneSync Support (more than 32 slots server) +- Linux Support ## Installation @@ -28,7 +29,7 @@ $ cd fivem-fxadmin $ npm install ``` Copy your `server-template.json` to `server.json` and modify it according to your preferences. -- `buildPath` is the folder containing the files `run.cmd`, `fxserver.exe` and a bunch of DLLs. +- `buildPath` is the folder containing the files `run.cmd`, `fxserver.exe` and a bunch of DLLs in case of Windows, and only `run.sh` in case of Linux. - `basePath` is the folder that **contains** the `resources` folder, usually it's here that you put your `server.cfg`. - `cfgPath` is the absolute or relative path of your `server.cfg`. diff --git a/data/server-template.json b/data/server-template.json index 3bb1b20f3..55f42fbbd 100644 --- a/data/server-template.json +++ b/data/server-template.json @@ -31,6 +31,6 @@ "cfgPath": "C:/Users/Admin/Desktop/server01/server.cfg", "onesync": false, "isLinux": false, - "autostart": true + "autostart": false } } \ No newline at end of file diff --git a/src/components/fxRunner.js b/src/components/fxRunner.js index 5c15b0d6f..f57150a17 100644 --- a/src/components/fxRunner.js +++ b/src/components/fxRunner.js @@ -23,16 +23,31 @@ module.exports = class FXRunner { */ async spawnServer(){ if(this.fxChild !== null) return false; - cleanTerminal(); let onesyncFlag = (this.config.onesync)? '+set onesync_enabled 1' : ''; - //TODO: linux compatibility - this.fxChild = spawn( - "cmd.exe", - ['/c', `${this.config.buildPath}/run.cmd ${onesyncFlag} +exec ${this.config.cfgPath}`], - {cwd: this.config.basePath} - ); - logOk(`::Iniciado com PID ${this.fxChild.pid}!`, context); + let spawnShell = null; + let spawnCmdArgs = null; + if(this.config.isLinux){ + spawnShell = '/bin/bash'; + spawnCmdArgs = [`${this.config.buildPath}/run.sh`, `${onesyncFlag} +exec ${this.config.cfgPath}`]; + }else{ + spawnShell = 'cmd.exe'; + spawnCmdArgs = ['/c', `${this.config.buildPath}/run.cmd ${onesyncFlag} +exec ${this.config.cfgPath}`]; + } + + try { + this.fxChild = spawn( + spawnShell, + spawnCmdArgs, + {cwd: this.config.basePath} + ); + } catch (error) { + logError('Failed to start FXServer with the following error:'); + dir(error); + process.exit(0); + } + + logOk(`::Server started with PID ${this.fxChild.pid}!`, context); this.fxChild.stdout.pipe(process.stdout); process.stdin.pipe(this.fxChild.stdin); diff --git a/version.json b/version.json index 4f266bfc4..312bd6ad1 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { - "version": "0.4.3", - "changelog": "Config tester, better error handling and configuration change." + "version": "0.5.0", + "changelog": "Linux support, Config tester." } \ No newline at end of file