diff options
author | ShadowNinja <shadowninja@minetest.net> | 2017-06-03 14:55:10 -0400 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2017-06-03 14:55:10 -0400 |
commit | caecdb681c428c1aab9c0f7eec2570c0460f995c (patch) | |
tree | e5115982ea59bbf2343ba9b35bc4a0cfbb56f407 /builtin/client | |
parent | 81d56b94919dceb7b2e51d70b21a7ca22f852bd5 (diff) | |
parent | 80dc961d24e1964e25d57039ddb2ba639f9f4d22 (diff) | |
download | minetest-caecdb681c428c1aab9c0f7eec2570c0460f995c.tar.gz minetest-caecdb681c428c1aab9c0f7eec2570c0460f995c.tar.bz2 minetest-caecdb681c428c1aab9c0f7eec2570c0460f995c.zip |
Merge 0.4.16 into stable-0.4
Diffstat (limited to 'builtin/client')
-rw-r--r-- | builtin/client/chatcommands.lua | 65 | ||||
-rw-r--r-- | builtin/client/init.lua | 23 | ||||
-rw-r--r-- | builtin/client/register.lua | 73 |
3 files changed, 161 insertions, 0 deletions
diff --git a/builtin/client/chatcommands.lua b/builtin/client/chatcommands.lua new file mode 100644 index 000000000..2b8cc4acd --- /dev/null +++ b/builtin/client/chatcommands.lua @@ -0,0 +1,65 @@ +-- Minetest: builtin/client/chatcommands.lua + + +core.register_on_sending_chat_messages(function(message) + if message:sub(1,2) == ".." then + return false + end + + local first_char = message:sub(1,1) + if first_char == "/" or first_char == "." then + core.display_chat_message(core.gettext("issued command: ") .. message) + end + + if first_char ~= "." then + return false + end + + local cmd, param = string.match(message, "^%.([^ ]+) *(.*)") + param = param or "" + + if not cmd then + core.display_chat_message(core.gettext("-!- Empty command")) + return true + end + + local cmd_def = core.registered_chatcommands[cmd] + if cmd_def then + core.set_last_run_mod(cmd_def.mod_origin) + local _, message = cmd_def.func(param) + if message then + core.display_chat_message(message) + end + else + core.display_chat_message(core.gettext("-!- Invalid command: ") .. cmd) + end + + return true +end) + +core.register_chatcommand("list_players", { + description = core.gettext("List online players"), + func = function(param) + local players = table.concat(core.get_player_names(), ", ") + core.display_chat_message(core.gettext("Online players: ") .. players) + end +}) + +core.register_chatcommand("disconnect", { + description = core.gettext("Exit to main menu"), + func = function(param) + core.disconnect() + end, +}) + +core.register_chatcommand("clear_chat_queue", { + description = core.gettext("Clear the out chat queue"), + func = function(param) + core.clear_out_chat_queue() + return true, core.gettext("The out chat queue is now empty") + end, +}) + +function core.run_server_chatcommand(cmd, param) + core.send_chat_message("/" .. cmd .. " " .. param) +end diff --git a/builtin/client/init.lua b/builtin/client/init.lua new file mode 100644 index 000000000..3ac34d845 --- /dev/null +++ b/builtin/client/init.lua @@ -0,0 +1,23 @@ +-- Minetest: builtin/client/init.lua +local scriptpath = core.get_builtin_path()..DIR_DELIM +local clientpath = scriptpath.."client"..DIR_DELIM +local commonpath = scriptpath.."common"..DIR_DELIM + +dofile(clientpath .. "register.lua") +dofile(commonpath .. "after.lua") +dofile(commonpath .. "chatcommands.lua") +dofile(clientpath .. "chatcommands.lua") +dofile(commonpath .. "vector.lua") + +core.register_on_death(function() + core.display_chat_message("You died.") + local formspec = "size[11,5.5]bgcolor[#320000b4;true]" .. + "label[4.85,1.35;" .. fgettext("You died.") .. "]button_exit[4,3;3,0.5;btn_respawn;".. fgettext("Respawn") .."]" + core.show_formspec("bultin:death", formspec) +end) + +core.register_on_formspec_input(function(formname, fields) + if formname == "bultin:death" then + core.send_respawn() + end +end) diff --git a/builtin/client/register.lua b/builtin/client/register.lua new file mode 100644 index 000000000..6b12ddec8 --- /dev/null +++ b/builtin/client/register.lua @@ -0,0 +1,73 @@ + +core.callback_origins = {} + +local getinfo = debug.getinfo +debug.getinfo = nil + +function core.run_callbacks(callbacks, mode, ...) + assert(type(callbacks) == "table") + local cb_len = #callbacks + if cb_len == 0 then + if mode == 2 or mode == 3 then + return true + elseif mode == 4 or mode == 5 then + return false + end + end + local ret + for i = 1, cb_len do + local cb_ret = callbacks[i](...) + + if mode == 0 and i == 1 or mode == 1 and i == cb_len then + ret = cb_ret + elseif mode == 2 then + if not cb_ret or i == 1 then + ret = cb_ret + end + elseif mode == 3 then + if cb_ret then + return cb_ret + end + ret = cb_ret + elseif mode == 4 then + if (cb_ret and not ret) or i == 1 then + ret = cb_ret + end + elseif mode == 5 and cb_ret then + return cb_ret + end + end + return ret +end + +-- +-- Callback registration +-- + +local function make_registration() + local t = {} + local registerfunc = function(func) + t[#t + 1] = func + core.callback_origins[func] = { + mod = core.get_current_modname() or "??", + name = getinfo(1, "n").name or "??" + } + --local origin = core.callback_origins[func] + --print(origin.name .. ": " .. origin.mod .. " registering cbk " .. tostring(func)) + end + return t, registerfunc +end + +core.registered_globalsteps, core.register_globalstep = make_registration() +core.registered_on_shutdown, core.register_on_shutdown = make_registration() +core.registered_on_connect, core.register_on_connect = make_registration() +core.registered_on_receiving_chat_messages, core.register_on_receiving_chat_messages = make_registration() +core.registered_on_sending_chat_messages, core.register_on_sending_chat_messages = make_registration() +core.registered_on_death, core.register_on_death = make_registration() +core.registered_on_hp_modification, core.register_on_hp_modification = make_registration() +core.registered_on_damage_taken, core.register_on_damage_taken = make_registration() +core.registered_on_formspec_input, core.register_on_formspec_input = make_registration() +core.registered_on_dignode, core.register_on_dignode = make_registration() +core.registered_on_punchnode, core.register_on_punchnode = make_registration() +core.registered_on_placenode, core.register_on_placenode = make_registration() +core.registered_on_item_use, core.register_on_item_use = make_registration() |