Skip to content

Commit d7a260c

Browse files
committed
refactor(core): bunch of small wip
1 parent 4470cac commit d7a260c

9 files changed

Lines changed: 37 additions & 30 deletions

File tree

core/globalData.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@ const resourceName = GetCurrentResourceName();
5757
//9423 = feat(server): add more infos to playerDropped event
5858
//9655 = Fixed ScanResourceRoot + latent events
5959
const minFxsVersion = 5894;
60-
const fxsVerParsed = parseFxserverVersion(getConvarString('version'));
60+
const fxsVerConvar = getConvarString('version');
61+
const fxsVerParsed = parseFxserverVersion(fxsVerConvar);
6162
const fxsVersion = fxsVerParsed.valid ? fxsVerParsed.build : 99999;
6263
if (!fxsVerParsed.valid) {
6364
console.error('It looks like you are running a custom build of fxserver.');
6465
console.error('And because of that, there is no guarantee that txAdmin will work properly.');
66+
console.error(`Convar: ${fxsVerConvar}`);
67+
console.error(`Parsed Build: ${fxsVerParsed.build}`);
68+
console.error(`Parsed Branch: ${fxsVerParsed.branch}`);
69+
console.error(`Parsed Platform: ${fxsVerParsed.platform}`);
6570
} else if (fxsVerParsed.build < minFxsVersion) {
6671
fatalError.GlobalData(2, [
6772
'This version of FXServer is too outdated and NOT compatible with txAdmin',
@@ -187,6 +192,7 @@ if (txDevEnvSrc.ENABLED) {
187192

188193
/**
189194
* MARK: Host type check
195+
* TODO: move all the hosting stuff to another file
190196
*/
191197
//Checking for ZAP Configuration file
192198
const zapCfgFile = path.join(dataPath, 'txAdminZapConfig.json');
@@ -196,7 +202,18 @@ let forceFXServerPort: false | number;
196202
let txAdminPort: number;
197203
let loginPageLogo: false | string;
198204
let defaultMasterAccount: false | { name: string, password_hash: string };
199-
let deployerDefaults: false | Record<string, string>;
205+
206+
type DeployerDefaultsType = {
207+
license?: string,
208+
maxClients?: number,
209+
mysqlHost?: string,
210+
mysqlPort?: string,
211+
mysqlUser?: string,
212+
mysqlPassword?: string,
213+
mysqlDatabase?: string,
214+
}
215+
216+
let deployerDefaults: undefined | DeployerDefaultsType;
200217
const isPterodactyl = !isWindows && process.env?.TXADMIN_ENABLE === '1';
201218
if (fs.existsSync(zapCfgFile)) {
202219
isZapHosting = !isPterodactyl;
@@ -209,6 +226,7 @@ if (fs.existsSync(zapCfgFile)) {
209226
txAdminPort = zapCfgData.txAdminPort;
210227
loginPageLogo = zapCfgData.loginPageLogo;
211228
defaultMasterAccount = false;
229+
//FIXME: add validation
212230
deployerDefaults = {
213231
license: zapCfgData.defaults.license,
214232
maxClients: zapCfgData.defaults.maxClients,
@@ -238,7 +256,6 @@ if (fs.existsSync(zapCfgFile)) {
238256
forceFXServerPort = false;
239257
loginPageLogo = false;
240258
defaultMasterAccount = false;
241-
deployerDefaults = false;
242259

243260
const txAdminPortConvar = GetConvar('txAdminPort', '40120').trim();
244261
if (!/^\d+$/.test(txAdminPortConvar)) {

core/lib/fatalError.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ function fatalError(code: number, msg: ErrorMsgType, err?: any): never {
7070
211 - expired cron
7171
220 - configvault throw
7272
221 - modules constructor throw
73-
222 - global placeholder
74-
223 - TxAdmin.setRef called
73+
222 - txGlobal placeholder getter error
74+
223 - txGlobal placeholder setter error
75+
225 - txGlobal access before initial tick
7576
5100 - config vault
7677
5300 - admin vault
7778
5400 - fxrunner

core/lib/fxserver/fxsConfigHelper.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,7 @@ const validateCommands = async (parsedCommands: (ExecRecursionError | Command)[]
395395
//Check sv_maxClients against ZAP config
396396
const isMaxClientsString = cmd.getSetForVariable('sv_maxclients');
397397
if (
398-
typeof convars.deployerDefaults === 'object'
399-
&& convars.deployerDefaults?.maxClients
398+
convars.deployerDefaults?.maxClients
400399
&& isMaxClientsString
401400
) {
402401
const maxClients = parseInt(isMaxClientsString);

core/modules/AdminVault/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import chalk from 'chalk';
1212
import fatalError from '@lib/fatalError.js';
1313
const console = consoleFactory(modulename);
1414

15-
//FIXME: The way I'm doing bersioning right now is horrible
15+
//FIXME: The way I'm doing versioning right now is horrible
1616
// but for now it's the best I can do
1717
const ADMIN_SCHEMA_VERSION = 1;
1818

core/modules/ConfigVault.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export default class ConfigVault {
4848
}
4949

5050

51-
//================================================================
5251
/**
5352
* Returns the config file data
5453
*/
@@ -83,7 +82,6 @@ export default class ConfigVault {
8382
}
8483

8584

86-
//================================================================
8785
/**
8886
* ????????????
8987
* @param {object} cfgData
@@ -196,7 +194,6 @@ export default class ConfigVault {
196194
}
197195

198196

199-
//================================================================
200197
/**
201198
* Setup the this.config variable based on the config file data
202199
* FIXME: rename this function
@@ -262,7 +259,7 @@ export default class ConfigVault {
262259
cfg.banTemplates = cfg.banTemplates ?? [];
263260
} catch (error) {
264261
//If this is the first run, that is a fatal error
265-
if (!this.config){
262+
if (!this.config) {
266263
fatalError.ConfigVault(13, [
267264
'Unknown error while loading the configuration file!',
268265
'Make sure your txAdmin is updated!',
@@ -278,7 +275,6 @@ export default class ConfigVault {
278275
}
279276

280277

281-
//================================================================
282278
/**
283279
* Return configs for a specific scope (reconstructed and freezed)
284280
*/
@@ -287,7 +283,6 @@ export default class ConfigVault {
287283
}
288284

289285

290-
//================================================================
291286
/**
292287
* Return configs for a specific scope (reconstructed and freezed)
293288
*/
@@ -296,7 +291,6 @@ export default class ConfigVault {
296291
}
297292

298293

299-
//================================================================
300294
/**
301295
* Return configs for a specific scope (reconstructed and freezed)
302296
*/
@@ -305,7 +299,6 @@ export default class ConfigVault {
305299
}
306300

307301

308-
//================================================================
309302
/**
310303
* Return all configs individually reconstructed and freezed
311304
*/
@@ -323,7 +316,6 @@ export default class ConfigVault {
323316
}
324317

325318

326-
//================================================================
327319
/**
328320
* Save the new scope to this context, then saves it to the configFile
329321
* @param {string} scope

core/modules/FxRunner/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const chanEventBlackHole = (...args) => {
6161
}
6262
};
6363

64-
export default class FXRunner {
64+
export default class FxRunner {
6565
constructor(txAdmin, config) {
6666
this.config = config;
6767

@@ -579,7 +579,7 @@ export default class FXRunner {
579579
*/
580580
getUptime() {
581581
if (!this.history.length) return 0;
582-
let curr = this.history[this.history.length - 1];
582+
const curr = this.history[this.history.length - 1];
583583

584584
return now() - curr.timestamps.start;
585585
}

core/modules/StatsManager/playerDrop/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const LOG_DATA_FILE_NAME = 'stats_playerDrop.json';
3030
*/
3131
export default class PlayerDropStatsManager {
3232
readonly #txAdmin: TxAdmin;
33-
private readonly logFilePath: string;
33+
private readonly logFilePath = `${txEnv.profilePath}/data/${LOG_DATA_FILE_NAME}`;
3434
private eventLog: PDLHourlyType[] = [];
3535
private lastGameVersion: string | undefined;
3636
private lastServerVersion: string | undefined;
@@ -44,7 +44,6 @@ export default class PlayerDropStatsManager {
4444

4545
constructor(txAdmin: TxAdmin) {
4646
this.#txAdmin = txAdmin;
47-
this.logFilePath = `${txEnv.profilePath}/data/${LOG_DATA_FILE_NAME}`;
4847
this.loadEventLog();
4948
}
5049

core/modules/StatsManager/svRuntime/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const LOG_DATA_FILE_NAME = 'stats_svRuntime.json';
2727
*/
2828
export default class SvRuntimeStatsManager {
2929
readonly #txAdmin: TxAdmin;
30-
private readonly logFilePath: string;
30+
private readonly logFilePath = `${txEnv.profilePath}/data/${LOG_DATA_FILE_NAME}`;
3131
private statsLog: SvRtLogType = [];
3232
private lastFxsMemory: number | undefined;
3333
private lastNodeMemory: SvRtNodeMemoryType | undefined;
@@ -46,7 +46,6 @@ export default class SvRuntimeStatsManager {
4646

4747
constructor(txAdmin: TxAdmin) {
4848
this.#txAdmin = txAdmin;
49-
this.logFilePath = `${txEnv.profilePath}/data/${LOG_DATA_FILE_NAME}`;
5049
this.loadStatsHistory();
5150

5251
//Cron functions
@@ -241,7 +240,7 @@ export default class SvRuntimeStatsManager {
241240
let playerCount = this.#txAdmin.playerlistManager.onlineCount;
242241
if (txDevEnv.EXT_STATS_HOST) {
243242
try {
244-
const playerCountResp = await got(`http://${fxServerHost}/players.json`).json();
243+
const playerCountResp = await got(`http://${fxServerHost}/players.json`).json<any[]>();
245244
playerCount = playerCountResp.length;
246245
} catch (error) { }
247246
}

core/routes/deployer/stepper.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ export default async function DeployerStepper(ctx) {
4848
if (convars.deployerDefaults) {
4949
renderData.defaults = {
5050
autofilled: true,
51-
license: convars.deployerDefaults.license || '',
52-
mysqlHost: convars.deployerDefaults.mysqlHost || 'localhost',
53-
mysqlPort: convars.deployerDefaults.mysqlPort || '3306',
54-
mysqlUser: convars.deployerDefaults.mysqlUser || 'root',
55-
mysqlPassword: convars.deployerDefaults.mysqlPassword || '',
56-
mysqlDatabase: convars.deployerDefaults.mysqlDatabase || globals.deployer.deploymentID,
51+
license: convars.deployerDefaults.license ?? '',
52+
mysqlHost: convars.deployerDefaults.mysqlHost ?? 'localhost',
53+
mysqlPort: convars.deployerDefaults.mysqlPort ?? '3306',
54+
mysqlUser: convars.deployerDefaults.mysqlUser ?? 'root',
55+
mysqlPassword: convars.deployerDefaults.mysqlPassword ?? '',
56+
mysqlDatabase: convars.deployerDefaults.mysqlDatabase ?? globals.deployer.deploymentID,
5757
};
5858
} else {
5959
renderData.defaults = {

0 commit comments

Comments
 (0)