diff --git a/sky_phone/source/client/crewlink.lua b/sky_phone/source/client/crewlink.lua index d554d0a..5ecf4eb 100644 --- a/sky_phone/source/client/crewlink.lua +++ b/sky_phone/source/client/crewlink.lua @@ -1,4 +1,5 @@ local overhead_members = {} +local overhead_expires_at = 0 local function draw_overhead_label(coords, username, role) SetDrawOrigin(coords.x, coords.y, coords.z + 1.05, 0) @@ -14,17 +15,25 @@ local function draw_overhead_label(coords, username, role) ClearDrawOrigin() end -CreateThread(function() - while true do - local result = Bridge.Callbacks.Trigger("sky_phone:crewlink:overhead", {}) - overhead_members = result and result.success and result.data and result.data.members or {} - Wait(Config.CrewLink.OverheadRefreshMilliseconds) - end +RegisterNUICallback("crewlink:live", function(data, cb) + local result = Bridge.Callbacks.Trigger("sky_phone:crewlink:live", data) + overhead_members = result and result.success and result.data and result.data.overheadMembers or {} + overhead_expires_at = GetGameTimer() + Config.CrewLink.OverheadRefreshMilliseconds * 2 + cb(result or { success = false, error = "request_failed" }) +end) + +AddEventHandler("sky_phone:nuiClosed", function() + overhead_members = {} + overhead_expires_at = 0 end) CreateThread(function() while true do local sleep = 1000 + if overhead_expires_at > 0 and GetGameTimer() >= overhead_expires_at then + overhead_members = {} + overhead_expires_at = 0 + end if #overhead_members > 0 then sleep = 0 local player_coords = GetEntityCoords(PlayerPedId()) diff --git a/sky_phone/source/client/main.lua b/sky_phone/source/client/main.lua index 4bfd8f5..19867cc 100644 --- a/sky_phone/source/client/main.lua +++ b/sky_phone/source/client/main.lua @@ -168,7 +168,6 @@ local server_callbacks = { "crewlink:leave", "crewlink:create-ping", "crewlink:remove-ping", - "crewlink:live", "companies:list", "companies:get", "companies:my-requests", diff --git a/sky_phone/source/server/crewlink.lua b/sky_phone/source/server/crewlink.lua index 7dca0f3..0bb5cfe 100644 --- a/sky_phone/source/server/crewlink.lua +++ b/sky_phone/source/server/crewlink.lua @@ -1089,51 +1089,39 @@ Bridge.Callbacks.Register("sky_phone:crewlink:live", function(source) if not profile then return error_response end - if not profile.active_group_id or not membership(profile.id, profile.active_group_id) then - return { success = true, data = { members = {}, pings = {} } } + if not profile.active_group_id then + return { success = true, data = { members = {}, overheadMembers = {}, pings = {} } } + end + local active_membership = membership(profile.id, profile.active_group_id) + if not active_membership then + return { success = true, data = { members = {}, overheadMembers = {}, pings = {} } } + end + local members = live_group(profile.active_group_id) + local overhead_members = {} + if tonumber(profile.overhead_visible) == 1 + and tonumber(active_membership.overhead_allowed) == 1 + then + for _, member in ipairs(members) do + if member.source and member.source ~= source and member.overheadVisible then + overhead_members[#overhead_members + 1] = { + source = member.source, + username = member.username, + role = member.role, + roleLabel = member.role:sub(1, 1):upper() .. member.role:sub(2), + } + end + end end return { success = true, data = { - members = live_group(profile.active_group_id), + members = members, + overheadMembers = overhead_members, pings = active_pings(profile.active_group_id), }, } end) -Bridge.Callbacks.Register("sky_phone:crewlink:overhead", function(source) - if not SkyPhone.AllowOperation( - source, - "crewlink:overhead", - Config.CrewLink.LiveRequestsPerMinute, - 60 - ) then - return { success = false, error = "rate_limited" } - end - local profile = require_profile(source) - if not profile or not profile.active_group_id or tonumber(profile.overhead_visible) ~= 1 then - return { success = true, data = { members = {} } } - end - local active_membership = membership(profile.id, profile.active_group_id) - if not active_membership or tonumber(active_membership.overhead_allowed) ~= 1 then - return { success = true, data = { members = {} } } - end - local live_sources = live_sources_by_account() - local members = {} - for _, member in ipairs(member_dtos(profile.active_group_id)) do - local member_source = live_sources[member.account_id] - if member_source and member_source ~= source and member.overheadVisible then - members[#members + 1] = { - source = member_source, - username = member.username, - role = member.role, - roleLabel = member.role:sub(1, 1):upper() .. member.role:sub(2), - } - end - end - return { success = true, data = { members = members } } -end) - exports("GetCrewLinkActiveGroup", function(source) local profile = require_profile(source) if not profile or not profile.active_group_id then diff --git a/sky_phone/source/server/phone.lua b/sky_phone/source/server/phone.lua index 1c6d072..91d0a0f 100644 --- a/sky_phone/source/server/phone.lua +++ b/sky_phone/source/server/phone.lua @@ -492,6 +492,9 @@ local function bootstrap(source, security, security_loaded) error(("[sky_phone] Active IMEI %s has no device row."):format(session.imei)) end + session.account_id = device.account_id and tonumber(device.account_id) or nil + session.account_email = session.account_id and device.email or nil + return { token = session.token, security = security_status(device.imei, security, security_loaded), @@ -747,14 +750,13 @@ function SkyPhone.RequireAccount(source) if not session then return nil, error_response end - local device = load_device(session.imei) - if not device or not device.account_id then + if not session.account_id then return nil, { success = false, error = "not_authenticated" } end return { - id = tonumber(device.account_id), - email = device.email, - imei = device.imei, + id = session.account_id, + email = session.account_email, + imei = session.imei, } end