chatcommands.lua 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. -- Minetest: builtin/chatcommands.lua
  2. --
  3. -- Chat command handler
  4. --
  5. core.chatcommands = {}
  6. function core.register_chatcommand(cmd, def)
  7. def = def or {}
  8. def.params = def.params or ""
  9. def.description = def.description or ""
  10. def.privs = def.privs or {}
  11. core.chatcommands[cmd] = def
  12. end
  13. core.register_on_chat_message(function(name, message)
  14. local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
  15. if not param then
  16. param = ""
  17. end
  18. local cmd_def = core.chatcommands[cmd]
  19. if not cmd_def then
  20. return false
  21. end
  22. local has_privs, missing_privs = core.check_player_privs(name, cmd_def.privs)
  23. if has_privs then
  24. local success, message = cmd_def.func(name, param)
  25. if message then
  26. core.chat_send_player(name, message)
  27. end
  28. else
  29. core.chat_send_player(name, "You don't have permission"
  30. .. " to run this command (missing privileges: "
  31. .. table.concat(missing_privs, ", ") .. ")")
  32. end
  33. return true -- Handled chat message
  34. end)
  35. --
  36. -- Chat commands
  37. --
  38. core.register_chatcommand("me", {
  39. params = "<action>",
  40. description = "chat action (eg. /me orders a pizza)",
  41. privs = {shout=true},
  42. func = function(name, param)
  43. core.chat_send_all("* " .. name .. " " .. param)
  44. end,
  45. })
  46. core.register_chatcommand("help", {
  47. privs = {},
  48. params = "[all/privs/<cmd>]",
  49. description = "Get help for commands or list privileges",
  50. func = function(name, param)
  51. local function format_help_line(cmd, def)
  52. local msg = "/"..cmd
  53. if def.params and def.params ~= "" then
  54. msg = msg .. " " .. def.params
  55. end
  56. if def.description and def.description ~= "" then
  57. msg = msg .. ": " .. def.description
  58. end
  59. return msg
  60. end
  61. if param == "" then
  62. local msg = ""
  63. local cmds = {}
  64. for cmd, def in pairs(core.chatcommands) do
  65. if core.check_player_privs(name, def.privs) then
  66. table.insert(cmds, cmd)
  67. end
  68. end
  69. table.sort(cmds)
  70. return true, "Available commands: " .. table.concat(cmds, " ") .. "\n"
  71. .. "Use '/help <cmd>' to get more information,"
  72. .. " or '/help all' to list everything."
  73. elseif param == "all" then
  74. local cmds = {}
  75. for cmd, def in pairs(core.chatcommands) do
  76. if core.check_player_privs(name, def.privs) then
  77. table.insert(cmds, format_help_line(cmd, def))
  78. end
  79. end
  80. table.sort(cmds)
  81. return true, "Available commands:\n"..table.concat(cmds, "\n")
  82. elseif param == "privs" then
  83. local privs = {}
  84. for priv, def in pairs(core.registered_privileges) do
  85. table.insert(privs, priv .. ": " .. def.description)
  86. end
  87. table.sort(privs)
  88. return true, "Available privileges:\n"..table.concat(privs, "\n")
  89. else
  90. local cmd = param
  91. local def = core.chatcommands[cmd]
  92. if not def then
  93. return false, "Command not available: "..cmd
  94. else
  95. return true, format_help_line(cmd, def)
  96. end
  97. end
  98. end,
  99. })
  100. core.register_chatcommand("privs", {
  101. params = "<name>",
  102. description = "print out privileges of player",
  103. func = function(name, param)
  104. param = (param ~= "" and param or name)
  105. return true, "Privileges of " .. param .. ": "
  106. .. core.privs_to_string(
  107. core.get_player_privs(param), ' ')
  108. end,
  109. })
  110. core.register_chatcommand("grant", {
  111. params = "<name> <privilege>|all",
  112. description = "Give privilege to player",
  113. func = function(name, param)
  114. if not core.check_player_privs(name, {privs=true}) and
  115. not core.check_player_privs(name, {basic_privs=true}) then
  116. return false, "Your privileges are insufficient."
  117. end
  118. local grantname, grantprivstr = string.match(param, "([^ ]+) (.+)")
  119. if not grantname or not grantprivstr then
  120. return false, "Invalid parameters (see /help grant)"
  121. elseif not core.auth_table[grantname] then
  122. return false, "Player " .. grantname .. " does not exist."
  123. end
  124. local grantprivs = core.string_to_privs(grantprivstr)
  125. if grantprivstr == "all" then
  126. grantprivs = core.registered_privileges
  127. end
  128. local privs = core.get_player_privs(grantname)
  129. local privs_unknown = ""
  130. for priv, _ in pairs(grantprivs) do
  131. if priv ~= "interact" and priv ~= "shout" and
  132. not core.check_player_privs(name, {privs=true}) then
  133. return false, "Your privileges are insufficient."
  134. end
  135. if not core.registered_privileges[priv] then
  136. privs_unknown = privs_unknown .. "Unknown privilege: " .. priv .. "\n"
  137. end
  138. privs[priv] = true
  139. end
  140. if privs_unknown ~= "" then
  141. return false, privs_unknown
  142. end
  143. core.set_player_privs(grantname, privs)
  144. core.log("action", name..' granted ('..core.privs_to_string(grantprivs, ', ')..') privileges to '..grantname)
  145. if grantname ~= name then
  146. core.chat_send_player(grantname, name
  147. .. " granted you privileges: "
  148. .. core.privs_to_string(grantprivs, ' '))
  149. end
  150. return true, "Privileges of " .. grantname .. ": "
  151. .. core.privs_to_string(
  152. core.get_player_privs(grantname), ' ')
  153. end,
  154. })
  155. core.register_chatcommand("revoke", {
  156. params = "<name> <privilege>|all",
  157. description = "Remove privilege from player",
  158. privs = {},
  159. func = function(name, param)
  160. if not core.check_player_privs(name, {privs=true}) and
  161. not core.check_player_privs(name, {basic_privs=true}) then
  162. return false, "Your privileges are insufficient."
  163. end
  164. local revoke_name, revoke_priv_str = string.match(param, "([^ ]+) (.+)")
  165. if not revoke_name or not revoke_priv_str then
  166. return false, "Invalid parameters (see /help revoke)"
  167. elseif not core.auth_table[revoke_name] then
  168. return false, "Player " .. revoke_name .. " does not exist."
  169. end
  170. local revoke_privs = core.string_to_privs(revoke_priv_str)
  171. local privs = core.get_player_privs(revoke_name)
  172. for priv, _ in pairs(revoke_privs) do
  173. if priv ~= "interact" and priv ~= "shout" and priv ~= "interact_extra" and
  174. not core.check_player_privs(name, {privs=true}) then
  175. return false, "Your privileges are insufficient."
  176. end
  177. end
  178. if revoke_priv_str == "all" then
  179. privs = {}
  180. else
  181. for priv, _ in pairs(revoke_privs) do
  182. privs[priv] = nil
  183. end
  184. end
  185. core.set_player_privs(revoke_name, privs)
  186. core.log("action", name..' revoked ('
  187. ..core.privs_to_string(revoke_privs, ', ')
  188. ..') privileges from '..revoke_name)
  189. if revoke_name ~= name then
  190. core.chat_send_player(revoke_name, name
  191. .. " revoked privileges from you: "
  192. .. core.privs_to_string(revoke_privs, ' '))
  193. end
  194. return true, "Privileges of " .. revoke_name .. ": "
  195. .. core.privs_to_string(
  196. core.get_player_privs(revoke_name), ' ')
  197. end,
  198. })
  199. core.register_chatcommand("setpassword", {
  200. params = "<name> <password>",
  201. description = "set given password",
  202. privs = {password=true},
  203. func = function(name, param)
  204. local toname, raw_password = string.match(param, "^([^ ]+) +(.+)$")
  205. if not toname then
  206. toname = param:match("^([^ ]+) *$")
  207. raw_password = nil
  208. end
  209. if not toname then
  210. return false, "Name field required"
  211. end
  212. local actstr = "?"
  213. if not raw_password then
  214. core.set_player_password(toname, "")
  215. actstr = "cleared"
  216. else
  217. core.set_player_password(toname,
  218. core.get_password_hash(toname,
  219. raw_password))
  220. actstr = "set"
  221. end
  222. if toname ~= name then
  223. core.chat_send_player(toname, "Your password was "
  224. .. actstr .. " by " .. name)
  225. end
  226. return true, "Password of player \"" .. toname .. "\" " .. actstr
  227. end,
  228. })
  229. core.register_chatcommand("clearpassword", {
  230. params = "<name>",
  231. description = "set empty password",
  232. privs = {password=true},
  233. func = function(name, param)
  234. toname = param
  235. if toname == "" then
  236. return false, "Name field required"
  237. end
  238. core.set_player_password(toname, '')
  239. return true, "Password of player \"" .. toname .. "\" cleared"
  240. end,
  241. })
  242. core.register_chatcommand("auth_reload", {
  243. params = "",
  244. description = "reload authentication data",
  245. privs = {server=true},
  246. func = function(name, param)
  247. local done = core.auth_reload()
  248. return done, (done and "Done." or "Failed.")
  249. end,
  250. })
  251. core.register_chatcommand("teleport", {
  252. params = "<X>,<Y>,<Z> | <to_name> | <name> <X>,<Y>,<Z> | <name> <to_name>",
  253. description = "teleport to given position",
  254. privs = {teleport=true},
  255. func = function(name, param)
  256. -- Returns (pos, true) if found, otherwise (pos, false)
  257. local function find_free_position_near(pos)
  258. local tries = {
  259. {x=1,y=0,z=0},
  260. {x=-1,y=0,z=0},
  261. {x=0,y=0,z=1},
  262. {x=0,y=0,z=-1},
  263. }
  264. for _, d in ipairs(tries) do
  265. local p = {x = pos.x+d.x, y = pos.y+d.y, z = pos.z+d.z}
  266. local n = core.get_node_or_nil(p)
  267. if n and n.name then
  268. local def = core.registered_nodes[n.name]
  269. if def and not def.walkable then
  270. return p, true
  271. end
  272. end
  273. end
  274. return pos, false
  275. end
  276. local teleportee = nil
  277. local p = {}
  278. p.x, p.y, p.z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
  279. p.x = tonumber(p.x)
  280. p.y = tonumber(p.y)
  281. p.z = tonumber(p.z)
  282. teleportee = core.get_player_by_name(name)
  283. if teleportee and p.x and p.y and p.z then
  284. teleportee:setpos(p)
  285. return true, "Teleporting to "..core.pos_to_string(p)
  286. end
  287. local teleportee = nil
  288. local p = nil
  289. local target_name = nil
  290. target_name = param:match("^([^ ]+)$")
  291. teleportee = core.get_player_by_name(name)
  292. if target_name then
  293. local target = core.get_player_by_name(target_name)
  294. if target then
  295. p = target:getpos()
  296. end
  297. end
  298. if teleportee and p then
  299. p = find_free_position_near(p)
  300. teleportee:setpos(p)
  301. return true, "Teleporting to " .. target_name
  302. .. " at "..core.pos_to_string(p)
  303. end
  304. if core.check_player_privs(name, {bring=true}) then
  305. local teleportee = nil
  306. local p = {}
  307. local teleportee_name = nil
  308. teleportee_name, p.x, p.y, p.z = param:match(
  309. "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
  310. p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z)
  311. if teleportee_name then
  312. teleportee = core.get_player_by_name(teleportee_name)
  313. end
  314. if teleportee and p.x and p.y and p.z then
  315. teleportee:setpos(p)
  316. return true, "Teleporting " .. teleportee_name
  317. .. " to " .. core.pos_to_string(p)
  318. end
  319. local teleportee = nil
  320. local p = nil
  321. local teleportee_name = nil
  322. local target_name = nil
  323. teleportee_name, target_name = string.match(param, "^([^ ]+) +([^ ]+)$")
  324. if teleportee_name then
  325. teleportee = core.get_player_by_name(teleportee_name)
  326. end
  327. if target_name then
  328. local target = core.get_player_by_name(target_name)
  329. if target then
  330. p = target:getpos()
  331. end
  332. end
  333. if teleportee and p then
  334. p = find_free_position_near(p)
  335. teleportee:setpos(p)
  336. return true, "Teleporting " .. teleportee_name
  337. .. " to " .. target_name
  338. .. " at " .. core.pos_to_string(p)
  339. end
  340. end
  341. return false, 'Invalid parameters ("' .. param
  342. .. '") or player not found (see /help teleport)'
  343. end,
  344. })
  345. core.register_chatcommand("set", {
  346. params = "[-n] <name> <value> | <name>",
  347. description = "set or read server configuration setting",
  348. privs = {server=true},
  349. func = function(name, param)
  350. local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)")
  351. if arg and arg == "-n" and setname and setvalue then
  352. core.setting_set(setname, setvalue)
  353. return true, setname .. " = " .. setvalue
  354. end
  355. local setname, setvalue = string.match(param, "([^ ]+) (.+)")
  356. if setname and setvalue then
  357. if not core.setting_get(setname) then
  358. return false, "Failed. Use '/set -n <name> <value>' to create a new setting."
  359. end
  360. core.setting_set(setname, setvalue)
  361. return true, setname .. " = " .. setvalue
  362. end
  363. local setname = string.match(param, "([^ ]+)")
  364. if setname then
  365. local setvalue = core.setting_get(setname)
  366. if not setvalue then
  367. setvalue = "<not set>"
  368. end
  369. return true, setname .. " = " .. setvalue
  370. end
  371. return false, "Invalid parameters (see /help set)."
  372. end,
  373. })
  374. core.register_chatcommand("mods", {
  375. params = "",
  376. description = "List mods installed on the server",
  377. privs = {},
  378. func = function(name, param)
  379. return true, table.concat(core.get_modnames(), ", ")
  380. end,
  381. })
  382. local function handle_give_command(cmd, giver, receiver, stackstring)
  383. core.log("action", giver .. " invoked " .. cmd
  384. .. ', stackstring="' .. stackstring .. '"')
  385. local itemstack = ItemStack(stackstring)
  386. if itemstack:is_empty() then
  387. return false, "Cannot give an empty item"
  388. elseif not itemstack:is_known() then
  389. return false, "Cannot give an unknown item"
  390. end
  391. local receiverref = core.get_player_by_name(receiver)
  392. if receiverref == nil then
  393. return false, receiver .. " is not a known player"
  394. end
  395. local leftover = receiverref:get_inventory():add_item("main", itemstack)
  396. if leftover:is_empty() then
  397. partiality = ""
  398. elseif leftover:get_count() == itemstack:get_count() then
  399. partiality = "could not be "
  400. else
  401. partiality = "partially "
  402. end
  403. -- The actual item stack string may be different from what the "giver"
  404. -- entered (e.g. big numbers are always interpreted as 2^16-1).
  405. stackstring = itemstack:to_string()
  406. if giver == receiver then
  407. return true, ("%q %sadded to inventory.")
  408. :format(stackstring, partiality)
  409. else
  410. core.chat_send_player(receiver, ("%q %sadded to inventory.")
  411. :format(stackstring, partiality))
  412. return true, ("%q %sadded to %s's inventory.")
  413. :format(stackstring, partiality, receiver)
  414. end
  415. end
  416. core.register_chatcommand("give", {
  417. params = "<name> <ItemString>",
  418. description = "give item to player",
  419. privs = {give=true},
  420. func = function(name, param)
  421. local toname, itemstring = string.match(param, "^([^ ]+) +(.+)$")
  422. if not toname or not itemstring then
  423. return false, "Name and ItemString required"
  424. end
  425. return handle_give_command("/give", name, toname, itemstring)
  426. end,
  427. })
  428. core.register_chatcommand("giveme", {
  429. params = "<ItemString>",
  430. description = "give item to yourself",
  431. privs = {give=true},
  432. func = function(name, param)
  433. local itemstring = string.match(param, "(.+)$")
  434. if not itemstring then
  435. return false, "ItemString required"
  436. end
  437. return handle_give_command("/giveme", name, name, itemstring)
  438. end,
  439. })
  440. core.register_chatcommand("spawnentity", {
  441. params = "<EntityName>",
  442. description = "Spawn entity at your position",
  443. privs = {give=true, interact=true},
  444. func = function(name, param)
  445. local entityname = string.match(param, "(.+)$")
  446. if not entityname then
  447. return false, "EntityName required"
  448. end
  449. core.log("action", ("/spawnentity invoked, entityname=%q")
  450. :format(entityname))
  451. local player = core.get_player_by_name(name)
  452. if player == nil then
  453. core.log("error", "Unable to spawn entity, player is nil")
  454. return false, "Unable to spawn entity, player is nil"
  455. end
  456. local p = player:getpos()
  457. p.y = p.y + 1
  458. core.add_entity(p, entityname)
  459. return true, ("%q spawned."):format(entityname)
  460. end,
  461. })
  462. core.register_chatcommand("pulverize", {
  463. params = "",
  464. description = "Destroy item in hand",
  465. func = function(name, param)
  466. local player = core.get_player_by_name(name)
  467. if not player then
  468. core.log("error", "Unable to pulverize, no player.")
  469. return false, "Unable to pulverize, no player."
  470. end
  471. if player:get_wielded_item():is_empty() then
  472. return false, "Unable to pulverize, no item in hand."
  473. end
  474. player:set_wielded_item(nil)
  475. return true, "An item was pulverized."
  476. end,
  477. })
  478. -- Key = player name
  479. core.rollback_punch_callbacks = {}
  480. core.register_on_punchnode(function(pos, node, puncher)
  481. local name = puncher:get_player_name()
  482. if core.rollback_punch_callbacks[name] then
  483. core.rollback_punch_callbacks[name](pos, node, puncher)
  484. core.rollback_punch_callbacks[name] = nil
  485. end
  486. end)
  487. core.register_chatcommand("rollback_check", {
  488. params = "[<range>] [<seconds>] [limit]",
  489. description = "Check who has last touched a node or near it,"
  490. .. " max. <seconds> ago (default range=0,"
  491. .. " seconds=86400=24h, limit=5)",
  492. privs = {rollback=true},
  493. func = function(name, param)
  494. local range, seconds, limit =
  495. param:match("(%d+) *(%d*) *(%d*)")
  496. range = tonumber(range) or 0
  497. seconds = tonumber(seconds) or 86400
  498. limit = tonumber(limit) or 5
  499. if limit > 100 then
  500. return false, "That limit is too high!"
  501. end
  502. core.rollback_punch_callbacks[name] = function(pos, node, puncher)
  503. local name = puncher:get_player_name()
  504. core.chat_send_player(name, "Checking " .. core.pos_to_string(pos) .. "...")
  505. local actions = core.rollback_get_node_actions(pos, range, seconds, limit)
  506. local num_actions = #actions
  507. if num_actions == 0 then
  508. core.chat_send_player(name, "Nobody has touched"
  509. .. " the specified location in "
  510. .. seconds .. " seconds")
  511. return
  512. end
  513. local time = os.time()
  514. for i = num_actions, 1, -1 do
  515. local action = actions[i]
  516. core.chat_send_player(name,
  517. ("%s %s %s -> %s %d seconds ago.")
  518. :format(
  519. core.pos_to_string(action.pos),
  520. action.actor,
  521. action.oldnode.name,
  522. action.newnode.name,
  523. time - action.time))
  524. end
  525. end
  526. return true, "Punch a node (range=" .. range .. ", seconds="
  527. .. seconds .. "s, limit=" .. limit .. ")"
  528. end,
  529. })
  530. core.register_chatcommand("rollback", {
  531. params = "<player name> [<seconds>] | :<actor> [<seconds>]",
  532. description = "revert actions of a player; default for <seconds> is 60",
  533. privs = {rollback=true},
  534. func = function(name, param)
  535. local target_name, seconds = string.match(param, ":([^ ]+) *(%d*)")
  536. if not target_name then
  537. local player_name = nil
  538. player_name, seconds = string.match(param, "([^ ]+) *(%d*)")
  539. if not player_name then
  540. return false, "Invalid parameters. See /help rollback"
  541. .. " and /help rollback_check."
  542. end
  543. target_name = "player:"..player_name
  544. end
  545. seconds = tonumber(seconds) or 60
  546. core.chat_send_player(name, "Reverting actions of "
  547. .. target_name .. " since "
  548. .. seconds .. " seconds.")
  549. local success, log = core.rollback_revert_actions_by(
  550. target_name, seconds)
  551. local response = ""
  552. if #log > 100 then
  553. response = "(log is too long to show)\n"
  554. else
  555. for _, line in pairs(log) do
  556. response = response .. line .. "\n"
  557. end
  558. end
  559. response = response .. "Reverting actions "
  560. .. (success and "succeeded." or "FAILED.")
  561. return success, response
  562. end,
  563. })
  564. core.register_chatcommand("status", {
  565. description = "Print server status",
  566. func = function(name, param)
  567. return true, core.get_server_status()
  568. end,
  569. })
  570. core.register_chatcommand("time", {
  571. params = "<0...24000>",
  572. description = "set time of day",
  573. privs = {settime=true},
  574. func = function(name, param)
  575. if param == "" then
  576. return false, "Missing time."
  577. end
  578. local newtime = tonumber(param)
  579. if newtime == nil then
  580. return false, "Invalid time."
  581. end
  582. core.set_timeofday((newtime % 24000) / 24000)
  583. core.log("action", name .. " sets time " .. newtime)
  584. return true, "Time of day changed."
  585. end,
  586. })
  587. core.register_chatcommand("shutdown", {
  588. description = "shutdown server",
  589. privs = {server=true},
  590. func = function(name, param)
  591. core.log("action", name .. " shuts down server")
  592. core.request_shutdown()
  593. core.chat_send_all("*** Server shutting down (operator request).")
  594. end,
  595. })
  596. core.register_chatcommand("ban", {
  597. params = "<name>",
  598. description = "Ban IP of player",
  599. privs = {ban=true},
  600. func = function(name, param)
  601. if param == "" then
  602. return true, "Ban list: " .. core.get_ban_list()
  603. end
  604. if not core.get_player_by_name(param) then
  605. return false, "No such player."
  606. end
  607. if not core.ban_player(param) then
  608. return false, "Failed to ban player."
  609. end
  610. local desc = core.get_ban_description(param)
  611. core.log("action", name .. " bans " .. desc .. ".")
  612. return true, "Banned " .. desc .. "."
  613. end,
  614. })
  615. core.register_chatcommand("unban", {
  616. params = "<name/ip>",
  617. description = "remove IP ban",
  618. privs = {ban=true},
  619. func = function(name, param)
  620. if not core.unban_player_or_ip(param) then
  621. return false, "Failed to unban player/IP."
  622. end
  623. core.log("action", name .. " unbans " .. param)
  624. return true, "Unbanned " .. param
  625. end,
  626. })
  627. core.register_chatcommand("kick", {
  628. params = "<name> [reason]",
  629. description = "kick a player",
  630. privs = {kick=true},
  631. func = function(name, param)
  632. local tokick, reason = param:match("([^ ]+) (.+)")
  633. tokick = tokick or param
  634. if not core.kick_player(tokick, reason) then
  635. return false, "Failed to kick player " .. tokick
  636. end
  637. core.log("action", name .. " kicked " .. tokick)
  638. return true, "Kicked " .. tokick
  639. end,
  640. })
  641. core.register_chatcommand("clearobjects", {
  642. description = "clear all objects in world",
  643. privs = {server=true},
  644. func = function(name, param)
  645. core.log("action", name .. " clears all objects.")
  646. core.chat_send_all("Clearing all objects. This may take long."
  647. .. " You may experience a timeout. (by "
  648. .. name .. ")")
  649. core.clear_objects()
  650. core.log("action", "Object clearing done.")
  651. core.chat_send_all("*** Cleared all objects.")
  652. end,
  653. })
  654. core.register_chatcommand("msg", {
  655. params = "<name> <message>",
  656. description = "Send a private message",
  657. privs = {shout=true},
  658. func = function(name, param)
  659. local sendto, message = param:match("^(%S+)%s(.+)$")
  660. if not sendto then
  661. return false, "Invalid usage, see /help msg."
  662. end
  663. if not core.get_player_by_name(sendto) then
  664. return false, "The player " .. sendto
  665. .. " is not online."
  666. end
  667. core.log("action", "PM from " .. name .. " to " .. sendto
  668. .. ": " .. message)
  669. core.chat_send_player(sendto, "PM from " .. name .. ": "
  670. .. message)
  671. return true, "Message sent."
  672. end,
  673. })