From 9c8463d2e336d7dea1ce63095daaeb6d97e5ad23 Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Wed, 5 Apr 2023 14:43:07 +0200 Subject: [PATCH 01/15] add basic bed-chat --- mods/ITEMS/mcl_beds/functions.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 294dfc483..58df7c65d 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -202,7 +202,7 @@ local function lay_down(player, pos, bed_pos, state, skip) return true end -local function update_formspecs(finished, ges) +local function update_formspecs(finished, ges, singlular_player) --singlular_player isn't a boolean, just a player thats allowed to be nil here local ges = ges or #minetest.get_connected_players() local form_n = "size[12,5;true]" local all_in_bed = players_in_bed_setting() <= (player_in_bed * 100) / ges @@ -211,8 +211,17 @@ local function update_formspecs(finished, ges) local button_abort = "button_exit[4,3;4,0.75;leave;"..F(S("Abort sleep")).."]" local bg_presleep = "bgcolor[#00000080;true]" local bg_sleep = "bgcolor[#000000FF;true]" + local chatbox = "field[5,2;1,1;chatmessage;"..F(S("Chat:"))..";]" + local chatsubmit = "button[5,4;1,2;chatsubmit;"..F(S("send!")).."]" + + form_n = form_n .. chatbox .. chatsubmit --because these should be in the formspec in ANY case, they might as well be added here already if finished then + if singlular_player ~= nil then + minetest.close_formspec(singlular_player:get_player_name(),"mcl_beds_form") + return + end + for name,_ in pairs(mcl_beds.player) do minetest.close_formspec(name, "mcl_beds_form") end @@ -253,6 +262,11 @@ local function update_formspecs(finished, ges) form_n = form_n .. "label[0.5,1;"..F(text).."]" end + if singlular_player ~= nil then + minetest.show_formspec(singlular_player:get_player_name(),"mcl_beds_form",form_n) + return + end + for name,_ in pairs(mcl_beds.player) do minetest.show_formspec(name, "mcl_beds_form", form_n) end @@ -429,6 +443,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if formname ~= "mcl_beds_form" then return end + + if fields.chatsubmit and fields.chatmessage ~= "" then + minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), fields.chatmessage)) + update_formspecs(false,nil,player) + return --no need to check other conditions anymore + end + if fields.quit or fields.leave then lay_down(player, nil, nil, false) update_formspecs(false) From a026bbd3c4ce1e0d4247eeb1d2d812e85dd00d08 Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Wed, 5 Apr 2023 15:45:16 +0200 Subject: [PATCH 02/15] minor bed changes --- mods/ITEMS/mcl_beds/functions.lua | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 58df7c65d..8b64ffb42 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -202,7 +202,7 @@ local function lay_down(player, pos, bed_pos, state, skip) return true end -local function update_formspecs(finished, ges, singlular_player) --singlular_player isn't a boolean, just a player thats allowed to be nil here +local function update_formspecs(finished, ges) local ges = ges or #minetest.get_connected_players() local form_n = "size[12,5;true]" local all_in_bed = players_in_bed_setting() <= (player_in_bed * 100) / ges @@ -211,17 +211,12 @@ local function update_formspecs(finished, ges, singlular_player) --singlular_pla local button_abort = "button_exit[4,3;4,0.75;leave;"..F(S("Abort sleep")).."]" local bg_presleep = "bgcolor[#00000080;true]" local bg_sleep = "bgcolor[#000000FF;true]" - local chatbox = "field[5,2;1,1;chatmessage;"..F(S("Chat:"))..";]" - local chatsubmit = "button[5,4;1,2;chatsubmit;"..F(S("send!")).."]" + local chatbox = "field[1,4.5;9,1;chatmessage;"..F(S("Chat:"))..";]" + local chatsubmit = "button[10,3.75;1,2;chatsubmit;"..F(S("send!")).."]" form_n = form_n .. chatbox .. chatsubmit --because these should be in the formspec in ANY case, they might as well be added here already if finished then - if singlular_player ~= nil then - minetest.close_formspec(singlular_player:get_player_name(),"mcl_beds_form") - return - end - for name,_ in pairs(mcl_beds.player) do minetest.close_formspec(name, "mcl_beds_form") end @@ -262,11 +257,6 @@ local function update_formspecs(finished, ges, singlular_player) --singlular_pla form_n = form_n .. "label[0.5,1;"..F(text).."]" end - if singlular_player ~= nil then - minetest.show_formspec(singlular_player:get_player_name(),"mcl_beds_form",form_n) - return - end - for name,_ in pairs(mcl_beds.player) do minetest.show_formspec(name, "mcl_beds_form", form_n) end @@ -446,8 +436,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if fields.chatsubmit and fields.chatmessage ~= "" then minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), fields.chatmessage)) - update_formspecs(false,nil,player) - return --no need to check other conditions anymore end if fields.quit or fields.leave then From 645e20afa417888242a9bd143260293b5f1e6fbd Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Wed, 5 Apr 2023 15:45:48 +0200 Subject: [PATCH 03/15] translation updates --- mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr | 4 +++- mods/ITEMS/mcl_beds/locale/template.txt | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr b/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr index 7fe400b7f..79ed0ded9 100644 --- a/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr +++ b/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr @@ -40,4 +40,6 @@ You will fall asleep when all players are in bed.=Sie werden einschlafen, wenn a You will fall asleep when @1% of all players are in bed.=Sie werden einschlafen, wenn @1% der Spieler im Bett sind. You're in bed.=Sie sind im Bett. Allows you to sleep=Zum Einschafen -Respawn Anchor=Seelenanker \ No newline at end of file +Respawn Anchor=Seelenanker +Chat:=Chat: +send!=senden! \ No newline at end of file diff --git a/mods/ITEMS/mcl_beds/locale/template.txt b/mods/ITEMS/mcl_beds/locale/template.txt index 69c493880..4f6611149 100644 --- a/mods/ITEMS/mcl_beds/locale/template.txt +++ b/mods/ITEMS/mcl_beds/locale/template.txt @@ -41,3 +41,5 @@ You will fall asleep when @1% of all players are in bed.= You're in bed.= Allows you to sleep= Respawn Anchor= +Chat:= +send!= \ No newline at end of file From 786aaf7a6d902d93997885f5b923b21eeb188373 Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Fri, 7 Apr 2023 11:58:03 +0200 Subject: [PATCH 04/15] check for shout priv --- mods/ITEMS/mcl_beds/functions.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 8b64ffb42..9def86870 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -435,6 +435,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end if fields.chatsubmit and fields.chatmessage ~= "" then + if not minetest.check_player_privs(player,"shout") then + minetest.chat_send_player(player:get_player_name(),S("You are missing the 'shout' privilege! It's required in order to talk in chat...")) minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), fields.chatmessage)) end From 4b1cc017a9feb73d8c8bec260b9c4461e6a8711c Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Fri, 7 Apr 2023 11:58:27 +0200 Subject: [PATCH 05/15] fix syntax --- mods/ITEMS/mcl_beds/functions.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 9def86870..be60adec8 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -437,6 +437,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if fields.chatsubmit and fields.chatmessage ~= "" then if not minetest.check_player_privs(player,"shout") then minetest.chat_send_player(player:get_player_name(),S("You are missing the 'shout' privilege! It's required in order to talk in chat...")) + return + end minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), fields.chatmessage)) end From fca23ba47fb07a9e4e60fce275d66841d5eb0cb3 Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Fri, 7 Apr 2023 11:59:07 +0200 Subject: [PATCH 06/15] update traslation template --- mods/ITEMS/mcl_beds/locale/template.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_beds/locale/template.txt b/mods/ITEMS/mcl_beds/locale/template.txt index 4f6611149..f86a21642 100644 --- a/mods/ITEMS/mcl_beds/locale/template.txt +++ b/mods/ITEMS/mcl_beds/locale/template.txt @@ -42,4 +42,5 @@ You're in bed.= Allows you to sleep= Respawn Anchor= Chat:= -send!= \ No newline at end of file +send!= +You are missing the 'shout' privilege! It's required in order to talk in chat...= \ No newline at end of file From 2366969e00fe500b6c17955c7f6fccbb34198381 Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Fri, 7 Apr 2023 12:00:36 +0200 Subject: [PATCH 07/15] update german translation --- mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr b/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr index 79ed0ded9..183d07790 100644 --- a/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr +++ b/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr @@ -42,4 +42,5 @@ You're in bed.=Sie sind im Bett. Allows you to sleep=Zum Einschafen Respawn Anchor=Seelenanker Chat:=Chat: -send!=senden! \ No newline at end of file +send!=senden! +You are missing the 'shout' privilege! It's required in order to talk in chat...=Ihnen fehlt das 'shout' Privileg! Es wird benötigt, um im Chat reden zu können... \ No newline at end of file From a55cbaadd6bddc3a94fb48f85c074067c4761485 Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Sun, 9 Apr 2023 18:32:15 +0200 Subject: [PATCH 08/15] take 'chat_message_limit_per_10sec' into account --- mods/ITEMS/mcl_beds/functions.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index be60adec8..2bb460347 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -429,6 +429,24 @@ minetest.register_on_leaveplayer(function(player) update_formspecs(false, #players) end) + +local message_rate_limit = tonumber(minetest.settings:get("chat_message_limit_per_10sec")) or 8 --NEVER change this! if this was java, i would've declared it as final +local playermessagecounter = {} +--[[ + This table stores how many messages a player XY has sent (only while being in a bed) within 10 secs + It gets reset after 10 secs using a globalstep +]] + +local globalstep_timer = 0 +minetest.register_globalstep(function(dtime) + globalstep_timer = globalstep_timer + dtime + if globalstep_timer >= 10 then + globalstep_timer = 0 + playermessagecounter = {} + minetest.log("reset counter") + end +end) + minetest.register_on_player_receive_fields(function(player, formname, fields) if formname ~= "mcl_beds_form" then return @@ -439,6 +457,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.chat_send_player(player:get_player_name(),S("You are missing the 'shout' privilege! It's required in order to talk in chat...")) return end + + if playermessagecounter[player:get_player_name()] == nil then + playermessagecounter[player:get_player_name()] = 0 + end + + if playermessagecounter[player:get_player_name()] >= message_rate_limit then -- == should do as well + minetest.chat_send_player(player:get_player_name(),S("You exceeded the maximum number of messages per 10 seconds! " .. "(" .. tostring(message_rate_limit) .. ")")) + return + end + + playermessagecounter[player:get_player_name()] = playermessagecounter[player:get_player_name()] + 1 minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), fields.chatmessage)) end From 145be4c83045d1c9ce3dfe58496cc020f9f4b984 Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Sun, 9 Apr 2023 18:32:52 +0200 Subject: [PATCH 09/15] remove debug logging --- mods/ITEMS/mcl_beds/functions.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 2bb460347..33bdc0e27 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -443,7 +443,6 @@ minetest.register_globalstep(function(dtime) if globalstep_timer >= 10 then globalstep_timer = 0 playermessagecounter = {} - minetest.log("reset counter") end end) From 899d6196245f70c6843fbd463825bbff2f75b42a Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Sun, 9 Apr 2023 18:35:03 +0200 Subject: [PATCH 10/15] fix translator syntax --- mods/ITEMS/mcl_beds/functions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 33bdc0e27..8b63fa596 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -462,7 +462,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end if playermessagecounter[player:get_player_name()] >= message_rate_limit then -- == should do as well - minetest.chat_send_player(player:get_player_name(),S("You exceeded the maximum number of messages per 10 seconds! " .. "(" .. tostring(message_rate_limit) .. ")")) + minetest.chat_send_player(player:get_player_name(),S("You exceeded the maximum number of messages per 10 seconds! ") .. "(" .. tostring(message_rate_limit) .. ")") return end From d9ac803f5bcf6958f4889d111450c6276fdc496b Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Sun, 9 Apr 2023 18:37:02 +0200 Subject: [PATCH 11/15] update translations --- mods/ITEMS/mcl_beds/functions.lua | 2 +- mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr | 3 ++- mods/ITEMS/mcl_beds/locale/template.txt | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 8b63fa596..0bbf0eca8 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -462,7 +462,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end if playermessagecounter[player:get_player_name()] >= message_rate_limit then -- == should do as well - minetest.chat_send_player(player:get_player_name(),S("You exceeded the maximum number of messages per 10 seconds! ") .. "(" .. tostring(message_rate_limit) .. ")") + minetest.chat_send_player(player:get_player_name(),S("You exceeded the maximum number of messages per 10 seconds!") .. " (" .. tostring(message_rate_limit) .. ")") return end diff --git a/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr b/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr index 183d07790..e0d00f62a 100644 --- a/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr +++ b/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr @@ -43,4 +43,5 @@ Allows you to sleep=Zum Einschafen Respawn Anchor=Seelenanker Chat:=Chat: send!=senden! -You are missing the 'shout' privilege! It's required in order to talk in chat...=Ihnen fehlt das 'shout' Privileg! Es wird benötigt, um im Chat reden zu können... \ No newline at end of file +You are missing the 'shout' privilege! It's required in order to talk in chat...=Ihnen fehlt das 'shout' Privileg! Es wird benötigt, um im Chat reden zu können... +You exceeded the maximum number of messages per 10 seconds!=Sie haben die maximale Anzahl an Chatnachrichten pro 10 Sekunden überschritten! \ No newline at end of file diff --git a/mods/ITEMS/mcl_beds/locale/template.txt b/mods/ITEMS/mcl_beds/locale/template.txt index f86a21642..a3b635675 100644 --- a/mods/ITEMS/mcl_beds/locale/template.txt +++ b/mods/ITEMS/mcl_beds/locale/template.txt @@ -43,4 +43,5 @@ Allows you to sleep= Respawn Anchor= Chat:= send!= -You are missing the 'shout' privilege! It's required in order to talk in chat...= \ No newline at end of file +You are missing the 'shout' privilege! It's required in order to talk in chat...= +You exceeded the maximum number of messages per 10 seconds!= \ No newline at end of file From 75595115a038c932ce806ef5298c084a69f16922 Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Sun, 9 Apr 2023 18:45:23 +0200 Subject: [PATCH 12/15] move rate checks to seperate function --- mods/ITEMS/mcl_beds/functions.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 0bbf0eca8..cb3e8ff0a 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -446,6 +446,17 @@ minetest.register_globalstep(function(dtime) end end) +local function exceeded_rate_limit(playername) --Note: will also take care of increasing value + if playermessagecounter[playername] == nil then + playermessagecounter[playername] = 0 + end + if playermessagecounter[playername] >= message_rate_limit then -- == should do as well + return true + end + playermessagecounter[playername] = playermessagecounter[playername] + 1 + return false +end + minetest.register_on_player_receive_fields(function(player, formname, fields) if formname ~= "mcl_beds_form" then return @@ -457,16 +468,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) return end - if playermessagecounter[player:get_player_name()] == nil then - playermessagecounter[player:get_player_name()] = 0 - end - - if playermessagecounter[player:get_player_name()] >= message_rate_limit then -- == should do as well + if exceeded_rate_limit(player:get_player_name()) then minetest.chat_send_player(player:get_player_name(),S("You exceeded the maximum number of messages per 10 seconds!") .. " (" .. tostring(message_rate_limit) .. ")") return end - playermessagecounter[player:get_player_name()] = playermessagecounter[player:get_player_name()] + 1 minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), fields.chatmessage)) end From 62c014363de79c8c937b47a28c98dcb27327458a Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Sun, 9 Apr 2023 18:50:34 +0200 Subject: [PATCH 13/15] 'fix' multiline comment --- mods/ITEMS/mcl_beds/functions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index cb3e8ff0a..ea77d9571 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -435,7 +435,7 @@ local playermessagecounter = {} --[[ This table stores how many messages a player XY has sent (only while being in a bed) within 10 secs It gets reset after 10 secs using a globalstep -]] +--]] local globalstep_timer = 0 minetest.register_globalstep(function(dtime) From bf9989beb91a01b3a4ffb4f4c0d917c1bd9554b1 Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Sun, 9 Apr 2023 19:51:55 +0200 Subject: [PATCH 14/15] add default message button --- mods/ITEMS/mcl_beds/functions.lua | 38 ++++++++++++++--------- mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr | 3 +- mods/ITEMS/mcl_beds/locale/template.txt | 3 +- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index ea77d9571..56e4a232b 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -211,8 +211,9 @@ local function update_formspecs(finished, ges) local button_abort = "button_exit[4,3;4,0.75;leave;"..F(S("Abort sleep")).."]" local bg_presleep = "bgcolor[#00000080;true]" local bg_sleep = "bgcolor[#000000FF;true]" - local chatbox = "field[1,4.5;9,1;chatmessage;"..F(S("Chat:"))..";]" - local chatsubmit = "button[10,3.75;1,2;chatsubmit;"..F(S("send!")).."]" + local chatbox = "field[0.2,4.5;9,1;chatmessage;"..F(S("Chat:"))..";]" + local chatsubmit = "button[9.2,3.75;1,2;chatsubmit;"..F(S("send!")).."]" + local defaultmessagebutton = "button[10.2,3.75;1,2;defaultmessage;zzZzzZ]" form_n = form_n .. chatbox .. chatsubmit --because these should be in the formspec in ANY case, they might as well be added here already @@ -241,6 +242,7 @@ local function update_formspecs(finished, ges) text = text .. "\n" .. comment form_n = form_n .. bg_presleep form_n = form_n .. button_leave + form_n = form_n .. defaultmessagebutton --Players should only be able to see that button when: -Skipping the night is possible -There aren't enoght players sleeping yet end form_n = form_n .. "label[0.5,1;"..F(text).."]" else @@ -429,7 +431,6 @@ minetest.register_on_leaveplayer(function(player) update_formspecs(false, #players) end) - local message_rate_limit = tonumber(minetest.settings:get("chat_message_limit_per_10sec")) or 8 --NEVER change this! if this was java, i would've declared it as final local playermessagecounter = {} --[[ @@ -446,16 +447,25 @@ minetest.register_globalstep(function(dtime) end end) -local function exceeded_rate_limit(playername) --Note: will also take care of increasing value +local function exceeded_rate_limit(playername) --Note: will also take care of increasing value and sending feedback message if needed if playermessagecounter[playername] == nil then playermessagecounter[playername] = 0 end if playermessagecounter[playername] >= message_rate_limit then -- == should do as well + minetest.chat_send_player(playername,S("You exceeded the maximum number of messages per 10 seconds!") .. " (" .. tostring(message_rate_limit) .. ")") return true end playermessagecounter[playername] = playermessagecounter[playername] + 1 return false -end +end + +local function shout_priv_check(player) + if not minetest.check_player_privs(player,"shout") then + minetest.chat_send_player(player:get_player_name(),S("You are missing the 'shout' privilege! It's required in order to talk in chat...")) + return false + end + return true +end minetest.register_on_player_receive_fields(function(player, formname, fields) if formname ~= "mcl_beds_form" then @@ -463,18 +473,18 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end if fields.chatsubmit and fields.chatmessage ~= "" then - if not minetest.check_player_privs(player,"shout") then - minetest.chat_send_player(player:get_player_name(),S("You are missing the 'shout' privilege! It's required in order to talk in chat...")) - return + if (not exceeded_rate_limit(player:get_player_name())) and shout_priv_check(player) then + minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), fields.chatmessage)) end + return + end - if exceeded_rate_limit(player:get_player_name()) then - minetest.chat_send_player(player:get_player_name(),S("You exceeded the maximum number of messages per 10 seconds!") .. " (" .. tostring(message_rate_limit) .. ")") - return + if fields.defaultmessage then + if (not exceeded_rate_limit(player:get_player_name())) and shout_priv_check(player) then + minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), S("Hey! Would you guys mind sleeping?"))) end - - minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), fields.chatmessage)) - end + return + end if fields.quit or fields.leave then lay_down(player, nil, nil, false) diff --git a/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr b/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr index e0d00f62a..ae035f3bb 100644 --- a/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr +++ b/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr @@ -44,4 +44,5 @@ Respawn Anchor=Seelenanker Chat:=Chat: send!=senden! You are missing the 'shout' privilege! It's required in order to talk in chat...=Ihnen fehlt das 'shout' Privileg! Es wird benötigt, um im Chat reden zu können... -You exceeded the maximum number of messages per 10 seconds!=Sie haben die maximale Anzahl an Chatnachrichten pro 10 Sekunden überschritten! \ No newline at end of file +You exceeded the maximum number of messages per 10 seconds!=Sie haben die maximale Anzahl an Chatnachrichten pro 10 Sekunden überschritten! +Hey! Would you guys mind sleeping?=Hey, würdet Ihr bitte zu Bett gehen? \ No newline at end of file diff --git a/mods/ITEMS/mcl_beds/locale/template.txt b/mods/ITEMS/mcl_beds/locale/template.txt index a3b635675..7d1f378c0 100644 --- a/mods/ITEMS/mcl_beds/locale/template.txt +++ b/mods/ITEMS/mcl_beds/locale/template.txt @@ -44,4 +44,5 @@ Respawn Anchor= Chat:= send!= You are missing the 'shout' privilege! It's required in order to talk in chat...= -You exceeded the maximum number of messages per 10 seconds!= \ No newline at end of file +You exceeded the maximum number of messages per 10 seconds!= +Hey! Would you guys mind sleeping? \ No newline at end of file From 0719d6038c17366c832a3ba04f9a2b3c49e13c14 Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Sun, 9 Apr 2023 19:53:28 +0200 Subject: [PATCH 15/15] add missing '=' to the translation template --- mods/ITEMS/mcl_beds/locale/template.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_beds/locale/template.txt b/mods/ITEMS/mcl_beds/locale/template.txt index 7d1f378c0..dd58d74e8 100644 --- a/mods/ITEMS/mcl_beds/locale/template.txt +++ b/mods/ITEMS/mcl_beds/locale/template.txt @@ -45,4 +45,4 @@ Chat:= send!= You are missing the 'shout' privilege! It's required in order to talk in chat...= You exceeded the maximum number of messages per 10 seconds!= -Hey! Would you guys mind sleeping? \ No newline at end of file +Hey! Would you guys mind sleeping?= \ No newline at end of file