-
-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathadmin_server.lua
More file actions
1702 lines (1613 loc) · 61.7 KB
/
Copy pathadmin_server.lua
File metadata and controls
1702 lines (1613 loc) · 61.7 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
--[[**********************************
*
* Multi Theft Auto - Admin Panel
*
* admin_server.lua
*
* Original File by lil_Toady
*
**************************************]]
_types = { "player", "team", "vehicle", "resource", "bans", "server", "admin" }
_settings = nil
aPlayers = {}
aLogMessages = {}
aInteriors = {}
aStats = {}
aReports = {}
aWeathers = {}
local aUnmuteTimerList = {}
local chatHistory = {}
function notifyPlayerLoggedIn(player)
outputChatBox ( "Press 'p' to open your admin panel", player )
local unread = 0
for _, msg in ipairs ( aReports ) do
unread = unread + ( msg.read and 0 or 1 )
end
if unread > 0 then
outputChatBox( unread .. " unread Admin message" .. ( unread==1 and "" or "s" ), player, 255, 0, 0 )
end
end
function aHandleIP2CUpdate()
local playersToUpdate = nil
local playersTable = getElementsByType("player") -- cache result, save function call
for playerID = 1, #playersTable do
local playerElement = playersTable[playerID]
if not playersToUpdate then
playersToUpdate = {} -- create table only when there are at least one player
end
updatePlayerCountry(playerElement)
playersToUpdate[#playersToUpdate + 1] = playerElement
end
if not playersToUpdate then
return -- if there are no players, stop further code execution
end
for playerID = 1, #playersTable do
local playerElement = playersTable[playerID]
local hasAdminPermission = hasObjectPermissionTo(playerElement, "general.adminpanel", false)
if hasAdminPermission then
for playerToUpdateID = 1, #playersToUpdate do
local playerToUpdate = playersToUpdate[playerToUpdateID]
triggerClientEvent(playerElement, "aClientPlayerJoin", playerToUpdate,
false, false, false, false,
aPlayers[playerToUpdate]["country"]
)
end
end
end
end
function aHandleIp2cSetting()
local enabled = get("*useip2c")
if enabled and enabled == "true" then
local ip2c = getResourceFromName("ip2c")
if ip2c and getResourceState(ip2c) == "loaded" then
-- Persistent
startResource(ip2c, true)
end
elseif (not enabled) or (enabled == "false") then
local ip2c = getResourceFromName("ip2c")
if ip2c and getResourceState(ip2c) == "running" then
stopResource(ip2c)
end
end
end
addEventHandler ( "onResourceStart", root, function ( resource )
if ( resource ~= getThisResource() ) then
local resourceName = getResourceName(resource)
for id, player in ipairs(getElementsByType("player")) do
if ( hasObjectPermissionTo ( player, "general.tab_resources", false ) ) then
triggerClientEvent ( player, "aClientResourceStart", root, resourceName )
end
end
if resourceName == "ip2c" then
aHandleIP2CUpdate()
end
return
end
_settings = xmlLoadFile ( "conf\\settings.xml" )
if ( not _settings ) then
_settings = xmlCreateFile ( "conf\\settings.xml", "main" )
xmlSaveFile ( _settings )
end
aSetupACL()
aSetupCommands()
for id, player in ipairs ( getElementsByType ( "player" ) ) do
aPlayerInitialize ( player )
if ( hasObjectPermissionTo ( player, "general.adminpanel", false ) ) then
notifyPlayerLoggedIn(player)
end
end
aHandleIp2cSetting()
local node = xmlLoadFile ( "conf\\interiors.xml" )
if ( node ) then
local interiors = 0
while ( xmlFindChild ( node, "interior", interiors ) ) do
local interior = xmlFindChild ( node, "interior", interiors )
interiors = interiors + 1
aInteriors[interiors] = {}
aInteriors[interiors]["world"] = tonumber ( xmlNodeGetAttribute ( interior, "world" ) )
aInteriors[interiors]["id"] = xmlNodeGetAttribute ( interior, "id" )
aInteriors[interiors]["x"] = xmlNodeGetAttribute ( interior, "posX" )
aInteriors[interiors]["y"] = xmlNodeGetAttribute ( interior, "posY" )
aInteriors[interiors]["z"] = xmlNodeGetAttribute ( interior, "posZ" )
aInteriors[interiors]["r"] = xmlNodeGetAttribute ( interior, "rot" )
end
xmlUnloadFile ( node )
end
local node2 = xmlLoadFile ( "conf\\stats.xml" )
if ( node2 ) then
local stats = 0
while ( xmlFindChild ( node2, "stat", stats ) ) do
local stat = xmlFindChild ( node2, "stat", stats )
local id = tonumber ( xmlNodeGetAttribute ( stat, "id" ) )
local name = xmlNodeGetAttribute ( stat, "name" )
if (id) then aStats[id] = name end
stats = stats + 1
end
xmlUnloadFile ( node2 )
end
local node3 = xmlLoadFile ( "conf\\weathers.xml" )
if ( node3 ) then
local weathers = 0
while ( xmlFindChild ( node3, "weather", weathers ) ~= false ) do
local weather = xmlFindChild ( node3, "weather", weathers )
local id = tonumber ( xmlNodeGetAttribute ( weather, "id" ) )
local name = xmlNodeGetAttribute ( weather, "name" )
if (id) then aWeathers[id] = name end
weathers = weathers + 1
end
xmlUnloadFile ( node3 )
end
local node4 = xmlLoadFile ( "conf\\reports.xml" )
if ( node4 ) then
local messages = 0
while ( xmlFindChild ( node4, "message", messages ) ) do
subnode = xmlFindChild ( node4, "message", messages )
local author = xmlFindChild ( subnode, "author", 0 )
local subject = xmlFindChild ( subnode, "subject", 0 )
local category = xmlFindChild ( subnode, "category", 0 )
local text = xmlFindChild ( subnode, "text", 0 )
local time = xmlFindChild ( subnode, "time", 0 )
local read = ( xmlFindChild ( subnode, "read", 0 ) ~= false )
local suspect = xmlFindChild ( subnode, "suspect", 0 )
local id = #aReports + 1
aReports[id] = {}
if ( author ) then aReports[id].author = xmlNodeGetValue ( author )
else aReports[id].author = "" end
if ( category ) then aReports[id].category = xmlNodeGetValue ( category )
else aReports[id].category = "" end
if ( subject ) then aReports[id].subject = xmlNodeGetValue ( subject )
else aReports[id].subject = "" end
if ( text ) then aReports[id].text = xmlNodeGetValue ( text )
else aReports[id].text = "" end
if ( time ) then aReports[id].time = xmlNodeGetValue ( time )
else aReports[id].time = "" end
if ( suspect ) then
aReports[id].suspect = {
name = xmlNodeGetAttribute ( suspect, "name" ),
username = xmlNodeGetAttribute ( suspect, "username" ),
ip = xmlNodeGetAttribute ( suspect, "ip" ),
serial = xmlNodeGetAttribute ( suspect, "serial" ),
version = xmlNodeGetAttribute ( suspect, "version" ),
chatLog = xmlNodeGetValue ( suspect )
}
else aReports[id].suspect = false end
aReports[id].read = read
messages = messages + 1
end
-- Remove duplicates
local a = 1
while a <= #aReports do
local b = a + 1
while b <= #aReports do
if table.cmp( aReports[a], aReports[b] ) then
table.remove( aReports, b )
b = b - 1
end
b = b + 1
end
a = a + 1
end
-- Upgrade time from '4/9 5:9' to '2009-09-04 05:09'
for id, rep in ipairs ( aReports ) do
if string.find( rep.time, "/" ) then
local monthday, month, hour, minute = string.match( rep.time, "^(.-)/(.-) (.-):(.-)$" )
rep.time = string.format( '%04d-%02d-%02d %02d:%02d', 2009, month + 1, monthday, hour, minute )
end
end
-- Sort messages by time
table.sort(aReports, function(b, c) return(b.time < c.time) end)
-- Limit number of messages
while #aReports > g_Prefs.maxmsgs do
table.remove( aReports, 1 )
end
xmlUnloadFile ( node4 )
end
local node5 = xmlLoadFile ( "conf\\messages.xml" )
if ( node5 ) then
for id, type in ipairs ( _types ) do
local subnode = xmlFindChild ( node5, type, 0 )
if ( subnode ) then
aLogMessages[type] = {}
local groups = 0
while ( xmlFindChild ( subnode, "group", groups ) ) do
local group = xmlFindChild ( subnode, "group", groups )
local action = xmlNodeGetAttribute ( group, "action" )
local r, g, b = tonumber ( xmlNodeGetAttribute ( group, "r" ) ), tonumber ( xmlNodeGetAttribute ( group, "g" ) ), tonumber ( xmlNodeGetAttribute ( group, "b" ) )
aLogMessages[type][action] = {}
aLogMessages[type][action]["r"], aLogMessages[type][action]["g"], aLogMessages[type][action]["b"] = r or 0, g or 255, b or 255
if ( xmlFindChild ( group, "all", 0 ) ) then aLogMessages[type][action]["all"] = xmlNodeGetValue ( xmlFindChild ( group, "all", 0 ) ) end
if ( xmlFindChild ( group, "admin", 0 ) ) then aLogMessages[type][action]["admin"] = xmlNodeGetValue ( xmlFindChild ( group, "admin", 0 ) ) end
if ( xmlFindChild ( group, "player", 0 ) ) then aLogMessages[type][action]["player"] = xmlNodeGetValue ( xmlFindChild ( group, "player", 0 ) ) end
if ( xmlFindChild ( group, "log", 0 ) ) then aLogMessages[type][action]["log"] = xmlNodeGetValue ( xmlFindChild ( group, "log", 0 ) ) end
groups = groups + 1
end
end
end
xmlUnloadFile ( node5 )
end
end )
addEventHandler ( "onResourceStop", root, function ( resource )
-- Incase the resource being stopped has been deleted
local stillExists = false
for i, res in ipairs(getResources()) do
if res == resource then
stillExists = true
break
end
end
if not stillExists then return end
if ( resource ~= getThisResource() ) then
local resourceName = getResourceName(resource)
for id, player in ipairs(getElementsByType("player")) do
if ( hasObjectPermissionTo ( player, "general.tab_resources", false ) ) then
triggerClientEvent ( player, "aClientResourceStop", root, resourceName )
end
end
if resourceName == "ip2c" then
aHandleIP2CUpdate()
end
else
local node = xmlLoadFile ( "conf\\reports.xml" )
if ( node ) then
while ( xmlFindChild ( node, "message", 0 ) ~= false ) do
local subnode = xmlFindChild ( node, "message", 0 )
xmlDestroyNode ( subnode )
end
else
node = xmlCreateFile ( "conf\\reports.xml", "messages" )
end
for id, message in ipairs ( aReports ) do
local subnode = xmlCreateChild ( node, "message" )
for key, value in pairs ( message ) do
if ( value ) then
if ( type ( value ) == "table" ) then
local child = xmlCreateChild ( subnode, key )
xmlNodeSetValue ( child, tostring ( value.chatLog ) )
xmlNodeSetAttribute ( child, "name", value.name )
xmlNodeSetAttribute ( child, "username", value.username )
xmlNodeSetAttribute ( child, "ip", value.ip )
xmlNodeSetAttribute ( child, "serial", value.serial )
xmlNodeSetAttribute ( child, "version", value.version )
else
xmlNodeSetValue ( xmlCreateChild ( subnode, key ), tostring ( value ) )
end
end
end
end
xmlSaveFile ( node )
xmlUnloadFile ( node )
-- Unmute anybody muted by admin
for i, player in ipairs(getElementsByType("player")) do
local serial = getPlayerSerial( player )
if (aUnmuteTimerList[serial]) then
aUnmuteTimerList[serial] = nil
setPlayerMuted(player, false)
end
end
end
aclSave ()
end )
function aGetSetting ( setting )
local result = xmlFindChild ( _settings, tostring ( setting ), 0 )
if ( result ) then
result = xmlNodeGetValue ( result )
if ( result == "true" ) then return true
elseif ( result == "false" ) then return false
else return result end
end
return false
end
function aSetSetting ( setting, value )
local node = xmlFindChild ( _settings, tostring ( setting ), 0 )
if ( not node ) then
node = xmlCreateChild ( _settings, tostring ( setting ) )
end
xmlNodeSetValue ( node, tostring ( value ) )
xmlSaveFile ( _settings )
end
function aRemoveSetting ( setting )
local node = xmlFindChild ( _settings, tostring ( setting ), 0 )
if ( node ) then
xmlDestroyNode ( node )
end
xmlSaveFile ( _settings )
end
function iif ( cond, arg1, arg2 )
if ( cond ) then
return arg1
end
return arg2
end
function getWeatherNameFromID ( weather )
return iif ( aWeathers[weather], aWeathers[weather], "Unknown" )
end
function getPlayerAccountName( player )
local account = getPlayerAccount ( player )
return account and getAccountName ( account )
end
function aSetPlayerMuted ( player, state, length )
if ( setPlayerMuted ( player, state ) ) then
if not state then
aRemoveUnmuteTimer( player )
elseif state and length and length > 0 then
aAddUnmuteTimer( player, length )
end
return true
end
return false
end
addEventHandler ( "onPlayerJoin", root, function ()
local player = source
if aHasUnmuteTimer( player ) then
if not isPlayerMuted(player) then
triggerEvent ( "aPlayer", getElementByIndex("console", 0), player, "mute" )
end
end
end )
-- Allows for timed mutes across reconnects
function aAddUnmuteTimer( player, length )
aRemoveUnmuteTimer( player )
local serial = getPlayerSerial( player )
aUnmuteTimerList[serial] = setTimer(
function()
aUnmuteTimerList[serial] = nil
for _,plr in ipairs(getElementsByType('player')) do
if getPlayerSerial(plr) == serial then
if isPlayerMuted(plr) then
triggerEvent ( "aPlayer", getElementByIndex("console", 0), plr, "mute" )
end
end
end
end,
length*1000, 1 )
end
function aRemoveUnmuteTimer( player )
local serial = getPlayerSerial( player )
if aUnmuteTimerList[serial] then
killTimer( aUnmuteTimerList[serial] )
aUnmuteTimerList[serial] = nil
end
end
function aHasUnmuteTimer( player )
local serial = getPlayerSerial( player )
if aUnmuteTimerList[serial] then
return true
end
end
addEvent ( "onPlayerFreeze", false )
function aSetPlayerFrozen ( player, state )
if ( toggleAllControls ( player, not state, true, false ) ) then
aPlayers[player]["freeze"] = state
triggerEvent ( "onPlayerFreeze", player, state )
local vehicle = getPedOccupiedVehicle( player )
if vehicle then
setElementFrozen ( vehicle, state )
end
return true
end
return false
end
function isPlayerFrozen ( player )
if ( aPlayers[player]["freeze"] == nil ) then aPlayers[player]["freeze"] = false end
return aPlayers[player]["freeze"]
end
addEventHandler ( "onPlayerJoin", root, function ()
if ( aGetSetting ( "welcome" ) ) then
outputChatBox ( aGetSetting ( "welcome" ), source, 255, 100, 100 )
end
aPlayerInitialize ( source )
for id, player in ipairs(getElementsByType("player")) do
if ( hasObjectPermissionTo ( player, "general.adminpanel", false ) ) then
triggerClientEvent ( player, "aClientPlayerJoin", source, getPlayerIP ( source ), getPlayerAccountName ( source ), getPlayerSerial ( source ), hasObjectPermissionTo ( source, "general.adminpanel", false ), aPlayers[source]["country"] )
end
end
setPedGravity ( source, getGravity() )
end )
function updatePlayerCountry ( player )
local isIP2CResourceRunning = getResourceFromName( "ip2c" )
isIP2CResourceRunning = isIP2CResourceRunning and getResourceState( isIP2CResourceRunning ) == "running"
aPlayers[player]["country"] = isIP2CResourceRunning and exports.ip2c:getPlayerCountry ( player ) or false
end
local serialExp = "^" .. string.rep("[A-F0-9]", 32) .. "$"
function isValidSerial(serial)
return serial:match(serialExp)
end
function aPlayerInitialize(player)
local serial = getPlayerSerial(player)
if (not isValidSerial(serial)) then
outputChatBox("LOG: " .. getPlayerName(player) .. " - Possibly tampered serial. Denied entry.")
kickPlayer(player, "5B Client verification mismatch.")
end
bindKey(player, "p", "down", "admin")
aPlayers[player] = {}
aPlayers[player]["money"] = getPlayerMoney(player)
local strVersion = getPlayerVersion(player)
-- Format it all prettyful
local _,_,ver,type,build = string.find ( strVersion, "(.*)-([0-9])%.(.*)" )
aPlayers[player]["version"] = ver .. ( type < '9' and " pre " or " " ) .. "(" .. type .. "." .. build .. ")"
updatePlayerCountry(player)
chatHistory[player] = {}
end
addEventHandler ( "onPlayerQuit", root, function ()
aPlayers[source] = nil
chatHistory[source] = nil
end )
function aPlayerSerialCheck ( player, result )
if ( result == 0 ) then kickPlayer ( player, "Invalid serial" ) end
end
addEventHandler ( "onPlayerLogin", root, function ( previous, account, auto )
if ( hasObjectPermissionTo ( source, "general.adminpanel", false ) ) then
triggerEvent ( "aPermissions", source )
notifyPlayerLoggedIn( source )
end
end )
addCommandHandler ( "register", function ( player, command, arg1, arg2 )
local username = getPlayerName ( player )
local password = arg1
if ( arg2 ) then
username = arg1
password = arg2
end
if ( password ~= nil ) then
if ( string.len ( password ) < 4 ) then
outputChatBox ( "register: - Password should be at least 4 characters long", player, 255, 100, 70 )
elseif ( addAccount ( username, password ) ) then
outputChatBox ( "You have successfully registered! Username: '"..username.."', Password: '"..password.."'(Remember it)", player, 255, 100, 70 )
outputServerLog ( "ACCOUNTS: "..getPlayerName ( player ).." registered account '"..username.."' (IP: "..getPlayerIP(player).." Serial: "..getPlayerSerial(player)..")" )
elseif ( getAccount ( username ) ) then
outputChatBox ( "register: - Account with this name already exists.", player, 255, 100, 70 )
else
outputChatBox ( "Unknown Error", player, 255, 100, 70 )
end
else
outputChatBox ( "register: - Syntax is 'register [<nick>] <password>'", player, 255, 100, 70 )
end
end )
-- This requires "function.removeAccount" permission for both the admin resource and the player
addCommandHandler ( "unregister", function ( player, command, arg1 )
local username = arg1 or ""
local result = "failed - No permission"
if ( hasObjectPermissionTo ( player, "function.removeAccount", false ) ) then
local account = getAccount ( username )
if not account then
result = "failed - Does not exist"
elseif #aclGetAccountGroups ( account ) > 1 then
result = "failed - Account in more than one ACL group"
elseif removeAccount( account ) then
result = "succeeded"
else
result = "failed - Check resource has permission"
end
end
outputChatBox ( "Unregistering account '"..username.."' "..result, player, 255, 100, 70 )
outputServerLog ( "ADMIN: "..getAdminNameForLog ( player ).." unregistering account '"..username.."' "..result.." (IP: "..getPlayerIP(player).." Serial: "..getPlayerSerial(player)..")" )
end )
-- Returns "name" or "name(accountname)" if they differ
function getAdminNameForLog(player)
local name = getPlayerName( player )
if not isGuestAccount( getPlayerAccount( player ) ) then
local accountName = getAccountName( getPlayerAccount( player ) )
if name ~= accountName then
return name.."("..accountName..")"
end
end
return name
end
function aAdminMenu ( player, command )
if ( hasObjectPermissionTo ( player, "general.adminpanel", false ) ) then
triggerClientEvent ( player, "aClientAdminMenu", root )
aPlayers[player]["chat"] = true
end
end
addCommandHandler ( "admin", aAdminMenu )
function aAction ( type, action, admin, player, data, more )
if ( aLogMessages[type] ) then
local function aEscapeNickname( name )
return string.gsub( name, "%%", "%%%%" )
end
local function aStripString ( string )
local adminName = aEscapeNickname( getPlayerName ( admin ) )
string = tostring ( string )
string = string.gsub ( string, "$admin", adminName)
string = string.gsub ( string, "$by_admin_4all", isAnonAdmin4All( admin ) and "" or " by " .. adminName )
string = string.gsub ( string, "$by_admin_4plr", isAnonAdmin4Victim( admin ) and "" or " by " .. adminName )
string = string.gsub ( string, "$data2", more or "" )
if ( player ) then
local playerName = aEscapeNickname( getPlayerName( player ) )
string = string.gsub ( string, "$player", playerName)
end
return tostring ( string.gsub ( string, "$data", data or "" ) )
end
local node = aLogMessages[type][action]
if ( node ) then
local r, g, b = node["r"], node["g"], node["b"]
if ( node["all"] ) then outputChatBox ( aStripString ( node["all"] ), root, r, g, b, true ) end
if ( node["admin"] ) and ( admin ~= player ) then outputChatBox ( aStripString ( node["admin"] ), admin, r, g, b, true ) end
if ( node["player"] ) then outputChatBox ( aStripString ( node["player"] ), player, r, g, b, true ) end
if ( node["log"] ) then outputServerLog ( aStripString ( node["log"] ) ) end
end
end
end
-- Should admin name be hidden from public chatbox message?
function isAnonAdmin4All ( admin )
return aPlayers[admin] and aPlayers[admin]["AnonymousAdmin"] or false
end
-- Should admin name be hidden from private chatbox message?
function isAnonAdmin4Victim ( admin )
return false
end
addEvent ( "aTeam", true )
addEventHandler ( "aTeam", root, function ( action, name, r, g, b )
if checkClient( "command."..action, source, 'aTeam', action ) then
return
end
if ( hasObjectPermissionTo ( client or source, "command."..action, false ) ) then
mdata = ""
if ( action == "createteam" ) then
local success
if ( tonumber ( r ) ) and ( tonumber ( g ) ) and ( tonumber ( b ) ) then
success = createTeam ( name, tonumber ( r ), tonumber ( g ), tonumber ( b ) )
else
success = createTeam ( name )
end
if ( not success ) then
action = nil
outputChatBox ( "Team \""..name.."\" could not be created.", source, 255, 0, 0 )
end
elseif ( action == "destroyteam" ) then
local team = getTeamFromName ( name )
if ( getTeamFromName ( name ) ) then
destroyElement ( team )
else
action = nil
end
else
action = nil
end
if ( action ~= nil ) then
aAction ( "server", action, source, false, mdata )
end
return true
end
outputChatBox ( "Access denied for '"..tostring ( action ).."'", source, 255, 168, 0 )
return false
end )
local aAdminRights = {
["settings"] = "general.tab_resources",
["resourcelist"] = "general.tab_resources",
["adminpanel"] = "general.adminpanel",
["sync"] = "command.aclmanager",
["aclcreate"] = "command.aclcreate",
["acldestroy"] = "command.acldestroy",
["acladd"] = "command.acladd",
["aclremove"] = "command.aclremove",
}
addEvent ( "aAdmin", true )
addEventHandler ( "aAdmin", root, function ( action, ... )
if not action then
return
end
if checkClient( aAdminRights[action] or true, source, 'aAdmin', action ) then
return
end
local mdata, mdata2
if ( action == "password" ) then
if ( not arg[1] ) then outputChatBox ( "Error - Password missing.", source, 255, 0, 0 )
elseif ( not arg[2] ) then outputChatBox ( "Error - New password missing.", source, 255, 0, 0 )
elseif ( not arg[3] ) then outputChatBox ( "Error - Confirm password.", source, 255, 0, 0 )
elseif ( tostring ( arg[2] ) ~= tostring ( arg[3] ) ) then outputChatBox ( "Error - Passwords do not match.", source, 255, 0, 0 )
else
local account = getAccount ( getPlayerAccountName ( source ), tostring ( arg[1] ) )
if ( account ) then
setAccountPassword ( account, arg[2] )
else
outputChatBox ( "Error - Invalid password.", source, 255, 0, 0 )
end
end
elseif ( action == "settings" ) then
local cmd = arg[1]
local resName = arg[2]
local tableOut = {}
if ( cmd == "change" ) then
local name = arg[3]
local value = arg[4]
-- Get previous value
local settings = aGetResourceSettings( resName )
local oldvalue = settings[name].current
-- Match type
local changed
if type(oldvalue) == 'boolean' then value = value=='true' end
if type(oldvalue) == 'number' then value = tonumber(value) end
if type(oldvalue) == "table" then
value = fromJSON("[["..value.."]]")
changed = not table.compare(value, oldvalue)
else
changed = value ~= oldvalue
end
if changed then
if aSetResourceSetting( resName, name, value ) then
-- Tell the resource one of its settings has changed
local res = getResourceFromName(resName)
local resRoot = getResourceRootElement(res)
if resRoot then
if getVersion().mta < "1.1" then
triggerEvent('onSettingChange', resRoot, name, oldvalue, value, source )
end
end
end
end
elseif ( cmd == "getall" ) then
tableOut = aGetResourceSettings( resName )
for name,value in pairs(tableOut) do
if type(value.default) == "table" then
tableOut[name].default = string.gsub(toJSON(value.default),"^(%[ %[ )(.*)( %] %])$", "%2")
tableOut[name].current = string.gsub(toJSON(value.current),"^(%[ %[ )(.*)( %] %])$", "%2")
end
end
end
triggerClientEvent ( source, "aAdminSettings", root, cmd, resName, tableOut )
elseif (action == "resourcelist") then
local resName = arg[1]
local count = true
_, count = aGetResourceSettings(resName, count)
if count then
local hasResourceSetting
if count ~= 0 then
hasResourceSetting = true
end
triggerClientEvent ( source, "setVisibilityOfSettingsButton", resourceRoot, hasResourceSetting)
end
elseif ( action == "sync" ) then
local type = arg[1]
local tableOut = {}
if ( type == "aclgroups" ) then
tableOut["groups"] = {}
for id, group in ipairs ( aclGroupList() ) do
table.insert ( tableOut["groups"] ,aclGroupGetName ( group ) )
end
tableOut["acl"] = {}
for id, acl in ipairs ( aclList() ) do
table.insert ( tableOut["acl"] ,aclGetName ( acl ) )
end
triggerClientEvent ( source, "aAdminACL", root, type, tableOut )
elseif ( type == "aclobjects" ) then
local group = aclGetGroup ( tostring ( arg[2] ) )
if ( group ) then
tableOut["name"] = arg[2]
tableOut["objects"] = aclGroupListObjects ( group )
tableOut["acl"] = {}
for id, acl in ipairs ( aclGroupListACL ( group ) ) do
table.insert ( tableOut["acl"], aclGetName ( acl ) )
end
end
triggerClientEvent ( source, "aAdminACL", root, type, tableOut )
elseif ( type == "aclrights" ) then
local acl = aclGet ( tostring ( arg[2] ) )
if ( acl ) then
tableOut["name"] = arg[2]
tableOut["rights"] = {}
for id, name in ipairs ( aclListRights ( acl ) ) do
tableOut["rights"][name] = aclGetRight ( acl, name )
end
end
triggerClientEvent ( source, "aAdminACL", root, type, tableOut )
elseif ( type == 'playeraclgroups') then
local player = arg[2]
if isElement(player) then
local ignoredGroups = {
['Everyone'] = true,
['autoGroup_irc'] = true,
}
for _, v in ipairs(aclGroupList()) do
local groupName = aclGroupGetName(v)
if (not ignoredGroups[groupName]) then
tableOut[groupName] = isObjectInACLGroup('user.'..getAccountName(getPlayerAccount(player)), v)
end
end
end
triggerClientEvent ( source, "aPermissionsSync", root, player, tableOut )
end
elseif ( action == "aclcreate" ) then
local name = arg[2]
if ( ( name ) and ( string.len ( name ) >= 1 ) ) then
if ( arg[1] == "group" ) then
mdata = "Group "..name
if ( aclCreateGroup ( name ) ) then
outputServerLog ("ACL: "..getPlayerName(source).."["..getAccountName (getPlayerAccount(source)).."] ["..getPlayerSerial (source).."] ["..getPlayerIP (source).."] created "..mdata)
end
elseif ( arg[1] == "acl" ) then
mdata = "ACL "..name
if ( aclCreate ( name ) ) then
outputServerLog ("ACL: "..getPlayerName(source).."["..getAccountName (getPlayerAccount(source)).."] ["..getPlayerSerial (source).."] ["..getPlayerIP (source).."] created "..mdata)
end
end
triggerEvent ( "aAdmin", source, "sync", "aclgroups" )
else
outputChatBox ( "Error - Invalid "..arg[1].." name", source, 255, 0, 0 )
end
elseif ( action == "acldestroy" ) then
local name = arg[2]
if ( arg[1] == "group" ) then
if ( aclGetGroup ( name ) ) then
mdata = "Group "..name
aclDestroyGroup ( aclGetGroup ( name ) )
outputServerLog ("ACL: "..getPlayerName(source).."["..getAccountName (getPlayerAccount(source)).."] ["..getPlayerSerial (source).."] ["..getPlayerIP (source).."] destroyed "..mdata)
end
elseif ( arg[1] == "acl" ) then
if ( aclGet ( name ) ) then
mdata = "ACL "..name
aclDestroy ( aclGet ( name ) )
outputServerLog ("ACL: "..getPlayerName(source).."["..getAccountName (getPlayerAccount(source)).."] ["..getPlayerSerial (source).."] ["..getPlayerIP (source).."] destroyed "..mdata)
end
end
triggerEvent ( "aAdmin", source, "sync", "aclgroups" )
elseif ( action == "acladd" ) then
if ( arg[3] ) then
if ( arg[1] == "object" ) then
local group = aclGetGroup ( arg[2] )
local object = arg[3]
if ( not aclGroupAddObject ( group, object ) ) then
outputChatBox ( "Error adding object '"..tostring ( object ).."' to group '"..tostring ( arg[2] ).."'", source, 255, 0, 0 )
else
outputServerLog ("ACL: "..getPlayerName(source).."["..getAccountName (getPlayerAccount(source)).."] ["..getPlayerSerial (source).."] ["..getPlayerIP (source).."] added "..object.." to ACL Group "..arg[2])
triggerEvent ( "aAdmin", source, "sync", "aclobjects", arg[2] )
if arg[4] then
triggerClientEvent ( source, "aOnPermissionsChange", source )
end
end
elseif ( arg[1] == "acl" ) then
local group = aclGetGroup ( arg[2] )
local acl = aclGet ( arg[3] )
if ( not aclGroupAddACL ( group, acl ) ) then
outputChatBox ( "Error adding ACL '"..tostring ( arg[3] ).."' to group '"..tostring ( arg[2] ).."'", source, 255, 0, 0 )
else
mdata2 = "ACL '"..arg[3].."'"
triggerEvent ( "aAdmin", source, "sync", "aclobjects", arg[2] )
outputServerLog ("ACL: "..getPlayerName(source).."["..getAccountName (getPlayerAccount(source)).."] ["..getPlayerSerial (source).."] ["..getPlayerIP (source).."] added "..mdata2.." to Group "..arg[2])
end
elseif ( arg[1] == "right" ) then
local acl = aclGet ( arg[2] )
local right = arg[3]
local enabled = arg[4]
if enabled == nil then
enabled = true
end
local verb = enabled and "adding" or "removing"
local prep = enabled and "to" or "from"
if ( not aclSetRight ( acl, right, enabled ) ) then
outputChatBox ( "Error "..verb.." right '"..tostring(arg[3]).."' "..prep.." group '"..tostring(arg[2]).."'", source, 255, 0, 0)
else
mdata2 = "Right '"..arg[3].."'"
triggerEvent ( "aAdmin", source, "sync", "aclrights", arg[2] )
outputServerLog ("ACL: "..getPlayerName(source).."["..getAccountName (getPlayerAccount(source)).."] ["..getPlayerSerial (source).."] ["..getPlayerIP (source).."] added "..mdata2.." to ACL "..arg[2])
end
end
end
elseif ( action == "aclremove" ) then
if ( arg[3] ) then
if ( arg[1] == "object" ) then
local group = aclGetGroup ( arg[2] )
local object = arg[3]
if ( not aclGroupRemoveObject ( group, object ) ) then
outputChatBox ( "Error - object '"..tostring ( object ).."' does not exist in group '"..tostring ( arg[2] ).."'", source, 255, 0, 0 )
else
mdata2 = "Object '"..arg[3].."'"
triggerEvent ( "aAdmin", source, "sync", "aclobjects", arg[2] )
outputServerLog ("ACL: "..getPlayerName(source).."["..getAccountName (getPlayerAccount(source)).."] ["..getPlayerSerial (source).."] ["..getPlayerIP (source).."] removed "..mdata2)
if arg[4] then
triggerClientEvent ( source, "aOnPermissionsChange", source )
end
end
elseif ( arg[1] == "acl" ) then
local group = aclGetGroup ( arg[2] )
local acl = aclGet ( arg[3] )
if ( not aclGroupRemoveACL ( group, acl ) ) then
outputChatBox ( "Error - ACL '"..tostring ( arg[3] ).."' does not exist in group '"..tostring ( arg[2] ).."'", source, 255, 0, 0 )
else
mdata2 = "ACL '"..arg[3].."'"
triggerEvent ( "aAdmin", source, "sync", "aclobjects", arg[2] )
outputServerLog ("ACL: "..getPlayerName(source).."["..getAccountName (getPlayerAccount(source)).."] ["..getPlayerSerial (source).."] ["..getPlayerIP (source).."] removed "..mdata2)
end
elseif ( arg[1] == "right" ) then
local acl = aclGet ( arg[2] )
local right = arg[3]
if ( not aclRemoveRight ( acl, right ) ) then
outputChatBox ( "Error - right '"..tostring ( arg[3] ).."' does not exist in ACL '"..tostring ( arg[2] ).."'", source, 255, 0, 0 )
else
mdata = "ACL '"..arg[2].."'"
mdata2 = "Right '"..arg[3].."'"
triggerEvent ( "aAdmin", source, "sync", "aclrights", arg[2] )
outputServerLog ("ACL: "..getPlayerName(source).."["..getAccountName (getPlayerAccount(source)).."] ["..getPlayerSerial (source).."] ["..getPlayerIP (source).."] removed "..mdata2.." from "..mdata)
end
end
end
elseif ( action == "adminpanel" ) then
local cmd = arg[1]
if cmd == "updateAnonymous" then
local state = arg[2]
aPlayers[client]["AnonymousAdmin"] = state
end
end
end )
-- seconds to description i.e. "10 mins"
function secondsToTimeDesc( seconds )
if seconds then
local tab = { {"day",60*60*24}, {"hour",60*60}, {"min",60}, {"sec",1} }
for i,item in ipairs(tab) do
local t = math.floor(seconds/item[2])
if t > 0 or i == #tab then
return tostring(t) .. " " .. item[1] .. (t~=1 and "s" or "")
end
end
end
return ""
end
function warp ( p, to )
local x, y, z, r, dim, int
if type ( to ) == "table" then
x, y, z = unpack ( to )
r, dim, int = 0, 0, 0
else
x, y, z = getElementPosition ( to )
_, _, r = getElementRotation ( to )
dim = getElementDimension ( to )
int = getElementInterior ( to )
end
local target = getPedOccupiedVehicle ( p ) or p
x = x - math.sin ( math.rad ( r ) ) * 2
y = y + math.cos ( math.rad ( r ) ) * 2
setTimer ( setElementPosition, 1000, 1, target, x, y, z + 1 )
fadeCamera ( p, false, 1, 0, 0, 0 )
setElementDimension ( target, dim )
setElementInterior ( target, int )
setTimer ( fadeCamera, 1000, 1, p, true, 1 )
end
addEvent ( "aPlayer", true )
addEventHandler ( "aPlayer", root, function ( player, action, data, additional, additional2 )
if checkClient( "command."..action, source, 'aPlayer', action ) then return end
if not isElement( player ) then
return -- Ignore if player is no longer valid
end
if ( hasObjectPermissionTo ( client or source, "command."..action, false ) ) then
local admin = source
local mdata = ""
local more = ""
if ( action == "kick" ) then
local reason = data or ""
mdata = reason~="" and ( "(" .. reason .. ")" ) or ""
local isAnonAdmin = isAnonAdmin4All(source)
if isAnonAdmin then
setTimer ( kickPlayer, 100, 1, player, "Anonymous admin", reason )
else
setTimer ( kickPlayer, 100, 1, player, source, reason )
end
elseif ( action == "ban" ) then
local reason = data or ""
local seconds = tonumber(additional) and tonumber(additional) > 0 and tonumber(additional)
local bUseSerial = additional2
local isAnonAdmin = isAnonAdmin4All(source)
mdata = reason~="" and ( "(" .. reason .. ")" ) or ""
more = seconds and ( "(" .. secondsToTimeDesc(seconds) .. ")" ) or ""
if bUseSerial and getPlayerName ( player ) and not isAnonAdmin then
-- Add banned player name to the reason
reason = reason .. " (nick: " .. getPlayerName ( player ) .. ")"
end
-- Add account name of banner to the reason
local adminAccountName = getAccountName ( getPlayerAccount ( source ) )
if adminAccountName and adminAccountName ~= getPlayerName( source ) and not isAnonAdmin then
reason = reason .. " (by " .. adminAccountName .. ")"
end
if bUseSerial then
outputChatBox ( "You banned serial " .. getPlayerSerial( player ), source, 255, 100, 70 )
if isAnonAdmin then
setTimer ( function()
local tBan = addBan( nil, nil, getPlayerSerial(player), "Anonymous admin", reason, seconds or 0 )
setBanAdmin(tBan,adminAccountName)
end, 100, 1)
else
setTimer ( function()
local tBan = addBan( nil, nil, getPlayerSerial(player), source, reason, seconds or 0 )
setBanAdmin(tBan,adminAccountName)
end, 100, 1)
end
else
outputChatBox ( "You banned IP " .. getPlayerIP( player ), source, 255, 100, 70 )
if isAnonAdmin then
setTimer ( function()
local tBan = banPlayer( player, true, false, false, nil, reason, seconds or 0 )
setBanAdmin(tBan,adminAccountName)
end, 100, 1)
else
setTimer ( function()
local tBan = banPlayer( player, true, false, false, source, reason, seconds or 0 )
setBanAdmin(tBan,adminAccountName)
end, 100, 1)
end
end
setTimer( triggerEvent, 1000, 1, "aSync", root, "bansdirty" )
elseif ( action == "mute" ) then
if ( isPlayerMuted ( player ) ) then action = "un"..action end