More fixes
This commit is contained in:
parent
d5224e7124
commit
a0062ddacc
21
atm-core.lua
21
atm-core.lua
|
@ -80,9 +80,9 @@ function formspecs.pay(name, fields, guessed_amount)
|
||||||
|
|
||||||
if exc < 0 then
|
if exc < 0 then
|
||||||
lurkcoin.get_exchange_rate(fields.amount, fields.server or
|
lurkcoin.get_exchange_rate(fields.amount, fields.server or
|
||||||
lurkcoin.server_name, function(data)
|
lurkcoin.server_name, function(data, msg)
|
||||||
if not data then
|
if not data then
|
||||||
fields._err = 'That server does not exist!'
|
fields._err = msg
|
||||||
end
|
end
|
||||||
fields._exchange_rate = data
|
fields._exchange_rate = data
|
||||||
return lurkcoin.show_atm(name, 'pay', fields)
|
return lurkcoin.show_atm(name, 'pay', fields)
|
||||||
|
@ -239,14 +239,18 @@ function lurkcoin.show_atm(name, page, params)
|
||||||
page, params))
|
page, params))
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, raw)
|
||||||
if formname ~= 'lurkcoin:atm' then return end
|
if formname ~= 'lurkcoin:atm' then return end
|
||||||
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
|
||||||
-- These probably don't need to be deleted.
|
-- Do a shallow copy in case some other mod relies on "fields" not changing.
|
||||||
fields._err = nil
|
local fields = {}
|
||||||
fields._exchange_rate = nil
|
for k, v in pairs(raw) do
|
||||||
|
if type(k) == 'string' and k:sub(1, 1) ~= '_' then
|
||||||
|
fields[k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if withdrawls then
|
if withdrawls then
|
||||||
if fields.deposit then
|
if fields.deposit then
|
||||||
|
@ -333,11 +337,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
lurkcoin.show_atm(name, 'pay', fields)
|
lurkcoin.show_atm(name, 'pay', fields)
|
||||||
return
|
return
|
||||||
elseif fields.server then
|
elseif fields.server then
|
||||||
fields.server = fields.server:gsub('^ *(.-) *$', '%1')
|
fields.server = fields.server:trim()
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields.user then
|
if fields.user then
|
||||||
fields.user = fields.user:gsub('^ *(.-) *$', '%1')
|
fields.user = fields.user:trim()
|
||||||
end
|
end
|
||||||
|
|
||||||
if not fields.server or fields.server == '' then
|
if not fields.server or fields.server == '' then
|
||||||
|
@ -359,7 +363,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
fields._err = nil
|
|
||||||
lurkcoin.show_atm(name, 'pay', fields)
|
lurkcoin.show_atm(name, 'pay', fields)
|
||||||
elseif fields.home then
|
elseif fields.home then
|
||||||
lurkcoin.show_atm(name, 'main')
|
lurkcoin.show_atm(name, 'main')
|
||||||
|
|
18
core.lua
18
core.lua
|
@ -36,18 +36,21 @@ lurkcoin.user_agent = 'Minetest ' .. minetest.get_version().string ..
|
||||||
|
|
||||||
-- Download functions
|
-- Download functions
|
||||||
local function get(url, data, callback)
|
local function get(url, data, callback)
|
||||||
|
-- To prevent race conditions, these callbacks wait until at least the next
|
||||||
|
-- globalstep.
|
||||||
if not data then
|
if not data then
|
||||||
data = {}
|
data = {}
|
||||||
elseif not http then
|
elseif not http then
|
||||||
return callback({
|
minetest.after(0, callback, {
|
||||||
completed = true,
|
completed = true,
|
||||||
succeeded = false,
|
succeeded = false,
|
||||||
timeout = true,
|
timeout = true,
|
||||||
code = 500,
|
code = 500,
|
||||||
data = 'ERROR: The lurkcoin mod is not in secure.http_mods!'
|
data = 'ERROR: The lurkcoin mod is not in secure.http_mods!'
|
||||||
})
|
})
|
||||||
|
return
|
||||||
elseif not lurkcoin.server_name or not token then
|
elseif not lurkcoin.server_name or not token then
|
||||||
return callback({
|
minetest.after(0, callback, {
|
||||||
completed = true,
|
completed = true,
|
||||||
succeeded = false,
|
succeeded = false,
|
||||||
timeout = true,
|
timeout = true,
|
||||||
|
@ -55,6 +58,7 @@ local function get(url, data, callback)
|
||||||
data = 'ERROR: The lurkcoin mod does not have (correct) ' ..
|
data = 'ERROR: The lurkcoin mod does not have (correct) ' ..
|
||||||
'account credentials!'
|
'account credentials!'
|
||||||
})
|
})
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
data.name = lurkcoin.server_name
|
data.name = lurkcoin.server_name
|
||||||
|
@ -146,9 +150,15 @@ function lurkcoin.get_exchange_rate(amount, to, callback)
|
||||||
}, function(res)
|
}, function(res)
|
||||||
if res.code == 200 then
|
if res.code == 200 then
|
||||||
local amount = tonumber(res.data)
|
local amount = tonumber(res.data)
|
||||||
if amount == amount then return callback(amount) end
|
if amount == amount then return callback(amount, nil) end
|
||||||
end
|
end
|
||||||
return callback(nil)
|
local msg
|
||||||
|
if res.code == 502 then
|
||||||
|
msg = 'That server does not exist!'
|
||||||
|
else
|
||||||
|
msg = res.data
|
||||||
|
end
|
||||||
|
return callback(nil, tostring(msg))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue