dbimport.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. xban.importers = xban.importers or { }
  2. -- Files are reloadable.
  3. dofile(xban.MP.."/importers/minetest.lua")
  4. dofile(xban.MP.."/importers/v1.lua")
  5. dofile(xban.MP.."/importers/v2.lua")
  6. function xban.importers.chatcommand(name, params)
  7. if params == "--list" then
  8. local importers = { }
  9. for importer in pairs(xban.importers) do
  10. table.insert(importers, importer)
  11. end
  12. minetest.chat_send_player(name,
  13. ("# Server: Known importers: %s."):format(
  14. table.concat(importers, ", ")))
  15. return
  16. elseif not xban.importers[params] then
  17. minetest.chat_send_player(name,
  18. ("# Server: Unknown importer '%s'"):format(params))
  19. minetest.chat_send_player(name, "# Server: Try '/xban_dbi --list'.")
  20. return
  21. end
  22. local f = xban.importers[params]
  23. local ok, err = f()
  24. if ok then
  25. minetest.chat_send_player(name, "# Server: Import successfull.")
  26. else
  27. minetest.chat_send_player(name,
  28. ("# Server: Import failed: '%s'."):format(err))
  29. end
  30. end
  31. if not xban.importers.registered then
  32. minetest.register_chatcommand("xban_dbi", {
  33. description = "Import old databases.",
  34. params = "<importer>",
  35. privs = { server=true },
  36. func = function(...)
  37. return xban.importers.chatcommand(...)
  38. end,
  39. })
  40. xban.importers.registered = true
  41. end