code tidy / update to new responses
This commit is contained in:
parent
ea867c1293
commit
eab60b1cdb
28
auth.lua
28
auth.lua
@ -8,20 +8,20 @@ local has_xban2_mod = minetest.get_modpath("xban2")
|
|||||||
-- auth request
|
-- auth request
|
||||||
local function auth_handler(auth)
|
local function auth_handler(auth)
|
||||||
local handler = minetest.get_auth_handler()
|
local handler = minetest.get_auth_handler()
|
||||||
minetest.log("action", "[auth_proxy] auth: " .. auth.name)
|
minetest.log("action", "[auth_proxy] auth: " .. auth.username)
|
||||||
|
|
||||||
local success = false
|
local success = false
|
||||||
local banned = false
|
local banned = false
|
||||||
local message = ""
|
local message = ""
|
||||||
|
|
||||||
local custom_auth_success, custom_msg = auth_proxy.custom_handler(auth.name)
|
local custom_auth_success, custom_msg = auth_proxy.custom_handler(auth.username)
|
||||||
if not custom_auth_success and custom_msg then
|
if not custom_auth_success and custom_msg then
|
||||||
message = custom_msg
|
message = custom_msg
|
||||||
end
|
end
|
||||||
|
|
||||||
if auth_proxy.disallow_banned_players and has_xban2_mod then
|
if auth_proxy.disallow_banned_players and has_xban2_mod then
|
||||||
-- check xban db
|
-- check xban db
|
||||||
local xbanentry = xban.find_entry(auth.name)
|
local xbanentry = xban.find_entry(auth.username)
|
||||||
if xbanentry and xbanentry.banned then
|
if xbanentry and xbanentry.banned then
|
||||||
banned = true
|
banned = true
|
||||||
message = "Banned!"
|
message = "Banned!"
|
||||||
@ -30,37 +30,29 @@ local function auth_handler(auth)
|
|||||||
|
|
||||||
if not banned and custom_auth_success then
|
if not banned and custom_auth_success then
|
||||||
-- check tan
|
-- check tan
|
||||||
local tan = auth_proxy.tan[auth.name]
|
local tan = auth_proxy.tan[auth.username]
|
||||||
if tan ~= nil then
|
if tan ~= nil then
|
||||||
success = tan == auth.password
|
success = tan == auth.password
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check auth
|
-- check auth
|
||||||
if not success then
|
if not success then
|
||||||
local entry = handler.get_auth(auth.name)
|
local entry = handler.get_auth(auth.username)
|
||||||
if entry and minetest.check_password_entry(auth.name, entry.password, auth.password) then
|
if entry and minetest.check_password_entry(auth.username, entry.password, auth.password) then
|
||||||
success = true
|
success = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
channel.send({
|
channel.send({
|
||||||
type = "auth",
|
name = auth.username,
|
||||||
data = {
|
success = success,
|
||||||
name = auth.name,
|
message = message
|
||||||
success = success,
|
|
||||||
message = message
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function auth_proxy.http_init(http, url)
|
function auth_proxy.http_init(http, url)
|
||||||
channel = Channel(http, url .. "/api/minetest/channel")
|
channel = Channel(http, url .. "/api/minetest/channel")
|
||||||
|
channel.receive(auth_handler)
|
||||||
channel.receive(function(data)
|
|
||||||
if data.type == "auth" then
|
|
||||||
auth_handler(data.data)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
2
init.lua
2
init.lua
@ -1,6 +1,6 @@
|
|||||||
auth_proxy = {
|
auth_proxy = {
|
||||||
disallow_banned_players = true,
|
disallow_banned_players = true,
|
||||||
url = minetest.settings:get("auth_proxy.url"),
|
url = minetest.settings:get("auth_proxy.url") or "http://127.0.0.1:8080",
|
||||||
tan = {},
|
tan = {},
|
||||||
custom_handler = function()
|
custom_handler = function()
|
||||||
return true
|
return true
|
||||||
|
2
settingtypes.txt
Normal file
2
settingtypes.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# The url to the auth proxy app
|
||||||
|
auth_proxy.url (Auth proxy url) string http://127.0.0.1:8080
|
@ -34,7 +34,7 @@ local function Channel(http, url, cfg)
|
|||||||
local data = minetest.parse_json(res.data)
|
local data = minetest.parse_json(res.data)
|
||||||
|
|
||||||
if debug then
|
if debug then
|
||||||
minetest.log("action", "[webmail-rx] " .. dump(data))
|
minetest.log("action", "[channel-rx] " .. dump(data))
|
||||||
end
|
end
|
||||||
|
|
||||||
if data then
|
if data then
|
||||||
@ -57,7 +57,7 @@ local function Channel(http, url, cfg)
|
|||||||
-- POST
|
-- POST
|
||||||
|
|
||||||
if debug then
|
if debug then
|
||||||
minetest.log("action", "[webmail-tx] " .. dump(data))
|
minetest.log("action", "[channel-tx] " .. dump(data))
|
||||||
end
|
end
|
||||||
|
|
||||||
http.fetch({
|
http.fetch({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user