Garry's Mod Wiki

Revision Difference

GM:CheckPassword#517829

<function name="CheckPassword" parent="GM" type="hook"> <ishook>yes</ishook> <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. </description> <realm>Server</realm> <predicted>No</predicted> <args> <arg name="steamID64" type="string">The 64bit Steam ID of the joining player, use &lt;page&gt;util.SteamIDFrom64&lt;/page&gt; to convert it to a &quot;STEAM_0:&quot; one.</arg> <arg name="steamID64" type="string">The 64bit Steam ID of the joining player, use <page>util.SteamIDFrom64</page> to convert it to a "STEAM_0:" one.</arg> <arg name="ipAddress" type="string">The IP of the connecting client</arg> <arg name="svPassword" type="string">The current value of sv_password (the password set by the server)</arg> <arg name="clPassword" type="string">The password provided by the client</arg> <arg name="name" type="string">The name of the joining player</arg> </args> <rets> <ret name="" type="boolean">If the hook returns false then the player is disconnected</ret> <ret name="" type="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.</ret> </rets> </function> <example> <description> 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` </description> <code> 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 ) </code> </example>