forked from minetest-mods/xban2
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)
|
-- supports wildcard IP pattern (both IPv4 and IPv6)
|
||||||
function xban.find_entry(key, create)
|
function xban.find_entry(key, create)
|
||||||
-- exact match (player or IP)
|
-- exact match (player or IP)
|
||||||
for i, e in ipairs(xban.db) do
|
for i, e in ipairs(xban.db) do
|
||||||
if e.names[key] then return e, i end
|
if e.names[key] then return e, i end
|
||||||
end
|
end
|
||||||
-- wildcard pattern match for IPs
|
-- wildcard pattern match for IPs
|
||||||
if key and key:find("[.:]") then
|
if key and key:find("[.:]") then
|
||||||
for i, e in ipairs(xban.db) do
|
for i, e in ipairs(xban.db) do
|
||||||
for name in pairs(e.names) do
|
for name in pairs(e.names) do
|
||||||
local wildcard_prefix = name:match("(.+[.:])%*$")
|
local wildcard_prefix = name:match("(.+[.:])%*$")
|
||||||
if wildcard_prefix and key:sub(1, #wildcard_prefix) == wildcard_prefix then
|
if wildcard_prefix and key:sub(1, #wildcard_prefix) == wildcard_prefix then
|
||||||
return e, i
|
return e, i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if create then
|
if create then
|
||||||
local e = { names = { [key] = true }, bans = {} }
|
local e = {
|
||||||
table.insert(xban.db, e)
|
names = { [key]=true },
|
||||||
return e, #xban.db
|
banned = false,
|
||||||
end
|
record = { },
|
||||||
return nil
|
}
|
||||||
|
table.insert(xban.db, e)
|
||||||
|
return e, #xban.db
|
||||||
|
end
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function xban.get_info(player) --> ip_name_list, banned, last_record
|
function xban.get_info(player) --> ip_name_list, banned, last_record
|
||||||
@@ -197,15 +201,18 @@ function xban.get_record(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_prejoinplayer(function(name, ip)
|
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
|
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
|
local e = xban.find_entry(name)
|
||||||
if e.banned then
|
if not e or not e.banned then
|
||||||
local date = (e.expires and os.date("%c", e.expires)
|
e = ip and xban.find_entry(ip)
|
||||||
or "the end of time")
|
end
|
||||||
return ("Banned: Expires: %s, Reason: %s"):format(
|
|
||||||
date, e.reason)
|
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
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user