Skip to content

Commit 06ed453

Browse files
committed
Improved data structure, added leaderboards api, simplified response structure
1 parent 84c32eb commit 06ed453

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+892
-1165
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

Runtime/Common/LootLockerBaseServerAPI.cs renamed to Runtime/Client/LootLockerBaseServerAPI.cs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public static void Init(LootLockerBaseServerAPI childType)
2626
}
2727

2828
protected Func<IEnumerator, System.Object> StartCoroutine;
29-
29+
int maxRetry = 3;
30+
int tries = 0;
3031
/// <summary>
3132
/// This would be something like "www.mydomain.com" or "api.mydomain.com". But you could also directly supply the IPv4 address of the server to speed the calls up a little bit by bypassing DNS Lookup
3233
/// </summary>
@@ -93,20 +94,18 @@ IEnumerator coroutine()
9394

9495
try
9596
{
96-
#if UNITY_EDITOR
9797
LootLockerSDKManager.DebugMessage("Server Response: " + request.httpMethod + " " + request.endpoint + " completed in " + (Time.time - startTime).ToString("n4") + " secs.\nResponse: " + webRequest.downloadHandler.text);
98-
#endif
9998
}
10099
catch
101100
{
102-
LootLockerSDKManager.DebugMessage(request.httpMethod.ToString(),true);
103-
LootLockerSDKManager.DebugMessage(request.endpoint,true);
104-
LootLockerSDKManager.DebugMessage(webRequest.downloadHandler.text,true);
101+
LootLockerSDKManager.DebugMessage(request.httpMethod.ToString(), true);
102+
LootLockerSDKManager.DebugMessage(request.endpoint, true);
103+
LootLockerSDKManager.DebugMessage(webRequest.downloadHandler.text, true);
105104
}
106105

107106
LootLockerResponse response = new LootLockerResponse();
108107
response.statusCode = (int)webRequest.responseCode;
109-
if (webRequest.isHttpError || webRequest.isNetworkError || !string.IsNullOrEmpty(webRequest.error))
108+
if (webRequest.result == UnityWebRequest.Result.ProtocolError || webRequest.result == UnityWebRequest.Result.ConnectionError || !string.IsNullOrEmpty(webRequest.error))
110109
{
111110
switch (webRequest.responseCode)
112111
{
@@ -147,23 +146,28 @@ IEnumerator coroutine()
147146
response.Error = "Service Unavailable -- We're either offline for maintenance, or an error that should be solvable by calling again later was triggered.";
148147
break;
149148
}
150-
#if UNITY_EDITOR
149+
151150
LootLockerSDKManager.DebugMessage("Response code: " + webRequest.responseCode);
152-
#endif
153-
if (webRequest.responseCode != 401 || !LootLockerConfig.current.allowTokenRefresh)
151+
152+
153+
if ((webRequest.responseCode == 401 || webRequest.responseCode == 403) && LootLockerConfig.current.allowTokenRefresh && LootLockerConfig.current.platform != LootLockerConfig.platformType.Steam
154+
&& tries < maxRetry)
154155
{
155-
response.Error += " " + webRequest.downloadHandler.text;
156-
response.text = webRequest.downloadHandler.text;
156+
tries++;
157+
LootLockerSDKManager.DebugMessage("Refreshing Token, Since we could not find out. If you do not want this please turn off in the lootlocker config settings");
158+
RefreshTokenAndCompleteCall(request,(value)=> { tries = 0; OnServerResponse?.Invoke(value); });
157159
}
158160
else
159161
{
160-
RefreshTokenAndCompleteCall(request, OnServerResponse);
161-
}
162+
tries = 0;
163+
response.Error += " " + webRequest.downloadHandler.text;
164+
response.text = webRequest.downloadHandler.text;
162165

163-
response.status = false;
164-
response.hasError = true;
165-
response.text = webRequest.downloadHandler.text;
166-
OnServerResponse?.Invoke(response);
166+
response.status = false;
167+
response.hasError = true;
168+
response.text = webRequest.downloadHandler.text;
169+
OnServerResponse?.Invoke(response);
170+
}
167171

168172
}
169173
else
@@ -173,6 +177,7 @@ IEnumerator coroutine()
173177
response.text = webRequest.downloadHandler.text;
174178
OnServerResponse?.Invoke(response);
175179
}
180+
176181
}
177182
}
178183
}
@@ -223,7 +228,7 @@ protected IEnumerator DoDownloadTexture2D(string url, System.Action<Texture2D> O
223228

224229
if (texture == null)
225230
{
226-
LootLockerSDKManager.DebugMessage("Texture download failed for: " + url,true);
231+
LootLockerSDKManager.DebugMessage("Texture download failed for: " + url, true);
227232
}
228233

229234
OnComplete?.Invoke(texture);
@@ -255,25 +260,25 @@ UnityWebRequest CreateWebRequest(string url, LootLockerServerRequest request)
255260
byte[] formSections = UnityWebRequest.SerializeFormSections(form, boundary);
256261
// Set the content type - NO QUOTES around the boundary
257262
string contentType = String.Concat("multipart/form-data; boundary=--", Encoding.UTF8.GetString(boundary));
258-
263+
259264
//Debug.LogError("Content type Set: " + contentType);
260265
// Make my request object and add the raw body. Set anything else you need here
261266
webRequest = new UnityWebRequest();
262267
webRequest.SetRequestHeader("Content-Type", "multipart/form-data; boundary=--");
263-
webRequest.uri = new Uri(url);
268+
webRequest.uri = new Uri(url);
264269
Debug.Log(url);//the url is wrong in some cases
265270
webRequest.uploadHandler = new UploadHandlerRaw(formSections);
266271
webRequest.uploadHandler.contentType = contentType;
267272
webRequest.useHttpContinue = false;
268-
273+
269274
// webRequest.method = "POST";
270275
webRequest.method = UnityWebRequest.kHttpVerbPOST;
271276
}
272277
else
273278
{
274279
string json = (request.payload != null && request.payload.Count > 0) ? JsonConvert.SerializeObject(request.payload) : request.jsonPayload;
275280
#if UNITY_EDITOR
276-
LootLockerSDKManager.DebugMessage("REQUEST BODY = " + json);
281+
LootLockerSDKManager.DebugMessage("REQUEST BODY = " + json);
277282
#endif
278283
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(string.IsNullOrEmpty(json) ? "{}" : json);
279284
webRequest = UnityWebRequest.Put(url, bytes);

Runtime/Common/LootLockerEndPoints.cs renamed to Runtime/Client/LootLockerEndPoints.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,12 @@ public static LootLockerEndPoints current
154154
//Crashes
155155
[Header("Crashes")]
156156
public EndPointClass submittingACrashLog = new EndPointClass("v1/crash", LootLockerHTTPMethod.POST);
157+
158+
//Leaderboards
159+
[Header("Leaderboards")]
160+
public EndPointClass getMemberRank = new EndPointClass("leaderboards/{0}/member/{1}", LootLockerHTTPMethod.GET);
161+
public EndPointClass getByListOfMembers = new EndPointClass("leaderboards/{0}/members", LootLockerHTTPMethod.POST);
162+
public EndPointClass getScoreList = new EndPointClass("leaderboards/{0}/list?count={1}", LootLockerHTTPMethod.GET);
163+
public EndPointClass submitScore = new EndPointClass("leaderboards/{0}/submit", LootLockerHTTPMethod.POST);
157164
}
158165
}

0 commit comments

Comments
 (0)