repair_station.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. local S = minetest.get_translator("travelnet")
  2. return function (node_info, _, player)
  3. local owner_name = node_info.props.owner_name
  4. local station_name = node_info.props.station_name
  5. local station_network = node_info.props.station_network
  6. if not owner_name
  7. or not station_name
  8. or travelnet.is_falsey_string(station_network)
  9. then
  10. if node_info.props.is_elevator then
  11. return travelnet.actions.add_station(node_info, _, player)
  12. end
  13. return false, S("Update failed! Resetting this box on the travelnet.")
  14. end
  15. local travelnets = travelnet.get_travelnets(owner_name)
  16. local network = travelnets[station_network]
  17. if not network then
  18. network = {}
  19. travelnets[station_network] = network
  20. end
  21. -- if the station got lost from the network for some reason (savefile corrupted?) then add it again
  22. if not network[station_name] then
  23. local timestamp = node_info.meta:get_int("timestamp")
  24. if not timestamp or type(timestamp) ~= "number" or timestamp < 100000 then
  25. timestamp = os.time()
  26. end
  27. -- add this station
  28. network[station_name] = {
  29. pos = node_info.pos,
  30. timestamp = timestamp
  31. }
  32. minetest.chat_send_player(owner_name,
  33. S("Station '@1'" .. " " ..
  34. "has been reattached to the network '@2'.", station_name, station_network))
  35. travelnet.log("action", "repared station '" .. owner_name .. "' on network '" .. station_network ..
  36. "' for player '" .. owner_name .. "'")
  37. travelnet.set_travelnets(owner_name, travelnets)
  38. end
  39. return true, { formspec = travelnet.formspecs.primary }
  40. end