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
This commit is contained in:
NullBite 2022-03-23 22:13:43 -04:00
parent d006d88009
commit 0f16fc3579
Signed by: nullbite
GPG Key ID: 6C4D545385D4925A

View File

@ -521,7 +521,7 @@ function ping.syncState(tbl)
for k, v in pairs(tbl) do for k, v in pairs(tbl) do
local_state[k]=v local_state[k]=v
end end
PartsManager.refreshAll() rateLimit(1, PartsManager.refreshAll, "refreshAll")
end end
-- }}} -- }}}
@ -579,6 +579,12 @@ do
end end
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())) -- print(string.format('old_health=%03.2f, player.getHealth=%03.2f', old_health,player.getHealth()))
ping.oof(player.getHealth()) ping.oof(player.getHealth())
end end
if old_state.isUnderwater ~= player.isUnderwater() then syncState() end if old_state.isUnderwater ~= player.isUnderwater() then syncState() end
old_state.isUnderwater=player.isUnderwater() old_state.isUnderwater=player.isUnderwater()