Skip to content

Commit 32725b2

Browse files
committed
fixed minor leaderboard bugs
1 parent 0f1d06d commit 32725b2

File tree

3 files changed

+66
-50
lines changed

3 files changed

+66
-50
lines changed

Runtime/Client/LootLockerServerRequest.cs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,7 @@ public struct LootLockerServerRequest
8888
public int retryCount;
8989

9090
#region Make ServerRequest and call send (3 functions)
91-
public static void CallAPI(string endPoint, LootLockerHTTPMethod httpMethod, Dictionary<string, object> body = null, Action<LootLockerResponse> onComplete = null)
92-
{
93-
new LootLockerServerRequest(endPoint, httpMethod, body).Send((response) =>
94-
{
95-
onComplete?.Invoke(response);
96-
});
97-
}
91+
9892
public static void CallAPI(string endPoint, LootLockerHTTPMethod httpMethod, string body = null, Action<LootLockerResponse> onComplete = null, bool useAuthToken = true, LootLocker.LootLockerEnums.LootLockerCallerRole callerRole = LootLocker.LootLockerEnums.LootLockerCallerRole.User)
9993
{
10094
#if UNITY_EDITOR
@@ -116,6 +110,7 @@ public static void CallAPI(string endPoint, LootLockerHTTPMethod httpMethod, str
116110
onComplete?.Invoke(response);
117111
});
118112
}
113+
119114
public static void UploadFile(string endPoint, LootLockerHTTPMethod httpMethod, byte[] file, string fileName = "file", string fileContentType = "text/plain", Dictionary<string, string> body = null, Action<LootLockerResponse> onComplete = null, bool useAuthToken = true, LootLocker.LootLockerEnums.LootLockerCallerRole callerRole = LootLocker.LootLockerEnums.LootLockerCallerRole.User)
120115
{
121116
Dictionary<string, string> headers = new Dictionary<string, string>();
@@ -167,27 +162,7 @@ public LootLockerServerRequest(string endpoint, LootLockerHTTPMethod httpMethod
167162
LootLockerSDKManager.DebugMessage("WARNING: Payloads should not be sent in GET, HEAD, OPTIONS, requests. Attempted to send a payload to: " + this.httpMethod.ToString() + " " + this.endpoint);
168163
}
169164
}
170-
public LootLockerServerRequest(string endpoint, LootLockerHTTPMethod httpMethod = LootLockerHTTPMethod.GET, byte[] upload = null, string uploadName = null, string uploadType = null, string body = null, Dictionary<string, string> extraHeaders = null, Dictionary<string, string> queryParams = null, bool useAuthToken = true, LootLocker.LootLockerEnums.LootLockerCallerRole callerRole = LootLocker.LootLockerEnums.LootLockerCallerRole.User)
171-
{
172-
this.retryCount = 0;
173-
this.endpoint = endpoint;
174-
this.httpMethod = httpMethod;
175-
this.payload = null;
176-
this.upload = upload;
177-
this.uploadName = uploadName;
178-
this.uploadType = uploadType;
179-
this.jsonPayload = null;
180-
this.extraHeaders = extraHeaders != null && extraHeaders.Count == 0 ? null : extraHeaders; // Force extra headers to null if empty dictionary was supplied
181-
this.queryParams = queryParams != null && queryParams.Count == 0 ? null : queryParams;
182-
this.adminCall = callerRole;
183-
this.form = null;
184-
bool isNonPayloadMethod = (this.httpMethod == LootLockerHTTPMethod.GET || this.httpMethod == LootLockerHTTPMethod.HEAD || this.httpMethod == LootLockerHTTPMethod.OPTIONS);
185165

186-
if (this.payload != null && isNonPayloadMethod)
187-
{
188-
LootLockerSDKManager.DebugMessage("WARNING: Payloads should not be sent in GET, HEAD, OPTIONS, requests. Attempted to send a payload to: " + this.httpMethod.ToString() + " " + this.endpoint);
189-
}
190-
}
191166
public LootLockerServerRequest(string endpoint, LootLockerHTTPMethod httpMethod = LootLockerHTTPMethod.GET, Dictionary<string, object> payload = null, Dictionary<string, string> extraHeaders = null, Dictionary<string, string> queryParams = null, bool useAuthToken = true, LootLocker.LootLockerEnums.LootLockerCallerRole callerRole = LootLocker.LootLockerEnums.LootLockerCallerRole.User)
192167
{
193168
this.retryCount = 0;

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ public static void GetByListOfMembers(string[] members, int id, Action<LootLocke
16821682
LootLockerAPIManager.GetByListOfMembers(request, id.ToString(), onComplete);
16831683
}
16841684

1685-
public static void GetScoreList(int leaderboardId, int count, Action<LootLockerGetScoreListResponse> onComplete)
1685+
public static void GetScoreListMain(int leaderboardId, int count, int after, Action<LootLockerGetScoreListResponse> onComplete)
16861686
{
16871687
if (!CheckInitialized())
16881688
{
@@ -1697,11 +1697,42 @@ public static void GetScoreList(int leaderboardId, int count, Action<LootLockerG
16971697
LootLockerGetScoreListRequest request = new LootLockerGetScoreListRequest();
16981698
request.leaderboardId = leaderboardId;
16991699
request.count = count.ToString();
1700+
request.after = after > 0 ? after.ToString() : null;
1701+
Action<LootLockerGetScoreListResponse> callback = (response) =>
1702+
{
1703+
if (response != null && response.pagination != null)
1704+
{
1705+
LootLockerGetScoreListRequest.nextCursor = response.pagination.next_cursor;
1706+
LootLockerGetScoreListRequest.prevCursor = response.pagination.previous_cursor;
1707+
response.pagination.allowNext = response.pagination.next_cursor > 0;
1708+
response.pagination.allowPrev = (response.pagination.previous_cursor != null);
1709+
}
1710+
onComplete?.Invoke(response);
1711+
};
1712+
LootLockerAPIManager.GetScoreList(request, callback);
1713+
}
17001714

1701-
LootLockerAPIManager.GetScoreList(request, onComplete);
1715+
public static void GetScoreList(int leaderboardId, int count, Action<LootLockerGetScoreListResponse> onComplete)
1716+
{
1717+
GetScoreListMain(leaderboardId, count, -1, onComplete);
1718+
}
1719+
1720+
public static void GetNextScoreList(int leaderboardId, int count, Action<LootLockerGetScoreListResponse> onComplete)
1721+
{
1722+
GetScoreListMain(leaderboardId, count, int.Parse(LootLockerGetScoreListRequest.nextCursor.ToString()), onComplete);
1723+
}
1724+
1725+
public static void GetPrevScoreList(int leaderboardId, int count, Action<LootLockerGetScoreListResponse> onComplete)
1726+
{
1727+
GetScoreListMain(leaderboardId, count, int.Parse(LootLockerGetScoreListRequest.prevCursor.ToString()), onComplete);
1728+
}
1729+
1730+
public void ResetScoreCalls()
1731+
{
1732+
LootLockerGetScoreListRequest.Reset();
17021733
}
17031734

1704-
public static void GetScoreList(int leaderboardId, int count, int after, Action<LootLockerGetScoreListResponse> onComplete)
1735+
public static void GetScoreListOriginal(int leaderboardId, int count, int after, Action<LootLockerGetScoreListResponse> onComplete)
17051736
{
17061737
if (!CheckInitialized())
17071738
{
@@ -1721,7 +1752,7 @@ public static void GetScoreList(int leaderboardId, int count, int after, Action<
17211752
LootLockerAPIManager.GetScoreList(request, onComplete);
17221753
}
17231754

1724-
public static void SubmitScore(string member_id, int score, int id, Action<LootLockerSubmitScoreResponse> onComplete)
1755+
public static void SubmitScore(string memberId, int score, int leaderboardId, Action<LootLockerSubmitScoreResponse> onComplete)
17251756
{
17261757
if (!CheckInitialized())
17271758
{
@@ -1734,10 +1765,10 @@ public static void SubmitScore(string member_id, int score, int id, Action<LootL
17341765
return;
17351766
}
17361767
LootLockerSubmitScoreRequest request = new LootLockerSubmitScoreRequest();
1737-
request.member_id = member_id;
1768+
request.member_id = memberId;
17381769
request.score = score;
17391770

1740-
LootLockerAPIManager.SubmitScore(request, id.ToString(), onComplete);
1771+
LootLockerAPIManager.SubmitScore(request, leaderboardId.ToString(), onComplete);
17411772
}
17421773

17431774
public static void ComputeAndLockDropTable(int tableInstanceId, Action<LootLockerComputeAndLockDropTableResponse> onComplete, bool AddAssetDetails = false, string tag = "")

Runtime/Game/Requests/LeaderboardRequest.cs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ public class LootLockerGetScoreListResponse : LootLockerResponse
5252
public class LootLockerPagination
5353
{
5454
public int total { get; set; }
55-
public int next_cursor { get; set; }
56-
// public object previous_cursor { get; set; }
55+
public int? next_cursor { get; set; }
56+
public int? previous_cursor { get; set; }
57+
public bool allowNext { get; set; }
58+
public bool allowPrev { get; set; }
5759
}
5860

5961
public class LootLockerSubmitScoreResponse : LootLockerResponse
@@ -82,6 +84,14 @@ public class LootLockerGetScoreListRequest
8284
public int leaderboardId { get; set; }
8385
public string count { get; set; }
8486
public string after { get; set; }
87+
88+
public static int? nextCursor;
89+
public static int? prevCursor;
90+
public static void Reset()
91+
{
92+
nextCursor = 0;
93+
prevCursor = 0;
94+
}
8595
}
8696

8797
public class LootLockerGetByListMembersRequest
@@ -105,10 +115,10 @@ public static void GetMemberRank(LootLockerGetMemberRankRequest data, Action<Loo
105115
if (string.IsNullOrEmpty(serverResponse.Error))
106116
response = JsonConvert.DeserializeObject<LootLockerGetMemberRankResponse>(serverResponse.text);
107117

108-
// LootLockerSDKManager.DebugMessage(serverResponse.text, !string.IsNullOrEmpty(serverResponse.Error));
118+
// LootLockerSDKManager.DebugMessage(serverResponse.text, !string.IsNullOrEmpty(serverResponse.Error));
109119
response.text = serverResponse.text;
110-
response.status = serverResponse.status;
111-
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
120+
response.status = serverResponse.status;
121+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
112122
onComplete?.Invoke(response);
113123
}, true, LootLocker.LootLockerEnums.LootLockerCallerRole.User);
114124
}
@@ -128,10 +138,10 @@ public static void GetByListOfMembers(LootLockerGetByListMembersRequest data, st
128138
if (string.IsNullOrEmpty(serverResponse.Error))
129139
response = JsonConvert.DeserializeObject<LootLockerGetByListOfMembersResponse>(serverResponse.text);
130140

131-
// LootLockerSDKManager.DebugMessage(serverResponse.text, !string.IsNullOrEmpty(serverResponse.Error));
141+
// LootLockerSDKManager.DebugMessage(serverResponse.text, !string.IsNullOrEmpty(serverResponse.Error));
132142
response.text = serverResponse.text;
133-
response.status = serverResponse.status;
134-
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
143+
response.status = serverResponse.status;
144+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
135145

136146
onComplete?.Invoke(response);
137147
}, true, LootLocker.LootLockerEnums.LootLockerCallerRole.User);
@@ -142,24 +152,24 @@ public static void GetScoreList(LootLockerGetScoreListRequest getRequests, Actio
142152
EndPointClass requestEndPoint = LootLockerEndPoints.getScoreList;
143153

144154
string tempEndpoint = requestEndPoint.endPoint;
145-
string endPoint = string.Format(requestEndPoint.endPoint, getRequests.leaderboardId,int.Parse(getRequests.count));
155+
string endPoint = string.Format(requestEndPoint.endPoint, getRequests.leaderboardId, int.Parse(getRequests.count));
146156

147157
if (!string.IsNullOrEmpty(getRequests.after))
148158
{
149159
tempEndpoint = requestEndPoint.endPoint + "&after={2}";
150-
endPoint = string.Format(requestEndPoint.endPoint, getRequests.leaderboardId, int.Parse(getRequests.count), int.Parse(getRequests.after));
160+
endPoint = string.Format(tempEndpoint, getRequests.leaderboardId, int.Parse(getRequests.count), int.Parse(getRequests.after));
151161
}
152-
162+
153163
LootLockerServerRequest.CallAPI(endPoint, requestEndPoint.httpMethod, null, (serverResponse) =>
154164
{
155165
LootLockerGetScoreListResponse response = new LootLockerGetScoreListResponse();
156166
if (string.IsNullOrEmpty(serverResponse.Error))
157167
response = JsonConvert.DeserializeObject<LootLockerGetScoreListResponse>(serverResponse.text);
158168

159-
// LootLockerSDKManager.DebugMessage(serverResponse.text, !string.IsNullOrEmpty(serverResponse.Error));
169+
// LootLockerSDKManager.DebugMessage(serverResponse.text, !string.IsNullOrEmpty(serverResponse.Error));
160170
response.text = serverResponse.text;
161-
response.status = serverResponse.status;
162-
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
171+
response.status = serverResponse.status;
172+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
163173
onComplete?.Invoke(response);
164174
}, true, LootLocker.LootLockerEnums.LootLockerCallerRole.User);
165175
}
@@ -179,10 +189,10 @@ public static void SubmitScore(LootLockerSubmitScoreRequest data, string id, Act
179189
if (string.IsNullOrEmpty(serverResponse.Error))
180190
response = JsonConvert.DeserializeObject<LootLockerSubmitScoreResponse>(serverResponse.text);
181191

182-
// LootLockerSDKManager.DebugMessage(serverResponse.text, !string.IsNullOrEmpty(serverResponse.Error));
192+
// LootLockerSDKManager.DebugMessage(serverResponse.text, !string.IsNullOrEmpty(serverResponse.Error));
183193
response.text = serverResponse.text;
184-
response.status = serverResponse.status;
185-
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
194+
response.status = serverResponse.status;
195+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
186196
onComplete?.Invoke(response);
187197
}, useAuthToken: true, callerRole: LootLocker.LootLockerEnums.LootLockerCallerRole.User);
188198
}

0 commit comments

Comments
 (0)