Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CSM] Add client-sided chat commands (#5092)
- Loading branch information
Showing
9 changed files
with
100 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- Minetest: builtin/client/chatcommands.lua | ||
|
||
|
||
core.register_on_sending_chat_messages(function(message) | ||
if not (message:sub(1,1) == "/") then | ||
return false | ||
end | ||
|
||
core.display_chat_message("issued command: " .. message) | ||
|
||
local cmd, param = string.match(message, "^/([^ ]+) *(.*)") | ||
if not param then | ||
param = "" | ||
end | ||
|
||
local cmd_def = core.registered_chatcommands[cmd] | ||
|
||
if cmd_def then | ||
core.set_last_run_mod(cmd_def.mod_origin) | ||
local success, message = cmd_def.func(param) | ||
if message then | ||
core.display_chat_message(message) | ||
end | ||
return true | ||
end | ||
|
||
return false | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-- Minetest: builtin/common/chatcommands.lua | ||
|
||
core.registered_chatcommands = {} | ||
|
||
function core.register_chatcommand(cmd, def) | ||
def = def or {} | ||
def.params = def.params or "" | ||
def.description = def.description or "" | ||
def.privs = def.privs or {} | ||
def.mod_origin = core.get_current_modname() or "??" | ||
core.registered_chatcommands[cmd] = def | ||
end | ||
|
||
function core.unregister_chatcommand(name) | ||
if core.registered_chatcommands[name] then | ||
core.registered_chatcommands[name] = nil | ||
else | ||
core.log("warning", "Not unregistering chatcommand " ..name.. | ||
" because it doesn't exist.") | ||
end | ||
end | ||
|
||
function core.override_chatcommand(name, redefinition) | ||
local chatcommand = core.registered_chatcommands[name] | ||
assert(chatcommand, "Attempt to override non-existent chatcommand "..name) | ||
for k, v in pairs(redefinition) do | ||
rawset(chatcommand, k, v) | ||
end | ||
core.registered_chatcommands[name] = chatcommand | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters