Compare commits

...

5 Commits

Author SHA1 Message Date
TalkLounge f1019d13a6
Update settingtypes.txt 2022-02-15 18:32:22 +01:00
TalkLounge 3b6c354dd2
Update init.lua 2022-02-15 18:32:04 +01:00
TalkLounge e9287e844a
Merge pull request #1 from minenux/master-timeout-configurable
made configurable the timeout message
2022-02-15 18:28:59 +01:00
mckaygerhard abd1706571 made configurable the tomeout message 2022-02-14 21:06:26 -04:00
TalkLounge 3b4551c9e8
Fix RAM Overflow Crash 2020-06-12 21:03:20 +02:00
2 changed files with 11 additions and 12 deletions

View File

@ -2,6 +2,8 @@
-- =================
-- See README.md for licensing and other information.
local timeout_message = minetest.settings and tonumber(minetest.settings:get("adblock_timeout_message")) or 10
local adusers = {}
local function form()
@ -23,23 +25,20 @@ local function adcheck()
local pos = player:getpos()
local control = player:get_player_control()
local controlBit = player:get_player_control_bits()
if adusers[name] and vector.equals(adusers[name].pos, pos) and adusers[name].controlBit == controlBit and (control.up or control.down or control.right or control.left) and not isAttached(name) then
if adusers[name] and not adusers[name].active and vector.equals(adusers[name].pos, pos) and adusers[name].controlBit == controlBit and (control.up or control.down or control.right or control.left) and not isAttached(name) then
adusers[name].counter = (adusers[name].counter or 1) + 1
if adusers[name].counter >= 10 then
elseif adusers[name] and adusers[name].counter and adusers[name].counter >= timeout_message then
if not adusers[name].active or adusers[name].active == true then
adusers[name].active = true
end
elseif adusers[name] and adusers[name].active then
if adusers[name].active == true then
minetest.show_formspec(name, "adblock:main", form() .."button[1.35,3.5;1.2,0.1;adblock_main;Accept]")
else
if adusers[name].active >= 1 then
minetest.show_formspec(name, "adblock:main", form() .."label[0.5,3.5;You can close this message in ".. adusers[name].active .." seconds]")
adusers[name].active = adusers[name].active - 1
else
minetest.show_formspec(name, "adblock:main", form() .."button_exit[1.35,3.5;1.2,0.1;adblock_close;Close]")
end
adusers[name].active = adusers[name].active - 1
if adusers[name].active <= -1 then
adusers[name].active = nil
adusers[name].counter = nil
end
end
elseif adusers[name] then
@ -56,13 +55,12 @@ end
adcheck()
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "adblock:main" or not fields.adblock_main then
local name = player:get_player_name()
if formname ~= "adblock:main" or not fields.adblock_main or adusers[name].active ~= true then
return
end
local name = player:get_player_name()
minetest.log(string.format("AdBlock: %s seen an ad for %s seconds", name, adusers[name].counter))
adusers[name].active = 10
adusers[name].counter = nil
adusers[name].active = timeout_message
end)
minetest.register_on_leaveplayer(function(player)

1
settingtypes.txt Normal file
View File

@ -0,0 +1 @@
adblock_timeout_message (Timeout of the message [seconds]) string 10