2551ddbf1d
This commit contains changes best credited to flyc0r <flyc0r@localhost.localdomain>, although the changes were separated out from waspsaliva's original initial commit rev. 0e9e1f352, which added the files from DFC work tree, and squashed in numerous additions by flyc0r and collaborators. That commit log: commit 0e9e1f3528c3d2fa1f1e9a79d4a00576be8552f5 Author: flyc0r <flyc0r@localhost.localdomain> Date: Sun Oct 4 03:37:08 2020 +0200 init This rebase had the effect of griefing the git history xD, so for example `git blame` of DFC and even upstream Minetest sources appear to be originally authored by `flyc0r` in that commit. To fix this, I will recommit only the changes onto the appropriate commit in DFC, and recreate the following git history (incl. merges). After this, the git history will be at least visually the same as the original Waspsaliva, even if commit sha1sums have changed. AFAICT, the closest commit from DFC was af085acbd. That commit was found simply by running `git diff wsc-master <some_DFC_rev>`, and locating the commit with the smallest number of differences. This commit was then created as follows: # Check out the DFC base commit git checkout af085acbd # Check out the *files* from WSC's initial commit git checkout 0e9e1f352 -- . # Make sure everything is added and commit the changes git add -A git commit
91 lines
2.3 KiB
Lua
91 lines
2.3 KiB
Lua
--
|
|
-- coras Chat hacks
|
|
-- * verify death messages
|
|
-- * log chat to stdout
|
|
|
|
cchat = {}
|
|
|
|
-- verify death
|
|
table.insert(minetest.registered_on_receiving_chat_message, 1, function(msg)
|
|
local d = msg:find('\1b@mcl_death_messages\1b') --mineclone specific
|
|
if d then
|
|
-- minetest.send_chat_message("real.") --uncomment to publish approval
|
|
minetest.display_chat_message("real.")
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
-- chat logging
|
|
local mod_name = minetest.get_current_modname()
|
|
|
|
local function log(level, message)
|
|
minetest.log(level, ('[%s] %s'):format(mod_name, message))
|
|
end
|
|
|
|
log('action', 'Chatlog loading...')
|
|
|
|
local LOG_LEVEL = 'action'
|
|
|
|
local server_info = minetest.get_server_info()
|
|
local server_id = server_info.address .. ':' .. server_info.port
|
|
local my_name = ''
|
|
|
|
local register_on_send = minetest.register_on_sending_chat_message or minetest.register_on_sending_chat_messages
|
|
local register_on_receive = minetest.register_on_receiving_chat_message or minetest.register_on_receiving_chat_messages
|
|
|
|
|
|
local function safe(func)
|
|
-- wrap a function w/ logic to avoid crashing the game
|
|
local f = function(...)
|
|
local status, out = pcall(func, ...)
|
|
if status then
|
|
return out
|
|
else
|
|
log('warning', 'Error (func): ' .. out)
|
|
return nil
|
|
end
|
|
end
|
|
return f
|
|
end
|
|
|
|
local set_my_name_tries = 0
|
|
local function set_my_name()
|
|
if minetest.localplayer then
|
|
my_name = minetest.localplayer:get_name()
|
|
elseif set_my_name_tries < 20 then
|
|
set_my_name_tries = set_my_name_tries + 1
|
|
minetest.after(1, set_my_name)
|
|
else
|
|
my_name = ''
|
|
end
|
|
end
|
|
|
|
|
|
if minetest.register_on_connect then
|
|
minetest.register_on_connect(set_my_name)
|
|
elseif minetest.register_on_mods_loaded then
|
|
minetest.register_on_mods_loaded(set_my_name)
|
|
else
|
|
minetest.after(1, set_my_name)
|
|
end
|
|
|
|
|
|
if register_on_send then
|
|
register_on_send(safe(function(message)
|
|
local msg = minetest.strip_colors(message)
|
|
if msg ~= '' then
|
|
log(LOG_LEVEL, ('%s@%s [sent] %s'):format(my_name, server_id, msg))
|
|
end
|
|
end))
|
|
end
|
|
|
|
if register_on_receive then
|
|
register_on_receive(safe(function(message)
|
|
local msg = minetest.strip_colors(message)
|
|
if msg ~= '' then
|
|
log(LOG_LEVEL, ('%s@%s %s'):format(my_name, server_id, msg))
|
|
end
|
|
end))
|
|
end
|