Skip to content

Commit

Permalink
Merge pull request #36 from Jordan2139/master
Browse files Browse the repository at this point in the history
Version 1.5.4 Fixes
  • Loading branch information
Fireant456 authored May 2, 2024
2 parents afd4767 + edcd1b2 commit 0f965f7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion sonorancms/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ games {'gta5'}
author 'Sonoran Software Systems'
real_name 'Sonoran CMS FiveM Integration'
description 'Sonoran CMS to FiveM translation layer'
version '1.5.3'
version '1.5.4'
lua54 'yes'

server_scripts {'server/*.lua', 'config.lua', 'server/util/unzip.js', 'server/util/http.js', 'server/util/sonoran.js', 'server/util/utils.js', '@oxmysql/lib/MySQL.lua', 'server/util/imageHandler.js', 'server/modules/**/*_sv.js', 'server/modules/**/*_sv.lua'}
Expand Down
48 changes: 24 additions & 24 deletions sonorancms/server/modules/whitelist/whitelist_sv.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const whiteListLuaConfig = LoadResourceFile(GetCurrentResourceName(), "./config.lua");
const whitelistCleanLuaConfig = whiteListLuaConfig.replace(/--.*/g, "");
const whitelistCleanLuaConfig = whiteListLuaConfig.replace(/--.*(?:\r?\n|$)/g, "");
const regexPattern = /Config\.(\w+)\s*=\s*(?:'([^']*)'|"([^"]*)"|(.*?))(?=\s*(?:\-\-|\n|$))/g;
let activePlayers = {};
const whiteListConfig = {};
whitelistCleanLuaConfig.replace(/Config\.(\w+)\s*=\s*(.*?)(?=\n|$)/g, (match, key, value) => {
whiteListConfig[key] = value.trim();
whitelistCleanLuaConfig.replace(regexPattern, (match, key, value) => {
whiteListConfig[key] = value?.trim();
});
let whiteListapiKey = whiteListConfig.whiteListapiKey;
let whiteListapiIdType = whiteListConfig.whiteListapiIdType;
let whiteListapiKey = whiteListConfig.APIKey;
let whiteListapiIdType = whiteListConfig.apiIdType;
const enabledConfig = JSON.parse(LoadResourceFile(GetCurrentResourceName(), "./server/modules/whitelist/whitelist_config.json"));

/**
Expand All @@ -15,7 +16,7 @@ const enabledConfig = JSON.parse(LoadResourceFile(GetCurrentResourceName(), "./s
* @param {errStack} args
* @returns
*/
errorLog = (message, ...args) => {
let errorLog = (message, ...args) => {
return console.log(`^1[ERROR - Sonoran CMS Whitelist - ${new Date().toLocaleString()}] ${message}`, args + "^0");
};

Expand All @@ -24,7 +25,7 @@ errorLog = (message, ...args) => {
* @param {string} message
* @returns {string}
*/
infoLog = (message) => {
let infoLog = (message) => {
return console.log(`[INFO - Sonoran CMS Whitelist - ${new Date().toLocaleString()}] ${message}`);
};

Expand All @@ -33,7 +34,7 @@ infoLog = (message) => {
* @param {int} subInt
* @returns {string}
*/
subIntToName = (subInt) => {
let subIntToName = (subInt) => {
switch (subInt) {
case 0:
return "FREE";
Expand All @@ -55,7 +56,7 @@ subIntToName = (subInt) => {
* @param {string} apiMsg
* @returns {string}
*/
apiMsgToEnglish = (apiMsg) => {
let apiMsgToEnglish = (apiMsg) => {
console.log(apiMsg);
switch (apiMsg) {
case "UNKNOWN_ACC_API_ID":
Expand Down Expand Up @@ -84,7 +85,7 @@ apiMsgToEnglish = (apiMsg) => {
*
* returns {Promise}
*/
updateBackup = () => {
let updateBackup = () => {
exports.sonorancms.getFullWhitelist(function (fullWhitelist) {
if (fullWhitelist.success) {
const idArray = [];
Expand All @@ -104,32 +105,32 @@ async function initialize() {
});
await exports.sonorancms.sleep(2000);
let backup = JSON.parse(LoadResourceFile(GetCurrentResourceName(), "/server/modules/whitelist/whitelist_backup.json"));
exports.sonorancms.updateBackup();
updateBackup();
RegisterNetEvent("sonoran_whitelist::rankupdate");
on("sonoran_whitelist::rankupdate", async (data) => {
const accountID = data.data.accId;
if (activePlayers[accountID]) {
let apiId;
apiId = exports.sonorancms.getAppropriateIdentifier(activePlayers[accountID], whiteListapiIdType.toLowerCase());
if (!apiId)
return exports.sonorancms.errorLog(
return errorLog(
`Could not find the correct API ID to cross check with the whitelist... Requesting type: ${whiteListapiIdType.toUpperCase()}`
);
if (data.key === whiteListapiKey) {
exports.sonorancms.checkCMSWhitelist(apiId, function (whitelist) {
if (whitelist.success) {
exports.sonorancms.infoLog(
infoLog(
`After role update, ${data.data.accName} (${accountID}) is still whitelisted, username returned: ${JSON.stringify(whitelist.reason)} `
);
} else {
DropPlayer(
activePlayers[accountID],
"After SonoranCMS role update, you were no longer whitelisted: " + exports.sonorancms.apiMsgToEnglish(whitelist.reason.message)
);
exports.sonorancms.infoLog(
`After SonoranCMS role update ${data.data.accName} (${accountID}) was no longer whitelisted, reason returned: ${exports.sonorancms.apiMsgToEnglish(
whitelist.reason.message
)}`
infoLog(
`After SonoranCMS role update ${
data.data.accName
} (${accountID}) was no longer whitelisted, reason returned: ${exports.sonorancms.apiMsgToEnglish(whitelist.reason.message)}`
);
activePlayers[accountID] = null;
}
Expand All @@ -144,26 +145,25 @@ async function initialize() {
deferrals.update("Grabbing API ID to check against the whitelist...");
apiId = exports.sonorancms.getAppropriateIdentifier(src, whiteListapiIdType.toLowerCase());
if (!apiId)
return exports.sonorancms.errorLog(
`Could not find the correct API ID to cross check with the whitelist... Requesting type: ${whiteListapiIdType.toUpperCase()}`
);
return errorLog(`Could not find the correct API ID to cross check with the whitelist... Requesting type: ${whiteListapiIdType.toUpperCase()}`);
deferrals.update("Checking whitelist...");
exports.sonorancms.updateBackup();
updateBackup();
await exports.sonorancms.checkCMSWhitelist(apiId, function (whitelist) {
if (whitelist.success) {
deferrals.done();
exports.sonorancms.infoLog(`Successfully allowed ${name} (${apiId}) through whitelist, username returned: ${JSON.stringify(whitelist.reason)} `);
infoLog(`Successfully allowed ${name} (${apiId}) through whitelist, username returned: ${JSON.stringify(whitelist.reason)} `);
exports.sonorancms.performApiRequest([{ apiId: apiId }], "GET_COM_ACCOUNT", function (data) {
activePlayers[data[0].accId] = src;
});
} else {
deferrals.done(`Failed whitelist check: ${exports.sonorancms.apiMsgToEnglish(whitelist.reason.message)} \n\nAPI ID used to check: ${apiId}`);
exports.sonorancms.infoLog(`Denied ${name} (${apiId}) through whitelist, reason returned: ${exports.sonorancms.apiMsgToEnglish(whitelist.reason.message)}`);
DropPlayer(src, "You are not whitelisted: " + exports.sonorancms.apiMsgToEnglish(whitelist.reason.message));
infoLog(`Denied ${name} (${apiId}) through whitelist, reason returned: ${exports.sonorancms.apiMsgToEnglish(whitelist.reason.message)}`);
}
});
});
setInterval(() => {
exports.sonorancms.updateBackup();
updateBackup();
}, 1800000);
}

Expand Down
2 changes: 1 addition & 1 deletion sonorancms/version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"resource": "1.5.3",
"resource": "1.5.4",
"testedFxServerVersion": "7290"
}

0 comments on commit 0f965f7

Please sign in to comment.