mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 10:31:06 +01:00
move rate checks to seperate function
This commit is contained in:
parent
d9ac803f5b
commit
75595115a0
1 changed files with 12 additions and 6 deletions
|
@ -446,6 +446,17 @@ minetest.register_globalstep(function(dtime)
|
||||||
end
|
end
|
||||||
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)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
if formname ~= "mcl_beds_form" then
|
if formname ~= "mcl_beds_form" then
|
||||||
return
|
return
|
||||||
|
@ -457,16 +468,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if playermessagecounter[player:get_player_name()] == nil then
|
if exceeded_rate_limit(player:get_player_name()) 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) .. ")")
|
minetest.chat_send_player(player:get_player_name(),S("You exceeded the maximum number of messages per 10 seconds!") .. " (" .. tostring(message_rate_limit) .. ")")
|
||||||
return
|
return
|
||||||
end
|
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))
|
minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), fields.chatmessage))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue