2016-11-18 05:19:33 +01:00
|
|
|
local insecure_env = minetest.request_insecure_environment()
|
2017-06-01 12:14:13 +02:00
|
|
|
assert(insecure_env, "global_exchange needs to be trusted to run under mod security.")
|
2016-11-18 05:19:33 +01:00
|
|
|
|
2016-02-25 23:38:19 +01:00
|
|
|
local modpath = minetest.get_modpath(minetest.get_current_modname()) .. "/"
|
|
|
|
|
2017-06-01 12:14:13 +02:00
|
|
|
local exchange = assert(loadfile(modpath .. "exchange.lua"))(insecure_env).
|
|
|
|
open_exchange(minetest.get_worldpath() .. "/global_exchange.db")
|
2016-02-25 23:38:19 +01:00
|
|
|
|
2017-06-01 12:14:13 +02:00
|
|
|
local formlib = assert(loadfile(modpath .. "formlib.lua"))()
|
2016-02-25 23:38:19 +01:00
|
|
|
|
|
|
|
minetest.register_on_shutdown(function()
|
2017-06-01 12:14:13 +02:00
|
|
|
exchange:close()
|
2016-02-25 23:38:19 +01:00
|
|
|
end)
|
|
|
|
|
2017-06-01 12:14:13 +02:00
|
|
|
local function handle_setbalance_command(caller, name, newbalance)
|
|
|
|
return exchange:set_balance(name, newbalance)
|
2016-03-05 11:47:35 +01:00
|
|
|
end
|
2016-02-25 23:38:19 +01:00
|
|
|
|
2017-06-01 12:14:13 +02:00
|
|
|
minetest.register_privilege("balance", {
|
|
|
|
description = "Can use /setbalance",
|
|
|
|
give_to_singleplayer = false
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("setbalance", {
|
|
|
|
params = "[<name>] <balance>",
|
|
|
|
description = "set a player's trading balance",
|
|
|
|
privs = {balance=true},
|
|
|
|
func = function(caller, param)
|
|
|
|
local name, balancestr = string.match(param, "([^ ]+) ([0-9]+)")
|
|
|
|
if not name or not balancestr then
|
|
|
|
name = caller
|
|
|
|
balancestr = string.match(param, "([0-9]+)")
|
|
|
|
if not balancestr then
|
|
|
|
return false, "Invalid parameters (see /help setbalance)"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return handle_setbalance_command(caller, name, tonumber(balancestr))
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
assert(loadfile(modpath .. "atm.lua"))(exchange, formlib)
|
|
|
|
assert(loadfile(modpath .. "exchange_machine.lua"))(exchange, formlib)
|
|
|
|
assert(loadfile(modpath .. "digital_mailbox.lua"))(exchange, formlib)
|