forked from Simnation/Main
ed
This commit is contained in:
parent
91f2af8b8b
commit
4a1367fb44
2 changed files with 310 additions and 200 deletions
|
@ -5,6 +5,7 @@ local isMenuOpen = false
|
|||
local currentTarget = nil
|
||||
local nearbyPlayers = {}
|
||||
local isLicenseShowing = false
|
||||
local pendingRequests = {}
|
||||
|
||||
-- Hilfsfunktionen
|
||||
local function debugPrint(message)
|
||||
|
@ -13,16 +14,6 @@ local function debugPrint(message)
|
|||
end
|
||||
end
|
||||
|
||||
local function safeCallback(cb, ...)
|
||||
if cb and type(cb) == "function" then
|
||||
cb(...)
|
||||
return true
|
||||
else
|
||||
debugPrint("^1FEHLER: Callback ist keine Funktion! Typ: " .. type(cb) .. "^7")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local function showNotification(message, type)
|
||||
QBCore.Functions.Notify(message, type or 'primary')
|
||||
end
|
||||
|
@ -104,132 +95,26 @@ end
|
|||
|
||||
-- Spieler-Lizenz anzeigen
|
||||
local function showPlayerLicense(targetId)
|
||||
debugPrint("Rufe Server-Callback auf für Spieler: " .. tostring(targetId))
|
||||
debugPrint("=== showPlayerLicense START ===")
|
||||
debugPrint("Sende Event: requestLicense für Spieler: " .. tostring(targetId))
|
||||
|
||||
QBCore.Functions.TriggerCallback('license-system:server:getLicense', function(licenseData)
|
||||
debugPrint("Callback-Antwort erhalten für Spieler-Lizenz")
|
||||
|
||||
if licenseData then
|
||||
debugPrint("Lizenz-Daten erhalten: " .. licenseData.license.license_type)
|
||||
showLicense(licenseData)
|
||||
else
|
||||
debugPrint("Keine Lizenz-Daten erhalten")
|
||||
showNotification(Config.Notifications.license_not_found.message, Config.Notifications.license_not_found.type)
|
||||
end
|
||||
end, targetId)
|
||||
TriggerServerEvent('license-system:server:requestLicense', targetId)
|
||||
end
|
||||
|
||||
-- Eigene Lizenz anzeigen
|
||||
local function showMyLicense(licenseType)
|
||||
debugPrint("Rufe Server-Callback auf für eigene Lizenz: " .. tostring(licenseType))
|
||||
debugPrint("=== showMyLicense START ===")
|
||||
debugPrint("Sende Event: requestMyLicense für Typ: " .. tostring(licenseType))
|
||||
|
||||
QBCore.Functions.TriggerCallback('license-system:server:getMyLicense', function(licenseData)
|
||||
debugPrint("Eigene Lizenz Callback-Antwort erhalten")
|
||||
|
||||
if licenseData then
|
||||
debugPrint("Eigene Lizenz-Daten erhalten: " .. licenseData.license.license_type)
|
||||
showLicense(licenseData)
|
||||
else
|
||||
debugPrint("Keine eigene Lizenz gefunden")
|
||||
local config = Config.LicenseTypes[licenseType]
|
||||
local licenseName = config and config.label or licenseType
|
||||
showNotification('Du hast keine ' .. licenseName .. '!', 'error')
|
||||
end
|
||||
end, licenseType)
|
||||
TriggerServerEvent('license-system:server:requestMyLicense', licenseType)
|
||||
end
|
||||
|
||||
-- Spieler-Lizenz-Menü
|
||||
local function openPlayerLicenseMenu(targetId, targetName)
|
||||
debugPrint("Öffne Lizenz-Menü für Spieler: " .. targetName .. " (ID: " .. targetId .. ")")
|
||||
debugPrint("=== openPlayerLicenseMenu START ===")
|
||||
debugPrint("Sende Event: requestPlayerLicenses für: " .. targetName .. " (ID: " .. targetId .. ")")
|
||||
|
||||
QBCore.Functions.TriggerCallback('license-system:server:getPlayerLicenses', function(licenses)
|
||||
debugPrint("Spieler-Lizenzen Callback-Antwort erhalten, Anzahl: " .. (licenses and #licenses or 0))
|
||||
|
||||
local menuOptions = {}
|
||||
|
||||
if licenses and #licenses > 0 then
|
||||
for _, license in ipairs(licenses) do
|
||||
local licenseConfig = Config.LicenseTypes[license.license_type] or {
|
||||
label = license.license_type,
|
||||
icon = 'fas fa-id-card',
|
||||
color = '#667eea'
|
||||
}
|
||||
|
||||
local statusIcon = license.is_active == 1 and '✅' or '❌'
|
||||
local statusText = license.is_active == 1 and 'Gültig' or 'Ungültig'
|
||||
local expireText = license.expire_date or 'Unbegrenzt'
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = licenseConfig.label .. ' ' .. statusIcon,
|
||||
description = 'Status: ' .. statusText .. ' | Gültig bis: ' .. expireText,
|
||||
icon = licenseConfig.icon,
|
||||
onSelect = function()
|
||||
local licenseData = {
|
||||
license = license,
|
||||
config = licenseConfig
|
||||
}
|
||||
showLicense(licenseData)
|
||||
end,
|
||||
metadata = {
|
||||
{label = 'Status', value = statusText},
|
||||
{label = 'Ausgestellt', value = license.issue_date or 'Unbekannt'},
|
||||
{label = 'Gültig bis', value = expireText},
|
||||
{label = 'Aussteller', value = license.issued_by_name or 'System'}
|
||||
}
|
||||
})
|
||||
end
|
||||
else
|
||||
table.insert(menuOptions, {
|
||||
title = 'Keine Lizenzen gefunden',
|
||||
description = 'Dieser Spieler hat keine Lizenzen',
|
||||
icon = 'fas fa-exclamation-triangle',
|
||||
disabled = true
|
||||
})
|
||||
end
|
||||
|
||||
-- Aktionen hinzufügen
|
||||
table.insert(menuOptions, {
|
||||
title = '─────────────────',
|
||||
disabled = true
|
||||
})
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = 'Neue Lizenz ausstellen',
|
||||
description = 'Eine neue Lizenz für diesen Spieler ausstellen',
|
||||
icon = 'fas fa-plus',
|
||||
onSelect = function()
|
||||
openIssueLicenseMenu(targetId, targetName)
|
||||
end
|
||||
})
|
||||
|
||||
if licenses and #licenses > 0 then
|
||||
table.insert(menuOptions, {
|
||||
title = 'Lizenz entziehen',
|
||||
description = 'Eine bestehende Lizenz entziehen',
|
||||
icon = 'fas fa-minus',
|
||||
onSelect = function()
|
||||
openRevokeLicenseMenu(targetId, targetName, licenses)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = '← Zurück',
|
||||
icon = 'fas fa-arrow-left',
|
||||
onSelect = function()
|
||||
openLicenseMenu()
|
||||
end
|
||||
})
|
||||
|
||||
lib.registerContext({
|
||||
id = 'player_licenses',
|
||||
title = 'Lizenzen: ' .. targetName,
|
||||
options = menuOptions
|
||||
})
|
||||
|
||||
lib.showContext('player_licenses')
|
||||
|
||||
end, targetId)
|
||||
TriggerServerEvent('license-system:server:requestPlayerLicenses', targetId)
|
||||
end
|
||||
|
||||
-- Lizenz ausstellen Menü
|
||||
|
@ -578,17 +463,177 @@ local function showMyLicenses()
|
|||
lib.showContext('my_licenses')
|
||||
end
|
||||
|
||||
-- Events
|
||||
-- EVENT HANDLER: Einzelne Lizenz erhalten
|
||||
RegisterNetEvent('license-system:client:receiveLicense', function(licenseData)
|
||||
debugPrint("=== Event: receiveLicense ===")
|
||||
debugPrint("LicenseData-Typ: " .. type(licenseData))
|
||||
|
||||
if licenseData then
|
||||
debugPrint("Lizenz-Daten erhalten: " .. licenseData.license.license_type)
|
||||
showLicense(licenseData)
|
||||
else
|
||||
debugPrint("Keine Lizenz-Daten erhalten")
|
||||
showNotification(Config.Notifications.license_not_found.message, Config.Notifications.license_not_found.type)
|
||||
end
|
||||
end)
|
||||
|
||||
-- EVENT HANDLER: Eigene Lizenz erhalten
|
||||
RegisterNetEvent('license-system:client:receiveMyLicense', function(licenseData, licenseType)
|
||||
debugPrint("=== Event: receiveMyLicense ===")
|
||||
debugPrint("LicenseType: " .. tostring(licenseType))
|
||||
debugPrint("LicenseData-Typ: " .. type(licenseData))
|
||||
|
||||
if licenseData then
|
||||
debugPrint("Eigene Lizenz-Daten erhalten: " .. licenseData.license.license_type)
|
||||
showLicense(licenseData)
|
||||
else
|
||||
debugPrint("Keine eigene Lizenz gefunden")
|
||||
local config = Config.LicenseTypes[licenseType]
|
||||
local licenseName = config and config.label or licenseType
|
||||
showNotification('Du hast keine ' .. licenseName .. '!', 'error')
|
||||
end
|
||||
end)
|
||||
|
||||
-- EVENT HANDLER: Alle Spieler-Lizenzen erhalten
|
||||
RegisterNetEvent('license-system:client:receivePlayerLicenses', function(licenses, targetId, targetName)
|
||||
debugPrint("=== Event: receivePlayerLicenses ===")
|
||||
debugPrint("Erhaltene Lizenzen: " .. #licenses)
|
||||
debugPrint("TargetName: " .. tostring(targetName))
|
||||
|
||||
local menuOptions = {}
|
||||
|
||||
if licenses and #licenses > 0 then
|
||||
for _, license in ipairs(licenses) do
|
||||
local licenseConfig = Config.LicenseTypes[license.license_type] or {
|
||||
label = license.license_type,
|
||||
icon = 'fas fa-id-card',
|
||||
color = '#667eea'
|
||||
}
|
||||
|
||||
local statusIcon = (license.is_active == 1) and '✅' or '❌'
|
||||
local statusText = (license.is_active == 1) and 'Gültig' or 'Ungültig'
|
||||
local expireText = license.expire_date or 'Unbegrenzt'
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = licenseConfig.label .. ' ' .. statusIcon,
|
||||
description = 'Status: ' .. statusText .. ' | Gültig bis: ' .. expireText,
|
||||
icon = licenseConfig.icon,
|
||||
onSelect = function()
|
||||
local licenseData = {
|
||||
license = license,
|
||||
config = licenseConfig
|
||||
}
|
||||
showLicense(licenseData)
|
||||
end,
|
||||
metadata = {
|
||||
{label = 'Status', value = statusText},
|
||||
{label = 'Ausgestellt', value = license.issue_date or 'Unbekannt'},
|
||||
{label = 'Gültig bis', value = expireText},
|
||||
{label = 'Aussteller', value = license.issued_by_name or 'System'}
|
||||
}
|
||||
})
|
||||
end
|
||||
else
|
||||
table.insert(menuOptions, {
|
||||
title = 'Keine Lizenzen gefunden',
|
||||
description = 'Dieser Spieler hat keine Lizenzen',
|
||||
icon = 'fas fa-exclamation-triangle',
|
||||
disabled = true
|
||||
})
|
||||
end
|
||||
|
||||
-- Aktionen hinzufügen
|
||||
table.insert(menuOptions, {
|
||||
title = '─────────────────',
|
||||
disabled = true
|
||||
})
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = 'Neue Lizenz ausstellen',
|
||||
description = 'Eine neue Lizenz für diesen Spieler ausstellen',
|
||||
icon = 'fas fa-plus',
|
||||
onSelect = function()
|
||||
openIssueLicenseMenu(targetId, targetName)
|
||||
end
|
||||
})
|
||||
|
||||
if licenses and #licenses > 0 then
|
||||
table.insert(menuOptions, {
|
||||
title = 'Lizenz entziehen',
|
||||
description = 'Eine bestehende Lizenz entziehen',
|
||||
icon = 'fas fa-minus',
|
||||
onSelect = function()
|
||||
openRevokeLicenseMenu(targetId, targetName, licenses)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
table.insert(menuOptions, {
|
||||
title = '← Zurück',
|
||||
icon = 'fas fa-arrow-left',
|
||||
onSelect = function()
|
||||
openLicenseMenu()
|
||||
end
|
||||
})
|
||||
|
||||
lib.registerContext({
|
||||
id = 'player_licenses',
|
||||
title = 'Lizenzen: ' .. targetName,
|
||||
options = menuOptions
|
||||
})
|
||||
|
||||
lib.showContext('player_licenses')
|
||||
end)
|
||||
|
||||
-- EVENT HANDLER: Berechtigung erhalten
|
||||
RegisterNetEvent('license-system:client:receivePermission', function(hasAuth, licenseType)
|
||||
debugPrint("=== Event: receivePermission ===")
|
||||
debugPrint("Berechtigung für " .. licenseType .. ": " .. tostring(hasAuth))
|
||||
|
||||
if not hasAuth then
|
||||
showNotification(Config.Notifications.no_permission.message, Config.Notifications.no_permission.type)
|
||||
end
|
||||
end)
|
||||
|
||||
-- EVENT HANDLER: Lizenz erfolgreich ausgestellt
|
||||
RegisterNetEvent('license-system:client:licenseIssued', function(targetId, licenseType)
|
||||
debugPrint("=== Event: licenseIssued ===")
|
||||
debugPrint("Lizenz " .. licenseType .. " für Spieler " .. targetId .. " ausgestellt")
|
||||
|
||||
-- Menü aktualisieren
|
||||
if lib.getOpenContextMenu() then
|
||||
lib.hideContext()
|
||||
Wait(100)
|
||||
openLicenseMenu()
|
||||
end
|
||||
end)
|
||||
|
||||
-- EVENT HANDLER: Lizenz erfolgreich entzogen
|
||||
RegisterNetEvent('license-system:client:licenseRevoked', function(targetId, licenseType)
|
||||
debugPrint("=== Event: licenseRevoked ===")
|
||||
debugPrint("Lizenz " .. licenseType .. " für Spieler " .. targetId .. " entzogen")
|
||||
|
||||
-- Menü aktualisieren
|
||||
if lib.getOpenContextMenu() then
|
||||
lib.hideContext()
|
||||
Wait(100)
|
||||
openLicenseMenu()
|
||||
end
|
||||
end)
|
||||
|
||||
-- EVENT HANDLER: Lizenz anzeigen (von anderen Spielern)
|
||||
RegisterNetEvent('license-system:client:showLicense', function(targetId)
|
||||
debugPrint("Event erhalten: showLicense für ID " .. tostring(targetId))
|
||||
showPlayerLicense(targetId)
|
||||
end)
|
||||
|
||||
-- EVENT HANDLER: Eigene Lizenz anzeigen
|
||||
RegisterNetEvent('license-system:client:showMyLicense', function(licenseType)
|
||||
debugPrint("Event erhalten: showMyLicense für Typ " .. tostring(licenseType))
|
||||
showMyLicense(licenseType)
|
||||
end)
|
||||
|
||||
-- EVENT HANDLER: Kamera öffnen
|
||||
RegisterNetEvent('license-system:client:openCamera', function()
|
||||
debugPrint("Event erhalten: openCamera")
|
||||
SendNUIMessage({
|
||||
|
@ -596,6 +641,7 @@ RegisterNetEvent('license-system:client:openCamera', function()
|
|||
})
|
||||
end)
|
||||
|
||||
-- EVENT HANDLER: Menü aktualisieren
|
||||
RegisterNetEvent('license-system:client:refreshMenu', function()
|
||||
debugPrint("Event erhalten: refreshMenu")
|
||||
if lib.getOpenContextMenu() then
|
||||
|
@ -605,7 +651,7 @@ RegisterNetEvent('license-system:client:refreshMenu', function()
|
|||
end
|
||||
end)
|
||||
|
||||
-- NUI Callbacks
|
||||
-- NUI CALLBACKS
|
||||
RegisterNUICallback('closeLicense', function(data, cb)
|
||||
debugPrint("NUI Callback: closeLicense")
|
||||
closeLicense()
|
||||
|
@ -642,7 +688,7 @@ RegisterNUICallback('takePicture', function(data, cb)
|
|||
end
|
||||
end)
|
||||
|
||||
-- Commands
|
||||
-- COMMANDS
|
||||
RegisterCommand(Config.Commands.license.name, function()
|
||||
debugPrint("Command ausgeführt: " .. Config.Commands.license.name)
|
||||
openLicenseMenu()
|
||||
|
@ -674,7 +720,7 @@ RegisterCommand('pass', function()
|
|||
showMyLicense('passport')
|
||||
end, false)
|
||||
|
||||
-- Keybinds
|
||||
-- KEYBINDS
|
||||
if Config.Keybinds.open_license_menu then
|
||||
RegisterKeyMapping(Config.Commands.license.name, Config.Keybinds.open_license_menu.description, 'keyboard', Config.Keybinds.open_license_menu.key)
|
||||
end
|
||||
|
@ -698,7 +744,7 @@ CreateThread(function()
|
|||
end
|
||||
end)
|
||||
|
||||
-- Cleanup und Initialisierung
|
||||
-- CLEANUP UND INITIALISIERUNG
|
||||
AddEventHandler('onResourceStop', function(resourceName)
|
||||
if GetCurrentResourceName() == resourceName then
|
||||
if isLicenseShowing then
|
||||
|
@ -715,7 +761,7 @@ end)
|
|||
|
||||
AddEventHandler('onResourceStart', function(resourceName)
|
||||
if GetCurrentResourceName() == resourceName then
|
||||
debugPrint("License-System Client gestartet")
|
||||
debugPrint("License-System Client gestartet (Event-basiert)")
|
||||
|
||||
-- Warten bis QBCore geladen ist
|
||||
while not QBCore do
|
||||
|
@ -748,3 +794,73 @@ CreateThread(function()
|
|||
debugPrint("Spieler ist aktiv - System bereit")
|
||||
end)
|
||||
|
||||
-- Zusätzliche Utility-Funktionen
|
||||
local function requestLicenseWithTimeout(eventName, targetId, timeout)
|
||||
timeout = timeout or 5000
|
||||
local requestId = math.random(1000, 9999)
|
||||
|
||||
pendingRequests[requestId] = {
|
||||
timestamp = GetGameTimer(),
|
||||
timeout = timeout
|
||||
}
|
||||
|
||||
debugPrint("Sende Request mit Timeout: " .. eventName .. " (ID: " .. requestId .. ")")
|
||||
TriggerServerEvent(eventName, targetId, requestId)
|
||||
|
||||
-- Timeout-Handler
|
||||
CreateThread(function()
|
||||
Wait(timeout)
|
||||
if pendingRequests[requestId] then
|
||||
pendingRequests[requestId] = nil
|
||||
debugPrint("^1Request Timeout: " .. eventName .. " (ID: " .. requestId .. ")^7")
|
||||
showNotification('Anfrage-Timeout! Versuche es erneut.', 'error')
|
||||
end
|
||||
end)
|
||||
|
||||
return requestId
|
||||
end
|
||||
|
||||
-- Erweiterte Error-Handling
|
||||
local function safeExecute(func, errorMessage)
|
||||
local success, error = pcall(func)
|
||||
if not success then
|
||||
debugPrint("^1Fehler: " .. (errorMessage or "Unbekannter Fehler") .. "^7")
|
||||
debugPrint("^1Details: " .. tostring(error) .. "^7")
|
||||
showNotification('Ein Fehler ist aufgetreten!', 'error')
|
||||
end
|
||||
return success
|
||||
end
|
||||
|
||||
-- Performance-Monitoring
|
||||
local performanceStats = {
|
||||
menuOpens = 0,
|
||||
licenseShows = 0,
|
||||
errors = 0
|
||||
}
|
||||
|
||||
CreateThread(function()
|
||||
while true do
|
||||
Wait(60000) -- Jede Minute
|
||||
|
||||
if Config.Debug then
|
||||
debugPrint("=== Performance Stats ===")
|
||||
debugPrint("Menü-Öffnungen: " .. performanceStats.menuOpens)
|
||||
debugPrint("Lizenz-Anzeigen: " .. performanceStats.licenseShows)
|
||||
debugPrint("Fehler: " .. performanceStats.errors)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Stats aktualisieren
|
||||
local originalOpenLicenseMenu = openLicenseMenu
|
||||
openLicenseMenu = function()
|
||||
performanceStats.menuOpens = performanceStats.menuOpens + 1
|
||||
return originalOpenLicenseMenu()
|
||||
end
|
||||
|
||||
local originalShowLicense = showLicense
|
||||
showLicense = function(licenseData)
|
||||
performanceStats.licenseShows = performanceStats.licenseShows + 1
|
||||
return originalShowLicense(licenseData)
|
||||
end
|
||||
|
||||
|
|
|
@ -10,16 +10,6 @@ local function debugPrint(message)
|
|||
end
|
||||
end
|
||||
|
||||
local function safeCallback(cb, ...)
|
||||
if cb and type(cb) == "function" then
|
||||
cb(...)
|
||||
return true
|
||||
else
|
||||
debugPrint("^1FEHLER: Callback ist keine Funktion! Typ: " .. type(cb) .. "^7")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local function formatDate(timestamp)
|
||||
if not timestamp then return nil end
|
||||
return os.date("%d.%m.%Y", timestamp)
|
||||
|
@ -165,19 +155,16 @@ local function getIssuerName(citizenid, callback)
|
|||
end)
|
||||
end
|
||||
|
||||
-- Callbacks
|
||||
QBCore.Functions.CreateCallback('license-system:server:getLicense', function(source, cb, targetId)
|
||||
debugPrint("getLicense Callback - Source: " .. source .. ", Target: " .. tostring(targetId))
|
||||
|
||||
if not cb or type(cb) ~= "function" then
|
||||
debugPrint("^1FEHLER: Ungültiger Callback in getLicense!^7")
|
||||
return
|
||||
end
|
||||
-- EVENT: Einzelne Lizenz abrufen
|
||||
RegisterNetEvent('license-system:server:requestLicense', function(targetId)
|
||||
local src = source
|
||||
debugPrint("=== Event: requestLicense ===")
|
||||
debugPrint("Source: " .. src .. ", Target: " .. tostring(targetId))
|
||||
|
||||
local TargetPlayer = QBCore.Functions.GetPlayer(targetId)
|
||||
if not TargetPlayer then
|
||||
debugPrint("^1Ziel-Spieler nicht gefunden: " .. tostring(targetId) .. "^7")
|
||||
safeCallback(cb, nil)
|
||||
TriggerClientEvent('license-system:client:receiveLicense', src, nil)
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -209,27 +196,26 @@ QBCore.Functions.CreateCallback('license-system:server:getLicense', function(sou
|
|||
}
|
||||
}
|
||||
|
||||
safeCallback(cb, licenseData)
|
||||
debugPrint("Sende Lizenz-Daten an Client")
|
||||
TriggerClientEvent('license-system:client:receiveLicense', src, licenseData)
|
||||
end)
|
||||
else
|
||||
debugPrint("Keine aktive Lizenz gefunden für: " .. citizenid)
|
||||
safeCallback(cb, nil)
|
||||
TriggerClientEvent('license-system:client:receiveLicense', src, nil)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
QBCore.Functions.CreateCallback('license-system:server:getMyLicense', function(source, cb, licenseType)
|
||||
debugPrint("getMyLicense Callback - Source: " .. source .. ", Typ: " .. tostring(licenseType))
|
||||
-- EVENT: Eigene Lizenz abrufen
|
||||
RegisterNetEvent('license-system:server:requestMyLicense', function(licenseType)
|
||||
local src = source
|
||||
debugPrint("=== Event: requestMyLicense ===")
|
||||
debugPrint("Source: " .. src .. ", LicenseType: " .. tostring(licenseType))
|
||||
|
||||
if not cb or type(cb) ~= "function" then
|
||||
debugPrint("^1FEHLER: Ungültiger Callback in getMyLicense!^7")
|
||||
return
|
||||
end
|
||||
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if not Player then
|
||||
debugPrint("^1Spieler nicht gefunden: " .. source .. "^7")
|
||||
safeCallback(cb, nil)
|
||||
debugPrint("^1Spieler nicht gefunden: " .. src .. "^7")
|
||||
TriggerClientEvent('license-system:client:receiveMyLicense', src, nil, licenseType)
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -262,73 +248,71 @@ QBCore.Functions.CreateCallback('license-system:server:getMyLicense', function(s
|
|||
}
|
||||
}
|
||||
|
||||
safeCallback(cb, licenseData)
|
||||
debugPrint("Sende eigene Lizenz-Daten an Client")
|
||||
TriggerClientEvent('license-system:client:receiveMyLicense', src, licenseData, licenseType)
|
||||
end)
|
||||
else
|
||||
debugPrint("Keine eigene Lizenz vom Typ " .. licenseType .. " gefunden")
|
||||
safeCallback(cb, nil)
|
||||
TriggerClientEvent('license-system:client:receiveMyLicense', src, nil, licenseType)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
QBCore.Functions.CreateCallback('license-system:server:getPlayerLicenses', function(source, cb, targetId)
|
||||
debugPrint("getPlayerLicenses Callback - Source: " .. source .. ", Target: " .. tostring(targetId))
|
||||
|
||||
if not cb or type(cb) ~= "function" then
|
||||
debugPrint("^1FEHLER: Ungültiger Callback in getPlayerLicenses!^7")
|
||||
return
|
||||
end
|
||||
-- EVENT: Alle Spieler-Lizenzen abrufen
|
||||
RegisterNetEvent('license-system:server:requestPlayerLicenses', function(targetId)
|
||||
local src = source
|
||||
debugPrint("=== Event: requestPlayerLicenses ===")
|
||||
debugPrint("Source: " .. src .. ", Target: " .. tostring(targetId))
|
||||
|
||||
local TargetPlayer = QBCore.Functions.GetPlayer(targetId)
|
||||
if not TargetPlayer then
|
||||
debugPrint("^1Ziel-Spieler nicht gefunden: " .. tostring(targetId) .. "^7")
|
||||
safeCallback(cb, {})
|
||||
TriggerClientEvent('license-system:client:receivePlayerLicenses', src, {}, targetId, "Unbekannt")
|
||||
return
|
||||
end
|
||||
|
||||
local citizenid = TargetPlayer.PlayerData.citizenid
|
||||
local targetName = TargetPlayer.PlayerData.charinfo.firstname .. ' ' .. TargetPlayer.PlayerData.charinfo.lastname
|
||||
debugPrint("Suche alle Lizenzen für CitizenID: " .. citizenid)
|
||||
|
||||
MySQL.Async.fetchAll('SELECT * FROM player_licenses WHERE citizenid = ? ORDER BY created_at DESC', {
|
||||
citizenid
|
||||
}, function(result)
|
||||
if result then
|
||||
debugPrint("Gefundene Lizenzen: " .. #result)
|
||||
local licenses = result or {}
|
||||
debugPrint("Gefundene Lizenzen: " .. #licenses)
|
||||
|
||||
-- Spieler-Daten zu jeder Lizenz hinzufügen
|
||||
for i, license in ipairs(result) do
|
||||
license.name = TargetPlayer.PlayerData.charinfo.firstname .. ' ' .. TargetPlayer.PlayerData.charinfo.lastname
|
||||
license.birthday = TargetPlayer.PlayerData.charinfo.birthdate
|
||||
license.gender = TargetPlayer.PlayerData.charinfo.gender
|
||||
license.issued_by_name = 'System' -- Wird später durch echten Namen ersetzt
|
||||
end
|
||||
-- Spieler-Daten zu jeder Lizenz hinzufügen
|
||||
for i, license in ipairs(licenses) do
|
||||
license.name = TargetPlayer.PlayerData.charinfo.firstname .. ' ' .. TargetPlayer.PlayerData.charinfo.lastname
|
||||
license.birthday = TargetPlayer.PlayerData.charinfo.birthdate
|
||||
license.gender = TargetPlayer.PlayerData.charinfo.gender
|
||||
license.issued_by_name = 'System' -- Wird später durch echten Namen ersetzt
|
||||
|
||||
safeCallback(cb, result)
|
||||
else
|
||||
debugPrint("Keine Lizenzen gefunden")
|
||||
safeCallback(cb, {})
|
||||
debugPrint("Lizenz " .. i .. ": " .. license.license_type .. " (Aktiv: " .. tostring(license.is_active) .. ")")
|
||||
end
|
||||
|
||||
debugPrint("Sende " .. #licenses .. " Lizenzen an Client")
|
||||
TriggerClientEvent('license-system:client:receivePlayerLicenses', src, licenses, targetId, targetName)
|
||||
end)
|
||||
end)
|
||||
|
||||
QBCore.Functions.CreateCallback('license-system:server:canIssueLicense', function(source, cb, licenseType)
|
||||
debugPrint("canIssueLicense Callback - Source: " .. source .. ", Typ: " .. tostring(licenseType))
|
||||
-- EVENT: Berechtigung prüfen
|
||||
RegisterNetEvent('license-system:server:checkPermission', function(licenseType)
|
||||
local src = source
|
||||
debugPrint("=== Event: checkPermission ===")
|
||||
debugPrint("Source: " .. src .. ", LicenseType: " .. tostring(licenseType))
|
||||
|
||||
if not cb or type(cb) ~= "function" then
|
||||
debugPrint("^1FEHLER: Ungültiger Callback in canIssueLicense!^7")
|
||||
return
|
||||
end
|
||||
|
||||
local hasAuth = hasPermission(source, licenseType)
|
||||
local hasAuth = hasPermission(src, licenseType)
|
||||
debugPrint("Berechtigung für Lizenz " .. licenseType .. ": " .. tostring(hasAuth))
|
||||
|
||||
safeCallback(cb, hasAuth)
|
||||
TriggerClientEvent('license-system:client:receivePermission', src, hasAuth, licenseType)
|
||||
end)
|
||||
|
||||
-- Events
|
||||
-- EVENT: Lizenz ausstellen
|
||||
RegisterNetEvent('license-system:server:issueLicense', function(targetId, licenseType, classes)
|
||||
local src = source
|
||||
debugPrint("Event: issueLicense - Von: " .. src .. ", Für: " .. targetId .. ", Typ: " .. licenseType)
|
||||
debugPrint("=== Event: issueLicense ===")
|
||||
debugPrint("Von: " .. src .. ", Für: " .. targetId .. ", Typ: " .. licenseType)
|
||||
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
local TargetPlayer = QBCore.Functions.GetPlayer(targetId)
|
||||
|
@ -384,6 +368,9 @@ RegisterNetEvent('license-system:server:issueLicense', function(targetId, licens
|
|||
TriggerClientEvent('QBCore:Notify', src, Config.Notifications.license_granted.message, Config.Notifications.license_granted.type)
|
||||
TriggerClientEvent('QBCore:Notify', targetId, 'Du hast eine neue ' .. licenseConfig.label .. ' erhalten!', 'success')
|
||||
|
||||
-- Client über erfolgreiche Ausstellung informieren
|
||||
TriggerClientEvent('license-system:client:licenseIssued', src, targetId, licenseType)
|
||||
|
||||
-- Log erstellen
|
||||
debugPrint(Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname .. ' hat ' .. TargetPlayer.PlayerData.charinfo.firstname .. ' ' .. TargetPlayer.PlayerData.charinfo.lastname .. ' eine ' .. licenseConfig.label .. ' ausgestellt')
|
||||
else
|
||||
|
@ -391,9 +378,11 @@ RegisterNetEvent('license-system:server:issueLicense', function(targetId, licens
|
|||
end
|
||||
end)
|
||||
|
||||
-- EVENT: Lizenz entziehen
|
||||
RegisterNetEvent('license-system:server:revokeLicense', function(targetId, licenseType)
|
||||
local src = source
|
||||
debugPrint("Event: revokeLicense - Von: " .. src .. ", Für: " .. targetId .. ", Typ: " .. licenseType)
|
||||
debugPrint("=== Event: revokeLicense ===")
|
||||
debugPrint("Von: " .. src .. ", Für: " .. targetId .. ", Typ: " .. licenseType)
|
||||
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
local TargetPlayer = QBCore.Functions.GetPlayer(targetId)
|
||||
|
@ -423,6 +412,9 @@ RegisterNetEvent('license-system:server:revokeLicense', function(targetId, licen
|
|||
licenseCache[TargetPlayer.PlayerData.citizenid][licenseType] = nil
|
||||
end
|
||||
|
||||
-- Client über erfolgreiche Entziehung informieren
|
||||
TriggerClientEvent('license-system:client:licenseRevoked', src, targetId, licenseType)
|
||||
|
||||
debugPrint(Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname .. ' hat ' .. TargetPlayer.PlayerData.charinfo.firstname .. ' ' .. TargetPlayer.PlayerData.charinfo.lastname .. ' die ' .. (Config.LicenseTypes[licenseType] and Config.LicenseTypes[licenseType].label or licenseType) .. ' entzogen')
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Keine aktive Lizenz gefunden!', 'error')
|
||||
|
@ -430,9 +422,11 @@ RegisterNetEvent('license-system:server:revokeLicense', function(targetId, licen
|
|||
end)
|
||||
end)
|
||||
|
||||
-- EVENT: Foto speichern
|
||||
RegisterNetEvent('license-system:server:savePhoto', function(citizenid, photoData)
|
||||
local src = source
|
||||
debugPrint("Event: savePhoto für CitizenID: " .. citizenid)
|
||||
debugPrint("=== Event: savePhoto ===")
|
||||
debugPrint("CitizenID: " .. citizenid)
|
||||
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if not Player then return end
|
||||
|
@ -537,7 +531,7 @@ end)
|
|||
-- Resource Start/Stop Events
|
||||
AddEventHandler('onResourceStart', function(resourceName)
|
||||
if GetCurrentResourceName() == resourceName then
|
||||
debugPrint("License-System Server gestartet")
|
||||
debugPrint("License-System Server gestartet (Event-basiert)")
|
||||
|
||||
-- Datenbank-Tabelle erstellen falls nicht vorhanden
|
||||
MySQL.Async.execute([[
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue