Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 37 additions & 28 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ function xban.find_entry(key, create)
end
end
if create then
local e = { names = { [key] = true }, bans = {} }
local e = {
names = { [key]=true },
banned = false,
record = { },
}
table.insert(xban.db, e)
return e, #xban.db
end
Expand Down Expand Up @@ -197,36 +201,41 @@ function xban.get_record(player)
end

minetest.register_on_prejoinplayer(function(name, ip)
local wl = db.whitelist or { }
if wl[name] or wl[ip] then return end
local e = xban.find_entry(name) or xban.find_entry(ip)
if not e then return end
if e.banned then
local date = (e.expires and os.date("%c", e.expires)
or "the end of time")
return ("Banned: Expires: %s, Reason: %s"):format(
date, e.reason)
end
end)
local wl = db.whitelist or {}
if wl[name] or wl[ip] then return end

minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
local e = xban.find_entry(name)
local ip = minetest.get_player_ip(name)
if not e then
if ip then
e = xban.find_entry(ip, true)
else
return
end
end
e.names[name] = true
if ip then
e.names[ip] = true
end
e.last_seen = os.time()
local e = xban.find_entry(name)
if not e or not e.banned then
e = ip and xban.find_entry(ip)
end

if e and e.banned then
local date = e.expires and os.date("%c", e.expires) or "the end of time"
local reason = e.reason or "No reason given"
return ("Banned: Expires: %s, Reason: %s"):format(date, reason)
end
end)

minetest.register_on_joinplayer(
function(player)
local name = player:get_player_name()
local e = xban.find_entry(name)
local ip = minetest.get_player_ip(name)
if not e then
if ip then
e = xban.find_entry(ip, true)
else
return
end
end
e.names[name] = true
if ip then
e.names[ip] = true
end
e.last_seen = os.time()
end
)

minetest.register_chatcommand("xban", {
description = "XBan a player",
params = "<player> <reason>",
Expand Down