1 local playerdb = elidragon.playerdb
5 local players = playerdb.players
6 local admin = minetest.settings:get("name")
7 local server = minetest.settings:get("server_name")
8 playerdb.initial_data.rank = "player"
10 function ranks.get(name)
15 local playerdata = players[name]
17 rank = playerdata.rank
19 rank = name == admin and "console" or "offline"
22 return rank, ranks.defs[rank]
25 function ranks.get_player_name(name, brackets)
26 local _, def = ranks.get(name)
27 brackets = brackets or {"", ""}
28 return minetest.colorize("#" .. def.color, def.tag) .. brackets[1] .. name .. brackets[2]
31 function ranks.reload(player)
32 local name = player:get_player_name()
33 local rank, def = ranks.get(name)
34 player:set_nametag_attributes({text = rank == "system" and "" or ranks.get_player_name(name)})
35 minetest.set_player_privs(name, assert(def.privs))
38 function ranks.set(name, rank)
40 return false, "The rank of the rpc player cannot be changed."
42 local rank_def = ranks.defs[rank]
43 if not rank_def or rank_def.can_assign == false then
44 return false, "Invalid rank."
46 local player = minetest.get_player_by_name(name)
48 return false, name .. " is not online."
50 local playerdata = players[name]
51 playerdata.rank = rank
56 minetest.register_on_joinplayer(ranks.reload)
58 function minetest.send_join_message(name)
60 minetest.chat_send_all("*** " .. ranks.get_player_name(name) .. " joined " .. server .. ".")
64 function minetest.send_leave_message(name, timed_out)
66 minetest.chat_send_all("*** " .. ranks.get_player_name(name) .. " left " .. server .. (timed_out and " (timed out)" or "") .. ".")
70 minetest.register_on_chat_message(function(name, message)
71 if not minetest.check_player_privs(name, {shout = true}) then
74 minetest.chat_send_all(ranks.get_player_name(name, {"<", ">"}) .. " " .. message)
78 minetest.register_chatcommand("rank", {
79 params = "<player> <rank>",
80 description = "Set a player's rank",
81 privs = {privs = true},
82 func = function(name, param)
83 local target = param:split(" ")[1] or ""
84 local rank = param:split(" ")[2] or ""
85 return ranks.set(target, rank)
89 local function get_privs_setting(setting, tbl)
90 local privs = minetest.string_to_privs(minetest.settings:get(setting))
92 for k, v in pairs(tbl) do
99 minetest.register_on_mods_loaded(function()
100 local all_privs = minetest.registered_privileges
101 local default_privs = get_privs_setting("default_privs")
102 local moderator_privs = get_privs_setting("moderator_privs", default_privs)
103 local vip_privs = get_privs_setting("vip_privs", default_privs)
104 local mvp_privs = get_privs_setting("mvp_privs", vip_privs)
111 description = "The Developer rank is for the admins who maintain the server software.",
117 description = "The Admin rank is for people with ssh access to the server, they have all privileges. They are members of the Elidragon group.",
123 description = "People who moderate the server.",
124 privs = moderator_privs,
127 tag = "[Contributor]",
129 description = "The Contributor rank is for people that contribute to the server software. It has the same privs as the MVP rank.",
135 description = "The Builder rank is for people that have helped constructing the buildings in the lobby etc. It has the same privs as the MVP rank.",
141 description = "The MVP rank can be purchased in out store (upcoming). It is purely cosmetic.",
147 description = "The VIP rank can be purchased in out store (upcoming). It is purely cosmetic.",
153 description = "This is the rank for normal players.",
154 privs = default_privs,
159 description = "This is an offline rank for the console.",
165 description = "This is the default offline rank.",
171 description = "This is the rank for the rpc player, which is a bot.",