-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Title says it all. Currently if you are using the RateLimit function for BridgeNet2, it will block a few requests but will not adhere to your desired Invokes per second.
Here is the solution I made that fixed the issue. Replace the code at line 77 in the serverBridgePrototype connect method.
if self.RateLimitActive then
if self._rateMap[player] == nil then
self._rateMap[player] = 0
end
if self._rateMap[player] >= self._maxRate then
if not self._overflowFunction(player) then
return
end
end
self._rateMap[player] += 1
task.delay(1, function()
local currentCount: number = self._rateMap[player]
self._rateMap[player] = math.min(0, currentCount - 1)
end)
endHere is proof of the issue. This is my current setup, if a request goes through it will print "Passed rate limit". If a request is caught then it will print "Hit ratelimit"
Network.ToggleTroop:Connect(function(Player, TroopID)
print("Passed rate limit")
assert(typeof(TroopID) == "string", `TroopID must be a string when attempting to equip`)
local IsEquipped, Index = IsTroopEquipped(Player, TroopID)
if IsEquipped and Index then
Towers:UnEquipTower(Player, TroopID, Index)
else
Towers:EquipTower(Player, TroopID)
end
end)
Network.ToggleTroop:RateLimit(1, function()
print("Hit ratelimit")
end)Here is a screenshot from the console when I'm spamming requests

As you can see by the timestamps there are streaks where all requests are blocked and streaks where they pass through.
Here is a screenshot with my solution and we can see that only 1 request is allowed every second.

I personally have little to no experience with github and have no idea how to make a commit so I thought I would raise this issue and the solution.