Skip to content

Commit

Permalink
Proper IP getter. Skip check for registered accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed Apr 13, 2019
1 parent da6110d commit 846e184
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function ipnames.command_unignore(name, param)
return true, "Removed '" .. param .. "' from the name whitelist."
end

local player_auth_exists = minetest.player_exists
ipnames.is_registered = minetest.player_exists
or function(name)
-- 0.4.x support: If you get a nil error here -> update Minetest
return minetest.auth_table[name]
Expand All @@ -62,7 +62,7 @@ function ipnames.load_data()
local data = line:split("|")
if #data >= 2 then
-- Ignore players which were removed (according to auth)
local player_exists = player_auth_exists(data[1])
local player_exists = ipnames.is_registered(data[1])

if player_exists then
data[3] = tonumber(data[3]) or 0
Expand Down
26 changes: 13 additions & 13 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ end

ipnames = {}
ipnames.data = {}
ipnames.tmp_data = {}
ipnames.whitelist = {}
ipnames.changes = false
ipnames.save_time = 0
Expand Down Expand Up @@ -58,9 +57,7 @@ minetest.register_chatcommand("ipnames", {
-- Get IP if player tries to join, ban if there are too much names per IP
minetest.register_on_prejoinplayer(function(name, ip)
-- Only stop new accounts
ipnames.tmp_data[name] = ip

if ipnames.data[name] then
if ipnames.data[name] or ipnames.is_registered(name) then
return
end

Expand All @@ -76,7 +73,6 @@ minetest.register_on_prejoinplayer(function(name, ip)
end
-- Return error message if too many accounts have been created
if #names > ipnames.name_per_ip_limit + (count_bonus or 0) then
ipnames.tmp_data[name] = nil
return "\nYou exceeded the limit of accounts.\n" ..
"You already own the following accounts:\n" .. table.concat(names, ", ")
end
Expand All @@ -85,15 +81,19 @@ end)
-- Save IP if player joined
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
local t = os.time()
ipnames.data[name] = {ipnames.tmp_data[name], t}
ipnames.tmp_data[name] = nil
ipnames.changes = true
end)
local time = os.time()
local player_info = minetest.get_player_information(name)
if not player_info.address then
minetest.log("warning", "[names_per_ip] Failed to get the IP address for " ..
name .. ". This should not happen.")
end

ipnames.data[name] = {
player_info.address or "??",
time
}

-- Clean up garbage
minetest.register_on_leaveplayer(function(player)
ipnames.tmp_data[player:get_player_name()] = nil
ipnames.changes = true
end)

minetest.register_globalstep(function(t)
Expand Down

0 comments on commit 846e184

Please sign in to comment.