Skip to content

Commit

Permalink
Merge pull request #34 from Jordan2139/master
Browse files Browse the repository at this point in the history
M89 Activity Tracker
  • Loading branch information
SonoranBrian authored Apr 18, 2024
2 parents dc5ee80 + 85b06f0 commit afd4767
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 6 deletions.
2 changes: 0 additions & 2 deletions sonorancms/client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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.1'
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'}
Expand Down
76 changes: 76 additions & 0 deletions sonorancms/server/activityTracker.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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)
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
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['forceStop'] = true
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 .. ' - ' .. json.encode(res.error))
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)
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)
4 changes: 3 additions & 1 deletion sonorancms/server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions sonorancms/version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"resource": "1.5.1",
"testedFxServerVersion": "6683"
"resource": "1.5.3",
"testedFxServerVersion": "7290"
}

0 comments on commit afd4767

Please sign in to comment.