Compare commits

...

10 Commits

Author SHA1 Message Date
AndrejIT
608ec5be85
Merge pull request #4 from Panquesito7/master
Compatibility with MT 5.0.0+
Small changes, looks like valid for compatibility with 5.0.0.
As i understand it breaks back compatibility with 4 version, ok, let it be, eventually it need to be done.
2019-12-16 22:31:27 +02:00
Panquesito7
2d91517677
Use mod.conf for dependencies and description 2019-12-08 13:38:21 -06:00
Panquesito7
3f30bf701c
Replace deprecated functions with newer ones 2019-11-29 15:39:29 -06:00
AndrejIT
9dab1fa9ad Improved compatibility with chat_anticurse, chat_antiflood and may-be other chat mods 2017-06-04 02:02:55 +03:00
AndrejIT
f9841a938e Merge pull request #1 from minetest-mods/sofar-patch-1
Add standard mod files.
Enforcing some standards to mods is good. And you even did some work for me, thanks!
2016-04-06 12:34:19 +03:00
Auke Kok
21c420de50 Add description.txt 2016-04-06 00:16:01 -07:00
Auke Kok
e1e6263193 Add mod.conf 2016-04-06 00:15:05 -07:00
AndrejIT
f01516617c Remove usage of lua bit operators 2015-07-21 21:52:06 +03:00
AndrejIT
99bbd3d19e Fixed correct code for space symbol(decimal 32, not 20) 2015-07-06 22:57:45 +03:00
AndrejIT
8274582d2a Correctly break utf8 strings and prefer breaking on space character 2015-07-06 21:49:06 +03:00
6 changed files with 105 additions and 62 deletions

0
LICENSE Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

View File

@ -1 +1,2 @@
chat_anticurse?
chat_anticurse?
chat_antiflood?

1
description.txt Normal file
View File

@ -0,0 +1 @@
Complements game built-in chat or replaces it.

160
init.lua Normal file → Executable file
View 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.
-- + Higlight some messages in different colors - nearby talk, PM messages, messages with your name in it, shouts(!)
-- + 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
--[[
Minetest 0.4.16+ mod: chat2
chat2 is mod for Minetest, created by Andrey. It's purpose is to improve or replace game built-in chat:
-- This mod is Free and Open Source Software, released under the LGPL 2.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.
+ Higlight some messages in different colors - nearby talk, PM messages, messages with your name in it, shouts(!)
+ 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.speedlimit = {}
@ -34,7 +37,7 @@ chat2.add_message = function(player, new_text, new_color)
minetest.log("action", "Player "..name.." - chat2 no hud yet error")
return
end
for id = firsthud, (firsthud + chat2.messages_on_screen - 1) do
hud = player:hud_get(id)
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 line2 = nil
local line3 = nil
line1 = string.sub(message, 1, chat2.chat_width)
if string.len(message) > chat2.chat_width then
line2 = " "..string.sub(message, chat2.chat_width, (chat2.chat_width * 2))
end
if string.len(message) > (chat2.chat_width * 2) then
line3 = " "..string.sub(message, (chat2.chat_width * 2), (chat2.chat_width * 3))
local symbols = ''
for i = 1, #message do
if
string.byte(message, i) == 32 and --is space symbol
string.len(symbols) > (chat2.chat_width - 8) and --space have priority for breaking lines
(
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
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
chat2.add_message(player, line2, color)
end
if line3 then
chat2.add_message(player, line3, color)
end
if message ~= '' then
chat2.lastmessagetimes[player:get_player_name()] = minetest.get_gametime()
end
@ -105,33 +156,24 @@ minetest.register_on_leaveplayer(function(player)
end)
minetest.register_on_chat_message(function(name, message)
local fmt = nil
local color = nil
local submes = nil
local player = minetest.get_player_by_name(name)
local players = minetest.get_connected_players()
if chat2.speedlimit[name]==nil then
chat2.speedlimit[name] = true
else
return
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, "^/(.+)")
if submes then
return
end
submes = string.match(message, "^!(.+)")
if submes then
fmt = "<%s> %s"
@ -139,23 +181,25 @@ minetest.register_on_chat_message(function(name, message)
minetest.log("action", "chat2 !:"..string.format(fmt, name, submes))
end
local senderpos = player:getpos()
local senderpos = player:get_pos()
for i = 1, #players do
local fmt_p = fmt
local color_p = color
local submes_p = submes
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"
color_p = 0x00FF00
submes_p = message
end
if not submes_p and chat2.users[name_p] and chat2.additionalfilters[name_p] then
local additionalfound = false
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
end
end
@ -167,25 +211,25 @@ minetest.register_on_chat_message(function(name, message)
end
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
fmt_p = "<%s> %s"
color_p = 0x88FFFF
submes_p = message
end
end
if not submes_p and chat2.users[name_p] == 2 then
fmt_p = "<%s> %s"
color_p = 0xFFFFFF
submes_p = message
end
if submes_p and chat2.users[name_p] then
chat2.send_message(players[i], string.format(fmt_p, name, submes_p), color_p)
end
end
return
end)
@ -193,27 +237,21 @@ if minetest.chatcommands["msg"] then
local old_command = minetest.chatcommands["msg"].func
minetest.chatcommands["msg"].func = function(name, param)
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 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 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(sender, string.format("<%s> %s", name, message), 0xF000F0)
minetest.log("action", "chat2 msg:"..string.format("<%s> %s", name, message))
end
end
return old_command(name, param)
return result, msg
end
end
@ -224,14 +262,14 @@ minetest.register_chatcommand("chat2", {
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then
return false, "chat2: Player not found"
return false, "chat2: Player not found."
end
if chat2.users[name] == nil and param and #param > 0 then
minetest.chat_send_player(name, 'First, please turn chat2 on.')
return
end
if param == "*" then
if chat2.users[name] == 1 then
chat2.users[name] = 2
@ -244,7 +282,7 @@ minetest.register_chatcommand("chat2", {
end
return
end
--user add additional search strings
if param and #param > 0 then
local parameters = {}
@ -263,7 +301,7 @@ minetest.register_chatcommand("chat2", {
end
return
end
if chat2.users[name] ~= nil then
for i = 1, chat2.messages_on_screen do
chat2.send_message(player, '', 0x000000)
@ -286,15 +324,15 @@ minetest.register_globalstep(function(dtime)
if timer >= 3 then
chat2.speedlimit = {}
timer = 0
--clean chat
local players = minetest.get_connected_players()
for i = 1, #players do
local name = players[i]:get_player_name()
if
chat2.lastmessagetimes[name] and
(minetest.get_gametime() - chat2.lastmessagetimes[name]) > 90
then
if
chat2.lastmessagetimes[name] and
(minetest.get_gametime() - chat2.lastmessagetimes[name]) > 90
then
chat2.send_message(players[i], '', 0x000000)
if (minetest.get_gametime() - chat2.lastmessagetimes[name]) > (90 + chat2.messages_on_screen * 3) then
chat2.lastmessagetimes[name] = nil
@ -302,4 +340,4 @@ minetest.register_globalstep(function(dtime)
end
end
end
end)
end)

3
mod.conf Executable file
View File

@ -0,0 +1,3 @@
name = chat2
optional_depends = chat_anticurse, chat_antiflood
description = Complements game built-in chat or replaces it.