From 790d3f810408f7c53f9917261d483f2d5bd26936 Mon Sep 17 00:00:00 2001 From: Muhammad Rifqi Priyo Susanto Date: Wed, 24 Dec 2014 20:51:40 +0700 Subject: [PATCH] Add Initial Development Files --- README.md | 18 ++++++++++++++++++ README.txt | 18 ++++++++++++++++++ depends.txt | 0 init.lua | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 README.md create mode 100644 README.txt create mode 100644 depends.txt create mode 100644 init.lua diff --git a/README.md b/README.md new file mode 100644 index 0000000..b6aac79 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +advancedban +=========== +This mod will ban ONLY username, not the ip address. + +##Usage +```lua +advancedban.ban(player_name) +``` +or using chat commands: +``` +/advancedban +``` +This will add player to advancedban list. +This does NOT kick the player! + +###Parameter +- `FILE_NAME` = the name of file that contains list of banned player. +- `BAN_MESSAGE` = the message that will be sent to the banned player each time the player log-in. diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..8a72224 --- /dev/null +++ b/README.txt @@ -0,0 +1,18 @@ +advancedban +=========== +This mod will ban ONLY username, not the ip address. + +# Usage + + advancedban.ban(player_name) + + or using chat commands: + + /advancedban + +This will add player to advancedban list. +This does NOT kick the player! + +## Parameter +- FILE_NAME = the name of file that contains list of banned player. +- BAN_MESSAGE = the message that will be sent to the banned player each time the player log-in. diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..e69de29 diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..91346d6 --- /dev/null +++ b/init.lua @@ -0,0 +1,39 @@ +-- Advanced Ban [advancedban] by srifqi +advancedban = {} + +-- parameter +local FILE_NAME = "bannedplayerlist.txt" +local BAN_MESSAGE = "Your username is banned." + +function advancedban.ban(name) + local list = io.open(minetest.get_worldpath()..DIR_DELIM..FILE_NAME, "w") + list:write(name.."\n") + list:close() + minetest.log("action", name.." has been added to advancedban list.") -- print debug +end + +minetest.register_chatcommand("advancedban", { + privs = {ban = true}, + func = function(name, param) + advancedban.ban(param) + minetest.chat_send_player(name, param.." has been added to advancedban list.") + end, +}) + +minetest.register_on_joinplayer(function(player) + if file_exists(minetest.get_worldpath()..DIR_DELIM..FILE_NAME) == true then + local list = io.open(minetest.get_worldpath()..DIR_DELIM..FILE_NAME, "r") + for username in list:lines() do + local name = player:get_player_name() + if name == username then + minetest.after(0.1, function() + minetest.kick_player(name, BAN_MESSAGE) -- kick player + end) + end + end + list:close() + end +end) + +-- Minetest library - misc_helpers.lua +function file_exists(filename)local f=io.open(filename, "r");if f==nil then return false else f:close() return true end end