Hey guys.
I want to make reserved slots on my server, and i need to kick someone before he gets authenticating otherwise my server crashes with a weird message.
I've tried gatekeeper, but i think that its not compatible with gmod 13.
anyone got a good idea how to kick the player?
Return false in this hook: [url]http://wiki.garrysmod.com/page/GM/CheckPassword[/url]
That's the first one called when a player connects.
[QUOTE=ms333;46422134]Return false in this hook: [url]http://wiki.garrysmod.com/page/GM/CheckPassword[/url]
That's the first one called when a player connects.[/QUOTE]
is there anyway of inputting a reason?
[code]
return false, "reason"
[/code]
can i check someones usergroup with thier steamid?
Depends on which admin mod you're using.
ulx, i'll guess its on the mysq lite db?
[QUOTE=tzahush;46422377]ulx, i'll guess its on the mysq lite db?[/QUOTE]
ok so i found the way of getting it, but how do i convert steamid to uniqueid?
[QUOTE=tzahush;46422762]ok so i found the way of getting it, but how do i convert steamid to uniqueid?[/QUOTE]
[code]
util.CRC("gm_" .. ply:SteamID() .. "_gm")
[/code]
Just remember that doing that calculation is relatively expensive. The wiki says:
[quote=http://gmod-wiki.tk/indexe82b.html?title=Player.UniqueID]
This function is relatively slow. Don't call it too many times per a frame and don't use it in big loops.
[/quote]
[QUOTE=tzahush;46422762]ok so i found the way of getting it, but how do i convert steamid to uniqueid?[/QUOTE]
This is how it's done internally pretty much, mind you that this requires the actual steamid ( STEAM_0:1:242whatever ), the one from the checkpassword hook is in 64bits ( 7634535 etc etc ) .
[lua]
local thesteamid = util.SteamIDFrom64( thesteamidfromthehook )
local uniqueid = util.CRC( "gm_"..thesteamid.."_gm" )
[/lua]
Ok so i got a mysql database full of my users, and i'm doing the following thing:
[QUOTE]local db = mysqloo.connect(HOST, USER, PASS, NAME, PORT)
db:connect()
local function CheckPassword(steamid)
local thesteamid = util.SteamIDFrom64( steamid )
local q = db:query("SELECT `group` FROM `users` WHERE `steamid`= '" .. thesteamid.. "'")
q:start()
function q:onSuccess(data)
print("in the Q!")
group = data[1].group
print(group)
return false, "test!";
end
end[/QUOTE]
I'll guess that it takes a while until the function "onsuccess" is established, so someone else got another idea on how to make it quicker?
[QUOTE=tzahush;46423589]Ok so i got a mysql database full of my users, and i'm doing the following thing:
I'll guess that it takes a while until the function "onsuccess" is established, so someone else got another idea on how to make it quicker?[/QUOTE]
Cache your list of users locally?
This should work better than what you're doing.
[lua]
local allowedGroups = {
superadmin = true,
admin = true,
donator = true,
}
local reservedSlots = 5
hook.Add("CheckPassword", "", function(id)
local id = util.SteamIDFrom64(id)
if (not allowedGroups[ULib.ucl.users[id].group]) and #player.GetAll() >= (game.MaxPlayers() - reservedSlots) then
return false, "Server full, donate to use the reserved slots."
end
end)
[/lua]
It allows multiple groups to access the reserved slots and allows configurable reserved slots. It also doesn't require you to mess with DB queries.
Untested but should work.
Beware, database queries might finish after the CheckPassword hook has expired. If you find that it doesn't work, cache the table in Lua or something
[QUOTE=Jvs;46422789]This is how it's done internally pretty much, mind you that this requires the actual steamid ( STEAM_0:1:242whatever ), the one from the checkpassword hook is in 64bits ( 7634535 etc etc ) .
[lua]
local thesteamid = util.SteamIDFrom64( thesteamidfromthehook )
local uniqueid = util.CRC( "gm_"..thesteamid.."_gm" )
[/lua][/QUOTE]
Why doesn't it check if it already CRC'd something?
like:
[code]
local ocrc = util.CRC
local didcrc = {}
function util.CRC( str )
if ( didcrc[str] ) then return didcrc[str] end
local crc = ocrc( str )
didcrc[str] = crc
return crc
end
[/code]
Since when is crc32 relatively expensive anyway? Especially on small strings like the steam ID.
The speed of CRC32 isn't the biggest issue though. The fact that it's a one-way hash and it has a high chance of [url=http://preshing.com/20110504/hash-collision-probabilities]hash collisions[/url] make it a bad choice.
[QUOTE=mcd1992;46433997]The speed of CRC32 isn't the biggest issue though. The fact that it's a one-way hash and it has a high chance of [url=http://preshing.com/20110504/hash-collision-probabilities]hash collisions[/url] make it a bad choice.[/QUOTE]
This is quite worrying :/ I just migrated everything to steamid64 last night after seeing that.
I had about 190k rows and I'm pretty sure it has had collisions already.. :(
Sorry, you need to Log In to post a reply to this thread.