/
admin_server.lua
494 lines (460 loc) · 16.3 KB
/
admin_server.lua
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
--[[**********************************
*
* Multi Theft Auto - Admin Panel
*
* server/admin_server.lua
*
* Original File by lil_Toady
*
**************************************]]
_types = {"player", "team", "vehicle", "resource", "bans", "server", "admin"}
aPlayers = {}
aLogMessages = {}
aInteriors = {}
aStats = {}
aReports = {}
aWeathers = {}
function aHandleIP2CUpdate()
local playersToUpdate = false
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")
if hasAdminPermission then
for playerToUpdateID = 1, #playersToUpdate do
local playerToUpdate = playersToUpdate[playerToUpdateID]
triggerClientEvent(playerElement, "aClientPlayerJoin", playerToUpdate,
false, false, false, false,
aPlayers[playerToUpdate].country,
aPlayers[playerToUpdate].countryname
)
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")) then
triggerClientEvent(player, "aClientResourceStart", root, resourceName)
end
end
if resourceName == "ip2c" then
aHandleIP2CUpdate()
end
return
end
aSetupACL()
aSetupCommands()
aSetupStorage()
for id, player in ipairs(getElementsByType("player")) do
aPlayerInitialize(player)
end
aHandleIp2cSetting()
end
)
addEventHandler(
"onResourceStop",
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")) then
triggerClientEvent(player, "aClientResourceStop", root, resourceName)
end
end
if resourceName == "ip2c" then
aHandleIP2CUpdate()
end
else
aReleaseStorage()
end
aclSave()
end
)
addEventHandler(
"onPlayerJoin",
root,
function()
aPlayerInitialize(source)
for id, player in ipairs(getElementsByType("player")) do
if (hasObjectPermissionTo(player, "general.adminpanel")) then
triggerClientEvent(
player,
"aClientPlayerJoin",
source,
getPlayerIP(source),
getPlayerUserName(source),
getPlayerSerial(source),
false,
aPlayers[source]["country"],
aPlayers[source]["countryname"]
)
end
end
setPedGravity(source, getGravity())
end
)
addEventHandler(
"onPlayerQuit",
root,
function()
aPlayers[source] = nil
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
if aPlayers[player].country then
aPlayers[player].countryname = isIP2CResourceRunning and exports.ip2c:getCountryName(aPlayers[player].country) or false
end
end
function aPlayerInitialize(player)
aPlayers[player] = {}
aPlayers[player].money = getPlayerMoney(player)
aPlayers[player].muted = isPlayerMuted(player)
aPlayers[player].frozen = isElementFrozen(player)
updatePlayerCountry(player)
end
function aAction(type, action, admin, player, data, more)
if (aLogMessages[type]) then
function aStripString(string, hex)
if not hex then
hex = ""
end
string = tostring(string)
string = string.gsub(string, "$admin", isAnonAdmin(admin) and "Admin" or (getPlayerName(admin) .. hex))
string = string.gsub(string, "$data2", more or "")
if (player) then
string = string.gsub(string, "$player", getPlayerName(player) .. hex)
end
return string.gsub(string, "$data", (data and data .. hex or ""))
end
local node = aLogMessages[type][action]
if (node) then
local r, g, b = node["r"], node["g"], node["b"]
local hex = RGBToHex(r, g, b)
if (node["all"]) then
outputChatBox(aStripString(node["all"], hex), root, r, g, b, true)
end
if (node["admin"]) and (admin ~= player) then
outputChatBox(aStripString(node["admin"], hex), admin, r, g, b, true)
end
if (node["player"]) then
outputChatBox(aStripString(node["player"], hex), player, r, g, b, true)
end
if (node["log"]) then
outputServerLog(aStripString(node["log"]))
end
end
end
end
addEvent("aTeam", true)
addEventHandler(
"aTeam",
root,
function(action, name, ...)
if (hasObjectPermissionTo(source, "command." .. action)) then
local func = aFunctions.team[action]
if (func) then
local result, mdata1, mdata2 = func(name, ...)
if (result ~= false) then
if (type(result) == "string") then
action = result
end
aAction("team", action, source, false, mdata1, mdata2)
end
end
else
outputChatBox("Access denied for '" .. tostring(action) .. "'", source, 255, 168, 0)
end
end
)
addEvent("aPlayer", true)
addEventHandler(
"aPlayer",
root,
function(player, action, ...)
if (hasObjectPermissionTo(source, "command." .. action)) then
local mdata1, mdata2
local func = aFunctions.player[action]
if (func) then
local result
result, mdata1, mdata2 = func(player, ...)
if (result ~= false) then
if (type(result) == "string") then
action = result
end
aAction("player", action, source, player, mdata1, mdata2)
end
end
else
outputChatBox("Access denied for '" .. tostring(action) .. "'", source, 255, 168, 0)
end
end
)
addEvent("aVehicle", true)
addEventHandler(
"aVehicle",
root,
function(player, action, ...)
local vehicle = getPedOccupiedVehicle(player)
if (not vehicle) then
return
end
if (hasObjectPermissionTo(source, "command." .. action)) then
local mdata1, mdata2
local func = aFunctions.vehicle[action]
if (func) then
local result
result, mdata1, mdata2 = func(player, vehicle, ...)
if (result ~= false) then
if (type(result) == "string") then
action = result
end
local seats = getVehicleMaxPassengers(vehicle) + 1
for i = 0, seats do
local passenger = getVehicleOccupant(vehicle, i)
if (passenger) then
if ((passenger == player) and (getPedOccupiedVehicle(source) ~= vehicle)) then
aAction("vehicle", action, source, passenger, mdata)
else
aAction("vehicle", action, passenger, passenger, mdata1, mdata2)
end
end
end
end
end
else
outputChatBox("Access denied for '" .. tostring(action) .. "'", source, 255, 168, 0)
end
end
)
addEvent("aResource", true)
addEventHandler(
"aResource",
root,
function(name, action, ...)
if (not name or not action) then
return
end
local resource = getResourceFromName(name)
if (not resource) then
return
end
if (hasObjectPermissionTo(source, "command." .. action)) then
local func = aFunctions.resource[action]
if (func) then
local result, mdata1, mdata2 = func(resource, ...)
if (result ~= false) then
if (type(result) == "string") then
action = result
end
aAction("resource", action, source, player, mdata1, mdata2)
end
end
else
outputChatBox("Access denied for '" .. tostring(action) .. "'", source, 255, 168, 0)
end
end
)
addEvent("aServer", true)
addEventHandler(
"aServer",
root,
function(action, ...)
if (hasObjectPermissionTo(source, "command." .. action)) then
local func = aFunctions.server[action]
if (func) then
local result, mdata1, mdata2 = func(...)
if (result ~= false) then
if (type(result) == "string") then
action = result
end
aAction("server", action, source, player, mdata1, mdata2)
end
end
else
outputChatBox("Access denied for '" .. tostring(action) .. "'", source, 255, 168, 0)
end
end
)
addEvent("aServerGlitchRefresh", true)
addEventHandler(
"aServerGlitchRefresh",
root,
function()
triggerClientEvent("aClientRefresh", client, isGlitchEnabled("quickreload"), isGlitchEnabled("fastmove"), isGlitchEnabled("fastfire"), isGlitchEnabled("crouchbug"), isGlitchEnabled("highcloserangedamage"), isGlitchEnabled("hitanim"), isGlitchEnabled("fastsprint"), isGlitchEnabled("baddrivebyhitbox"), isGlitchEnabled("quickstand"))
end
)
addEvent("aMessage", true)
addEventHandler(
"aMessage",
root,
function(action, data)
if (action == "new") then
local time = getRealTime()
local id = #aReports + 1
aReports[id] = {}
aReports[id].author = getPlayerName(source)
aReports[id].category = tostring(data.category)
aReports[id].subject = tostring(data.subject)
aReports[id].text = tostring(data.message)
aReports[id].time = string.format("%02d/%02d %02d:%02d", time.monthday, time.month+1, time.hour, time.minute)
aReports[id].read = false
elseif (action == "get") then
triggerClientEvent(source, "aMessage", source, "get", aReports)
return
elseif (action == "read") then
if (aReports[data]) then
aReports[data].read = true
end
triggerClientEvent(source, "aMessage", source, "get", aReports)
elseif (action == "delete") then
local id = data[1]
if (not aReports[id]) then
outputChatBox("Error - Message not found.", source, 255, 0, 0)
triggerClientEvent(source, "aMessage", source, "get", aReports)
return
end
local message = data[2]
for key, value in pairs(aReports[id]) do
if (message[key] ~= value) then
outputChatBox("Error - Message mismatch, please try again.", source, 255, 0, 0)
triggerClientEvent(source, "aMessage", source, "get", aReports)
return
end
end
table.remove(aReports, id)
triggerClientEvent(source, "aMessage", source, "get", aReports)
end
for id, p in ipairs(getElementsByType("player")) do
if (hasObjectPermissionTo(p, "general.adminpanel")) then
triggerEvent(EVENT_SYNC, p, SYNC_MESSAGES)
end
end
end
)
addEvent("aBans", true)
addEventHandler(
"aBans",
root,
function(action, data)
if (hasObjectPermissionTo(source, "command." .. action)) then
local mdata = ""
local more = ""
if (action == "banip") then
mdata = data
if (not BanIP(data, source)) then
action = nil
end
elseif (action == "banserial") then
mdata = data
if (isValidSerial(data)) then
if (not BanSerial(string.upper(data), source)) then
action = nil
end
else
outputChatBox("Error - Invalid serial", source, 255, 0, 0)
action = nil
end
elseif (action == "unbanip") then
mdata = data
if (not UnbanIP(data, source)) then
action = nil
end
elseif (action == "unbanserial") then
mdata = data
if (not UnbanSerial(data, source)) then
action = nil
end
else
action = nil
end
if (action ~= nil) then
aAction("bans", action, source, false, mdata, more)
triggerEvent("aSync", source, "sync", "bans")
end
return true
end
outputChatBox("Access denied for '" .. tostring(action) .. "'", source, 255, 168, 0)
return false
end
)
addEvent("aExecute", true)
addEventHandler(
"aExecute",
root,
function(action, echo)
if (hasObjectPermissionTo(source, "command.execute")) then
local result = loadstring("return " .. action)()
if (echo == true) then
local restring = ""
if (type(result) == "table") then
for k, v in pairs(result) do
restring = restring .. tostring(v) .. ", "
end
restring = string.sub(restring, 1, -3)
restring = "Table (" .. restring .. ")"
elseif (type(result) == "userdata") then
restring = "Element (" .. getElementType(result) .. ")"
else
restring = tostring(result)
end
outputChatBox("Command executed! Result: " .. restring, source, 0, 0, 255)
end
outputServerLog("ADMIN: " .. getPlayerName(source) .. " executed command: " .. action)
end
end
)
addEvent("aAdminChat", true)
addEventHandler(
"aAdminChat",
root,
function(chat)
for id, player in ipairs(getElementsByType("player")) do
if (aPlayers[player]["chat"]) then
triggerClientEvent(player, "aClientAdminChat", source, chat)
end
end
end
)
addCommandHandler(get("adminChatCommandName"),
function(thePlayer, cmd, ...)
if (hasObjectPermissionTo(thePlayer, "general.tab_adminchat", false) and #arg > 0) then
triggerEvent("aAdminChat", thePlayer, table.concat(arg, " "))
end
end
)