Skip to content

Commit

Permalink
Fixes from turborilla
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmightyMikkel committed Jun 19, 2024
1 parent 7bc202c commit 5a7c534
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
17 changes: 13 additions & 4 deletions Runtime/Client/LootLockerServerApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,18 @@ IEnumerator coroutine()
text = webRequest.downloadHandler.text
};

response.errorData = LootLockerJson.DeserializeObject<LootLockerErrorData>(webRequest.downloadHandler.text);

try
{
response.errorData = LootLockerJson.DeserializeObject<LootLockerErrorData>(webRequest.downloadHandler.text);
}
catch (Exception)
{
if (webRequest.downloadHandler.text.StartsWith("<"))
{
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Warning)("JSON Starts with <, info: \n statusCode: " + response.statusCode + "\n body: " + response.text);
}
response.errorData = null;
}
// Error data was not parseable, populate with what we know
if (response.errorData == null)
{
Expand Down Expand Up @@ -332,7 +342,7 @@ private void RefreshTokenAndCompleteCall(LootLockerServerRequest cachedRequest,
private static bool ShouldRefreshUsingRefreshToken(LootLockerServerRequest cachedRequest)
{
// The failed request isn't a refresh session request but we have a refresh token stored, so try to refresh the session automatically before failing
return !cachedRequest.jsonPayload.Contains("refresh_token") && !string.IsNullOrEmpty(LootLockerConfig.current.refreshToken);
return (string.IsNullOrEmpty(cachedRequest.jsonPayload) || !cachedRequest.jsonPayload.Contains("refresh_token")) && !string.IsNullOrEmpty(LootLockerConfig.current.refreshToken);
}

private void CompleteCall(LootLockerServerRequest cachedRequest, LootLockerSessionResponse sessionRefreshResponse, Action<LootLockerResponse> onComplete)
Expand Down Expand Up @@ -480,4 +490,3 @@ private string GetQueryStringFromDictionary(Dictionary<string, string> queryDict
#endregion
}
}

12 changes: 11 additions & 1 deletion Runtime/Client/LootLockerServerRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ public class LootLockerResponse
return new T() { success = false, errorData = serverResponse.errorData, statusCode = serverResponse.statusCode, text = serverResponse.text };
}

/*
* Turborilla:
* Patched based on conversation with LootLocker. I suspect that some users are getting login pages for wifi or something else instead of the intended response from LootLocker servers.
* We have similar checks in our other projects.
*/
if (serverResponse.text.StartsWith("<"))
{
LootLockerLogger.GetForLogLevel()("JSON Starts with <, info: \n statusCode: " + serverResponse.statusCode + "\n body: " + serverResponse.text);
return new T() { success = false, errorData = serverResponse.errorData, statusCode = serverResponse.statusCode };
}
var response = LootLockerJson.DeserializeObject<T>(serverResponse.text, options ?? LootLockerJsonSettings.Default) ?? new T();

response.text = serverResponse.text;
Expand Down Expand Up @@ -708,4 +718,4 @@ public void Send(System.Action<LootLockerResponse> OnServerResponse)
LootLockerServerApi.SendRequest(this, (response) => { OnServerResponse?.Invoke(response); });
}
}
}
}
2 changes: 1 addition & 1 deletion Runtime/Game/LootLockerObfuscator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@ public static string ObfuscateJsonStringForLogging(string json)
#endif //LOOTLOCKER_USE_NEWTONSOFTJSON
}
}
}
}

0 comments on commit 5a7c534

Please sign in to comment.