Skip to content
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

Server enforcement for fog_distance (#13448) to block cheating #13643

Merged
merged 3 commits into from Jul 6, 2023

Conversation

lhofhansl
Copy link
Contributor

@lhofhansl lhofhansl commented Jul 2, 2023

Followup from #13448

  • Goal of the PR
    Enforce fog_distance at the server to block cheating clients.
    Only allow reasonable values to set for fog_distance, i.e. the same limits we have now: 20 to 4000

To do

This PR is Ready for Review.

How to test

Set fog_distance to 0. Ensure it uses 20.
Set fog_distance to 1000000, make sure it all works.
Can't really test a cheating client without changing the code. If you want to hard code wanted_range in client and see how the server still won't send more data. At least make sure the server never sends less that what is expected.

if (sky_params.fog_distance >= 0) {
// if set, enforce game limits
sky_params.fog_distance = rangelim(sky_params.fog_distance, 20, 4000);
}
Copy link
Member

@grorp grorp Jul 3, 2023

Choose a reason for hiding this comment

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

I think the minimum is too high. A fog distance of 10 allows for really nice effects, but there could also be use cases for something like 2. The only value I really see no use for is 0.

I don't think we should define an artificial minimum here. Instead, we could just change this

Any value >= 0 sets the desired upper bound for the client's viewing_range and disables range_all.

into this

Any value > 0 sets the desired upper bound for the client's viewing_range and disables range_all.

and call it a day. (Not only in the docs, but also in the implementation, of course.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The client won't allow less than 20.

if (range_new < 20) {

Copy link
Member

@grorp grorp Jul 3, 2023

Choose a reason for hiding this comment

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

The client won't allow the user to set a value below 20, but via the current set_sky API, you can set values below 20 and they will be applied. E.g. this works:

minetest.register_on_joinplayer(function(player)
    player:set_sky({ fog = { fog_distance = 2 }})
end)

And I think there's no good reason to disallow it.

Copy link
Contributor Author

@lhofhansl lhofhansl Jul 3, 2023

Choose a reason for hiding this comment

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

I do not feel strongly. The main part was to avoid was allowing setting this to 0 - which would not render anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to get some consensus. I can change this to only disallow 0 as valid value.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see an issue with setting fog_distance even to 0. Why do we need a limit?

Copy link
Contributor Author

@lhofhansl lhofhansl Jul 3, 2023

Choose a reason for hiding this comment

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

At 0 you see nothing. Even the wield item is not shaded correctly.
It's not just black (or fog color) it looks like a bug.

Actually: Can you try and see what you think (without this PR)?

Copy link
Member

@grorp grorp Jul 4, 2023

Choose a reason for hiding this comment

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

At 0 you see nothing. Even the wield item is not shaded correctly.
It's not just black (or fog color) it looks like a bug.

Some more testing reveals that for me, any fog_distance value below 1 results in only the fog color being visible, both with shaders and with the fixed pipeline. The value of fog_start doesn't seem to make any difference.

-- for Minetest game
minetest.register_on_joinplayer(function(player)
    minetest.after(0, function()
        player:set_sky({ fog = { fog_distance = <insert value here>, fog_start = 0.5 }, type = "plain", base_color = "#ff0000", clouds = false })
    end)
end)

All screenshots were taken from the same point of view. The first screenshot is always with shaders (enable_shaders = true) and the second with the fixed pipeline (enable_shaders = false). The differences are probably (partially) due to the fact that tone mapping is enabled (tone_mapping = true).

fog_distance = 10 screenshot with fog_distance set to 10, shaders enabled screenshot with fog_distance set to 10, shaders disabled
fog_distance = 1 screenshot with fog_distance set to 1, shaders enabled screenshot with fog_distance set to 1, shaders disabled
fog_distance = 0.999999 screenshot with fog_distance set to 0.999999, shaders enabled screenshot with fog_distance set to 0.999999, shaders disabled
fog_distance = 0.1 screenshot with fog_distance set to 0.1, shaders enabled screenshot with fog_distance set to 0.1, shaders disabled
fog_distance = 0 screenshot with fog_distance set to 0, shaders enabled screenshot with fog_distance set to 0, shaders disabled

So, something seems to break with values below 1.

Copy link
Member

Choose a reason for hiding this comment

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

fog_distance is an s16, that's why it's rounded.

Not seeing anything bug fog is the intended behaviour for fog_distance=0, I'd say.
And the wieldhand issues are not that severe, imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok... Make this simpler :)
I'll post an update soon.

@wsor4035 wsor4035 added the Maintenance Tasks to keep the codebase and related parts in order, including architectural improvements label Jul 4, 2023
@lhofhansl lhofhansl changed the title 13448 fixes, server enforcement, and rangelim of distance values Server enforcement for fog_distance (#13448) to block cheating Jul 4, 2023
@lhofhansl lhofhansl added Feature ✨ PRs that add or enhance a feature and removed Maintenance Tasks to keep the codebase and related parts in order, including architectural improvements labels Jul 4, 2023
@lhofhansl lhofhansl merged commit 869df17 into minetest:master Jul 6, 2023
12 of 13 checks passed
Wuzzy2 pushed a commit to Wuzzy2/minetest that referenced this pull request Jul 31, 2023
minetest#13643)

This enforces the fog_distance (if set) at the server, so that a hacked client could not cheat and retrieve blocks beyond the set distance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature ✨ PRs that add or enhance a feature One approval ✅ ◻️
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants