Skip to content

Commit 6efb197

Browse files
authored
Merge pull request #20 from LootLocker/xbox-support
Add initial support for Xbox One
2 parents a4902ad + bc004b5 commit 6efb197

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class LootLockerEndPoints
1717
public static EndPointClass twoFactorAuthenticationCodeVerification = new EndPointClass("v1/2fa", LootLockerHTTPMethod.POST);
1818
public static EndPointClass subsequentRequests = new EndPointClass("v1/games", LootLockerHTTPMethod.GET);
1919
public static EndPointClass nintendoSwitchSessionRequest = new EndPointClass("session/nintendo-switch", LootLockerHTTPMethod.POST);
20+
public static EndPointClass xboxSessionRequest = new EndPointClass("session/xbox-one", LootLockerHTTPMethod.POST);
2021

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

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,22 @@ public static void StartNintendoSwitchSession(string nsa_id_token, Action<LootLo
357357
LootLockerAPIManager.NintendoSwitchSession(sessionRequest, onComplete);
358358
}
359359

360+
/// <summary>
361+
/// Create a new session for a Xbox One user
362+
///
363+
/// The Xbox One platform must be enabled in the web console for this to work.
364+
/// </summary>
365+
public static void StartXboxOneSession(string xbox_user_token, Action<LootLockerSessionResponse> onComplete)
366+
{
367+
if (!CheckInitialized())
368+
{
369+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerSessionResponse>());
370+
return;
371+
}
372+
LootLockerXboxOneSessionRequest sessionRequest = new LootLockerXboxOneSessionRequest(xbox_user_token);
373+
LootLockerAPIManager.XboxOneSession(sessionRequest, onComplete);
374+
}
375+
360376
public static void EndSession(string deviceId, Action<LootLockerSessionResponse> onComplete)
361377
{
362378
if (!CheckInitialized())

Runtime/Game/Requests/LootLockerSessionRequest.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ public LootLockerNintendoSwitchSessionRequest(string nsa_id_token)
9090
this.nsa_id_token = nsa_id_token;
9191
}
9292
}
93+
94+
public class LootLockerXboxOneSessionRequest : LootLockerGetRequest
95+
{
96+
public string game_key => LootLockerConfig.current.apiKey?.ToString();
97+
public string xbox_user_token { get; private set; }
98+
public string game_version => LootLockerConfig.current.game_version;
99+
public bool development_mode => LootLockerConfig.current.developmentMode;
100+
public LootLockerXboxOneSessionRequest(string xbox_user_token)
101+
{
102+
this.xbox_user_token = xbox_user_token;
103+
}
104+
}
93105
}
94106

95107
namespace LootLocker
@@ -201,6 +213,34 @@ public static void NintendoSwitchSession(LootLockerNintendoSwitchSessionRequest
201213
}, false);
202214
}
203215

216+
public static void XboxOneSession(LootLockerXboxOneSessionRequest data, Action<LootLockerSessionResponse> onComplete)
217+
{
218+
EndPointClass endPoint = LootLockerEndPoints.xboxSessionRequest;
219+
220+
string json = "";
221+
if (data == null)
222+
{
223+
return;
224+
}
225+
226+
json = JsonConvert.SerializeObject(data);
227+
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, json, (serverResponse) =>
228+
{
229+
LootLockerSessionResponse response = new LootLockerSessionResponse();
230+
if (string.IsNullOrEmpty(serverResponse.Error))
231+
{
232+
response = JsonConvert.DeserializeObject<LootLockerSessionResponse>(serverResponse.text);
233+
LootLockerConfig.current.UpdateToken(response.session_token, "");
234+
}
235+
236+
response.text = serverResponse.text;
237+
response.success = serverResponse.success;
238+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
239+
onComplete?.Invoke(response);
240+
241+
}, false);
242+
}
243+
204244
public static void EndSession(LootLockerGetRequest data, Action<LootLockerSessionResponse> onComplete)
205245
{
206246
EndPointClass endPoint = LootLockerEndPoints.endingSession;

0 commit comments

Comments
 (0)