-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinit.lua
More file actions
62 lines (54 loc) · 1.5 KB
/
init.lua
File metadata and controls
62 lines (54 loc) · 1.5 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
local OUTFILE = core.get_worldpath() .. "/tmp/ctf_out"
local cache = {}
local function get_player_list()
local player_names = {}
for _, player in ipairs(minetest.get_connected_players()) do
if not core.check_player_privs(player, {spectate = true}) then
table.insert(player_names, player:get_player_name())
end
end
return player_names, #player_names
end
local function update(data)
if core.path_exists(OUTFILE) then
core.safe_file_write(OUTFILE, minetest.write_json(data, true))
end
end
ctf_api.register_on_new_match(function()
cache.current_map = {
name = ctf_map.current_map.name,
technical_name = ctf_map.current_map.dirname,
start_time = os.time(), -- Can be converted to local date here https://www.unixtimestamp.com/
}
cache.current_mode = {
name = ctf_modebase.current_mode,
matches = ctf_modebase.current_mode_matches,
matches_played = ctf_modebase.current_mode_matches_played,
}
update(cache)
end)
minetest.register_on_joinplayer(function()
local player_names, player_count = get_player_list()
cache.player_info = {
players = player_names,
count = player_count
}
update(cache)
end)
minetest.register_on_leaveplayer(function()
minetest.after(0, function()
local player_names, player_count = get_player_list()
cache.player_info = {
players = player_names,
count = player_count
}
update(cache)
end)
end)
minetest.register_on_shutdown(function()
cache = {
error = 1,
error_message = "Server has shut down (or is restarting). Try again later",
}
update(cache)
end)