diff options
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 32 |
1 files changed, 26 insertions, 6 deletions
@@ -69,6 +69,23 @@ function xban.get_info(player) --> ip_name_list, banned, last_record return e.names, e.banned, e.record[#e.record] end +function xban.add_record(player, record) + -- Add records for other punishments banned. + local e = xban.find_entry(player, true) + table.insert(e.record, record) +end + +function xban.add_property(player, property, value) + -- adds a property to a player, for instance a "jailed" property which indicates that a player is jailed + local e = xban.find_entry(player, true) + e[property] = value +end +function xban.get_property(player, property) + local e = xban.find_entry(player, true) + return e[property] +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" @@ -82,6 +99,7 @@ function xban.ban_player(player, source, expires, reason) --> bool, err time = os.time(), expires = expires, reason = reason, + type = "ban", } table.insert(e.record, rec) e.names[player] = true @@ -115,7 +133,7 @@ function xban.ban_player(player, source, expires, reason) --> bool, err return true end -function xban.unban_player(player, source) --> bool, err +function xban.unban_player(player, source, reason) --> bool, err local e = xban.find_entry(player) if not e then return nil, "No such entry" @@ -123,7 +141,8 @@ function xban.unban_player(player, source) --> bool, err local rec = { source = source, time = os.time(), - reason = "Unbanned", + reason = (reason or ""), + type = "unban" } table.insert(e.record, rec) e.banned = false @@ -166,7 +185,8 @@ function xban.get_record(player) end local record = { } for _, rec in ipairs(e.record) do - local msg = rec.reason or "No reason given." + local msg = rec.type or "ban" + msg = msg .. ": " .. rec.reason or "No reason given." if rec.expires then msg = msg..(", Expires: %s"):format(os.date("%c", e.expires)) end @@ -250,16 +270,16 @@ minetest.register_chatcommand("xtempban", { minetest.register_chatcommand("xunban", { description = "XUnBan a player", - params = "<player_or_ip>", + params = "<player_or_ip> <reason>", privs = { ban=true }, func = function(name, params) - local plname = params:match("%S+") + local plname, reason = params:match("(%S+)%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) + local ok, e = xban.unban_player(plname, name, reason) return ok, ok and ("Unbanned %s."):format(plname) or e end, }) |