Bugfixes and cloaking detection
Doesn't allow you to send a message while cloaked.
This commit is contained in:
parent
62e3096a9f
commit
3c29637838
44
init.lua
44
init.lua
|
@ -10,6 +10,7 @@ local storage = minetest.get_mod_storage()
|
||||||
local channels = {}
|
local channels = {}
|
||||||
local connected_players = {}
|
local connected_players = {}
|
||||||
local messages_sent = 0
|
local messages_sent = 0
|
||||||
|
local status_sent = 0
|
||||||
local buffer = ''
|
local buffer = ''
|
||||||
local msgprefix
|
local msgprefix
|
||||||
local localplayer = '[you]'
|
local localplayer = '[you]'
|
||||||
|
@ -66,6 +67,7 @@ local get_channel_users = function(c)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
elseif prefix == '@' then
|
elseif prefix == '@' then
|
||||||
|
if not connected_players[name] then return {} end
|
||||||
return {name}
|
return {name}
|
||||||
else
|
else
|
||||||
show_main_channel = true
|
show_main_channel = true
|
||||||
|
@ -114,9 +116,11 @@ minetest.register_on_sending_chat_messages(function(msg)
|
||||||
msg = ''
|
msg = ''
|
||||||
end
|
end
|
||||||
if c == main_channel then
|
if c == main_channel then
|
||||||
show_main_channel = true
|
if connected_players[localplayer] then
|
||||||
minetest.send_chat_message(msg)
|
show_main_channel = true
|
||||||
return true
|
minetest.send_chat_message(msg)
|
||||||
|
return true
|
||||||
|
end
|
||||||
elseif cmdprefix == '#' and not channels[c:sub(2)] then
|
elseif cmdprefix == '#' and not channels[c:sub(2)] then
|
||||||
minetest.display_chat_message('The channel ' .. c ..
|
minetest.display_chat_message('The channel ' .. c ..
|
||||||
' was not found.')
|
' was not found.')
|
||||||
|
@ -126,15 +130,18 @@ minetest.register_on_sending_chat_messages(function(msg)
|
||||||
if c == '@' then
|
if c == '@' then
|
||||||
minetest.display_chat_message('-!- <' .. localplayer .. '> ' .. msg)
|
minetest.display_chat_message('-!- <' .. localplayer .. '> ' .. msg)
|
||||||
return true
|
return true
|
||||||
|
elseif not connected_players[localplayer] then
|
||||||
|
minetest.display_chat_message('You cannot use chat while cloaked. '
|
||||||
|
.. 'Please use /uncloak if you want to use chat.')
|
||||||
|
minetest.run_server_chatcommand('status', '')
|
||||||
|
status_sent = status_sent + 1
|
||||||
|
return true
|
||||||
elseif c == '@[off]' then
|
elseif c == '@[off]' then
|
||||||
minetest.send_chat_message('[off] ' .. msg)
|
minetest.send_chat_message('[off] ' .. msg)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local players = get_channel_users(c)
|
local players = get_channel_users(c)
|
||||||
if not players then return end
|
if not players then return end
|
||||||
if #buffer > 0 then buffer = buffer .. '\n' end
|
|
||||||
buffer = buffer .. '-' .. c .. '- <' .. localplayer .. '> ' .. msg
|
|
||||||
messages_sent = messages_sent + #players
|
|
||||||
for p = 1, #players do
|
for p = 1, #players do
|
||||||
if connected_players[players[p]] then
|
if connected_players[players[p]] then
|
||||||
messages_sent = messages_sent + 1
|
messages_sent = messages_sent + 1
|
||||||
|
@ -142,6 +149,15 @@ minetest.register_on_sending_chat_messages(function(msg)
|
||||||
'- ' .. msg)
|
'- ' .. msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if messages_sent > 0 then
|
||||||
|
if #buffer > 0 then buffer = buffer .. '\n' end
|
||||||
|
buffer = buffer .. '-' .. c .. '- <' .. localplayer .. '> ' .. msg
|
||||||
|
else
|
||||||
|
if channel == c then channel = '@' end
|
||||||
|
minetest.display_chat_message('The channel ' .. c ..
|
||||||
|
' is empty.')
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -217,6 +233,10 @@ minetest.register_on_receiving_chat_messages(function(msg)
|
||||||
connected_players[player] = true
|
connected_players[player] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if status_sent > 0 then
|
||||||
|
status_sent = status_sent - 1
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -352,9 +372,11 @@ minetest.register_chatcommand('who', {
|
||||||
c = c:sub(2)
|
c = c:sub(2)
|
||||||
local players
|
local players
|
||||||
if c == main_channel:sub(2) then
|
if c == main_channel:sub(2) then
|
||||||
players = {}
|
players = {localplayer}
|
||||||
for player, _ in pairs(connected_players) do
|
for player, _ in pairs(connected_players) do
|
||||||
table.insert(players, player)
|
if player ~= localplayer and _ then
|
||||||
|
table.insert(players, player)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
elseif channels[c] then
|
elseif channels[c] then
|
||||||
local u = table.unpack or unpack
|
local u = table.unpack or unpack
|
||||||
|
@ -373,9 +395,11 @@ minetest.register_chatcommand('who', {
|
||||||
-- visible to the client.
|
-- visible to the client.
|
||||||
minetest.override_chatcommand('list_players', {
|
minetest.override_chatcommand('list_players', {
|
||||||
func = function()
|
func = function()
|
||||||
local p = {}
|
local p = {localplayer}
|
||||||
for player, _ in pairs(connected_players) do
|
for player, _ in pairs(connected_players) do
|
||||||
table.insert(p, player)
|
if player ~= localplayer and _ then
|
||||||
|
table.insert(p, player)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
table.sort(p)
|
table.sort(p)
|
||||||
return true, "Online players: " .. table.concat(p, ', ')
|
return true, "Online players: " .. table.concat(p, ', ')
|
||||||
|
|
Loading…
Reference in New Issue