commit c15f5f69dc41057195299db48e7b90753aeca58a Author: sys4-fr Date: Sat Sep 8 14:00:37 2018 +0200 Remplissage du dépôt. diff --git a/depends.txt b/depends.txt new file mode 100755 index 0000000..e69de29 diff --git a/init.lua b/init.lua new file mode 100755 index 0000000..8f80be2 --- /dev/null +++ b/init.lua @@ -0,0 +1,110 @@ +minetest.register_privilege("whois", { + description = "Allows player to see other player IPs"}) + +-- Created by Krock to stop mass-account-creators +-- License: WTFPL + +ipnames = {} +ipnames.data = {} +ipnames.tmp_data = {} +ipnames.changes = false +ipnames.file = minetest.get_worldpath().."/ipnames.txt" + +ipnames.name_per_ip_limit = tonumber(minetest.setting_get("max_names_per_ip")) or 5 + +-- Get accounts self: +minetest.register_chatcommand("whois", { + description = "Gets all players who have the same IP as the specified player", + privs = {whois = true}, + func = function(name, param) + if not ipnames.data[param] then + minetest.chat_send_player(name, "The player \"" .. param .. "\" did not join yet.") + return + end + + local ip = ipnames.data[param] + local names = ""; + for k, v in pairs(ipnames.data) do + if v == ip then + if names ~= "" then + names = names .. ", " .. k + else + names = names .. " " .. k + end + end + end + minetest.chat_send_player(name, "Players for IP address " .. ip .. ": " .. names) + end, +}) + +-- 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 not ipnames.data[name] then + local count = 1 + local names = "" + for k, v in pairs(ipnames.data) do + if v == ip then + count = count + 1 + names = names .. k .. ", " + end + end + + if count <= ipnames.name_per_ip_limit and count > 1 then + minetest.log("action", name .. " now has " .. count .. " accounts. Other accounts: " .. names) + end + + if count > ipnames.name_per_ip_limit then + ipnames.tmp_data[name] = nil + if tostring(ip) ~= "127.0.0.1" then + return ("\nYou exceeded the limit of accounts (" .. ipnames.name_per_ip_limit .. + ").\nYou already have the following accounts:\n" .. names) + end + end + end +end) + +-- Save IP if player joined: +minetest.register_on_joinplayer(function(player) + local name = player:get_player_name() + ipnames.data[name] = ipnames.tmp_data[name] + ipnames.tmp_data[name] = nil + ipnames.changes = true + ipnames.save_data() +end) + +function ipnames.load_data() + local file = io.open(ipnames.file, "r") + if not file then + return + end + for line in file:lines() do + if line ~= "" then + local data = line:split("|") + if #data >= 2 then + ipnames.data[data[1]] = data[2] + end + end + end + io.close(file) +end + +function ipnames.save_data() + if not ipnames.changes then + return + end + ipnames.changes = false + local file = io.open(ipnames.file, "w") + for i, v in pairs(ipnames.data) do + if v ~= nil then + file:write(i .. "|" .. v .. "\n") + end + end + io.close(file) +end + + +minetest.register_on_shutdown(function() ipnames.save_data() end) + +minetest.after(3, function() ipnames.load_data() end)