restrict mod to special users

BlindBanana
Member
 
Posts: 23
Joined: Sun Mar 17, 2013 13:33

restrict mod to special users

by BlindBanana » Sun Mar 17, 2013 13:40

Hi everyone!

Is there a way to restrict some mod, lets say nuke to only some users, like the server admin?

For example with some addition to the grant command:
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
/grant <username> <modname>
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Sun Mar 17, 2013 14:24

This has to be implemented into the mod. The engine doesnt offer any commands for that, except the privilege system (but the mod has to use it).
 

BlindBanana
Member
 
Posts: 23
Joined: Sun Mar 17, 2013 13:33

by BlindBanana » Sun Mar 17, 2013 14:49

Are there any examples for this? Or can you give me some hints to implement this by myself?
Right now I have no idea how to start.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Sun Mar 17, 2013 15:00

You basically register a new privilege and check if a player has this when interacting.
For example if the nuke explodes when the player rightclicks it, then just do:
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
minetest.register_node("nuke", {
    ...
    on_rightclick = function(pos, node, player)
        if minetest.check_player_privs(player:get_player_name(), {nuke=true}) then
            code here
        end
    end,
})

Maybe useful:
http://dev.minetest.net/register_privilege
http://dev.minetest.net/check_player_privs
http://dev.minetest.net/register_node#Primary_Callbacks
Last edited by PilzAdam on Sun Mar 17, 2013 15:00, edited 1 time in total.
 

BlindBanana
Member
 
Posts: 23
Joined: Sun Mar 17, 2013 13:33

by BlindBanana » Sun Mar 17, 2013 17:31

Based on the mod nuke version 1.4 from sfan5 http://forum.minetest.net/viewtopic.php?id=638

I modified the init.lua file.

At the verry beginning I register a new privilege (add before the first line):
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
minetest.register_privilege("nuke", {
    description = "Can use TNT from mod nuke",
    give_to_singleplayer = false
})


After this, I modified every register_on_punchnode function to check the newly registerd privilege:
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
minetest.register_on_punchnode(function(p, node, puncher)
    if node.name == "nuke:iron_tnt" then
        minetest.env:remove_node(p)
        local p_name = puncher:get_player_name()
        if minetest.check_player_privs(p_name, {nuke=false}) then
            -- player doesn''t have privilege --> cancel explosion
            minetest.chat_send_player(p_name, "privilege nuke required: defuse!")
            nodeupdate(p)
        end
        if minetest.check_player_privs(p_name, {nuke=true}) then
            -- player has privilege --> explode
            minetest.chat_send_player(p_name, "privilege nuke found: explode!")
            spawn_tnt(p, "nuke:iron_tnt")
            nodeupdate(p)
        end
    end
end)


This works.

Nobody has the privilege "nuke" by default (except maybe the serveradmin). The TNT gets defused and removed as it should.

If somebody has the privilege, the TNT explodes. But in this case both messages "privilege nuke required: defuse!" and "privilege nuke found: explode!" are sent to the player. This one thing i don't understand. Only "privilege nuke found: explode!" should be sent to the player.
Last edited by BlindBanana on Mon Mar 18, 2013 22:12, edited 1 time in total.
 

BlindBanana
Member
 
Posts: 23
Joined: Sun Mar 17, 2013 13:33

by BlindBanana » Mon Mar 18, 2013 22:11

Stupid! Just reverse it and use elseif..

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
minetest.register_on_punchnode(function(p, node, puncher)
    if node.name == "nuke:iron_tnt" then
        minetest.env:remove_node(p)
        local p_name = puncher:get_player_name()
        if minetest.check_player_privs(p_name, {nuke=true}) then
            -- player has privilege --> explode
            minetest.chat_send_player(p_name, "privilege nuke found: explode!")
            spawn_tnt(p, "nuke:iron_tnt")
            nodeupdate(p)
        elseif minetest.check_player_privs(p_name, {nuke=false}) then
            -- player doesn''t have privilege --> cancel explosion
            minetest.chat_send_player(p_name, "privilege nuke required: defuse!")
            nodeupdate(p)
        else
            minetest.chat_send_player(p_name, "nuke mod: this should never be seen!")
        end
    end
end)
Last edited by BlindBanana on Mon Mar 18, 2013 22:12, edited 1 time in total.
 

User avatar
jojoa1997
Member
 
Posts: 2890
Joined: Thu Dec 13, 2012 05:11

by jojoa1997 » Mon Mar 18, 2013 22:16

That is what I do with my npc mod. You need a priv to place spawners so people can't overload the servers.
Coding;
1X coding
3X debugging
12X tweaking to be just right
 


Return to Minetest Features

Who is online

Users browsing this forum: No registered users and 8 guests

cron