Only save when needed

master
rubenwardy 2015-07-14 09:37:40 +01:00
parent 61830d59bb
commit 0dae99bacd
6 changed files with 21 additions and 13 deletions

View File

@ -167,6 +167,14 @@ minetest.after(0, function()
ctf._mt_loaded = true
end)
function ctf.check_save()
if ctf.needs_save then
ctf.save()
end
minetest.after(10, ctf.check_save)
end
minetest.after(10, ctf.check_save)
function ctf.save()
ctf.log("io", "Saving CTF state...")
local file = io.open(minetest.get_worldpath().."/ctf.txt", "w")

View File

@ -232,7 +232,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.clear then
if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
ctf.team(ctf.players[name].team).log = {}
ctf.save()
ctf.needs_save = true
ctf.gui.show(name, "news")
end
return true
@ -246,7 +246,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if ctf and ctf.team(ctf.players[name].team) and ctf.team(ctf.players[name].team).data then
if ctf.flag_colors[fields.color] then
ctf.team(ctf.players[name].team).data.color = fields.color
ctf.save()
ctf.needs_save = true
else
local colors = ""
for color, code in pairs(ctf.flag_colors) do
@ -278,7 +278,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
table.remove(ctf.team(ctf.player(name).team).log,id)
ctf.save()
ctf.needs_save = true
ctf.gui.show(name, "news")
return true
end

View File

@ -18,7 +18,7 @@ function ctf.team(name)
ctf.registered_on_new_team[i](ctf.teams[name.name])
end
ctf.save()
ctf.needs_save = true
return ctf.teams[name.name]
else
@ -145,7 +145,7 @@ function ctf.add_user(team, user)
user.auth = false
_team.players[user.name] = user
ctf.players[user.name] = user
ctf.save()
ctf.needs_save = true
return true
else
@ -198,7 +198,7 @@ function ctf.post(team, msg)
ctf.log("team", "message posted to team board")
table.insert(ctf.team(team).log, 1, msg)
ctf.save()
ctf.needs_save = true
return true
end

View File

@ -140,7 +140,7 @@ minetest.register_chatcommand("ctf_reload", {
description = "reload the ctf main frame and get settings",
privs = {ctf_admin=true},
func = function(name, param)
ctf.save()
ctf.needs_save = true
ctf.init()
minetest.chat_send_player(name, "CTF core reloaded!")
end
@ -159,7 +159,7 @@ minetest.register_chatcommand("team_owner", {
ctf.player(param).auth = true
minetest.chat_send_player(name, param.." was upgraded to an admin of "..ctf.player(name).team,false)
end
ctf.save()
ctf.needs_save = true
else
minetest.chat_send_player(name, "Unable to do that :/ "..param.." does not exist, or is not part of a valid team.",false)
end

View File

@ -68,7 +68,7 @@ local function do_capture(attname, flag, returned)
end
ctf_flag.collect_claimed()
ctf.save()
ctf.needs_save = true
end
minetest.register_on_dieplayer(function(player)
@ -216,7 +216,7 @@ ctf_flag = {
ctf.get_spawn(team)
end
ctf.save()
ctf.needs_save = true
local pos2 = {
x = pos.x,
@ -226,7 +226,7 @@ ctf_flag = {
if not ctf.team(team).data.color then
ctf.team(team).data.color = "red"
ctf.save()
ctf.needs_save = true
end
minetest.env:set_node(pos2, {name="ctf_flag:flag_top_"..ctf.team(team).data.color})

View File

@ -98,7 +98,7 @@ function ctf_flag.add(team, pos)
pos.team = team
table.insert(ctf.team(team).flags,pos)
ctf.save()
ctf.needs_save = true
end
-- get a flag from a team
@ -279,7 +279,7 @@ minetest.register_abm({
if not ctf.team(flag_team_data.team).data.color then
ctf.team(flag_team_data.team).data.color = "red"
ctf.save()
ctf.needs_save = true
end
if flag_team_data.claimed then