-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcl_check_permissions.txt
127 lines (91 loc) · 3.04 KB
/
cl_check_permissions.txt
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
--@name cl_check_permissions
--@author legokidlogan
--@client
if checkPermissions then return end -- Don't run twice
permissions = permissions or {}
permissionSatisfied = permissionSatisfied or false
permissionRequestSent = false
local urlTest = "https://cdn.discordapp.com/attachments/269175189382758400/421572398689550338/unknown.png"
local permArgs = {
["bass.loadURL"] = urlTest,
["http.get"] = urlTest,
["http.post"] = urlTest,
["material.urlcreate"] = urlTest,
}
function checkPermissions( default )
local isSatisfied = true
default = default == nil or default
for _, permission in pairs( permissions ) do
local doBreak
local succeeded = pcall( function()
if not hasPermission( permission, permArgs[permission] ) then
isSatisfied = false
doBreak = true
end
end )
if not succeeded then
isSatisfied = default
doBreak = not default
end
if doBreak then break end
end
permissionSatisfied = isSatisfied
return permissionSatisfied
end
function addPermission( permission )
if not permission then return end
if not table.hasValue( permissions, permission ) then
table.insert( permissions, permission )
end
end
function addPermissions( perms )
if not perms then return end
for _, perm in ipairs( perms ) do
addPermission( perm )
end
end
-- Automatically handles permission requests that might not exist depending on which server you're playing on
function setupPermissionRequestSafe( perms, str, popup )
local success, err = pcall( setupPermissionRequest, perms, str, popup )
if success then return end
if type( err ) == "table" then
err = err.message
end
local perm = string.explode( "Invalid permission name: ", err )[2]
local newPerms = {}
local newCount = 0
for _, oldPerm in ipairs( perms ) do
if oldPerm ~= perm then
newCount = newCount + 1
newPerms[newCount] = oldPerm
end
end
return setupPermissionRequestSafe( newPerms, str, popup )
end
_sendPermissionRequest = _sendPermissionRequest or sendPermissionRequest
function sendPermissionRequest()
if not render.isHUDActive() then return end
if permissionRequestSent then return end
_sendPermissionRequest()
permissionRequestSent = true
end
hook.add( "permissionrequest", "LKL_CheckPerms_PermissionRequest", function()
--permissionRequestSent = true
checkPermissions()
--hook.remove( "permissionrequest", "LKL_CheckPerms_PermissionRequest" )
end )
local function HUDConnected() -- Auto-check and auto-request perms when someone connects to a HUD
checkPermissions()
if not permissionSatisfied then
if permissionRequestSent then
enableHud( player(), false )
else
sendPermissionRequest()
end
end
end
hook.add( "hudconnected", "LKL_CheckPerms_HUDConnected", HUDConnected )
checkPermissions()
if render.isHUDActive() then
HUDConnected()
end