2014-07-16 11:55:37 +02:00
|
|
|
-- Created by Krock to stop mass-account-creators
|
2019-02-09 16:48:34 +01:00
|
|
|
-- License: CC0
|
|
|
|
|
|
|
|
if not minetest.safe_file_write then
|
|
|
|
error("[simple_protection] Your Minetest version is no longer supported."
|
|
|
|
.. " (version < 0.4.17)")
|
|
|
|
end
|
|
|
|
|
2014-07-16 11:55:37 +02:00
|
|
|
ipnames = {}
|
|
|
|
ipnames.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-11-09 10:22:44 +01:00
|
|
|
-- 2 + 3 = 5 accounts as limit for "ignored" players
|
|
|
|
ipnames.extended_limit = 3
|
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
|
2019-02-09 16:48:34 +01:00
|
|
|
return true,
|
|
|
|
"Available commands:\n" ..
|
|
|
|
"Get all accounts of <name>: /ipnames whois <name>\n" ..
|
|
|
|
"Show all whitelisted names: /ipnames list\n" ..
|
|
|
|
"Add/remove whitelist entry: /ipnames (un)ignore <name>"
|
2014-08-16 09:39:55 +02:00
|
|
|
end
|
|
|
|
if param == "list" then
|
2019-02-09 16:48:34 +01:00
|
|
|
return ipnames.command_list(name)
|
2014-07-16 11:55:37 +02:00
|
|
|
end
|
2019-02-09 16:48:34 +01:00
|
|
|
|
|
|
|
-- Commands with two arguments
|
2014-08-16 09:39:55 +02:00
|
|
|
local args = param:split(" ")
|
|
|
|
if #args < 2 then
|
2019-02-09 16:48:34 +01:00
|
|
|
return false, "Error: Too few command arguments."
|
2014-08-16 09:39:55 +02:00
|
|
|
end
|
2019-02-09 16:48:34 +01:00
|
|
|
|
|
|
|
local func = ipnames["command_" .. args[1]]
|
|
|
|
if func then
|
|
|
|
return func(name, args[2])
|
2014-07-16 11:55:37 +02:00
|
|
|
end
|
2019-02-09 16:48:34 +01:00
|
|
|
|
|
|
|
return false, "Error: No known action for argument #1 ('"..args[1].."')"
|
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
|
2019-04-13 11:29:59 +02:00
|
|
|
if ipnames.data[name] or ipnames.is_registered(name) then
|
2014-08-16 09:39:55 +02:00
|
|
|
return
|
|
|
|
end
|
2019-02-09 16:48:34 +01:00
|
|
|
|
|
|
|
local names = {} -- faster than string concat
|
2019-03-22 19:24:03 +01:00
|
|
|
local count_bonus = nil
|
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
|
2019-03-22 19:24:03 +01:00
|
|
|
if not count_bonus and ipnames.whitelist[k] then
|
|
|
|
count_bonus = ipnames.extended_limit
|
2014-07-16 11:55:37 +02:00
|
|
|
end
|
2019-02-09 16:48:34 +01:00
|
|
|
names[#names + 1] = 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
|
2019-03-22 19:24:03 +01:00
|
|
|
if #names > ipnames.name_per_ip_limit + (count_bonus or 0) then
|
2019-02-09 16:48:34 +01:00
|
|
|
return "\nYou exceeded the limit of accounts.\n" ..
|
|
|
|
"You already own the following accounts:\n" .. table.concat(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()
|
2019-04-13 11:29:59 +02:00
|
|
|
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
|
|
|
|
}
|
2014-07-16 11:55:37 +02:00
|
|
|
|
2019-04-13 11:29:59 +02:00
|
|
|
ipnames.changes = true
|
2019-03-22 19:24:03 +01:00
|
|
|
end)
|
|
|
|
|
2014-07-16 11:55:37 +02:00
|
|
|
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)
|
|
|
|
|
2019-02-09 16:48:34 +01:00
|
|
|
minetest.register_on_shutdown(ipnames.save_data)
|
2014-07-16 11:55:37 +02:00
|
|
|
|
2019-02-09 16:48:34 +01:00
|
|
|
minetest.after(3, ipnames.load_data)
|
2019-06-09 12:11:07 +02:00
|
|
|
minetest.after(3, ipnames.load_whitelist)
|
|
|
|
|
|
|
|
minetest.log("action", "[names_per_ip] loaded.")
|