[MOD]Whitelist[whitelist]

User avatar
Pitriss
Member
 
Posts: 253
Joined: Mon Aug 05, 2013 17:09
GitHub: Pitriss
IRC: pitriss
In-game: pitriss

[MOD]Whitelist[whitelist]

by Pitriss » Thu Jan 02, 2014 20:04

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.

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 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

by fairiestoy » Thu Jan 02, 2014 21:02

Nice work. Though i have a suggestion. Maybe transform this 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.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: 253
Joined: Mon Aug 05, 2013 17:09
GitHub: Pitriss
IRC: pitriss
In-game: pitriss

by Pitriss » Thu Jan 02, 2014 21:17

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
Member
 
Posts: 3598
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker

by Krock » Thu Jan 02, 2014 21:23

Pitriss wrote:
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
..
        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:
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
privs = {basic_privs=true},

and it should say that itself.
Newest Win32 builds - Find a mod - All my mods
ALL YOUR DONATION ARE BELONG TO PARAMAT (Please support him and Minetest)
New DuckDuckGo !bang: !mtmod <keyword here>
 

User avatar
Pitriss
Member
 
Posts: 253
Joined: Mon Aug 05, 2013 17:09
GitHub: Pitriss
IRC: pitriss
In-game: pitriss

by Pitriss » Thu Jan 02, 2014 21:47

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.
 


Return to WIP Mods

Who is online

Users browsing this forum: Google [Bot] and 48 guests

cron