-
Notifications
You must be signed in to change notification settings - Fork 24
Missing record on creating new in find_entry. Fix for access logic #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Access logic was flawed because if a name existed that was not banned, the IP was not checked for a ban.
init.lua
Outdated
| local wl = db.whitelist or {} | ||
| if wl[name] or wl[ip] then return end | ||
|
|
||
| -- Single lookups for name and IP | ||
| local e_name = xban.find_entry(name) | ||
| local e_ip = ip and xban.find_entry(ip) | ||
|
|
||
| if (e_name and e_name.banned) or (e_ip and e_ip.banned) then | ||
| local date = | ||
| (e_name and e_name.banned and e_name.expires and os.date("%c", e_name.expires)) or | ||
| (e_ip and e_ip.banned and e_ip.expires and os.date("%c", e_ip.expires)) or "the end of time" | ||
| local reason = | ||
| (e_name and e_name.banned and e_name.reason) or | ||
| (e_ip and e_ip.banned and e_ip.reason) or "No reason given" | ||
| minetest.kick_player(name, ("Banned: Expires: %s, Reason: %s"):format(date, reason)) | ||
| return | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need the same code here? All players must first pass register_on_prejoinplayer, thus this is redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, flawed logic in my head. no need to check that again
init.lua
Outdated
| local date = | ||
| (e_name and e_name.banned and e_name.expires and os.date("%c", e_name.expires)) or | ||
| (e_ip and e_ip.banned and e_ip.expires and os.date("%c", e_ip.expires)) or "the end of time" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code duplication. Wouldn't it be simpler to use something like this? (untested)
local e = xban.find_entry(name)
if not e or not e.banned then
-- Check if banned by IP
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)
endThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true.
| e.names[ip] = true | ||
| end | ||
| e.last_seen = os.time() | ||
| local e = xban.find_entry(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use tabs to indent, like used in the rest of the code.
EDIT: The same goes for xban.find_entry. I did not notice that the indent style is now mixed.
| end) | ||
|
|
||
| minetest.register_on_joinplayer( | ||
| function(player) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So... no changes here? The change of indent levels makes it difficult to see differences.
Access logic was flawed because if a name existed that was not banned, the IP was not checked for a ban.
I forgot to add the records table when creating a new entry.(Fix)