summaryrefslogtreecommitdiff
path: root/xban2
diff options
context:
space:
mode:
Diffstat (limited to 'xban2')
-rw-r--r--xban2/gui.lua6
-rw-r--r--xban2/init.lua64
-rw-r--r--xban2/mod.conf1
3 files changed, 67 insertions, 4 deletions
diff --git a/xban2/gui.lua b/xban2/gui.lua
index fb0c1df..d3306e2 100644
--- a/xban2/gui.lua
+++ b/xban2/gui.lua
@@ -100,6 +100,11 @@ end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= FORMNAME then return end
local name = player:get_player_name()
+ if not minetest.check_player_privs(name, { ban=true }) then
+ minetest.log("warning",
+ "[xban2] Received fields from unauthorized user: "..name)
+ return
+ end
local state = get_state(name)
if fields.player then
local t = minetest.explode_textlist_event(fields.player)
@@ -128,6 +133,7 @@ end)
minetest.register_chatcommand("xban_gui", {
description = "Show XBan GUI",
params = "",
+ privs = { ban=true, },
func = function(name, params)
minetest.show_formspec(name, FORMNAME, make_fs(name))
end,
diff --git a/xban2/init.lua b/xban2/init.lua
index 81818a8..d8b20e7 100644
--- a/xban2/init.lua
+++ b/xban2/init.lua
@@ -72,7 +72,13 @@ function xban.get_info(player) --> ip_name_list, banned, last_record
end
function xban.ban_player(player, source, expires, reason) --> bool, err
+ if xban.get_whitelist(player) then
+ return nil, "Player is whitelisted; remove from whitelist first"
+ end
local e = xban.find_entry(player, true)
+ if e.banned then
+ return nil, "Already banned"
+ end
local rec = {
source = source,
time = os.time(),
@@ -131,6 +137,28 @@ function xban.unban_player(player, source) --> bool, err
return true
end
+function xban.get_whitelist(name_or_ip)
+ return db.whitelist and db.whitelist[name_or_ip]
+end
+
+function xban.remove_whitelist(name_or_ip)
+ if db.whitelist then
+ db.whitelist[name_or_ip] = nil
+ end
+end
+
+function xban.add_whitelist(name_or_ip, source)
+ local wl = db.whitelist
+ if not wl then
+ wl = { }
+ db.whitelist = wl
+ end
+ wl[name_or_ip] = {
+ source=source,
+ }
+ return true
+end
+
function xban.get_record(player)
local e = xban.find_entry(player)
if not e then
@@ -158,6 +186,8 @@ 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
@@ -195,8 +225,8 @@ minetest.register_chatcommand("xban", {
if not (plname and reason) then
return false, "Usage: /xban <player> <reason>"
end
- xban.ban_player(plname, name, nil, reason)
- return true, ("Banned %s."):format(plname)
+ local ok, e = xban.ban_player(plname, name, nil, reason)
+ return ok, ok and ("Banned %s."):format(plname) or e
end,
})
@@ -214,8 +244,9 @@ minetest.register_chatcommand("xtempban", {
return false, "You must ban for at least 60 seconds."
end
local expires = os.time() + time
- xban.ban_player(plname, name, expires, reason)
- return true, ("Banned %s until %s."):format(plname, os.date("%c", expires))
+ local ok, e = xban.ban_player(plname, name, expires, reason)
+ return ok, (ok and ("Banned %s until %s."):format(
+ plname, os.date("%c", expires)) or e)
end,
})
@@ -260,6 +291,31 @@ minetest.register_chatcommand("xban_record", {
end,
})
+minetest.register_chatcommand("xban_wl", {
+ description = "Manages the whitelist",
+ params = "(add|del|get) <name_or_ip>",
+ privs = { ban=true },
+ func = function(name, params)
+ local cmd, plname = params:match("%s*(%S+)%s*(%S+)")
+ if cmd == "add" then
+ xban.add_whitelist(plname, name)
+ ACTION("%s adds %s to whitelist", source, plname)
+ return true, "Added to whitelist: "..plname
+ elseif cmd == "del" then
+ xban.remove_whitelist(plname)
+ ACTION("%s removes %s to whitelist", source, plname)
+ return true, "Removed from whitelist: "..plname
+ elseif cmd == "get" then
+ local e = xban.get_whitelist(plname)
+ if e then
+ return true, "Source: "..(e.source or "Unknown")
+ else
+ return true, "No whitelist for: "..plname
+ end
+ end
+ end,
+})
+
local function check_temp_bans()
minetest.after(60, check_temp_bans)
local to_rm = { }
diff --git a/xban2/mod.conf b/xban2/mod.conf
new file mode 100644
index 0000000..b046e3c
--- /dev/null
+++ b/xban2/mod.conf
@@ -0,0 +1 @@
+name = xban2