1 -- Minetest: builtin/chatcommands.lua
4 -- Chat command handler
8 function core.register_chatcommand(cmd, def)
10 def.params = def.params or ""
11 def.description = def.description or ""
12 def.privs = def.privs or {}
13 def.mod_origin = core.get_current_modname() or "??"
14 core.chatcommands[cmd] = def
17 core.register_on_chat_message(function(name, message)
18 local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
22 local cmd_def = core.chatcommands[cmd]
26 local has_privs, missing_privs = core.check_player_privs(name, cmd_def.privs)
28 core.set_last_run_mod(cmd_def.mod_origin)
29 local success, message = cmd_def.func(name, param)
31 core.chat_send_player(name, message)
34 core.chat_send_player(name, "You don't have permission"
35 .. " to run this command (missing privileges: "
36 .. table.concat(missing_privs, ", ") .. ")")
38 return true -- Handled chat message
41 if core.setting_getbool("profiler.load") then
42 -- Run after register_chatcommand and its register_on_chat_message
43 -- Before any chattcommands that should be profiled
44 profiler.init_chatcommand()
47 -- Parses a "range" string in the format of "here (number)" or
48 -- "(x1, y1, z1) (x2, y2, z2)", returning two position vectors
49 local function parse_range_str(player_name, str)
51 local args = str:split(" ")
53 if args[1] == "here" then
54 p1, p2 = core.get_player_radius_area(player_name, tonumber(args[2]))
56 return false, "Unable to get player " .. player_name .. " position"
59 p1, p2 = core.string_to_area(str)
61 return false, "Incorrect area format. Expected: (x1,y1,z1) (x2,y2,z2)"
71 core.register_chatcommand("me", {
73 description = "chat action (eg. /me orders a pizza)",
75 func = function(name, param)
76 core.chat_send_all("* " .. name .. " " .. param)
80 core.register_chatcommand("admin", {
81 description = "Show the name of the server owner",
83 local admin = minetest.setting_get("name")
85 return true, "The administrator of this server is "..admin.."."
87 return false, "There's no administrator named in the config file."
92 core.register_chatcommand("help", {
94 params = "[all/privs/<cmd>]",
95 description = "Get help for commands or list privileges",
96 func = function(name, param)
97 local function format_help_line(cmd, def)
98 local msg = core.colorize("#00ffff", "/"..cmd)
99 if def.params and def.params ~= "" then
100 msg = msg .. " " .. def.params
102 if def.description and def.description ~= "" then
103 msg = msg .. ": " .. def.description
110 for cmd, def in pairs(core.chatcommands) do
111 if core.check_player_privs(name, def.privs) then
112 cmds[#cmds + 1] = cmd
116 return true, "Available commands: " .. table.concat(cmds, " ") .. "\n"
117 .. "Use '/help <cmd>' to get more information,"
118 .. " or '/help all' to list everything."
119 elseif param == "all" then
121 for cmd, def in pairs(core.chatcommands) do
122 if core.check_player_privs(name, def.privs) then
123 cmds[#cmds + 1] = format_help_line(cmd, def)
127 return true, "Available commands:\n"..table.concat(cmds, "\n")
128 elseif param == "privs" then
130 for priv, def in pairs(core.registered_privileges) do
131 privs[#privs + 1] = priv .. ": " .. def.description
134 return true, "Available privileges:\n"..table.concat(privs, "\n")
137 local def = core.chatcommands[cmd]
139 return false, "Command not available: "..cmd
141 return true, format_help_line(cmd, def)
147 core.register_chatcommand("privs", {
149 description = "print out privileges of player",
150 func = function(caller, param)
152 local name = (param ~= "" and param or caller)
153 return true, "Privileges of " .. name .. ": "
154 .. core.privs_to_string(
155 core.get_player_privs(name), ' ')
159 local function handle_grant_command(caller, grantname, grantprivstr)
160 local caller_privs = minetest.get_player_privs(caller)
161 if not (caller_privs.privs or caller_privs.basic_privs) then
162 return false, "Your privileges are insufficient."
165 if not core.auth_table[grantname] then
166 return false, "Player " .. grantname .. " does not exist."
168 local grantprivs = core.string_to_privs(grantprivstr)
169 if grantprivstr == "all" then
170 grantprivs = core.registered_privileges
172 local privs = core.get_player_privs(grantname)
173 local privs_unknown = ""
175 core.string_to_privs(core.setting_get("basic_privs") or "interact,shout")
176 for priv, _ in pairs(grantprivs) do
177 if not basic_privs[priv] and not caller_privs.privs then
178 return false, "Your privileges are insufficient."
180 if not core.registered_privileges[priv] then
181 privs_unknown = privs_unknown .. "Unknown privilege: " .. priv .. "\n"
185 if privs_unknown ~= "" then
186 return false, privs_unknown
188 core.set_player_privs(grantname, privs)
189 core.log("action", caller..' granted ('..core.privs_to_string(grantprivs, ', ')..') privileges to '..grantname)
190 if grantname ~= caller then
191 core.chat_send_player(grantname, caller
192 .. " granted you privileges: "
193 .. core.privs_to_string(grantprivs, ' '))
195 return true, "Privileges of " .. grantname .. ": "
196 .. core.privs_to_string(
197 core.get_player_privs(grantname), ' ')
200 core.register_chatcommand("grant", {
201 params = "<name> <privilege>|all",
202 description = "Give privilege to player",
203 func = function(name, param)
204 local grantname, grantprivstr = string.match(param, "([^ ]+) (.+)")
205 if not grantname or not grantprivstr then
206 return false, "Invalid parameters (see /help grant)"
208 return handle_grant_command(name, grantname, grantprivstr)
212 core.register_chatcommand("grantme", {
213 params = "<privilege>|all",
214 description = "Grant privileges to yourself",
215 func = function(name, param)
217 return false, "Invalid parameters (see /help grantme)"
219 return handle_grant_command(name, name, param)
223 core.register_chatcommand("revoke", {
224 params = "<name> <privilege>|all",
225 description = "Remove privilege from player",
227 func = function(name, param)
228 if not core.check_player_privs(name, {privs=true}) and
229 not core.check_player_privs(name, {basic_privs=true}) then
230 return false, "Your privileges are insufficient."
232 local revoke_name, revoke_priv_str = string.match(param, "([^ ]+) (.+)")
233 if not revoke_name or not revoke_priv_str then
234 return false, "Invalid parameters (see /help revoke)"
235 elseif not core.auth_table[revoke_name] then
236 return false, "Player " .. revoke_name .. " does not exist."
238 local revoke_privs = core.string_to_privs(revoke_priv_str)
239 local privs = core.get_player_privs(revoke_name)
241 core.string_to_privs(core.setting_get("basic_privs") or "interact,shout")
242 for priv, _ in pairs(revoke_privs) do
243 if not basic_privs[priv] and
244 not core.check_player_privs(name, {privs=true}) then
245 return false, "Your privileges are insufficient."
248 if revoke_priv_str == "all" then
251 for priv, _ in pairs(revoke_privs) do
255 core.set_player_privs(revoke_name, privs)
256 core.log("action", name..' revoked ('
257 ..core.privs_to_string(revoke_privs, ', ')
258 ..') privileges from '..revoke_name)
259 if revoke_name ~= name then
260 core.chat_send_player(revoke_name, name
261 .. " revoked privileges from you: "
262 .. core.privs_to_string(revoke_privs, ' '))
264 return true, "Privileges of " .. revoke_name .. ": "
265 .. core.privs_to_string(
266 core.get_player_privs(revoke_name), ' ')
270 core.register_chatcommand("setpassword", {
271 params = "<name> <password>",
272 description = "set given password",
273 privs = {password=true},
274 func = function(name, param)
275 local toname, raw_password = string.match(param, "^([^ ]+) +(.+)$")
277 toname = param:match("^([^ ]+) *$")
281 return false, "Name field required"
283 local act_str_past = "?"
284 local act_str_pres = "?"
285 if not raw_password then
286 core.set_player_password(toname, "")
287 act_str_past = "cleared"
288 act_str_pres = "clears"
290 core.set_player_password(toname,
291 core.get_password_hash(toname,
294 act_str_pres = "sets"
296 if toname ~= name then
297 core.chat_send_player(toname, "Your password was "
298 .. act_str_past .. " by " .. name)
301 core.log("action", name .. " " .. act_str_pres
302 .. " password of " .. toname .. ".")
304 return true, "Password of player \"" .. toname .. "\" " .. act_str_past
308 core.register_chatcommand("clearpassword", {
310 description = "set empty password",
311 privs = {password=true},
312 func = function(name, param)
315 return false, "Name field required"
317 core.set_player_password(toname, '')
319 core.log("action", name .. " clears password of " .. toname .. ".")
321 return true, "Password of player \"" .. toname .. "\" cleared"
325 core.register_chatcommand("auth_reload", {
327 description = "reload authentication data",
328 privs = {server=true},
329 func = function(name, param)
330 local done = core.auth_reload()
331 return done, (done and "Done." or "Failed.")
335 core.register_chatcommand("teleport", {
336 params = "<X>,<Y>,<Z> | <to_name> | <name> <X>,<Y>,<Z> | <name> <to_name>",
337 description = "teleport to given position",
338 privs = {teleport=true},
339 func = function(name, param)
340 -- Returns (pos, true) if found, otherwise (pos, false)
341 local function find_free_position_near(pos)
348 for _, d in ipairs(tries) do
349 local p = {x = pos.x+d.x, y = pos.y+d.y, z = pos.z+d.z}
350 local n = core.get_node_or_nil(p)
352 local def = core.registered_nodes[n.name]
353 if def and not def.walkable then
361 local teleportee = nil
363 p.x, p.y, p.z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
367 if p.x and p.y and p.z then
368 local lm = tonumber(minetest.setting_get("map_generation_limit") or 31000)
369 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
370 return false, "Cannot teleport out of map bounds!"
372 teleportee = core.get_player_by_name(name)
375 return true, "Teleporting to "..core.pos_to_string(p)
379 local teleportee = nil
381 local target_name = nil
382 target_name = param:match("^([^ ]+)$")
383 teleportee = core.get_player_by_name(name)
385 local target = core.get_player_by_name(target_name)
390 if teleportee and p then
391 p = find_free_position_near(p)
393 return true, "Teleporting to " .. target_name
394 .. " at "..core.pos_to_string(p)
397 if not core.check_player_privs(name, {bring=true}) then
398 return false, "You don't have permission to teleport other players (missing bring privilege)"
401 local teleportee = nil
403 local teleportee_name = nil
404 teleportee_name, p.x, p.y, p.z = param:match(
405 "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
406 p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
407 if teleportee_name then
408 teleportee = core.get_player_by_name(teleportee_name)
410 if teleportee and p.x and p.y and p.z then
412 return true, "Teleporting " .. teleportee_name
413 .. " to " .. core.pos_to_string(p)
416 local teleportee = nil
418 local teleportee_name = nil
419 local target_name = nil
420 teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
421 if teleportee_name then
422 teleportee = core.get_player_by_name(teleportee_name)
425 local target = core.get_player_by_name(target_name)
430 if teleportee and p then
431 p = find_free_position_near(p)
433 return true, "Teleporting " .. teleportee_name
434 .. " to " .. target_name
435 .. " at " .. core.pos_to_string(p)
438 return false, 'Invalid parameters ("' .. param
439 .. '") or player not found (see /help teleport)'
443 core.register_chatcommand("set", {
444 params = "[-n] <name> <value> | <name>",
445 description = "set or read server configuration setting",
446 privs = {server=true},
447 func = function(name, param)
448 local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)")
449 if arg and arg == "-n" and setname and setvalue then
450 core.setting_set(setname, setvalue)
451 return true, setname .. " = " .. setvalue
453 local setname, setvalue = string.match(param, "([^ ]+) (.+)")
454 if setname and setvalue then
455 if not core.setting_get(setname) then
456 return false, "Failed. Use '/set -n <name> <value>' to create a new setting."
458 core.setting_set(setname, setvalue)
459 return true, setname .. " = " .. setvalue
461 local setname = string.match(param, "([^ ]+)")
463 local setvalue = core.setting_get(setname)
465 setvalue = "<not set>"
467 return true, setname .. " = " .. setvalue
469 return false, "Invalid parameters (see /help set)."
473 local function emergeblocks_callback(pos, action, num_calls_remaining, ctx)
474 if ctx.total_blocks == 0 then
475 ctx.total_blocks = num_calls_remaining + 1
476 ctx.current_blocks = 0
478 ctx.current_blocks = ctx.current_blocks + 1
480 if ctx.current_blocks == ctx.total_blocks then
481 core.chat_send_player(ctx.requestor_name,
482 string.format("Finished emerging %d blocks in %.2fms.",
483 ctx.total_blocks, (os.clock() - ctx.start_time) * 1000))
487 local function emergeblocks_progress_update(ctx)
488 if ctx.current_blocks ~= ctx.total_blocks then
489 core.chat_send_player(ctx.requestor_name,
490 string.format("emergeblocks update: %d/%d blocks emerged (%.1f%%)",
491 ctx.current_blocks, ctx.total_blocks,
492 (ctx.current_blocks / ctx.total_blocks) * 100))
494 core.after(2, emergeblocks_progress_update, ctx)
498 core.register_chatcommand("emergeblocks", {
499 params = "(here [radius]) | (<pos1> <pos2>)",
500 description = "starts loading (or generating, if inexistent) map blocks "
501 .. "contained in area pos1 to pos2",
502 privs = {server=true},
503 func = function(name, param)
504 local p1, p2 = parse_range_str(name, param)
512 start_time = os.clock(),
513 requestor_name = name
516 core.emerge_area(p1, p2, emergeblocks_callback, context)
517 core.after(2, emergeblocks_progress_update, context)
519 return true, "Started emerge of area ranging from " ..
520 core.pos_to_string(p1, 1) .. " to " .. core.pos_to_string(p2, 1)
524 core.register_chatcommand("deleteblocks", {
525 params = "(here [radius]) | (<pos1> <pos2>)",
526 description = "delete map blocks contained in area pos1 to pos2",
527 privs = {server=true},
528 func = function(name, param)
529 local p1, p2 = parse_range_str(name, param)
534 if core.delete_area(p1, p2) then
535 return true, "Successfully cleared area ranging from " ..
536 core.pos_to_string(p1, 1) .. " to " .. core.pos_to_string(p2, 1)
538 return false, "Failed to clear one or more blocks in area"
543 core.register_chatcommand("mods", {
545 description = "List mods installed on the server",
547 func = function(name, param)
548 return true, table.concat(core.get_modnames(), ", ")
552 local function handle_give_command(cmd, giver, receiver, stackstring)
553 core.log("action", giver .. " invoked " .. cmd
554 .. ', stackstring="' .. stackstring .. '"')
555 local itemstack = ItemStack(stackstring)
556 if itemstack:is_empty() then
557 return false, "Cannot give an empty item"
558 elseif not itemstack:is_known() then
559 return false, "Cannot give an unknown item"
561 local receiverref = core.get_player_by_name(receiver)
562 if receiverref == nil then
563 return false, receiver .. " is not a known player"
565 local leftover = receiverref:get_inventory():add_item("main", itemstack)
567 if leftover:is_empty() then
569 elseif leftover:get_count() == itemstack:get_count() then
570 partiality = "could not be "
572 partiality = "partially "
574 -- The actual item stack string may be different from what the "giver"
575 -- entered (e.g. big numbers are always interpreted as 2^16-1).
576 stackstring = itemstack:to_string()
577 if giver == receiver then
578 return true, ("%q %sadded to inventory.")
579 :format(stackstring, partiality)
581 core.chat_send_player(receiver, ("%q %sadded to inventory.")
582 :format(stackstring, partiality))
583 return true, ("%q %sadded to %s's inventory.")
584 :format(stackstring, partiality, receiver)
588 core.register_chatcommand("give", {
589 params = "<name> <ItemString>",
590 description = "give item to player",
592 func = function(name, param)
593 local toname, itemstring = string.match(param, "^([^ ]+) +(.+)$")
594 if not toname or not itemstring then
595 return false, "Name and ItemString required"
597 return handle_give_command("/give", name, toname, itemstring)
601 core.register_chatcommand("giveme", {
602 params = "<ItemString>",
603 description = "give item to yourself",
605 func = function(name, param)
606 local itemstring = string.match(param, "(.+)$")
607 if not itemstring then
608 return false, "ItemString required"
610 return handle_give_command("/giveme", name, name, itemstring)
614 core.register_chatcommand("spawnentity", {
615 params = "<EntityName> [<X>,<Y>,<Z>]",
616 description = "Spawn entity at given (or your) position",
617 privs = {give=true, interact=true},
618 func = function(name, param)
619 local entityname, p = string.match(param, "^([^ ]+) *(.*)$")
620 if not entityname then
621 return false, "EntityName required"
623 core.log("action", ("%s invokes /spawnentity, entityname=%q")
624 :format(name, entityname))
625 local player = core.get_player_by_name(name)
626 if player == nil then
627 core.log("error", "Unable to spawn entity, player is nil")
628 return false, "Unable to spawn entity, player is nil"
633 p = core.string_to_pos(p)
635 return false, "Invalid parameters ('" .. param .. "')"
639 core.add_entity(p, entityname)
640 return true, ("%q spawned."):format(entityname)
644 core.register_chatcommand("pulverize", {
646 description = "Destroy item in hand",
647 func = function(name, param)
648 local player = core.get_player_by_name(name)
650 core.log("error", "Unable to pulverize, no player.")
651 return false, "Unable to pulverize, no player."
653 if player:get_wielded_item():is_empty() then
654 return false, "Unable to pulverize, no item in hand."
656 player:set_wielded_item(nil)
657 return true, "An item was pulverized."
662 core.rollback_punch_callbacks = {}
664 core.register_on_punchnode(function(pos, node, puncher)
665 local name = puncher:get_player_name()
666 if core.rollback_punch_callbacks[name] then
667 core.rollback_punch_callbacks[name](pos, node, puncher)
668 core.rollback_punch_callbacks[name] = nil
672 core.register_chatcommand("rollback_check", {
673 params = "[<range>] [<seconds>] [limit]",
674 description = "Check who has last touched a node or near it,"
675 .. " max. <seconds> ago (default range=0,"
676 .. " seconds=86400=24h, limit=5)",
677 privs = {rollback=true},
678 func = function(name, param)
679 if not core.setting_getbool("enable_rollback_recording") then
680 return false, "Rollback functions are disabled."
682 local range, seconds, limit =
683 param:match("(%d+) *(%d*) *(%d*)")
684 range = tonumber(range) or 0
685 seconds = tonumber(seconds) or 86400
686 limit = tonumber(limit) or 5
688 return false, "That limit is too high!"
691 core.rollback_punch_callbacks[name] = function(pos, node, puncher)
692 local name = puncher:get_player_name()
693 core.chat_send_player(name, "Checking " .. core.pos_to_string(pos) .. "...")
694 local actions = core.rollback_get_node_actions(pos, range, seconds, limit)
696 core.chat_send_player(name, "Rollback functions are disabled")
699 local num_actions = #actions
700 if num_actions == 0 then
701 core.chat_send_player(name, "Nobody has touched"
702 .. " the specified location in "
703 .. seconds .. " seconds")
706 local time = os.time()
707 for i = num_actions, 1, -1 do
708 local action = actions[i]
709 core.chat_send_player(name,
710 ("%s %s %s -> %s %d seconds ago.")
712 core.pos_to_string(action.pos),
720 return true, "Punch a node (range=" .. range .. ", seconds="
721 .. seconds .. "s, limit=" .. limit .. ")"
725 core.register_chatcommand("rollback", {
726 params = "<player name> [<seconds>] | :<actor> [<seconds>]",
727 description = "revert actions of a player; default for <seconds> is 60",
728 privs = {rollback=true},
729 func = function(name, param)
730 if not core.setting_getbool("enable_rollback_recording") then
731 return false, "Rollback functions are disabled."
733 local target_name, seconds = string.match(param, ":([^ ]+) *(%d*)")
734 if not target_name then
735 local player_name = nil
736 player_name, seconds = string.match(param, "([^ ]+) *(%d*)")
737 if not player_name then
738 return false, "Invalid parameters. See /help rollback"
739 .. " and /help rollback_check."
741 target_name = "player:"..player_name
743 seconds = tonumber(seconds) or 60
744 core.chat_send_player(name, "Reverting actions of "
745 .. target_name .. " since "
746 .. seconds .. " seconds.")
747 local success, log = core.rollback_revert_actions_by(
748 target_name, seconds)
751 response = "(log is too long to show)\n"
753 for _, line in pairs(log) do
754 response = response .. line .. "\n"
757 response = response .. "Reverting actions "
758 .. (success and "succeeded." or "FAILED.")
759 return success, response
763 core.register_chatcommand("status", {
764 description = "Print server status",
765 func = function(name, param)
766 return true, core.get_server_status()
770 core.register_chatcommand("time", {
771 params = "<0..23>:<0..59> | <0..24000>",
772 description = "set time of day",
774 func = function(name, param)
776 local current_time = math.floor(core.get_timeofday() * 1440)
777 local minutes = current_time % 60
778 local hour = (current_time - minutes) / 60
779 return true, ("Current time is %d:%02d"):format(hour, minutes)
781 local player_privs = core.get_player_privs(name)
782 if not player_privs.settime then
783 return false, "You don't have permission to run this command " ..
784 "(missing privilege: settime)."
786 local hour, minute = param:match("^(%d+):(%d+)$")
788 local new_time = tonumber(param)
790 return false, "Invalid time."
792 -- Backward compatibility.
793 core.set_timeofday((new_time % 24000) / 24000)
794 core.log("action", name .. " sets time to " .. new_time)
795 return true, "Time of day changed."
797 hour = tonumber(hour)
798 minute = tonumber(minute)
799 if hour < 0 or hour > 23 then
800 return false, "Invalid hour (must be between 0 and 23 inclusive)."
801 elseif minute < 0 or minute > 59 then
802 return false, "Invalid minute (must be between 0 and 59 inclusive)."
804 core.set_timeofday((hour * 60 + minute) / 1440)
805 core.log("action", ("%s sets time to %d:%02d"):format(name, hour, minute))
806 return true, "Time of day changed."
810 core.register_chatcommand("days", {
811 description = "Display day count",
812 func = function(name, param)
813 return true, "Current day is " .. core.get_day_count()
817 core.register_chatcommand("shutdown", {
818 description = "shutdown server",
819 privs = {server=true},
820 func = function(name, param)
821 core.log("action", name .. " shuts down server")
822 core.request_shutdown()
823 core.chat_send_all("*** Server shutting down (operator request).")
827 core.register_chatcommand("ban", {
829 description = "Ban IP of player",
831 func = function(name, param)
833 return true, "Ban list: " .. core.get_ban_list()
835 if not core.get_player_by_name(param) then
836 return false, "No such player."
838 if not core.ban_player(param) then
839 return false, "Failed to ban player."
841 local desc = core.get_ban_description(param)
842 core.log("action", name .. " bans " .. desc .. ".")
843 return true, "Banned " .. desc .. "."
847 core.register_chatcommand("unban", {
848 params = "<name/ip>",
849 description = "remove IP ban",
851 func = function(name, param)
852 if not core.unban_player_or_ip(param) then
853 return false, "Failed to unban player/IP."
855 core.log("action", name .. " unbans " .. param)
856 return true, "Unbanned " .. param
860 core.register_chatcommand("kick", {
861 params = "<name> [reason]",
862 description = "kick a player",
864 func = function(name, param)
865 local tokick, reason = param:match("([^ ]+) (.+)")
866 tokick = tokick or param
867 if not core.kick_player(tokick, reason) then
868 return false, "Failed to kick player " .. tokick
870 local log_reason = ""
872 log_reason = " with reason \"" .. reason .. "\""
874 core.log("action", name .. " kicks " .. tokick .. log_reason)
875 return true, "Kicked " .. tokick
879 core.register_chatcommand("clearobjects", {
880 params = "[full|quick]",
881 description = "clear all objects in world",
882 privs = {server=true},
883 func = function(name, param)
885 if param == "" or param == "full" then
886 options.mode = "full"
887 elseif param == "quick" then
888 options.mode = "quick"
890 return false, "Invalid usage, see /help clearobjects."
893 core.log("action", name .. " clears all objects ("
894 .. options.mode .. " mode).")
895 core.chat_send_all("Clearing all objects. This may take long."
896 .. " You may experience a timeout. (by "
898 core.clear_objects(options)
899 core.log("action", "Object clearing done.")
900 core.chat_send_all("*** Cleared all objects.")
904 core.register_chatcommand("msg", {
905 params = "<name> <message>",
906 description = "Send a private message",
907 privs = {shout=true},
908 func = function(name, param)
909 local sendto, message = param:match("^(%S+)%s(.+)$")
911 return false, "Invalid usage, see /help msg."
913 if not core.get_player_by_name(sendto) then
914 return false, "The player " .. sendto
917 core.log("action", "PM from " .. name .. " to " .. sendto
919 core.chat_send_player(sendto, "PM from " .. name .. ": "
921 return true, "Message sent."
925 core.register_chatcommand("last-login", {
927 description = "Get the last login time of a player",
928 func = function(name, param)
932 local pauth = core.get_auth_handler().get_auth(param)
933 if pauth and pauth.last_login then
934 -- Time in UTC, ISO 8601 format
935 return true, "Last login time was " ..
936 os.date("!%Y-%m-%dT%H:%M:%SZ", pauth.last_login)
938 return false, "Last login time is unknown"