Skip to content

Commit 8e890ae

Browse files
committed
Make failed permission checks throw errors
1 parent 26fa040 commit 8e890ae

6 files changed

Lines changed: 40 additions & 40 deletions

File tree

lua/starfall/libs_sh/files.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ file.CreateDir("starfallscriptdata/")
2323
-- @return Contents, or nil if error
2424
-- @return Error message if applicable
2525
function files_library.read(path)
26-
if not SF.Permissions.check( SF.instance.player, path, "file.read" ) then return end
26+
if not SF.Permissions.check( SF.instance.player, path, "file.read" ) then SF.throw( "Insufficient permissions", 2 ) end
2727
SF.CheckType(path, "string")
2828
if path:find("..",1,true) then error("path contains '..'") return end
2929
local contents = file.Read("starfallscriptdata/"..path, "DATA")
@@ -35,7 +35,7 @@ end
3535
-- @return True if OK, nil if error
3636
-- @return Error message if applicable
3737
function files_library.write(path, data)
38-
if not SF.Permissions.check( SF.instance.player, path, "file.write" ) then return end
38+
if not SF.Permissions.check( SF.instance.player, path, "file.write" ) then SF.throw( "Insufficient permissions", 2 ) end
3939
SF.CheckType(path, "string")
4040
SF.CheckType(data, "string")
4141
if path:find("..",1,true) then error("path contains '..'") return end
@@ -48,7 +48,7 @@ end
4848
-- @param data String that will be appended to the file.
4949
-- @return Error message if applicable
5050
function files_library.append(path,data)
51-
if not SF.Permissions.check( SF.instance.player, path, "file.write" ) then return end
51+
if not SF.Permissions.check( SF.instance.player, path, "file.write" ) then SF.throw( "Insufficient permissions", 2 ) end
5252
SF.CheckType(path, "string")
5353
SF.CheckType(data, "string")
5454
if path:find("..",1,true) then error("path contains '..'") return end
@@ -61,7 +61,7 @@ end
6161
-- @return True if exists, false if not, nil if error
6262
-- @return Error message if applicable
6363
function files_library.exists(path)
64-
if not SF.Permissions.check( SF.instance.player, path, "file.exists" ) then return end
64+
if not SF.Permissions.check( SF.instance.player, path, "file.exists" ) then SF.throw( "Insufficient permissions", 2 ) end
6565
SF.CheckType(path, "string")
6666
if path:find("..",1,true) then error("path contains '..'") return end
6767
return file.Exists("starfallscriptdata/"..path, "DATA")
@@ -72,7 +72,7 @@ end
7272
-- @return True if successful, nil if error
7373
-- @return Error message if applicable
7474
function files_library.delete(path)
75-
if not SF.Permissions.check( SF.instance.player, path, "file.write" ) then return end
75+
if not SF.Permissions.check( SF.instance.player, path, "file.write" ) then SF.throw( "Insufficient permissions", 2 ) end
7676
SF.CheckType(path, "string")
7777
if path:find("..",1,true) then error("path contains '..'") return end
7878
if not file.Exists("starfallscriptdata/"..path, "DATA") then error("doesn't exist") return end

lua/starfall/libs_sh/find.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ end
5959
-- @param filter Optional function to filter results
6060
-- @return An array of found entities
6161
function find_library.inBox(min, max, filter)
62-
if not SF.Permissions.check( SF.instance.player, nil, "find" ) then return end
62+
if not SF.Permissions.check( SF.instance.player, nil, "find" ) then SF.throw( "Insufficient permissions", 2 ) end
6363
SF.CheckType(min,"Vector")
6464
SF.CheckType(max,"Vector")
6565
if filter then SF.CheckType(filter,"function") end
@@ -76,7 +76,7 @@ end
7676
-- @param filter Optional function to filter results
7777
-- @return An array of found entities
7878
function find_library.inSphere(center, radius, filter)
79-
if not SF.Permissions.check( SF.instance.player, nil, "find" ) then return end
79+
if not SF.Permissions.check( SF.instance.player, nil, "find" ) then SF.throw( "Insufficient permissions", 2 ) end
8080
SF.CheckType(center,"Vector")
8181
SF.CheckType(radius,"number")
8282

@@ -94,7 +94,7 @@ end
9494
-- @param filter Optional function to filter results
9595
-- @return An array of found entities
9696
function find_library.inCone(pos, dir, distance, radius, filter)
97-
if not SF.Permissions.check( SF.instance.player, nil, "find" ) then return end
97+
if not SF.Permissions.check( SF.instance.player, nil, "find" ) then SF.throw( "Insufficient permissions", 2 ) end
9898
SF.CheckType(pos,"Vector")
9999
SF.CheckType(dir,"Vector")
100100
SF.CheckType(distance,"number")
@@ -111,7 +111,7 @@ end
111111
-- @param filter Optional function to filter results
112112
-- @return An array of found entities
113113
function find_library.byClass(class, filter)
114-
if not SF.Permissions.check( SF.instance.player, nil, "find" ) then return end
114+
if not SF.Permissions.check( SF.instance.player, nil, "find" ) then SF.throw( "Insufficient permissions", 2 ) end
115115
SF.CheckType(class,"string")
116116

117117
local instance = SF.instance
@@ -125,7 +125,7 @@ end
125125
-- @param filter Optional function to filter results
126126
-- @return An array of found entities
127127
function find_library.byModel(model, filter)
128-
if not SF.Permissions.check( SF.instance.player, nil, "find" ) then return end
128+
if not SF.Permissions.check( SF.instance.player, nil, "find" ) then SF.throw( "Insufficient permissions", 2 ) end
129129
SF.CheckType(model,"string")
130130

131131
local instance = SF.instance
@@ -138,7 +138,7 @@ end
138138
-- @param filter Optional function to filter results
139139
-- @return An array of found entities
140140
function find_library.allPlayers(filter)
141-
if not SF.Permissions.check( SF.instance.player, nil, "find" ) then return end
141+
if not SF.Permissions.check( SF.instance.player, nil, "find" ) then SF.throw( "Insufficient permissions", 2 ) end
142142
local instance = SF.instance
143143
if not updateCooldown( instance ) then SF.throw( "You cannot run a find right now; use 'find_library.canFind()'", 2 ) end
144144

@@ -149,7 +149,7 @@ end
149149
-- @param filter Optional function to filter results
150150
-- @return An array of found entities
151151
function find_library.all(filter)
152-
if not SF.Permissions.check( SF.instance.player, nil, "find" ) then return end
152+
if not SF.Permissions.check( SF.instance.player, nil, "find" ) then SF.throw( "Insufficient permissions", 2 ) end
153153
local instance = SF.instance
154154
if not updateCooldown(instance) then SF.throw( "You cannot run a find right now; use 'find_library.canFind()'", 2 ) end
155155

lua/starfall/libs_sh/sound.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ end
2121
-- @return The sound object. Keep this around to ensure it isn't GC'd (and thus stopped)
2222
-- before it is done playing.
2323
function sound_library.create(entity, path)
24-
if not SF.Permissions.check( SF.instance.player, path, "sound.create" ) then return end
24+
if not SF.Permissions.check( SF.instance.player, path, "sound.create" ) then SF.throw( "Insufficient permissions", 2 ) end
2525
SF.CheckType(path, "string")
2626
SF.CheckType(entity, SF.Entities.Metatable)
2727
if path:match('["?]') then SF.throw( "Invalid sound path: " .. path, 2 ) end
@@ -35,7 +35,7 @@ end
3535
-- @param amplitude (Optinal) Loudness of the sound, from 0 to 255
3636
-- @param pitch (Optional) Pitch percent, from 0 to 255
3737
function sound_library.emitWorld(origin, path, amplitude, pitch)
38-
if not SF.Permissions.check( SF.instance.player, path, "sound.create" ) then return end
38+
if not SF.Permissions.check( SF.instance.player, path, "sound.create" ) then SF.throw( "Insufficient permissions", 2 ) end
3939
SF.CheckType(path, "string")
4040
SF.CheckType(origin, "Vector")
4141
if amplitude then
@@ -56,7 +56,7 @@ end
5656
-- @param soundlevel (Optional) The sound level. See sound:setLevel() for more info
5757
-- @param pitch (Optional) Pitch percent, from 0 to 255
5858
function sound_library.emitEntity(entity, path, soundlevel, pitch)
59-
if not SF.Permissions.check( SF.instance.player, path, "sound.create" ) then return end
59+
if not SF.Permissions.check( SF.instance.player, path, "sound.create" ) then SF.throw( "Insufficient permissions", 2 ) end
6060
SF.CheckType(entity, SF.Entities.Metatable)
6161
SF.CheckType(path, "string")
6262
if soundlevel then
@@ -86,7 +86,7 @@ end
8686

8787
--- Plays the sound.
8888
function sound_methods:play()
89-
if not SF.Permissions.check( SF.instance.player, this, "sound.modify" ) then return end
89+
if not SF.Permissions.check( SF.instance.player, this, "sound.modify" ) then SF.throw( "Insufficient permissions", 2 ) end
9090
SF.CheckType(self, sound_metamethods)
9191
unwrap(self):Play()
9292
end
@@ -95,7 +95,7 @@ end
9595
-- @param pitch The sound pitch as a percent from 0 to 255
9696
-- @param delta (Optinal) The transition time between the current pitch and the new one
9797
function sound_methods:setPitch(pitch, delta)
98-
if not SF.Permissions.check( SF.instance.player, this, "sound.modify" ) then return end
98+
if not SF.Permissions.check( SF.instance.player, this, "sound.modify" ) then SF.throw( "Insufficient permissions", 2 ) end
9999
SF.CheckType(self, sound_metamethods)
100100
SF.CheckType(pitch, "number")
101101
if delta then
@@ -108,7 +108,7 @@ end
108108
--- Sets the sound volume
109109
-- @param vol Volume as a percent between 0 and 1
110110
function sound_methods:setVolume(vol)
111-
if not SF.Permissions.check( SF.instance.player, this, "sound.modify" ) then return end
111+
if not SF.Permissions.check( SF.instance.player, this, "sound.modify" ) then SF.throw( "Insufficient permissions", 2 ) end
112112
SF.CheckType(self, sound_metamethods)
113113
SF.CheckType(vol, "number")
114114
unwrap(self):ChangeVolume(math.Clamp(vol,0,1))
@@ -119,7 +119,7 @@ end
119119
-- (use decibel value from the 'code' column, not the actual enum or 'value' column).
120120
-- @param level New level
121121
function sound_methods:setLevel(level)
122-
if not SF.Permissions.check( SF.instance.player, this, "sound.modify" ) then return end
122+
if not SF.Permissions.check( SF.instance.player, this, "sound.modify" ) then SF.throw( "Insufficient permissions", 2 ) end
123123
SF.CheckType(self, sound_metamethods)
124124
SF.CheckType(level, "number")
125125
unwrap(self):SetSoundLevel(math.Clamp(level, 0, 511))
@@ -128,7 +128,7 @@ end
128128
--- Stops or fades out the sound.
129129
-- @param fade (Optional) Time, in seconds, to fade out the sound. Not given = stop immediately
130130
function sound_methods:stop(fade)
131-
if not SF.Permissions.check( SF.instance.player, this, "sound.modify" ) then return end
131+
if not SF.Permissions.check( SF.instance.player, this, "sound.modify" ) then SF.throw( "Insufficient permissions", 2 ) end
132132
SF.CheckType(self, sound_metamethods)
133133
if fade then
134134
SF.CheckType(fade, "number")

lua/starfall/libs_sh/trace.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ end
234234
-- @param mask Trace mask
235235
-- @return Result of the trace
236236
function trace_library.trace(start,endpos,filter,mask)
237-
if not SF.Permissions.check( SF.instance.player, nil, "trace" ) then return end
237+
if not SF.Permissions.check( SF.instance.player, nil, "trace" ) then SF.throw( "Insufficient permissions", 2 ) end
238238
SF.CheckType(start,"Vector")
239239
SF.CheckType(endpos,"Vector")
240240
filter = convertFilter(SF.CheckType(filter,"table",0,{}))
@@ -259,7 +259,7 @@ end
259259
-- @param mask Trace mask
260260
-- @return Result of the trace
261261
function trace_library.traceHull(start,endpos,minbox,maxbox,filter,mask)
262-
if not SF.Permissions.check( SF.instance.player, nil, "trace" ) then return end
262+
if not SF.Permissions.check( SF.instance.player, nil, "trace" ) then SF.throw( "Insufficient permissions", 2 ) end
263263
SF.CheckType(start,"Vector")
264264
SF.CheckType(endpos,"Vector")
265265
SF.CheckType(minbox,"Vector")

lua/starfall/libs_sv/entities.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function ents_methods:parent ( ent )
145145
local ent = unwrap( ent )
146146
local this = unwrap( self )
147147

148-
if not SF.Permissions.check( SF.instance.player, { this, ent }, "entities.parent" ) then return end
148+
if not SF.Permissions.check( SF.instance.player, { this, ent }, "entities.parent" ) then SF.throw( "Insufficient permissions", 2 ) end
149149

150150
if not isValid( ent ) then return false, "entity not valid" end
151151
if not parent_check( this, ent ) then return false, "cannot parent to self" end
@@ -155,7 +155,7 @@ end
155155

156156
function ents_methods:unparent ()
157157
local this = unwrap(self)
158-
if not SF.Permissions.check( SF.instance.player, this, "entities.unparent" ) then return end
158+
if not SF.Permissions.check( SF.instance.player, this, "entities.unparent" ) then SF.throw( "Insufficient permissions", 2 ) end
159159
this:SetParent( nil )
160160
end
161161

@@ -172,7 +172,7 @@ function ents_methods:applyForceCenter(vec)
172172
local phys = getPhysObject(ent)
173173
if not phys then return false, "entity has no physics object" end
174174

175-
if not SF.Permissions.check( SF.instance.player, ent, "entities.applyForce" ) then return end
175+
if not SF.Permissions.check( SF.instance.player, ent, "entities.applyForce" ) then SF.throw( "Insufficient permissions", 2 ) end
176176

177177
phys:ApplyForceCenter( vec )
178178

@@ -193,7 +193,7 @@ function ents_methods:applyForceOffset(vec, offset)
193193
local phys = getPhysObject(ent)
194194
if not phys then return false, "entity has no physics object" end
195195

196-
if not SF.Permissions.check( SF.instance.player, ent, "entities.applyForce" ) then return end
196+
if not SF.Permissions.check( SF.instance.player, ent, "entities.applyForce" ) then SF.throw( "Insufficient permissions", 2 ) end
197197

198198
phys:ApplyForceOffset( vec, offset )
199199

@@ -212,7 +212,7 @@ function ents_methods:applyAngForce(ang)
212212
local phys = getPhysObject(ent)
213213
if not phys then return false, "entity has no physics object" end
214214

215-
if not SF.Permissions.check( SF.instance.player, ent, "entities.applyForce" ) then return end
215+
if not SF.Permissions.check( SF.instance.player, ent, "entities.applyForce" ) then SF.throw( "Insufficient permissions", 2 ) end
216216

217217
-- assign vectors
218218
local up = ent:GetUp()
@@ -255,7 +255,7 @@ function ents_methods:applyTorque(tq)
255255
local phys = getPhysObject(ent)
256256
if not phys then return false, "entity has no physics object" end
257257

258-
if not SF.Permissions.check( SF.instance.player, ent, "entities.applyForce" ) then return end
258+
if not SF.Permissions.check( SF.instance.player, ent, "entities.applyForce" ) then SF.throw( "Insufficient permissions", 2 ) end
259259

260260
local torqueamount = tq:Length()
261261

@@ -289,7 +289,7 @@ function ents_methods:setPos(vec)
289289
local ent = unwrap(self)
290290
if not isValid(ent) then return false, "entity not valid" end
291291

292-
if not SF.Permissions.check( SF.instance.player, ent, "entities.setPos" ) then return end
292+
if not SF.Permissions.check( SF.instance.player, ent, "entities.setPos" ) then SF.throw( "Insufficient permissions", 2 ) end
293293

294294
SF.setPos( ent, vec )
295295

@@ -305,7 +305,7 @@ function ents_methods:setAngles(ang)
305305
local ent = unwrap(self)
306306
if not isValid(ent) then return false, "entity not valid" end
307307

308-
if not SF.Permissions.check( SF.instance.player, ent, "entities.setAngles" ) then return end
308+
if not SF.Permissions.check( SF.instance.player, ent, "entities.setAngles" ) then SF.throw( "Insufficient permissions", 2 ) end
309309

310310
SF.setAng( ent, ang )
311311

@@ -323,7 +323,7 @@ function ents_methods:setVelocity(vel)
323323
local phys = getPhysObject(ent)
324324
if not phys then return false, "entity has no physics object" end
325325

326-
if not SF.Permissions.check( SF.instance.player, ent, "entities.setVelocity" ) then return end
326+
if not SF.Permissions.check( SF.instance.player, ent, "entities.setVelocity" ) then SF.throw( "Insufficient permissions", 2 ) end
327327

328328
phys:SetVelocity(vel)
329329
return true
@@ -339,7 +339,7 @@ function ents_methods:setFrozen(freeze)
339339
local phys = getPhysObject(ent)
340340
if not phys then return false, "entity has no physics object" end
341341

342-
if not SF.Permissions.check( SF.instance.player, ent, "entities.setFrozen" ) then return end
342+
if not SF.Permissions.check( SF.instance.player, ent, "entities.setFrozen" ) then SF.throw( "Insufficient permissions", 2 ) end
343343

344344
phys:EnableMotion(not (freeze and true or false))
345345
phys:Wake()
@@ -366,7 +366,7 @@ function ents_methods:setSolid ( solid )
366366
local ent = unwrap( self )
367367
if not isValid( ent ) then return false, "entity not valid" end
368368

369-
if not SF.Permissions.check( SF.instance.player, ent, "entities.setSolid" ) then return end
369+
if not SF.Permissions.check( SF.instance.player, ent, "entities.setSolid" ) then SF.throw( "Insufficient permissions", 2 ) end
370370

371371
ent:SetNotSolid( not solid )
372372
end
@@ -381,7 +381,7 @@ function ents_methods:enableGravity(grav)
381381
local phys = getPhysObject(ent)
382382
if not phys then return false, "entity has no physics object" end
383383

384-
if not SF.Permissions.check( SF.instance.player, ent, "entities.enableGravity" ) then return end
384+
if not SF.Permissions.check( SF.instance.player, ent, "entities.enableGravity" ) then SF.throw( "Insufficient permissions", 2 ) end
385385

386386
phys:EnableGravity(grav and true or false)
387387
phys:Wake()

lua/starfall/libs_sv/wire.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ end
203203
-- @param names An array of input names. May be modified by the function.
204204
-- @param types An array of input types. May be modified by the function.
205205
function wire_library.createInputs ( names, types )
206-
if not SF.Permissions.check( SF.instance.player, nil, "wire.setInputs" ) then return end
206+
if not SF.Permissions.check( SF.instance.player, nil, "wire.setInputs" ) then SF.throw( "Insufficient permissions", 2 ) end
207207
SF.CheckType(names,"table")
208208
SF.CheckType(types,"table")
209209
local ent = SF.instance.data.entity
@@ -230,7 +230,7 @@ end
230230
-- @param names An array of output names. May be modified by the function.
231231
-- @param types An array of output types. May be modified by the function.
232232
function wire_library.createOutputs ( names, types )
233-
if not SF.Permissions.check( SF.instance.player, nil, "wire.setOutputs" ) then return end
233+
if not SF.Permissions.check( SF.instance.player, nil, "wire.setOutputs" ) then SF.throw( "Insufficient permissions", 2 ) end
234234
SF.CheckType(names,"table")
235235
SF.CheckType(types,"table")
236236
local ent = SF.instance.data.entity
@@ -263,7 +263,7 @@ end
263263

264264
--- Retrieves an output. Returns nil if the output doesn't exist.
265265
wirelink_metatable.__index = function(self,k)
266-
if not SF.Permissions.check( SF.instance.player, nil, "wire.wirelink.read" ) then return end
266+
if not SF.Permissions.check( SF.instance.player, nil, "wire.wirelink.read" ) then SF.throw( "Insufficient permissions", 2 ) end
267267
SF.CheckType(self,wirelink_metatable)
268268
if wirelink_methods[k] then
269269
return wirelink_methods[k]
@@ -283,7 +283,7 @@ end
283283

284284
--- Writes to an input.
285285
wirelink_metatable.__newindex = function(self,k,v)
286-
if not SF.Permissions.check( SF.instance.player, nil, "wire.wirelink.write" ) then return end
286+
if not SF.Permissions.check( SF.instance.player, nil, "wire.wirelink.write" ) then SF.throw( "Insufficient permissions", 2 ) end
287287
SF.CheckType(self,wirelink_metatable)
288288
local wl = wlunwrap(self)
289289
if not wl or not wl:IsValid() or not wl.extended then return end -- TODO: What is wl.extended?
@@ -385,7 +385,7 @@ end
385385
local wire_ports_methods, wire_ports_metamethods = SF.Typedef("Ports")
386386

387387
function wire_ports_metamethods:__index ( name )
388-
if not SF.Permissions.check( SF.instance.player, nil, "wire.input" ) then return end
388+
if not SF.Permissions.check( SF.instance.player, nil, "wire.input" ) then SF.throw( "Insufficient permissions", 2 ) end
389389
SF.CheckType(name,"string")
390390
local instance = SF.instance
391391
local ent = instance.data.entity
@@ -399,7 +399,7 @@ function wire_ports_metamethods:__index ( name )
399399
end
400400

401401
function wire_ports_metamethods:__newindex ( name, value )
402-
if not SF.Permissions.check( SF.instance.player, nil, "wire.output" ) then return end
402+
if not SF.Permissions.check( SF.instance.player, nil, "wire.output" ) then SF.throw( "Insufficient permissions", 2 ) end
403403
SF.CheckType(name,"string")
404404
local instance = SF.instance
405405
local ent = instance.data.entity

0 commit comments

Comments
 (0)