-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
472 lines (397 loc) · 22.5 KB
/
Copy pathserver.lua
File metadata and controls
472 lines (397 loc) · 22.5 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
local Ox = require '@ox_core.lib.init'
local ox_inventory = exports.ox_inventory
-- ═══════════════════════════════════════════════════
-- 🌐 Locale Helper
-- ═══════════════════════════════════════════════════
---Translate a key, with optional string.format args.
---Falls back to EN if key missing in active locale.
---@param key string
---@param ... any
local function T(key, ...)
local locale = Config.Locales[Config.Locale] or Config.Locales['en']
local str = locale[key] or Config.Locales['en'][key] or key
if select('#', ...) > 0 then
return str:format(...)
end
return str
end
-- ═══════════════════════════════════════════════════
-- 🎯 State Management
-- ═══════════════════════════════════════════════════
local ServerState = {
hookerData = {},
playerHookers = {},
serviceStats = {
totalInvites = 0,
totalServices = 0,
totalRevenue = 0,
blowjobs = 0,
fullServices = 0,
},
}
-- ═══════════════════════════════════════════════════
-- 🛠️ Utility
-- ═══════════════════════════════════════════════════
local function GetPedName(playerId)
return GetPlayerName(playerId) or 'Unknown'
end
local function Debug(...)
if not Config.Debug then return end
print(('[^5HOOKER^7][^3SERVER^7][^2%s^7] %s'):format(
os.date('%H:%M:%S'),
table.concat({...}, ' ')
))
end
-- ═══════════════════════════════════════════════════
-- 📡 Nostr Logger — Optional Integration
-- ═══════════════════════════════════════════════════
local function NostrLog(message, tags)
if GetResourceState('rde_nostr_log') ~= 'started' then return end
local ok, err = pcall(function()
exports['rde_nostr_log']:postLog(message, tags or {})
end)
if not ok and Config.Debug then
print(('[^5HOOKER^7][^1NOSTR-ERR^7] %s'):format(tostring(err)))
end
end
local function NostrInvite(playerId, hookerNetId)
NostrLog(('💋 [HOOKER] %s (ID:%d) invited hooker (NetID:%d)'):format(GetPedName(playerId), playerId, hookerNetId), {
{ 'script', 'rde_hookers' }, { 'event', 'hooker_invite' },
{ 'player_id', tostring(playerId) }, { 'player_name', GetPedName(playerId) },
{ 'hooker_net', tostring(hookerNetId) },
})
end
local function NostrService(playerId, serviceType, price)
local emoji = serviceType == 'blowjob' and '👄' or '🔥'
NostrLog(('%s [HOOKER] %s (ID:%d) purchased %s for $%d'):format(emoji, GetPedName(playerId), playerId, serviceType, price), {
{ 'script', 'rde_hookers' }, { 'event', 'hooker_service' },
{ 'player_id', tostring(playerId) }, { 'player_name', GetPedName(playerId) },
{ 'service_type', serviceType }, { 'price', tostring(price) },
})
end
local function NostrServiceAbort(playerId, serviceType, reason)
NostrLog(('❌ [HOOKER] %s (ID:%d) – service "%s" aborted: %s'):format(GetPedName(playerId), playerId, serviceType, reason), {
{ 'script', 'rde_hookers' }, { 'event', 'hooker_service_abort' },
{ 'player_id', tostring(playerId) }, { 'player_name', GetPedName(playerId) },
{ 'service_type', serviceType }, { 'reason', reason },
})
end
local function NostrDismiss(playerId, hookerNetId, reason)
NostrLog(('👋 [HOOKER] %s (ID:%d) dismissed hooker (NetID:%d) – %s'):format(GetPedName(playerId), playerId, hookerNetId, reason or 'manual'), {
{ 'script', 'rde_hookers' }, { 'event', 'hooker_dismiss' },
{ 'player_id', tostring(playerId) }, { 'player_name', GetPedName(playerId) },
{ 'hooker_net', tostring(hookerNetId) }, { 'reason', reason or 'manual' },
})
end
local function NostrDisconnect(playerId, playerName, reason)
NostrLog(('🚪 [HOOKER] %s (ID:%d) disconnected with active hooker – %s'):format(playerName, playerId, reason or '?'), {
{ 'script', 'rde_hookers' }, { 'event', 'hooker_dc_cleanup' },
{ 'player_id', tostring(playerId) }, { 'player_name', playerName },
{ 'dc_reason', reason or '?' },
})
end
local function NostrAdmin(adminId, action, detail)
NostrLog(('👑 [HOOKER ADMIN] %s (ID:%d) – %s%s'):format(GetPedName(adminId), adminId, action, detail and (' | ' .. detail) or ''), {
{ 'script', 'rde_hookers' }, { 'event', 'hooker_admin' },
{ 'admin_id', tostring(adminId) }, { 'admin_name', GetPedName(adminId) },
{ 'action', action }, { 'detail', detail or '' },
})
end
-- ═══════════════════════════════════════════════════
-- 💰 Money Helpers
-- ═══════════════════════════════════════════════════
local function GetPlayerMoney(playerId)
local count = ox_inventory:GetItem(playerId, Config.Currency, nil, true)
return type(count) == 'number' and count or 0
end
local function HasEnoughMoney(playerId, amount)
local balance = GetPlayerMoney(playerId)
return balance >= amount, balance
end
local function RemovePlayerMoney(playerId, amount)
local hasEnough, balance = HasEnoughMoney(playerId, amount)
if not hasEnough then
local shortage = amount - balance
Debug('❌ Player', playerId, 'lacks $' .. shortage)
return false, shortage
end
local ok = ox_inventory:RemoveItem(playerId, Config.Currency, amount)
if ok then
ServerState.serviceStats.totalRevenue += amount
Debug('✅ Removed $' .. amount .. ' from player', playerId)
return true, 0
end
Debug('❌ RemoveItem failed for player', playerId)
return false, amount
end
-- ═══════════════════════════════════════════════════
-- 🔎 Validation / Cleanup
-- ═══════════════════════════════════════════════════
local function GetOxPlayer(playerId)
local player = Ox.GetPlayer(playerId)
if not player then Debug('⚠️ GetPlayer nil for source', playerId) end
return player
end
local function ValidateHooker(hooker, playerId)
if not hooker or not DoesEntityExist(hooker) then
return false, T('hooker_invalid')
end
local state = Entity(hooker).state
if not state then return false, T('hooker_invalid') end
if playerId and state.withPlayer and state.withPlayer ~= playerId then
return false, T('hooker_invalid')
end
return true
end
local function CleanupHooker(hooker, playerId)
if not DoesEntityExist(hooker) then return end
Debug('🧹 Cleaning up hooker:', hooker, '| player:', playerId or 'any')
local state = Entity(hooker).state
if state then
state:set('withPlayer', nil, true)
state:set('inService', nil, true)
state:set('invitedAt', nil, true)
end
local entry = ServerState.hookerData[hooker]
if entry then
local owner = entry.player
if owner and ServerState.playerHookers[owner] == hooker then
ServerState.playerHookers[owner] = nil
end
ServerState.hookerData[hooker] = nil
end
if playerId and ServerState.playerHookers[playerId] == hooker then
ServerState.playerHookers[playerId] = nil
end
end
-- ═══════════════════════════════════════════════════
-- 📨 Network Events
-- ═══════════════════════════════════════════════════
RegisterNetEvent('hooker:inviteHooker', function(hookerNetId)
local src = source
if not src or src == 0 then return end
if not GetOxPlayer(src) then
TriggerClientEvent('ox_lib:notify', src, { title = Config.Icons.error .. ' ' .. T('not_available'), description = T('session_error'), type = 'error' })
return
end
local ok, err = pcall(function()
local hooker = NetworkGetEntityFromNetworkId(hookerNetId)
if not DoesEntityExist(hooker) then error(T('hooker_invalid')) end
local valid, reason = ValidateHooker(hooker, src)
if not valid then error(reason) end
if ServerState.playerHookers[src] then error(T('already_busy')) end
local state = Entity(hooker).state
if state.withPlayer and state.withPlayer ~= src then error(T('hooker_invalid')) end
Entity(hooker).state:set('withPlayer', src, true)
Entity(hooker).state:set('invitedAt', os.time(), true)
ServerState.hookerData[hooker] = { player = src, invitedAt = os.time(), entity = hooker, netId = hookerNetId }
ServerState.playerHookers[src] = hooker
ServerState.serviceStats.totalInvites += 1
Debug('✅ Player', src, GetPedName(src), 'invited hooker netId:', hookerNetId)
NostrInvite(src, hookerNetId)
TriggerClientEvent('hooker:invitationAccepted', src, hookerNetId)
TriggerClientEvent('ox_lib:notify', src, {
title = Config.Icons.success .. ' ' .. T('shes_coming'),
description = T('shes_coming_desc'),
type = 'success',
})
end)
if not ok then
Debug('❌ hooker:inviteHooker error:', err)
TriggerClientEvent('ox_lib:notify', src, {
title = Config.Icons.error .. ' ' .. T('not_available'),
description = tostring(err):gsub('^.-: ', ''),
type = 'error',
})
end
end)
-- ────────────────────────────────────────────────────
RegisterNetEvent('hooker:requestService', function(serviceType, hookerNetId)
local src = source
if not src or src == 0 then return end
if serviceType ~= 'blowjob' and serviceType ~= 'sex' then
Debug('❌ Invalid service type from player', src, ':', serviceType)
return
end
if not GetOxPlayer(src) then return end
local ok, err = pcall(function()
local hooker = NetworkGetEntityFromNetworkId(hookerNetId)
if not DoesEntityExist(hooker) then error(T('hooker_invalid')) end
local valid, reason = ValidateHooker(hooker, src)
if not valid then error(reason) end
if ServerState.playerHookers[src] ~= hooker then error(T('hooker_invalid')) end
local state = Entity(hooker).state
if state.inService then error(T('service_busy')) end
local price = serviceType == 'blowjob' and Config.BlowjobPrice or Config.SexPrice
local serviceName = serviceType == 'blowjob' and T('blowjob_title') or T('sex_title')
local paid, shortage = RemovePlayerMoney(src, price)
if not paid then
error(('$%d %s'):format(shortage, serviceName))
end
ServerState.serviceStats.totalServices += 1
if serviceType == 'blowjob' then
ServerState.serviceStats.blowjobs += 1
else
ServerState.serviceStats.fullServices += 1
end
Debug('💰 Player', src, GetPedName(src), 'paid $' .. price, 'for', serviceType)
NostrService(src, serviceType, price)
Entity(hooker).state:set('inService', { player = src, type = serviceType, startTime = os.time() }, true)
local duration = serviceType == 'blowjob' and Config.BlowjobDuration or Config.SexDuration
SetTimeout((duration + 10) * 1000, function()
if DoesEntityExist(hooker) then
Entity(hooker).state:set('inService', nil, true)
end
end)
TriggerClientEvent('hooker:startService', src, serviceType, hookerNetId)
TriggerClientEvent('ox_lib:notify', src, {
title = Config.Icons.success .. ' ' .. T('service_started'),
description = T('service_started_desc', Config.Icons.money, price, serviceName),
type = 'success',
})
end)
if not ok then
Debug('❌ hooker:requestService error:', err)
local cleanErr = tostring(err):gsub('^.-: ', '')
NostrServiceAbort(src, serviceType, cleanErr)
TriggerClientEvent('ox_lib:notify', src, {
title = Config.Icons.error .. ' ' .. T('cannot_start'),
description = cleanErr,
type = 'error',
})
TriggerClientEvent('hooker:serviceAborted', src)
end
end)
-- ────────────────────────────────────────────────────
RegisterNetEvent('hooker:dismissHooker', function(hookerNetId)
local src = source
if not src or src == 0 then return end
local ok, err = pcall(function()
local hooker = NetworkGetEntityFromNetworkId(hookerNetId)
if not DoesEntityExist(hooker) then error(T('hooker_invalid')) end
local valid, reason = ValidateHooker(hooker, src)
if not valid then error(reason) end
Debug('👋 Player', src, 'dismissed hooker netId:', hookerNetId)
NostrDismiss(src, hookerNetId, 'manual')
CleanupHooker(hooker, src)
TriggerClientEvent('hooker:dismissed', src, hookerNetId)
end)
if not ok then
Debug('❌ hooker:dismissHooker error:', err)
end
end)
-- ═══════════════════════════════════════════════════
-- 🔔 Player Disconnect
-- ═══════════════════════════════════════════════════
AddEventHandler('playerDropped', function(reason)
local src = source
local name = GetPedName(src)
Debug('🚪 Player', src, name, 'disconnected:', reason)
local hooker = ServerState.playerHookers[src]
if hooker then
NostrDisconnect(src, name, reason)
CleanupHooker(hooker, src)
end
end)
-- ═══════════════════════════════════════════════════
-- 📡 Statebag Monitoring (debug)
-- ═══════════════════════════════════════════════════
if Config.Debug then
AddStateBagChangeHandler('withPlayer', nil, function(bagName, _, value)
if value then Debug('📡 Statebag:', bagName, '→ withPlayer =', value)
else Debug('📡 Statebag:', bagName, '→ withPlayer cleared') end
end)
AddStateBagChangeHandler('inService', nil, function(bagName, _, value)
if value then Debug('📡 Service started:', bagName, '→ Player:', value.player, '| Type:', value.type)
else Debug('📡 Service ended:', bagName) end
end)
end
-- ═══════════════════════════════════════════════════
-- 🎮 Admin Commands
-- ═══════════════════════════════════════════════════
lib.addCommand('hookerstats', { help = 'Show hooker system statistics', restricted = 'group.admin' }, function(src)
local active, inSvc = 0, 0
for hooker in pairs(ServerState.hookerData) do
if DoesEntityExist(hooker) then
active += 1
if Entity(hooker).state.inService then inSvc += 1 end
end
end
local s = ServerState.serviceStats
NostrAdmin(src, 'hookerstats', ('active=%d inService=%d revenue=$%d'):format(active, inSvc, s.totalRevenue))
TriggerClientEvent('ox_lib:notify', src, {
title = Config.Icons.info .. ' ' .. T('stats_title'),
description = ('📊 **Active:** %d 🔥 **In Service:** %d\n\n💰 **Revenue:** $%d\n👋 **Invites:** %d 🎯 **Services:** %d\n👄 **BJs:** %d 🔥 **Full:** %d'):format(
active, inSvc, s.totalRevenue, s.totalInvites, s.totalServices, s.blowjobs, s.fullServices),
type = 'info', duration = 15000,
})
end)
lib.addCommand('hookercleanup', { help = 'Cleanup all active hookers', restricted = 'group.admin' }, function(src)
local count = 0
for hooker, data in pairs(ServerState.hookerData) do
if DoesEntityExist(hooker) then
if data.player then TriggerClientEvent('hooker:dismissed', data.player, NetworkGetNetworkIdFromEntity(hooker)) end
CleanupHooker(hooker, data.player)
count += 1
end
end
ServerState.hookerData = {}
ServerState.playerHookers = {}
NostrAdmin(src, 'hookercleanup', ('removed %d hooker(s)'):format(count))
TriggerClientEvent('ox_lib:notify', src, {
title = Config.Icons.success .. ' ' .. T('cleanup_complete'),
description = T('cleanup_desc', count), type = 'success',
})
Debug('🧹 Admin cleanup: removed', count, 'hooker(s)')
end)
lib.addCommand('hookerresetstats', { help = 'Reset hooker system statistics', restricted = 'group.admin' }, function(src)
ServerState.serviceStats = { totalInvites = 0, totalServices = 0, totalRevenue = 0, blowjobs = 0, fullServices = 0 }
NostrAdmin(src, 'hookerresetstats', 'all statistics reset')
TriggerClientEvent('ox_lib:notify', src, {
title = Config.Icons.success .. ' ' .. T('stats_reset'),
description = T('stats_reset_desc'), type = 'success',
})
Debug('📊 Admin reset statistics')
end)
-- ═══════════════════════════════════════════════════
-- 📤 Exports
-- ═══════════════════════════════════════════════════
exports('HasEnoughMoney', function(src, amount) return HasEnoughMoney(src, amount) end)
exports('GetServicePrice', function(t) return t == 'blowjob' and Config.BlowjobPrice or Config.SexPrice end)
exports('GetStatistics', function() return ServerState.serviceStats end)
exports('PlayerHasHooker', function(src) return ServerState.playerHookers[src] ~= nil end)
exports('GetActiveHookerCount', function()
local c = 0
for h in pairs(ServerState.hookerData) do if DoesEntityExist(h) then c += 1 end end
return c
end)
-- ═══════════════════════════════════════════════════
-- 🚀 Startup Banner
-- ═══════════════════════════════════════════════════
CreateThread(function()
local version = GetResourceMetadata(GetCurrentResourceName(), 'version', 0) or '1.0.0'
local libVersion = GetResourceMetadata('ox_lib', 'version', 0) or '?'
local coreVersion = GetResourceMetadata('ox_core', 'version', 0) or '?'
print('^5═══════════════════════════════════════════════════════^7')
print('^5██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗ ^7')
print('^5██║ ██║██╔═══██╗██╔═══██╗██║ ██╔╝██╔════╝██╔══██╗^7')
print('^5███████║██║ ██║██║ ██║█████╔╝ █████╗ ██████╔╝^7')
print('^5██╔══██║██║ ██║██║ ██║██╔═██╗ ██╔══╝ ██╔══██╗^7')
print('^5██║ ██║╚██████╔╝╚██████╔╝██║ ██╗███████╗██║ ██║^7')
print('^5╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝^7')
print('^5═══════════════════════════════════════════════════════^7')
print('^5 RDE Hooker System ^3v' .. version .. '^7')
print(('^5 ox_lib ^3%s^5 • ox_core ^3%s^7'):format(libVersion, coreVersion))
print('^5═══════════════════════════════════════════════════════^7')
if Config.Debug then
print('^3[HOOKER]^7 ^1' .. T('debug_enabled') .. '^7')
print((' 💰 Blowjob: ^2$%d^7 / ^2%ds^7'):format(Config.BlowjobPrice, Config.BlowjobDuration))
print((' 🔥 Full: ^2$%d^7 / ^2%ds^7'):format(Config.SexPrice, Config.SexDuration))
print((' 🧸 Currency: ^2%s^7 Models: ^2%d^7'):format(Config.Currency, #Config.HookerModels))
print((' 🌐 Locale: ^2%s^7'):format(Config.Locale))
print(' Commands: /hookerstats /hookercleanup /hookerresetstats')
end
print('^2[HOOKER]^7 ' .. T('server_ready'))
print('^5═══════════════════════════════════════════════════════^7')
end)
Debug('✅ Server initialised | Locale: ' .. Config.Locale)