Hi,
When i get kicked, the Server crashes instant any idea?
[CODE]
--Security, Checks Ranks
--Check if is a Server or not
if SERVER then
local function UserSpawn(ply)
if ply:IsUserGroup("owner") then
if tostring(ply:SteamID()) == "" then
return true
else
ply:Kick("Not allowed")
end
elseif ply:IsUserGroup("superadmin") then
if tostring(ply:SteamID()) == "" then
return true
else
ply:Kick("Not allowed")
end
end
end
hook.Add("PlayerSpawn", "security_check_spawn", function(...) UserSpawn(...) end)
end
[/CODE]
Why are you waiting until the user spawns before kicking them?
Use the CheckPassword hook.
Why are you using ..., it isn't necessary for what you're doing; simple do: hook.Add( "CheckPassword", "Unique Hook Identifier", UserSpawn );
By passing the reference to the function, the hook when called with use func_reference( arguments )... The only time where you may want to use a function( ... ) is if there are an unknown number of arguments.. Example, the new MsgC:
[code]//
// MsgC Helper Function to act more like print / chat.AddText - Josh 'Acecool' Moser
// -- Do as you want with this code ( This is now implemented into GMod ) --
//
if ( !__MSGC ) then __MSGC = MsgC; end
function MsgC( _color, _text, ... )
__MSGC( _color, _text );
local _tab = { ... };
if ( #_tab >= 2 ) then
return MsgC( ... );
end
return true;
end[/code]
The above code knows about the first two arguments, and passes it to the reference to the real MsgC function, then it shifts the arguments left, forgetting about the current set of 2 we used, if there are more arguments.
Also, why define a function at all in local namespace? Why not just define the function in the hook?
Example using a function in the hook as the function is only meant for this hook, uses CheckPassword instead of waiting until player spawns, and uses SteamID instead of group:
[code]// This should be in a SERVER file...
//
// Authorized users list
//
local AuthorizedUsers = { };
AuthorizedUsers[ "STEAM_0:1:4173055" ] = true;
//
// Add a CheckPassword hook to compare a joining user against an Authorized User list.
//
hook.Add( "CheckPassword", "Unique Hook Identifier", function( _steam64, _sv_password, _cl_password, _nick )
// Convert to 32 bit SteamID
local _steam = util.SteamIDFrom64( _steam64 );
// If the user isn't on the authorized list...
if ( !AuthorizedUsers[ _steam ] ) then
// Kick them
return false, "You are not authorized to join this server...";
end
end );[/code]
Because i need to get the Players Rank if he is allowed to have admin rights.
What the hell are you trying to achieve? That code makes no sense at all.
[QUOTE=JackBauerr;46075011]Because i need to get the Players Rank if he is allowed to have admin rights.[/QUOTE]
How about you fix the exploits in your server that enable people to make themselves admin instead?
Sorry, you need to Log In to post a reply to this thread.