Skip to content

Commit 8b65573

Browse files
Implement Meta session methods
1 parent ff282bb commit 8b65573

File tree

4 files changed

+172
-38
lines changed

4 files changed

+172
-38
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 subsequentRequests = new EndPointClass("v1/games", LootLockerHTTPMethod.GET);
1818
public static EndPointClass nintendoSwitchSessionRequest = new EndPointClass("session/nintendo-switch", LootLockerHTTPMethod.POST);
1919
public static EndPointClass epicSessionRequest = new EndPointClass("session/epic", LootLockerHTTPMethod.POST);
20+
public static EndPointClass metaSessionRequest = new EndPointClass("session/meta", LootLockerHTTPMethod.POST);
2021
public static EndPointClass xboxSessionRequest = new EndPointClass("session/xbox-one", LootLockerHTTPMethod.POST);
2122
public static EndPointClass appleSessionRequest = new EndPointClass("session/apple", LootLockerHTTPMethod.POST);
2223
public static EndPointClass appleGameCenterSessionRequest = new EndPointClass("session/apple/game-center", LootLockerHTTPMethod.POST);

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,83 @@ public static void RefreshEpicSession(string refresh_token, Action<LootLockerEpi
735735
onComplete(response);
736736
});
737737
}
738+
739+
/// <summary>
740+
/// Start a Meta session
741+
/// </summary>
742+
/// <param name="user_id">User ID as a string</param>
743+
/// <param name="nonce">Nonce as a string</param>
744+
/// <param name="onComplete">Action to handle the response of type LootLockerMetaSessionResponse</param>
745+
public static void StartMetaSession(string user_id, string nonce, Action<LootLockerMetaSessionResponse> onComplete)
746+
{
747+
if (!CheckInitialized(true))
748+
{
749+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerMetaSessionResponse>());
750+
return;
751+
}
752+
CurrentPlatform.Set(Platforms.Epic);
753+
var sessionRequest = new LootLockerMetaSessionRequest()
754+
{
755+
user_id = user_id,
756+
nonce = nonce
757+
};
758+
759+
var endPoint = LootLockerEndPoints.metaSessionRequest;
760+
761+
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, LootLockerJson.SerializeObject(sessionRequest), (serverResponse) =>
762+
{
763+
var response = LootLockerResponse.Deserialize<LootLockerMetaSessionResponse>(serverResponse);
764+
LootLockerConfig.current.token = response.session_token;
765+
LootLockerConfig.current.refreshToken = response.refresh_token;
766+
LootLockerConfig.current.deviceID = "";
767+
onComplete?.Invoke(response);
768+
}, false);
769+
}
770+
771+
/// <summary>
772+
/// Refresh a previous Meta session
773+
/// A response code of 400 (Bad request) could mean that the refresh token has expired and you'll need to sign in again
774+
/// The Meta sign in platform must be enabled and configured in the web console for this to work.
775+
/// </summary>
776+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerMetaSessionResponse</param>
777+
public static void RefreshMetaSession(Action<LootLockerMetaSessionResponse> onComplete)
778+
{
779+
RefreshMetaSession("", onComplete);
780+
}
781+
782+
/// <summary>
783+
/// Refresh a previous Meta session
784+
/// If you do not want to manually handle the refresh token we recommend using the RefreshMetaSession(Action<LootLockerMetaSessionResponse> onComplete) method.
785+
/// A response code of 400 (Bad request) could mean that the refresh token has expired and you'll need to sign in again
786+
/// The Meta platform must be enabled and configured in the web console for this to work.
787+
/// </summary>
788+
/// <param name="refresh_token">Token received in response from StartMetaSession request</param>
789+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerMetaSessionResponse</param>
790+
public static void RefreshMetaSession(string refresh_token, Action<LootLockerMetaSessionResponse> onComplete)
791+
{
792+
if (!CheckInitialized(true))
793+
{
794+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerMetaSessionResponse>());
795+
return;
796+
}
797+
798+
CurrentPlatform.Set(Platforms.Meta);
799+
var sessionRequest = new LootLockerMetaRefreshSessionRequest()
800+
{
801+
refresh_token = string.IsNullOrEmpty(refresh_token) ? LootLockerConfig.current.refreshToken : refresh_token
802+
};
803+
var endPoint = LootLockerEndPoints.metaSessionRequest;
804+
805+
806+
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, LootLockerJson.SerializeObject(sessionRequest), (serverResponse) =>
807+
{
808+
var response = LootLockerResponse.Deserialize<LootLockerMetaSessionResponse>(serverResponse);
809+
LootLockerConfig.current.token = response.session_token;
810+
LootLockerConfig.current.refreshToken = response.refresh_token;
811+
LootLockerConfig.current.deviceID = "";
812+
onComplete?.Invoke(response);
813+
}, false);
814+
}
738815

739816
/// <summary>
740817
/// End active session (if any exists)

Runtime/Game/Platforms/PlatformManager.cs

Lines changed: 70 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using UnityEngine;
23
#if UNITY_EDITOR
34
using UnityEditor;
45
#endif
@@ -7,19 +8,20 @@ namespace LootLocker.Requests
78
{
89
public enum Platforms
910
{
10-
None
11-
,Guest
12-
,WhiteLabel
13-
,Steam
14-
,PlayStationNetwork
15-
,XboxOne
16-
,NintendoSwitch
17-
,AmazonLuna
18-
,AppleSignIn
19-
,AppleGameCenter
20-
,Android
21-
,Google
22-
,Epic
11+
None,
12+
Guest,
13+
WhiteLabel,
14+
Steam,
15+
PlayStationNetwork,
16+
XboxOne,
17+
NintendoSwitch,
18+
AmazonLuna,
19+
AppleSignIn,
20+
AppleGameCenter,
21+
Android,
22+
Google,
23+
Epic,
24+
Meta
2325
}
2426

2527
public class CurrentPlatform
@@ -30,43 +32,73 @@ static CurrentPlatform()
3032
{
3133
throw new ArrayTypeMismatchException($"A Platform is missing a string representation, {PlatformStrings.Length} vs {Enum.GetNames(typeof(Platforms)).Length}");
3234
}
35+
3336
if (PlatformFriendlyStrings.Length != Enum.GetNames(typeof(Platforms)).Length)
3437
{
3538
throw new ArrayTypeMismatchException($"A Platform is missing a friendly name, {PlatformFriendlyStrings.Length} vs {Enum.GetNames(typeof(Platforms)).Length}");
3639
}
3740
}
38-
41+
3942
private static readonly string[] PlatformStrings = new[]
4043
{
4144
"" // None
42-
,"guest" // Guest
43-
,"white_label_login" // WhiteLabel
44-
,"steam" // Steam
45-
,"psn" // PSN
46-
,"xbox_one" // XboxOne
47-
,"nintendo_switch" // NintendoSwitch
48-
,"amazon_luna" // AmazonLuna
49-
,"apple_sign_in" // AppleSignIn
50-
,"apple_game_center" // Apple Game Center
51-
,"android" // Android
52-
,"google_sign_in" // Google
53-
,"epic_games" // Epic Online Services / Epic Games
45+
,
46+
"guest" // Guest
47+
,
48+
"white_label_login" // WhiteLabel
49+
,
50+
"steam" // Steam
51+
,
52+
"psn" // PSN
53+
,
54+
"xbox_one" // XboxOne
55+
,
56+
"nintendo_switch" // NintendoSwitch
57+
,
58+
"amazon_luna" // AmazonLuna
59+
,
60+
"apple_sign_in" // AppleSignIn
61+
,
62+
"apple_game_center" // Apple Game Center
63+
,
64+
"android" // Android
65+
,
66+
"google_sign_in" // Google
67+
,
68+
"epic_games" // Epic Online Services / Epic Games
69+
,
70+
"meta" // Meta
5471
};
72+
5573
private static readonly string[] PlatformFriendlyStrings = new[]
5674
{
5775
"None" // None
58-
,"Guest" // Guest
59-
,"White Label" // WhiteLabel
60-
,"Steam" // Steam
61-
,"Playstation Network" // PSN
62-
,"Xbox One" // XboxOne
63-
,"Nintendo Switch" // NintendoSwitch
64-
,"Amazon Luna" // AmazonLuna
65-
,"Apple Sign In" // AppleSignIn
66-
,"Apple Game Center" // Apple Game Center
67-
,"Android" // Android
68-
,"Google" // Google
69-
,"Epic Online Services" // Epic Online Services / Epic Games
76+
,
77+
"Guest" // Guest
78+
,
79+
"White Label" // WhiteLabel
80+
,
81+
"Steam" // Steam
82+
,
83+
"Playstation Network" // PSN
84+
,
85+
"Xbox One" // XboxOne
86+
,
87+
"Nintendo Switch" // NintendoSwitch
88+
,
89+
"Amazon Luna" // AmazonLuna
90+
,
91+
"Apple Sign In" // AppleSignIn
92+
,
93+
"Apple Game Center" // Apple Game Center
94+
,
95+
"Android" // Android
96+
,
97+
"Google" // Google
98+
,
99+
"Epic Online Services" // Epic Online Services / Epic Games
100+
,
101+
"Meta" // Meta
70102
};
71103

72104
public struct PlatformRepresentation

Runtime/Game/Requests/LootLockerSessionRequest.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ public class LootLockerEpicSessionResponse : LootLockerSessionResponse
110110
{
111111
public string refresh_token { get; set; }
112112
}
113+
114+
public class LootLockerMetaSessionResponse : LootLockerSessionResponse
115+
{
116+
public string refresh_token { get; set; }
117+
}
113118

114119
[Serializable]
115120
public class LootLockerLevel_Thresholds
@@ -158,6 +163,25 @@ public LootLockerEpicRefreshSessionRequest(string refresh_token)
158163
this.refresh_token = refresh_token;
159164
}
160165
}
166+
167+
[Serializable]
168+
public class LootLockerMetaSessionRequest : LootLockerGetRequest
169+
{
170+
public string game_key => LootLockerConfig.current.apiKey?.ToString();
171+
public string game_version => LootLockerConfig.current.game_version;
172+
173+
public string user_id { get; set; }
174+
175+
public string nonce { get; set; }
176+
}
177+
178+
[Serializable]
179+
public class LootLockerMetaRefreshSessionRequest : LootLockerGetRequest
180+
{
181+
public string game_key => LootLockerConfig.current.apiKey?.ToString();
182+
public string refresh_token { get; set; }
183+
public string game_version => LootLockerConfig.current.game_version;
184+
}
161185

162186
public class LootLockerXboxOneSessionRequest : LootLockerGetRequest
163187
{

0 commit comments

Comments
 (0)