mirror of
https://github.com/SmallJoker/names_per_ip.git
synced 2025-01-03 14:10:24 +01:00
Upload. Needs testing
This commit is contained in:
commit
c3c737ed38
0
depends.txt
Normal file
0
depends.txt
Normal file
103
init.lua
Normal file
103
init.lua
Normal file
@ -0,0 +1,103 @@
|
||||
-- Created by Krock to stop mass-account-creators
|
||||
-- License: WTFPL
|
||||
ipnames = {}
|
||||
ipnames.data = {}
|
||||
ipnames.tmp_data = {}
|
||||
ipnames.changes = false
|
||||
ipnames.save_interval = 480
|
||||
ipnames.save_time = 0
|
||||
ipnames.file = minetest.get_worldpath().."/ipnames.data"
|
||||
|
||||
ipnames.name_per_ip_limit = 3
|
||||
|
||||
-- Get accounts self.
|
||||
minetest.register_chatcommand("whois", {
|
||||
description = "Gets all player names which have the same IP as <param>.",
|
||||
privs = {ban=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
|
||||
names = names.." "..k
|
||||
end
|
||||
end
|
||||
minetest.chat_send_player(name, "Following players share an 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 then
|
||||
ipnames.tmp_data[name] = nil
|
||||
return ("\nYou exceeded the limit of accounts.\nYou already own the following accounts:\n"..names)
|
||||
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
|
||||
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_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)
|
||||
|
||||
minetest.after(3, function() ipnames.load_data() end)
|
Loading…
Reference in New Issue
Block a user