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 if core.setting_getbool("mod_profiling") then
18 local tracefct = profiling_print_log
19 profiling_print_log = nil
20 core.register_chatcommand("save_mod_profile",
23 description = "save mod profiling data to logfile " ..
24 "(depends on default loglevel)",
26 privs = { server=true }
30 core.register_on_chat_message(function(name, message)
31 local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
35 local cmd_def = core.chatcommands[cmd]
39 local has_privs, missing_privs = core.check_player_privs(name, cmd_def.privs)
41 core.set_last_run_mod(cmd_def.mod_origin)
42 local success, message = cmd_def.func(name, param)
44 core.chat_send_player(name, message)
47 core.chat_send_player(name, "You don't have permission"
48 .. " to run this command (missing privileges: "
49 .. table.concat(missing_privs, ", ") .. ")")
51 return true -- Handled chat message
54 -- Parses a "range" string in the format of "here (number)" or
55 -- "(x1, y1, z1) (x2, y2, z2)", returning two position vectors
56 local function parse_range_str(player_name, str)
58 local args = str:split(" ")
60 if args[1] == "here" then
61 p1, p2 = core.get_player_radius_area(player_name, tonumber(args[2]))
63 return false, "Unable to get player " .. player_name .. " position"
66 p1, p2 = core.string_to_area(str)
68 return false, "Incorrect area format. Expected: (x1,y1,z1) (x2,y2,z2)"
78 core.register_chatcommand("me", {
80 description = "chat action (eg. /me orders a pizza)",
82 func = function(name, param)
83 core.chat_send_all("* " .. name .. " " .. param)
87 core.register_chatcommand("admin", {
88 description = "Show the name of the server owner",
90 local admin = minetest.setting_get("name")
92 return true, "The administrator of this server is "..admin.."."
94 return false, "There's no administrator named in the config file."
99 core.register_chatcommand("help", {
101 params = "[all/privs/<cmd>]",
102 description = "Get help for commands or list privileges",
103 func = function(name, param)
104 local function format_help_line(cmd, def)
106 if def.params and def.params ~= "" then
107 msg = msg .. " " .. def.params
109 if def.description and def.description ~= "" then
110 msg = msg .. ": " .. def.description
117 for cmd, def in pairs(core.chatcommands) do
118 if core.check_player_privs(name, def.privs) then
119 cmds[#cmds + 1] = cmd
123 return true, "Available commands: " .. table.concat(cmds, " ") .. "\n"
124 .. "Use '/help <cmd>' to get more information,"
125 .. " or '/help all' to list everything."
126 elseif param == "all" then
128 for cmd, def in pairs(core.chatcommands) do
129 if core.check_player_privs(name, def.privs) then
130 cmds[#cmds + 1] = format_help_line(cmd, def)
134 return true, "Available commands:\n"..table.concat(cmds, "\n")
135 elseif param == "privs" then
137 for priv, def in pairs(core.registered_privileges) do
138 privs[#privs + 1] = priv .. ": " .. def.description
141 return true, "Available privileges:\n"..table.concat(privs, "\n")
144 local def = core.chatcommands[cmd]
146 return false, "Command not available: "..cmd
148 return true, format_help_line(cmd, def)
154 core.register_chatcommand("privs", {
156 description = "print out privileges of player",
157 func = function(name, param)
158 param = (param ~= "" and param or name)
159 return true, "Privileges of " .. param .. ": "
160 .. core.privs_to_string(
161 core.get_player_privs(param), ' ')
164 core.register_chatcommand("grant", {
165 params = "<name> <privilege>|all",
166 description = "Give privilege to player",
167 func = function(name, param)
168 if not core.check_player_privs(name, {privs=true}) and
169 not core.check_player_privs(name, {basic_privs=true}) then
170 return false, "Your privileges are insufficient."
172 local grantname, grantprivstr = string.match(param, "([^ ]+) (.+)")
173 if not grantname or not grantprivstr then
174 return false, "Invalid parameters (see /help grant)"
175 elseif not core.auth_table[grantname] then
176 return false, "Player " .. grantname .. " does not exist."
178 local grantprivs = core.string_to_privs(grantprivstr)
179 if grantprivstr == "all" then
180 grantprivs = core.registered_privileges
182 local privs = core.get_player_privs(grantname)
183 local privs_unknown = ""
184 for priv, _ in pairs(grantprivs) do
185 if priv ~= "interact" and priv ~= "shout" and
186 not core.check_player_privs(name, {privs=true}) then
187 return false, "Your privileges are insufficient."
189 if not core.registered_privileges[priv] then
190 privs_unknown = privs_unknown .. "Unknown privilege: " .. priv .. "\n"
194 if privs_unknown ~= "" then
195 return false, privs_unknown
197 core.set_player_privs(grantname, privs)
198 core.log("action", name..' granted ('..core.privs_to_string(grantprivs, ', ')..') privileges to '..grantname)
199 if grantname ~= name then
200 core.chat_send_player(grantname, name
201 .. " granted you privileges: "
202 .. core.privs_to_string(grantprivs, ' '))
204 return true, "Privileges of " .. grantname .. ": "
205 .. core.privs_to_string(
206 core.get_player_privs(grantname), ' ')
209 core.register_chatcommand("revoke", {
210 params = "<name> <privilege>|all",
211 description = "Remove privilege from player",
213 func = function(name, param)
214 if not core.check_player_privs(name, {privs=true}) and
215 not core.check_player_privs(name, {basic_privs=true}) then
216 return false, "Your privileges are insufficient."
218 local revoke_name, revoke_priv_str = string.match(param, "([^ ]+) (.+)")
219 if not revoke_name or not revoke_priv_str then
220 return false, "Invalid parameters (see /help revoke)"
221 elseif not core.auth_table[revoke_name] then
222 return false, "Player " .. revoke_name .. " does not exist."
224 local revoke_privs = core.string_to_privs(revoke_priv_str)
225 local privs = core.get_player_privs(revoke_name)
226 for priv, _ in pairs(revoke_privs) do
227 if priv ~= "interact" and priv ~= "shout" and
228 not core.check_player_privs(name, {privs=true}) then
229 return false, "Your privileges are insufficient."
232 if revoke_priv_str == "all" then
235 for priv, _ in pairs(revoke_privs) do
239 core.set_player_privs(revoke_name, privs)
240 core.log("action", name..' revoked ('
241 ..core.privs_to_string(revoke_privs, ', ')
242 ..') privileges from '..revoke_name)
243 if revoke_name ~= name then
244 core.chat_send_player(revoke_name, name
245 .. " revoked privileges from you: "
246 .. core.privs_to_string(revoke_privs, ' '))
248 return true, "Privileges of " .. revoke_name .. ": "
249 .. core.privs_to_string(
250 core.get_player_privs(revoke_name), ' ')
254 core.register_chatcommand("setpassword", {
255 params = "<name> <password>",
256 description = "set given password",
257 privs = {password=true},
258 func = function(name, param)
259 local toname, raw_password = string.match(param, "^([^ ]+) +(.+)$")
261 toname = param:match("^([^ ]+) *$")
265 return false, "Name field required"
267 local act_str_past = "?"
268 local act_str_pres = "?"
269 if not raw_password then
270 core.set_player_password(toname, "")
271 act_str_past = "cleared"
272 act_str_pres = "clears"
274 core.set_player_password(toname,
275 core.get_password_hash(toname,
278 act_str_pres = "sets"
280 if toname ~= name then
281 core.chat_send_player(toname, "Your password was "
282 .. act_str_past .. " by " .. name)
285 core.log("action", name .. " " .. act_str_pres
286 .. " password of " .. toname .. ".")
288 return true, "Password of player \"" .. toname .. "\" " .. act_str_past
292 core.register_chatcommand("clearpassword", {
294 description = "set empty password",
295 privs = {password=true},
296 func = function(name, param)
299 return false, "Name field required"
301 core.set_player_password(toname, '')
303 core.log("action", name .. " clears password of " .. toname .. ".")
305 return true, "Password of player \"" .. toname .. "\" cleared"
309 core.register_chatcommand("auth_reload", {
311 description = "reload authentication data",
312 privs = {server=true},
313 func = function(name, param)
314 local done = core.auth_reload()
315 return done, (done and "Done." or "Failed.")
319 core.register_chatcommand("teleport", {
320 params = "<X>,<Y>,<Z> | <to_name> | <name> <X>,<Y>,<Z> | <name> <to_name>",
321 description = "teleport to given position",
322 privs = {teleport=true},
323 func = function(name, param)
324 -- Returns (pos, true) if found, otherwise (pos, false)
325 local function find_free_position_near(pos)
332 for _, d in ipairs(tries) do
333 local p = {x = pos.x+d.x, y = pos.y+d.y, z = pos.z+d.z}
334 local n = core.get_node_or_nil(p)
336 local def = core.registered_nodes[n.name]
337 if def and not def.walkable then
345 local teleportee = nil
347 p.x, p.y, p.z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
351 teleportee = core.get_player_by_name(name)
352 if teleportee and p.x and p.y and p.z then
354 return true, "Teleporting to "..core.pos_to_string(p)
357 local teleportee = nil
359 local target_name = nil
360 target_name = param:match("^([^ ]+)$")
361 teleportee = core.get_player_by_name(name)
363 local target = core.get_player_by_name(target_name)
368 if teleportee and p then
369 p = find_free_position_near(p)
371 return true, "Teleporting to " .. target_name
372 .. " at "..core.pos_to_string(p)
375 if not core.check_player_privs(name, {bring=true}) then
376 return false, "You don't have permission to teleport other players (missing bring privilege)"
379 local teleportee = nil
381 local teleportee_name = nil
382 teleportee_name, p.x, p.y, p.z = param:match(
383 "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
384 p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
385 if teleportee_name then
386 teleportee = core.get_player_by_name(teleportee_name)
388 if teleportee and p.x and p.y and p.z then
390 return true, "Teleporting " .. teleportee_name
391 .. " to " .. core.pos_to_string(p)
394 local teleportee = nil
396 local teleportee_name = nil
397 local target_name = nil
398 teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
399 if teleportee_name then
400 teleportee = core.get_player_by_name(teleportee_name)
403 local target = core.get_player_by_name(target_name)
408 if teleportee and p then
409 p = find_free_position_near(p)
411 return true, "Teleporting " .. teleportee_name
412 .. " to " .. target_name
413 .. " at " .. core.pos_to_string(p)
416 return false, 'Invalid parameters ("' .. param
417 .. '") or player not found (see /help teleport)'
421 core.register_chatcommand("set", {
422 params = "[-n] <name> <value> | <name>",
423 description = "set or read server configuration setting",
424 privs = {server=true},
425 func = function(name, param)
426 local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)")
427 if arg and arg == "-n" and setname and setvalue then
428 core.setting_set(setname, setvalue)
429 return true, setname .. " = " .. setvalue
431 local setname, setvalue = string.match(param, "([^ ]+) (.+)")
432 if setname and setvalue then
433 if not core.setting_get(setname) then
434 return false, "Failed. Use '/set -n <name> <value>' to create a new setting."
436 core.setting_set(setname, setvalue)
437 return true, setname .. " = " .. setvalue
439 local setname = string.match(param, "([^ ]+)")
441 local setvalue = core.setting_get(setname)
443 setvalue = "<not set>"
445 return true, setname .. " = " .. setvalue
447 return false, "Invalid parameters (see /help set)."
451 local function emergeblocks_callback(pos, action, num_calls_remaining, ctx)
452 if ctx.total_blocks == 0 then
453 ctx.total_blocks = num_calls_remaining + 1
454 ctx.current_blocks = 0
456 ctx.current_blocks = ctx.current_blocks + 1
458 if ctx.current_blocks == ctx.total_blocks then
459 core.chat_send_player(ctx.requestor_name,
460 string.format("Finished emerging %d blocks in %.2fms.",
461 ctx.total_blocks, (os.clock() - ctx.start_time) * 1000))
465 local function emergeblocks_progress_update(ctx)
466 if ctx.current_blocks ~= ctx.total_blocks then
467 core.chat_send_player(ctx.requestor_name,
468 string.format("emergeblocks update: %d/%d blocks emerged (%.1f%%)",
469 ctx.current_blocks, ctx.total_blocks,
470 (ctx.current_blocks / ctx.total_blocks) * 100))
472 core.after(2, emergeblocks_progress_update, ctx)
476 core.register_chatcommand("emergeblocks", {
477 params = "(here [radius]) | (<pos1> <pos2>)",
478 description = "starts loading (or generating, if inexistent) map blocks "
479 .. "contained in area pos1 to pos2",
480 privs = {server=true},
481 func = function(name, param)
482 local p1, p2 = parse_range_str(name, param)
490 start_time = os.clock(),
491 requestor_name = name
494 core.emerge_area(p1, p2, emergeblocks_callback, context)
495 core.after(2, emergeblocks_progress_update, context)
497 return true, "Started emerge of area ranging from " ..
498 core.pos_to_string(p1, 1) .. " to " .. core.pos_to_string(p2, 1)
502 core.register_chatcommand("deleteblocks", {
503 params = "(here [radius]) | (<pos1> <pos2>)",
504 description = "delete map blocks contained in area pos1 to pos2",
505 privs = {server=true},
506 func = function(name, param)
507 local p1, p2 = parse_range_str(name, param)
512 if core.delete_area(p1, p2) then
513 return true, "Successfully cleared area ranging from " ..
514 core.pos_to_string(p1, 1) .. " to " .. core.pos_to_string(p2, 1)
516 return false, "Failed to clear one or more blocks in area"
521 core.register_chatcommand("mods", {
523 description = "List mods installed on the server",
525 func = function(name, param)
526 return true, table.concat(core.get_modnames(), ", ")
530 local function handle_give_command(cmd, giver, receiver, stackstring)
531 core.log("action", giver .. " invoked " .. cmd
532 .. ', stackstring="' .. stackstring .. '"')
533 local itemstack = ItemStack(stackstring)
534 if itemstack:is_empty() then
535 return false, "Cannot give an empty item"
536 elseif not itemstack:is_known() then
537 return false, "Cannot give an unknown item"
539 local receiverref = core.get_player_by_name(receiver)
540 if receiverref == nil then
541 return false, receiver .. " is not a known player"
543 local leftover = receiverref:get_inventory():add_item("main", itemstack)
545 if leftover:is_empty() then
547 elseif leftover:get_count() == itemstack:get_count() then
548 partiality = "could not be "
550 partiality = "partially "
552 -- The actual item stack string may be different from what the "giver"
553 -- entered (e.g. big numbers are always interpreted as 2^16-1).
554 stackstring = itemstack:to_string()
555 if giver == receiver then
556 return true, ("%q %sadded to inventory.")
557 :format(stackstring, partiality)
559 core.chat_send_player(receiver, ("%q %sadded to inventory.")
560 :format(stackstring, partiality))
561 return true, ("%q %sadded to %s's inventory.")
562 :format(stackstring, partiality, receiver)
566 core.register_chatcommand("give", {
567 params = "<name> <ItemString>",
568 description = "give item to player",
570 func = function(name, param)
571 local toname, itemstring = string.match(param, "^([^ ]+) +(.+)$")
572 if not toname or not itemstring then
573 return false, "Name and ItemString required"
575 return handle_give_command("/give", name, toname, itemstring)
579 core.register_chatcommand("giveme", {
580 params = "<ItemString>",
581 description = "give item to yourself",
583 func = function(name, param)
584 local itemstring = string.match(param, "(.+)$")
585 if not itemstring then
586 return false, "ItemString required"
588 return handle_give_command("/giveme", name, name, itemstring)
592 core.register_chatcommand("spawnentity", {
593 params = "<EntityName> [<X>,<Y>,<Z>]",
594 description = "Spawn entity at given (or your) position",
595 privs = {give=true, interact=true},
596 func = function(name, param)
597 local entityname, p = string.match(param, "^([^ ]+) *(.*)$")
598 if not entityname then
599 return false, "EntityName required"
601 core.log("action", ("%s invokes /spawnentity, entityname=%q")
602 :format(name, entityname))
603 local player = core.get_player_by_name(name)
604 if player == nil then
605 core.log("error", "Unable to spawn entity, player is nil")
606 return false, "Unable to spawn entity, player is nil"
611 p = core.string_to_pos(p)
613 return false, "Invalid parameters ('" .. param .. "')"
617 core.add_entity(p, entityname)
618 return true, ("%q spawned."):format(entityname)
622 core.register_chatcommand("pulverize", {
624 description = "Destroy item in hand",
625 func = function(name, param)
626 local player = core.get_player_by_name(name)
628 core.log("error", "Unable to pulverize, no player.")
629 return false, "Unable to pulverize, no player."
631 if player:get_wielded_item():is_empty() then
632 return false, "Unable to pulverize, no item in hand."
634 player:set_wielded_item(nil)
635 return true, "An item was pulverized."
640 core.rollback_punch_callbacks = {}
642 core.register_on_punchnode(function(pos, node, puncher)
643 local name = puncher:get_player_name()
644 if core.rollback_punch_callbacks[name] then
645 core.rollback_punch_callbacks[name](pos, node, puncher)
646 core.rollback_punch_callbacks[name] = nil
650 core.register_chatcommand("rollback_check", {
651 params = "[<range>] [<seconds>] [limit]",
652 description = "Check who has last touched a node or near it,"
653 .. " max. <seconds> ago (default range=0,"
654 .. " seconds=86400=24h, limit=5)",
655 privs = {rollback=true},
656 func = function(name, param)
657 if not core.setting_getbool("enable_rollback_recording") then
658 return false, "Rollback functions are disabled."
660 local range, seconds, limit =
661 param:match("(%d+) *(%d*) *(%d*)")
662 range = tonumber(range) or 0
663 seconds = tonumber(seconds) or 86400
664 limit = tonumber(limit) or 5
666 return false, "That limit is too high!"
669 core.rollback_punch_callbacks[name] = function(pos, node, puncher)
670 local name = puncher:get_player_name()
671 core.chat_send_player(name, "Checking " .. core.pos_to_string(pos) .. "...")
672 local actions = core.rollback_get_node_actions(pos, range, seconds, limit)
674 core.chat_send_player(name, "Rollback functions are disabled")
677 local num_actions = #actions
678 if num_actions == 0 then
679 core.chat_send_player(name, "Nobody has touched"
680 .. " the specified location in "
681 .. seconds .. " seconds")
684 local time = os.time()
685 for i = num_actions, 1, -1 do
686 local action = actions[i]
687 core.chat_send_player(name,
688 ("%s %s %s -> %s %d seconds ago.")
690 core.pos_to_string(action.pos),
698 return true, "Punch a node (range=" .. range .. ", seconds="
699 .. seconds .. "s, limit=" .. limit .. ")"
703 core.register_chatcommand("rollback", {
704 params = "<player name> [<seconds>] | :<actor> [<seconds>]",
705 description = "revert actions of a player; default for <seconds> is 60",
706 privs = {rollback=true},
707 func = function(name, param)
708 if not core.setting_getbool("enable_rollback_recording") then
709 return false, "Rollback functions are disabled."
711 local target_name, seconds = string.match(param, ":([^ ]+) *(%d*)")
712 if not target_name then
713 local player_name = nil
714 player_name, seconds = string.match(param, "([^ ]+) *(%d*)")
715 if not player_name then
716 return false, "Invalid parameters. See /help rollback"
717 .. " and /help rollback_check."
719 target_name = "player:"..player_name
721 seconds = tonumber(seconds) or 60
722 core.chat_send_player(name, "Reverting actions of "
723 .. target_name .. " since "
724 .. seconds .. " seconds.")
725 local success, log = core.rollback_revert_actions_by(
726 target_name, seconds)
729 response = "(log is too long to show)\n"
731 for _, line in pairs(log) do
732 response = response .. line .. "\n"
735 response = response .. "Reverting actions "
736 .. (success and "succeeded." or "FAILED.")
737 return success, response
741 core.register_chatcommand("status", {
742 description = "Print server status",
743 func = function(name, param)
744 return true, core.get_server_status()
748 core.register_chatcommand("time", {
749 params = "<0..23>:<0..59> | <0..24000>",
750 description = "set time of day",
752 func = function(name, param)
754 local current_time = math.floor(core.get_timeofday() * 1440)
755 local minutes = current_time % 60
756 local hour = (current_time - minutes) / 60
757 return true, ("Current time is %d:%02d"):format(hour, minutes)
759 local player_privs = core.get_player_privs(name)
760 if not player_privs.settime then
761 return false, "You don't have permission to run this command " ..
762 "(missing privilege: settime)."
764 local hour, minute = param:match("^(%d+):(%d+)$")
766 local new_time = tonumber(param)
768 return false, "Invalid time."
770 -- Backward compatibility.
771 core.set_timeofday((new_time % 24000) / 24000)
772 core.log("action", name .. " sets time to " .. new_time)
773 return true, "Time of day changed."
775 hour = tonumber(hour)
776 minute = tonumber(minute)
777 if hour < 0 or hour > 23 then
778 return false, "Invalid hour (must be between 0 and 23 inclusive)."
779 elseif minute < 0 or minute > 59 then
780 return false, "Invalid minute (must be between 0 and 59 inclusive)."
782 core.set_timeofday((hour * 60 + minute) / 1440)
783 core.log("action", ("%s sets time to %d:%02d"):format(name, hour, minute))
784 return true, "Time of day changed."
788 core.register_chatcommand("days", {
789 description = "Display day count",
790 func = function(name, param)
791 return true, "Current day is " .. core.get_day_count()
795 core.register_chatcommand("shutdown", {
796 description = "shutdown server",
797 privs = {server=true},
798 func = function(name, param)
799 core.log("action", name .. " shuts down server")
800 core.request_shutdown()
801 core.chat_send_all("*** Server shutting down (operator request).")
805 core.register_chatcommand("ban", {
807 description = "Ban IP of player",
809 func = function(name, param)
811 return true, "Ban list: " .. core.get_ban_list()
813 if not core.get_player_by_name(param) then
814 return false, "No such player."
816 if not core.ban_player(param) then
817 return false, "Failed to ban player."
819 local desc = core.get_ban_description(param)
820 core.log("action", name .. " bans " .. desc .. ".")
821 return true, "Banned " .. desc .. "."
825 core.register_chatcommand("unban", {
826 params = "<name/ip>",
827 description = "remove IP ban",
829 func = function(name, param)
830 if not core.unban_player_or_ip(param) then
831 return false, "Failed to unban player/IP."
833 core.log("action", name .. " unbans " .. param)
834 return true, "Unbanned " .. param
838 core.register_chatcommand("kick", {
839 params = "<name> [reason]",
840 description = "kick a player",
842 func = function(name, param)
843 local tokick, reason = param:match("([^ ]+) (.+)")
844 tokick = tokick or param
845 if not core.kick_player(tokick, reason) then
846 return false, "Failed to kick player " .. tokick
848 local log_reason = ""
850 log_reason = " with reason \"" .. reason .. "\""
852 core.log("action", name .. " kicks " .. tokick .. log_reason)
853 return true, "Kicked " .. tokick
857 core.register_chatcommand("clearobjects", {
858 params = "[full|quick]",
859 description = "clear all objects in world",
860 privs = {server=true},
861 func = function(name, param)
863 if param == "" or param == "full" then
864 options.mode = "full"
865 elseif param == "quick" then
866 options.mode = "quick"
868 return false, "Invalid usage, see /help clearobjects."
871 core.log("action", name .. " clears all objects ("
872 .. options.mode .. " mode).")
873 core.chat_send_all("Clearing all objects. This may take long."
874 .. " You may experience a timeout. (by "
876 core.clear_objects(options)
877 core.log("action", "Object clearing done.")
878 core.chat_send_all("*** Cleared all objects.")
882 core.register_chatcommand("msg", {
883 params = "<name> <message>",
884 description = "Send a private message",
885 privs = {shout=true},
886 func = function(name, param)
887 local sendto, message = param:match("^(%S+)%s(.+)$")
889 return false, "Invalid usage, see /help msg."
891 if not core.get_player_by_name(sendto) then
892 return false, "The player " .. sendto
895 core.log("action", "PM from " .. name .. " to " .. sendto
897 core.chat_send_player(sendto, "PM from " .. name .. ": "
899 return true, "Message sent."
903 core.register_chatcommand("last-login", {
905 description = "Get the last login time of a player",
906 func = function(name, param)
910 local pauth = core.get_auth_handler().get_auth(param)
911 if pauth and pauth.last_login then
912 -- Time in UTC, ISO 8601 format
913 return true, "Last login time was " ..
914 os.date("!%Y-%m-%dT%H:%M:%SZ", pauth.last_login)
916 return false, "Last login time is unknown"