-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
86 lines (64 loc) · 1.81 KB
/
Copy pathinit.lua
File metadata and controls
86 lines (64 loc) · 1.81 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
nonew = {}
nonew.players = {}
nonew.data = minetest.get_worldpath().."/blocked_nonew.txt"
nonew.state = true
if minetest.setting_get("nonew.state") == 'off' then
nonew.state = false
end
-- This can be overridden with another function
function nonew:action(playername)
if not nonew.state then return end
disconnect_string = "No new players are being accepted at the moment."
if nonew.players[playername] == 1 then
minetest.after(0, function()
minetest.kick_player(playername, disconnect_string)
end)
return disconnect_string
end
end
function nonew:unblock_all()
nonew.players = {}
write_blocked_players()
end
local function write_blocked_players()
local sdata = minetest.serialize(nonew.players)
if not sdata then
minetest.log("error", "No player object data")
return
end
local file, err = io.open(nonew.data, "w")
if err then return err end
file:write(sdata)
file:close()
end
local function read_blocked_players()
local file, err = io.open(nonew.data, "r")
if err then return err end
local sdata = file:read("*a")
file:close()
nonew.players = minetest.deserialize(sdata)
end
function nonew:unblock(playername)
if not playername then return end
nonew.players[playername] = nil
write_blocked_players()
end
function nonew:block(playername)
if not playername then return end
nonew.players[playername] = 1
write_blocked_players()
if minetest.get_player_by_name(playername) then
nonew:action(playername)
end
end
minetest.register_on_newplayer(function(player)
local playername = player:get_player_name()
nonew:block(playername)
nonew:action(playername)
end)
minetest.register_on_prejoinplayer(function(playername, ip)
-- If they are already in the block list, just get them here
return nonew:action(playername)
end)
read_blocked_players()
dofile(minetest.get_modpath("nonew").."/commands.lua")