forked from mff/names_per_ip
Compare commits
10 Commits
9d777bbb06
...
master
Author | SHA1 | Date | |
---|---|---|---|
563b8a6c5c | |||
08bf5f9c52 | |||
6737210d5d | |||
3530fa9277 | |||
7f99133a17 | |||
c2648b829b | |||
9c0142f767 | |||
12284b5ea4 | |||
d17ecc5436 | |||
680c0b3743 |
52
init.lua
52
init.lua
@ -10,12 +10,11 @@ ipnames = {}
|
|||||||
ipnames.data = {}
|
ipnames.data = {}
|
||||||
ipnames.whitelist = {}
|
ipnames.whitelist = {}
|
||||||
ipnames.changes = false
|
ipnames.changes = false
|
||||||
ipnames.save_time = 0
|
|
||||||
ipnames.file = minetest.get_worldpath().."/ipnames.data"
|
ipnames.file = minetest.get_worldpath().."/ipnames.data"
|
||||||
ipnames.whitelist_file = minetest.get_worldpath().."/ipnames_whitelist.data"
|
ipnames.whitelist_file = minetest.get_worldpath().."/ipnames_whitelist.data"
|
||||||
|
|
||||||
-- Limit 2 = maximal 2 accounts, the 3rd under the same IP gets blocked
|
-- Limit 2 = maximal 2 accounts, the 3rd under the same IP gets blocked
|
||||||
ipnames.name_per_ip_limit = tonumber(minetest.setting_get("max_names_per_ip")) or 2
|
ipnames.name_per_ip_limit = tonumber(minetest.settings:get("max_names_per_ip")) or 2
|
||||||
-- 2 + 3 = 5 accounts as limit for "ignored" players
|
-- 2 + 3 = 5 accounts as limit for "ignored" players
|
||||||
ipnames.extended_limit = 3
|
ipnames.extended_limit = 3
|
||||||
|
|
||||||
@ -71,6 +70,7 @@ minetest.register_on_prejoinplayer(function(name, ip)
|
|||||||
names[#names + 1] = k
|
names[#names + 1] = k
|
||||||
end
|
end
|
||||||
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
|
||||||
return "\nYou exceeded the limit of accounts.\n" ..
|
return "\nYou exceeded the limit of accounts.\n" ..
|
||||||
@ -79,35 +79,45 @@ minetest.register_on_prejoinplayer(function(name, ip)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
-- Save IP if player joined
|
-- Save IP if player joined
|
||||||
minetest.register_on_joinplayer(function(player)
|
local function update_player_address(name, recursive)
|
||||||
local name = player:get_player_name()
|
local info = minetest.get_player_information(name)
|
||||||
local time = os.time()
|
local address = info and info.address
|
||||||
local player_info = minetest.get_player_information(name)
|
|
||||||
if not player_info.address then
|
if not address then
|
||||||
minetest.log("warning", "[names_per_ip] Failed to get the IP address for " ..
|
minetest.log("warning", "[names_per_ip] minetest.get_player_information(\"" ..
|
||||||
name .. ". This should not happen.")
|
name .. "\"): " .. dump(info) .. ". This is probably an engine bug.")
|
||||||
|
if not recursive then
|
||||||
|
-- Delay, hope it works next time
|
||||||
|
minetest.after(0.5, update_player_address, name, true)
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ipnames.data[name] = {
|
ipnames.data[name] = {
|
||||||
player_info.address or "??",
|
address or "??",
|
||||||
time
|
os.time()
|
||||||
}
|
}
|
||||||
|
|
||||||
ipnames.changes = true
|
ipnames.changes = true
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
update_player_address(player:get_player_name())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_globalstep(function(t)
|
-- Data saving routine
|
||||||
ipnames.save_time = ipnames.save_time + t
|
-- Save changes at a fixed interval
|
||||||
if ipnames.save_time < ipnames.save_interval then
|
local function save_data_job()
|
||||||
return
|
|
||||||
end
|
|
||||||
ipnames.save_time = 0
|
|
||||||
ipnames.save_data()
|
ipnames.save_data()
|
||||||
end)
|
minetest.after(ipnames.save_interval, save_data_job)
|
||||||
|
end
|
||||||
|
minetest.after(ipnames.save_interval, save_data_job)
|
||||||
minetest.register_on_shutdown(ipnames.save_data)
|
minetest.register_on_shutdown(ipnames.save_data)
|
||||||
|
|
||||||
minetest.after(3, ipnames.load_data)
|
-- Due to use of minetest.player_exists, the data loading must be delayed
|
||||||
minetest.after(3, ipnames.load_whitelist)
|
-- until ServerEnvironment is set up. register_on_mods_loaded is still too early.
|
||||||
|
minetest.after(0, ipnames.load_data)
|
||||||
|
|
||||||
|
ipnames.load_whitelist()
|
||||||
|
|
||||||
minetest.log("action", "[names_per_ip] loaded.")
|
minetest.log("action", "[names_per_ip] loaded.")
|
||||||
|
Reference in New Issue
Block a user