Skip to content
This repository has been archived by the owner on Jun 7, 2019. It is now read-only.

Bug fix on bug fix ... throttling cast to int at the wrong place #4

Merged
merged 1 commit into from
Nov 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion POGOLib.Core/Net/RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ private Task<ByteString> SendRemoteProcedureCall(RequestEnvelope requestEnvelope
while (_rpcQueue.TryDequeue(out processRequestEnvelope))
{
// var diff = Math.Max(0, DateTime.Now.Millisecond - LastRpcRequest.Millisecond);
var diff = Math.Min((int)(DateTime.UtcNow - LastRpcRequest.ToUniversalTime()).TotalMilliseconds, Configuration.ThrottleDifference);
var diff = (int)Math.Min((DateTime.UtcNow - LastRpcRequest.ToUniversalTime()).TotalMilliseconds, Configuration.ThrottleDifference);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe

int diff = 0; 

diff = (int)Math.Min((DateTime.UtcNow - LastRpcRequest.ToUniversalTime()).TotalMilliseconds, Configuration.ThrottleDifference);
if (diff < 0) diff = 0;

idee only

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under normal conditions LastRpcRequest always comes before UtcNow => So the difference should always be greater than zero.
The problem here was that initial LastRpcRequest has a value of '01/01/0001' so the difference between the current date and LastRpcRequest was a big double value, and casting that number to a int resulted in a negative value.

if (diff < Configuration.ThrottleDifference)
{
var delay = Configuration.ThrottleDifference - diff + (int)(_session.Random.NextDouble() * 0);
Expand Down