[Master] Minor fixes in lua scripts

new-script-api
Koncord 7 years ago
parent 76f1a61538
commit 5fcdff843c

@ -6,7 +6,7 @@ end
-------------------------------------[response strings]------------------------------------- -------------------------------------[response strings]-------------------------------------
response_ok = "HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nOK" response_ok = "HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nOK"
--response_bad = "HTTP/1.1 400 Bad Request\r\nContent-Length: 11\r\n\r\nbad request" response_bad = "HTTP/1.1 400 Bad Request\r\nContent-Length: 11\r\n\r\nbad request"
response_forbidden = "HTTP/1.1 403 Forbidden\r\nContent-Length: 9\r\n\r\nforbidden" response_forbidden = "HTTP/1.1 403 Forbidden\r\nContent-Length: 9\r\n\r\nforbidden"
response_error = "HTTP/1.1 500 Internal Server Error\r\nContent-Length: 21\r\n\r\nInternal Server Error" response_error = "HTTP/1.1 500 Internal Server Error\r\nContent-Length: 21\r\n\r\nInternal Server Error"
@ -43,7 +43,7 @@ local json = require ("dkjson");
function ban(addr, admin, reason, dontInsert) function ban(addr, admin, reason, dontInsert)
local entry = { local entry = {
address = addr, address = addr,
date = os.date("%s"), date = tonumber(os.date("%s")),
by = admin, by = admin,
reason = reason reason = reason
} }
@ -59,9 +59,10 @@ function unban(addr)
if value.address == addr then if value.address == addr then
table.remove(banned, idx) table.remove(banned, idx)
UnbanAddress(addr) UnbanAddress(addr)
break return true
end end
end end
return false
end end
function loadBans() function loadBans()
@ -142,7 +143,9 @@ function OnCommand(command, v, address)
ban(v["address"], loggedIn[loginId][1], v["reason"]) ban(v["address"], loggedIn[loginId][1], v["reason"])
elseif command == "unban" then elseif command == "unban" then
print("Unban address: " .. v["address"]) print("Unban address: " .. v["address"])
unban(v["address"]) if not unban(v["address"]) then -- if server not found
return true, response_bad
end
elseif command == "banlist" then -- can be used only as last command elseif command == "banlist" then -- can be used only as last command
local data = json.encode(banned, { indent = true--[[, keyorder = {"address", "date", "by", "reason"} ]] }) local data = json.encode(banned, { indent = true--[[, keyorder = {"address", "date", "by", "reason"} ]] })
return true, ResponseStr(data) return true, ResponseStr(data)

Loading…
Cancel
Save