-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathserver.lua
More file actions
1104 lines (1011 loc) · 47.6 KB
/
server.lua
File metadata and controls
1104 lines (1011 loc) · 47.6 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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local QBCore = exports['qb-core']:GetCoreObject({ 'Functions', 'Commands' })
local sharedVehicles = exports['qb-core']:GetShared('Vehicles')
local QBPhone = {}
local AppAlerts = {}
local MentionedTweets = {}
local Hashtags = {}
local Calls = {}
local Adverts = {}
local GeneratedPlates = {}
local WebHook = ''
local FivemerrApiToken = ''
local bannedCharacters = { '%', '$', ';' }
local TWData = {}
-- Functions
local function Round(value, numDecimalPlaces)
local mult = 10 ^ (numDecimalPlaces or 0)
return math.floor(value * mult + 0.5) / mult
end
local function GetOnlineStatus(number)
local Target = QBCore.Functions.GetPlayerByPhone(number)
local retval = false
if Target ~= nil then
retval = true
end
return retval
end
local function GenerateMailId()
return math.random(111111, 999999)
end
local function escape_sqli(source)
local replacements = {
['"'] = '\\"',
["'"] = "\\'"
}
return source:gsub("['\"]", replacements)
end
function QBPhone.AddMentionedTweet(citizenid, TweetData)
if MentionedTweets[citizenid] == nil then
MentionedTweets[citizenid] = {}
end
MentionedTweets[citizenid][#MentionedTweets[citizenid] + 1] = TweetData
end
function QBPhone.SetPhoneAlerts(citizenid, app, alerts)
if citizenid ~= nil and app ~= nil then
if AppAlerts[citizenid] == nil then
AppAlerts[citizenid] = {}
if AppAlerts[citizenid][app] == nil then
if alerts == nil then
AppAlerts[citizenid][app] = 1
else
AppAlerts[citizenid][app] = alerts
end
end
else
if AppAlerts[citizenid][app] == nil then
if alerts == nil then
AppAlerts[citizenid][app] = 1
else
AppAlerts[citizenid][app] = 0
end
else
if alerts == nil then
AppAlerts[citizenid][app] = AppAlerts[citizenid][app] + 1
else
AppAlerts[citizenid][app] = AppAlerts[citizenid][app] + 0
end
end
end
end
end
local function SplitStringToArray(string)
local retval = {}
for i in string.gmatch(string, '%S+') do
retval[#retval + 1] = i
end
return retval
end
local function GenerateOwnerName()
local names = {
[1] = { name = 'Bailey Sykes', citizenid = 'DSH091G93' },
[2] = { name = 'Aroush Goodwin', citizenid = 'AVH09M193' },
[3] = { name = 'Tom Warren', citizenid = 'DVH091T93' },
[4] = { name = 'Abdallah Friedman', citizenid = 'GZP091G93' },
[5] = { name = 'Lavinia Powell', citizenid = 'DRH09Z193' },
[6] = { name = 'Andrew Delarosa', citizenid = 'KGV091J93' },
[7] = { name = 'Skye Cardenas', citizenid = 'ODF09S193' },
[8] = { name = 'Amelia-Mae Walter', citizenid = 'KSD0919H3' },
[9] = { name = 'Elisha Cote', citizenid = 'NDX091D93' },
[10] = { name = 'Janice Rhodes', citizenid = 'ZAL0919X3' },
[11] = { name = 'Justin Harris', citizenid = 'ZAK09D193' },
[12] = { name = 'Montel Graves', citizenid = 'POL09F193' },
[13] = { name = 'Benjamin Zavala', citizenid = 'TEW0J9193' },
[14] = { name = 'Mia Willis', citizenid = 'YOO09H193' },
[15] = { name = 'Jacques Schmitt', citizenid = 'QBC091H93' },
[16] = { name = 'Mert Simmonds', citizenid = 'YDN091H93' },
[17] = { name = 'Rickie Browne', citizenid = 'PJD09D193' },
[18] = { name = 'Deacon Stanley', citizenid = 'RND091D93' },
[19] = { name = 'Daisy Fraser', citizenid = 'QWE091A93' },
[20] = { name = 'Kitty Walters', citizenid = 'KJH0919M3' },
[21] = { name = 'Jareth Fernandez', citizenid = 'ZXC09D193' },
[22] = { name = 'Meredith Calhoun', citizenid = 'XYZ0919C3' },
[23] = { name = 'Teagan Mckay', citizenid = 'ZYX0919F3' },
[24] = { name = 'Kurt Bain', citizenid = 'IOP091O93' },
[25] = { name = 'Burt Kain', citizenid = 'PIO091R93' },
[26] = { name = 'Joanna Huff', citizenid = 'LEK091X93' },
[27] = { name = 'Carrie-Ann Pineda', citizenid = 'ALG091Y93' },
[28] = { name = 'Gracie-Mai Mcghee', citizenid = 'YUR09E193' },
[29] = { name = 'Robyn Boone', citizenid = 'SOM091W93' },
[30] = { name = 'Aliya William', citizenid = 'KAS009193' },
[31] = { name = 'Rohit West', citizenid = 'SOK091093' },
[32] = { name = 'Skylar Archer', citizenid = 'LOK091093' },
[33] = { name = 'Jake Kumar', citizenid = 'AKA420609' },
}
return names[math.random(1, #names)]
end
local function sendNewMailToOffline(citizenid, mailData)
local Player = QBCore.Functions.GetPlayerByCitizenId(citizenid)
if Player then
local src = Player.PlayerData.source
if mailData.button == nil then
MySQL.insert('INSERT INTO player_mails (`citizenid`, `sender`, `subject`, `message`, `mailid`, `read`) VALUES (?, ?, ?, ?, ?, ?)', { Player.PlayerData.citizenid, mailData.sender, mailData.subject, mailData.message, GenerateMailId(), 0 })
TriggerClientEvent('qb-phone:client:NewMailNotify', src, mailData)
else
MySQL.insert('INSERT INTO player_mails (`citizenid`, `sender`, `subject`, `message`, `mailid`, `read`, `button`) VALUES (?, ?, ?, ?, ?, ?, ?)', { Player.PlayerData.citizenid, mailData.sender, mailData.subject, mailData.message, GenerateMailId(), 0, json.encode(mailData.button) })
TriggerClientEvent('qb-phone:client:NewMailNotify', src, mailData)
end
SetTimeout(200, function()
local mails = MySQL.query.await(
'SELECT * FROM player_mails WHERE citizenid = ? ORDER BY `date` ASC', { Player.PlayerData.citizenid })
if mails[1] ~= nil then
for k, _ in pairs(mails) do
if mails[k].button ~= nil then
mails[k].button = json.decode(mails[k].button)
end
end
end
TriggerClientEvent('qb-phone:client:UpdateMails', src, mails)
end)
else
if mailData.button == nil then
MySQL.insert('INSERT INTO player_mails (`citizenid`, `sender`, `subject`, `message`, `mailid`, `read`) VALUES (?, ?, ?, ?, ?, ?)', { citizenid, mailData.sender, mailData.subject, mailData.message, GenerateMailId(), 0 })
else
MySQL.insert('INSERT INTO player_mails (`citizenid`, `sender`, `subject`, `message`, `mailid`, `read`, `button`) VALUES (?, ?, ?, ?, ?, ?, ?)', { citizenid, mailData.sender, mailData.subject, mailData.message, GenerateMailId(), 0, json.encode(mailData.button) })
end
end
end
exports('sendNewMailToOffline', sendNewMailToOffline)
-- Callbacks
QBCore.Functions.CreateCallback('qb-phone:server:GetInvoices', function(source, cb)
local Player = exports['qb-core']:GetPlayer(source)
if Player then
local invoices = MySQL.query.await('SELECT * FROM phone_invoices WHERE citizenid = ?', { Player.PlayerData.citizenid })
for _, v in pairs(invoices) do
local Ply = QBCore.Functions.GetPlayerByCitizenId(v.sender)
if Ply ~= nil then
v.number = Ply.PlayerData.charinfo.phone
else
local res = MySQL.query.await('SELECT * FROM players WHERE citizenid = ?', { v.sender })
if res[1] ~= nil then
res[1].charinfo = json.decode(res[1].charinfo)
v.number = res[1].charinfo.phone
else
v.number = nil
end
end
end
cb(invoices)
return
end
cb({})
end)
QBCore.Functions.CreateCallback('qb-phone:server:GetCallState', function(_, cb, ContactData)
local Target = QBCore.Functions.GetPlayerByPhone(ContactData.number)
if Target ~= nil then
if Calls[Target.PlayerData.citizenid] ~= nil then
if Calls[Target.PlayerData.citizenid].inCall then
cb(false, true)
else
cb(true, true)
end
else
cb(true, true)
end
else
cb(false, false)
end
end)
QBCore.Functions.CreateCallback('qb-phone:server:GetPhoneData', function(source, cb)
local src = source
local Player = exports['qb-core']:GetPlayer(src)
if Player ~= nil then
local PhoneData = {
Applications = {},
PlayerContacts = {},
MentionedTweets = {},
Chats = {},
Hashtags = {},
Garage = {},
Mails = {},
Adverts = {},
CryptoTransactions = {},
Tweets = {},
Images = {},
InstalledApps = Player.PlayerData.metadata['phonedata'].InstalledApps
}
PhoneData.Adverts = Adverts
local result = MySQL.query.await('SELECT * FROM player_contacts WHERE citizenid = ? ORDER BY name ASC', { Player.PlayerData.citizenid })
if result[1] ~= nil then
for _, v in pairs(result) do
v.status = GetOnlineStatus(v.number)
end
PhoneData.PlayerContacts = result
end
local garageresult = MySQL.query.await('SELECT * FROM player_vehicles WHERE citizenid = ?', { Player.PlayerData.citizenid })
if garageresult[1] ~= nil then
PhoneData.Garage = garageresult
end
local messages = MySQL.query.await('SELECT * FROM phone_messages WHERE citizenid = ?', { Player.PlayerData.citizenid })
if messages ~= nil and next(messages) ~= nil then
PhoneData.Chats = messages
end
if AppAlerts[Player.PlayerData.citizenid] ~= nil then
PhoneData.Applications = AppAlerts[Player.PlayerData.citizenid]
end
if MentionedTweets[Player.PlayerData.citizenid] ~= nil then
PhoneData.MentionedTweets = MentionedTweets[Player.PlayerData.citizenid]
end
if Hashtags ~= nil and next(Hashtags) ~= nil then
PhoneData.Hashtags = Hashtags
end
local Tweets = MySQL.query.await('SELECT * FROM phone_tweets WHERE `date` > NOW() - INTERVAL ? hour', { Config.TweetDuration })
if Tweets ~= nil and next(Tweets) ~= nil then
PhoneData.Tweets = Tweets
TWData = Tweets
end
local mails = MySQL.query.await('SELECT * FROM player_mails WHERE citizenid = ? ORDER BY `date` ASC', { Player.PlayerData.citizenid })
if mails[1] ~= nil then
for k, _ in pairs(mails) do
if mails[k].button ~= nil then
mails[k].button = json.decode(mails[k].button)
end
end
PhoneData.Mails = mails
end
local transactions = MySQL.query.await('SELECT * FROM crypto_transactions WHERE citizenid = ? ORDER BY `date` ASC', { Player.PlayerData.citizenid })
if transactions[1] ~= nil then
for _, v in pairs(transactions) do
PhoneData.CryptoTransactions[#PhoneData.CryptoTransactions + 1] = {
TransactionTitle = v.title,
TransactionMessage = v.message
}
end
end
local images = MySQL.query.await('SELECT * FROM phone_gallery WHERE citizenid = ? ORDER BY `date` DESC', { Player.PlayerData.citizenid })
if images ~= nil and next(images) ~= nil then
PhoneData.Images = images
end
cb(PhoneData)
end
end)
QBCore.Functions.CreateCallback('qb-phone:server:PayInvoice', function(source, cb, society, amount, invoiceId, sendercitizenid)
local Ply = exports['qb-core']:GetPlayer(source)
local SenderPly = QBCore.Functions.GetPlayerByCitizenId(sendercitizenid)
local invoiceMailData = nil
if Ply then
local exists = MySQL.query.await('select count(1) as count FROM phone_invoices WHERE id = ? and citizenid = ?', { invoiceId, Ply.PlayerData.citizenid })
if exists[1] and exists[1]['count'] == 1 then
if SenderPly and Config.BillingCommissions[society] then
local commission = Round(amount * Config.BillingCommissions[society])
SenderPly.Functions.AddMoney('bank', commission)
invoiceMailData = {
sender = 'Billing Department',
subject = 'Commission Received',
message = string.format('You received a commission check of $%s when %s %s paid a bill of $%s.', commission, Ply.PlayerData.charinfo.firstname, Ply.PlayerData.charinfo.lastname, amount)
}
elseif not SenderPly and Config.BillingCommissions[society] then
invoiceMailData = {
sender = 'Billing Department',
subject = 'Bill Paid',
message = string.format('%s %s paid a bill of $%s', Ply.PlayerData.charinfo.firstname, Ply.PlayerData.charinfo.lastname, amount)
}
end
if Ply.Functions.RemoveMoney('bank', amount, 'paid-invoice') then
MySQL.query('DELETE FROM phone_invoices WHERE id = ? and citizenid = ?', { invoiceId, Ply.PlayerData.citizenid })
if invoiceMailData then
exports['qb-phone']:sendNewMailToOffline(sendercitizenid, invoiceMailData)
end
TriggerEvent('qb-phone:server:paidInvoice', source, invoiceId)
exports['qb-banking']:AddMoney(society, amount, 'Phone invoice')
cb(true)
return
end
end
end
cb(false)
end)
QBCore.Functions.CreateCallback('qb-phone:server:DeclineInvoice', function(source, cb, _, _, invoiceId)
local Ply = exports['qb-core']:GetPlayer(source)
if Ply then
local exists = MySQL.query.await('select count(1) as count FROM phone_invoices WHERE id = ? and citizenid = ? and candecline = ?', { invoiceId, Ply.PlayerData.citizenid, 1 })
if exists[1] and exists[1]['count'] == 1 then
TriggerEvent('qb-phone:server:declinedInvoice', source, invoiceId)
MySQL.query('DELETE FROM phone_invoices WHERE id = ? and citizenid = ? and candecline = ?', { invoiceId, Ply.PlayerData.citizenid, 1 })
cb(true)
return
end
end
cb(false)
end)
QBCore.Functions.CreateCallback('qb-phone:server:GetContactPictures', function(_, cb, Chats)
for _, v in pairs(Chats) do
local query = '%' .. v.number .. '%'
local result = MySQL.query.await('SELECT * FROM players WHERE charinfo LIKE ?', { query })
if result[1] ~= nil then
local MetaData = json.decode(result[1].metadata)
if MetaData.phone.profilepicture ~= nil then
v.picture = MetaData.phone.profilepicture
else
v.picture = 'default'
end
end
end
SetTimeout(100, function()
cb(Chats)
end)
end)
QBCore.Functions.CreateCallback('qb-phone:server:GetContactPicture', function(_, cb, Chat)
local query = '%' .. Chat.number .. '%'
local result = MySQL.query.await('SELECT * FROM players WHERE charinfo LIKE ?', { query })
local MetaData = json.decode(result[1].metadata)
if MetaData.phone.profilepicture ~= nil then
Chat.picture = MetaData.phone.profilepicture
else
Chat.picture = 'default'
end
SetTimeout(100, function()
cb(Chat)
end)
end)
QBCore.Functions.CreateCallback('qb-phone:server:GetPicture', function(_, cb, number)
local query = '%' .. number .. '%'
local result = MySQL.query.await('SELECT * FROM players WHERE charinfo LIKE ?', { query })
if result[1] ~= nil then
local Picture = 'default'
local MetaData = json.decode(result[1].metadata)
if MetaData.phone.profilepicture ~= nil then
Picture = MetaData.phone.profilepicture
end
cb(Picture)
else
cb(nil)
end
end)
QBCore.Functions.CreateCallback('qb-phone:server:FetchResult', function(_, cb, search)
search = escape_sqli(search)
local searchData = {}
local ApaData = {}
local query = 'SELECT * FROM `players` WHERE `citizenid` = "' .. search .. '"'
-- Split on " " and check each var individual
local searchParameters = SplitStringToArray(search)
-- Construct query dynamicly for individual parm check
if #searchParameters > 1 then
query = query .. ' OR `charinfo` LIKE "%' .. searchParameters[1] .. '%"'
for i = 2, #searchParameters do
query = query .. ' AND `charinfo` LIKE "%' .. searchParameters[i] .. '%"'
end
else
query = query .. ' OR `charinfo` LIKE "%' .. search .. '%"'
end
local ApartmentData = MySQL.query.await('SELECT * FROM apartments', {})
for k, v in pairs(ApartmentData) do
ApaData[v.citizenid] = ApartmentData[k]
end
local result = MySQL.query.await(query)
if result[1] ~= nil then
for _, v in pairs(result) do
local charinfo = json.decode(v.charinfo)
local metadata = json.decode(v.metadata)
local appiepappie = {}
if ApaData[v.citizenid] ~= nil and next(ApaData[v.citizenid]) ~= nil then
appiepappie = ApaData[v.citizenid]
end
searchData[#searchData + 1] = {
citizenid = v.citizenid,
firstname = charinfo.firstname,
lastname = charinfo.lastname,
birthdate = charinfo.birthdate,
phone = charinfo.phone,
nationality = charinfo.nationality,
gender = charinfo.gender,
warrant = false,
driverlicense = metadata['licences']['driver'],
appartmentdata = appiepappie
}
end
cb(searchData)
else
cb(nil)
end
end)
QBCore.Functions.CreateCallback('qb-phone:server:GetVehicleSearchResults', function(_, cb, search)
search = escape_sqli(search)
local searchData = {}
local query = '%' .. search .. '%'
local result = MySQL.query.await('SELECT * FROM player_vehicles WHERE plate LIKE ? OR citizenid = ?',
{ query, search })
if result[1] ~= nil then
for k, _ in pairs(result) do
local player = MySQL.query.await('SELECT * FROM players WHERE citizenid = ?', { result[k].citizenid })
if player[1] ~= nil then
local charinfo = json.decode(player[1].charinfo)
local vehicleInfo = sharedVehicles[result[k].vehicle]
if vehicleInfo ~= nil then
searchData[#searchData + 1] = {
plate = result[k].plate,
status = true,
owner = charinfo.firstname .. ' ' .. charinfo.lastname,
citizenid = result[k].citizenid,
label = vehicleInfo['name']
}
else
searchData[#searchData + 1] = {
plate = result[k].plate,
status = true,
owner = charinfo.firstname .. ' ' .. charinfo.lastname,
citizenid = result[k].citizenid,
label = 'Name not found..'
}
end
end
end
else
if GeneratedPlates[search] ~= nil then
searchData[#searchData + 1] = {
plate = GeneratedPlates[search].plate,
status = GeneratedPlates[search].status,
owner = GeneratedPlates[search].owner,
citizenid = GeneratedPlates[search].citizenid,
label = 'Brand unknown..'
}
else
local ownerInfo = GenerateOwnerName()
GeneratedPlates[search] = {
plate = search,
status = true,
owner = ownerInfo.name,
citizenid = ownerInfo.citizenid
}
searchData[#searchData + 1] = {
plate = search,
status = true,
owner = ownerInfo.name,
citizenid = ownerInfo.citizenid,
label = 'Brand unknown..'
}
end
end
cb(searchData)
end)
QBCore.Functions.CreateCallback('qb-phone:server:ScanPlate', function(source, cb, plate)
local src = source
local vehicleData
if plate ~= nil then
local result = MySQL.query.await('SELECT * FROM player_vehicles WHERE plate = ?', { plate })
if result[1] ~= nil then
local player = MySQL.query.await('SELECT * FROM players WHERE citizenid = ?', { result[1].citizenid })
local charinfo = json.decode(player[1].charinfo)
vehicleData = {
plate = plate,
status = true,
owner = charinfo.firstname .. ' ' .. charinfo.lastname,
citizenid = result[1].citizenid
}
elseif GeneratedPlates ~= nil and GeneratedPlates[plate] ~= nil then
vehicleData = GeneratedPlates[plate]
else
local ownerInfo = GenerateOwnerName()
GeneratedPlates[plate] = {
plate = plate,
status = true,
owner = ownerInfo.name,
citizenid = ownerInfo.citizenid
}
vehicleData = {
plate = plate,
status = true,
owner = ownerInfo.name,
citizenid = ownerInfo.citizenid
}
end
cb(vehicleData)
else
TriggerClientEvent('QBCore:Notify', src, 'No Vehicle Nearby', 'error')
cb(nil)
end
end)
QBCore.Functions.CreateCallback('qb-phone:server:HasPhone', function(source, cb)
local Player = exports['qb-core']:GetPlayer(source)
if Player ~= nil then
local HasPhone = Player.GetItemByName('phone')
if HasPhone ~= nil then
cb(true)
else
cb(false)
end
end
end)
QBCore.Functions.CreateCallback('qb-phone:server:CanTransferMoney', function(source, cb, amount, iban)
-- strip bad characters from bank transfers
local newAmount = tostring(amount)
local newiban = tostring(iban)
for _, v in pairs(bannedCharacters) do
newAmount = string.gsub(newAmount, '%' .. v, '')
newiban = string.gsub(newiban, '%' .. v, '')
end
iban = newiban
amount = tonumber(newAmount)
local Player = exports['qb-core']:GetPlayer(source)
if (Player.PlayerData.money.bank - amount) >= 0 then
local query = '%"account":"' .. iban .. '"%'
local result = MySQL.query.await('SELECT * FROM players WHERE charinfo LIKE ?', { query })
if result[1] ~= nil then
local Reciever = QBCore.Functions.GetPlayerByCitizenId(result[1].citizenid)
Player.RemoveMoney('bank', amount)
if Reciever ~= nil then
Reciever.Functions.AddMoney('bank', amount)
else
local RecieverMoney = json.decode(result[1].money)
RecieverMoney.bank = (RecieverMoney.bank + amount)
MySQL.update('UPDATE players SET money = ? WHERE citizenid = ?', { json.encode(RecieverMoney), result[1].citizenid })
end
cb(true)
else
cb(false)
end
end
end)
QBCore.Functions.CreateCallback('qb-phone:server:GetCurrentLawyers', function(_, cb)
local Lawyers = {}
for _, v in pairs(QBCore.Functions.GetPlayers()) do
local Player = exports['qb-core']:GetPlayer(v)
if Player ~= nil then
if (Player.PlayerData.job.name == 'lawyer' or Player.PlayerData.job.name == 'realestate' or
Player.PlayerData.job.name == 'mechanic' or Player.PlayerData.job.name == 'taxi' or
Player.PlayerData.job.name == 'police' or Player.PlayerData.job.name == 'ambulance') and
Player.PlayerData.job.onduty then
Lawyers[#Lawyers + 1] = {
name = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname,
phone = Player.PlayerData.charinfo.phone,
typejob = Player.PlayerData.job.name
}
end
end
end
cb(Lawyers)
end)
QBCore.Functions.CreateCallback('qb-phone:server:GetWebhook', function(_, cb)
if WebHook ~= '' then
cb(WebHook)
else
print('Set your webhook to ensure that your camera will work!!!!!! Set this on line 9 of the server sided script!!!!!')
cb(nil)
end
end)
QBCore.Functions.CreateCallback('qb-phone:server:UploadToFivemerr', function(source, cb)
local src = source
if Config.Fivemerr == true and FivemerrApiToken == '' then
print('^1--- Fivemerr is enabled but no API token has been specified. ---^7')
return cb(nil)
end
exports['screenshot-basic']:requestClientScreenshot(src, {
encoding = 'png'
}, function(err, data)
if err then return cb(nil) end
PerformHttpRequest(WebHook, function(status, response)
if status ~= 200 then
print('^1--- ERROR UPLOADING IMAGE: ' .. status .. ' ---^7')
cb(nil)
end
cb(response)
end, 'POST', json.encode({ data = data }), {
['Authorization'] = FivemerrApiToken,
['Content-Type'] = 'application/json'
})
end)
end)
-- Events
RegisterNetEvent('qb-phone:server:AddAdvert', function(msg, url)
local src = source
local Player = exports['qb-core']:GetPlayer(src)
local CitizenId = Player.PlayerData.citizenid
if Adverts[CitizenId] ~= nil then
Adverts[CitizenId].message = msg
Adverts[CitizenId].name = '@' .. Player.PlayerData.charinfo.firstname .. '' .. Player.PlayerData.charinfo.lastname
Adverts[CitizenId].number = Player.PlayerData.charinfo.phone
Adverts[CitizenId].url = url
else
Adverts[CitizenId] = {
message = msg,
name = '@' .. Player.PlayerData.charinfo.firstname .. '' .. Player.PlayerData.charinfo.lastname,
number = Player.PlayerData.charinfo.phone,
url = url
}
end
TriggerClientEvent('qb-phone:client:UpdateAdverts', -1, Adverts, '@' .. Player.PlayerData.charinfo.firstname .. '' .. Player.PlayerData.charinfo.lastname)
end)
RegisterNetEvent('qb-phone:server:DeleteAdvert', function()
local Player = exports['qb-core']:GetPlayer(source)
local citizenid = Player.PlayerData.citizenid
Adverts[citizenid] = nil
TriggerClientEvent('qb-phone:client:UpdateAdvertsDel', -1, Adverts)
end)
RegisterNetEvent('qb-phone:server:SetCallState', function(bool)
local src = source
local Ply = exports['qb-core']:GetPlayer(src)
if Calls[Ply.PlayerData.citizenid] ~= nil then
Calls[Ply.PlayerData.citizenid].inCall = bool
else
Calls[Ply.PlayerData.citizenid] = {}
Calls[Ply.PlayerData.citizenid].inCall = bool
end
end)
RegisterNetEvent('qb-phone:server:RemoveMail', function(MailId)
local src = source
local Player = exports['qb-core']:GetPlayer(src)
MySQL.query('DELETE FROM player_mails WHERE mailid = ? AND citizenid = ?', { MailId, Player.PlayerData.citizenid })
SetTimeout(100, function()
local mails = MySQL.query.await('SELECT * FROM player_mails WHERE citizenid = ? ORDER BY `date` ASC', { Player.PlayerData.citizenid })
if mails[1] ~= nil then
for k, _ in pairs(mails) do
if mails[k].button ~= nil then
mails[k].button = json.decode(mails[k].button)
end
end
end
TriggerClientEvent('qb-phone:client:UpdateMails', src, mails)
end)
end)
RegisterNetEvent('qb-phone:server:sendNewMail', function(mailData)
local src = source
local Player = exports['qb-core']:GetPlayer(src)
if mailData.button == nil then
MySQL.insert('INSERT INTO player_mails (`citizenid`, `sender`, `subject`, `message`, `mailid`, `read`) VALUES (?, ?, ?, ?, ?, ?)', { Player.PlayerData.citizenid, mailData.sender, mailData.subject, mailData.message, GenerateMailId(), 0 })
else
MySQL.insert('INSERT INTO player_mails (`citizenid`, `sender`, `subject`, `message`, `mailid`, `read`, `button`) VALUES (?, ?, ?, ?, ?, ?, ?)', { Player.PlayerData.citizenid, mailData.sender, mailData.subject, mailData.message, GenerateMailId(), 0, json.encode(mailData.button) })
end
TriggerClientEvent('qb-phone:client:NewMailNotify', src, mailData)
SetTimeout(200, function()
local mails = MySQL.query.await('SELECT * FROM player_mails WHERE citizenid = ? ORDER BY `date` DESC',
{ Player.PlayerData.citizenid })
if mails[1] ~= nil then
for k, _ in pairs(mails) do
if mails[k].button ~= nil then
mails[k].button = json.decode(mails[k].button)
end
end
end
TriggerClientEvent('qb-phone:client:UpdateMails', src, mails)
end)
end)
RegisterNetEvent('qb-phone:server:sendNewEventMail', function(citizenid, mailData)
local Player = QBCore.Functions.GetPlayerByCitizenId(citizenid)
if mailData.button == nil then
MySQL.insert('INSERT INTO player_mails (`citizenid`, `sender`, `subject`, `message`, `mailid`, `read`) VALUES (?, ?, ?, ?, ?, ?)', { citizenid, mailData.sender, mailData.subject, mailData.message, GenerateMailId(), 0 })
else
MySQL.insert('INSERT INTO player_mails (`citizenid`, `sender`, `subject`, `message`, `mailid`, `read`, `button`) VALUES (?, ?, ?, ?, ?, ?, ?)', { citizenid, mailData.sender, mailData.subject, mailData.message, GenerateMailId(), 0, json.encode(mailData.button) })
end
SetTimeout(200, function()
local mails = MySQL.query.await('SELECT * FROM player_mails WHERE citizenid = ? ORDER BY `date` ASC', { citizenid })
if mails[1] ~= nil then
for k, _ in pairs(mails) do
if mails[k].button ~= nil then
mails[k].button = json.decode(mails[k].button)
end
end
end
TriggerClientEvent('qb-phone:client:UpdateMails', Player.PlayerData.source, mails)
end)
end)
RegisterNetEvent('qb-phone:server:ClearButtonData', function(mailId)
local src = source
local Player = exports['qb-core']:GetPlayer(src)
MySQL.update('UPDATE player_mails SET button = ? WHERE mailid = ? AND citizenid = ?', { '', mailId, Player.PlayerData.citizenid })
SetTimeout(200, function()
local mails = MySQL.query.await('SELECT * FROM player_mails WHERE citizenid = ? ORDER BY `date` ASC', { Player.PlayerData.citizenid })
if mails[1] ~= nil then
for k, _ in pairs(mails) do
if mails[k].button ~= nil then
mails[k].button = json.decode(mails[k].button)
end
end
end
TriggerClientEvent('qb-phone:client:UpdateMails', src, mails)
end)
end)
RegisterNetEvent('qb-phone:server:MentionedPlayer', function(firstName, lastName, TweetMessage)
for _, v in pairs(QBCore.Functions.GetPlayers()) do
local Player = exports['qb-core']:GetPlayer(v)
if Player ~= nil then
if (Player.PlayerData.charinfo.firstname == firstName and Player.PlayerData.charinfo.lastname == lastName) then
QBPhone.SetPhoneAlerts(Player.PlayerData.citizenid, 'twitter')
QBPhone.AddMentionedTweet(Player.PlayerData.citizenid, TweetMessage)
TriggerClientEvent('qb-phone:client:GetMentioned', Player.PlayerData.source, TweetMessage, AppAlerts[Player.PlayerData.citizenid]['twitter'])
else
local query1 = '%' .. firstName .. '%'
local query2 = '%' .. lastName .. '%'
local result = MySQL.query.await('SELECT * FROM players WHERE charinfo LIKE ? AND charinfo LIKE ?', { query1, query2 })
if result[1] ~= nil then
local MentionedTarget = result[1].citizenid
QBPhone.SetPhoneAlerts(MentionedTarget, 'twitter')
QBPhone.AddMentionedTweet(MentionedTarget, TweetMessage)
end
end
end
end
end)
RegisterNetEvent('qb-phone:server:CallContact', function(TargetData, CallId, AnonymousCall)
local src = source
local Ply = exports['qb-core']:GetPlayer(src)
local Target = QBCore.Functions.GetPlayerByPhone(TargetData.number)
if Target ~= nil then
TriggerClientEvent('qb-phone:client:GetCalled', Target.PlayerData.source, Ply.PlayerData.charinfo.phone, CallId, AnonymousCall)
end
end)
RegisterNetEvent('qb-phone:server:BillingEmail', function(data, paid)
for _, v in pairs(QBCore.Functions.GetPlayers()) do
local target = exports['qb-core']:GetPlayer(v)
if target.PlayerData.job.name == data.society then
if paid then
local name = '' .. exports['qb-core']:GetPlayer(source).PlayerData.charinfo.firstname .. ' ' .. exports['qb-core']:GetPlayer(source).PlayerData.charinfo.lastname .. ''
TriggerClientEvent('qb-phone:client:BillingEmail', target.PlayerData.source, data, true, name)
else
local name = '' .. exports['qb-core']:GetPlayer(source).PlayerData.charinfo.firstname .. ' ' .. exports['qb-core']:GetPlayer(source).PlayerData.charinfo.lastname .. ''
TriggerClientEvent('qb-phone:client:BillingEmail', target.PlayerData.source, data, false, name)
end
end
end
end)
RegisterNetEvent('qb-phone:server:UpdateHashtags', function(Handle, messageData)
if Hashtags[Handle] ~= nil and next(Hashtags[Handle]) ~= nil then
Hashtags[Handle].messages[#Hashtags[Handle].messages + 1] = messageData
else
Hashtags[Handle] = {
hashtag = Handle,
messages = {}
}
Hashtags[Handle].messages[#Hashtags[Handle].messages + 1] = messageData
end
TriggerClientEvent('qb-phone:client:UpdateHashtags', -1, Handle, messageData)
end)
RegisterNetEvent('qb-phone:server:SetPhoneAlerts', function(app, alerts)
local src = source
local CitizenId = exports['qb-core']:GetPlayer(src).citizenid
QBPhone.SetPhoneAlerts(CitizenId, app, alerts)
end)
RegisterNetEvent('qb-phone:server:DeleteTweet', function(tweetId)
local Player = exports['qb-core']:GetPlayer(source)
local delete = false
local TID = tweetId
local Data = MySQL.scalar.await('SELECT citizenid FROM phone_tweets WHERE tweetId = ?', { TID })
if Data == Player.PlayerData.citizenid then
MySQL.query.await('DELETE FROM phone_tweets WHERE tweetId = ?', { TID })
delete = true
end
if delete then
for k, _ in pairs(TWData) do
if TWData[k].tweetId == TID then
TWData = nil
end
end
TriggerClientEvent('qb-phone:client:UpdateTweets', -1, TWData, nil, true)
end
end)
RegisterNetEvent('qb-phone:server:UpdateTweets', function(NewTweets, TweetData)
local src = source
MySQL.insert('INSERT INTO phone_tweets (citizenid, firstName, lastName, message, date, url, picture, tweetid) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', {
TweetData.citizenid,
TweetData.firstName,
TweetData.lastName,
TweetData.message,
TweetData.time,
TweetData.url:gsub('[%<>\"()\' $]', ''),
TweetData.picture:gsub('[%<>\"()\' $]', ''),
TweetData.tweetId
})
TriggerClientEvent('qb-phone:client:UpdateTweets', -1, src, NewTweets, TweetData, false)
end)
RegisterNetEvent('qb-phone:server:TransferMoney', function(iban, amount)
local src = source
local sender = exports['qb-core']:GetPlayer(src)
local query = '%' .. iban .. '%'
local result = MySQL.query.await('SELECT * FROM players WHERE charinfo LIKE ?', { query })
if result[1] ~= nil then
local reciever = QBCore.Functions.GetPlayerByCitizenId(result[1].citizenid)
if reciever ~= nil then
local PhoneItem = reciever.Functions.GetItemByName('phone')
reciever.Functions.AddMoney('bank', amount, 'phone-transfered-from-' .. sender.PlayerData.citizenid)
sender.Functions.RemoveMoney('bank', amount, 'phone-transfered-to-' .. reciever.PlayerData.citizenid)
if PhoneItem ~= nil then
TriggerClientEvent('qb-phone:client:TransferMoney', reciever.PlayerData.source, amount,
reciever.PlayerData.money.bank)
end
else
local moneyInfo = json.decode(result[1].money)
moneyInfo.bank = Round(moneyInfo.bank + amount)
MySQL.update('UPDATE players SET money = ? WHERE citizenid = ?',
{ json.encode(moneyInfo), result[1].citizenid })
sender.Functions.RemoveMoney('bank', amount, 'phone-transfered')
end
else
TriggerClientEvent('QBCore:Notify', src, "This account number doesn't exist!", 'error')
end
end)
RegisterNetEvent('qb-phone:server:EditContact', function(newName, newNumber, newIban, oldName, oldNumber, _)
local src = source
local Player = exports['qb-core']:GetPlayer(src)
MySQL.update(
'UPDATE player_contacts SET name = ?, number = ?, iban = ? WHERE citizenid = ? AND name = ? AND number = ?',
{ newName, newNumber, newIban, Player.PlayerData.citizenid, oldName, oldNumber })
end)
RegisterNetEvent('qb-phone:server:RemoveContact', function(Name, Number)
local src = source
local Player = exports['qb-core']:GetPlayer(src)
MySQL.query('DELETE FROM player_contacts WHERE name = ? AND number = ? AND citizenid = ?',
{ Name, Number, Player.PlayerData.citizenid })
end)
RegisterNetEvent('qb-phone:server:AddNewContact', function(name, number, iban)
local src = source
local Player = exports['qb-core']:GetPlayer(src)
MySQL.insert('INSERT INTO player_contacts (citizenid, name, number, iban) VALUES (?, ?, ?, ?)', { Player.PlayerData.citizenid, tostring(name), tostring(number), tostring(iban) })
end)
RegisterNetEvent('qb-phone:server:UpdateMessages', function(ChatMessages, ChatNumber, _)
local src = source
local SenderData = exports['qb-core']:GetPlayer(src)
local query = '%' .. ChatNumber .. '%'
local Player = MySQL.query.await('SELECT * FROM players WHERE charinfo LIKE ?', { query })
if Player[1] ~= nil then
local TargetData = QBCore.Functions.GetPlayerByCitizenId(Player[1].citizenid)
if TargetData ~= nil then
local Chat = MySQL.query.await('SELECT * FROM phone_messages WHERE citizenid = ? AND number = ?', { SenderData.PlayerData.citizenid, ChatNumber })
if Chat[1] ~= nil then
-- Update for target
MySQL.update('UPDATE phone_messages SET messages = ? WHERE citizenid = ? AND number = ?', { json.encode(ChatMessages), TargetData.PlayerData.citizenid, SenderData.PlayerData.charinfo.phone })
-- Update for sender
MySQL.update('UPDATE phone_messages SET messages = ? WHERE citizenid = ? AND number = ?', { json.encode(ChatMessages), SenderData.PlayerData.citizenid, TargetData.PlayerData.charinfo.phone })
-- Send notification & Update messages for target
TriggerClientEvent('qb-phone:client:UpdateMessages', TargetData.PlayerData.source, ChatMessages, SenderData.PlayerData.charinfo.phone, false)
else
-- Insert for target
MySQL.insert('INSERT INTO phone_messages (citizenid, number, messages) VALUES (?, ?, ?)', { TargetData.PlayerData.citizenid, SenderData.PlayerData.charinfo.phone, json.encode(ChatMessages) })
-- Insert for sender
MySQL.insert('INSERT INTO phone_messages (citizenid, number, messages) VALUES (?, ?, ?)', { SenderData.PlayerData.citizenid, TargetData.PlayerData.charinfo.phone, json.encode(ChatMessages) })
-- Send notification & Update messages for target
TriggerClientEvent('qb-phone:client:UpdateMessages', TargetData.PlayerData.source, ChatMessages, SenderData.PlayerData.charinfo.phone, true)
end
else
local Chat = MySQL.query.await('SELECT * FROM phone_messages WHERE citizenid = ? AND number = ?', { SenderData.PlayerData.citizenid, ChatNumber })
if Chat[1] ~= nil then
-- Update for target
MySQL.update('UPDATE phone_messages SET messages = ? WHERE citizenid = ? AND number = ?', { json.encode(ChatMessages), Player[1].citizenid, SenderData.PlayerData.charinfo.phone })
-- Update for sender
Player[1].charinfo = json.decode(Player[1].charinfo)
MySQL.update('UPDATE phone_messages SET messages = ? WHERE citizenid = ? AND number = ?', { json.encode(ChatMessages), SenderData.PlayerData.citizenid, Player[1].charinfo.phone })
else
-- Insert for target
MySQL.insert('INSERT INTO phone_messages (citizenid, number, messages) VALUES (?, ?, ?)', { Player[1].citizenid, SenderData.PlayerData.charinfo.phone, json.encode(ChatMessages) })
-- Insert for sender
Player[1].charinfo = json.decode(Player[1].charinfo)
MySQL.insert('INSERT INTO phone_messages (citizenid, number, messages) VALUES (?, ?, ?)', { SenderData.PlayerData.citizenid, Player[1].charinfo.phone, json.encode(ChatMessages) })
end
end
end
end)
RegisterNetEvent('qb-phone:server:AddRecentCall', function(type, data)
local src = source
local Ply = exports['qb-core']:GetPlayer(src)
local Hour = os.date('%H')
local Minute = os.date('%M')
local label = Hour .. ':' .. Minute
TriggerClientEvent('qb-phone:client:AddRecentCall', src, data, label, type)
local Trgt = QBCore.Functions.GetPlayerByPhone(data.number)
if Trgt ~= nil then
TriggerClientEvent('qb-phone:client:AddRecentCall', Trgt.PlayerData.source, {
name = Ply.PlayerData.charinfo.firstname .. ' ' .. Ply.PlayerData.charinfo.lastname,
number = Ply.PlayerData.charinfo.phone,
anonymous = data.anonymous
}, label, 'outgoing')
end
end)
RegisterNetEvent('qb-phone:server:CancelCall', function(ContactData)
local Ply = QBCore.Functions.GetPlayerByPhone(ContactData.TargetData.number)
if Ply ~= nil then
TriggerClientEvent('qb-phone:client:CancelCall', Ply.PlayerData.source)
end
end)
RegisterNetEvent('qb-phone:server:AnswerCall', function(CallData)
local Ply = QBCore.Functions.GetPlayerByPhone(CallData.TargetData.number)
if Ply ~= nil then
TriggerClientEvent('qb-phone:client:AnswerCall', Ply.PlayerData.source)
end
end)
RegisterNetEvent('qb-phone:server:SaveMetaData', function(MData)
local src = source
local Player = exports['qb-core']:GetPlayer(src)
local result = MySQL.query.await('SELECT * FROM players WHERE citizenid = ?', { Player.PlayerData.citizenid })
local MetaData = json.decode(result[1].metadata)
MetaData.phone = MData
MySQL.update('UPDATE players SET metadata = ? WHERE citizenid = ?',
{ json.encode(MetaData), Player.PlayerData.citizenid })
Player.SetMetaData('phone', MData)
end)
RegisterNetEvent('qb-phone:server:GiveContactDetails', function(PlayerId)
local src = source
local Player = exports['qb-core']:GetPlayer(src)
local SuggestionData = {
name = {
[1] = Player.PlayerData.charinfo.firstname,
[2] = Player.PlayerData.charinfo.lastname
},
number = Player.PlayerData.charinfo.phone,