GM:CheckPassword

From Garry's Mod
Jump to: navigation, search
 GM:CheckPassword( )

Contents

Description

Called when a non local player connects to allow the Lua system to check the password.

The default behaviour in the base gamemodes emulates what would normally happen. If sv_password is set and its value matches the password passed in by the client - then they are allowed to join. If it isn't set it lets them in too.

Arguments

string steamID64

The 64bit Steam ID of the joining player, use util.SteamIDFrom64 to convert it to a "STEAM_0:" one.

Arguments

string ipAddress

The IP of the connecting client

Arguments

string svPassword

The current value of sv_password (the password set by the server)

Arguments

string clPassword

The password provided by the client

Arguments

string name

The name of the joining player

Returns

boolean

If the hook returns false then the player is disconnected

Returns

string

If returning false in the first argument, then this should be the disconnect message. This will default to "#GameUI_ServerRejectBadPassword", which is "Bad Password." translated to the client's language.

Examples

Example

A user access whitelist to the server

Available pre-defined messages can be found in ../sourceengine/resource/gameui_english.txt files.

Suggested messages are #GameUI_ConnectionFailed and #GameUI_ServerRejectLANRestrict

local allowed = {
	["76561198012345678"] = true, -- Me
	["76561198123456789"] = true, -- Friend #1
	["76561198234567890"] = true, -- Friend #2
}

hook.Add( "CheckPassword", "access_whitelist", function( steamID64 )
	if not allowed[steamID64] then
		return false, "#GameUI_ServerRejectLANRestrict"
	end
end )


Personal tools
Navigation