1 -- Minetest: builtin/chatcommands.lua
4 -- Chat command handler
7 core.registered_chatcommands = {}
8 core.chatcommands = core.registered_chatcommands -- BACKWARDS COMPATIBILITY
9 function core.register_chatcommand(cmd, def)
11 def.params = def.params or ""
12 def.description = def.description or ""
13 def.privs = def.privs or {}
14 def.mod_origin = core.get_current_modname() or "??"
15 core.registered_chatcommands[cmd] = def
18 core.register_on_chat_message(function(name, message)
19 local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
23 local cmd_def = core.registered_chatcommands[cmd]
27 local has_privs, missing_privs = core.check_player_privs(name, cmd_def.privs)
29 core.set_last_run_mod(cmd_def.mod_origin)
30 local success, message = cmd_def.func(name, param)
32 core.chat_send_player(name, message)
35 core.chat_send_player(name, "You don't have permission"
36 .. " to run this command (missing privileges: "
37 .. table.concat(missing_privs, ", ") .. ")")
39 return true -- Handled chat message
42 if core.setting_getbool("profiler.load") then
43 -- Run after register_chatcommand and its register_on_chat_message
44 -- Before any chattcommands that should be profiled
45 profiler.init_chatcommand()
48 -- Parses a "range" string in the format of "here (number)" or
49 -- "(x1, y1, z1) (x2, y2, z2)", returning two position vectors
50 local function parse_range_str(player_name, str)
52 local args = str:split(" ")
54 if args[1] == "here" then
55 p1, p2 = core.get_player_radius_area(player_name, tonumber(args[2]))
57 return false, "Unable to get player " .. player_name .. " position"
60 p1, p2 = core.string_to_area(str)
62 return false, "Incorrect area format. Expected: (x1,y1,z1) (x2,y2,z2)"
72 core.register_chatcommand("me", {
74 description = "chat action (eg. /me orders a pizza)",
76 func = function(name, param)
77 core.chat_send_all("* " .. name .. " " .. param)
81 core.register_chatcommand("admin", {
82 description = "Show the name of the server owner",
84 local admin = minetest.setting_get("name")
86 return true, "The administrator of this server is "..admin.."."
88 return false, "There's no administrator named in the config file."
93 core.register_chatcommand("help", {
95 params = "[all/privs/<cmd>]",
96 description = "Get help for commands or list privileges",
97 func = function(name, param)
98 local function format_help_line(cmd, def)
99 local msg = core.colorize("#00ffff", "/"..cmd)
100 if def.params and def.params ~= "" then
101 msg = msg .. " " .. def.params
103 if def.description and def.description ~= "" then
104 msg = msg .. ": " .. def.description
111 for cmd, def in pairs(core.registered_chatcommands) do
112 if core.check_player_privs(name, def.privs) then
113 cmds[#cmds + 1] = cmd
117 return true, "Available commands: " .. table.concat(cmds, " ") .. "\n"
118 .. "Use '/help <cmd>' to get more information,"
119 .. " or '/help all' to list everything."
120 elseif param == "all" then
122 for cmd, def in pairs(core.registered_chatcommands) do
123 if core.check_player_privs(name, def.privs) then
124 cmds[#cmds + 1] = format_help_line(cmd, def)
128 return true, "Available commands:\n"..table.concat(cmds, "\n")
129 elseif param == "privs" then
131 for priv, def in pairs(core.registered_privileges) do
132 privs[#privs + 1] = priv .. ": " .. def.description
135 return true, "Available privileges:\n"..table.concat(privs, "\n")
138 local def = core.registered_chatcommands[cmd]
140 return false, "Command not available: "..cmd
142 return true, format_help_line(cmd, def)
148 core.register_chatcommand("privs", {
150 description = "print out privileges of player",
151 func = function(caller, param)
153 local name = (param ~= "" and param or caller)
154 return true, "Privileges of " .. name .. ": "
155 .. core.privs_to_string(
156 core.get_player_privs(name), ' ')
160 local function handle_grant_command(caller, grantname, grantprivstr)
161 local caller_privs = minetest.get_player_privs(caller)
162 if not (caller_privs.privs or caller_privs.basic_privs) then
163 return false, "Your privileges are insufficient."
166 if not core.get_auth_handler().get_auth(grantname) then
167 return false, "Player " .. grantname .. " does not exist."
169 local grantprivs = core.string_to_privs(grantprivstr)
170 if grantprivstr == "all" then
171 grantprivs = core.registered_privileges
173 local privs = core.get_player_privs(grantname)
174 local privs_unknown = ""
176 core.string_to_privs(core.setting_get("basic_privs") or "interact,shout")
177 for priv, _ in pairs(grantprivs) do
178 if not basic_privs[priv] and not caller_privs.privs then
179 return false, "Your privileges are insufficient."
181 if not core.registered_privileges[priv] then
182 privs_unknown = privs_unknown .. "Unknown privilege: " .. priv .. "\n"
186 if privs_unknown ~= "" then
187 return false, privs_unknown
189 core.set_player_privs(grantname, privs)
190 core.log("action", caller..' granted ('..core.privs_to_string(grantprivs, ', ')..') privileges to '..grantname)
191 if grantname ~= caller then
192 core.chat_send_player(grantname, caller
193 .. " granted you privileges: "
194 .. core.privs_to_string(grantprivs, ' '))
196 return true, "Privileges of " .. grantname .. ": "
197 .. core.privs_to_string(
198 core.get_player_privs(grantname), ' ')
201 core.register_chatcommand("grant", {
202 params = "<name> <privilege>|all",
203 description = "Give privilege to player",
204 func = function(name, param)
205 local grantname, grantprivstr = string.match(param, "([^ ]+) (.+)")
206 if not grantname or not grantprivstr then
207 return false, "Invalid parameters (see /help grant)"
209 return handle_grant_command(name, grantname, grantprivstr)
213 core.register_chatcommand("grantme", {
214 params = "<privilege>|all",
215 description = "Grant privileges to yourself",
216 func = function(name, param)
218 return false, "Invalid parameters (see /help grantme)"
220 return handle_grant_command(name, name, param)
224 core.register_chatcommand("revoke", {
225 params = "<name> <privilege>|all",
226 description = "Remove privilege from player",
228 func = function(name, param)
229 if not core.check_player_privs(name, {privs=true}) and
230 not core.check_player_privs(name, {basic_privs=true}) then
231 return false, "Your privileges are insufficient."
233 local revoke_name, revoke_priv_str = string.match(param, "([^ ]+) (.+)")
234 if not revoke_name or not revoke_priv_str then
235 return false, "Invalid parameters (see /help revoke)"
236 elseif not core.get_auth_handler().get_auth(revoke_name) then
237 return false, "Player " .. revoke_name .. " does not exist."
239 local revoke_privs = core.string_to_privs(revoke_priv_str)
240 local privs = core.get_player_privs(revoke_name)
242 core.string_to_privs(core.setting_get("basic_privs") or "interact,shout")
243 for priv, _ in pairs(revoke_privs) do
244 if not basic_privs[priv] and
245 not core.check_player_privs(name, {privs=true}) then
246 return false, "Your privileges are insufficient."
249 if revoke_priv_str == "all" then
252 for priv, _ in pairs(revoke_privs) do
256 core.set_player_privs(revoke_name, privs)
257 core.log("action", name..' revoked ('
258 ..core.privs_to_string(revoke_privs, ', ')
259 ..') privileges from '..revoke_name)
260 if revoke_name ~= name then
261 core.chat_send_player(revoke_name, name
262 .. " revoked privileges from you: "
263 .. core.privs_to_string(revoke_privs, ' '))
265 return true, "Privileges of " .. revoke_name .. ": "
266 .. core.privs_to_string(
267 core.get_player_privs(revoke_name), ' ')
271 core.register_chatcommand("setpassword", {
272 params = "<name> <password>",
273 description = "set given password",
274 privs = {password=true},
275 func = function(name, param)
276 local toname, raw_password = string.match(param, "^([^ ]+) +(.+)$")
278 toname = param:match("^([^ ]+) *$")
282 return false, "Name field required"
284 local act_str_past = "?"
285 local act_str_pres = "?"
286 if not raw_password then
287 core.set_player_password(toname, "")
288 act_str_past = "cleared"
289 act_str_pres = "clears"
291 core.set_player_password(toname,
292 core.get_password_hash(toname,
295 act_str_pres = "sets"
297 if toname ~= name then
298 core.chat_send_player(toname, "Your password was "
299 .. act_str_past .. " by " .. name)
302 core.log("action", name .. " " .. act_str_pres
303 .. " password of " .. toname .. ".")
305 return true, "Password of player \"" .. toname .. "\" " .. act_str_past
309 core.register_chatcommand("clearpassword", {
311 description = "set empty password",
312 privs = {password=true},
313 func = function(name, param)
316 return false, "Name field required"
318 core.set_player_password(toname, '')
320 core.log("action", name .. " clears password of " .. toname .. ".")
322 return true, "Password of player \"" .. toname .. "\" cleared"
326 core.register_chatcommand("auth_reload", {
328 description = "reload authentication data",
329 privs = {server=true},
330 func = function(name, param)
331 local done = core.auth_reload()
332 return done, (done and "Done." or "Failed.")
336 core.register_chatcommand("teleport", {
337 params = "<X>,<Y>,<Z> | <to_name> | <name> <X>,<Y>,<Z> | <name> <to_name>",
338 description = "teleport to given position",
339 privs = {teleport=true},
340 func = function(name, param)
341 -- Returns (pos, true) if found, otherwise (pos, false)
342 local function find_free_position_near(pos)
349 for _, d in ipairs(tries) do
350 local p = {x = pos.x+d.x, y = pos.y+d.y, z = pos.z+d.z}
351 local n = core.get_node_or_nil(p)
353 local def = core.registered_nodes[n.name]
354 if def and not def.walkable then
362 local teleportee = nil
364 p.x, p.y, p.z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
368 if p.x and p.y and p.z then
369 local lm = tonumber(minetest.setting_get("map_generation_limit") or 31000)
370 if p.x < -lm or p.x > lm or p.y < -lm or p.y > lm or p.z < -lm or p.z > lm then
371 return false, "Cannot teleport out of map bounds!"
373 teleportee = core.get_player_by_name(name)
376 return true, "Teleporting to "..core.pos_to_string(p)
380 local teleportee = nil
382 local target_name = nil
383 target_name = param:match("^([^ ]+)$")
384 teleportee = core.get_player_by_name(name)
386 local target = core.get_player_by_name(target_name)
391 if teleportee and p then
392 p = find_free_position_near(p)
394 return true, "Teleporting to " .. target_name
395 .. " at "..core.pos_to_string(p)
398 if not core.check_player_privs(name, {bring=true}) then
399 return false, "You don't have permission to teleport other players (missing bring privilege)"
402 local teleportee = nil
404 local teleportee_name = nil
405 teleportee_name, p.x, p.y, p.z = param:match(
406 "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
407 p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
408 if teleportee_name then
409 teleportee = core.get_player_by_name(teleportee_name)
411 if teleportee and p.x and p.y and p.z then
413 return true, "Teleporting " .. teleportee_name
414 .. " to " .. core.pos_to_string(p)
417 local teleportee = nil
419 local teleportee_name = nil
420 local target_name = nil
421 teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
422 if teleportee_name then
423 teleportee = core.get_player_by_name(teleportee_name)
426 local target = core.get_player_by_name(target_name)
431 if teleportee and p then
432 p = find_free_position_near(p)
434 return true, "Teleporting " .. teleportee_name
435 .. " to " .. target_name
436 .. " at " .. core.pos_to_string(p)
439 return false, 'Invalid parameters ("' .. param
440 .. '") or player not found (see /help teleport)'
444 core.register_chatcommand("set", {
445 params = "[-n] <name> <value> | <name>",
446 description = "set or read server configuration setting",
447 privs = {server=true},
448 func = function(name, param)
449 local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)")
450 if arg and arg == "-n" and setname and setvalue then
451 core.setting_set(setname, setvalue)
452 return true, setname .. " = " .. setvalue
454 local setname, setvalue = string.match(param, "([^ ]+) (.+)")
455 if setname and setvalue then
456 if not core.setting_get(setname) then
457 return false, "Failed. Use '/set -n <name> <value>' to create a new setting."
459 core.setting_set(setname, setvalue)
460 return true, setname .. " = " .. setvalue
462 local setname = string.match(param, "([^ ]+)")
464 local setvalue = core.setting_get(setname)
466 setvalue = "<not set>"
468 return true, setname .. " = " .. setvalue
470 return false, "Invalid parameters (see /help set)."
474 local function emergeblocks_callback(pos, action, num_calls_remaining, ctx)
475 if ctx.total_blocks == 0 then
476 ctx.total_blocks = num_calls_remaining + 1
477 ctx.current_blocks = 0
479 ctx.current_blocks = ctx.current_blocks + 1
481 if ctx.current_blocks == ctx.total_blocks then
482 core.chat_send_player(ctx.requestor_name,
483 string.format("Finished emerging %d blocks in %.2fms.",
484 ctx.total_blocks, (os.clock() - ctx.start_time) * 1000))
488 local function emergeblocks_progress_update(ctx)
489 if ctx.current_blocks ~= ctx.total_blocks then
490 core.chat_send_player(ctx.requestor_name,
491 string.format("emergeblocks update: %d/%d blocks emerged (%.1f%%)",
492 ctx.current_blocks, ctx.total_blocks,
493 (ctx.current_blocks / ctx.total_blocks) * 100))
495 core.after(2, emergeblocks_progress_update, ctx)
499 core.register_chatcommand("emergeblocks", {
500 params = "(here [radius]) | (<pos1> <pos2>)",
501 description = "starts loading (or generating, if inexistent) map blocks "
502 .. "contained in area pos1 to pos2",
503 privs = {server=true},
504 func = function(name, param)
505 local p1, p2 = parse_range_str(name, param)
513 start_time = os.clock(),
514 requestor_name = name
517 core.emerge_area(p1, p2, emergeblocks_callback, context)
518 core.after(2, emergeblocks_progress_update, context)
520 return true, "Started emerge of area ranging from " ..
521 core.pos_to_string(p1, 1) .. " to " .. core.pos_to_string(p2, 1)
525 core.register_chatcommand("deleteblocks", {
526 params = "(here [radius]) | (<pos1> <pos2>)",
527 description = "delete map blocks contained in area pos1 to pos2",
528 privs = {server=true},
529 func = function(name, param)
530 local p1, p2 = parse_range_str(name, param)
535 if core.delete_area(p1, p2) then
536 return true, "Successfully cleared area ranging from " ..
537 core.pos_to_string(p1, 1) .. " to " .. core.pos_to_string(p2, 1)
539 return false, "Failed to clear one or more blocks in area"
544 core.register_chatcommand("mods", {
546 description = "List mods installed on the server",
548 func = function(name, param)
549 return true, table.concat(core.get_modnames(), ", ")
553 local function handle_give_command(cmd, giver, receiver, stackstring)
554 core.log("action", giver .. " invoked " .. cmd
555 .. ', stackstring="' .. stackstring .. '"')
556 local itemstack = ItemStack(stackstring)
557 if itemstack:is_empty() then
558 return false, "Cannot give an empty item"
559 elseif not itemstack:is_known() then
560 return false, "Cannot give an unknown item"
562 local receiverref = core.get_player_by_name(receiver)
563 if receiverref == nil then
564 return false, receiver .. " is not a known player"
566 local leftover = receiverref:get_inventory():add_item("main", itemstack)
568 if leftover:is_empty() then
570 elseif leftover:get_count() == itemstack:get_count() then
571 partiality = "could not be "
573 partiality = "partially "
575 -- The actual item stack string may be different from what the "giver"
576 -- entered (e.g. big numbers are always interpreted as 2^16-1).
577 stackstring = itemstack:to_string()
578 if giver == receiver then
579 return true, ("%q %sadded to inventory.")
580 :format(stackstring, partiality)
582 core.chat_send_player(receiver, ("%q %sadded to inventory.")
583 :format(stackstring, partiality))
584 return true, ("%q %sadded to %s's inventory.")
585 :format(stackstring, partiality, receiver)
589 core.register_chatcommand("give", {
590 params = "<name> <ItemString>",
591 description = "give item to player",
593 func = function(name, param)
594 local toname, itemstring = string.match(param, "^([^ ]+) +(.+)$")
595 if not toname or not itemstring then
596 return false, "Name and ItemString required"
598 return handle_give_command("/give", name, toname, itemstring)
602 core.register_chatcommand("giveme", {
603 params = "<ItemString>",
604 description = "give item to yourself",
606 func = function(name, param)
607 local itemstring = string.match(param, "(.+)$")
608 if not itemstring then
609 return false, "ItemString required"
611 return handle_give_command("/giveme", name, name, itemstring)
615 core.register_chatcommand("spawnentity", {
616 params = "<EntityName> [<X>,<Y>,<Z>]",
617 description = "Spawn entity at given (or your) position",
618 privs = {give=true, interact=true},
619 func = function(name, param)
620 local entityname, p = string.match(param, "^([^ ]+) *(.*)$")
621 if not entityname then
622 return false, "EntityName required"
624 core.log("action", ("%s invokes /spawnentity, entityname=%q")
625 :format(name, entityname))
626 local player = core.get_player_by_name(name)
627 if player == nil then
628 core.log("error", "Unable to spawn entity, player is nil")
629 return false, "Unable to spawn entity, player is nil"
634 p = core.string_to_pos(p)
636 return false, "Invalid parameters ('" .. param .. "')"
640 core.add_entity(p, entityname)
641 return true, ("%q spawned."):format(entityname)
645 core.register_chatcommand("pulverize", {
647 description = "Destroy item in hand",
648 func = function(name, param)
649 local player = core.get_player_by_name(name)
651 core.log("error", "Unable to pulverize, no player.")
652 return false, "Unable to pulverize, no player."
654 if player:get_wielded_item():is_empty() then
655 return false, "Unable to pulverize, no item in hand."
657 player:set_wielded_item(nil)
658 return true, "An item was pulverized."
663 core.rollback_punch_callbacks = {}
665 core.register_on_punchnode(function(pos, node, puncher)
666 local name = puncher:get_player_name()
667 if core.rollback_punch_callbacks[name] then
668 core.rollback_punch_callbacks[name](pos, node, puncher)
669 core.rollback_punch_callbacks[name] = nil
673 core.register_chatcommand("rollback_check", {
674 params = "[<range>] [<seconds>] [limit]",
675 description = "Check who has last touched a node or near it,"
676 .. " max. <seconds> ago (default range=0,"
677 .. " seconds=86400=24h, limit=5)",
678 privs = {rollback=true},
679 func = function(name, param)
680 if not core.setting_getbool("enable_rollback_recording") then
681 return false, "Rollback functions are disabled."
683 local range, seconds, limit =
684 param:match("(%d+) *(%d*) *(%d*)")
685 range = tonumber(range) or 0
686 seconds = tonumber(seconds) or 86400
687 limit = tonumber(limit) or 5
689 return false, "That limit is too high!"
692 core.rollback_punch_callbacks[name] = function(pos, node, puncher)
693 local name = puncher:get_player_name()
694 core.chat_send_player(name, "Checking " .. core.pos_to_string(pos) .. "...")
695 local actions = core.rollback_get_node_actions(pos, range, seconds, limit)
697 core.chat_send_player(name, "Rollback functions are disabled")
700 local num_actions = #actions
701 if num_actions == 0 then
702 core.chat_send_player(name, "Nobody has touched"
703 .. " the specified location in "
704 .. seconds .. " seconds")
707 local time = os.time()
708 for i = num_actions, 1, -1 do
709 local action = actions[i]
710 core.chat_send_player(name,
711 ("%s %s %s -> %s %d seconds ago.")
713 core.pos_to_string(action.pos),
721 return true, "Punch a node (range=" .. range .. ", seconds="
722 .. seconds .. "s, limit=" .. limit .. ")"
726 core.register_chatcommand("rollback", {
727 params = "<player name> [<seconds>] | :<actor> [<seconds>]",
728 description = "revert actions of a player; default for <seconds> is 60",
729 privs = {rollback=true},
730 func = function(name, param)
731 if not core.setting_getbool("enable_rollback_recording") then
732 return false, "Rollback functions are disabled."
734 local target_name, seconds = string.match(param, ":([^ ]+) *(%d*)")
735 if not target_name then
736 local player_name = nil
737 player_name, seconds = string.match(param, "([^ ]+) *(%d*)")
738 if not player_name then
739 return false, "Invalid parameters. See /help rollback"
740 .. " and /help rollback_check."
742 target_name = "player:"..player_name
744 seconds = tonumber(seconds) or 60
745 core.chat_send_player(name, "Reverting actions of "
746 .. target_name .. " since "
747 .. seconds .. " seconds.")
748 local success, log = core.rollback_revert_actions_by(
749 target_name, seconds)
752 response = "(log is too long to show)\n"
754 for _, line in pairs(log) do
755 response = response .. line .. "\n"
758 response = response .. "Reverting actions "
759 .. (success and "succeeded." or "FAILED.")
760 return success, response
764 core.register_chatcommand("status", {
765 description = "Print server status",
766 func = function(name, param)
767 return true, core.get_server_status()
771 core.register_chatcommand("time", {
772 params = "<0..23>:<0..59> | <0..24000>",
773 description = "set time of day",
775 func = function(name, param)
777 local current_time = math.floor(core.get_timeofday() * 1440)
778 local minutes = current_time % 60
779 local hour = (current_time - minutes) / 60
780 return true, ("Current time is %d:%02d"):format(hour, minutes)
782 local player_privs = core.get_player_privs(name)
783 if not player_privs.settime then
784 return false, "You don't have permission to run this command " ..
785 "(missing privilege: settime)."
787 local hour, minute = param:match("^(%d+):(%d+)$")
789 local new_time = tonumber(param)
791 return false, "Invalid time."
793 -- Backward compatibility.
794 core.set_timeofday((new_time % 24000) / 24000)
795 core.log("action", name .. " sets time to " .. new_time)
796 return true, "Time of day changed."
798 hour = tonumber(hour)
799 minute = tonumber(minute)
800 if hour < 0 or hour > 23 then
801 return false, "Invalid hour (must be between 0 and 23 inclusive)."
802 elseif minute < 0 or minute > 59 then
803 return false, "Invalid minute (must be between 0 and 59 inclusive)."
805 core.set_timeofday((hour * 60 + minute) / 1440)
806 core.log("action", ("%s sets time to %d:%02d"):format(name, hour, minute))
807 return true, "Time of day changed."
811 core.register_chatcommand("days", {
812 description = "Display day count",
813 func = function(name, param)
814 return true, "Current day is " .. core.get_day_count()
818 core.register_chatcommand("shutdown", {
819 description = "shutdown server",
820 privs = {server=true},
821 func = function(name, param)
822 core.log("action", name .. " shuts down server")
823 core.request_shutdown()
824 core.chat_send_all("*** Server shutting down (operator request).")
828 core.register_chatcommand("ban", {
830 description = "Ban IP of player",
832 func = function(name, param)
834 return true, "Ban list: " .. core.get_ban_list()
836 if not core.get_player_by_name(param) then
837 return false, "No such player."
839 if not core.ban_player(param) then
840 return false, "Failed to ban player."
842 local desc = core.get_ban_description(param)
843 core.log("action", name .. " bans " .. desc .. ".")
844 return true, "Banned " .. desc .. "."
848 core.register_chatcommand("unban", {
849 params = "<name/ip>",
850 description = "remove IP ban",
852 func = function(name, param)
853 if not core.unban_player_or_ip(param) then
854 return false, "Failed to unban player/IP."
856 core.log("action", name .. " unbans " .. param)
857 return true, "Unbanned " .. param
861 core.register_chatcommand("kick", {
862 params = "<name> [reason]",
863 description = "kick a player",
865 func = function(name, param)
866 local tokick, reason = param:match("([^ ]+) (.+)")
867 tokick = tokick or param
868 if not core.kick_player(tokick, reason) then
869 return false, "Failed to kick player " .. tokick
871 local log_reason = ""
873 log_reason = " with reason \"" .. reason .. "\""
875 core.log("action", name .. " kicks " .. tokick .. log_reason)
876 return true, "Kicked " .. tokick
880 core.register_chatcommand("clearobjects", {
881 params = "[full|quick]",
882 description = "clear all objects in world",
883 privs = {server=true},
884 func = function(name, param)
886 if param == "" or param == "full" then
887 options.mode = "full"
888 elseif param == "quick" then
889 options.mode = "quick"
891 return false, "Invalid usage, see /help clearobjects."
894 core.log("action", name .. " clears all objects ("
895 .. options.mode .. " mode).")
896 core.chat_send_all("Clearing all objects. This may take long."
897 .. " You may experience a timeout. (by "
899 core.clear_objects(options)
900 core.log("action", "Object clearing done.")
901 core.chat_send_all("*** Cleared all objects.")
905 core.register_chatcommand("msg", {
906 params = "<name> <message>",
907 description = "Send a private message",
908 privs = {shout=true},
909 func = function(name, param)
910 local sendto, message = param:match("^(%S+)%s(.+)$")
912 return false, "Invalid usage, see /help msg."
914 if not core.get_player_by_name(sendto) then
915 return false, "The player " .. sendto
918 core.log("action", "PM from " .. name .. " to " .. sendto
920 core.chat_send_player(sendto, "PM from " .. name .. ": "
922 return true, "Message sent."
926 core.register_chatcommand("last-login", {
928 description = "Get the last login time of a player",
929 func = function(name, param)
933 local pauth = core.get_auth_handler().get_auth(param)
934 if pauth and pauth.last_login then
935 -- Time in UTC, ISO 8601 format
936 return true, "Last login time was " ..
937 os.date("!%Y-%m-%dT%H:%M:%SZ", pauth.last_login)
939 return false, "Last login time is unknown"