123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- chat_colorize = chat_colorize or {}
- chat_colorize.player_just_died = chat_colorize.player_just_died or {}
- chat_colorize.modpath = minetest.get_modpath("chat_colorize")
- -- Localize for performance.
- local math_random = math.random
- -- Support for hot reloading.
- local mp = chat_colorize.modpath .. "/init.lua"
- local rn = "chat_colorize:core"
- if minetest.get_modpath("reload") then
- if not reload.file_registered(rn) then
- reload.register_file(rn, mp, false)
- end
- end
- mp = nil
- rn = nil
- function chat_colorize.notify_death(pname)
- if chat_colorize.player_just_died[pname] then
- return
- end
- chat_colorize.player_just_died[pname] = true
- minetest.after(math_random(30, 60), function()
- chat_colorize.player_just_died[pname] = nil
- end)
- end
- function chat_colorize.is_ragequit(pname)
- if chat_colorize.player_just_died[pname] then
- return true
- end
- end
- if not chat_colorize.gotten then
- chat_colorize.old_chat_send_player = minetest.chat_send_player
- chat_colorize.old_chat_send_all = minetest.chat_send_all
- chat_colorize.gotten = true
- end
- -- Using cyan color, at request of sorcerykid. This color is easy to see.
- chat_colorize.COLOR_CYAN = core.get_color_escape_sequence("#00e0ff")
- chat_colorize.COLOR_OLIVE = core.get_color_escape_sequence("#9a7122")
- chat_colorize.COLOR_YELLOW = core.get_color_escape_sequence("#ffff00")
- chat_colorize.COLOR_ORANGE = core.get_color_escape_sequence("#ffae00")
- chat_colorize.COLOR_GRAY = core.get_color_escape_sequence("#aaaaaaff")
- if not chat_colorize.registered then
- minetest.register_privilege("nojoinmsg", {
- description = "Player's join/leave messages will not be announced.",
- give_to_singleplayer = false,
- })
- end
- chat_colorize.send_player = function(name, message)
- local color = ""
- if string.sub(message, 1, 1) == "#" then
- color = chat_colorize.COLOR_OLIVE
- elseif string.find(message, "^%-!%- Invalid command") then
- message = "# Server: Invalid command. See '/help all' for a list of valid commands."
- easyvend.sound_error(name)
- color = chat_colorize.COLOR_OLIVE
- end
- return chat_colorize.old_chat_send_player(name, color .. message)
- end
- local should_suppress = function(msg)
- --if string.sub(msg, 1, 4) == "*** " then
- local strs = string.split(msg, " ")
- local name = strs[2]
- if type(name) == "string" and string.len(name) > 0 then
- local hide = minetest.check_player_privs(name, {nojoinmsg=true})
- if hide then return true end
- end
- --end
- end
- chat_colorize.should_suppress = function(pname)
- local hide = minetest.check_player_privs(pname, {nojoinmsg=true})
- if hide then return true end
- end
- local ragequit = {
- "Rage-quit",
- "Sneaked out",
- "Left in a huff",
- "Quit",
- "Couldn't take the heat",
- "Embarrassed",
- "Stormed out",
- "Stormed off",
- "Walked out",
- "Ugh",
- "This place stinks",
- "Gone home",
- "This server sucks, I'm going home",
- "Getting out",
- "Escaped",
- }
- chat_colorize.send_all = function(message)
- local color = ""
- local is_server_message = false
- if string.sub(message, 1, 1) == "#" then
- color = chat_colorize.COLOR_CYAN
- is_server_message = true
- --elseif string.sub(message, 1, 2) == "* " then
- -- color = chat_colorize.COLOR_ORANGE
- elseif string.sub(message, 1, 3) == "***" then
- -- Some players can have join/leave messages hidden.
- if should_suppress(message) then return end
-
- color = chat_colorize.COLOR_GRAY
- -- Add <> around player's name.
- message = string.gsub(message, "%*%*%* ([%w_%-]+) ", "*** <%1> ")
- -- Get player's internal name, so we can substitute their nick.
- local nick = string.match(message, "<([%w_%-]+)>")
- if nick then
- message = string.gsub(message, "<[%w_%-]+>", "<" .. rename.gpn(nick) .. ">")
- end
- -- Rewrite the timeout message.
- -- March 20, 2018: changed "timed out" to "connection broke" for better understanding.
- message = string.gsub(message, ". %(timed out%)$", ". (Broken connection.)")
- -- Check whether this is a player-leave-game message.
- local is_leaveplayer = message:find("left the game")
- if nick and is_leaveplayer and chat_colorize.is_ragequit(nick) then
- message = message .. " (" .. ragequit[math_random(1, #ragequit)] .. ".)"
- end
- if nick then
- chat_logging.report_leavejoin_player(nick, message)
- end
- end
-
- if is_server_message then
- chat_logging.log_server_message(message)
- end
- return chat_colorize.old_chat_send_all(color .. message)
- end
- if not chat_colorize.registered then
- minetest.chat_send_all = function(...) return chat_colorize.send_all(...) end
- minetest.chat_send_player = function(...) return chat_colorize.send_player(...) end
- chat_colorize.registered = true
- end
|