Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Rate limit does not work properly and allows players to exceed request limit. #44

Open
Mal0n1 opened this issue Jan 16, 2024 · 0 comments

Comments

@Mal0n1
Copy link

Mal0n1 commented Jan 16, 2024

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)
end

Here 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
image
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.
image

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant