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(name, param)
151 param = (param ~= "" and param or name)
152 return true, "Privileges of " .. param .. ": "
153 .. core.privs_to_string(
154 core.get_player_privs(param), ' ')
157 core.register_chatcommand("grant", {
158 params = "<name> <privilege>|all",
159 description = "Give privilege to player",
160 func = function(name, param)
161 if not core.check_player_privs(name, {privs=true}) and
162 not core.check_player_privs(name, {basic_privs=true}) then
163 return false, "Your privileges are insufficient."
165 local grantname, grantprivstr = string.match(param, "([^ ]+) (.+)")
166 if not grantname or not grantprivstr then
167 return false, "Invalid parameters (see /help grant)"
168 elseif not core.auth_table[grantname] then
169 return false, "Player " .. grantname .. " does not exist."
171 local grantprivs = core.string_to_privs(grantprivstr)
172 if grantprivstr == "all" then
173 grantprivs = core.registered_privileges
175 local privs = core.get_player_privs(grantname)
176 local privs_unknown = ""
178 core.string_to_privs(core.setting_get("basic_privs") or "interact,shout")
179 for priv, _ in pairs(grantprivs) do
180 if not basic_privs[priv] and
181 not core.check_player_privs(name, {privs=true}) then
182 return false, "Your privileges are insufficient."
184 if not core.registered_privileges[priv] then
185 privs_unknown = privs_unknown .. "Unknown privilege: " .. priv .. "\n"
189 if privs_unknown ~= "" then
190 return false, privs_unknown
192 core.set_player_privs(grantname, privs)
193 core.log("action", name..' granted ('..core.privs_to_string(grantprivs, ', ')..') privileges to '..grantname)
194 if grantname ~= name then
195 core.chat_send_player(grantname, name
196 .. " granted you privileges: "
197 .. core.privs_to_string(grantprivs, ' '))
199 return true, "Privileges of " .. grantname .. ": "
200 .. core.privs_to_string(
201 core.get_player_privs(grantname), ' ')
204 core.register_chatcommand("revoke", {
205 params = "<name> <privilege>|all",
206 description = "Remove privilege from player",
208 func = function(name, param)
209 if not core.check_player_privs(name, {privs=true}) and
210 not core.check_player_privs(name, {basic_privs=true}) then
211 return false, "Your privileges are insufficient."
213 local revoke_name, revoke_priv_str = string.match(param, "([^ ]+) (.+)")
214 if not revoke_name or not revoke_priv_str then
215 return false, "Invalid parameters (see /help revoke)"
216 elseif not core.auth_table[revoke_name] then
217 return false, "Player " .. revoke_name .. " does not exist."
219 local revoke_privs = core.string_to_privs(revoke_priv_str)
220 local privs = core.get_player_privs(revoke_name)
222 core.string_to_privs(core.setting_get("basic_privs") or "interact,shout")
223 for priv, _ in pairs(revoke_privs) do
224 if not basic_privs[priv] and
225 not core.check_player_privs(name, {privs=true}) then
226 return false, "Your privileges are insufficient."
229 if revoke_priv_str == "all" then
232 for priv, _ in pairs(revoke_privs) do
236 core.set_player_privs(revoke_name, privs)
237 core.log("action", name..' revoked ('
238 ..core.privs_to_string(revoke_privs, ', ')
239 ..') privileges from '..revoke_name)
240 if revoke_name ~= name then
241 core.chat_send_player(revoke_name, name
242 .. " revoked privileges from you: "
243 .. core.privs_to_string(revoke_privs, ' '))
245 return true, "Privileges of " .. revoke_name .. ": "
246 .. core.privs_to_string(
247 core.get_player_privs(revoke_name), ' ')
251 core.register_chatcommand("setpassword", {
252 params = "<name> <password>",
253 description = "set given password",
254 privs = {password=true},
255 func = function(name, param)
256 local toname, raw_password = string.match(param, "^([^ ]+) +(.+)$")
258 toname = param:match("^([^ ]+) *$")
262 return false, "Name field required"
264 local act_str_past = "?"
265 local act_str_pres = "?"
266 if not raw_password then
267 core.set_player_password(toname, "")
268 act_str_past = "cleared"
269 act_str_pres = "clears"
271 core.set_player_password(toname,
272 core.get_password_hash(toname,
275 act_str_pres = "sets"
277 if toname ~= name then
278 core.chat_send_player(toname, "Your password was "
279 .. act_str_past .. " by " .. name)
282 core.log("action", name .. " " .. act_str_pres
283 .. " password of " .. toname .. ".")
285 return true, "Password of player \"" .. toname .. "\" " .. act_str_past
289 core.register_chatcommand("clearpassword", {
291 description = "set empty password",
292 privs = {password=true},
293 func = function(name, param)
296 return false, "Name field required"
298 core.set_player_password(toname, '')
300 core.log("action", name .. " clears password of " .. toname .. ".")
302 return true, "Password of player \"" .. toname .. "\" cleared"
306 core.register_chatcommand("auth_reload", {
308 description = "reload authentication data",
309 privs = {server=true},
310 func = function(name, param)
311 local done = core.auth_reload()
312 return done, (done and "Done." or "Failed.")
316 core.register_chatcommand("teleport", {
317 params = "<X>,<Y>,<Z> | <to_name> | <name> <X>,<Y>,<Z> | <name> <to_name>",
318 description = "teleport to given position",
319 privs = {teleport=true},
320 func = function(name, param)
321 -- Returns (pos, true) if found, otherwise (pos, false)
322 local function find_free_position_near(pos)
329 for _, d in ipairs(tries) do
330 local p = {x = pos.x+d.x, y = pos.y+d.y, z = pos.z+d.z}
331 local n = core.get_node_or_nil(p)
333 local def = core.registered_nodes[n.name]
334 if def and not def.walkable then
342 local teleportee = nil
344 p.x, p.y, p.z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
348 if p.x and p.y and p.z then
349 local lm = tonumber(minetest.setting_get("map_generation_limit") or 31000)
350 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
351 return false, "Cannot teleport out of map bounds!"
353 teleportee = core.get_player_by_name(name)
356 return true, "Teleporting to "..core.pos_to_string(p)
360 local teleportee = nil
362 local target_name = nil
363 target_name = param:match("^([^ ]+)$")
364 teleportee = core.get_player_by_name(name)
366 local target = core.get_player_by_name(target_name)
371 if teleportee and p then
372 p = find_free_position_near(p)
374 return true, "Teleporting to " .. target_name
375 .. " at "..core.pos_to_string(p)
378 if not core.check_player_privs(name, {bring=true}) then
379 return false, "You don't have permission to teleport other players (missing bring privilege)"
382 local teleportee = nil
384 local teleportee_name = nil
385 teleportee_name, p.x, p.y, p.z = param:match(
386 "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
387 p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
388 if teleportee_name then
389 teleportee = core.get_player_by_name(teleportee_name)
391 if teleportee and p.x and p.y and p.z then
393 return true, "Teleporting " .. teleportee_name
394 .. " to " .. core.pos_to_string(p)
397 local teleportee = nil
399 local teleportee_name = nil
400 local target_name = nil
401 teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
402 if teleportee_name then
403 teleportee = core.get_player_by_name(teleportee_name)
406 local target = core.get_player_by_name(target_name)
411 if teleportee and p then
412 p = find_free_position_near(p)
414 return true, "Teleporting " .. teleportee_name
415 .. " to " .. target_name
416 .. " at " .. core.pos_to_string(p)
419 return false, 'Invalid parameters ("' .. param
420 .. '") or player not found (see /help teleport)'
424 core.register_chatcommand("set", {
425 params = "[-n] <name> <value> | <name>",
426 description = "set or read server configuration setting",
427 privs = {server=true},
428 func = function(name, param)
429 local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)")
430 if arg and arg == "-n" and setname and setvalue then
431 core.setting_set(setname, setvalue)
432 return true, setname .. " = " .. setvalue
434 local setname, setvalue = string.match(param, "([^ ]+) (.+)")
435 if setname and setvalue then
436 if not core.setting_get(setname) then
437 return false, "Failed. Use '/set -n <name> <value>' to create a new setting."
439 core.setting_set(setname, setvalue)
440 return true, setname .. " = " .. setvalue
442 local setname = string.match(param, "([^ ]+)")
444 local setvalue = core.setting_get(setname)
446 setvalue = "<not set>"
448 return true, setname .. " = " .. setvalue
450 return false, "Invalid parameters (see /help set)."
454 local function emergeblocks_callback(pos, action, num_calls_remaining, ctx)
455 if ctx.total_blocks == 0 then
456 ctx.total_blocks = num_calls_remaining + 1
457 ctx.current_blocks = 0
459 ctx.current_blocks = ctx.current_blocks + 1
461 if ctx.current_blocks == ctx.total_blocks then
462 core.chat_send_player(ctx.requestor_name,
463 string.format("Finished emerging %d blocks in %.2fms.",
464 ctx.total_blocks, (os.clock() - ctx.start_time) * 1000))
468 local function emergeblocks_progress_update(ctx)
469 if ctx.current_blocks ~= ctx.total_blocks then
470 core.chat_send_player(ctx.requestor_name,
471 string.format("emergeblocks update: %d/%d blocks emerged (%.1f%%)",
472 ctx.current_blocks, ctx.total_blocks,
473 (ctx.current_blocks / ctx.total_blocks) * 100))
475 core.after(2, emergeblocks_progress_update, ctx)
479 core.register_chatcommand("emergeblocks", {
480 params = "(here [radius]) | (<pos1> <pos2>)",
481 description = "starts loading (or generating, if inexistent) map blocks "
482 .. "contained in area pos1 to pos2",
483 privs = {server=true},
484 func = function(name, param)
485 local p1, p2 = parse_range_str(name, param)
493 start_time = os.clock(),
494 requestor_name = name
497 core.emerge_area(p1, p2, emergeblocks_callback, context)
498 core.after(2, emergeblocks_progress_update, context)
500 return true, "Started emerge of area ranging from " ..
501 core.pos_to_string(p1, 1) .. " to " .. core.pos_to_string(p2, 1)
505 core.register_chatcommand("deleteblocks", {
506 params = "(here [radius]) | (<pos1> <pos2>)",
507 description = "delete map blocks contained in area pos1 to pos2",
508 privs = {server=true},
509 func = function(name, param)
510 local p1, p2 = parse_range_str(name, param)
515 if core.delete_area(p1, p2) then
516 return true, "Successfully cleared area ranging from " ..
517 core.pos_to_string(p1, 1) .. " to " .. core.pos_to_string(p2, 1)
519 return false, "Failed to clear one or more blocks in area"
524 core.register_chatcommand("mods", {
526 description = "List mods installed on the server",
528 func = function(name, param)
529 return true, table.concat(core.get_modnames(), ", ")
533 local function handle_give_command(cmd, giver, receiver, stackstring)
534 core.log("action", giver .. " invoked " .. cmd
535 .. ', stackstring="' .. stackstring .. '"')
536 local itemstack = ItemStack(stackstring)
537 if itemstack:is_empty() then
538 return false, "Cannot give an empty item"
539 elseif not itemstack:is_known() then
540 return false, "Cannot give an unknown item"
542 local receiverref = core.get_player_by_name(receiver)
543 if receiverref == nil then
544 return false, receiver .. " is not a known player"
546 local leftover = receiverref:get_inventory():add_item("main", itemstack)
548 if leftover:is_empty() then
550 elseif leftover:get_count() == itemstack:get_count() then
551 partiality = "could not be "
553 partiality = "partially "
555 -- The actual item stack string may be different from what the "giver"
556 -- entered (e.g. big numbers are always interpreted as 2^16-1).
557 stackstring = itemstack:to_string()
558 if giver == receiver then
559 return true, ("%q %sadded to inventory.")
560 :format(stackstring, partiality)
562 core.chat_send_player(receiver, ("%q %sadded to inventory.")
563 :format(stackstring, partiality))
564 return true, ("%q %sadded to %s's inventory.")
565 :format(stackstring, partiality, receiver)
569 core.register_chatcommand("give", {
570 params = "<name> <ItemString>",
571 description = "give item to player",
573 func = function(name, param)
574 local toname, itemstring = string.match(param, "^([^ ]+) +(.+)$")
575 if not toname or not itemstring then
576 return false, "Name and ItemString required"
578 return handle_give_command("/give", name, toname, itemstring)
582 core.register_chatcommand("giveme", {
583 params = "<ItemString>",
584 description = "give item to yourself",
586 func = function(name, param)
587 local itemstring = string.match(param, "(.+)$")
588 if not itemstring then
589 return false, "ItemString required"
591 return handle_give_command("/giveme", name, name, itemstring)
595 core.register_chatcommand("spawnentity", {
596 params = "<EntityName> [<X>,<Y>,<Z>]",
597 description = "Spawn entity at given (or your) position",
598 privs = {give=true, interact=true},
599 func = function(name, param)
600 local entityname, p = string.match(param, "^([^ ]+) *(.*)$")
601 if not entityname then
602 return false, "EntityName required"
604 core.log("action", ("%s invokes /spawnentity, entityname=%q")
605 :format(name, entityname))
606 local player = core.get_player_by_name(name)
607 if player == nil then
608 core.log("error", "Unable to spawn entity, player is nil")
609 return false, "Unable to spawn entity, player is nil"
614 p = core.string_to_pos(p)
616 return false, "Invalid parameters ('" .. param .. "')"
620 core.add_entity(p, entityname)
621 return true, ("%q spawned."):format(entityname)
625 core.register_chatcommand("pulverize", {
627 description = "Destroy item in hand",
628 func = function(name, param)
629 local player = core.get_player_by_name(name)
631 core.log("error", "Unable to pulverize, no player.")
632 return false, "Unable to pulverize, no player."
634 if player:get_wielded_item():is_empty() then
635 return false, "Unable to pulverize, no item in hand."
637 player:set_wielded_item(nil)
638 return true, "An item was pulverized."
643 core.rollback_punch_callbacks = {}
645 core.register_on_punchnode(function(pos, node, puncher)
646 local name = puncher:get_player_name()
647 if core.rollback_punch_callbacks[name] then
648 core.rollback_punch_callbacks[name](pos, node, puncher)
649 core.rollback_punch_callbacks[name] = nil
653 core.register_chatcommand("rollback_check", {
654 params = "[<range>] [<seconds>] [limit]",
655 description = "Check who has last touched a node or near it,"
656 .. " max. <seconds> ago (default range=0,"
657 .. " seconds=86400=24h, limit=5)",
658 privs = {rollback=true},
659 func = function(name, param)
660 if not core.setting_getbool("enable_rollback_recording") then
661 return false, "Rollback functions are disabled."
663 local range, seconds, limit =
664 param:match("(%d+) *(%d*) *(%d*)")
665 range = tonumber(range) or 0
666 seconds = tonumber(seconds) or 86400
667 limit = tonumber(limit) or 5
669 return false, "That limit is too high!"
672 core.rollback_punch_callbacks[name] = function(pos, node, puncher)
673 local name = puncher:get_player_name()
674 core.chat_send_player(name, "Checking " .. core.pos_to_string(pos) .. "...")
675 local actions = core.rollback_get_node_actions(pos, range, seconds, limit)
677 core.chat_send_player(name, "Rollback functions are disabled")
680 local num_actions = #actions
681 if num_actions == 0 then
682 core.chat_send_player(name, "Nobody has touched"
683 .. " the specified location in "
684 .. seconds .. " seconds")
687 local time = os.time()
688 for i = num_actions, 1, -1 do
689 local action = actions[i]
690 core.chat_send_player(name,
691 ("%s %s %s -> %s %d seconds ago.")
693 core.pos_to_string(action.pos),
701 return true, "Punch a node (range=" .. range .. ", seconds="
702 .. seconds .. "s, limit=" .. limit .. ")"
706 core.register_chatcommand("rollback", {
707 params = "<player name> [<seconds>] | :<actor> [<seconds>]",
708 description = "revert actions of a player; default for <seconds> is 60",
709 privs = {rollback=true},
710 func = function(name, param)
711 if not core.setting_getbool("enable_rollback_recording") then
712 return false, "Rollback functions are disabled."
714 local target_name, seconds = string.match(param, ":([^ ]+) *(%d*)")
715 if not target_name then
716 local player_name = nil
717 player_name, seconds = string.match(param, "([^ ]+) *(%d*)")
718 if not player_name then
719 return false, "Invalid parameters. See /help rollback"
720 .. " and /help rollback_check."
722 target_name = "player:"..player_name
724 seconds = tonumber(seconds) or 60
725 core.chat_send_player(name, "Reverting actions of "
726 .. target_name .. " since "
727 .. seconds .. " seconds.")
728 local success, log = core.rollback_revert_actions_by(
729 target_name, seconds)
732 response = "(log is too long to show)\n"
734 for _, line in pairs(log) do
735 response = response .. line .. "\n"
738 response = response .. "Reverting actions "
739 .. (success and "succeeded." or "FAILED.")
740 return success, response
744 core.register_chatcommand("status", {
745 description = "Print server status",
746 func = function(name, param)
747 return true, core.get_server_status()
751 core.register_chatcommand("time", {
752 params = "<0..23>:<0..59> | <0..24000>",
753 description = "set time of day",
755 func = function(name, param)
757 local current_time = math.floor(core.get_timeofday() * 1440)
758 local minutes = current_time % 60
759 local hour = (current_time - minutes) / 60
760 return true, ("Current time is %d:%02d"):format(hour, minutes)
762 local player_privs = core.get_player_privs(name)
763 if not player_privs.settime then
764 return false, "You don't have permission to run this command " ..
765 "(missing privilege: settime)."
767 local hour, minute = param:match("^(%d+):(%d+)$")
769 local new_time = tonumber(param)
771 return false, "Invalid time."
773 -- Backward compatibility.
774 core.set_timeofday((new_time % 24000) / 24000)
775 core.log("action", name .. " sets time to " .. new_time)
776 return true, "Time of day changed."
778 hour = tonumber(hour)
779 minute = tonumber(minute)
780 if hour < 0 or hour > 23 then
781 return false, "Invalid hour (must be between 0 and 23 inclusive)."
782 elseif minute < 0 or minute > 59 then
783 return false, "Invalid minute (must be between 0 and 59 inclusive)."
785 core.set_timeofday((hour * 60 + minute) / 1440)
786 core.log("action", ("%s sets time to %d:%02d"):format(name, hour, minute))
787 return true, "Time of day changed."
791 core.register_chatcommand("days", {
792 description = "Display day count",
793 func = function(name, param)
794 return true, "Current day is " .. core.get_day_count()
798 core.register_chatcommand("shutdown", {
799 description = "shutdown server",
800 privs = {server=true},
801 func = function(name, param)
802 core.log("action", name .. " shuts down server")
803 core.request_shutdown()
804 core.chat_send_all("*** Server shutting down (operator request).")
808 core.register_chatcommand("ban", {
810 description = "Ban IP of player",
812 func = function(name, param)
814 return true, "Ban list: " .. core.get_ban_list()
816 if not core.get_player_by_name(param) then
817 return false, "No such player."
819 if not core.ban_player(param) then
820 return false, "Failed to ban player."
822 local desc = core.get_ban_description(param)
823 core.log("action", name .. " bans " .. desc .. ".")
824 return true, "Banned " .. desc .. "."
828 core.register_chatcommand("unban", {
829 params = "<name/ip>",
830 description = "remove IP ban",
832 func = function(name, param)
833 if not core.unban_player_or_ip(param) then
834 return false, "Failed to unban player/IP."
836 core.log("action", name .. " unbans " .. param)
837 return true, "Unbanned " .. param
841 core.register_chatcommand("kick", {
842 params = "<name> [reason]",
843 description = "kick a player",
845 func = function(name, param)
846 local tokick, reason = param:match("([^ ]+) (.+)")
847 tokick = tokick or param
848 if not core.kick_player(tokick, reason) then
849 return false, "Failed to kick player " .. tokick
851 local log_reason = ""
853 log_reason = " with reason \"" .. reason .. "\""
855 core.log("action", name .. " kicks " .. tokick .. log_reason)
856 return true, "Kicked " .. tokick
860 core.register_chatcommand("clearobjects", {
861 params = "[full|quick]",
862 description = "clear all objects in world",
863 privs = {server=true},
864 func = function(name, param)
866 if param == "" or param == "full" then
867 options.mode = "full"
868 elseif param == "quick" then
869 options.mode = "quick"
871 return false, "Invalid usage, see /help clearobjects."
874 core.log("action", name .. " clears all objects ("
875 .. options.mode .. " mode).")
876 core.chat_send_all("Clearing all objects. This may take long."
877 .. " You may experience a timeout. (by "
879 core.clear_objects(options)
880 core.log("action", "Object clearing done.")
881 core.chat_send_all("*** Cleared all objects.")
885 core.register_chatcommand("msg", {
886 params = "<name> <message>",
887 description = "Send a private message",
888 privs = {shout=true},
889 func = function(name, param)
890 local sendto, message = param:match("^(%S+)%s(.+)$")
892 return false, "Invalid usage, see /help msg."
894 if not core.get_player_by_name(sendto) then
895 return false, "The player " .. sendto
898 core.log("action", "PM from " .. name .. " to " .. sendto
900 core.chat_send_player(sendto, "PM from " .. name .. ": "
902 return true, "Message sent."
906 core.register_chatcommand("last-login", {
908 description = "Get the last login time of a player",
909 func = function(name, param)
913 local pauth = core.get_auth_handler().get_auth(param)
914 if pauth and pauth.last_login then
915 -- Time in UTC, ISO 8601 format
916 return true, "Last login time was " ..
917 os.date("!%Y-%m-%dT%H:%M:%SZ", pauth.last_login)
919 return false, "Last login time is unknown"