Give players fly priv when creative is enabled #1865

Merged
NO11 merged 8 commits from NO11/MineClone2:privs into master 2021-10-07 17:13:30 +02:00
Member
No description provided.
NO11 added this to the 0.72.0 milestone 2021-09-19 14:09:34 +02:00
NO11 added the
missing feature
gameplay
labels 2021-09-19 14:09:34 +02:00
NO11 added 5 commits 2021-09-19 14:09:40 +02:00
Ghost requested changes 2021-09-20 07:52:59 +02:00
@ -6,0 +8,4 @@
local name = player:get_player_name()
local meta = player:get_meta()
if meta:get_int("fly_changed") == 1 then return end
First-time contributor

use last_login parameter to check new players.

use `last_login` parameter to check new players.
Author
Member

used on_newplayer now.

used on_newplayer now.
First-time contributor

oh much better!

oh much better!
Author
Member

Oh NO now i remember why i didnt use on_newplayer. Imagine: a server owner turns the server back to survival...

Oh NO now i remember why i didnt use on_newplayer. Imagine: a server owner turns the server back to survival...
Author
Member

use last_login parameter to check new players.

Sry i forgot what my own code does. It wasnt a check for new players, it was a check wether the server owner or someone else changed the privs of the player when creative is disabled again when the player joins.

> use `last_login` parameter to check new players. Sry i forgot what my own code does. It wasnt a check for new players, it was a check wether the server owner or someone else changed the privs of the player when creative is disabled again when the player joins.
Author
Member

When the the sever owner grants fly to the player maunally, the priv will not be changed on rejoin when creative isnt enabled.

When the the sever owner grants fly to the player maunally, the priv will not be changed on rejoin when creative isnt enabled.
Author
Member

So can i change it back? Do you understand it?

So can i change it back? Do you understand it?
First-time contributor

just change it then :p. this PR is still in the works. Though, i appreciate explaining why 👍.

just change it then \:p. this PR is still in the works. Though, i appreciate explaining why :+1:.
NO11 marked this conversation as resolved
@ -6,0 +16,4 @@
end
minetest.set_player_privs(name, {
fly = fly,
})
First-time contributor

This will remove all of new players' default_privs (check minetest.conf.example for the setting).

Test code:

@@ -14,9 +14,11 @@ minetest.register_on_joinplayer(function(player)
 	if minetest.is_creative_enabled(name) then
 		fly = true
 	end
+	minetest.chat_send_all(dump2(minetest.get_player_privs(name), name .."'s initial privs"))
 	minetest.set_player_privs(name, {
 		fly = fly,
 	})
+	minetest.chat_send_all(dump2(minetest.get_player_privs(name), name .."'s current privs"))
 end)
 
 for _, action in pairs({ "grant", "revoke" }) do

Chatlog:

TES_'s initial privs = {}
TES_'s initial privs["interact"] = true
TES_'s initial privs["shout"] = true
TES_'s current privs = {}
TES_'s current privs["fly"] = true
This will remove all of new players' `default_privs` (check `minetest.conf.example` for the setting). Test code: ```diff @@ -14,9 +14,11 @@ minetest.register_on_joinplayer(function(player) if minetest.is_creative_enabled(name) then fly = true end + minetest.chat_send_all(dump2(minetest.get_player_privs(name), name .."'s initial privs")) minetest.set_player_privs(name, { fly = fly, }) + minetest.chat_send_all(dump2(minetest.get_player_privs(name), name .."'s current privs")) end) for _, action in pairs({ "grant", "revoke" }) do ``` Chatlog: ``` TES_'s initial privs = {} TES_'s initial privs["interact"] = true TES_'s initial privs["shout"] = true TES_'s current privs = {} TES_'s current privs["fly"] = true ```
Author
Member

hmmm. I know this is oudated but i dont think set_player_privs changed https://dev.minetest.net/minetest.set_player_privs

privs — a table containing the new privileges of the player. The keys are privilege names and the values are true. Privileges not specified are removed if the player had them before the call.
hmmm. I know this is oudated but i dont think set_player_privs changed https://dev.minetest.net/minetest.set_player_privs ``` privs — a table containing the new privileges of the player. The keys are privilege names and the values are true. Privileges not specified are removed if the player had them before the call. ```
First-time contributor

this is not "outdated" despite what gitea tells you. the code is still the same, see lines 17-19.

or, if i misunderstood; yes, dev.minetest.net is probably outdated, but in this case it's correct (which you can verify it yourself by running the test code). i use the nightly lua_api.txt on gitlab and unfortunately the description is rather sparse.

Privileges not specified are removed if the player had them before the call.

What this means is that if i had interact priv as specified by default_privs, i will lose the priv once the call is made. my suggestion to fix this:

local player_privs = minetest.get_player_privs(name)
player_privs.fly = true
minetest.set_player_privs(name, player_privs)
this is not "outdated" despite what gitea tells you. the code is still the same, see lines 17-19. or, if i misunderstood; yes, dev.minetest.net is probably outdated, but in this case it's correct (which you can verify it yourself by running the test code). i use the nightly `lua_api.txt` on [gitlab](https://minetest.gitlab.io/minetest/) and unfortunately the description is rather sparse. > Privileges not specified are removed if the player had them before the call. What this means is that if i had `interact` priv as specified by `default_privs`, i will lose the priv once the call is made. my suggestion to fix this: ```lua local player_privs = minetest.get_player_privs(name) player_privs.fly = true minetest.set_player_privs(name, player_privs) ```
Author
Member

@iliekprogrammar for me it works also without your fix:

2021-09-30 14:53:18: ERROR[Server]: singleplayer's initial privs = {}
singleplayer's initial privs["privs"] = true
singleplayer's initial privs["shout"] = true
singleplayer's initial privs["maphack"] = true
singleplayer's initial privs["interact"] = true
singleplayer's initial privs["basic_privs"] = true

2021-09-30 14:53:18: ERROR[Server]: ---------
2021-09-30 14:53:18: ERROR[Server]: singleplayer's initial privs = {}
singleplayer's initial privs["interact"] = true
singleplayer's initial privs["shout"] = true
singleplayer's initial privs["maphack"] = true
singleplayer's initial privs["privs"] = true
singleplayer's initial privs["fly"] = true
singleplayer's initial privs["basic_privs"] = true

@iliekprogrammar for me it works also without your fix: ``` 2021-09-30 14:53:18: ERROR[Server]: singleplayer's initial privs = {} singleplayer's initial privs["privs"] = true singleplayer's initial privs["shout"] = true singleplayer's initial privs["maphack"] = true singleplayer's initial privs["interact"] = true singleplayer's initial privs["basic_privs"] = true 2021-09-30 14:53:18: ERROR[Server]: --------- 2021-09-30 14:53:18: ERROR[Server]: singleplayer's initial privs = {} singleplayer's initial privs["interact"] = true singleplayer's initial privs["shout"] = true singleplayer's initial privs["maphack"] = true singleplayer's initial privs["privs"] = true singleplayer's initial privs["fly"] = true singleplayer's initial privs["basic_privs"] = true ```
Author
Member

You're right, sorry.

You're right, sorry.
NO11 marked this conversation as resolved
Member

why cant gitea allow me to self-request a review???

why cant gitea allow me to self-request a review???
Member

I aggree with @iliekprogrammar and whould like to test before merge

I aggree with @iliekprogrammar and whould like to test before merge
Ghost closed this pull request 2021-09-20 10:01:59 +02:00
Member

@iliekprogrammar why did you close the pr??

@iliekprogrammar why did you close the pr??
Ghost reopened this pull request 2021-09-20 10:04:58 +02:00
First-time contributor

what the heck? i press escape and things magically happen?

what the heck? i press escape and things magically happen?
Member

gitea is so bad...

gitea is so bad...
NO11 added 1 commit 2021-09-20 16:17:07 +02:00
AFCMS requested review from Ghost 2021-09-20 17:23:58 +02:00
NO11 added 1 commit 2021-09-27 22:00:16 +02:00
NO11 added 1 commit 2021-09-30 22:14:20 +02:00
NO11 requested review from AFCMS 2021-09-30 22:14:46 +02:00
Ghost approved these changes 2021-10-02 22:51:36 +02:00
Ghost left a comment
First-time contributor

LGTM and tests went well. (if only we had something like mineunit tho. but i digress)

LGTM and tests went well. (if only we had something like [mineunit](https://github.com/mt-mods/mineunit) tho. but i digress)
NO11 merged commit 6803d22dbd into master 2021-10-07 17:13:09 +02:00
NO11 deleted branch privs 2021-10-07 22:13:47 +02:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: VoxeLibre/VoxeLibre#1865
No description provided.