forked from mff/names_per_ip
Proper IP getter. Skip check for registered accounts
This commit is contained in:
parent
da6110de50
commit
846e1848ea
|
@ -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]
|
||||
|
@ -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
|
||||
|
|
26
init.lua
26
init.lua
|
@ -8,7 +8,6 @@ end
|
|||
|
||||
ipnames = {}
|
||||
ipnames.data = {}
|
||||
ipnames.tmp_data = {}
|
||||
ipnames.whitelist = {}
|
||||
ipnames.changes = false
|
||||
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
|
||||
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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
-- Clean up garbage
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
ipnames.tmp_data[player:get_player_name()] = nil
|
||||
ipnames.data[name] = {
|
||||
player_info.address or "??",
|
||||
time
|
||||
}
|
||||
|
||||
ipnames.changes = true
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(t)
|
||||
|
|
Loading…
Reference in New Issue
Block a user