Skip to content

Refine wildcard IP matching and fix range ban precedence - #32

Open
MCLV-pandorabox wants to merge 3 commits into
minetest-mods:masterfrom
MCLV-pandorabox:patch-1
Open

MCLV-pandorabox wants to merge 3 commits into
minetest-mods:masterfrom
MCLV-pandorabox:patch-1

Conversation

@MCLV-pandorabox

Copy link
Copy Markdown
Contributor

Fixes Issue #31

  • Adjust wildcard prefix extraction to correctly handle patterns like ::ffff:79.127.164.* and 79.127.164.*.

  • Ensure both IPv4 and IPv4-mapped IPv6 addresses match the same wildcard bans.

  • Change ban lookup logic so non-banned exact IP entries no longer shadow later wildcard range bans.

  • Keep compatibility with existing xban2 databases while making IP range bans reliably effective.

Fixes Issue minetest-mods#31 

- Adjust wildcard prefix extraction to correctly handle patterns like ::ffff:79.127.164.* and 79.127.164.*.

-  Ensure both IPv4 and IPv4-mapped IPv6 addresses match the same wildcard bans.

- Change ban lookup logic so non-banned exact IP entries no longer shadow later wildcard range bans.

- Keep compatibility with existing xban2 databases while making IP range bans reliably effective.
Comment thread init.lua Outdated
if wildcard_prefix and key:sub(1, #wildcard_prefix) == wildcard_prefix then
return e, i
end
local key_prefix = key:match("(.*)%*$")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move outside the loop. This does not need to be re-evaluated every time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to fix this really simple thing, but I also wanted to try out copilot.
it messed up and apologized, then told me I was out of tokens when I asked it to fix it.
I have no idea what happened or have enough experience with github to fix this, but it looks like the entire init.lua was pushed as a nearly blank file.
Please advice

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To revert changes, look up git revert or git reset in your preferred manual.

Comment thread init.lua Outdated
end
local key_prefix = key:match("(.*)%*$")
if key_prefix and name:sub(1, #key_prefix) == key_prefix then
return e, i

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be sure that e.banned is true?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that! Yes, we can't assume e.banned is true on an exact match, and that's intentional. The logic here is: if an entry exists (exact or wildcard match) and it's banned, block immediately. If it exists but is unbanned, keep searching — there might be another entry (wildcard or otherwise) that IS banned and should take precedence.
No code change needed I think

@SmallJoker

Copy link
Copy Markdown
Member

In case you're waiting on a feedback: Did you yet test these changes? I am pretty sure the word dunction causes a Lua error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants