-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit.lua
69 lines (54 loc) · 1.87 KB
/
init.lua
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
channels = {}
channels.huds = {}
channels.players = {}
channels.allow_global_channel = minetest.settings:get_bool("channels.allow_global_channel") ~= false
channels.disable_private_messages = minetest.settings:get_bool("channels.disable_private_messages") == true
channels.suggested_channel = minetest.settings:get("channels.suggested_channel")
dofile(minetest.get_modpath("channels") .. "/chatcommands.lua")
if channels.disable_private_messages then
minetest.registered_chatcommands["msg"] = nil
end
local function remind_global_off()
if not channels.allow_global_channel and channels.suggested_channel then
channels.say_chat("*server*",
"<*server*> Out-of-channel chat is off." ..
"(try '/channel join " .. channels.suggested_channel .. "' ?)"
)
end
end
if not channels.allow_global_channel then
local global_inhibition_counter = 0 -- local to the file
minetest.register_globalstep(function(dtime)
global_inhibition_counter = global_inhibition_counter + dtime
if global_inhibition_counter > 5*60 then
global_inhibition_counter = 0
else
return
end
remind_global_off()
end)
end
minetest.register_on_chat_message(function(name, message)
local pl_channel = channels.players[name]
if pl_channel == "" then
channels.players[name] = nil
pl_channel = nil
end
if not pl_channel then
if not channels.allow_global_channel then
minetest.chat_send_player(name, "No channel selected. Run '/channel' for more info")
-- return true to prevent subsequent/global handler from kicking in
return true
else
-- return false to indicate we have not handled the chat
return false
end
end
channels.say_chat(name, "<" .. name .. "> " .. message, pl_channel)
return true
end)
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
channels.players[name] = nil
channels.huds[name] = nil
end)