Replace all my mods with submodules
parent
dfd3ec26f5
commit
f9de9038d2
|
@ -0,0 +1,19 @@
|
|||
[submodule "mods/serverlist_score"]
|
||||
path = mods/serverlist_score
|
||||
url = https://github.com/Lejo1/serverlist_score
|
||||
[submodule "mods/getip"]
|
||||
path = mods/getip
|
||||
url = https://github.com/Lejo1/getip
|
||||
[submodule "mods/vps_blocker"]
|
||||
path = mods/vps_blocker
|
||||
url = https://github.com/Lejo1/vps_blocker
|
||||
[submodule "mods/playtime"]
|
||||
path = mods/playtime
|
||||
url = https://github.com/Lejo1/playtime
|
||||
[submodule "mods/reportlist"]
|
||||
path = mods/reportlist
|
||||
url = https://github.com/Lejo1/reportlist
|
||||
[submodule "mods/xban2"]
|
||||
path = mods/xban2
|
||||
url = https://github.com/Lejo1/xban2
|
||||
branch = report
|
|
@ -7,7 +7,7 @@ This Repository is not for using on your own Server!
|
|||
|
||||
Installing
|
||||
----------
|
||||
1. `git clone https://github.com/Lejo1/subgames.git`
|
||||
1. `git clone --recursive https://github.com/Lejo1/subgames.git`
|
||||
|
||||
License
|
||||
-------
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit cd99dfb935b60591f33ccb042d1285e266fbac5a
|
|
@ -1,41 +0,0 @@
|
|||
# Compiled Lua sources
|
||||
luac.out
|
||||
|
||||
# luarocks build files
|
||||
*.src.rock
|
||||
*.zip
|
||||
*.tar.gz
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.os
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
*.def
|
||||
*.exp
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
# Getip
|
||||
Add a way to get ip's in Minetest.
|
||||
By just typing /getip <name>.
|
||||
You can also can get ips from not connected players, if they were online since the last server restart.
|
|
@ -1,36 +0,0 @@
|
|||
--[[ Getip
|
||||
Minetest Mod from Lejo
|
||||
Use it to get always the last ip of a player, if he isn't online.
|
||||
]]
|
||||
|
||||
getip = {}
|
||||
|
||||
local ip = {}
|
||||
|
||||
--Add the Privileg.
|
||||
minetest.register_privilege("ip", "Player can get ip's from other players")
|
||||
|
||||
--create new data for a player if it doesn't exist.
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
local players_ip = minetest.get_player_ip(name)
|
||||
ip[name] = players_ip
|
||||
end)
|
||||
|
||||
--Creat the Command /getip.
|
||||
minetest.register_chatcommand("getip", {
|
||||
params = "<player>",
|
||||
description = "Show other ips.",
|
||||
privs = {ip=true},
|
||||
func = function(name, player)
|
||||
if not minetest.get_player_by_name(player) then
|
||||
minetest.chat_send_player(name, "The Player is not online")
|
||||
if ip[player] then
|
||||
minetest.chat_send_player(name, "His last ip was: \""..ip[player].."\".")
|
||||
else minetest.chat_send_player(name, "There is no ip saved for this player.")
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(name, "The IP is \""..minetest.get_player_ip(player).."\".")
|
||||
end
|
||||
end,
|
||||
})
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 0ec16d00a6e404417ea99a080b4c3b95c1c5ddb6
|
|
@ -1,41 +0,0 @@
|
|||
# Compiled Lua sources
|
||||
luac.out
|
||||
|
||||
# luarocks build files
|
||||
*.src.rock
|
||||
*.zip
|
||||
*.tar.gz
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.os
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
*.def
|
||||
*.exp
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
|
@ -1 +0,0 @@
|
|||
CC0
|
|
@ -1,7 +0,0 @@
|
|||
# Playtime
|
||||
|
||||
This mod the function: playtime.get_current_playtime(name) / playtime.get_total_playtime(name)
|
||||
|
||||
License: CC0
|
||||
|
||||
Created by [Lejo](https://github.com/Lejo1)
|
|
@ -1,43 +0,0 @@
|
|||
playtime = {}
|
||||
|
||||
local storage = minetest.get_mod_storage()
|
||||
|
||||
function playtime.get_current_playtime(name)
|
||||
return os.time() - storage:get_int(name.."-join")
|
||||
end
|
||||
|
||||
-- Function to get playtime
|
||||
function playtime.get_total_playtime(name)
|
||||
return storage:get_int(name) + playtime.get_current_playtime(name)
|
||||
end
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
storage:set_int(name, storage:get_int(name) + (os.time() - storage:get_int(name.."-join")))
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
storage:set_int(name.."-join", os.time())
|
||||
end)
|
||||
|
||||
local function SecondsToClock(seconds)
|
||||
local seconds = tonumber(seconds)
|
||||
|
||||
if seconds <= 0 then
|
||||
return "00:00:00";
|
||||
else
|
||||
hours = string.format("%02.f", math.floor(seconds/3600));
|
||||
mins = string.format("%02.f", math.floor(seconds/60 - (hours*60)));
|
||||
secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60));
|
||||
return hours..":"..mins..":"..secs
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("playtime", {
|
||||
params = "",
|
||||
description = "Use it to get your own playtime!",
|
||||
func = function(name)
|
||||
minetest.chat_send_player(name, "Total: "..SecondsToClock(playtime.get_total_playtime(name)).." Current: "..SecondsToClock(playtime.get_current_playtime(name)))
|
||||
end,
|
||||
})
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 7d11ba608bf0512e59b0c72e51ba9db7bc014d38
|
|
@ -1,41 +0,0 @@
|
|||
# Compiled Lua sources
|
||||
luac.out
|
||||
|
||||
# luarocks build files
|
||||
*.src.rock
|
||||
*.zip
|
||||
*.tar.gz
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.os
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
*.def
|
||||
*.exp
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
|
@ -1 +0,0 @@
|
|||
CC0
|
|
@ -1,18 +0,0 @@
|
|||
# Reportlist
|
||||
|
||||
This mod add a report list of players to minetest.
|
||||
|
||||
A Player can only report an other player ones!
|
||||
|
||||
Players can be reported by just typing /report <name>
|
||||
|
||||
You can show the report count using: /report_get <name>
|
||||
|
||||
And set it with: /report_set <name> <amount>
|
||||
|
||||
Depends: xban2
|
||||
[Here](https://github.com/Lejo1/xban2/tree/report) is a xban2 fork with report count in gui.
|
||||
|
||||
License: CC0
|
||||
|
||||
Created by [Lejo](https://github.com/Lejo1)
|
|
@ -1 +0,0 @@
|
|||
xban2
|
|
@ -1,174 +0,0 @@
|
|||
--[[This is a mod that contains a player register with the count of the reports.
|
||||
Mod created by Lejo!]]
|
||||
report = {
|
||||
report_on_cheat = {
|
||||
enable = true,
|
||||
only_one_report_per_cheat = false,
|
||||
report_count_on_cheat = 1,
|
||||
player_message_on_report_cheat = true,
|
||||
global_chat_message_on_report_cheat = false,
|
||||
},
|
||||
autoban = false,
|
||||
autotempban = false,
|
||||
ban_notification_in_chat = false,
|
||||
time_played_to_report = 3600, -- in seconds Only needed when useing playtime
|
||||
}
|
||||
reportfunc = {}
|
||||
|
||||
function reportfunc.set_count(name, amount)
|
||||
local e = xban.find_entry(name)
|
||||
e.reported = amount
|
||||
reportfunc.check_ban(name)
|
||||
end
|
||||
|
||||
function reportfunc.get_count(name)
|
||||
local e = xban.find_entry(name)
|
||||
if e and e.reporter then
|
||||
return e.reported
|
||||
else return 0
|
||||
end
|
||||
end
|
||||
|
||||
function reportfunc.is_reporter(name, reportername)
|
||||
local reporterentry = xban.find_entry(reportername)
|
||||
local e = xban.find_entry(name)
|
||||
if e.reporter and reporterentry.names then
|
||||
for testi,value in ipairs(e.reporter) do
|
||||
if reporterentry.names[value] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function reportfunc.add_reporter(name, reportername)
|
||||
local reportertable = xban.find_entry(name)
|
||||
if not table.contains(reportertable.reporter, reportername) then
|
||||
table.insert(reportertable.reporter, reportername)
|
||||
end
|
||||
end
|
||||
|
||||
--Create player acout if there is no
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
local e = xban.find_entry(name)
|
||||
if e and not e.reported then
|
||||
e.reported = 0
|
||||
e.reporter = {}
|
||||
end
|
||||
reportfunc.check_ban(name)
|
||||
end)
|
||||
|
||||
-- Auto ban players
|
||||
function reportfunc.check_ban(name)
|
||||
if reportfunc.get_count(name) >= 20 and report.autoban == true then
|
||||
xban.ban_player(name, "Reportmod", nil, "You have been reported 20 times or cheated to much! Make sure you are useing an orginal minetest client.")
|
||||
minetest.log("action", "Player "..name.." has been baned after he got reported 20 times.")
|
||||
if report.ban_notification_in_chat == true then
|
||||
minetest.chat_send_all("Player "..name.." has been baned, because he has been reported 20 times or cheated to much!")
|
||||
end
|
||||
elseif reportfunc.get_count(name) >= 10 and report.autotempban == true and not xban.get_record(name) then
|
||||
xban.ban_player(name, "Reportmod", os.time()+259200, "You have been reported 10 times or cheated to much!")
|
||||
minetest.log("action", "Player "..name.." has been baned for three days after he got reported 10 times.")
|
||||
if report.ban_notification_in_chat == true then
|
||||
minetest.chat_send_all("Player "..name.." has been baned for three days, because he has been reported 10 times or cheated to much!")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- May report players on cheat
|
||||
if report.report_on_cheat["enable"] == true then
|
||||
minetest.register_on_cheat(function(player, cheat)
|
||||
local name = player:get_player_name()
|
||||
if cheat.type == "dug_unbreakable" or cheat.type == "dug_too_fast" then
|
||||
local reporthim = true
|
||||
if report.report_on_cheat["only_one_report_per_cheat"] == true then
|
||||
if reportfunc.is_reporter(name, cheat.type) == true then
|
||||
reporthim = false
|
||||
else reportfunc.add_reporter(name, cheat.type)
|
||||
end
|
||||
end
|
||||
if reporthim == true then
|
||||
local count = report.report_on_cheat["report_count_on_cheat"]
|
||||
reportfunc.set_count(name, reportfunc.get_count(name)+count)
|
||||
if report.report_on_cheat["player_message_on_report_cheat"] == true then
|
||||
minetest.chat_send_player(name, "Are you hacking/cheating? Stop it!")
|
||||
end
|
||||
if report.report_on_cheat["global_chat_message_on_report_cheat"] == true then
|
||||
minetest.chat_send_all(name.." is maybe hacking: "..cheat.type.." ! Have a look at him.")
|
||||
end
|
||||
minetest.log("action", "Player "..name.." has been reported automaticly by cheating with: "..cheat.type)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Add the report Command
|
||||
minetest.register_chatcommand("report", {
|
||||
privs = {shout=true},
|
||||
params = "<name>",
|
||||
description = "Use it to report players, if they are hacking, cheating...",
|
||||
func = function(name, param)
|
||||
local reportcount = 1
|
||||
if minetest.get_player_privs(name).ban then
|
||||
reportcount = 10
|
||||
elseif minetest.get_player_privs(name).kick then
|
||||
reportcount = 5
|
||||
end
|
||||
local ename = xban.find_entry(name)
|
||||
local eparam = xban.find_entry(param)
|
||||
if ename and eparam then
|
||||
if name ~= param and ename ~= eparam then
|
||||
if minetest.get_player_by_name(param) then
|
||||
if minetest.get_player_information(name).connection_uptime >= 480 then
|
||||
if not playtime or playtime.get_total_playtime(name) >= report.time_played_to_report then
|
||||
if reportfunc.is_reporter(param, name) ~= true then
|
||||
reportfunc.set_count(param, reportfunc.get_count(param)+reportcount)
|
||||
reportfunc.add_reporter(param, name)
|
||||
minetest.chat_send_player(name, param.." has been reported!")
|
||||
minetest.log("action", "Player "..param.." has been reported by "..name)
|
||||
else minetest.chat_send_player(name, "You have already have reported "..param.." or somebody out of his ip-Group!")
|
||||
end
|
||||
else minetest.chat_send_player(name, "You have to play longer to report a player!")
|
||||
end
|
||||
else minetest.chat_send_player(name, "You have to play longer to report a player!")
|
||||
end
|
||||
else minetest.chat_send_player(name, "The Player "..param.." is not online!")
|
||||
end
|
||||
else minetest.chat_send_player(name, "You can't report yourself or somebody out of you ip-Group.")
|
||||
end
|
||||
else minetest.chat_send_player(name, "The Player "..param.." don't exist.")
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Add a chat command to get the report counter
|
||||
minetest.register_chatcommand("report_get", {
|
||||
privs = {ban=true},
|
||||
params = "<name>",
|
||||
description = "Use it to get the report count of a player.",
|
||||
func = function(name, param)
|
||||
local count = reportfunc.get_count(param)
|
||||
if count ~= "" then
|
||||
minetest.chat_send_player(name, "The Player "..param.." has a reportcount of "..count.."!")
|
||||
else minetest.chat_send_player(name, "The Player "..param.." don't exist.")
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Add a chat command to set the report counter
|
||||
minetest.register_chatcommand("report_set", {
|
||||
privs = {ban=true},
|
||||
params = "<name> <amount>",
|
||||
description = "Use it to set the report count of a player.",
|
||||
func = function(name, param)
|
||||
local pname, amount1 = param:match("(%S+)%s+(.+)")
|
||||
local amount = tonumber(amount1)
|
||||
local count = reportfunc.get_count(pname)
|
||||
if count ~= "" and tonumber(amount) then
|
||||
reportfunc.set_count(pname, amount)
|
||||
minetest.chat_send_player(name, "The reportcount of the Player "..pname.." has been setted!")
|
||||
else minetest.chat_send_player(name, "The Player don't exist.")
|
||||
end
|
||||
end,
|
||||
})
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 6544d91baab2d9b9bd095ad3f7d658917f67e793
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 19c076aff02d33cce578eb330814a2fce178a72e
|
|
@ -1 +0,0 @@
|
|||
CC0
|
|
@ -1,29 +0,0 @@
|
|||
# Vps Blocker
|
||||
|
||||
This mod checks the ips of the player for vpns, proxys, or other hosting services.
|
||||
|
||||
It gets the information from nastyhosts.com and iphub.info
|
||||
|
||||
Installing
|
||||
----------
|
||||
|
||||
First you need to add vps_blocker to secure.http_mods to allow https requests.
|
||||
|
||||
If you want to use iphub.info you need to register there and paste your API key in the minetest config to iphub_key = 123
|
||||
|
||||
Set the kick message:
|
||||
|
||||
vps_kick_message = "You are using a proxy, vpn or other hosting services, please disable them to play on this server."
|
||||
|
||||
Commands
|
||||
--------
|
||||
|
||||
Use /vps_wl <add or remove> <name or ip> to allow people using vps.
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
The idea for the mod is taken from https://github.com/red-001/block_vps but it's a complete redo of it.
|
||||
|
||||
Created by [Lejo](https://github.com/Lejo1)
|
||||
License: CC0
|
|
@ -1,102 +0,0 @@
|
|||
-- Declear some default tables
|
||||
|
||||
local http = minetest.request_http_api()
|
||||
assert(http ~= nil, "You need to add vps_blocker to secure.http_mods")
|
||||
|
||||
local kick_message = minetest.settings:get("vps_kick_message") or "You are using a proxy, vpn or other hosting services, please disable them to play on this server."
|
||||
local iphub_key = minetest.settings:get("iphub_key")
|
||||
|
||||
vps_blocker = {}
|
||||
local storage = minetest.get_mod_storage()
|
||||
--[[
|
||||
modstorage of ip == 0 not checked yet
|
||||
== 1 checked allow
|
||||
== 2 checked deny
|
||||
== 3 checking
|
||||
]]
|
||||
|
||||
-- Add the main ipcheckup function
|
||||
function vps_blocker.check_ip(name, ip)
|
||||
-- First nastyhosts request only if iphub is not used
|
||||
if not iphub_key then
|
||||
storage:set_int(ip, 3)
|
||||
local req = {
|
||||
["url"] = "http://v1.nastyhosts.com/"..ip
|
||||
}
|
||||
local callback = function(result)
|
||||
local data = minetest.parse_json(result.data)
|
||||
if result.completed and result.succeeded and data and data.status == 200 then -- Correct request
|
||||
if data.suggestion == "deny" then
|
||||
storage:set_int(ip, 2)
|
||||
elseif storage:get_int(ip) ~= 2 then
|
||||
storage:set_int(ip, 1)
|
||||
end
|
||||
vps_blocker.handle_player(name, ip)
|
||||
else minetest.log("error", "vps_blocker: Incorrect request!")
|
||||
end
|
||||
end
|
||||
http.fetch(req, callback)
|
||||
|
||||
else -- Second may iphub request
|
||||
local ireq = {
|
||||
["url"] = "http://v2.api.iphub.info/ip/"..ip,
|
||||
["extra_headers"] = {"X-Key: "..iphub_key}
|
||||
}
|
||||
local icallback = function(result)
|
||||
local data = minetest.parse_json(result.data)
|
||||
if result.completed and result.succeeded and data and data.block then -- Correct request
|
||||
if data.block == 1 then
|
||||
storage:set_int(ip, 2)
|
||||
elseif storage:get_int(ip) ~= 2 then
|
||||
storage:set_int(ip, 1)
|
||||
end
|
||||
vps_blocker.handle_player(name, ip)
|
||||
else minetest.log("error", "vps_blocker: Incorrect request!")
|
||||
end
|
||||
end
|
||||
http.fetch(ireq, icallback)
|
||||
end
|
||||
end
|
||||
|
||||
-- Add a function which handels what do do(check, kick, nth...)
|
||||
function vps_blocker.handle_player(name, ip)
|
||||
if not name or not ip or storage:get_int(ip) == 1 or storage:get_int(name) == 1 then
|
||||
return
|
||||
end
|
||||
if storage:get_int(ip) == 0 then
|
||||
vps_blocker.check_ip(name, ip)
|
||||
end
|
||||
if storage:get_int(ip) == 2 then
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
minetest.kick_player(name, kick_message)
|
||||
else return kick_message
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Do handle_player on prejoin and norma join
|
||||
minetest.register_on_prejoinplayer(vps_blocker.handle_player)
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
local ip = minetest.get_player_ip(name)
|
||||
vps_blocker.handle_player(name, ip)
|
||||
end)
|
||||
|
||||
-- Add a command to whitelist players
|
||||
minetest.register_chatcommand("vps_wl", {
|
||||
description = "Allow a player to use vps services.",
|
||||
params = "<add or remove> <name or ip>",
|
||||
privs = {server=true},
|
||||
func = function(name, params)
|
||||
local p = string.split(params, " ")
|
||||
if p[1] == "add" then
|
||||
storage:set_int(p[2], 1)
|
||||
return true, "Added "..p[2].." to the whitelist."
|
||||
elseif p[1] == "remove" then
|
||||
storage:set_int(p[2], 0)
|
||||
return true, "Removed "..p[2].." from the whitelist."
|
||||
else return false, "Invalid Input"
|
||||
end
|
||||
end
|
||||
})
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 01870693084f0449ec6f12db9cdc21734fcedc7d
|
|
@ -1,7 +0,0 @@
|
|||
|
||||
unused_args = false
|
||||
allow_defined_top = true
|
||||
|
||||
read_globals = {
|
||||
"minetest",
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
|
||||
# Extended Ban Mod for Minetest
|
||||
|
||||
This mod attempts to be an improvement to Minetest's ban system.
|
||||
|
||||
* It supports normal bans and temporary bans (from 60 seconds up to the end of
|
||||
time, with 1 second granularity).
|
||||
* Records and joins all accounts using the same IP address and several IP
|
||||
addresses using the same name into a single record, and can ban/unban them as
|
||||
a single user.
|
||||
* Can ban offline players if you know their IP or username.
|
||||
* Holds a record of bans for each user, so moderators and administrators can
|
||||
consult it to know if a player is a repeat offender.
|
||||
* Does not modify the default ban database in any way (`ipban.txt').
|
||||
* Has an API to ban and check the ban database to allows other mods to manage
|
||||
users (for example, anticheat mods).
|
||||
|
||||
## Chat commands
|
||||
|
||||
The mod provides the following chat commands. All commands require the `ban`
|
||||
privilege.
|
||||
|
||||
### `xban`
|
||||
|
||||
Bans a player permanently.
|
||||
|
||||
**Usage:** `/xban <player_or_ip> <reason>`
|
||||
|
||||
**Example:** `/xban 127.0.0.1 Some reason.`
|
||||
|
||||
### `xtempban`
|
||||
|
||||
Bans a player temporarily.
|
||||
|
||||
**Usage:** `/xtempban <player_or_ip> <time> <reason>`
|
||||
|
||||
The `time` parameter is a string in the format `<count><unit>` where `<unit>`
|
||||
is one of `s` for seconds, `m` for minutes, `h` for hours, `D` for days, `W`
|
||||
for weeks, `M` for months, or `Y` for years. If the unit is omitted, it is
|
||||
assumed to mean seconds. For example, `42s` means 42 seconds, `1337m` 1337
|
||||
minutes, and so on. You can chain more than one such group and they will add
|
||||
up. For example, `1Y3M3D7h` will ban for 1 year, 3 months, 3 days and 7 hours.
|
||||
|
||||
**Example:** `/xtempban Joe 3600 Some reason.`
|
||||
|
||||
### `xunban`
|
||||
|
||||
Unbans a player.
|
||||
|
||||
**Usage:** `/xunban <player_or_ip>`
|
||||
|
||||
**Example:** `/xunban Joe`
|
||||
|
||||
### `xban_record`
|
||||
|
||||
Shows the ban record on chat.
|
||||
|
||||
**Usage:** `/xban_record <player_or_ip>`
|
||||
|
||||
This prints one ban entry per line, with the time the ban came into effect,
|
||||
the expiration time (if applicable), the reason, and the source of the ban.
|
||||
The record is printed to chat with one entry per line.
|
||||
|
||||
**Example:** `/xban_record Joe`
|
||||
|
||||
### `xban_wl`
|
||||
|
||||
Manages the whitelist.
|
||||
|
||||
**Usage:** `/xban_wl (add|del|get) <player_or_ip>`
|
||||
|
||||
Whitelisted players are allowed on the server even if it's otherwise marked
|
||||
as banned. This is useful to only allow certain users from shared computers,
|
||||
for example.
|
||||
|
||||
The `add` subcommand adds the player to the whitelist. The `del` subcommand
|
||||
removes the player from the whitelist. The `get` subcommand checks if the
|
||||
player is in the whitelist, and prints the status to chat.
|
||||
|
||||
**Example:** `/xban_record add Jane`
|
||||
|
||||
### `xban_gui`
|
||||
|
||||
Shows a form to consult the database interactively.
|
||||
|
||||
**Usage:** `/xban_gui`
|
||||
|
||||
## Administrator commands
|
||||
|
||||
The following commands require the `server` privilege, so they are only
|
||||
available to server administrators.
|
||||
|
||||
### `xban_dbi`
|
||||
|
||||
Imports ban entries from other database formats.
|
||||
|
||||
**Usage:** `/xban_dbi <importer>`
|
||||
|
||||
The `importer` argument specifies from which database to import. These are
|
||||
the supported import plugins at the time of writing:
|
||||
|
||||
* `minetest`: Import entries from Minetest's ban list (`ipban.txt`).
|
||||
* `v1`: Old format used by xban (`players.iplist`).
|
||||
* `v2`: Old format used by xban (`players.iplist.v2`).
|
||||
|
||||
**Example:** `/xban_dbi minetest`
|
|
@ -1,15 +0,0 @@
|
|||
{
|
||||
"name": "xban2",
|
||||
"description": "Ban system extension with support for temporary bans.",
|
||||
"keywords": [
|
||||
"ban",
|
||||
"administration",
|
||||
"system",
|
||||
"server"
|
||||
],
|
||||
"homepage": "http://github.com/kaeza/minetest-xban2.git",
|
||||
"authors": [
|
||||
"Diego Martínez <lkaezadl3@yahoo.com>"
|
||||
],
|
||||
"license": "BSD 2-Clause"
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
|
||||
xban.importers = { }
|
||||
|
||||
dofile(xban.MP.."/importers/minetest.lua")
|
||||
dofile(xban.MP.."/importers/v1.lua")
|
||||
dofile(xban.MP.."/importers/v2.lua")
|
||||
|
||||
minetest.register_chatcommand("xban_dbi", {
|
||||
description = "Import old databases",
|
||||
params = "<importer>",
|
||||
privs = { server=true },
|
||||
func = function(name, params)
|
||||
if params == "--list" then
|
||||
local importers = { }
|
||||
for importer in pairs(xban.importers) do
|
||||
table.insert(importers, importer)
|
||||
end
|
||||
minetest.chat_send_player(name,
|
||||
("[xban] Known importers: %s"):format(
|
||||
table.concat(importers, ", ")))
|
||||
return
|
||||
elseif not xban.importers[params] then
|
||||
minetest.chat_send_player(name,
|
||||
("[xban] Unknown importer `%s'"):format(params))
|
||||
minetest.chat_send_player(name, "[xban] Try `--list'")
|
||||
return
|
||||
end
|
||||
local f = xban.importers[params]
|
||||
local ok, err = f()
|
||||
if ok then
|
||||
minetest.chat_send_player(name,
|
||||
"[xban] Import successfull")
|
||||
else
|
||||
minetest.chat_send_player(name,
|
||||
("[xban] Import failed: %s"):format(err))
|
||||
end
|
||||
end,
|
||||
})
|
|
@ -1,32 +0,0 @@
|
|||
|
||||
## Extended Ban Mod API
|
||||
|
||||
### ban_player
|
||||
|
||||
`xban.ban_player(player_or_ip, source, expires, reason)`
|
||||
|
||||
Ban a player and all of his/her alternative names and IPs.
|
||||
|
||||
#### Arguments:
|
||||
|
||||
* `player_or_ip` - Player to search for and ban. See note 1 below.
|
||||
* `source` - Source of the ban. See note 2 below.
|
||||
* `expires` - Time at which the ban expires. If nil, ban is permanent.
|
||||
* `reason` - Reason for ban.
|
||||
|
||||
### unban_player
|
||||
|
||||
`xban.unban_player(player_or_ip, source)`
|
||||
|
||||
Unban a player and all of his/her alternative names and IPs.
|
||||
|
||||
#### Arguments:
|
||||
|
||||
* `player_or_ip` - Player to search for and unban.
|
||||
* `source` - Source of the ban. See note 2 below.
|
||||
|
||||
### Notes
|
||||
|
||||
* 1: If player is currently online, all his accounts are kicked.
|
||||
* 2: Mods using the xban API are advised to use the `"modname:source"`
|
||||
format for `source` (for example: `"anticheat:main"`).
|
|
@ -1,45 +0,0 @@
|
|||
|
||||
Database is a regular Lua script that returns a table.
|
||||
|
||||
Table has a single named field `timestamp' containing the time_t the
|
||||
DB was last saved. It's not used in the mod and is only meant for
|
||||
external use (I don't find filesystem timestamps too reliable).
|
||||
|
||||
Next is a simple array (number indices) of entries.
|
||||
|
||||
Each entry contains following fields:
|
||||
|
||||
[1] = {
|
||||
-- Names/IPs associated with this entry
|
||||
names = {
|
||||
["foo"] = true,
|
||||
["bar"] = true,
|
||||
["123.45.67.89"] = true,
|
||||
},
|
||||
banned = true, -- Whether this user is banned
|
||||
-- Other fields do not apply if false
|
||||
time = 12341234, -- Time of last ban (*1)
|
||||
expires = 43214321 -- Time at which ban expires (*2)
|
||||
-- If nil, permanent ban
|
||||
reason = "asdf", -- Reason for ban
|
||||
source = "qwerty", -- Source of ban (*2)
|
||||
record = {
|
||||
[1] = {
|
||||
source = "asdf",
|
||||
reason = "qwerty",
|
||||
time = 12341234,
|
||||
expires = 43214321,
|
||||
},
|
||||
[1] = {
|
||||
source = "asdf",
|
||||
reason = "Unbanned", -- When unbanned
|
||||
time = 12341234,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Notes:
|
||||
(*1) All times are expressed in whatever unit `os.time()' uses
|
||||
(`time_t' on most (all?) systems).
|
||||
(*2) Mods using the xban API are advised to use the "modname:source"
|
||||
format for `source' (for example: "anticheat:main").
|
|
@ -1,194 +0,0 @@
|
|||
|
||||
local FORMNAME = "xban2:main"
|
||||
local MAXLISTSIZE = 100000000000000
|
||||
|
||||
local strfind, format = string.find, string.format
|
||||
|
||||
local ESC = minetest.formspec_escape
|
||||
|
||||
local function make_list(filter)
|
||||
filter = filter or ""
|
||||
local list, n, dropped = { }, 0, false
|
||||
for _, e in ipairs(xban.db) do
|
||||
for name in pairs(e.names) do
|
||||
if strfind(name, filter, 1, true) then
|
||||
if n >= MAXLISTSIZE then
|
||||
dropped = true
|
||||
break
|
||||
end
|
||||
n=n+1 list[n] = name
|
||||
end
|
||||
end
|
||||
end
|
||||
table.sort(list)
|
||||
return list, dropped
|
||||
end
|
||||
|
||||
local states = { }
|
||||
|
||||
local function get_state(name)
|
||||
local state = states[name]
|
||||
if not state then
|
||||
state = { index=1, filter="" }
|
||||
states[name] = state
|
||||
state.list, state.dropped = make_list()
|
||||
end
|
||||
return state
|
||||
end
|
||||
|
||||
local function get_record_simple(name)
|
||||
local e = xban.find_entry(name)
|
||||
if not e then
|
||||
return nil, ("No entry for `%s'"):format(name)
|
||||
elseif (not e.record) or (#e.record == 0) then
|
||||
return nil, ("`%s' has no ban records"):format(name)
|
||||
end
|
||||
local record = { }
|
||||
for _, rec in ipairs(e.record) do
|
||||
local msg = (os.date("%Y-%m-%d %H:%M:%S", rec.time).." | "
|
||||
..(rec.reason or "No reason given."))
|
||||
table.insert(record, msg)
|
||||
end
|
||||
return record, e.record
|
||||
end
|
||||
|
||||
local function make_reporter(name)
|
||||
local e = xban.find_entry(name)
|
||||
if e then
|
||||
if e.reporter and e.reporter ~= {} then
|
||||
return table.concat(e.reporter, " ")
|
||||
else return "This player has not been reportet yet."
|
||||
end
|
||||
else return "Missing player data"
|
||||
end
|
||||
end
|
||||
|
||||
-- checks if a string represents an ip address
|
||||
-- @return true or false
|
||||
local function isIpAddress(ip)
|
||||
if not ip then return false end
|
||||
local a,b,c,d=ip:match("^(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)$")
|
||||
a=tonumber(a)
|
||||
b=tonumber(b)
|
||||
c=tonumber(c)
|
||||
d=tonumber(d)
|
||||
if not a or not b or not c or not d then return false end
|
||||
if a<0 or 255<a then return false end
|
||||
if b<0 or 255<b then return false end
|
||||
if c<0 or 255<c then return false end
|
||||
if d<0 or 255<d then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
local function make_names(name)
|
||||
local e = xban.find_entry(name)
|
||||
local pnames = {}
|
||||
local pips = {}
|
||||
if e then
|
||||
for key in pairs(e.names) do
|
||||
if isIpAddress(key) == true then
|
||||
table.insert(pips, key)
|
||||
else table.insert(pnames, key)
|
||||
end
|
||||
end
|
||||
if pnames ~= {} and pips ~= {} then
|
||||
return table.concat(pnames, " "), table.concat(pips, " ")
|
||||
else return "Missing player data", "Missing player data"
|
||||
end
|
||||
else return "Missing player data", "Missing player data"
|
||||
end
|
||||
end
|
||||
|
||||
local function make_fs(name)
|
||||
local state = get_state(name)
|
||||
local list, filter = state.list, state.filter
|
||||
local pli, ei = state.player_index or 1, state.entry_index or 0
|
||||
if pli > #list then
|
||||
pli = #list
|
||||
end
|
||||
local fs = {
|
||||
"size[16,12]",
|
||||
"label[0,-.1;Filter]",
|
||||
"field[1.5,0;12.8,1;filter;;"..ESC(filter).."]",
|
||||
"button[14,-.3;2,1;search;Search]",
|
||||
}
|
||||
local fsn = #fs
|
||||
fsn=fsn+1 fs[fsn] = format("textlist[0,.8;4,9.3;player;%s;%d;0]",
|
||||
table.concat(list, ","), pli)
|
||||
local record_name = list[pli]
|
||||
if record_name then
|
||||
local record, e = get_record_simple(record_name)
|
||||
if record then
|
||||
for i, r in ipairs(record) do
|
||||
record[i] = ESC(r)
|
||||
end
|
||||
fsn=fsn+1 fs[fsn] = format(
|
||||
"textlist[4.2,.8;11.7,9.3;entry;%s;%d;0]",
|
||||
table.concat(record, ","), ei)
|
||||
local rec = e[ei]
|
||||
if rec then
|
||||
fsn=fsn+1 fs[fsn] = format("label[0,10.3;%s]",
|
||||
ESC("Source: "..(rec.source or "<none>")
|
||||
.."\nTime: "..os.date("%c", rec.time)
|
||||
.."\n"..(rec.expires and
|
||||
os.date("%c", rec.expires) or "")),
|
||||
pli)
|
||||
end
|
||||
else
|
||||
fsn=fsn+1 fs[fsn] = "textlist[4.2,.8;11.7,9.3;err;"..ESC(e)..";0]"
|
||||
fsn=fsn+1 fs[fsn] = "label[0,10.3;"..ESC(e).."]"
|
||||
end
|
||||
else
|
||||
local e = "No entry matches the query."
|
||||
fsn=fsn+1 fs[fsn] = "textlist[4.2,.8;11.7,9.3;err;"..ESC(e)..";0]"
|
||||
fsn=fsn+1 fs[fsn] = "label[0,10.3;"..ESC(e).."]"
|
||||
end
|
||||
local onames, oips = make_names(record_name)
|
||||
fsn=fsn+1 fs[fsn] = "label[5,10.3;Reported: "..reportfunc.get_count(record_name).."]"
|
||||
fsn=fsn+1 fs[fsn] = "label[5,10.6;Reporter: "..make_reporter(record_name).."]"
|
||||
fsn=fsn+1 fs[fsn] = "label[5,10.9;Names: "..onames.."]"
|
||||
fsn=fsn+1 fs[fsn] = "label[5,11.2;Ips: "..oips.."]"
|
||||
return table.concat(fs)
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= FORMNAME then return end
|
||||
local name = player:get_player_name()
|
||||
if not minetest.check_player_privs(name, { ban=true }) then
|
||||
minetest.log("warning",
|
||||
"[xban2] Received fields from unauthorized user: "..name)
|
||||
return
|
||||
end
|
||||
local state = get_state(name)
|
||||
if fields.player then
|
||||
local t = minetest.explode_textlist_event(fields.player)
|
||||
if (t.type == "CHG") or (t.type == "DCL") then
|
||||
state.player_index = t.index
|
||||
minetest.show_formspec(name, FORMNAME, make_fs(name))
|
||||
end
|
||||
return
|
||||
end
|
||||
if fields.entry then
|
||||
local t = minetest.explode_textlist_event(fields.entry)
|
||||
if (t.type == "CHG") or (t.type == "DCL") then
|
||||
state.entry_index = t.index
|
||||
minetest.show_formspec(name, FORMNAME, make_fs(name))
|
||||
end
|
||||
return
|
||||
end
|
||||
if fields.search then
|
||||
local filter = fields.filter or ""
|
||||
state.filter = filter
|
||||
state.list = make_list(filter)
|
||||
minetest.show_formspec(name, FORMNAME, make_fs(name))
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_chatcommand("xban_gui", {
|
||||
description = "Show XBan GUI",
|
||||
params = "",
|
||||
privs = { ban=true, },
|
||||
func = function(name, params)
|
||||
minetest.show_formspec(name, FORMNAME, make_fs(name))
|
||||
end,
|
||||
})
|
|
@ -1,29 +0,0 @@
|
|||
|
||||
function xban.importers.minetest()
|
||||
local f, e = io.open(minetest.get_worldpath().."/ipban.txt")
|
||||
if not f then
|
||||
return false, "Unable to open `ipban.txt': "..e
|
||||
end
|
||||
for line in f:lines() do
|
||||
local ip, name = line:match("([^|]+)%|(.+)")
|
||||
if ip and name then
|
||||
local entry
|
||||
entry = xban.find_entry(ip, true)
|
||||
entry.banned = true
|
||||
entry.reason = "Banned in `ipban.txt'"
|
||||
entry.names[name] = true
|
||||
entry.names[ip] = true
|
||||
entry.time = os.time()
|
||||
entry.expires = nil
|
||||
entry.source = "xban:importer_minetest"
|
||||
table.insert(entry.record, {
|
||||
source = entry.source,
|
||||
reason = entry.reason,
|
||||
time = entry.time,
|
||||
expires = nil,
|
||||
})
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
return true
|
||||
end
|
|
@ -1,33 +0,0 @@
|
|||
|
||||
function xban.importers.v1()
|
||||
local f, e = io.open(minetest.get_worldpath().."/players.iplist")
|
||||
if not f then
|
||||
return false, "Unable to open `players.iplist': "..e
|
||||
end
|
||||
for line in f:lines() do
|
||||
local list = line:split("|")
|
||||
if #list >= 2 then
|
||||
local banned = (list[1]:sub(1, 1) == "!")
|
||||
local entry
|
||||
entry = xban.find_entry(list[1], true)
|
||||
entry.banned = banned
|
||||
for _, name in ipairs(list) do
|
||||
entry.names[name] = true
|
||||
end
|
||||
if banned then
|
||||
entry.reason = "Banned in `players.iplist'"
|
||||
entry.time = os.time()
|
||||
entry.expires = nil
|
||||
entry.source = "xban:importer_v1"
|
||||
table.insert(entry.record, {
|
||||
source = entry.source,
|
||||
reason = entry.reason,
|
||||
time = entry.time,
|
||||
expires = nil,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
return true
|
||||
end
|
|
@ -1,35 +0,0 @@
|
|||
|
||||
function xban.importers.v2()
|
||||
return pcall(function()
|
||||
local f, e = io.open(minetest.get_worldpath().."/players.iplist.v2")
|
||||
if not f then
|
||||
error("Unable to open `players.iplist.v2': "..e)
|
||||
end
|
||||
local text = f:read("*a")
|
||||
f:close()
|
||||
local db = minetest.deserialize(text)
|
||||
for _, ent in ipairs(db) do
|
||||
for name in pairs(ent.names) do
|
||||
local entry = xban.find_entry(name, true)
|
||||
if entry.source ~= "xban:importer_v2" then
|
||||
for nm in pairs(e.names) do
|
||||
entry.names[nm] = true
|
||||
end
|
||||
if ent.banned then
|
||||
entry.banned = true
|
||||
entry.reason = e.banned
|
||||
entry.source = "xban:importer_v2"
|
||||
entry.time = ent.time
|
||||
entry.expires = ent.expires
|
||||
table.insert(entry.record, {
|
||||
source = entry.source,
|
||||
reason = entry.reason,
|
||||
time = entry.time,
|
||||
expires = entry.expires,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
|
@ -1,384 +0,0 @@
|
|||
|
||||
xban = { MP = minetest.get_modpath(minetest.get_current_modname()) }
|
||||
|
||||
dofile(xban.MP.."/serialize.lua")
|
||||
|
||||
local db = { }
|
||||
local tempbans = { }
|
||||
|
||||
local DEF_SAVE_INTERVAL = 300 -- 5 minutes
|
||||
local DEF_DB_FILENAME = minetest.get_worldpath().."/xban.db"
|
||||
|
||||
local DB_FILENAME = minetest.setting_get("xban.db_filename")
|
||||
local SAVE_INTERVAL = tonumber(
|
||||
minetest.setting_get("xban.db_save_interval")) or DEF_SAVE_INTERVAL
|
||||
|
||||
if (not DB_FILENAME) or (DB_FILENAME == "") then
|
||||
DB_FILENAME = DEF_DB_FILENAME
|
||||
end
|
||||
|
||||
local function make_logger(level)
|
||||
return function(text, ...)
|
||||
minetest.log(level, "[xban] "..text:format(...))
|
||||
end
|
||||
end
|
||||
|
||||
local ACTION = make_logger("action")
|
||||
local WARNING = make_logger("warning")
|
||||
|
||||
local unit_to_secs = {
|
||||
s = 1, m = 60, h = 3600,
|
||||
D = 86400, W = 604800, M = 2592000, Y = 31104000,
|
||||
[""] = 1,
|
||||
}
|
||||
|
||||
local function parse_time(t) --> secs
|
||||
local secs = 0
|
||||
for num, unit in t:gmatch("(%d+)([smhDWMY]?)") do
|
||||
secs = secs + (tonumber(num) * (unit_to_secs[unit] or 1))
|
||||
end
|
||||
return secs
|
||||
end
|
||||
|
||||
function xban.find_entry(player, create) --> entry, index
|
||||
for index, e in ipairs(db) do
|
||||
for name in pairs(e.names) do
|
||||
if name == player then
|
||||
return e, index
|
||||
end
|
||||
end
|
||||
end
|
||||
if create then
|
||||
local e = {
|
||||
names = { [player]=true },
|
||||
banned = false,
|
||||
record = { },
|
||||
}
|
||||
table.insert(db, e)
|
||||
return e, #db
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function xban.get_info(player) --> ip_name_list, banned, last_record
|
||||
local e = xban.find_entry(player)
|
||||
if not e then
|
||||
return nil, "No such entry"
|
||||
end
|
||||
return e.names, e.banned, e.record[#e.record]
|
||||
end
|
||||
|
||||
function xban.ban_player(player, source, expires, reason) --> bool, err
|
||||
if xban.get_whitelist(player) then
|
||||
return nil, "Player is whitelisted; remove from whitelist first"
|
||||
end
|
||||
local e = xban.find_entry(player, true)
|
||||
if e.banned then
|
||||
return nil, "Already banned"
|
||||
end
|
||||
local rec = {
|
||||
source = source,
|
||||
time = os.time(),
|
||||
expires = expires,
|
||||
reason = reason,
|
||||
}
|
||||
table.insert(e.record, rec)
|
||||
e.names[player] = true
|
||||
local pl = minetest.get_player_by_name(player)
|
||||
if pl then
|
||||
local ip = minetest.get_player_ip(player)
|
||||
if ip then
|
||||
e.names[ip] = true
|
||||
end
|
||||
e.last_pos = pl:getpos()
|
||||
end
|
||||
e.reason = reason
|
||||
e.time = rec.time
|
||||
e.expires = expires
|
||||
e.banned = true
|
||||
local msg
|
||||
local date = (expires and os.date("%c", expires)
|
||||
or "the end of time")
|
||||
if expires then
|
||||
table.insert(tempbans, e)
|
||||
msg = ("Banned: Expires: %s, Reason: %s"):format(date, reason)
|
||||
else
|
||||
msg = ("Banned: Reason: %s"):format(reason)
|
||||
end
|
||||
for nm in pairs(e.names) do
|
||||
minetest.kick_player(nm, msg)
|
||||
end
|
||||
ACTION("%s bans %s until %s for reason: %s", source, player,
|
||||
date, reason)
|
||||
ACTION("Banned Names/IPs: %s", table.concat(e.names, ", "))
|
||||
return true
|
||||
end
|
||||
|
||||
function xban.unban_player(player, source) --> bool, err
|
||||
local e = xban.find_entry(player)
|
||||
if not e then
|
||||
return nil, "No such entry"
|
||||
end
|
||||
local rec = {
|
||||
source = source,
|
||||
time = os.time(),
|
||||
reason = "Unbanned",
|
||||
}
|
||||
table.insert(e.record, rec)
|
||||
e.banned = false
|
||||
e.reason = nil
|
||||
e.expires = nil
|
||||
e.time = nil
|
||||
ACTION("%s unbans %s", source, player)
|
||||
ACTION("Unbanned Names/IPs: %s", table.concat(e.names, ", "))
|
||||
return true
|
||||
end
|
||||
|
||||
function xban.get_whitelist(name_or_ip)
|
||||
return db.whitelist and db.whitelist[name_or_ip]
|
||||
end
|
||||
|
||||
function xban.remove_whitelist(name_or_ip)
|
||||
if db.whitelist then
|
||||
db.whitelist[name_or_ip] = nil
|
||||
end
|
||||
end
|
||||
|
||||
function xban.add_whitelist(name_or_ip, source)
|
||||
local wl = db.whitelist
|
||||
if not wl then
|
||||
wl = { }
|
||||
db.whitelist = wl
|
||||
end
|
||||
wl[name_or_ip] = {
|
||||
source=source,
|
||||
}
|
||||
return true
|
||||
end
|
||||
|
||||
function xban.get_record(player)
|
||||
local e = xban.find_entry(player)
|
||||
if not e then
|
||||
return nil, ("No entry for `%s'"):format(player)
|
||||
elseif (not e.record) or (#e.record == 0) then
|
||||
return nil, ("`%s' has no ban records"):format(player)
|
||||
end
|
||||
local record = { }
|
||||
for _, rec in ipairs(e.record) do
|
||||
local msg = rec.reason or "No reason given."
|
||||
if rec.expires then
|
||||
msg = msg..(", Expires: %s"):format(os.date("%c", e.expires))
|
||||
end
|
||||
if rec.source then
|
||||
msg = msg..", Source: "..rec.source
|
||||
end
|
||||
table.insert(record, ("[%s]: %s"):format(os.date("%c", e.time), msg))
|
||||
end
|
||||
local last_pos
|
||||
if e.last_pos then
|
||||
last_pos = ("User was last seen at %s"):format(
|
||||
minetest.pos_to_string(e.last_pos))
|
||||
end
|
||||
return record, last_pos
|
||||
end
|
||||
|
||||
minetest.register_on_prejoinplayer(function(name, ip)
|
||||
local wl = db.whitelist or { }
|
||||
if wl[name] or wl[ip] then return end
|
||||
local e = xban.find_entry(name) or xban.find_entry(ip)
|
||||
if not e then return end
|
||||
if e.banned then
|
||||
local date = (e.expires and os.date("%c", e.expires)
|
||||
or "the end of time")
|
||||
return ("Banned: Expires: %s, Reason: %s"):format(
|
||||
date, e.reason)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
local e = xban.find_entry(name)
|
||||
local ip = minetest.get_player_ip(name)
|
||||
if not e then
|
||||
if ip then
|
||||
e = xban.find_entry(ip, true)
|
||||
else
|
||||
return
|
||||
end
|
||||
end
|
||||
e.names[name] = true
|
||||
if ip then
|
||||
e.names[ip] = true
|
||||
end
|
||||
e.last_seen = os.time()
|
||||
end)
|
||||
|
||||
minetest.register_chatcommand("xban", {
|
||||
description = "XBan a player",
|
||||
params = "<player> <reason>",
|
||||
privs = { ban=true },
|
||||
func = function(name, params)
|
||||
local plname, reason = params:match("(%S+)%s+(.+)")
|
||||
if not (plname and reason) then
|
||||
return false, "Usage: /xban <player> <reason>"
|
||||
end
|
||||
local ok, e = xban.ban_player(plname, name, nil, reason)
|
||||
return ok, ok and ("Banned %s."):format(plname) or e
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("xtempban", {
|
||||
description = "XBan a player temporarily",
|
||||
params = "<player> <time> <reason>",
|
||||
privs = { ban=true },
|
||||
func = function(name, params)
|
||||
local plname, time, reason = params:match("(%S+)%s+(%S+)%s+(.+)")
|
||||
if not (plname and time and reason) then
|
||||
return false, "Usage: /xtempban <player> <time> <reason>"
|
||||
end
|
||||
time = parse_time(time)
|
||||
if time < 60 then
|
||||
return false, "You must ban for at least 60 seconds."
|
||||
end
|
||||
local expires = os.time() + time
|
||||
local ok, e = xban.ban_player(plname, name, expires, reason)
|
||||
return ok, (ok and ("Banned %s until %s."):format(
|
||||
plname, os.date("%c", expires)) or e)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("xunban", {
|
||||
description = "XUnBan a player",
|
||||
params = "<player_or_ip>",
|
||||
privs = { ban=true },
|
||||
func = function(name, params)
|
||||
local plname = params:match("%S+")
|
||||
if not plname then
|
||||
minetest.chat_send_player(name,
|
||||
"Usage: /xunban <player_or_ip>")
|
||||
return
|
||||
end
|
||||
local ok, e = xban.unban_player(plname, name)
|
||||
return ok, ok and ("Unbanned %s."):format(plname) or e
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("xban_record", {
|
||||
description = "Show the ban records of a player",
|
||||
params = "<player_or_ip>",
|
||||
privs = { ban=true },
|
||||
func = function(name, params)
|
||||
local plname = params:match("%S+")
|
||||
if not plname then
|
||||
return false, "Usage: /xban_record <player_or_ip>"
|
||||
end
|
||||
local record, last_pos = xban.get_record(plname)
|
||||
if not record then
|
||||
local err = last_pos
|
||||
minetest.chat_send_player(name, "[xban] "..err)
|
||||
return
|
||||
end
|
||||
for _, e in ipairs(record) do
|
||||
minetest.chat_send_player(name, "[xban] "..e)
|
||||
end
|
||||
if last_pos then
|
||||
minetest.chat_send_player(name, "[xban] "..last_pos)
|
||||
end
|
||||
return true, "Record listed."
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("xban_wl", {
|
||||
description = "Manages the whitelist",
|
||||
params = "(add|del|get) <name_or_ip>",
|
||||
privs = { ban=true },
|
||||
func = function(name, params)
|
||||
local cmd, plname = params:match("%s*(%S+)%s*(%S+)")
|
||||
if cmd == "add" then
|
||||
xban.add_whitelist(plname, name)
|
||||
ACTION("%s adds %s to whitelist", name, plname)
|
||||
return true, "Added to whitelist: "..plname
|
||||
elseif cmd == "del" then
|
||||
xban.remove_whitelist(plname)
|
||||
ACTION("%s removes %s to whitelist", name, plname)
|
||||
return true, "Removed from whitelist: "..plname
|
||||
elseif cmd == "get" then
|
||||
local e = xban.get_whitelist(plname)
|
||||
if e then
|
||||
return true, "Source: "..(e.source or "Unknown")
|
||||
else
|
||||
return true, "No whitelist for: "..plname
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
local function check_temp_bans()
|
||||
minetest.after(60, check_temp_bans)
|
||||
local to_rm = { }
|
||||
local now = os.time()
|
||||
for i, e in ipairs(tempbans) do
|
||||
if e.expires and (e.expires <= now) then
|
||||
table.insert(to_rm, i)
|
||||
e.banned = false
|
||||
e.expires = nil
|
||||
e.reason = nil
|
||||
e.time = nil
|
||||
end
|
||||
end
|
||||
for _, i in ipairs(to_rm) do
|
||||
table.remove(tempbans, i)
|
||||
end
|
||||
end
|
||||
|
||||
local function save_db()
|
||||
minetest.after(SAVE_INTERVAL, save_db)
|
||||
local f, e = io.open(DB_FILENAME, "wt")
|
||||
db.timestamp = os.time()
|
||||
if f then
|
||||
local ok, err = f:write(xban.serialize(db))
|
||||
if not ok then
|
||||
WARNING("Unable to save database: %s", err)
|
||||
end
|
||||
else
|
||||
WARNING("Unable to save database: %s", e)
|
||||
end
|
||||
if f then f:close() end
|
||||
return
|
||||
end
|
||||
|
||||
local function load_db()
|
||||
local f, e = io.open(DB_FILENAME, "rt")
|
||||
if not f then
|
||||
WARNING("Unable to load database: %s", e)
|
||||
return
|
||||
end
|
||||
local cont = f:read("*a")
|
||||
if not cont then
|
||||
WARNING("Unable to load database: %s", "Read failed")
|
||||
return
|
||||
end
|
||||
local t, e2 = minetest.deserialize(cont)
|
||||
if not t then
|
||||
WARNING("Unable to load database: %s",
|
||||
"Deserialization failed: "..(e2 or "unknown error"))
|
||||
return
|
||||
end
|
||||
db = t
|
||||
tempbans = { }
|
||||
for _, entry in ipairs(db) do
|
||||
if entry.banned and entry.expires then
|
||||
table.insert(tempbans, entry)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_shutdown(save_db)
|
||||
minetest.after(SAVE_INTERVAL, save_db)
|
||||
load_db()
|
||||
xban.db = db
|
||||
|
||||
minetest.after(1, check_temp_bans)
|
||||
|
||||
dofile(xban.MP.."/dbimport.lua")
|
||||
dofile(xban.MP.."/gui.lua")
|
|
@ -1 +0,0 @@
|
|||
name = xban2
|
|
@ -1,31 +0,0 @@
|
|||
|
||||
local function repr(x)
|
||||
if type(x) == "string" then
|
||||
return ("%q"):format(x)
|
||||
else
|
||||
return tostring(x)
|
||||
end
|
||||
end
|
||||
|
||||
local function my_serialize_2(t, level)
|
||||
level = level or 0
|
||||
local lines = { }
|
||||
local indent = ("\t"):rep(level)
|
||||
for k, v in pairs(t) do
|
||||
local typ = type(v)
|
||||
if typ == "table" then
|
||||
table.insert(lines,
|
||||
indent..("[%s] = {\n"):format(repr(k))
|
||||
..my_serialize_2(v, level + 1).."\n"
|
||||
..indent.."},")
|
||||
else
|
||||
table.insert(lines,
|
||||
indent..("[%s] = %s,"):format(repr(k), repr(v)))
|
||||
end
|
||||
end
|
||||
return table.concat(lines, "\n")
|
||||
end
|
||||
|
||||
function xban.serialize(t)
|
||||
return "return {\n"..my_serialize_2(t, 1).."\n}"
|
||||
end
|
Loading…
Reference in New Issue