Skip to content

Commit

Permalink
Builtin: Disallow registering users with the same name
Browse files Browse the repository at this point in the history
Prevents duplicate names: 'NickName', 'nickname', 'NICKNAME'.
Skips already registered users, so they can connect as usual.
  • Loading branch information
SmallJoker authored and paramat committed Aug 28, 2016
1 parent e10fee0 commit 51e13ae
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions builtin/game/auth.lua
Expand Up @@ -199,3 +199,19 @@ core.register_on_joinplayer(function(player)
record_login(player:get_player_name())
end)

core.register_on_prejoinplayer(function(name, ip)
local auth = core.auth_table
if auth[name] ~= nil then

This comment has been minimized.

Copy link
@sorcerykid

sorcerykid Dec 17, 2016

Contributor

Checking against nil in Lua is superfluous. The statement "if auth[name] then" would suffice.

This comment has been minimized.

Copy link
@paramat

paramat Dec 18, 2016

Contributor

if auth[name] is a bool then ~= nil means true or false, which is different behaviour to your suggestion.

This comment has been minimized.

Copy link
@SmallJoker

SmallJoker Dec 18, 2016

Author Member

I assume you meant if not auth[name] then, then it would have the same behaviour. The table value can not be false, otherwise the auth save function would throw an exception for not being a table.

This comment has been minimized.

Copy link
@sorcerykid

sorcerykid Dec 18, 2016

Contributor

I don't understand, how could "auth[name]" ever contain a boolean when the values of the "auth[]" table contain a table data type? I would think it highly unlikely that a user could inject true or false into auth[name], unless the server itself was compromised.

This comment has been minimized.

Copy link
@paramat

paramat Dec 19, 2016

Contributor

Sorry, auth[name] may not contain bools, i have no idea what it contains. I was replying to your statement 'Checking against nil in Lua is superfluous' as if it were a general statement.

return
end

local name_lower = name:lower()
for k in pairs(auth) do
if k:lower() == name_lower then
return string.format("\nCannot create new player called '%s'. "..
"Another account called '%s' is already registered. "..
"Please check the spelling if it's your account "..
"or use a different nickname.", name, k)
end
end
end)

0 comments on commit 51e13ae

Please sign in to comment.