Compare commits
10 Commits
8c50c5bb50
...
608ec5be85
Author | SHA1 | Date | |
---|---|---|---|
|
608ec5be85 | ||
|
2d91517677 | ||
|
3f30bf701c | ||
|
9dab1fa9ad | ||
|
f9841a938e | ||
|
21c420de50 | ||
|
e1e6263193 | ||
|
f01516617c | ||
|
99bbd3d19e | ||
|
8274582d2a |
@ -1 +1,2 @@
|
|||||||
chat_anticurse?
|
chat_anticurse?
|
||||||
|
chat_antiflood?
|
1
description.txt
Normal file
1
description.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Complements game built-in chat or replaces it.
|
160
init.lua
Normal file → Executable file
160
init.lua
Normal file → Executable file
@ -1,13 +1,16 @@
|
|||||||
-- Minetest 0.4.12+ mod: chat2
|
--[[
|
||||||
-- chat2 is mod for minetest game created by Andrey. It's purpose is to improve or replace game built in chat.
|
Minetest 0.4.16+ mod: chat2
|
||||||
-- + Higlight some messages in different colors - nearby talk, PM messages, messages with your name in it, shouts(!)
|
chat2 is mod for Minetest, created by Andrey. It's purpose is to improve or replace game built-in chat:
|
||||||
-- + Also can show all regular chat messages (use "/chat2 *" command)
|
|
||||||
-- + Switch on/off (use "/chat2" command)
|
|
||||||
-- + Old messages dissapear after some time
|
|
||||||
-- - Problems with unicode symbols on some clients
|
|
||||||
|
|
||||||
-- This mod is Free and Open Source Software, released under the LGPL 2.1 or later.
|
+ Higlight some messages in different colors - nearby talk, PM messages, messages with your name in it, shouts(!)
|
||||||
-- I used this mod:https://github.com/vegasd/minetest-mods/blob/master/kmchat/init.lua as example for how to use hud api.
|
+ Also can show all regular chat messages (use "/chat2 *" command)
|
||||||
|
+ Switch on/off (use "/chat2" command)
|
||||||
|
+ Old messages dissapear after some time
|
||||||
|
- Problems with unicode symbols on some clients
|
||||||
|
|
||||||
|
This mod is Free and Open Source Software, released under the GNU LGPLv2.1 or later.
|
||||||
|
I used this mod:https://github.com/vegasd/minetest-mods/blob/master/kmchat/init.lua as example for how to use hud api.
|
||||||
|
--]]
|
||||||
|
|
||||||
chat2 = {}
|
chat2 = {}
|
||||||
chat2.speedlimit = {}
|
chat2.speedlimit = {}
|
||||||
@ -34,7 +37,7 @@ chat2.add_message = function(player, new_text, new_color)
|
|||||||
minetest.log("action", "Player "..name.." - chat2 no hud yet error")
|
minetest.log("action", "Player "..name.." - chat2 no hud yet error")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
for id = firsthud, (firsthud + chat2.messages_on_screen - 1) do
|
for id = firsthud, (firsthud + chat2.messages_on_screen - 1) do
|
||||||
hud = player:hud_get(id)
|
hud = player:hud_get(id)
|
||||||
if hud and hud.name == "chat2" then
|
if hud and hud.name == "chat2" then
|
||||||
@ -52,22 +55,70 @@ chat2.send_message = function(player, message, color)
|
|||||||
local line1 = nil --allow message to span at most to three lines. more is not ok for public chat.
|
local line1 = nil --allow message to span at most to three lines. more is not ok for public chat.
|
||||||
local line2 = nil
|
local line2 = nil
|
||||||
local line3 = nil
|
local line3 = nil
|
||||||
|
local symbols = ''
|
||||||
line1 = string.sub(message, 1, chat2.chat_width)
|
for i = 1, #message do
|
||||||
if string.len(message) > chat2.chat_width then
|
if
|
||||||
line2 = " "..string.sub(message, chat2.chat_width, (chat2.chat_width * 2))
|
string.byte(message, i) == 32 and --is space symbol
|
||||||
end
|
string.len(symbols) > (chat2.chat_width - 8) and --space have priority for breaking lines
|
||||||
if string.len(message) > (chat2.chat_width * 2) then
|
(
|
||||||
line3 = " "..string.sub(message, (chat2.chat_width * 2), (chat2.chat_width * 3))
|
not line1 or
|
||||||
|
not line2 or
|
||||||
|
not line3
|
||||||
|
)
|
||||||
|
then
|
||||||
|
if not line1 then
|
||||||
|
line1 = symbols
|
||||||
|
symbols = ''
|
||||||
|
elseif not line2 then
|
||||||
|
line2 = symbols
|
||||||
|
symbols = ''
|
||||||
|
elseif not line3 then
|
||||||
|
line3 = symbols
|
||||||
|
symbols = ''
|
||||||
|
end
|
||||||
|
elseif
|
||||||
|
(string.byte(message, i) < 128 or string.byte(message, i) >= 192) and --is ascii or first byte of unicode
|
||||||
|
string.len(symbols) > (chat2.chat_width - 1) and
|
||||||
|
(
|
||||||
|
not line1 or
|
||||||
|
not line2 or
|
||||||
|
not line3
|
||||||
|
)
|
||||||
|
then
|
||||||
|
if not line1 then
|
||||||
|
line1 = symbols
|
||||||
|
symbols = ''
|
||||||
|
elseif not line2 then
|
||||||
|
line2 = symbols
|
||||||
|
symbols = ''
|
||||||
|
elseif not line3 then
|
||||||
|
line3 = symbols
|
||||||
|
symbols = ''
|
||||||
|
end
|
||||||
|
elseif line1 and line2 and line3 then --stop when all three lines filled
|
||||||
|
break
|
||||||
|
end
|
||||||
|
symbols = symbols..message:sub(i,i)
|
||||||
end
|
end
|
||||||
|
|
||||||
chat2.add_message(player, line1, color)
|
if not line1 and symbols then --when message is shorten than line
|
||||||
|
line1 = symbols
|
||||||
|
elseif not line2 and symbols then --when message is shorten than line
|
||||||
|
line2 = symbols
|
||||||
|
elseif not line3 and symbols then --when message is shorten than line
|
||||||
|
line3 = symbols
|
||||||
|
end
|
||||||
|
|
||||||
|
if line1 then
|
||||||
|
chat2.add_message(player, line1, color)
|
||||||
|
end
|
||||||
if line2 then
|
if line2 then
|
||||||
chat2.add_message(player, line2, color)
|
chat2.add_message(player, line2, color)
|
||||||
end
|
end
|
||||||
if line3 then
|
if line3 then
|
||||||
chat2.add_message(player, line3, color)
|
chat2.add_message(player, line3, color)
|
||||||
end
|
end
|
||||||
|
|
||||||
if message ~= '' then
|
if message ~= '' then
|
||||||
chat2.lastmessagetimes[player:get_player_name()] = minetest.get_gametime()
|
chat2.lastmessagetimes[player:get_player_name()] = minetest.get_gametime()
|
||||||
end
|
end
|
||||||
@ -105,33 +156,24 @@ minetest.register_on_leaveplayer(function(player)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_chat_message(function(name, message)
|
minetest.register_on_chat_message(function(name, message)
|
||||||
|
|
||||||
local fmt = nil
|
local fmt = nil
|
||||||
local color = nil
|
local color = nil
|
||||||
local submes = nil
|
local submes = nil
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
|
|
||||||
if chat2.speedlimit[name]==nil then
|
if chat2.speedlimit[name]==nil then
|
||||||
chat2.speedlimit[name] = true
|
chat2.speedlimit[name] = true
|
||||||
else
|
else
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if chat_anticurse then
|
|
||||||
local uncensored = chat_anticurse.check_message(name, message)
|
|
||||||
if uncensored == 2 or uncensored > 2 then
|
|
||||||
return true
|
|
||||||
elseif uncensored == 1 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
submes = string.match(message, "^/(.+)")
|
submes = string.match(message, "^/(.+)")
|
||||||
if submes then
|
if submes then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
submes = string.match(message, "^!(.+)")
|
submes = string.match(message, "^!(.+)")
|
||||||
if submes then
|
if submes then
|
||||||
fmt = "<%s> %s"
|
fmt = "<%s> %s"
|
||||||
@ -139,23 +181,25 @@ minetest.register_on_chat_message(function(name, message)
|
|||||||
minetest.log("action", "chat2 !:"..string.format(fmt, name, submes))
|
minetest.log("action", "chat2 !:"..string.format(fmt, name, submes))
|
||||||
end
|
end
|
||||||
|
|
||||||
local senderpos = player:getpos()
|
local senderpos = player:get_pos()
|
||||||
for i = 1, #players do
|
for i = 1, #players do
|
||||||
local fmt_p = fmt
|
local fmt_p = fmt
|
||||||
local color_p = color
|
local color_p = color
|
||||||
local submes_p = submes
|
local submes_p = submes
|
||||||
local name_p = players[i]:get_player_name()
|
local name_p = players[i]:get_player_name()
|
||||||
|
|
||||||
if not submes_p and chat2.users[name_p] and string.find(message, name_p, 1, true) ~= nil then
|
--if not submes_p and chat2.users[name_p] and string.find(message, name_p, 1, true) ~= nil then
|
||||||
|
if not submes_p and chat2.users[name_p] and string.find( string.lower(message), string.lower(name_p), 1, true) ~= nil then
|
||||||
fmt_p = "<%s> %s"
|
fmt_p = "<%s> %s"
|
||||||
color_p = 0x00FF00
|
color_p = 0x00FF00
|
||||||
submes_p = message
|
submes_p = message
|
||||||
end
|
end
|
||||||
|
|
||||||
if not submes_p and chat2.users[name_p] and chat2.additionalfilters[name_p] then
|
if not submes_p and chat2.users[name_p] and chat2.additionalfilters[name_p] then
|
||||||
local additionalfound = false
|
local additionalfound = false
|
||||||
for n = 1, #chat2.additionalfilters[name_p] do
|
for n = 1, #chat2.additionalfilters[name_p] do
|
||||||
if additionalfound or name == chat2.additionalfilters[name_p][n] or string.find(message, chat2.additionalfilters[name_p][n], 1, true) ~= nil then
|
--if additionalfound or name == chat2.additionalfilters[name_p][n] or string.find(message, chat2.additionalfilters[name_p][n], 1, true) ~= nil then
|
||||||
|
if additionalfound or name == chat2.additionalfilters[name_p][n] or string.find( string.lower(message), string.lower(chat2.additionalfilters[name_p][n]), 1, true) ~= nil then
|
||||||
additionalfound = true
|
additionalfound = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -167,25 +211,25 @@ minetest.register_on_chat_message(function(name, message)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not submes_p and chat2.users[name_p] and name_p ~= name then
|
if not submes_p and chat2.users[name_p] and name_p ~= name then
|
||||||
recieverpos = players[i]:getpos()
|
recieverpos = players[i]:get_pos()
|
||||||
if vector.distance(senderpos, recieverpos) < 12 then
|
if vector.distance(senderpos, recieverpos) < 12 then
|
||||||
fmt_p = "<%s> %s"
|
fmt_p = "<%s> %s"
|
||||||
color_p = 0x88FFFF
|
color_p = 0x88FFFF
|
||||||
submes_p = message
|
submes_p = message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not submes_p and chat2.users[name_p] == 2 then
|
if not submes_p and chat2.users[name_p] == 2 then
|
||||||
fmt_p = "<%s> %s"
|
fmt_p = "<%s> %s"
|
||||||
color_p = 0xFFFFFF
|
color_p = 0xFFFFFF
|
||||||
submes_p = message
|
submes_p = message
|
||||||
end
|
end
|
||||||
|
|
||||||
if submes_p and chat2.users[name_p] then
|
if submes_p and chat2.users[name_p] then
|
||||||
chat2.send_message(players[i], string.format(fmt_p, name, submes_p), color_p)
|
chat2.send_message(players[i], string.format(fmt_p, name, submes_p), color_p)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return
|
return
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -193,27 +237,21 @@ if minetest.chatcommands["msg"] then
|
|||||||
local old_command = minetest.chatcommands["msg"].func
|
local old_command = minetest.chatcommands["msg"].func
|
||||||
minetest.chatcommands["msg"].func = function(name, param)
|
minetest.chatcommands["msg"].func = function(name, param)
|
||||||
local sendto, message = param:match("^(%S+)%s(.+)$")
|
local sendto, message = param:match("^(%S+)%s(.+)$")
|
||||||
|
|
||||||
|
-- Check if old /msg was succeful
|
||||||
|
local result, msg = old_command(name, param)
|
||||||
|
|
||||||
if sendto and message and chat2.users[sendto] then
|
if sendto and message and chat2.users[sendto] then
|
||||||
|
|
||||||
if chat_anticurse then
|
|
||||||
local uncensored = chat_anticurse.check_message(name, message)
|
|
||||||
if uncensored == 2 or uncensored > 2 then
|
|
||||||
return old_command(name, param)
|
|
||||||
elseif uncensored == 1 then
|
|
||||||
return old_command(name, param)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local player = minetest.get_player_by_name(sendto)
|
local player = minetest.get_player_by_name(sendto)
|
||||||
local sender = minetest.get_player_by_name(name)
|
local sender = minetest.get_player_by_name(name)
|
||||||
if player and sender then
|
if result and player and sender then
|
||||||
chat2.send_message(player, string.format("<%s> %s", name, message), 0xFF00FF)
|
chat2.send_message(player, string.format("<%s> %s", name, message), 0xFF00FF)
|
||||||
chat2.send_message(sender, string.format("<%s> %s", name, message), 0xF000F0)
|
chat2.send_message(sender, string.format("<%s> %s", name, message), 0xF000F0)
|
||||||
minetest.log("action", "chat2 msg:"..string.format("<%s> %s", name, message))
|
minetest.log("action", "chat2 msg:"..string.format("<%s> %s", name, message))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
return old_command(name, param)
|
return result, msg
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -224,14 +262,14 @@ minetest.register_chatcommand("chat2", {
|
|||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
if not player then
|
if not player then
|
||||||
return false, "chat2: Player not found"
|
return false, "chat2: Player not found."
|
||||||
end
|
end
|
||||||
|
|
||||||
if chat2.users[name] == nil and param and #param > 0 then
|
if chat2.users[name] == nil and param and #param > 0 then
|
||||||
minetest.chat_send_player(name, 'First, please turn chat2 on.')
|
minetest.chat_send_player(name, 'First, please turn chat2 on.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if param == "*" then
|
if param == "*" then
|
||||||
if chat2.users[name] == 1 then
|
if chat2.users[name] == 1 then
|
||||||
chat2.users[name] = 2
|
chat2.users[name] = 2
|
||||||
@ -244,7 +282,7 @@ minetest.register_chatcommand("chat2", {
|
|||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--user add additional search strings
|
--user add additional search strings
|
||||||
if param and #param > 0 then
|
if param and #param > 0 then
|
||||||
local parameters = {}
|
local parameters = {}
|
||||||
@ -263,7 +301,7 @@ minetest.register_chatcommand("chat2", {
|
|||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if chat2.users[name] ~= nil then
|
if chat2.users[name] ~= nil then
|
||||||
for i = 1, chat2.messages_on_screen do
|
for i = 1, chat2.messages_on_screen do
|
||||||
chat2.send_message(player, '', 0x000000)
|
chat2.send_message(player, '', 0x000000)
|
||||||
@ -286,15 +324,15 @@ minetest.register_globalstep(function(dtime)
|
|||||||
if timer >= 3 then
|
if timer >= 3 then
|
||||||
chat2.speedlimit = {}
|
chat2.speedlimit = {}
|
||||||
timer = 0
|
timer = 0
|
||||||
|
|
||||||
--clean chat
|
--clean chat
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
for i = 1, #players do
|
for i = 1, #players do
|
||||||
local name = players[i]:get_player_name()
|
local name = players[i]:get_player_name()
|
||||||
if
|
if
|
||||||
chat2.lastmessagetimes[name] and
|
chat2.lastmessagetimes[name] and
|
||||||
(minetest.get_gametime() - chat2.lastmessagetimes[name]) > 90
|
(minetest.get_gametime() - chat2.lastmessagetimes[name]) > 90
|
||||||
then
|
then
|
||||||
chat2.send_message(players[i], '', 0x000000)
|
chat2.send_message(players[i], '', 0x000000)
|
||||||
if (minetest.get_gametime() - chat2.lastmessagetimes[name]) > (90 + chat2.messages_on_screen * 3) then
|
if (minetest.get_gametime() - chat2.lastmessagetimes[name]) > (90 + chat2.messages_on_screen * 3) then
|
||||||
chat2.lastmessagetimes[name] = nil
|
chat2.lastmessagetimes[name] = nil
|
||||||
@ -302,4 +340,4 @@ minetest.register_globalstep(function(dtime)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user