forked from googolgl/lp_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.lua
100 lines (87 loc) · 3.69 KB
/
router.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
--
-- router
--
lp_api.router = {}
lp_api.router.cmd = minetest.settings:get("lp_api.router.cmd") or false
function lp_api.router.to_string(tab, from_key)
local res
for k = #tab, from_key, -1 do
if res then
res = tab[k].." "..res
else
res = tab[k]
end
end
return res
end
function lp_api.msg_router(data)
if data.type == "chat" then
minetest.chat_send_all(core.colorize("#debd21", "<"..data.player.."> "..data.message))
end
if data.type == "cmd" and lp_api.router.cmd then
if data.command == "msg" then
minetest.chat_send_player(data.args[1],
core.colorize("#de6821", "<"..data.player.."> "..lp_api.router.to_string(data.args, 2)))
end
if data.command == "ban" then
minetest.ban_player(data.args[1])
lp_api.publisher.pub_msg("minetest", "system", "Player {"..data.args[1].."} Banned!", "")
end
if data.command == "unban" then
minetest.unban_player_or_ip(data.args[1])
lp_api.publisher.pub_msg("minetest", "system", "Player {"..data.args[1].."} UnBanned!", "")
end
if data.command == "kick" then
local result = minetest.kick_player(data.args[1], lp_api.router.to_string(data.args, 2))
if result then
if data.args[2] then
lp_api.publisher.pub_msg("minetest", "system",
"Player {"..data.args[1].."} kicked!", lp_api.router.to_string(data.args, 2))
else
lp_api.publisher.pub_msg("minetest", "system",
"Player {"..data.args[1].."} kicked!", "")
end
end
end
if data.command == "grant" then
if data.args[2] then
local sp = lp_api.router.to_string(data.args, 2)
local add_privs = minetest.string_to_privs(sp)
local privs = minetest.get_player_privs(data.args[1])
for p, _ in pairs(add_privs) do
privs[p] = true
end
minetest.set_player_privs(data.args[1], privs)
lp_api.publisher.pub_msg("minetest", "system", "The {"..data.args[1].."} was given the", sp)
end
end
if data.command == "revoke" then
if data.args[2] then
local sp = lp_api.router.to_string(data.args, 2)
local add_privs = minetest.string_to_privs(sp)
local privs = minetest.get_player_privs(data.args[1])
for p, _ in pairs(add_privs) do
privs[p] = nil
end
minetest.set_player_privs(data.args[1], privs)
lp_api.publisher.pub_msg("minetest", "system", "The {"..data.args[1].."} was taken away the", sp)
end
end
if data.command == "privs" then
local privs = minetest.privs_to_string(minetest.get_player_privs(data.args[1]), ' ')
lp_api.publisher.pub_msg("minetest", "system", "Privileges of {"..data.args[1].."}:", privs)
end
if data.command == "status" then
lp_api.publisher.pub_msg("minetest", "system", "Status server.", minetest.get_server_status())
end
end
end
minetest.register_on_chat_message(function(name, message)
lp_api.publisher.pub_msg(name, "chat", "", message)
end)
minetest.register_on_joinplayer(function(player)
lp_api.publisher.pub_msg("minetest", "chat", "", "player {"..player:get_player_name().."} joined the game")
end)
minetest.register_on_leaveplayer(function(player)
lp_api.publisher.pub_msg("minetest", "chat", "", "player {"..player:get_player_name().."} left the game")
end)