Repository navigation
Expand file tree
/
Copy pathclient.lua
More file actions
276 lines (243 loc) · 10.9 KB
/
Copy pathclient.lua
File metadata and controls
276 lines (243 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
-- ─────────────────────────────────────────────────────────────────────────────
-- qb-report | client.lua
-- ─────────────────────────────────────────────────────────────────────────────
local QBCore = exports['qb-core']:GetCoreObject()
local isNUIOpen = false
local isAdminOpen = false
local isHistoryOpen = false
-- ─────────────────────────────────────────
-- Locale sistemi
-- ─────────────────────────────────────────
local Locale = {}
local function LoadLocale(lang)
local ok, data = pcall(function()
return LoadResourceFile(GetCurrentResourceName(), 'locales/' .. lang .. '.lua')
end)
if ok and data then
local fn, err = load(data)
if fn then
return fn()
else
print('^1[qb-report] Locale parse hatası (' .. lang .. '): ' .. tostring(err) .. '^0')
end
end
return nil
end
-- Önce seçilen dili yükle, başarısız olursa 'en' fallback
local function InitLocale()
local lang = Config.Locale or 'en'
local data = LoadLocale(lang)
if not data then
print('^3[qb-report] ' .. lang .. ' locale yüklenemedi, İngilizce\'ye düşülüyor.^0')
data = LoadLocale('en')
end
Locale = data or {}
end
InitLocale()
-- Çeviri fonksiyonu ({key} placeholder desteği)
local function T(key, vars)
local str = Locale[key] or key
if vars then
for k, v in pairs(vars) do
str = str:gsub('{' .. k .. '}', tostring(v))
end
end
return str
end
-- ─────────────────────────────────────────
-- Kategori etiketlerini locale'den doldur
-- ─────────────────────────────────────────
local function GetCategories()
local cats = {}
for _, v in ipairs(Config.Categories) do
local label = T('cat_' .. v.id)
cats[#cats + 1] = {
id = v.id,
label = label,
icon = v.icon,
color = v.color,
}
end
return cats
end
-- ─────────────────────────────────────────
-- NUI'yi kapat
-- ─────────────────────────────────────────
local function CloseNUI()
print('[DEBUG] CloseNUI() called - isNUIOpen: ' .. tostring(isNUIOpen) .. ', isAdminOpen: ' .. tostring(isAdminOpen) .. ', isHistoryOpen: ' .. tostring(isHistoryOpen))
isNUIOpen = false
isAdminOpen = false
isHistoryOpen = false
SetNuiFocus(false, false)
print('[DEBUG] SetNuiFocus(false, false) called in CloseNUI()')
SendNUIMessage({ action = 'closeAll' })
end
-- ─────────────────────────────────────────
-- Rapor menüsü
-- ─────────────────────────────────────────
local function OpenReportMenu()
if isNUIOpen or isAdminOpen or isHistoryOpen then return end
QBCore.Functions.TriggerCallback('qb-report:server:getPlayers', function(players)
isNUIOpen = true
SetNuiFocus(true, true)
-- NUI'ye dil bilgisini de gönder
SendNUIMessage({ action = 'setLang', lang = Config.Locale or 'en' })
SendNUIMessage({ action = 'openReport', categories = GetCategories(), players = players })
end)
end
-- ─────────────────────────────────────────
-- Admin paneli
-- ─────────────────────────────────────────
local function OpenAdminPanel(reports)
if isNUIOpen or isAdminOpen or isHistoryOpen then return end
isAdminOpen = true
SetNuiFocus(true, true)
SendNUIMessage({ action = 'setLang', lang = Config.Locale or 'en' })
SendNUIMessage({ action = 'openAdmin', reports = reports })
end
-- ─────────────────────────────────────────
-- History paneli
-- ─────────────────────────────────────────
local function OpenHistoryPanel()
if isNUIOpen or isAdminOpen or isHistoryOpen then return end
isHistoryOpen = true
SetNuiFocus(true, true)
SendNUIMessage({ action = 'setLang', lang = Config.Locale or 'en' })
SendNUIMessage({ action = 'openHistory' })
-- İlk sayfa verilerini hemen yükle
QBCore.Functions.TriggerCallback('qb-report:server:getHistory', function(data)
SendNUIMessage({ action = 'loadHistory', data = data, page = 1 })
end, { page = 1, filter = 'all', search = '' })
end
-- ─────────────────────────────────────────
-- Komutlar
-- ─────────────────────────────────────────
RegisterCommand(Config.Command, function()
OpenReportMenu()
end, false)
RegisterCommand(Config.AdminCommand, function()
TriggerServerEvent('qb-report:server:checkAdmin')
end, false)
RegisterCommand(Config.SuperAdminCommand, function()
TriggerServerEvent('qb-report:server:checkSuperAdmin')
end, false)
-- ─────────────────────────────────────────
-- Server → Client olayları
-- ─────────────────────────────────────────
RegisterNetEvent('qb-report:client:openAdminPanel', function()
TriggerServerEvent('qb-report:server:getReports')
end)
RegisterNetEvent('qb-report:client:receiveReports', function(reports)
if type(reports) ~= 'table' then return end
OpenAdminPanel(reports)
end)
RegisterNetEvent('qb-report:client:openHistoryPanel', function()
OpenHistoryPanel()
end)
RegisterNetEvent('qb-report:client:reportSent', function()
print('[DEBUG] reportSent event received from server')
CloseNUI()
QBCore.Functions.Notify(T('report_sent'), 'success', 5000)
end)
RegisterNetEvent('qb-report:client:cooldown', function(remaining)
remaining = tonumber(remaining) or 0
CloseNUI()
QBCore.Functions.Notify(T('cooldown', { seconds = remaining }), 'error', 4000)
end)
RegisterNetEvent('qb-report:client:refreshReports', function(reports)
if type(reports) ~= 'table' then return end
if isAdminOpen then
SendNUIMessage({ action = 'updateReports', reports = reports })
end
end)
RegisterNetEvent('qb-report:client:newReportAlert', function(report)
if type(report) ~= 'table' then return end
SendNUIMessage({ action = 'newReportAlert', report = report })
QBCore.Functions.Notify(T('admin_notify'), 'primary', 5000)
end)
RegisterNetEvent('qb-report:client:teleportCoords', function(coords)
if type(coords) ~= 'table' then return end
local x, y, z = tonumber(coords.x), tonumber(coords.y), tonumber(coords.z)
if not x or not y or not z then return end
SetEntityCoords(PlayerPedId(), x, y, z, false, false, false, true)
end)
-- ─────────────────────────────────────────
-- NUI Callbacks
-- ─────────────────────────────────────────
RegisterNUICallback('closeReport', function(_, cb)
print('[DEBUG] closeReport NUI callback triggered')
isNUIOpen = false
SetNuiFocus(false, false)
print('[DEBUG] SetNuiFocus(false, false) called in closeReport callback')
cb('ok')
end)
RegisterNUICallback('closeAdmin', function(_, cb)
isAdminOpen = false
SetNuiFocus(false, false)
cb('ok')
end)
RegisterNUICallback('closeHistory', function(_, cb)
isHistoryOpen = false
SetNuiFocus(false, false)
cb('ok')
end)
RegisterNUICallback('submitReport', function(data, cb)
print('[DEBUG] submitReport NUI callback triggered')
if type(data) ~= 'table' then cb('err') return end
local cat = type(data.category) == 'string' and data.category or nil
local label = type(data.categoryLabel) == 'string' and data.categoryLabel or nil
local desc = type(data.description) == 'string' and data.description or nil
if not cat or not desc or #desc < 5 then cb('err') return end
print('[DEBUG] Sending submitReport to server')
TriggerServerEvent('qb-report:server:submitReport', {
category = cat,
categoryLabel = label,
description = desc:sub(1, 500),
targetId = tonumber(data.targetId),
targetName = type(data.targetName) == 'string' and data.targetName or nil,
})
print('[DEBUG] submitReport sent, returning cb(ok)')
cb('ok')
end)
RegisterNUICallback('claimReport', function(data, cb)
if type(data) ~= 'table' then cb('err') return end
local id = tonumber(data.reportId)
if not id then cb('err') return end
TriggerServerEvent('qb-report:server:claimReport', id)
cb('ok')
end)
RegisterNUICallback('resolveReport', function(data, cb)
if type(data) ~= 'table' then cb('err') return end
local id = tonumber(data.reportId)
if not id then cb('err') return end
TriggerServerEvent('qb-report:server:resolveReport', id)
cb('ok')
end)
RegisterNUICallback('teleportToReporter', function(data, cb)
if type(data) ~= 'table' then cb('err') return end
local pid = tonumber(data.playerId)
if not pid then cb('err') return end
TriggerServerEvent('qb-report:server:teleportToReporter', pid)
cb('ok')
end)
RegisterNUICallback('refreshReports', function(_, cb)
TriggerServerEvent('qb-report:server:getReports')
cb('ok')
end)
-- History: sayfalama / filtre / arama
RegisterNUICallback('fetchHistory', function(data, cb)
if type(data) ~= 'table' then cb('err') return end
QBCore.Functions.TriggerCallback('qb-report:server:getHistory', function(result)
SendNUIMessage({ action = 'loadHistory', data = result, page = data.page or 1 })
cb('ok')
end, {
page = tonumber(data.page) or 1,
filter = tostring(data.filter or 'all'),
search = tostring(data.search or ''),
status = tostring(data.status or 'all'),
})
end)
RegisterNUICallback('escPressed', function(_, cb)
CloseNUI()
cb('ok')
end)