Add Initial Development Files

This commit is contained in:
Muhammad Rifqi Priyo Susanto 2014-12-24 20:51:40 +07:00
parent 2c5b0b8085
commit 790d3f8104
4 changed files with 75 additions and 0 deletions

18
README.md Normal file
View File

@ -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 <player>
```
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.

18
README.txt Normal file
View File

@ -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 <player>
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.

0
depends.txt Normal file
View File

39
init.lua Normal file
View File

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