Skip to content

Commit a936c25

Browse files
committed
Re-add Nintendo Switch code
1 parent 66b0f6b commit a936c25

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class LootLockerEndPoints
1616
public static EndPointClass initialAuthenticationRequest = new EndPointClass("v1/session", LootLockerHTTPMethod.POST);
1717
public static EndPointClass twoFactorAuthenticationCodeVerification = new EndPointClass("v1/2fa", LootLockerHTTPMethod.POST);
1818
public static EndPointClass subsequentRequests = new EndPointClass("v1/games", LootLockerHTTPMethod.GET);
19+
public static EndPointClass nintendoSwitchSessionRequest = new EndPointClass("session/nintendo-switch", LootLockerHTTPMethod.POST);
1920

2021
// White Label Login
2122
[Header("White Label Login")]

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,22 @@ public static void StartWhiteLabelSession(Action<LootLockerSessionResponse> onCo
341341
LootLockerAPIManager.WhiteLabelSession(sessionRequest, onComplete);
342342
}
343343

344+
/// <summary>
345+
/// Create a new session for a Nintendo Switch user
346+
///
347+
/// The Nintendo Switch platform must be enabled in the web console for this to work.
348+
/// </summary>
349+
public static void StartNintendoSwitchSession(string nsa_id_token, Action<LootLockerSessionResponse> onComplete)
350+
{
351+
if (!CheckInitialized())
352+
{
353+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerSessionResponse>());
354+
return;
355+
}
356+
LootLockerNintendoSwitchSessionRequest sessionRequest = new LootLockerNintendoSwitchSessionRequest(nsa_id_token);
357+
LootLockerAPIManager.NintendoSwitchSession(sessionRequest, onComplete);
358+
}
359+
344360
public static void EndSession(string deviceId, Action<LootLockerSessionResponse> onComplete)
345361
{
346362
if (!CheckInitialized())

Runtime/Game/Requests/LootLockerSessionRequest.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ public class LootLockerLevel_Thresholds
7777
public int next { get; set; }
7878
public bool next_is_prestige { get; set; }
7979
}
80+
81+
[System.Serializable]
82+
public class LootLockerNintendoSwitchSessionRequest : LootLockerGetRequest
83+
{
84+
public string game_key => LootLockerConfig.current.apiKey?.ToString();
85+
public string nsa_id_token { get; private set; }
86+
public string game_version => LootLockerConfig.current.game_version;
87+
public bool development_mode => LootLockerConfig.current.developmentMode;
88+
public LootLockerNintendoSwitchSessionRequest(string nsa_id_token)
89+
{
90+
this.nsa_id_token = nsa_id_token;
91+
}
92+
}
8093
}
8194

8295
namespace LootLocker
@@ -160,6 +173,34 @@ public static void GuestSession(LootLockerGetRequest data, Action<LootLockerGues
160173
}, false);
161174
}
162175

176+
public static void NintendoSwitchSession(LootLockerNintendoSwitchSessionRequest data, Action<LootLockerSessionResponse> onComplete)
177+
{
178+
EndPointClass endPoint = LootLockerEndPoints.nintendoSwitchSessionRequest;
179+
180+
string json = "";
181+
if (data == null)
182+
{
183+
return;
184+
}
185+
186+
json = JsonConvert.SerializeObject(data);
187+
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, json, (serverResponse) =>
188+
{
189+
LootLockerSessionResponse response = new LootLockerSessionResponse();
190+
if (string.IsNullOrEmpty(serverResponse.Error))
191+
{
192+
response = JsonConvert.DeserializeObject<LootLockerSessionResponse>(serverResponse.text);
193+
LootLockerConfig.current.UpdateToken(response.session_token, (data as LootLockerSessionRequest)?.player_identifier);
194+
}
195+
196+
response.text = serverResponse.text;
197+
response.success = serverResponse.success;
198+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
199+
onComplete?.Invoke(response);
200+
201+
}, false);
202+
}
203+
163204
public static void EndSession(LootLockerGetRequest data, Action<LootLockerSessionResponse> onComplete)
164205
{
165206
EndPointClass endPoint = LootLockerEndPoints.endingSession;

0 commit comments

Comments
 (0)