diff --git a/core/components/AdminVault/index.js b/core/components/AdminVault/index.js index 08bcca5f9..7997f2141 100644 --- a/core/components/AdminVault/index.js +++ b/core/components/AdminVault/index.js @@ -480,7 +480,7 @@ export default class AdminVault { console.error('You can rey restoring it or you can delete it and let txAdmin create a new one.'); } console.error(`Admin File Path: ${this.adminsFile}`); - process.exit(1); + process.exit(5300); }; try { diff --git a/core/components/ConfigVault.js b/core/components/ConfigVault.js index 2207697cf..5d64ceba8 100644 --- a/core/components/ConfigVault.js +++ b/core/components/ConfigVault.js @@ -55,8 +55,8 @@ export default class ConfigVault { this.config = this.setupConfigDefaults(this.configFile); this.setupFolderStructure(); } catch (error) { - console.error(error.message); - process.exit(0); + console.error(error); + process.exit(5100); } } @@ -276,7 +276,7 @@ export default class ConfigVault { } } catch (error) { console.error(`Failed to set up folder structure in '${this.serverProfilePath}/' with error: ${error.message}`); - process.exit(); + process.exit(5101); } } diff --git a/core/components/FxRunner/index.js b/core/components/FxRunner/index.js index f6fa60149..ba5d0c485 100644 --- a/core/components/FxRunner/index.js +++ b/core/components/FxRunner/index.js @@ -248,7 +248,7 @@ export default class FXRunner { } catch (error) { console.error('Failed to start FXServer with the following error:'); console.dir(error); - process.exit(0); + process.exit(5400); } //Setting up stream handlers diff --git a/core/components/PerformanceCollector/index.js b/core/components/PerformanceCollector/index.js index 834a83dec..1940e28c9 100644 --- a/core/components/PerformanceCollector/index.js +++ b/core/components/PerformanceCollector/index.js @@ -61,7 +61,7 @@ export default class PerformanceCollector { this.perfSeries = []; } catch (error) { console.error(`Unable to create stats_heatmapData_v1 with error: ${error.message}`); - process.exit(); + process.exit(5500); } }; diff --git a/core/components/PlayerDatabase/database.ts b/core/components/PlayerDatabase/database.ts index f348a4652..2b964dda9 100644 --- a/core/components/PlayerDatabase/database.ts +++ b/core/components/PlayerDatabase/database.ts @@ -116,7 +116,7 @@ export class Database { console.error(`Backup error: '${(errorBackup as Error).message}'`); console.error(`Database path: '${this.dbPath}'`); console.error('If there is a file in that location, you may try to delete or restore it manually.'); - process.exit(); + process.exit(5600); } } @@ -141,7 +141,7 @@ export class Database { } catch (error) { console.error('Failed to setup database object.'); console.dir(error); - process.exit(); + process.exit(5601); } } diff --git a/core/components/PlayerDatabase/migrations.js b/core/components/PlayerDatabase/migrations.js index c8d9642bc..49351f8f1 100644 --- a/core/components/PlayerDatabase/migrations.js +++ b/core/components/PlayerDatabase/migrations.js @@ -16,12 +16,12 @@ export default async (dbo) => { } if (typeof dbo.data.version !== 'number') { console.error('Your players database version is not a number!'); - process.exit(1); + process.exit(5650); } if (dbo.data.version > DATABASE_VERSION) { console.error(`Your players database is on v${dbo.data.version}, and this txAdmin supports up to v${DATABASE_VERSION}.`); console.error('This means you likely downgraded your txAdmin version. Please update txAdmin.'); - process.exit(1); + process.exit(5651); } //Migrate database @@ -142,7 +142,7 @@ export default async (dbo) => { console.error(`Your players database is on v${dbo.data.version}, which is different from this version of txAdmin (v${DATABASE_VERSION}).`); console.error('Since there is currently no migration method ready for the migration, txAdmin will attempt to use it anyways.'); console.error('Please make sure your txAdmin is on the most updated version!'); - process.exit(1); + process.exit(5652); } console.ok('Database migrated successfully'); return dbo; diff --git a/core/components/StatisticsManager/index.ts b/core/components/StatisticsManager/index.ts index 210bfa90b..e8188e2ab 100644 --- a/core/components/StatisticsManager/index.ts +++ b/core/components/StatisticsManager/index.ts @@ -77,7 +77,7 @@ export default class StatisticsManager { this.#publicKey = await jose.importSPKI(statsPublicKeyPem, 'RS256'); } catch (error) { console.dir(error); - process.exit(1); + process.exit(5700); } } diff --git a/core/components/Translator.ts b/core/components/Translator.ts index d8ae8d460..2181fd4ff 100644 --- a/core/components/Translator.ts +++ b/core/components/Translator.ts @@ -51,7 +51,7 @@ export default class Translator { this.#polyglot = new Polyglot(polyglotOptions); } catch (error) { console.dir(error); - if (isFirstTime) process.exit(); + if (isFirstTime) process.exit(5200); } } diff --git a/core/components/WebServer/index.js b/core/components/WebServer/index.js index 92a5a151c..52c02503c 100644 --- a/core/components/WebServer/index.js +++ b/core/components/WebServer/index.js @@ -237,7 +237,7 @@ export default class WebServer { console.error('Maybe you already have another txAdmin running in this port.'); console.error('If you want to run multiple txAdmin instances, check the documentation for the port convar.'); console.error('You can also try restarting the host machine.'); - process.exit(1); + process.exit(5800); }; this.httpServer = HttpClass.createServer(this.httpCallbackHandler.bind(this, 'httpserver')); this.httpServer.on('error', listenErrorHandler); @@ -258,7 +258,7 @@ export default class WebServer { } catch (error) { console.error('Failed to start HTTP server with error:'); console.dir(error); - process.exit(); + process.exit(5801); } } }; diff --git a/core/extras/checkPreRelease.ts b/core/extras/checkPreRelease.ts index ba29d8ca8..8e543fac5 100644 --- a/core/extras/checkPreRelease.ts +++ b/core/extras/checkPreRelease.ts @@ -28,7 +28,7 @@ const cronCheckExpiration = () => { if (timeUntilExpiration < 0) { console.error('This pre-release version has expired, please update your txAdmin.'); console.error('For more information: https://discord.gg/txAdmin.'); - process.exit(1); + process.exit(400); } else if (timeUntilExpiration < 24 * 60 * 60 * 1000) { printExpirationBanner(timeUntilExpiration); } @@ -41,7 +41,7 @@ export default () => { if (timeUntilExpiration < 0) { console.error('This pre-release version has expired, please update your txAdmin.'); console.error('For more information: https://discord.gg/txAdmin.'); - process.exit(1); + process.exit(401); } //First warning diff --git a/core/extras/setupProfile.js b/core/extras/setupProfile.js index a2862ca9c..70f960156 100644 --- a/core/extras/setupProfile.js +++ b/core/extras/setupProfile.js @@ -39,7 +39,7 @@ export default (osType, fxServerPath, fxServerVersion, serverProfile, profilePat //Sanity check presence of profile if (fs.existsSync(profilePath)) { console.error(`There is already a profile named '${serverProfile}'.`); - process.exit(); + process.exit(500); } //Create new profile folder @@ -53,7 +53,7 @@ export default (osType, fxServerPath, fxServerVersion, serverProfile, profilePat } catch (error) { console.error(`Failed to set up folder structure in '${profilePath}' with error:`); console.dir(error); - process.exit(); + process.exit(501); } console.ok(`Server profile was saved in '${profilePath}'`); @@ -61,12 +61,14 @@ export default (osType, fxServerPath, fxServerVersion, serverProfile, profilePat //Saving start.bat if (osType == 'windows') { try { - const batData = `@echo off -"${fxServerPath}/FXServer.exe" +set serverProfile "${serverProfile}" -pause`; + const batLines = [ + `@echo off`, + `"${fxServerPath}/FXServer.exe" +set serverProfile "${serverProfile}"`, + `pause` + ]; const batFolder = path.resolve(fxServerPath, '..'); - const batPath = path.join(batFolder, `start_${fxServerVersion}_${serverProfile}.bat`); - fs.writeFileSync(batPath, batData); + const batPath = path.join(batFolder, `start_${fxServerVersion}_${serverProfile}.bat`); + fs.writeFileSync(batPath, batLines.join('\r\n')); console.ok(`You can use ${chalk.inverse(batPath)} to start this profile.`); } catch (error) { console.warn(`Failed to create 'start_${fxServerVersion}_${serverProfile}.bat' with error:`); diff --git a/core/index.ts b/core/index.ts index 4d3c29055..bb8429021 100644 --- a/core/index.ts +++ b/core/index.ts @@ -8,16 +8,14 @@ const console = consoleFactory(); /** * Starting txAdmin (have fun :p) */ -const logDie = (x: string) => { - console.error(x); - process.exit(1); -}; const serverProfile = GetConvar('serverProfile', 'default').replace(/[^a-z0-9._-]/gi, '').trim(); if (serverProfile.endsWith('.base')) { - logDie(`Looks like the folder named '${serverProfile}' is actually a deployed base instead of a profile.`); + console.error(`Looks like the folder named '${serverProfile}' is actually a deployed base instead of a profile.`); + process.exit(200); } if (!serverProfile.length) { - logDie('Invalid server profile name. Are you using Google Translator on the instructions page? Make sure there are no additional spaces in your command.'); + console.error('Invalid server profile name. Are you using Google Translator on the instructions page? Make sure there are no additional spaces in your command.'); + process.exit(201); } setTTYTitle(serverProfile); diff --git a/core/txAdmin.ts b/core/txAdmin.ts index d2666f157..7c3448d1b 100644 --- a/core/txAdmin.ts +++ b/core/txAdmin.ts @@ -121,7 +121,7 @@ export default class TxAdmin { setupProfile(txEnv.osType, txEnv.fxServerPath, txEnv.fxServerVersion, serverProfile, profilePath); } catch (error) { console.error(`Failed to create profile '${serverProfile}' with error: ${(error as Error).message}`); - process.exit(); + process.exit(300); } } this.info = { @@ -144,7 +144,7 @@ export default class TxAdmin { } catch (error) { console.error(`Error starting ConfigVault:`); console.dir(error); - process.exit(1); + process.exit(301); } //Start all modules @@ -205,7 +205,7 @@ export default class TxAdmin { } catch (error) { console.error(`Error starting main components:`); console.dir(error); - process.exit(1); + process.exit(302); } //Once they all finish loading, the function below will print the banner diff --git a/entrypoint.js b/entrypoint.js index ebb569a76..0707f60df 100644 --- a/entrypoint.js +++ b/entrypoint.js @@ -7,7 +7,7 @@ try { if (!IsDuplicityVersion()) throw new Error(); } catch (error) { console.log('txAdmin must be run inside FXServer in monitor mode!'); - process.exit(); + process.exit(999); } //Checking monitor mode and starting