From 18f19083a804d0ad92861bad11e5a158590d7b24 Mon Sep 17 00:00:00 2001 From: "Jordan.#2139" Date: Mon, 8 Apr 2024 19:35:13 -0400 Subject: [PATCH 1/5] feat: Player activity tracker --- sonorancms/fxmanifest.lua | 2 +- sonorancms/server/activityTracker.lua | 77 +++++++++++++++++++++++++++ sonorancms/server/server.lua | 4 +- sonorancms/version.json | 4 +- 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 sonorancms/server/activityTracker.lua diff --git a/sonorancms/fxmanifest.lua b/sonorancms/fxmanifest.lua index aada48e..188b973 100644 --- a/sonorancms/fxmanifest.lua +++ b/sonorancms/fxmanifest.lua @@ -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.1' +version '1.5.2' 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'} diff --git a/sonorancms/server/activityTracker.lua b/sonorancms/server/activityTracker.lua new file mode 100644 index 0000000..1c68437 --- /dev/null +++ b/sonorancms/server/activityTracker.lua @@ -0,0 +1,77 @@ +AddEventHandler('playerJoining', function() + local src = source + local name = GetPlayerName(src) + TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Player ' .. name .. ' (' .. src .. ') joined the server. Sending activity tracker to SonoranCMS.') + local identifier + local source = source + for _, v in pairs(GetPlayerIdentifiers(source)) do + if string.sub(v, 1, string.len(Config.apiIdType .. ':')) == Config.apiIdType .. ':' then + identifier = string.sub(v, string.len(Config.apiIdType .. ':') + 1) + end + end + local reqData = {} + if Config.apiIdType == 'discord' then + reqData['discord'] = identifier + else + reqData['apiId'] = identifier + end + reqData['serverId'] = Config.serverId + reqData['forceStart'] = true + exports['sonorancms']:performApiRequest({ + reqData + }, 'ACTIVITY_TRACKER_START_STOP', function(res) + if res.code == 200 then + TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Activity tracker started for ' .. name .. ' (' .. identifier .. ') - ' .. res.message) + else + TriggerEvent('SonoranCMS::core:writeLog', 'error', 'Failed to start activity tracker for ' .. name .. ' (' .. identifier .. ') - ' .. res.message) + end + end) +end) + +AddEventHandler('playerDropped', function() + local src = source + local name = GetPlayerName(src) + TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Player ' .. name .. ' (' .. src .. ') left the server. Sending activity tracker to SonoranCMS.') + local identifier + local source = source + for _, v in pairs(GetPlayerIdentifiers(source)) do + if string.sub(v, 1, string.len(Config.apiIdType .. ':')) == Config.apiIdType .. ':' then + identifier = string.sub(v, string.len(Config.apiIdType .. ':') + 1) + end + end + local reqData = {} + if Config.apiIdType == 'discord' then + reqData['discord'] = identifier + else + reqData['apiId'] = identifier + end + reqData['serverId'] = Config.serverId + reqData['forceClear'] = true + exports['sonorancms']:performApiRequest({ + reqData + }, 'ACTIVITY_TRACKER_START_STOP', function(res) + if res.code == 200 then + TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Activity tracker stopped for ' .. name .. ' (' .. identifier .. ') - ' .. res.message) + else + TriggerEvent('SonoranCMS::core:writeLog', 'error', 'Failed to stop activity tracker for ' .. name .. ' (' .. identifier .. ') - ' .. res.message) + end + end) +end) + +AddEventHandler('onResourceStart', function(resourceName) + if (GetCurrentResourceName() ~= resourceName) then + return + end + TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Resource ' .. resourceName .. ' started. Sending activity tracker to stop all active activities to SonoranCMS.') + local reqData = {} + reqData['serverId'] = Config.serverId + exports['sonorancms']:performApiRequest({ + reqData + }, 'ACTIVITY_TRACKER_SERVER_START', function(res) + if res.code == 200 then + TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Activity tracker stopped for all active activities - ' .. res.message) + else + TriggerEvent('SonoranCMS::core:writeLog', 'error', 'Failed to stop activity tracker for all active activities - ' .. res.message) + end + end) +end) diff --git a/sonorancms/server/server.lua b/sonorancms/server/server.lua index 47614f1..148938b 100644 --- a/sonorancms/server/server.lua +++ b/sonorancms/server/server.lua @@ -378,7 +378,9 @@ ApiEndpoints = { ['VERIFY_WHITELIST'] = 'servers', ['FULL_WHITELIST'] = 'servers', ['RSVP'] = 'events', - ['GAMESTATE'] = 'servers' + ['GAMESTATE'] = 'servers', + ['ACTIVITY_TRACKER_START_STOP'] = 'servers', + ['ACTIVITY_TRACKER_SERVER_START'] = 'servers' } function registerApiType(type, endpoint) diff --git a/sonorancms/version.json b/sonorancms/version.json index 49d5b05..917608b 100644 --- a/sonorancms/version.json +++ b/sonorancms/version.json @@ -1,4 +1,4 @@ { - "resource": "1.5.1", - "testedFxServerVersion": "6683" + "resource": "1.5.2", + "testedFxServerVersion": "7290" } From 46106e75d9e2df456429d72c766835af5c700736 Mon Sep 17 00:00:00 2001 From: "Jordan.#2139" Date: Mon, 15 Apr 2024 14:01:51 -0400 Subject: [PATCH 2/5] QA Fixes --- sonorancms/server/activityTracker.lua | 43 +++++++++++++-------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/sonorancms/server/activityTracker.lua b/sonorancms/server/activityTracker.lua index 1c68437..2bc607a 100644 --- a/sonorancms/server/activityTracker.lua +++ b/sonorancms/server/activityTracker.lua @@ -17,11 +17,10 @@ AddEventHandler('playerJoining', function() end reqData['serverId'] = Config.serverId reqData['forceStart'] = true - exports['sonorancms']:performApiRequest({ - reqData - }, 'ACTIVITY_TRACKER_START_STOP', function(res) - if res.code == 200 then - TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Activity tracker started for ' .. name .. ' (' .. identifier .. ') - ' .. res.message) + exports['sonorancms']:performApiRequest(reqData, 'ACTIVITY_TRACKER_START_STOP', function(res) + res = json.decode(res) + if res.success then + TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Activity tracker started for ' .. name .. ' (' .. identifier .. ')') else TriggerEvent('SonoranCMS::core:writeLog', 'error', 'Failed to start activity tracker for ' .. name .. ' (' .. identifier .. ') - ' .. res.message) end @@ -47,13 +46,12 @@ AddEventHandler('playerDropped', function() end reqData['serverId'] = Config.serverId reqData['forceClear'] = true - exports['sonorancms']:performApiRequest({ - reqData - }, 'ACTIVITY_TRACKER_START_STOP', function(res) - if res.code == 200 then - TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Activity tracker stopped for ' .. name .. ' (' .. identifier .. ') - ' .. res.message) + exports['sonorancms']:performApiRequest(reqData, 'ACTIVITY_TRACKER_START_STOP', function(res) + res = json.decode(res) + if res.success then + TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Activity tracker stopped for ' .. name .. ' (' .. identifier .. ')') else - TriggerEvent('SonoranCMS::core:writeLog', 'error', 'Failed to stop activity tracker for ' .. name .. ' (' .. identifier .. ') - ' .. res.message) + TriggerEvent('SonoranCMS::core:writeLog', 'error', 'Failed to stop activity tracker for ' .. name .. ' (' .. identifier .. ') - ' .. res.message .. ' - ' .. json.encode(res.error)) end end) end) @@ -63,15 +61,16 @@ AddEventHandler('onResourceStart', function(resourceName) return end TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Resource ' .. resourceName .. ' started. Sending activity tracker to stop all active activities to SonoranCMS.') - local reqData = {} - reqData['serverId'] = Config.serverId - exports['sonorancms']:performApiRequest({ - reqData - }, 'ACTIVITY_TRACKER_SERVER_START', function(res) - if res.code == 200 then - TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Activity tracker stopped for all active activities - ' .. res.message) - else - TriggerEvent('SonoranCMS::core:writeLog', 'error', 'Failed to stop activity tracker for all active activities - ' .. res.message) - end - end) + local reqData = {} + reqData['serverId'] = Config.serverId + exports['sonorancms']:performApiRequest({ + reqData + }, 'ACTIVITY_TRACKER_SERVER_START', function(res) + res = json.decode(res) + if res.success then + TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Activity tracker stopped for all active activities - ' .. json.encode(res.data)) + else + TriggerEvent('SonoranCMS::core:writeLog', 'error', 'Failed to stop activity tracker for all active activities - ' .. res.message .. ' - ' .. json.encode(res.error)) + end + end) end) From 61d7cc8538d7cbe70c2301399168845a188244a6 Mon Sep 17 00:00:00 2001 From: "Jordan.#2139" Date: Mon, 15 Apr 2024 14:04:22 -0400 Subject: [PATCH 3/5] Change variable name --- sonorancms/server/activityTracker.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonorancms/server/activityTracker.lua b/sonorancms/server/activityTracker.lua index 2bc607a..44480fc 100644 --- a/sonorancms/server/activityTracker.lua +++ b/sonorancms/server/activityTracker.lua @@ -45,7 +45,7 @@ AddEventHandler('playerDropped', function() reqData['apiId'] = identifier end reqData['serverId'] = Config.serverId - reqData['forceClear'] = true + reqData['forceStop'] = true exports['sonorancms']:performApiRequest(reqData, 'ACTIVITY_TRACKER_START_STOP', function(res) res = json.decode(res) if res.success then From fd3a849a8e9f823d73a52261d08617ac151b7b8a Mon Sep 17 00:00:00 2001 From: "Jordan.#2139" Date: Wed, 17 Apr 2024 16:13:43 -0400 Subject: [PATCH 4/5] chore: Remove stray print file --- sonorancms/client/client.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/sonorancms/client/client.lua b/sonorancms/client/client.lua index 07f29a6..64b363e 100644 --- a/sonorancms/client/client.lua +++ b/sonorancms/client/client.lua @@ -443,7 +443,5 @@ RegisterNetEvent('SonoranCMS::core::SetEnvironment', function(data) freezeTime = data.freezeTime timeOffset = data.timeOffset baseTime = data.baseTime - else - print('SonoranCMS: Weather sync is disabled, ignoring environment update.') end end) From 85b06f05337ab74ab9a6391640f6423f100e51b6 Mon Sep 17 00:00:00 2001 From: "Jordan.#2139" Date: Wed, 17 Apr 2024 16:14:35 -0400 Subject: [PATCH 5/5] chore: Version bump to 1.5.3 --- sonorancms/fxmanifest.lua | 2 +- sonorancms/version.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sonorancms/fxmanifest.lua b/sonorancms/fxmanifest.lua index 188b973..f213b90 100644 --- a/sonorancms/fxmanifest.lua +++ b/sonorancms/fxmanifest.lua @@ -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.2' +version '1.5.3' 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'} diff --git a/sonorancms/version.json b/sonorancms/version.json index 917608b..d40faa0 100644 --- a/sonorancms/version.json +++ b/sonorancms/version.json @@ -1,4 +1,4 @@ { - "resource": "1.5.2", + "resource": "1.5.3", "testedFxServerVersion": "7290" }