Skip to content

Commit e77d573

Browse files
committed
Add support for Apple Game Center
1 parent 146f92b commit e77d573

File tree

4 files changed

+145
-2
lines changed

4 files changed

+145
-2
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class LootLockerEndPoints
1919
public static EndPointClass epicSessionRequest = new EndPointClass("session/epic", LootLockerHTTPMethod.POST);
2020
public static EndPointClass xboxSessionRequest = new EndPointClass("session/xbox-one", LootLockerHTTPMethod.POST);
2121
public static EndPointClass appleSessionRequest = new EndPointClass("session/apple", LootLockerHTTPMethod.POST);
22+
public static EndPointClass appleGameCenterSessionRequest = new EndPointClass("session/apple/game-center", LootLockerHTTPMethod.POST);
2223
public static EndPointClass googleSessionRequest = new EndPointClass("session/google", LootLockerHTTPMethod.POST);
2324

2425
// White Label Login

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ public static void RefreshGoogleSession(string refresh_token, Action<LootLockerG
521521
/// The Apple sign in platform must be enabled in the web console for this to work.
522522
/// </summary>
523523
/// <param name="authorization_code">Authorization code, provided by apple</param>
524-
/// <param name="onComplete">onComplete Action for handling the response of type for handling the response of type LootLockerAppleSessionResponse</param>
524+
/// <param name="onComplete">onComplete Action for handling the response of type LootLockerAppleSessionResponse</param>
525525
public static void StartAppleSession(string authorization_code, Action<LootLockerAppleSessionResponse> onComplete)
526526
{
527527
if (!CheckInitialized(true))
@@ -581,6 +581,63 @@ public static void RefreshAppleSession(string refresh_token, Action<LootLockerAp
581581
});
582582
}
583583

584+
/// <summary>
585+
/// Create a new session for Sign in with Apple Game Center
586+
/// The Apple Game Center sign in platform must be enabled in the web console for this to work.
587+
/// </summary>
588+
/// <param name="bundleId">The Apple Game Center bundle id of your app</param>
589+
/// <param name="playerId">The user's player id in Apple Game Center</param>
590+
/// <param name="publicKeyUrl">The url of the public key generated from Apple Game Center Identity Verification</param>
591+
/// <param name="signature">The signature generated from Apple Game Center Identity Verification</param>
592+
/// <param name="salt">The salt of the signature generated from Apple Game Center Identity Verification</param>
593+
/// <param name="timestamp">The timestamp of the verification generated from Apple Game Center Identity Verification</param>
594+
/// <param name="onComplete">onComplete Action for handling the response of type for handling the response of type LootLockerAppleGameCenterSessionResponse</param>
595+
public static void StartAppleGameCenterSession(string bundleId, string playerId, string publicKeyUrl, string signature, string salt, long timestamp, Action<LootLockerAppleGameCenterSessionResponse> onComplete)
596+
{
597+
if (!CheckInitialized(true))
598+
{
599+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerAppleGameCenterSessionResponse>());
600+
return;
601+
}
602+
603+
CurrentPlatform.Set(Platforms.AppleGameCenter);
604+
LootLockerAppleGameCenterSessionRequest sessionRequest = new LootLockerAppleGameCenterSessionRequest(bundleId, playerId, publicKeyUrl, signature, salt, timestamp);
605+
LootLockerAPIManager.AppleGameCenterSession(sessionRequest, response =>
606+
{
607+
if (!response.success)
608+
{
609+
CurrentPlatform.Reset();
610+
}
611+
onComplete(response);
612+
});
613+
}
614+
615+
/// <summary>
616+
/// Refresh a previous session signed in with Apple Game Center
617+
/// A response code of 401 (Unauthorized) means the refresh token has expired and you'll need to sign in again
618+
/// The Apple Game Center sign in platform must be enabled in the web console for this to work.
619+
/// </summary>
620+
/// <param name="onComplete">onComplete Action for handling the response of type for handling the response of type LootLockerAppleGameCenterSessionResponse</param>
621+
public static void RefreshAppleGameCenterSession(Action<LootLockerAppleGameCenterSessionResponse> onComplete)
622+
{
623+
if (!CheckInitialized(true))
624+
{
625+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerAppleGameCenterSessionResponse>());
626+
return;
627+
}
628+
629+
CurrentPlatform.Set(Platforms.AppleGameCenter);
630+
LootLockerAppleGameCenterRefreshSessionRequest sessionRequest = new LootLockerAppleGameCenterRefreshSessionRequest(LootLockerConfig.current.refreshToken);
631+
LootLockerAPIManager.AppleGameCenterSession(sessionRequest, response =>
632+
{
633+
if (!response.success)
634+
{
635+
CurrentPlatform.Reset();
636+
}
637+
onComplete(response);
638+
});
639+
}
640+
584641
/// <summary>
585642
/// Create a new session for an Epic Online Services (EOS) user
586643
/// The Epic Games platform must be enabled in the web console for this to work.

Runtime/Game/Platforms/PlatformManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public enum Platforms
1616
,NintendoSwitch
1717
,AmazonLuna
1818
,AppleSignIn
19+
,AppleGameCenter
1920
,Android
2021
,Google
2122
,Epic
@@ -46,6 +47,7 @@ static CurrentPlatform()
4647
,"nintendo_switch" // NintendoSwitch
4748
,"amazon_luna" // AmazonLuna
4849
,"apple_sign_in" // AppleSignIn
50+
,"apple_game_center" // Apple Game Center
4951
,"android" // Android
5052
,"google" // Google
5153
,"epic" // Epic Online Services / Epic Games
@@ -61,6 +63,7 @@ static CurrentPlatform()
6163
,"Nintendo Switch" // NintendoSwitch
6264
,"Amazon Luna" // AmazonLuna
6365
,"Apple Sign In" // AppleSignIn
66+
,"Apple Game Center" // Apple Game Center
6467
,"Android" // Android
6568
,"Google" // Google
6669
,"Epic Online Services" // Epic Online Services / Epic Games

Runtime/Game/Requests/LootLockerSessionRequest.cs

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ public class LootLockerAppleSessionResponse : LootLockerSessionResponse
9898
public string refresh_token { get; set; }
9999
}
100100

101-
[Serializable]
101+
[System.Serializable]
102+
public class LootLockerAppleGameCenterSessionResponse : LootLockerSessionResponse
103+
{
104+
public string player_name { get; set; }
105+
public string refresh_token { get; set; }
106+
}
107+
108+
[System.Serializable]
102109
public class LootLockerEpicSessionResponse : LootLockerSessionResponse
103110
{
104111
public string refresh_token { get; set; }
@@ -211,6 +218,40 @@ public LootLockerAppleRefreshSessionRequest(string refresh_token)
211218
this.refresh_token = refresh_token;
212219
}
213220
}
221+
222+
public class LootLockerAppleGameCenterSessionRequest : LootLockerGetRequest
223+
{
224+
public string game_key => LootLockerConfig.current.apiKey?.ToString();
225+
public string game_version => LootLockerConfig.current.game_version;
226+
public string bundle_id { get; private set; }
227+
public string player_id { get; private set; }
228+
public string public_key_url { get; private set; }
229+
public string signature { get; private set; }
230+
public string salt { get; private set; }
231+
public long timestamp { get; private set; }
232+
233+
public LootLockerAppleGameCenterSessionRequest(string bundleId, string playerId, string publicKeyUrl, string signature, string salt, long timestamp)
234+
{
235+
this.bundle_id = bundleId;
236+
this.player_id = playerId;
237+
this.public_key_url = publicKeyUrl;
238+
this.signature = signature;
239+
this.salt = salt;
240+
this.timestamp = timestamp;
241+
}
242+
}
243+
244+
public class LootLockerAppleGameCenterRefreshSessionRequest : LootLockerGetRequest
245+
{
246+
public string game_key => LootLockerConfig.current.apiKey?.ToString();
247+
public string game_version => LootLockerConfig.current.game_version;
248+
public string refresh_token { get; private set; }
249+
250+
public LootLockerAppleGameCenterRefreshSessionRequest(string refresh_token)
251+
{
252+
this.refresh_token = refresh_token;
253+
}
254+
}
214255
}
215256

216257
namespace LootLocker
@@ -445,6 +486,47 @@ private static void AppleSession(string json, Action<LootLockerAppleSessionRespo
445486
}, false);
446487
}
447488

489+
public static void AppleGameCenterSession(LootLockerAppleGameCenterSessionRequest data, Action<LootLockerAppleGameCenterSessionResponse> onComplete)
490+
{
491+
if (data == null)
492+
{
493+
onComplete?.Invoke(LootLockerResponseFactory.InputUnserializableError<LootLockerAppleGameCenterSessionResponse>());
494+
return;
495+
}
496+
497+
string json = LootLockerJson.SerializeObject(data);
498+
AppleGameCenterSession(json, onComplete);
499+
}
500+
501+
public static void AppleGameCenterSession(LootLockerAppleGameCenterRefreshSessionRequest data, Action<LootLockerAppleGameCenterSessionResponse> onComplete)
502+
{
503+
if (data == null)
504+
{
505+
onComplete?.Invoke(LootLockerResponseFactory.InputUnserializableError<LootLockerAppleGameCenterSessionResponse>());
506+
return;
507+
}
508+
509+
string json = LootLockerJson.SerializeObject(data);
510+
AppleGameCenterSession(json, onComplete);
511+
}
512+
513+
private static void AppleGameCenterSession(string json, Action<LootLockerAppleGameCenterSessionResponse> onComplete)
514+
{
515+
EndPointClass endPoint = LootLockerEndPoints.appleGameCenterSessionRequest;
516+
if (string.IsNullOrEmpty(json))
517+
{
518+
return;
519+
}
520+
LootLockerConfig.AddDevelopmentModeFieldToJsonStringIfNeeded(ref json); // TODO: Deprecated, remove in version 1.2.0
521+
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, json, (serverResponse) =>
522+
{
523+
var response = LootLockerAppleGameCenterSessionResponse.Deserialize<LootLockerAppleGameCenterSessionResponse>(serverResponse);
524+
LootLockerConfig.current.token = response.session_token;
525+
LootLockerConfig.current.refreshToken = response.refresh_token;
526+
onComplete?.Invoke(response);
527+
}, false);
528+
}
529+
448530
public static void EndSession(LootLockerSessionRequest data, Action<LootLockerSessionResponse> onComplete)
449531
{
450532
EndPointClass endPoint = LootLockerEndPoints.endingSession;

0 commit comments

Comments
 (0)