aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--doc/API.md37
-rw-r--r--doc/dbformat.txt2
-rw-r--r--gui.lua2
-rw-r--r--init.lua32
5 files changed, 66 insertions, 11 deletions
diff --git a/README.md b/README.md
index 90eed0d..0f39ec3 100644
--- a/README.md
+++ b/README.md
@@ -47,9 +47,9 @@ up. For example, `1Y3M3D7h` will ban for 1 year, 3 months, 3 days and 7 hours.
Unbans a player.
-**Usage:** `/xunban <player_or_ip>`
+**Usage:** `/xunban <player_or_ip> <reason>`
-**Example:** `/xunban Joe`
+**Example:** `/xunban Joe has promised not to grief again`
### `xban_record`
diff --git a/doc/API.md b/doc/API.md
index bee7c42..2353cb4 100644
--- a/doc/API.md
+++ b/doc/API.md
@@ -16,14 +16,47 @@ Ban a player and all of his/her alternative names and IPs.
### unban_player
-`xban.unban_player(player_or_ip, source)`
+`xban.unban_player(player_or_ip, source, reason)`
+
+Unban a player and all of his/her alternative names and IPs. A reason
+may be given for this unbanning, so other moderators can follow your
+thoughts.
-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.
+* `reason` - Reason for unbanning.
+
+### add_record:
+
+`xban.add_record(player, record)`
+
+Adds a record to the player's criminal record.
+
+#### Arguments:
+
+* `player` - Name of a player
+* `record` - a xban record (see below)
+
+### Player record format:
+
+
+ local record = {
+ source = "admin",
+ time = os.time(),
+ expires = nil,
+ reason = "bad behaviour",
+ type = "ban",
+ }
+
+* `source` - who issued the record
+* `time` - time at which the record was issued
+* `expires` - time at which the record expires, `nil` for never
+* `reason` - reason for record
+* `type` - type of record.
+
### Notes
diff --git a/doc/dbformat.txt b/doc/dbformat.txt
index 71b25a5..a16737d 100644
--- a/doc/dbformat.txt
+++ b/doc/dbformat.txt
@@ -29,11 +29,13 @@ Each entry contains following fields:
reason = "qwerty",
time = 12341234,
expires = 43214321,
+ type = "ban"
},
[1] = {
source = "asdf",
reason = "Unbanned", -- When unbanned
time = 12341234,
+ type = "unban"
},
},
}
diff --git a/gui.lua b/gui.lua
index d3306e2..f6c18ce 100644
--- a/gui.lua
+++ b/gui.lua
@@ -43,7 +43,7 @@ local function get_record_simple(name)
end
local record = { }
for _, rec in ipairs(e.record) do
- local msg = (os.date("%Y-%m-%d %H:%M:%S", rec.time).." | "
+ local msg = (os.date("%Y-%m-%d %H:%M:%S", rec.time).." | " .. (rec.type or ban).." | "
..(rec.reason or "No reason given."))
table.insert(record, msg)
end
diff --git a/init.lua b/init.lua
index 6f15f14..24dab44 100644
--- a/init.lua
+++ b/init.lua
@@ -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,
})