Use: safe_file_write
This commit is contained in:
parent
3e63a1c657
commit
c65bde260e
37
factions.lua
37
factions.lua
@ -341,6 +341,8 @@ end
|
|||||||
|
|
||||||
function factions.Faction.remove_player(self, player)
|
function factions.Faction.remove_player(self, player)
|
||||||
self.players[player] = nil
|
self.players[player] = nil
|
||||||
|
self.onlineplayers[player] = nil
|
||||||
|
self.offlineplayers[player] = nil
|
||||||
factions.players[player] = nil
|
factions.players[player] = nil
|
||||||
self:on_player_leave(player)
|
self:on_player_leave(player)
|
||||||
self:check_players_in_faction(self)
|
self:check_players_in_faction(self)
|
||||||
@ -368,7 +370,7 @@ function factions.Faction.remove_player(self, player)
|
|||||||
self.onlineplayers[player] = nil
|
self.onlineplayers[player] = nil
|
||||||
factions.bulk_save()
|
factions.bulk_save()
|
||||||
end
|
end
|
||||||
|
local parcel_size = factions_config.parcel_size
|
||||||
--! @param parcelpos position of the wanted parcel
|
--! @param parcelpos position of the wanted parcel
|
||||||
--! @return whether this faction can claim a parcelpos
|
--! @return whether this faction can claim a parcelpos
|
||||||
function factions.Faction.can_claim_parcel(self, parcelpos)
|
function factions.Faction.can_claim_parcel(self, parcelpos)
|
||||||
@ -599,7 +601,7 @@ end
|
|||||||
function factions.Faction.tp_spawn(self, playername)
|
function factions.Faction.tp_spawn(self, playername)
|
||||||
player = minetest.get_player_by_name(playername)
|
player = minetest.get_player_by_name(playername)
|
||||||
if player then
|
if player then
|
||||||
player:moveto(self.spawn, false)
|
player:set_pos(self.spawn)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -926,7 +928,6 @@ function factions.Faction.on_revoke_invite(self, player)
|
|||||||
minetest.chat_send_player(player, "You are no longer invited to faction "..self.name)
|
minetest.chat_send_player(player, "You are no longer invited to faction "..self.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
local parcel_size = factions_config.parcel_size
|
|
||||||
function factions.get_parcel_pos(pos)
|
function factions.get_parcel_pos(pos)
|
||||||
if factions_config.protection_style == "2d" then
|
if factions_config.protection_style == "2d" then
|
||||||
return math.floor(pos.x / parcel_size) * parcel_size .. "," .. math.floor(pos.z / parcel_size) * parcel_size
|
return math.floor(pos.x / parcel_size) * parcel_size .. "," .. math.floor(pos.z / parcel_size) * parcel_size
|
||||||
@ -1023,17 +1024,12 @@ function factions.save()
|
|||||||
--due to figuring out which data to save and which is temporary only
|
--due to figuring out which data to save and which is temporary only
|
||||||
--all data is saved here
|
--all data is saved here
|
||||||
--this implies data needs to be cleant up on load
|
--this implies data needs to be cleant up on load
|
||||||
|
saving = false
|
||||||
local file,error = io.open(factions_worldid .. "/" .. "factions.conf","w")
|
if not minetest.safe_file_write(factions_worldid .. "/" .. "factions.conf",minetest.serialize(factions.factions)) then
|
||||||
|
|
||||||
if file ~= nil then
|
|
||||||
file:write(minetest.serialize(factions.factions))
|
|
||||||
file:close()
|
|
||||||
else
|
|
||||||
minetest.log("error","MOD factions: unable to save factions world specific data!: " .. error)
|
minetest.log("error","MOD factions: unable to save factions world specific data!: " .. error)
|
||||||
|
factions.bulk_save()
|
||||||
end
|
end
|
||||||
factions_ip.save()
|
factions_ip.save()
|
||||||
saving = false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function factions.bulk_save()
|
function factions.bulk_save()
|
||||||
@ -1239,11 +1235,8 @@ function factions.faction_tick()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local player_count = 0
|
|
||||||
|
|
||||||
minetest.register_on_joinplayer(
|
minetest.register_on_joinplayer(
|
||||||
function(player)
|
function(player)
|
||||||
player_count = player_count + 1
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
minetest.after(5,createHudfactionLand,player)
|
minetest.after(5,createHudfactionLand,player)
|
||||||
local faction = factions.get_player_faction(name)
|
local faction = factions.get_player_faction(name)
|
||||||
@ -1252,7 +1245,7 @@ function(player)
|
|||||||
minetest.after(5,createHudFactionName,player,faction.name)
|
minetest.after(5,createHudFactionName,player,faction.name)
|
||||||
minetest.after(5,createHudPower,player,faction)
|
minetest.after(5,createHudPower,player,faction)
|
||||||
faction.offlineplayers[name] = nil
|
faction.offlineplayers[name] = nil
|
||||||
faction.onlineplayers[name] = 1
|
faction.onlineplayers[name] = true
|
||||||
if faction.no_parcel ~= -1 then
|
if faction.no_parcel ~= -1 then
|
||||||
local now = os.time() - faction.no_parcel
|
local now = os.time() - faction.no_parcel
|
||||||
local l = factions_config.maximum_parcelless_faction_time
|
local l = factions_config.maximum_parcelless_faction_time
|
||||||
@ -1282,7 +1275,6 @@ end
|
|||||||
|
|
||||||
minetest.register_on_leaveplayer(
|
minetest.register_on_leaveplayer(
|
||||||
function(player)
|
function(player)
|
||||||
player_count = player_count - 1
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local faction = factions.get_player_faction(name)
|
local faction = factions.get_player_faction(name)
|
||||||
local id_name1 = name .. "factionLand"
|
local id_name1 = name .. "factionLand"
|
||||||
@ -1298,14 +1290,9 @@ minetest.register_on_leaveplayer(
|
|||||||
if hud_ids[id_name3] then
|
if hud_ids[id_name3] then
|
||||||
hud_ids[id_name3] = nil
|
hud_ids[id_name3] = nil
|
||||||
end
|
end
|
||||||
faction.offlineplayers[name] = 1
|
faction.offlineplayers[name] = true
|
||||||
faction.onlineplayers[name] = nil
|
faction.onlineplayers[name] = nil
|
||||||
end
|
end
|
||||||
if player_count > 0 then
|
|
||||||
factions.bulk_save()
|
|
||||||
else
|
|
||||||
factions.save()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1325,7 +1312,11 @@ minetest.register_on_respawnplayer(
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
minetest.register_on_shutdown(
|
||||||
|
function()
|
||||||
|
factions.save()
|
||||||
|
saving = false
|
||||||
|
end)
|
||||||
|
|
||||||
local default_is_protected = minetest.is_protected
|
local default_is_protected = minetest.is_protected
|
||||||
minetest.is_protected = function(pos, player)
|
minetest.is_protected = function(pos, player)
|
||||||
|
11
ip.lua
11
ip.lua
@ -5,14 +5,9 @@ factions_ip.player_ips = {}
|
|||||||
local factions_worldid = minetest.get_worldpath()
|
local factions_worldid = minetest.get_worldpath()
|
||||||
|
|
||||||
function factions_ip.save()
|
function factions_ip.save()
|
||||||
local file,error = io.open(factions_worldid .. "/" .. "factions_iplist.txt","w")
|
if not minetest.safe_file_write(factions_worldid .. "/" .. "factions_iplist.txt", minetest.serialize(factions_ip.player_ips)) then
|
||||||
|
minetest.log("error","MOD factions: unable to save faction player ips!: " .. error)
|
||||||
if file ~= nil then
|
end
|
||||||
file:write(minetest.serialize(factions_ip.player_ips))
|
|
||||||
file:close()
|
|
||||||
else
|
|
||||||
minetest.log("error","MOD factions: unable to save faction player ips!: " .. error)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function factions_ip.load()
|
function factions_ip.load()
|
||||||
|
@ -5,12 +5,7 @@ misc_mod_data.data = {factions_version = "0.8.1",config = factions_config}
|
|||||||
local factions_worldid = minetest.get_worldpath()
|
local factions_worldid = minetest.get_worldpath()
|
||||||
|
|
||||||
function misc_mod_data.save()
|
function misc_mod_data.save()
|
||||||
local file,error = io.open(factions_worldid .. "/" .. "factions_misc_mod_data.txt","w")
|
if not minetest.safe_file_write(factions_worldid .. "/" .. "factions_misc_mod_data.txt", minetest.serialize(misc_mod_data.data)) then
|
||||||
|
|
||||||
if file ~= nil then
|
|
||||||
file:write(minetest.serialize(misc_mod_data.data))
|
|
||||||
file:close()
|
|
||||||
else
|
|
||||||
minetest.log("error","MOD factions: unable to save factions misc mod data!: " .. error)
|
minetest.log("error","MOD factions: unable to save factions misc mod data!: " .. error)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user