mirror of
https://github.com/minetest-mods/xban2.git
synced 2025-11-24 18:35:37 +01:00
Missing record on creating new in find_entry. Fix for access logic (#30)
Access logic was flawed because if a name existed that was not banned, the IP was not checked for a ban.
This commit is contained in:
65
init.lua
65
init.lua
@@ -51,27 +51,31 @@ end
|
||||
|
||||
-- supports wildcard IP pattern (both IPv4 and IPv6)
|
||||
function xban.find_entry(key, create)
|
||||
-- exact match (player or IP)
|
||||
for i, e in ipairs(xban.db) do
|
||||
if e.names[key] then return e, i end
|
||||
end
|
||||
-- wildcard pattern match for IPs
|
||||
if key and key:find("[.:]") then
|
||||
for i, e in ipairs(xban.db) do
|
||||
for name in pairs(e.names) do
|
||||
local wildcard_prefix = name:match("(.+[.:])%*$")
|
||||
if wildcard_prefix and key:sub(1, #wildcard_prefix) == wildcard_prefix then
|
||||
return e, i
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if create then
|
||||
local e = { names = { [key] = true }, bans = {} }
|
||||
table.insert(xban.db, e)
|
||||
return e, #xban.db
|
||||
end
|
||||
return nil
|
||||
-- exact match (player or IP)
|
||||
for i, e in ipairs(xban.db) do
|
||||
if e.names[key] then return e, i end
|
||||
end
|
||||
-- wildcard pattern match for IPs
|
||||
if key and key:find("[.:]") then
|
||||
for i, e in ipairs(xban.db) do
|
||||
for name in pairs(e.names) do
|
||||
local wildcard_prefix = name:match("(.+[.:])%*$")
|
||||
if wildcard_prefix and key:sub(1, #wildcard_prefix) == wildcard_prefix then
|
||||
return e, i
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if create then
|
||||
local e = {
|
||||
names = { [key]=true },
|
||||
banned = false,
|
||||
record = { },
|
||||
}
|
||||
table.insert(xban.db, e)
|
||||
return e, #xban.db
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function xban.get_info(player) --> ip_name_list, banned, last_record
|
||||
@@ -197,15 +201,18 @@ function xban.get_record(player)
|
||||
end
|
||||
|
||||
minetest.register_on_prejoinplayer(function(name, ip)
|
||||
local wl = db.whitelist or { }
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user