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)
105 local msg = core.colorize("#00ffff", "/"..cmd)
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 = ""
185 core.string_to_privs(core.setting_get("basic_privs") or "interact,shout")
186 for priv, _ in pairs(grantprivs) do
187 if not basic_privs[priv] and
188 not core.check_player_privs(name, {privs=true}) then
189 return false, "Your privileges are insufficient."
191 if not core.registered_privileges[priv] then
192 privs_unknown = privs_unknown .. "Unknown privilege: " .. priv .. "\n"
196 if privs_unknown ~= "" then
197 return false, privs_unknown
199 core.set_player_privs(grantname, privs)
200 core.log("action", name..' granted ('..core.privs_to_string(grantprivs, ', ')..') privileges to '..grantname)
201 if grantname ~= name then
202 core.chat_send_player(grantname, name
203 .. " granted you privileges: "
204 .. core.privs_to_string(grantprivs, ' '))
206 return true, "Privileges of " .. grantname .. ": "
207 .. core.privs_to_string(
208 core.get_player_privs(grantname), ' ')
211 core.register_chatcommand("revoke", {
212 params = "<name> <privilege>|all",
213 description = "Remove privilege from player",
215 func = function(name, param)
216 if not core.check_player_privs(name, {privs=true}) and
217 not core.check_player_privs(name, {basic_privs=true}) then
218 return false, "Your privileges are insufficient."
220 local revoke_name, revoke_priv_str = string.match(param, "([^ ]+) (.+)")
221 if not revoke_name or not revoke_priv_str then
222 return false, "Invalid parameters (see /help revoke)"
223 elseif not core.auth_table[revoke_name] then
224 return false, "Player " .. revoke_name .. " does not exist."
226 local revoke_privs = core.string_to_privs(revoke_priv_str)
227 local privs = core.get_player_privs(revoke_name)
229 core.string_to_privs(core.setting_get("basic_privs") or "interact,shout")
230 for priv, _ in pairs(revoke_privs) do
231 if not basic_privs[priv] and
232 not core.check_player_privs(name, {privs=true}) then
233 return false, "Your privileges are insufficient."
236 if revoke_priv_str == "all" then
239 for priv, _ in pairs(revoke_privs) do
243 core.set_player_privs(revoke_name, privs)
244 core.log("action", name..' revoked ('
245 ..core.privs_to_string(revoke_privs, ', ')
246 ..') privileges from '..revoke_name)
247 if revoke_name ~= name then
248 core.chat_send_player(revoke_name, name
249 .. " revoked privileges from you: "
250 .. core.privs_to_string(revoke_privs, ' '))
252 return true, "Privileges of " .. revoke_name .. ": "
253 .. core.privs_to_string(
254 core.get_player_privs(revoke_name), ' ')
258 core.register_chatcommand("setpassword", {
259 params = "<name> <password>",
260 description = "set given password",
261 privs = {password=true},
262 func = function(name, param)
263 local toname, raw_password = string.match(param, "^([^ ]+) +(.+)$")
265 toname = param:match("^([^ ]+) *$")
269 return false, "Name field required"
271 local act_str_past = "?"
272 local act_str_pres = "?"
273 if not raw_password then
274 core.set_player_password(toname, "")
275 act_str_past = "cleared"
276 act_str_pres = "clears"
278 core.set_player_password(toname,
279 core.get_password_hash(toname,
282 act_str_pres = "sets"
284 if toname ~= name then
285 core.chat_send_player(toname, "Your password was "
286 .. act_str_past .. " by " .. name)
289 core.log("action", name .. " " .. act_str_pres
290 .. " password of " .. toname .. ".")
292 return true, "Password of player \"" .. toname .. "\" " .. act_str_past
296 core.register_chatcommand("clearpassword", {
298 description = "set empty password",
299 privs = {password=true},
300 func = function(name, param)
303 return false, "Name field required"
305 core.set_player_password(toname, '')
307 core.log("action", name .. " clears password of " .. toname .. ".")
309 return true, "Password of player \"" .. toname .. "\" cleared"
313 core.register_chatcommand("auth_reload", {
315 description = "reload authentication data",
316 privs = {server=true},
317 func = function(name, param)
318 local done = core.auth_reload()
319 return done, (done and "Done." or "Failed.")
323 core.register_chatcommand("teleport", {
324 params = "<X>,<Y>,<Z> | <to_name> | <name> <X>,<Y>,<Z> | <name> <to_name>",
325 description = "teleport to given position",
326 privs = {teleport=true},
327 func = function(name, param)
328 -- Returns (pos, true) if found, otherwise (pos, false)
329 local function find_free_position_near(pos)
336 for _, d in ipairs(tries) do
337 local p = {x = pos.x+d.x, y = pos.y+d.y, z = pos.z+d.z}
338 local n = core.get_node_or_nil(p)
340 local def = core.registered_nodes[n.name]
341 if def and not def.walkable then
349 local teleportee = nil
351 p.x, p.y, p.z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
355 if p.x and p.y and p.z then
356 local lm = tonumber(minetest.setting_get("map_generation_limit") or 31000)
357 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
358 return false, "Cannot teleport out of map bounds!"
360 teleportee = core.get_player_by_name(name)
363 return true, "Teleporting to "..core.pos_to_string(p)
367 local teleportee = nil
369 local target_name = nil
370 target_name = param:match("^([^ ]+)$")
371 teleportee = core.get_player_by_name(name)
373 local target = core.get_player_by_name(target_name)
378 if teleportee and p then
379 p = find_free_position_near(p)
381 return true, "Teleporting to " .. target_name
382 .. " at "..core.pos_to_string(p)
385 if not core.check_player_privs(name, {bring=true}) then
386 return false, "You don't have permission to teleport other players (missing bring privilege)"
389 local teleportee = nil
391 local teleportee_name = nil
392 teleportee_name, p.x, p.y, p.z = param:match(
393 "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
394 p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
395 if teleportee_name then
396 teleportee = core.get_player_by_name(teleportee_name)
398 if teleportee and p.x and p.y and p.z then
400 return true, "Teleporting " .. teleportee_name
401 .. " to " .. core.pos_to_string(p)
404 local teleportee = nil
406 local teleportee_name = nil
407 local target_name = nil
408 teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
409 if teleportee_name then
410 teleportee = core.get_player_by_name(teleportee_name)
413 local target = core.get_player_by_name(target_name)
418 if teleportee and p then
419 p = find_free_position_near(p)
421 return true, "Teleporting " .. teleportee_name
422 .. " to " .. target_name
423 .. " at " .. core.pos_to_string(p)
426 return false, 'Invalid parameters ("' .. param
427 .. '") or player not found (see /help teleport)'
431 core.register_chatcommand("set", {
432 params = "[-n] <name> <value> | <name>",
433 description = "set or read server configuration setting",
434 privs = {server=true},
435 func = function(name, param)
436 local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)")
437 if arg and arg == "-n" and setname and setvalue then
438 core.setting_set(setname, setvalue)
439 return true, setname .. " = " .. setvalue
441 local setname, setvalue = string.match(param, "([^ ]+) (.+)")
442 if setname and setvalue then
443 if not core.setting_get(setname) then
444 return false, "Failed. Use '/set -n <name> <value>' to create a new setting."
446 core.setting_set(setname, setvalue)
447 return true, setname .. " = " .. setvalue
449 local setname = string.match(param, "([^ ]+)")
451 local setvalue = core.setting_get(setname)
453 setvalue = "<not set>"
455 return true, setname .. " = " .. setvalue
457 return false, "Invalid parameters (see /help set)."
461 local function emergeblocks_callback(pos, action, num_calls_remaining, ctx)
462 if ctx.total_blocks == 0 then
463 ctx.total_blocks = num_calls_remaining + 1
464 ctx.current_blocks = 0
466 ctx.current_blocks = ctx.current_blocks + 1
468 if ctx.current_blocks == ctx.total_blocks then
469 core.chat_send_player(ctx.requestor_name,
470 string.format("Finished emerging %d blocks in %.2fms.",
471 ctx.total_blocks, (os.clock() - ctx.start_time) * 1000))
475 local function emergeblocks_progress_update(ctx)
476 if ctx.current_blocks ~= ctx.total_blocks then
477 core.chat_send_player(ctx.requestor_name,
478 string.format("emergeblocks update: %d/%d blocks emerged (%.1f%%)",
479 ctx.current_blocks, ctx.total_blocks,
480 (ctx.current_blocks / ctx.total_blocks) * 100))
482 core.after(2, emergeblocks_progress_update, ctx)
486 core.register_chatcommand("emergeblocks", {
487 params = "(here [radius]) | (<pos1> <pos2>)",
488 description = "starts loading (or generating, if inexistent) map blocks "
489 .. "contained in area pos1 to pos2",
490 privs = {server=true},
491 func = function(name, param)
492 local p1, p2 = parse_range_str(name, param)
500 start_time = os.clock(),
501 requestor_name = name
504 core.emerge_area(p1, p2, emergeblocks_callback, context)
505 core.after(2, emergeblocks_progress_update, context)
507 return true, "Started emerge of area ranging from " ..
508 core.pos_to_string(p1, 1) .. " to " .. core.pos_to_string(p2, 1)
512 core.register_chatcommand("deleteblocks", {
513 params = "(here [radius]) | (<pos1> <pos2>)",
514 description = "delete map blocks contained in area pos1 to pos2",
515 privs = {server=true},
516 func = function(name, param)
517 local p1, p2 = parse_range_str(name, param)
522 if core.delete_area(p1, p2) then
523 return true, "Successfully cleared area ranging from " ..
524 core.pos_to_string(p1, 1) .. " to " .. core.pos_to_string(p2, 1)
526 return false, "Failed to clear one or more blocks in area"
531 core.register_chatcommand("mods", {
533 description = "List mods installed on the server",
535 func = function(name, param)
536 return true, table.concat(core.get_modnames(), ", ")
540 local function handle_give_command(cmd, giver, receiver, stackstring)
541 core.log("action", giver .. " invoked " .. cmd
542 .. ', stackstring="' .. stackstring .. '"')
543 local itemstack = ItemStack(stackstring)
544 if itemstack:is_empty() then
545 return false, "Cannot give an empty item"
546 elseif not itemstack:is_known() then
547 return false, "Cannot give an unknown item"
549 local receiverref = core.get_player_by_name(receiver)
550 if receiverref == nil then
551 return false, receiver .. " is not a known player"
553 local leftover = receiverref:get_inventory():add_item("main", itemstack)
555 if leftover:is_empty() then
557 elseif leftover:get_count() == itemstack:get_count() then
558 partiality = "could not be "
560 partiality = "partially "
562 -- The actual item stack string may be different from what the "giver"
563 -- entered (e.g. big numbers are always interpreted as 2^16-1).
564 stackstring = itemstack:to_string()
565 if giver == receiver then
566 return true, ("%q %sadded to inventory.")
567 :format(stackstring, partiality)
569 core.chat_send_player(receiver, ("%q %sadded to inventory.")
570 :format(stackstring, partiality))
571 return true, ("%q %sadded to %s's inventory.")
572 :format(stackstring, partiality, receiver)
576 core.register_chatcommand("give", {
577 params = "<name> <ItemString>",
578 description = "give item to player",
580 func = function(name, param)
581 local toname, itemstring = string.match(param, "^([^ ]+) +(.+)$")
582 if not toname or not itemstring then
583 return false, "Name and ItemString required"
585 return handle_give_command("/give", name, toname, itemstring)
589 core.register_chatcommand("giveme", {
590 params = "<ItemString>",
591 description = "give item to yourself",
593 func = function(name, param)
594 local itemstring = string.match(param, "(.+)$")
595 if not itemstring then
596 return false, "ItemString required"
598 return handle_give_command("/giveme", name, name, itemstring)
602 core.register_chatcommand("spawnentity", {
603 params = "<EntityName> [<X>,<Y>,<Z>]",
604 description = "Spawn entity at given (or your) position",
605 privs = {give=true, interact=true},
606 func = function(name, param)
607 local entityname, p = string.match(param, "^([^ ]+) *(.*)$")
608 if not entityname then
609 return false, "EntityName required"
611 core.log("action", ("%s invokes /spawnentity, entityname=%q")
612 :format(name, entityname))
613 local player = core.get_player_by_name(name)
614 if player == nil then
615 core.log("error", "Unable to spawn entity, player is nil")
616 return false, "Unable to spawn entity, player is nil"
621 p = core.string_to_pos(p)
623 return false, "Invalid parameters ('" .. param .. "')"
627 core.add_entity(p, entityname)
628 return true, ("%q spawned."):format(entityname)
632 core.register_chatcommand("pulverize", {
634 description = "Destroy item in hand",
635 func = function(name, param)
636 local player = core.get_player_by_name(name)
638 core.log("error", "Unable to pulverize, no player.")
639 return false, "Unable to pulverize, no player."
641 if player:get_wielded_item():is_empty() then
642 return false, "Unable to pulverize, no item in hand."
644 player:set_wielded_item(nil)
645 return true, "An item was pulverized."
650 core.rollback_punch_callbacks = {}
652 core.register_on_punchnode(function(pos, node, puncher)
653 local name = puncher:get_player_name()
654 if core.rollback_punch_callbacks[name] then
655 core.rollback_punch_callbacks[name](pos, node, puncher)
656 core.rollback_punch_callbacks[name] = nil
660 core.register_chatcommand("rollback_check", {
661 params = "[<range>] [<seconds>] [limit]",
662 description = "Check who has last touched a node or near it,"
663 .. " max. <seconds> ago (default range=0,"
664 .. " seconds=86400=24h, limit=5)",
665 privs = {rollback=true},
666 func = function(name, param)
667 if not core.setting_getbool("enable_rollback_recording") then
668 return false, "Rollback functions are disabled."
670 local range, seconds, limit =
671 param:match("(%d+) *(%d*) *(%d*)")
672 range = tonumber(range) or 0
673 seconds = tonumber(seconds) or 86400
674 limit = tonumber(limit) or 5
676 return false, "That limit is too high!"
679 core.rollback_punch_callbacks[name] = function(pos, node, puncher)
680 local name = puncher:get_player_name()
681 core.chat_send_player(name, "Checking " .. core.pos_to_string(pos) .. "...")
682 local actions = core.rollback_get_node_actions(pos, range, seconds, limit)
684 core.chat_send_player(name, "Rollback functions are disabled")
687 local num_actions = #actions
688 if num_actions == 0 then
689 core.chat_send_player(name, "Nobody has touched"
690 .. " the specified location in "
691 .. seconds .. " seconds")
694 local time = os.time()
695 for i = num_actions, 1, -1 do
696 local action = actions[i]
697 core.chat_send_player(name,
698 ("%s %s %s -> %s %d seconds ago.")
700 core.pos_to_string(action.pos),
708 return true, "Punch a node (range=" .. range .. ", seconds="
709 .. seconds .. "s, limit=" .. limit .. ")"
713 core.register_chatcommand("rollback", {
714 params = "<player name> [<seconds>] | :<actor> [<seconds>]",
715 description = "revert actions of a player; default for <seconds> is 60",
716 privs = {rollback=true},
717 func = function(name, param)
718 if not core.setting_getbool("enable_rollback_recording") then
719 return false, "Rollback functions are disabled."
721 local target_name, seconds = string.match(param, ":([^ ]+) *(%d*)")
722 if not target_name then
723 local player_name = nil
724 player_name, seconds = string.match(param, "([^ ]+) *(%d*)")
725 if not player_name then
726 return false, "Invalid parameters. See /help rollback"
727 .. " and /help rollback_check."
729 target_name = "player:"..player_name
731 seconds = tonumber(seconds) or 60
732 core.chat_send_player(name, "Reverting actions of "
733 .. target_name .. " since "
734 .. seconds .. " seconds.")
735 local success, log = core.rollback_revert_actions_by(
736 target_name, seconds)
739 response = "(log is too long to show)\n"
741 for _, line in pairs(log) do
742 response = response .. line .. "\n"
745 response = response .. "Reverting actions "
746 .. (success and "succeeded." or "FAILED.")
747 return success, response
751 core.register_chatcommand("status", {
752 description = "Print server status",
753 func = function(name, param)
754 return true, core.get_server_status()
758 core.register_chatcommand("time", {
759 params = "<0..23>:<0..59> | <0..24000>",
760 description = "set time of day",
762 func = function(name, param)
764 local current_time = math.floor(core.get_timeofday() * 1440)
765 local minutes = current_time % 60
766 local hour = (current_time - minutes) / 60
767 return true, ("Current time is %d:%02d"):format(hour, minutes)
769 local player_privs = core.get_player_privs(name)
770 if not player_privs.settime then
771 return false, "You don't have permission to run this command " ..
772 "(missing privilege: settime)."
774 local hour, minute = param:match("^(%d+):(%d+)$")
776 local new_time = tonumber(param)
778 return false, "Invalid time."
780 -- Backward compatibility.
781 core.set_timeofday((new_time % 24000) / 24000)
782 core.log("action", name .. " sets time to " .. new_time)
783 return true, "Time of day changed."
785 hour = tonumber(hour)
786 minute = tonumber(minute)
787 if hour < 0 or hour > 23 then
788 return false, "Invalid hour (must be between 0 and 23 inclusive)."
789 elseif minute < 0 or minute > 59 then
790 return false, "Invalid minute (must be between 0 and 59 inclusive)."
792 core.set_timeofday((hour * 60 + minute) / 1440)
793 core.log("action", ("%s sets time to %d:%02d"):format(name, hour, minute))
794 return true, "Time of day changed."
798 core.register_chatcommand("days", {
799 description = "Display day count",
800 func = function(name, param)
801 return true, "Current day is " .. core.get_day_count()
805 core.register_chatcommand("shutdown", {
806 description = "shutdown server",
807 privs = {server=true},
808 func = function(name, param)
809 core.log("action", name .. " shuts down server")
810 core.request_shutdown()
811 core.chat_send_all("*** Server shutting down (operator request).")
815 core.register_chatcommand("ban", {
817 description = "Ban IP of player",
819 func = function(name, param)
821 return true, "Ban list: " .. core.get_ban_list()
823 if not core.get_player_by_name(param) then
824 return false, "No such player."
826 if not core.ban_player(param) then
827 return false, "Failed to ban player."
829 local desc = core.get_ban_description(param)
830 core.log("action", name .. " bans " .. desc .. ".")
831 return true, "Banned " .. desc .. "."
835 core.register_chatcommand("unban", {
836 params = "<name/ip>",
837 description = "remove IP ban",
839 func = function(name, param)
840 if not core.unban_player_or_ip(param) then
841 return false, "Failed to unban player/IP."
843 core.log("action", name .. " unbans " .. param)
844 return true, "Unbanned " .. param
848 core.register_chatcommand("kick", {
849 params = "<name> [reason]",
850 description = "kick a player",
852 func = function(name, param)
853 local tokick, reason = param:match("([^ ]+) (.+)")
854 tokick = tokick or param
855 if not core.kick_player(tokick, reason) then
856 return false, "Failed to kick player " .. tokick
858 local log_reason = ""
860 log_reason = " with reason \"" .. reason .. "\""
862 core.log("action", name .. " kicks " .. tokick .. log_reason)
863 return true, "Kicked " .. tokick
867 core.register_chatcommand("clearobjects", {
868 params = "[full|quick]",
869 description = "clear all objects in world",
870 privs = {server=true},
871 func = function(name, param)
873 if param == "" or param == "full" then
874 options.mode = "full"
875 elseif param == "quick" then
876 options.mode = "quick"
878 return false, "Invalid usage, see /help clearobjects."
881 core.log("action", name .. " clears all objects ("
882 .. options.mode .. " mode).")
883 core.chat_send_all("Clearing all objects. This may take long."
884 .. " You may experience a timeout. (by "
886 core.clear_objects(options)
887 core.log("action", "Object clearing done.")
888 core.chat_send_all("*** Cleared all objects.")
892 core.register_chatcommand("msg", {
893 params = "<name> <message>",
894 description = "Send a private message",
895 privs = {shout=true},
896 func = function(name, param)
897 local sendto, message = param:match("^(%S+)%s(.+)$")
899 return false, "Invalid usage, see /help msg."
901 if not core.get_player_by_name(sendto) then
902 return false, "The player " .. sendto
905 core.log("action", "PM from " .. name .. " to " .. sendto
907 core.chat_send_player(sendto, "PM from " .. name .. ": "
909 return true, "Message sent."
913 core.register_chatcommand("last-login", {
915 description = "Get the last login time of a player",
916 func = function(name, param)
920 local pauth = core.get_auth_handler().get_auth(param)
921 if pauth and pauth.last_login then
922 -- Time in UTC, ISO 8601 format
923 return true, "Last login time was " ..
924 os.date("!%Y-%m-%dT%H:%M:%SZ", pauth.last_login)
926 return false, "Last login time is unknown"