Proper IP getter. Skip check for registered accounts

This commit is contained in:
SmallJoker 2019-04-13 11:29:59 +02:00
parent da6110de50
commit 846e1848ea
2 changed files with 15 additions and 15 deletions

View File

@ -45,7 +45,7 @@ function ipnames.command_unignore(name, param)
return true, "Removed '" .. param .. "' from the name whitelist." return true, "Removed '" .. param .. "' from the name whitelist."
end end
local player_auth_exists = minetest.player_exists ipnames.is_registered = minetest.player_exists
or function(name) or function(name)
-- 0.4.x support: If you get a nil error here -> update Minetest -- 0.4.x support: If you get a nil error here -> update Minetest
return minetest.auth_table[name] return minetest.auth_table[name]
@ -62,7 +62,7 @@ function ipnames.load_data()
local data = line:split("|") local data = line:split("|")
if #data >= 2 then if #data >= 2 then
-- Ignore players which were removed (according to auth) -- 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 if player_exists then
data[3] = tonumber(data[3]) or 0 data[3] = tonumber(data[3]) or 0

View File

@ -8,7 +8,6 @@ end
ipnames = {} ipnames = {}
ipnames.data = {} ipnames.data = {}
ipnames.tmp_data = {}
ipnames.whitelist = {} ipnames.whitelist = {}
ipnames.changes = false ipnames.changes = false
ipnames.save_time = 0 ipnames.save_time = 0
@ -58,9 +57,7 @@ minetest.register_chatcommand("ipnames", {
-- Get IP if player tries to join, ban if there are too much names per IP -- Get IP if player tries to join, ban if there are too much names per IP
minetest.register_on_prejoinplayer(function(name, ip) minetest.register_on_prejoinplayer(function(name, ip)
-- Only stop new accounts -- Only stop new accounts
ipnames.tmp_data[name] = ip if ipnames.data[name] or ipnames.is_registered(name) then
if ipnames.data[name] then
return return
end end
@ -76,7 +73,6 @@ minetest.register_on_prejoinplayer(function(name, ip)
end end
-- Return error message if too many accounts have been created -- Return error message if too many accounts have been created
if #names > ipnames.name_per_ip_limit + (count_bonus or 0) then 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" .. return "\nYou exceeded the limit of accounts.\n" ..
"You already own the following accounts:\n" .. table.concat(names, ", ") "You already own the following accounts:\n" .. table.concat(names, ", ")
end end
@ -85,15 +81,19 @@ end)
-- Save IP if player joined -- Save IP if player joined
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
local t = os.time() local time = os.time()
ipnames.data[name] = {ipnames.tmp_data[name], t} local player_info = minetest.get_player_information(name)
ipnames.tmp_data[name] = nil if not player_info.address then
ipnames.changes = true minetest.log("warning", "[names_per_ip] Failed to get the IP address for " ..
end) name .. ". This should not happen.")
end
-- Clean up garbage ipnames.data[name] = {
minetest.register_on_leaveplayer(function(player) player_info.address or "??",
ipnames.tmp_data[player:get_player_name()] = nil time
}
ipnames.changes = true
end) end)
minetest.register_globalstep(function(t) minetest.register_globalstep(function(t)