summaryrefslogtreecommitdiff
path: root/u_skins/players.lua
blob: 772481eca2dae26a8e89e1b8445f530943758377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
u_skins.load_players = function()
	local file = io.open(u_skins.file, "r")
	if file then
		for line in file:lines() do
			local data = string.split(line, " ", 2)
			u_skins.u_skins[data[1]] = data[2]
		end
		io.close(file)
	end
end
u_skins.load_players()

local ttime = 0
minetest.register_globalstep(function(t)
	ttime = ttime + t
	if ttime < 360 then --every 6min'
		return
	end
	ttime = 0
	u_skins.save()
end)

minetest.register_on_shutdown(function() u_skins.save() end)

u_skins.save = function()
	if not u_skins.file_save then
		return
	end
	u_skins.file_save = false
	local output = io.open(u_skins.file, "w")
	for name, skin in pairs(u_skins.u_skins) do
		if name and skin then
			if skin ~= "character_1" then
				output:write(name.." "..skin.."\n")
			end
		end
	end
	io.close(output)
end