[MOD]Whitelist[whitelist]

Post Reply
User avatar
Pitriss
Member
Posts: 254
Joined: Mon Aug 05, 2013 17:09
GitHub: Pitriss
IRC: pitriss
In-game: pitriss
Location: Czech republic, Bohumin

[MOD]Whitelist[whitelist]

by Pitriss » Post

Simple whitelist mod.
You must specify admin name in minetest.conf to be able join server and setup allowed players.
For changing this setup use /allow <nickname> command. If you want someone to refuse playing on server just use /disallow <nickname> or delete him from allow.conf in your world directory. For these commands basic_privs are required.

Code: Select all

local config_file = minetest.get_worldpath().."/allow.conf"
--in case of not existant config file, it
--will create it
local file_desc = io.open(config_file, "a")
file_desc:close()

local config = Settings(config_file)

local admin_name = minetest.setting_get("name")
if admin_name ~= nil then
    config:set(admin_name, "true")
    config:write()
end


minetest.register_chatcommand("allow", {
    param = "allow <nickname>",
    privs = {basic_privs=true},
    description = "Allows joining for specified nickname.",
    func = function(name, param)
        local player = minetest.get_player_by_name(name)
        if not player then
            return
        end
        -- Handling parameter
        if param == "" then
            minetest.chat_send_player(name, "You must provide nickname to allow.");
            return
        else
            config:set(param, "true")
            config:write()
            minetest.chat_send_player(name, param.." is now allowed to join server.");
            return
        end
    end
})

minetest.register_chatcommand("disallow", {
    param = "disallow <nickname>",
    privs = {basic_privs=true},
    description = "Disallows joining for specified nickname.",
    func = function(name, param)
        local player = minetest.get_player_by_name(name)
        if not player then
            return
        end
        -- Handling parameter
        if param == "" then
            minetest.chat_send_player(name, "You must provide nickname to disallow.");
            return
        else
            config:set(param, "false")
            config:write()
            minetest.chat_send_player(name, param.." is now not allowed to join server.");
            return
        end
    end
})



minetest.register_on_prejoinplayer(function(name, ip)
    local joining = config:get_bool(name)
    if joining == nil or joining == false then
        minetest.chat_send_all("-!- Server "..name.." tried to join server.")
        return "Sorry you need permission to join this server."
    end
end)
Licence: WTFPL
Dependency: default

This mod was written in 10 minutes, so coding style is not perfect.

EDIT: Fixed privs handling. TY Krock
Last edited by Pitriss on Thu Jan 02, 2014 21:47, edited 1 time in total.
I reject your reality and substitute my own. (A. Savage, Mythbusters)
I'm not modding and/or playing minetest anymore. All my mods were released under WTFPL. You can fix/modify them yourself. Don't ask me for support. Thanks.

User avatar
fairiestoy
Member
Posts: 191
Joined: Sun Jun 09, 2013 19:25
Location: Germany

by fairiestoy » Post

Nice work. Though i have a suggestion. Maybe transform this line

Code: Select all

minetest.chat_send_all("-!- Server "..name.." tried to join server.")
into a log file or something. Since this current setup would allow people to flood your server with tons of
"-!- Server trololo tried to join server."
"-!- Server trololo tried to join server."
"-!- Server trololo tried to join server."
"-!- Server trololo tried to join server."
"-!- Server trololo tried to join server."
Saw something like that in another game, and it was more than annoying ;)
Interesting about new things is, to figure out how it works ...

User avatar
Pitriss
Member
Posts: 254
Joined: Mon Aug 05, 2013 17:09
GitHub: Pitriss
IRC: pitriss
In-game: pitriss
Location: Czech republic, Bohumin

by Pitriss » Post

Thanks. I'm aware of this.. But for our purpose it is better as it is now.. When someone will be abusing this, then I have no problem to handle this.. BTW logging is done automagically.
I reject your reality and substitute my own. (A. Savage, Mythbusters)
I'm not modding and/or playing minetest anymore. All my mods were released under WTFPL. You can fix/modify them yourself. Don't ask me for support. Thanks.

User avatar
Krock
Developer
Posts: 4572
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

by Krock » Post

Pitriss wrote:

Code: Select all

..
        if not minetest.check_player_privs(name, {basic_privs}) then
            minetest.chat_send_player(name, "Hey "..name..", you are not allowed to use that command. Privs needed: basic_privs");
            return
        end

...
        if not minetest.check_player_privs(name, {basic_privs}) then
            minetest.chat_send_player(name, "Hey "..name..", you are not allowed to use that command. Privs needed: basic_privs");
            return
        end
...
This mod was written in 10 minutes, so coding style is not perfect.
Yes, im my view are the codes abrove totally useless, just add this:

Code: Select all

privs = {basic_privs=true},
and it should say that itself.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
Pitriss
Member
Posts: 254
Joined: Mon Aug 05, 2013 17:09
GitHub: Pitriss
IRC: pitriss
In-game: pitriss
Location: Czech republic, Bohumin

by Pitriss » Post

Ok fixed, TY.
I reject your reality and substitute my own. (A. Savage, Mythbusters)
I'm not modding and/or playing minetest anymore. All my mods were released under WTFPL. You can fix/modify them yourself. Don't ask me for support. Thanks.

Post Reply

Who is online

Users browsing this forum: sirrobzeroone and 3 guests