Skip to content

Commit 97721a9

Browse files
committed
Add support for session refresh on new platforms
1 parent 145fe76 commit 97721a9

File tree

6 files changed

+101
-14
lines changed

6 files changed

+101
-14
lines changed

Runtime/Client/LootLockerBaseServerAPI.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,8 @@ IEnumerator coroutine()
156156
break;
157157
}
158158

159-
LootLockerSDKManager.DebugMessage("Response code: " + webRequest.responseCode);
160-
161-
162-
if ((webRequest.responseCode == 401 || webRequest.responseCode == 403) && LootLockerConfig.current.allowTokenRefresh && LootLockerConfig.current.platform != LootLockerConfig.platformType.Steam
163-
&& tries < maxRetry)
159+
bool isSteam = LootLockerSDKManager.GetCurrentPlatform() == "steam";
160+
if ((webRequest.responseCode == 401 || webRequest.responseCode == 403) && LootLockerConfig.current.allowTokenRefresh && !isSteam && tries < maxRetry)
164161
{
165162
tries++;
166163
LootLockerSDKManager.DebugMessage("Refreshing Token, Since we could not find one. If you do not want this please turn off in the lootlocker config settings");

Runtime/Game/LootLockerGameServerAPI.cs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
namespace LootLocker
99
{
10-
/// <summary>
11-
/// made for user, relay on playtime coroutines
12-
/// </summary>
1310
public class LootLockerGameServerAPI : LootLockerBaseServerAPI
1411
{
1512
public new static LootLockerGameServerAPI I;
@@ -28,9 +25,22 @@ public static void Init(LootLockerServerManager serverManager)
2825

2926
protected override void RefreshTokenAndCompleteCall(LootLockerServerRequest cacheServerRequest, Action<LootLockerResponse> OnServerResponse)
3027
{
31-
if (LootLockerConfig.current.platform == LootLockerConfig.platformType.Steam)
28+
string platform = LootLockerSDKManager.GetCurrentPlatform();
29+
30+
if (platform == Platforms.Steam)
31+
{
32+
LootLockerSDKManager.DebugMessage("Token has expired, And token refresh is not supported in Steam calls", true);
33+
LootLockerResponse res = new LootLockerResponse();
34+
res.statusCode = 401;
35+
res.Error = "Token Expired";
36+
res.hasError = true;
37+
OnServerResponse?.Invoke(res);
38+
return;
39+
}
40+
41+
if (platform == Platforms.NintendoSwitch)
3242
{
33-
LootLockerSDKManager.DebugMessage("Token has expired, And token refresh not supported in Steam calls", true);
43+
LootLockerSDKManager.DebugMessage("Token has expired, And token refresh is not supported in Nintendo calls", true);
3444
LootLockerResponse res = new LootLockerResponse();
3545
res.statusCode = 401;
3646
res.Error = "Token Expired";
@@ -39,9 +49,30 @@ protected override void RefreshTokenAndCompleteCall(LootLockerServerRequest cach
3949
return;
4050
}
4151

42-
var sessionRequest = new LootLockerSessionRequest(LootLockerConfig.current.deviceID);
52+
if (platform == Platforms.Guest)
53+
{
54+
LootLockerSDKManager.StartGuestSession(response =>
55+
{
56+
CompleteCall(cacheServerRequest, OnServerResponse, response);
57+
});
58+
return;
59+
} else if (platform == Platforms.WhiteLabel)
60+
{
61+
LootLockerSDKManager.StartWhiteLabelSession(response =>
62+
{
63+
CompleteCall(cacheServerRequest, OnServerResponse, response);
64+
});
4365

44-
LootLockerAPIManager.Session(sessionRequest, (response) =>
66+
return;
67+
} else {
68+
var sessionRequest = new LootLockerSessionRequest(LootLockerConfig.current.deviceID);
69+
LootLockerAPIManager.Session(sessionRequest, (response) =>
70+
{
71+
CompleteCall(cacheServerRequest, OnServerResponse, response);
72+
});
73+
}
74+
75+
void CompleteCall(LootLockerServerRequest cacheServerRequest, Action<LootLockerResponse> OnServerResponse, LootLockerSessionResponse response)
4576
{
4677
if (response.success)
4778
{
@@ -72,7 +103,7 @@ protected override void RefreshTokenAndCompleteCall(LootLockerServerRequest cach
72103
res.hasError = true;
73104
OnServerResponse?.Invoke(res);
74105
}
75-
});
106+
}
76107
}
77108
}
78109
}

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@
1313

1414
namespace LootLocker.Requests
1515
{
16-
1716
public partial class LootLockerSDKManager
1817
{
18+
/// <summary>
19+
/// Stores which platform the player currently has a session for.
20+
/// </summary>
21+
static string CurrentPlatform;
22+
23+
public static string GetCurrentPlatform()
24+
{
25+
return CurrentPlatform;
26+
}
27+
1928
#region Init
2029

2130
static bool initialized;
@@ -144,7 +153,11 @@ public static void StartSession(string deviceId, Action<LootLockerSessionRespons
144153
response.text = "SDk not initialised";
145154
onComplete?.Invoke(response);
146155
return;
156+
147157
}
158+
159+
CurrentPlatform = LootLockerConfig.current.platform.ToString();
160+
148161
LootLockerConfig.current.deviceID = deviceId;
149162
LootLockerSessionRequest sessionRequest = new LootLockerSessionRequest(deviceId);
150163
LootLockerAPIManager.Session(sessionRequest, onComplete);
@@ -167,6 +180,8 @@ public static void StartGuestSession(Action<LootLockerGuestSessionResponse> onCo
167180

168181
LootLockerAPIManager.GuestSession(sessionRequest, response =>
169182
{
183+
CurrentPlatform = "guest";
184+
170185
PlayerPrefs.SetString("LootLockerGuestPlayerID", response.player_identifier);
171186
PlayerPrefs.Save();
172187

@@ -186,6 +201,9 @@ public static void StartSteamSession(string steamId64, Action<LootLockerSessionR
186201
onComplete?.Invoke(response);
187202
return;
188203
}
204+
205+
CurrentPlatform = "steam";
206+
189207
LootLockerSessionRequest sessionRequest = new LootLockerSessionRequest(steamId64);
190208
LootLockerAPIManager.Session(sessionRequest, onComplete);
191209
}
@@ -273,6 +291,7 @@ public static void StartWhiteLabelSession(string email, string password, Action<
273291
return;
274292
}
275293
LootLockerWhiteLabelSessionRequest sessionRequest = new LootLockerWhiteLabelSessionRequest(email, password);
294+
CurrentPlatform = "white_label";
276295
LootLockerAPIManager.WhiteLabelSession(sessionRequest, onComplete);
277296
}
278297

@@ -285,6 +304,7 @@ public static void StartWhiteLabelSession(LootLockerWhiteLabelSessionRequest inp
285304
}
286305
LootLockerWhiteLabelSessionRequest sessionRequest = new LootLockerWhiteLabelSessionRequest(input.email);
287306
sessionRequest.token = input.token;
307+
CurrentPlatform = "white_label";
288308
LootLockerAPIManager.WhiteLabelSession(sessionRequest, onComplete);
289309
}
290310

@@ -310,6 +330,7 @@ public static void StartWhiteLabelSession(Action<LootLockerSessionResponse> onCo
310330
return;
311331
}
312332

333+
CurrentPlatform = "white_label";
313334
LootLockerWhiteLabelSessionRequest sessionRequest = new LootLockerWhiteLabelSessionRequest(existingSessionEmail);
314335
sessionRequest.token = existingSessionToken;
315336
LootLockerAPIManager.WhiteLabelSession(sessionRequest, onComplete);
@@ -327,6 +348,8 @@ public static void EndSession(string deviceId, Action<LootLockerSessionResponse>
327348
onComplete?.Invoke(response);
328349
return;
329350
}
351+
352+
CurrentPlatform = "";
330353
LootLockerSessionRequest sessionRequest = new LootLockerSessionRequest(deviceId);
331354
LootLockerAPIManager.EndSession(sessionRequest, onComplete);
332355
}

Runtime/Game/Platforms.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace LootLocker.Requests
4+
{
5+
public static class Platforms
6+
{
7+
public static string NintendoSwitch = "nintendo_switch";
8+
public static string Guest = "guest";
9+
public static string WhiteLabel = "white_label";
10+
public static string Steam = "white_label";
11+
}
12+
13+
public static class PlatformManager
14+
{
15+
private static string CurrentPlatform { get; set; }
16+
}
17+
}

Runtime/Game/Platforms/PlatformManager.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)