From 0f16fc3579c2655ddd797d4c286a85619e0a46a0 Mon Sep 17 00:00:00 2001 From: NullBite Date: Wed, 23 Mar 2022 22:13:43 -0400 Subject: [PATCH] Add rate limiter and rate limit refreshAll refreshAll is a very instruction heavy call, it will easily overrun instruction limit on unstrusted clients if not controlled --- script.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/script.lua b/script.lua index 08c23c1..d24f543 100644 --- a/script.lua +++ b/script.lua @@ -521,7 +521,7 @@ function ping.syncState(tbl) for k, v in pairs(tbl) do local_state[k]=v end - PartsManager.refreshAll() + rateLimit(1, PartsManager.refreshAll, "refreshAll") end -- }}} @@ -579,6 +579,12 @@ do end end +function rateLimit(ticks, next, name) + if cooldown(ticks+1, name) then + namedWait(ticks, next, name) + end +end + -- }}} @@ -630,7 +636,6 @@ function tick() -- print(string.format('old_health=%03.2f, player.getHealth=%03.2f', old_health,player.getHealth())) ping.oof(player.getHealth()) end - if old_state.isUnderwater ~= player.isUnderwater() then syncState() end old_state.isUnderwater=player.isUnderwater()