Skip to content

Commit

Permalink
Merge branch 'develop' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra authored Aug 12, 2024
2 parents ef332f0 + 0b4bff4 commit 87fb3d5
Show file tree
Hide file tree
Showing 81 changed files with 2,761 additions and 517 deletions.
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# Check if the !NC flag is present in the changes
if git diff --staged --unified=0 --no-color | grep '^+' | grep -q '!NC'; then
echo -e "COMMIT REJECTED: Found the !NC flag in your changes.\nMake sure you didn't accidently staged something you shouldn't!"
echo "Flags found:"
git diff --staged --unified=0 --no-color | grep -C 2 '!NC'
exit 1
fi

Expand Down
18 changes: 18 additions & 0 deletions core/components/AdminVault/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,4 +601,22 @@ export default class AdminVault {
return false;
}
}


/**
* Returns the public name to display for that particular purpose
* TODO: maybe use enums for the purpose
*/
getAdminPublicName(name, purpose) {
if (!name || !purpose) throw new Error('Invalid parameters');
const replacer = globals.txAdmin.globalConfig.serverName ?? 'txAdmin';

if (purpose === 'punishment') {
return globals.txAdmin.globalConfig.hideAdminInPunishments ? replacer : name;
} else if (purpose === 'message') {
return globals.txAdmin.globalConfig.hideAdminInMessages ? replacer : name;
} else {
throw new Error(`Invalid purpose: ${purpose}`);
}
}
};
4 changes: 4 additions & 0 deletions core/components/ConfigVault.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export default class ConfigVault {
hideDefaultDirectMessage: toDefault(cfg.global.hideDefaultDirectMessage, false),
hideDefaultWarning: toDefault(cfg.global.hideDefaultWarning, false),
hideDefaultScheduledRestartWarning: toDefault(cfg.global.hideDefaultScheduledRestartWarning, false),
hideAdminInPunishments: toDefault(cfg.global.hideAdminInPunishments, true),
hideAdminInMessages: toDefault(cfg.global.hideAdminInMessages, false),
};
out.logger = toDefault(cfg.logger, {}); //not in template
out.monitor = {
Expand Down Expand Up @@ -214,6 +216,8 @@ export default class ConfigVault {
cfg.global.hideDefaultDirectMessage = (cfg.global.hideDefaultDirectMessage === 'true' || cfg.global.hideDefaultDirectMessage === true);
cfg.global.hideDefaultWarning = (cfg.global.hideDefaultWarning === 'true' || cfg.global.hideDefaultWarning === true);
cfg.global.hideDefaultScheduledRestartWarning = (cfg.global.hideDefaultScheduledRestartWarning === 'true' || cfg.global.hideDefaultScheduledRestartWarning === true);
cfg.global.hideAdminInPunishments = (cfg.global.hideAdminInPunishments === 'true' || cfg.global.hideAdminInPunishments === true);
cfg.global.hideAdminInMessages = (cfg.global.hideAdminInMessages === 'true' || cfg.global.hideAdminInMessages === true);

//Logger - NOTE: this one default's i'm doing directly into the class
cfg.logger.fxserver = toDefault(cfg.logger.fxserver, {});
Expand Down
23 changes: 7 additions & 16 deletions core/components/FxRunner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ const getMutableConvars = (isCmdLine = false) => {

return [
//type, name, value
[`${p}set`, 'txAdmin-serverName', globals.txAdmin.globalConfig.serverName ?? 'txAdmin'],
[`${p}setr`, 'txAdmin-locale', globals.translator.language ?? 'en'],
[`${p}set`, 'txAdmin-localeFile', globals.translator.customLocalePath ?? 'false'],
[`${p}setr`, 'txAdmin-verbose', console.isVerbose],
[`${p}set`, 'txAdmin-checkPlayerJoin', checkPlayerJoin],
[`${p}set`, 'txAdmin-menuAlignRight', globals.txAdmin.globalConfig.menuAlignRight],
[`${p}set`, 'txAdmin-menuPageKey', globals.txAdmin.globalConfig.menuPageKey],
[`${p}set`, 'txAdmin-hideAdminInPunishments', globals.txAdmin.globalConfig.hideAdminInPunishments],
[`${p}set`, 'txAdmin-hideAdminInMessages', globals.txAdmin.globalConfig.hideAdminInMessages],
[`${p}set`, 'txAdmin-hideDefaultAnnouncement', globals.txAdmin.globalConfig.hideDefaultAnnouncement],
[`${p}set`, 'txAdmin-hideDefaultDirectMessage', globals.txAdmin.globalConfig.hideDefaultDirectMessage],
[`${p}set`, 'txAdmin-hideDefaultWarning', globals.txAdmin.globalConfig.hideDefaultWarning],
Expand Down Expand Up @@ -64,16 +67,14 @@ export default class FXRunner {
}


//================================================================
/**
* Refresh fxRunner configurations
*/
refreshConfig() {
this.config = globals.configVault.getScoped('fxRunner');
}//Final refreshConfig()
}


//================================================================
/**
* Receives the signal that all the start banner was already printed and other modules loaded
*/
Expand All @@ -89,10 +90,9 @@ export default class FXRunner {
}

this.spawnServer(true);
}//Final signalStartReady()
}


//================================================================
/**
* Setup the spawn parameters
*/
Expand Down Expand Up @@ -138,10 +138,9 @@ export default class FXRunner {
],
};
}
}//Final setupVariables()
}


//================================================================
/**
* Spawns the FXServer and sets up all the event handlers
* @param {boolean} announce
Expand Down Expand Up @@ -309,10 +308,9 @@ export default class FXRunner {
tracePipe.on('data', this.outputHandler.trace.bind(this.outputHandler, this.currentMutex));

return null;
}//Final spawnServer()
}


//================================================================
/**
* Restarts the FXServer
* @param {string} reason
Expand Down Expand Up @@ -343,7 +341,6 @@ export default class FXRunner {
}


//================================================================
/**
* Kills the FXServer
* @param {string} reason
Expand Down Expand Up @@ -405,7 +402,6 @@ export default class FXRunner {
}


//================================================================
/**
* Resets the convars in the server.
* Useful for when we change txAdmin settings and want it to reflect on the server.
Expand All @@ -428,7 +424,6 @@ export default class FXRunner {
}


//================================================================
/**
* Fires an `txAdmin:event` inside the server via srvCmd > stdin > command > lua broadcaster.
* @param {string} eventType
Expand All @@ -452,7 +447,6 @@ export default class FXRunner {
}


//================================================================
/**
* Pipe a string into FXServer's stdin (aka executes a cfx's command)
* TODO: make this method accept an array and apply the formatCommand() logic
Expand All @@ -474,7 +468,6 @@ export default class FXRunner {
}


//================================================================
/**
* Handles a live console command input
* @param {import('../WebServer/authLogic').AuthedAdminType} admin
Expand All @@ -486,7 +479,6 @@ export default class FXRunner {
}


//================================================================
/**
* Returns the status of the server, with the states being:
* - not started
Expand Down Expand Up @@ -530,7 +522,6 @@ export default class FXRunner {
}


//================================================================
/**
* Returns the current fxserver uptime in seconds
* @returns {numeric} buffer
Expand Down
3 changes: 2 additions & 1 deletion core/components/FxRunner/outputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ export default class OutputHandler {
this.#txAdmin.fxRunner.sendEvent('announcement', { message, author });

// Sending discord announcement
const publicAuthor = this.#txAdmin.adminVault.getAdminPublicName(payload.author, 'message');
this.#txAdmin.discordBot.sendAnnouncement({
type: 'info',
title: {
key: 'nui_menu.misc.announcement_title',
data: { author }
data: { author: publicAuthor }
},
description: message
});
Expand Down
10 changes: 5 additions & 5 deletions core/components/Logger/handlers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ export default class AdminLogger extends LoggerBase {
* Handles the input of log data
* TODO: add here discord log forwarding
*
* @param {string} author
* @param {string} action
* @param {'default'|'command'} type
* @param {string} author
* @param {string} action
* @param {'default'|'command'} type
*/
write(author, action, type = 'default') {
let saveMsg;
if(type === 'command'){
if (type === 'command') {
saveMsg = `[${author}] executed "${action}"`;
console.log(`${author} executed ` + chalk.inverse(' ' + action + ' '));
}else{
} else {
saveMsg = `[${author}] ${action}`;
console.log(saveMsg);
}
Expand Down
6 changes: 3 additions & 3 deletions core/components/PlayerDatabase/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default async (dbo) => {

//Changing Warn actions id prefix to W
dbo.data.actions.forEach((action) => {
if (action.type === 'warn'){
if (action.type === 'warn') {
action.id = `W${action.id.substring(1)}`;
}
});
Expand All @@ -98,11 +98,11 @@ export default async (dbo) => {
player.pureName = pureName;
player.name = undefined;
player.ids = [`license:${player.license}`];

//adding whitelist
const tsWhitelisted = whitelists.get(player.license);
if (tsWhitelisted) player.tsWhitelisted = tsWhitelisted;

//removing empty notes
if (!player.notes.text) player.notes = undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const crashExamples = [
`Game crashed: Recursive error: An exception occurred (c0000005 at 0x7ff6bb17f1c9) during loading of resources:/cars/data/[limiteds]/xmas 4/carvariations.meta in data file mounter 0x141a22350. The game will be terminated.`,
`O jogo crashou: %s`,
];
const exceptionExamples = [
`Unhandled exception: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.`,
`Exceção não tratada: %s`,
const crashExceptionExamples = [
`Game crashed: Unhandled exception: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.`,
`Game crashed: Exceção não tratada: %s`,
];


Expand Down Expand Up @@ -75,16 +75,16 @@ suite('classifyDropReason', () => {
}
});
it('should classify crash reasons', () => {
for (const reason of [...crashExamples, ...exceptionExamples]) {
for (const reason of [...crashExamples, ...crashExceptionExamples]) {
expect(fnc(reason).category).toBe('crash');
}
});
it('should translate crash reasons', () => {
for (const reason of [...crashExamples, ...exceptionExamples]) {
it('should translate crash exceptions', () => {
for (const reason of [...crashExceptionExamples]) {
const resp = fnc(reason);
expect(resp.cleanReason).toBeTypeOf('string');
expect(resp.cleanReason).toSatisfy((x: string) => {
return x.startsWith('Game crashed: ') || x.startsWith('Unhandled exception: ')
return x.startsWith('Unhandled exception: ')
});
}
});
Expand Down
19 changes: 8 additions & 11 deletions core/components/StatsManager/playerDrop/classifyDropReason.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const crashRulesIntl = [
// (sv) Swedish - 0.69%
`spelet kraschade: `,
];
const exceptionRulesIntl = [
const exceptionPrefixesIntl = [
// (en) English - 18.46%
`unhandled exception: `,
// (pt) Portuguese - 15.67%
Expand Down Expand Up @@ -95,7 +95,7 @@ const exceptionRulesIntl = [

const truncateReason = (reason: string, maxLength: number) => {
const truncationSuffix = '[truncated]';
if(reason.length > maxLength){
if (reason.length > maxLength) {
return reason.slice(0, maxLength - truncationSuffix.length) + truncationSuffix;
} else {
return reason;
Expand Down Expand Up @@ -126,16 +126,13 @@ export const classifyDropReason = (reason: string) => {
return { category: 'security' };
} else if (crashRulesIntl.some((rule) => reasonToMatch.includes(rule))) {
const cutoffIdx = reason.indexOf(': ') + 2;
const msg = 'Game crashed: ' + reason.slice(cutoffIdx);
const msg = reason.slice(cutoffIdx);
const exceptionPrefix = exceptionPrefixesIntl.find((prefix) => msg.toLocaleLowerCase().startsWith(prefix));
const saveMsg = exceptionPrefix
? 'Unhandled exception: ' + msg.slice(exceptionPrefix.length)
: msg;
return {
cleanReason: truncateReason(msg, PDL_CRASH_REASON_CHAR_LIMIT),
category: 'crash'
};
} else if (exceptionRulesIntl.some((rule) => reasonToMatch.includes(rule))) {
const cutoffIdx = reason.indexOf(': ') + 2;
const msg = 'Unhandled exception: ' + reason.slice(cutoffIdx);
return {
cleanReason: truncateReason(msg, PDL_CRASH_REASON_CHAR_LIMIT),
cleanReason: truncateReason(saveMsg, PDL_CRASH_REASON_CHAR_LIMIT),
category: 'crash'
};
} else {
Expand Down
Loading

0 comments on commit 87fb3d5

Please sign in to comment.