2014-07-16 11:55:37 +02:00
|
|
|
-- Created by Krock to stop mass-account-creators
|
|
|
|
-- License: WTFPL
|
|
|
|
ipnames = {}
|
|
|
|
ipnames.data = {}
|
|
|
|
ipnames.tmp_data = {}
|
2014-08-16 09:39:55 +02:00
|
|
|
ipnames.whitelist = {}
|
2014-07-16 11:55:37 +02:00
|
|
|
ipnames.changes = false
|
|
|
|
ipnames.save_time = 0
|
|
|
|
ipnames.file = minetest.get_worldpath().."/ipnames.data"
|
2014-08-16 09:39:55 +02:00
|
|
|
ipnames.whitelist_file = minetest.get_worldpath().."/ipnames_whitelist.data"
|
|
|
|
|
|
|
|
-- Limit 2 = maximal 2 accounts, the 3rd under the same IP gets blocked
|
2014-08-16 11:21:48 +02:00
|
|
|
ipnames.name_per_ip_limit = tonumber(minetest.setting_get("max_names_per_ip")) or 2
|
2014-08-16 11:32:44 +02:00
|
|
|
-- 2 + 2 = 4 accounts as limit for "ignored" players
|
|
|
|
ipnames.extended_limit = 2
|
2014-08-16 09:39:55 +02:00
|
|
|
|
|
|
|
-- Interval where the IP list gets saved/updated
|
|
|
|
ipnames.save_interval = 240
|
2014-07-16 11:55:37 +02:00
|
|
|
|
2014-08-16 09:39:55 +02:00
|
|
|
dofile(minetest.get_modpath("names_per_ip").."/functions.lua")
|
2014-07-16 11:55:37 +02:00
|
|
|
|
2014-08-16 09:39:55 +02:00
|
|
|
minetest.register_chatcommand("ipnames", {
|
|
|
|
description = "Get the features of names_per_ip",
|
2014-07-16 11:55:37 +02:00
|
|
|
privs = {ban=true},
|
|
|
|
func = function(name, param)
|
2014-08-16 09:39:55 +02:00
|
|
|
if param == "" then
|
|
|
|
minetest.chat_send_player(name, "Available commands: ")
|
|
|
|
minetest.chat_send_player(name, "Get all accounts of <name>: /ipnames whois <name>")
|
|
|
|
minetest.chat_send_player(name, "List all exceptions: /ipnames list")
|
|
|
|
minetest.chat_send_player(name, "Remove/add an exception: /ipnames (un)ignore <name>")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if param == "list" then
|
|
|
|
ipnames.command_list(name)
|
2014-07-16 11:55:37 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-08-16 09:39:55 +02:00
|
|
|
local args = param:split(" ")
|
|
|
|
if #args < 2 then
|
|
|
|
minetest.chat_send_player(name, "Error: Please check again '/ipnames' for correct usage.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if args[1] == "whois" then
|
|
|
|
ipnames.command_whois(name, args[2])
|
|
|
|
elseif args[1] == "ignore" then
|
|
|
|
ipnames.command_ignore(name, args[2])
|
|
|
|
elseif args[1] == "unignore" then
|
|
|
|
ipnames.command_unignore(name, args[2])
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(name, "Error: No known argument for #1 '"..args[1].."'")
|
2014-07-16 11:55:37 +02:00
|
|
|
end
|
2014-08-16 09:39:55 +02:00
|
|
|
end
|
2014-07-16 11:55:37 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- 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
|
2014-08-16 09:39:55 +02:00
|
|
|
|
|
|
|
if ipnames.data[name] then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local count = 1
|
|
|
|
local names = ""
|
2014-08-16 11:32:44 +02:00
|
|
|
local limit_ext = false
|
2014-08-16 09:39:55 +02:00
|
|
|
for k, v in pairs(ipnames.data) do
|
2014-08-16 09:53:41 +02:00
|
|
|
if v[1] == ip then
|
2014-08-16 11:32:44 +02:00
|
|
|
if not limit_ext and ipnames.whitelist[k] then
|
|
|
|
count = count - ipnames.extended_limit
|
|
|
|
limit_ext = true
|
2014-07-16 11:55:37 +02:00
|
|
|
end
|
2014-08-16 09:39:55 +02:00
|
|
|
count = count + 1
|
|
|
|
names = names..k..", "
|
2014-07-16 11:55:37 +02:00
|
|
|
end
|
2014-08-16 09:39:55 +02:00
|
|
|
end
|
|
|
|
-- Return error message if too many accounts have been created
|
|
|
|
if count > ipnames.name_per_ip_limit then
|
|
|
|
ipnames.tmp_data[name] = nil
|
|
|
|
return ("\nYou exceeded the limit of accounts.\nYou already own the following accounts:\n"..names)
|
2014-07-16 11:55:37 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- Save IP if player joined
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
2014-08-16 09:53:41 +02:00
|
|
|
local t = os.time()
|
|
|
|
ipnames.data[name] = {ipnames.tmp_data[name], t}
|
2014-07-16 11:55:37 +02:00
|
|
|
ipnames.tmp_data[name] = nil
|
|
|
|
ipnames.changes = true
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_globalstep(function(t)
|
|
|
|
ipnames.save_time = ipnames.save_time + t
|
|
|
|
if ipnames.save_time < ipnames.save_interval then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
ipnames.save_time = 0
|
|
|
|
ipnames.save_data()
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_shutdown(function() ipnames.save_data() end)
|
|
|
|
|
2014-08-16 09:39:55 +02:00
|
|
|
minetest.after(3, function() ipnames.load_data() end)
|
|
|
|
minetest.after(3, function() ipnames.load_whitelist() end)
|