-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.lua
More file actions
76 lines (66 loc) · 2.49 KB
/
server.lua
File metadata and controls
76 lines (66 loc) · 2.49 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
if not LoadResourceFile(GetCurrentResourceName(), "players.json") then
SaveResourceFile(GetCurrentResourceName(), "players.json", "{}", -1)
end
Citizen.CreateThread(function()
while GetConvar('rcon_password', nil) ~= nil do
local buffer = GetConsoleBuffer()
for i=0, GetNumPlayerIndices() -1 do
local player = GetPlayerFromIndex(i)
if IsPlayerAuthed(player) then
TriggerClientEvent("console:SetAuth", player, true)
TriggerClientEvent("console:UpdateConsoleBuffer", player, buffer)
else
TriggerClientEvent("console:SetAuth", player, false)
end
end
Citizen.Wait(500)
end
print('^1Fatal Error (ingame console): ^3No rcon password is defined. Make sure to set \'rcon_password\' in your server.cfg^7')
end)
RegisterServerEvent("console:ExecuteConsoleCommand")
AddEventHandler("console:ExecuteConsoleCommand", function(cmd)
if IsPlayerAuthed(source) then
ExecuteCommand(cmd)
if not IsPrincipalAceAllowed('resource.'..GetCurrentResourceName(), 'command') then
print('^1Please make sure to add ^3add_ace resource.'..GetCurrentResourceName()..' command allow^1 to your server.cfg^7')
end
end
end)
RegisterServerEvent("console:CheckPasssword")
AddEventHandler("console:CheckPasssword", function(pwd)
if GetConvar('rcon_password', nil) == pwd then
local players = json.decode(LoadResourceFile(GetCurrentResourceName(), "players.json"))
if players == nil then
players = {}
end
players[GetSteamHex(source)] = pwd
SaveResourceFile(GetCurrentResourceName(), "players.json", json.encode(players), -1)
--TriggerClientEvent("console:SetAuth", source, true)
else
TriggerClientEvent("console:ErrorMsg", source, 'Invalid rcon password.')
end
end)
function IsPlayerAuthed(player)
local players = json.decode(LoadResourceFile(GetCurrentResourceName(), "players.json"))
if players == nil then
players = {}
end
local hex = GetSteamHex(player)
if hex ~= nil then
if players[hex] == GetConvar('rcon_password', nil) then
return true
end
end
return false
end
function GetSteamHex(player)
local hex = nil
for i=0, GetNumPlayerIdentifiers(player)-1 do
local id = GetPlayerIdentifier(player, i)
if string.find(id, "steam:") then
hex = id
break;
end
end
return hex;
end