Electronic trading exchange in Minetest
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.6 KiB

  1. local insecure_env = minetest.request_insecure_environment()
  2. assert(insecure_env, "global_exchange needs to be trusted to run under mod security.")
  3. local modpath = minetest.get_modpath(minetest.get_current_modname()) .. "/"
  4. local exchange = assert(loadfile(modpath .. "exchange.lua"))(insecure_env).
  5. open_exchange(minetest.get_worldpath() .. "/global_exchange.db")
  6. local formlib = assert(loadfile(modpath .. "formlib.lua"))()
  7. minetest.register_on_shutdown(function()
  8. exchange:close()
  9. end)
  10. local function handle_setbalance_command(caller, name, newbalance)
  11. return exchange:set_balance(name, newbalance)
  12. end
  13. minetest.register_privilege("balance", {
  14. description = "Can use /setbalance",
  15. give_to_singleplayer = false
  16. })
  17. minetest.register_chatcommand("setbalance", {
  18. params = "[<name>] <balance>",
  19. description = "set a player's trading balance",
  20. privs = {balance=true},
  21. func = function(caller, param)
  22. local name, balancestr = string.match(param, "([^ ]+) ([0-9]+)")
  23. if not name or not balancestr then
  24. name = caller
  25. balancestr = string.match(param, "([0-9]+)")
  26. if not balancestr then
  27. return false, "Invalid parameters (see /help setbalance)"
  28. end
  29. end
  30. return handle_setbalance_command(caller, name, tonumber(balancestr))
  31. end,
  32. })
  33. assert(loadfile(modpath .. "atm.lua"))(exchange, formlib)
  34. assert(loadfile(modpath .. "exchange_machine.lua"))(exchange, formlib)
  35. assert(loadfile(modpath .. "digital_mailbox.lua"))(exchange, formlib)
  36. minetest.log("action", "[global_exchange] loaded.")