adding chat-jail support

This commit is contained in:
SwissalpS 2020-02-11 06:14:09 +01:00
parent 21e8e9609e
commit cc77c3290c
9 changed files with 76 additions and 1 deletions

View File

@ -153,6 +153,9 @@ local join_channel = {
description = "Join channel named <Channel Name>. " .. description = "Join channel named <Channel Name>. " ..
"After joining you will see messages sent to that channel (in addition to the other channels you have joined)", "After joining you will see messages sent to that channel (in addition to the other channels you have joined)",
func = function(name, param) func = function(name, param)
if beerchat.is_player_jailed(name) then
return false, "You are in chat-jail, no joining channels for you."
end
if not param or param == "" then if not param or param == "" then
return false, "ERROR: Invalid number of arguments. Please supply the channel name as a minimum" return false, "ERROR: Invalid number of arguments. Please supply the channel name as a minimum"
end end
@ -201,6 +204,9 @@ local leave_channel = {
"When you leave the channel you can no longer send/ receive messages from that channel. " .. "When you leave the channel you can no longer send/ receive messages from that channel. " ..
"NOTE: You can also leave the main channel", "NOTE: You can also leave the main channel",
func = function(name, param) func = function(name, param)
if beerchat.is_player_jailed(name) then
return false, "You are in chat-jail, no leaving for you."
end
if not param or param == "" then if not param or param == "" then
return false, "ERROR: Invalid number of arguments. Please supply the channel name" return false, "ERROR: Invalid number of arguments. Please supply the channel name"
end end
@ -267,6 +273,9 @@ local invite_channel = {
if not minetest.get_player_by_name(player_name) then if not minetest.get_player_by_name(player_name) then
return false, "ERROR: "..player_name.." does not exist or is not online" return false, "ERROR: "..player_name.." does not exist or is not online"
else else
if beerchat.is_player_jailed(player_name) then
return false, player_name .. " is in chat-jail, no inviting."
end
if not beerchat.has_player_muted_player(player_name, name) then if not beerchat.has_player_muted_player(player_name, name) then
if beerchat.enable_sounds then if beerchat.enable_sounds then
minetest.sound_play(channel_invite_sound, { to_player = player_name, gain = beerchat.sounds_default_gain } ) minetest.sound_play(channel_invite_sound, { to_player = player_name, gain = beerchat.sounds_default_gain } )
@ -295,6 +304,9 @@ local mute_player = {
description = "Mute a player. After muting a player, you will no longer see chat messages of this user, " .. description = "Mute a player. After muting a player, you will no longer see chat messages of this user, " ..
"regardless of what channel his user sends messages to", "regardless of what channel his user sends messages to",
func = function(name, param) func = function(name, param)
if beerchat.is_player_jailed(name) then
return false, "You are in chat-jail, no muting for you."
end
if not param or param == "" then if not param or param == "" then
return false, "ERROR: Invalid number of arguments. Please supply the name of the user to mute" return false, "ERROR: Invalid number of arguments. Please supply the name of the user to mute"
end end
@ -396,6 +408,15 @@ beerchat.force_player_to_channel = function(name, param)
-- force default channel -- force default channel
beerchat.currentPlayerChannel[player_name] = channel_name beerchat.currentPlayerChannel[player_name] = channel_name
meta:set_string("beerchat:current_channel", channel_name) meta:set_string("beerchat:current_channel", channel_name)
-- going to/from jail?
if channel_name == beerchat.jail_channel_name then
meta:set_int("beerchat:jailed", 1)
beerchat.jail_list[name] = true
elseif beerchat.is_player_jailed(player_name) then
meta:set_int("beerchat:jailed", 0)
beerchat.jail_list[name] = nil
end
-- inform user -- inform user
minetest.chat_send_player(player_name, name .. " has set your default channel to " minetest.chat_send_player(player_name, name .. " has set your default channel to "

View File

@ -13,6 +13,9 @@ minetest.register_on_chat_message(function(name, message)
end end
if channel_name and msg then if channel_name and msg then
if beerchat.is_player_jailed(name) then
return false, "You are in chat-jail, no channels for you."
end
if not beerchat.channels[channel_name] then if not beerchat.channels[channel_name] then
minetest.chat_send_player(name, "Channel "..channel_name.." does not exist. Make sure the channel still ".. minetest.chat_send_player(name, "Channel "..channel_name.." does not exist. Make sure the channel still "..
"exists and you format its name properly, e.g. #channel message or #my channel: message") "exists and you format its name properly, e.g. #channel message or #my channel: message")
@ -36,6 +39,9 @@ minetest.register_on_chat_message(function(name, message)
else else
channel_name = string.match(message, "^#(.*)") channel_name = string.match(message, "^#(.*)")
if channel_name then if channel_name then
if beerchat.is_player_jailed(name) then
return false, "You are in chat-jail, no switching channels for you."
end
if not beerchat.channels[channel_name] then if not beerchat.channels[channel_name] then
minetest.chat_send_player(name, "Channel "..channel_name.." does not exist") minetest.chat_send_player(name, "Channel "..channel_name.." does not exist")
elseif not beerchat.is_player_subscribed_to_channel(name, channel_name) then elseif not beerchat.is_player_subscribed_to_channel(name, channel_name) then

View File

@ -9,6 +9,8 @@ beerchat = {
-- The main channel is the one you send messages to when no channel is specified -- The main channel is the one you send messages to when no channel is specified
main_channel_name = "main", main_channel_name = "main",
jail_channel_name = "wail",
-- The default color of channels when no color is specified -- The default color of channels when no color is specified
default_channel_color = "#ffffff", default_channel_color = "#ffffff",
@ -43,6 +45,7 @@ dofile(MP.."/common.lua")
dofile(MP.."/format_message.lua") dofile(MP.."/format_message.lua")
dofile(MP.."/hooks.lua") dofile(MP.."/hooks.lua")
dofile(MP.."/storage.lua") dofile(MP.."/storage.lua")
dofile(MP.."/jail.lua")
dofile(MP.."/session.lua") dofile(MP.."/session.lua")
dofile(MP.."/pm.lua") dofile(MP.."/pm.lua")
dofile(MP.."/hash.lua") dofile(MP.."/hash.lua")

5
jail.lua Normal file
View File

@ -0,0 +1,5 @@
beerchat.jail_list = {}
beerchat.is_player_jailed = function(name)
return true == beerchat.jail_list[name]
end

3
me.lua
View File

@ -6,6 +6,9 @@ local me_override = {
description = "Send message in the \"* player message\" format, e.g. /me eats pizza becomes |#".. description = "Send message in the \"* player message\" format, e.g. /me eats pizza becomes |#"..
beerchat.main_channel_name.."| * Player01 eats pizza", beerchat.main_channel_name.."| * Player01 eats pizza",
func = function(name, param) func = function(name, param)
if beerchat.is_player_jailed(name) then
return false, "You are in chat-jail, you may not use /me command."
end
local msg = param local msg = param
local channel_name = beerchat.main_channel_name local channel_name = beerchat.main_channel_name
if not beerchat.channels[channel_name] then if not beerchat.channels[channel_name] then

9
pm.lua
View File

@ -12,6 +12,9 @@ minetest.register_on_chat_message(function(name, message)
minetest.log("action", "CHAT " .. name .. ": " .. message) minetest.log("action", "CHAT " .. name .. ": " .. message)
local players, msg = string.match(message, "^@([^%s:]*)[%s:](.*)") local players, msg = string.match(message, "^@([^%s:]*)[%s:](.*)")
if players and msg then if players and msg then
if beerchat.is_player_jailed(name) then
return false, "You are in chat-jail, no @ messages for you."
end
if msg == "" then if msg == "" then
minetest.chat_send_player(name, "Please enter the private message you would like to send") minetest.chat_send_player(name, "Please enter the private message you would like to send")
else else
@ -68,6 +71,9 @@ minetest.register_on_chat_message(function(name, message)
-- Register the chat in the target persons last spoken to table -- Register the chat in the target persons last spoken to table
atchat_lastrecv[name] = players atchat_lastrecv[name] = players
if atleastonesent then if atleastonesent then
if beerchat.is_player_jailed(name) then
return false, "You are in chat-jail, no @ messages for you."
end
successplayers = successplayers:sub(1, -2) successplayers = successplayers:sub(1, -2)
if (successplayers ~= name) then if (successplayers ~= name) then
minetest.chat_send_player( minetest.chat_send_player(
@ -153,6 +159,9 @@ local msg_override = {
"for compatibility with the old chat command but with new style chat muting support ".. "for compatibility with the old chat command but with new style chat muting support "..
"(players will not receive your message if they muted you) and multiple (comma separated) player support", "(players will not receive your message if they muted you) and multiple (comma separated) player support",
func = function(name, param) func = function(name, param)
if beerchat.is_player_jailed(name) then
return false, "You are in chat-jail, no PMs for you."
end
minetest.log("action", "PM " .. name .. ": " .. param) minetest.log("action", "PM " .. name .. ": " .. param)
local players, msg = string.match(param, "^(.-) (.*)") local players, msg = string.match(param, "^(.-) (.*)")
if players and msg then if players and msg then

View File

@ -20,6 +20,15 @@ minetest.register_on_joinplayer(function(player)
else else
beerchat.currentPlayerChannel[name] = beerchat.main_channel_name beerchat.currentPlayerChannel[name] = beerchat.main_channel_name
end end
local jailed = meta:get_int("beerchat:jailed")
if jailed then
beerchat.jail_list[name] = true
beerchat.currentPlayerChannel[name] = beerchat.jail_channel_name
beerchat.playersChannels[name][beerchat.jail_channel_name] = "joined"
else
beerchat.jail_list[name] = nil
end
end) end)
@ -28,5 +37,6 @@ minetest.register_on_leaveplayer(function(player)
beerchat.playersChannels[name] = nil beerchat.playersChannels[name] = nil
atchat_lastrecv[name] = nil atchat_lastrecv[name] = nil
beerchat.currentPlayerChannel[name] = nil beerchat.currentPlayerChannel[name] = nil
beerchat.jail_list[name] = nil
end) end)

View File

@ -5,8 +5,23 @@ local main_channel_color = "#ffffff" -- The color in hex of the main channel
if beerchat.mod_storage:get_string("channels") == "" then if beerchat.mod_storage:get_string("channels") == "" then
minetest.log("action", "[beerchat] One off initializing mod storage") minetest.log("action", "[beerchat] One off initializing mod storage")
beerchat.channels[beerchat.main_channel_name] = { owner = main_channel_owner, color = main_channel_color } beerchat.channels[beerchat.main_channel_name] = {
owner = main_channel_owner,
color = main_channel_color
}
beerchat.channels[beerchat.jail_channel_name] = {
owner = main_channel_owner,
color = main_channel_color
}
beerchat.mod_storage:set_string("channels", minetest.write_json(beerchat.channels)) beerchat.mod_storage:set_string("channels", minetest.write_json(beerchat.channels))
end end
beerchat.channels = minetest.parse_json(beerchat.mod_storage:get_string("channels")) beerchat.channels = minetest.parse_json(beerchat.mod_storage:get_string("channels"))
beerchat.channels[beerchat.main_channel_name] = {
owner = main_channel_owner,
color = main_channel_color
}
beerchat.channels[beerchat.jail_channel_name] = {
owner = main_channel_owner,
color = main_channel_color
}

View File

@ -12,6 +12,9 @@ beerchat.whisper = function(name, message)
if dollar ~= "$" then if dollar ~= "$" then
return false return false
end end
if beerchat.is_player_jailed(name) then
return false, "You are in chat-jail, no whispering for you."
end
local radius = tonumber(sradius) local radius = tonumber(sradius)
if not radius then if not radius then
radius = whisper_default_range radius = whisper_default_range