Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basically Everything Overhaul ( libs and perms ) #398

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lua/starfall/libraries/angle/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name" : "angle",
"description" : "Adds Angle type",
"version" : "INP"
}
5 changes: 5 additions & 0 deletions lua/starfall/libraries/bit/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name" : "bit",
"description" : "Bitwise operations library",
"version" : "INP"
}
File renamed without changes.
5 changes: 5 additions & 0 deletions lua/starfall/libraries/builtin/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name" : "builtin",
"description" : "Adds builtin functions and variables",
"version" : "INP"
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function SF.DefaultEnvironment.require (file)
loaded = {}
SF.instance.data.reqloaded = loaded
end

if loaded[ file ] then
return loaded[ file ]
else
Expand Down Expand Up @@ -285,12 +285,12 @@ end
-- @return Function of str
function SF.DefaultEnvironment.loadstring ( str )
local func = CompileString( str, "SF: " .. tostring( SF.instance.env ), false )

-- CompileString returns an error as a string, better check before setfenv
if type( func ) == "function" then
return setfenv( func, SF.instance.env )
end

return func
end

Expand Down
5 changes: 5 additions & 0 deletions lua/starfall/libraries/color/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name" : "color",
"description" : "Adds Color type",
"version" : "INP"
}
File renamed without changes.
5 changes: 5 additions & 0 deletions lua/starfall/libraries/coroutine/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name" : "coroutine",
"description" : "Coroutine library",
"version" : "INP"
}
6 changes: 6 additions & 0 deletions lua/starfall/libraries/entity/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name" : "entity",
"description" : "Entity library",
"dependencies" : [ "angle", "color", "vector" ],
"version" : "INP"
}
104 changes: 104 additions & 0 deletions lua/starfall/libraries/entity/permissions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"entity" : {
"description" : "Grants access to all entity permissions",
"children" : {
"setColor" : {
"description" : "Allows the user to change the color of an entity",
"children" : {
"self" : { "default" : true },
"buddy" : { "default" : true },
"other" : { "default" : "owner" }
}
},
"setSubMaterial" : {
"description" : "Allows the user to change the subMaterial of an entity",
"children" : {
"self" : { "default" : true },
"buddy" : { "default" : true },
"other" : { "default" : "owner" }
}
},
"parent" : {
"description" : "Allows the user to set the parent of an entity",
"locale" : "server",
"children" : {
"self" : { "default" : true },
"buddy" : { "default" : true },
"other" : { "default" : "owner" }
}
},
"unparent" : {
"description" : "Allows the user to remove the parent of an entity",
"locale" : "server",
"children" : {
"self" : { "default" : true },
"buddy" : { "default" : true },
"other" : { "default" : "owner" }
}
},
"applyForce" : {
"description" : "Allows the user to apply force to an entity",
"locale" : "server",
"children" : {
"self" : { "default" : true },
"buddy" : { "default" : true },
"other" : { "default" : "owner" }
}
},
"setPos" : {
"description" : "Allows the user to set the position of an entity",
"locale" : "server",
"children" : {
"self" : { "default" : true },
"buddy" : { "default" : true },
"other" : { "default" : "owner" }
}
},
"setAngles" : {
"description" : "Allows the user to set the angles of an entity",
"locale" : "server",
"children" : {
"self" : { "default" : true },
"buddy" : { "default" : true },
"other" : { "default" : "owner" }
}
},
"setVelocity" : {
"description" : "Allows the user to set the velocity of an entity",
"locale" : "server",
"children" : {
"self" : { "default" : true },
"buddy" : { "default" : true },
"other" : { "default" : "owner" }
}
},
"setFrozen" : {
"description" : "Allows the user to (un)freeze an entity",
"locale" : "server",
"children" : {
"self" : { "default" : true },
"buddy" : { "default" : true },
"other" : { "default" : "owner" }
}
},
"setSolid" : {
"description" : "Allows the user to set the solidity of an entity",
"locale" : "server",
"children" : {
"self" : { "default" : true },
"buddy" : { "default" : true },
"other" : { "default" : "owner" }
}
},
"enableGravity" : {
"description" : "Allows the user to change whether an entity is affected by gravity",
"locale" : "server",
"children" : {
"self" : { "default" : true },
"buddy" : { "default" : true },
"other" : { "default" : "owner" }
}
}
}
}
}
45 changes: 45 additions & 0 deletions lua/starfall/libraries/entity/permissions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
local P = {}

local canTool = {
[ "entities.parent" ] = true,
[ "entities.unparent" ] = true,
[ "entities.setSolid" ] = true,
[ "entities.enableGravity" ] = true,
[ "entities.setColor" ] = true,
[ "entities.setSubMaterial" ] = true
}

local canPhysgun = {
[ "entities.applyForce" ] = true,
[ "entities.setPos" ] = true,
[ "entities.setAngles" ] = true,
[ "entities.setVelocity" ] = true,
[ "entities.setFrozen" ] = true
}

local function check ( player, node, entity )
if entity:GetOwner() == player then
return SF.Permissions.hasNode( player, node .. ".self" )
elseif CPPI then
if ( canTool[ node ] and entity:CPPICanTool( player, "starfall_ent_lib" ) ) or ( canPhysgun[ node ] and entity:CPPICanPhysgun( player ) ) then
return SF.Permissions.hasNode( player, node .. ".buddy" )
end
end

return SF.Permissions.hasNode( player, node .. ".other" )
end

function P.check ( player, node, entities )
if type( entities ) == "table" then
for k, v in pairs( entities ) do
if not check( player, node, v ) then
return false
end
end
return true
end

return check( player, node, entities )
end

SF.Permissions.registerProvider( P )
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@ local ents_methods = SF.Entities.Methods
local wrap, unwrap = SF.Entities.Wrap, SF.Entities.Unwrap
local vunwrap = SF.UnwrapObject

-- Register privileges
do
local P = SF.Permissions
P.registerPrivilege( "entities.parent", "Parent", "Allows the user to parent an entity to another entity" )
P.registerPrivilege( "entities.unparent", "Unparent", "Allows the user to remove the parent of an entity" ) -- TODO: maybe merge with entities.parent?
P.registerPrivilege( "entities.applyForce", "Apply force", "Allows the user to apply force to an entity" )
P.registerPrivilege( "entities.setPos", "Set Position", "Allows the user to teleport an entity to another location" )
P.registerPrivilege( "entities.setAngles", "Set Angles", "Allows the user to teleport an entity to another orientation" )
P.registerPrivilege( "entities.setVelocity", "Set Velocity", "Allows the user to change the velocity of an entity" )
P.registerPrivilege( "entities.setFrozen", "Set Frozen", "Allows the user to freeze and unfreeze an entity" )
P.registerPrivilege( "entities.setSolid", "Set Solid", "Allows the user to change the solidity of an entity" )
P.registerPrivilege( "entities.enableGravity", "Enable gravity", "Allows the user to change whether an entity is affected by gravity" )
end

local function fix_nan ( v )
if v < huge and v > -huge then return v else return 0 end
end
Expand Down Expand Up @@ -141,7 +127,7 @@ function ents_methods:setParent ( ent )
local ent = unwrap( ent )
local this = unwrap( self )

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

if not isValid( ent ) then return false, "entity not valid" end
if not parent_check( this, ent ) then return false, "cannot parent to self" end
Expand All @@ -151,7 +137,7 @@ end

function ents_methods:unparent ()
local this = unwrap( self )
if not SF.Permissions.check( SF.instance.player, this, "entities.unparent" ) then SF.throw( "Insufficient permissions", 2 ) end
if not SF.Permissions.check( SF.instance.player, "entity.unparent", this ) then SF.throw( "Insufficient permissions", 2 ) end
this:SetParent( nil )
end

Expand All @@ -169,7 +155,7 @@ function ents_methods:applyForceCenter ( vec )
local phys = getPhysObject( ent )
if not phys then return false, "entity has no physics object" end

if not SF.Permissions.check( SF.instance.player, ent, "entities.applyForce" ) then SF.throw( "Insufficient permissions", 2 ) end
if not SF.Permissions.check( SF.instance.player, "entity.applyForce", ent ) then SF.throw( "Insufficient permissions", 2 ) end

phys:ApplyForceCenter( vec )

Expand All @@ -194,7 +180,7 @@ function ents_methods:applyForceOffset ( vec, offset )
local phys = getPhysObject( ent )
if not phys then return false, "entity has no physics object" end

if not SF.Permissions.check( SF.instance.player, ent, "entities.applyForce" ) then SF.throw( "Insufficient permissions", 2 ) end
if not SF.Permissions.check( SF.instance.player, "entity.applyForce", ent ) then SF.throw( "Insufficient permissions", 2 ) end

phys:ApplyForceOffset( vec, offset )

Expand All @@ -214,7 +200,7 @@ function ents_methods:applyAngForce ( ang )
local phys = getPhysObject( ent )
if not phys then return false, "entity has no physics object" end

if not SF.Permissions.check( SF.instance.player, ent, "entities.applyForce" ) then SF.throw( "Insufficient permissions", 2 ) end
if not SF.Permissions.check( SF.instance.player, "entity.applyForce", ent ) then SF.throw( "Insufficient permissions", 2 ) end

-- assign vectors
local up = ent:GetUp()
Expand Down Expand Up @@ -259,7 +245,7 @@ function ents_methods:applyTorque ( tq )
local phys = getPhysObject( ent )
if not phys then return false, "entity has no physics object" end

if not SF.Permissions.check( SF.instance.player, ent, "entities.applyForce" ) then SF.throw( "Insufficient permissions", 2 ) end
if not SF.Permissions.check( SF.instance.player, "entity.applyForce", ent ) then SF.throw( "Insufficient permissions", 2 ) end

local torqueamount = tq:Length()

Expand Down Expand Up @@ -294,7 +280,7 @@ function ents_methods:setPos ( vec )
local ent = unwrap( self )
if not isValid( ent ) then return false, "entity not valid" end

if not SF.Permissions.check( SF.instance.player, ent, "entities.setPos" ) then SF.throw( "Insufficient permissions", 2 ) end
if not SF.Permissions.check( SF.instance.player, "entity.setPos", ent ) then SF.throw( "Insufficient permissions", 2 ) end

SF.setPos( ent, vec )

Expand All @@ -311,7 +297,7 @@ function ents_methods:setAngles ( ang )
local ent = unwrap( self )
if not isValid( ent ) then return false, "entity not valid" end

if not SF.Permissions.check( SF.instance.player, ent, "entities.setAngles" ) then SF.throw( "Insufficient permissions", 2 ) end
if not SF.Permissions.check( SF.instance.player, "entity.setAngles", ent ) then SF.throw( "Insufficient permissions", 2 ) end

SF.setAng( ent, ang )

Expand All @@ -331,7 +317,7 @@ function ents_methods:setVelocity ( vel )
local phys = getPhysObject( ent )
if not phys then return false, "entity has no physics object" end

if not SF.Permissions.check( SF.instance.player, ent, "entities.setVelocity" ) then SF.throw( "Insufficient permissions", 2 ) end
if not SF.Permissions.check( SF.instance.player, "entity.setVelocity", ent ) then SF.throw( "Insufficient permissions", 2 ) end

phys:SetVelocity( vel )
return true
Expand All @@ -347,7 +333,7 @@ function ents_methods:setFrozen ( freeze )
local phys = getPhysObject( ent )
if not phys then return false, "entity has no physics object" end

if not SF.Permissions.check( SF.instance.player, ent, "entities.setFrozen" ) then SF.throw( "Insufficient permissions", 2 ) end
if not SF.Permissions.check( SF.instance.player, "entity.setFrozen", ent ) then SF.throw( "Insufficient permissions", 2 ) end

phys:EnableMotion( not ( freeze and true or false ) )
phys:Wake()
Expand All @@ -374,7 +360,7 @@ function ents_methods:setSolid ( solid )
local ent = unwrap( self )
if not isValid( ent ) then return false, "entity not valid" end

if not SF.Permissions.check( SF.instance.player, ent, "entities.setSolid" ) then SF.throw( "Insufficient permissions", 2 ) end
if not SF.Permissions.check( SF.instance.player, "entity.setSolid", ent ) then SF.throw( "Insufficient permissions", 2 ) end

ent:SetNotSolid( not solid )
end
Expand All @@ -389,7 +375,7 @@ function ents_methods:enableGravity ( grav )
local phys = getPhysObject( ent )
if not phys then return false, "entity has no physics object" end

if not SF.Permissions.check( SF.instance.player, ent, "entities.enableGravity" ) then SF.throw( "Insufficient permissions", 2 ) end
if not SF.Permissions.check( SF.instance.player, "entity.enableGravity", ent ) then SF.throw( "Insufficient permissions", 2 ) end

phys:EnableGravity( grav and true or false )
phys:Wake()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ local vwrap, vunwrap = SF.WrapObject, SF.UnwrapObject
-- @shared
local ents_lib, _ = SF.Libraries.Register( "entities" )

-- Register privileges
do
local P = SF.Permissions
P.registerPrivilege( "entities.setColor", "Set Color", "Allows the user to change the color of an entity" )
P.registerPrivilege( "entities.setSubMaterial", "Set SubMaterial", "Allows the user to change a specific SubMaterial of an entity" )
end

local materialBlacklist = {
[ "pp/copy" ] = true
}
Expand Down Expand Up @@ -107,7 +100,7 @@ function ents_methods:setColor ( clr )

local this = unwrap( self )
if IsValid( this ) then
if not SF.Permissions.check( SF.instance.player, this, "entities.setColor" ) then return end
if not SF.Permissions.check( SF.instance.player, "entity.setColor", this ) then return end
this:SetColor( clr )
this:SetRenderMode( clr.a == 255 and RENDERMODE_NORMAL or RENDERMODE_TRANSALPHA )
end
Expand Down Expand Up @@ -401,7 +394,7 @@ function ents_methods:setSubMaterial ( ind, mat )
local ent = unwrap( self )
if not isValid( ent ) then return nil, "invalid entity" end

if not SF.Permissions.check( SF.instance.player, ent, "entities.setSubMaterial" ) then return end
if not SF.Permissions.check( SF.instance.player, "entities.setSubMaterial", ent ) then return end
if materialBlacklist[ mat ] then SF.throw( "Material: " .. ( mat or "" ) .. " is blacklisted!", 2 ) end

ent:SetSubMaterial( ind and ind - 1 or nil, mat )
Expand Down
5 changes: 5 additions & 0 deletions lua/starfall/libraries/fastlz/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name" : "fastlz",
"description" : "FastLZ library",
"version" : "INP"
}
5 changes: 5 additions & 0 deletions lua/starfall/libraries/file/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name" : "file",
"description" : "File functions. Allows modification of files.",
"version" : "INP"
}
Loading