Grant Missing Privileges

User avatar
octacian
Member
 
Posts: 408
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian

Grant Missing Privileges

by octacian » Fri Aug 12, 2016 22:20

I'm trying to build a ranking module for my servertools mod, which lets you easily set a player's privs with ranks. It also shows the player's rank in chat, but that's off topic.

When a player joins, I check their rank, get the privileges in that rank, and then check to see if they are missing any privileges. If they are, I attempt to grant them the missing privilege(s). That's where I have a problem. minetest.check_player_privs returns a table of missing privileges, however, if the player were (for example) missing the fast privilege, the table has this entry: "fast". I then try to iterate through the table with a loop and grant each missing privilege, but that seems impossible since I must first get the player privileges, and then do privs.fast = true, raplacing fast with the name of the missing privilege.

How do I do this? Or should I be taking a completely different approach?


Current Code:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local privs = minetest.get_player_privs(name) -- get privileges
      local has, missing_privs = minetest.check_player_privs(name, servertools.get_rank_privs(servertools.get_player_rank(name))) -- check privs
      if missing_privs ~= "" then
        for _,i in pairs(missing_privs) do
          table.insert(privs, i) -- insert missing priv
          minetest.log("action", "After Insertion: "..dump(privs))
        end
        minetest.chat_send_player(name, "Granting missing rank privileges.")
      end
'

servertools.get_rank_privs, obviously, returns the privileges of the rank in the same formap as minetest.get_player_privs. servertools.get_player_rank gets the rank of a player. Both of these functions have been proven to work, the only problem is granting the missing privileges.
God isn't dead!

My Coolest Mods:
MicroExpansion, Working Computers, Interchangeable Hands

Check out my YouTube channel! (octacian)
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: Grant Missing Privileges

by kaeza » Sat Aug 13, 2016 01:38

I don't recall off the top of my head if `missing_privs` is a list or a mapping, and too lazy to actually check, so...

If it's a list:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
for _, key in ipairs(missing) do
  new_privs[key] = true
end


If it's a mapping:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
for key in pairs(missing) do -- Note: `pairs` without 'i'
  new_privs[key] = true
end


Of course, you should `minetest.set_player_privs(name, new_privs)` afterward.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
octacian
Member
 
Posts: 408
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian

Re: Grant Missing Privileges

by octacian » Sun Aug 14, 2016 16:58

Thanks! I can't believe I actually forgot there was two ways to access tables..
God isn't dead!

My Coolest Mods:
MicroExpansion, Working Computers, Interchangeable Hands

Check out my YouTube channel! (octacian)
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 6 guests

cron