SHOW:
|
|
- or go back to the newest paste.
| 1 | -- *********************************************************************************** | |
| 2 | -- Nick/IP Range Bans ***************************************** | |
| 3 | -- *********************************************************************************** | |
| 4 | NICKBANS = {}
| |
| 5 | ||
| 6 | local write_nickbans = function() | |
| 7 | local f = io.open(minetest.get_worldpath()..'/.nickbans', "w") | |
| 8 | f:write(minetest.serialize(NICKBANS)) | |
| 9 | io.close(f) | |
| 10 | end | |
| 11 | local gonfile = io.open(minetest.get_worldpath()..'/.nickbans', "r") | |
| 12 | if gonfile then | |
| 13 | local contents = gonfile:read() | |
| 14 | io.close(gonfile) | |
| 15 | if contents ~= nil then | |
| 16 | NICKBANS = minetest.deserialize(contents) | |
| 17 | end | |
| 18 | end | |
| 19 | local default_ban = minetest.ban_player | |
| 20 | function minetest.ban_player(playername) | |
| 21 | NICKBANS[playername] = true | |
| 22 | write_nickbans() | |
| 23 | return default_ban(playername) | |
| 24 | end | |
| 25 | ||
| 26 | IPRBANS = {}
| |
| 27 | local add_ip_range = function(range) | |
| 28 | local ipr = string.split(range,'.') | |
| 29 | if table.getn(ipr) < 3 then return end | |
| 30 | if not IPRBANS[ipr[1]] then IPRBANS[ipr[1]] = {} end
| |
| 31 | if not IPRBANS[ipr[1]][ipr[2]] then IPRBANS[ipr[1]][ipr[2]] = {} end
| |
| 32 | if not IPRBANS[ipr[1]][ipr[2]][ipr[3]] then IPRBANS[ipr[1]][ipr[2]][ipr[3]] = true end | |
| 33 | end | |
| 34 | ||
| 35 | --add_ip_range('66.66.66') -- test range
| |
| 36 | ||
| 37 | minetest.register_on_joinplayer(function(player) | |
| 38 | player = player:get_player_name() | |
| 39 | if NICKBANS[player] or string.match(player,"%d%d(%d+)") then -- or string.match(player,"Guest%d%d%d%d") | |
| 40 | minetest.ban_player(player) | |
| 41 | minetest.log("action", player.." banned [nick]")
| |
| 42 | end | |
| 43 | local ip = string.split(minetest.get_player_ip(player),'.') | |
| 44 | if IPRBANS[ip[1]] and IPRBANS[ip[1]][ip[2]] and IPRBANS[ip[1]][ip[2]][ip[3]] then | |
| 45 | minetest.ban_player(player) | |
| 46 | minetest.log("action", player.." banned [ip-range]")
| |
| 47 | end | |
| 48 | ||
| 49 | end) |