roaddog Posted April 2, 2015 Posted April 2, 2015 So I use this useful function CallServerFunction server: -- Always, always, always, (always) use a list of allowed servers functions. -- Otherwise hackers can call any function and destroy your server. allowedFunctions = { ["isPlayerInACL"]=true } function callServerFunction(funcname, ...) if not allowedFunctions[funcname] then -- Protect server from abuse outputServerLog( "SECURITY: " .. tostring(getPlayerName(client)) .. " tried to use function " .. tostring(funcname) ) return end local arg = { ... } if (arg[1]) then for key, value in next, arg do arg[key] = tonumber(value) or value end end loadstring("return "..funcname)()(unpack(arg)) end addEvent("onClientCallsServerFunction", true) addEventHandler("onClientCallsServerFunction", resourceRoot , callServerFunction) client: function callServerFunction(funcname, ...) local arg = { ... } if (arg[1]) then for key, value in next, arg do if (type(value) == "number") then arg[key] = tostring(value) end end end -- If the serverside event handler is not in the same resource, replace 'resourceRoot' with the appropriate element triggerServerEvent("onClientCallsServerFunction", resourceRoot , funcname, unpack(arg)) end My function: ---Client function isPlayerStaff ( p ) local p = p or getLocalPlayer() if ( p and getElementType ( p ) == 'player' ) then if ( callServerFunction("isPlayerInACL", p, "Level 1" ) ) then return true end return false end end --Server function isPlayerInACL ( player, acl ) local account = getPlayerAccount ( player ) if ( isGuestAccount ( account ) ) then return false end return isObjectInACLGroup ( "user."..getAccountName ( account ), aclGetGroup ( acl ) ) end This code returns nothing. I don't know why but it should return true @isPlayerInACL.
JR10 Posted April 2, 2015 Posted April 2, 2015 The function just calls the server function, it can't return the anything. Just use events to check serverside.
Buffalo Posted April 2, 2015 Posted April 2, 2015 function isPlayerStaff ( p ) will always return true You can not check this way, you must callServerFunction and then callback callClientFunction with an answer.
roaddog Posted April 2, 2015 Author Posted April 2, 2015 function isPlayerStaff ( p ) will always return true no its not, It returned false, I have checked several times. what should I get from this line loadstring("return "..funcname)()(unpack(arg)) ?
Buffalo Posted April 2, 2015 Posted April 2, 2015 The point is, it will stay returning what it returns. Well loadstring loads a function and its arguements from string provided. Thats the scheme how its done Client (callServerFunction('checkACL',....)) -> server (check some things and let's return with callClientFunction('asnwerACL',....)) -> Client
Sasu Posted April 2, 2015 Posted April 2, 2015 function isPlayerStaff ( p ) will always return trueYou can not check this way, you must callServerFunction and then callback callClientFunction with an answer. No, it will always returns false because the function callServerFunction doesn't return anything -> nil
JR10 Posted April 3, 2015 Posted April 3, 2015 isPlayerStaff will either return nil (won't return anything in fact) or return false, because callServerFunction will always return nil, so the check will fail and end up returning false. If the first check fails, it will return nil.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now