]> git.lizzy.rs Git - coronaserver.git/blob - init.lua
Save data
[coronaserver.git] / init.lua
1 coronaserver = {}
2 function coronaserver.load()
3         local file = io.open(minetest.get_worldpath() .. "/coronaserver", "r")
4         if file then
5                 coronaserver.savedata = minetest.deserialize(file:read())
6                 file:close()
7         else
8                 coronaserver.savedata = {}
9         end
10 end
11 function coronaserver.save()
12         local file = io.open(minetest.get_worldpath() .. "/coronaserver", "w")
13         file:write(minetest.serialize(coronaserver.savedata))
14         file:close()
15 end
16 coronaserver.load()
17
18 coronaserver.grantall = coronaserver.grantall or {}
19
20 function coronaserver.update_privs(player)
21         local name = player:get_player_name()
22         local privs = minetest.get_player_privs(name)
23         for _, priv in pairs(coronaserver.grantall) do
24                 privs[priv] = true
25         end
26         minetest.set_player_privs(name, privs)
27 end
28
29 minetest.register_on_joinplayer(coronaserver.update_privs)
30
31 minetest.register_chatcommand("grantall", {
32         description = "Grant a privilegue to players when they join",
33         param = "<priv>",
34         privs = {privs = true},
35         func = function(name, param)
36                 coronaserver.grantall[#coronaserver.grantall] = param
37                 local players = minetest.get_connected_players()
38                 for _, player in pairs(players) do
39                         coronaserver.update_privs(player)
40                 end
41                 coronaserver.save()
42         end
43 })