skinsdb/players.lua

41 lines
774 B
Lua
Raw Normal View History

skins.load_players = function()
local file = io.open(skins.file, "r")
2014-07-23 13:46:42 +02:00
if file then
for line in file:lines() do
local data = string.split(line, " ", 2)
skins.skins[data[1]] = data[2]
2014-03-17 06:26:58 +01:00
end
2014-07-23 13:46:42 +02:00
io.close(file)
2014-03-17 06:26:58 +01:00
end
end
skins.load_players()
2014-07-23 13:46:42 +02:00
local ttime = 0
minetest.register_globalstep(function(t)
ttime = ttime + t
if ttime < 360 then --every 6min'
return
end
ttime = 0
skins.save()
2014-07-23 13:46:42 +02:00
end)
minetest.register_on_shutdown(function() skins.save() end)
2014-03-17 06:26:58 +01:00
skins.save = function()
if not skins.file_save then
2014-07-23 13:46:42 +02:00
return
end
skins.file_save = false
local output = io.open(skins.file, "w")
for name, skin in pairs(skins.skins) do
2014-03-17 06:26:58 +01:00
if name and skin then
if skin ~= skins.default then
2014-07-23 13:46:42 +02:00
output:write(name.." "..skin.."\n")
end
2014-03-17 06:26:58 +01:00
end
end
io.close(output)
end