Skip to content

Commit 92600e1

Browse files
committed
Add initial support for guest login
1 parent 8ed6837 commit 92600e1

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class LootLockerEndPoints
1010
[Header("Authentication Endpoints")]
1111
public static EndPointClass playerVerification = new EndPointClass("v1/player/verify", LootLockerHTTPMethod.POST);
1212
public static EndPointClass authenticationRequest = new EndPointClass("v2/session", LootLockerHTTPMethod.POST);
13+
public static EndPointClass guestSessionRequest = new EndPointClass("v2/session/guest", LootLockerHTTPMethod.POST);
1314
public static EndPointClass endingSession = new EndPointClass("v1/session", LootLockerHTTPMethod.DELETE);
1415
public static EndPointClass initialAuthenticationRequest = new EndPointClass("v1/session", LootLockerHTTPMethod.POST);
1516
public static EndPointClass twoFactorAuthenticationCodeVerification = new EndPointClass("v1/2fa", LootLockerHTTPMethod.POST);

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,37 @@ public static void StartSession(string deviceId, Action<LootLockerSessionRespons
149149
LootLockerSessionRequest sessionRequest = new LootLockerSessionRequest(deviceId);
150150
LootLockerAPIManager.Session(sessionRequest, onComplete);
151151
}
152+
153+
public static void StartGuestSession(Action<LootLockerGuestSessionResponse> onComplete)
154+
{
155+
if (!CheckInitialized())
156+
{
157+
LootLockerGuestSessionResponse response = new LootLockerGuestSessionResponse();
158+
response.success = false;
159+
response.success = false;
160+
response.hasError = true;
161+
response.Error = "SDk not initialised";
162+
response.text = "SDk not initialised";
163+
onComplete?.Invoke(response);
164+
return;
165+
}
166+
167+
LootLockerSessionRequest sessionRequest = new LootLockerSessionRequest();
168+
string existingPlayerID = PlayerPrefs.GetString("LootLockerGuestPlayerID", "");
169+
if (existingPlayerID != "")
170+
{
171+
sessionRequest = new LootLockerSessionRequest(existingPlayerID);
172+
}
173+
174+
LootLockerAPIManager.GuestSession(sessionRequest, response =>
175+
{
176+
PlayerPrefs.SetString("LootLockerGuestPlayerID", response.player_identifier);
177+
PlayerPrefs.Save();
178+
179+
onComplete(response);
180+
});
181+
}
182+
152183
public static void StartSteamSession(string steamId64, Action<LootLockerSessionResponse> onComplete)
153184
{
154185
if (!CheckInitialized())

Runtime/Game/Requests/LootLockerSessionRequest.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public LootLockerSessionRequest(string player_identifier)
2222
{
2323
this.player_identifier = player_identifier;
2424
}
25+
public LootLockerSessionRequest()
26+
{
27+
}
2528
}
2629

2730
[System.Serializable]
@@ -40,6 +43,12 @@ public class LootLockerSessionResponse : LootLockerResponse
4043
public LootLockerLevel_Thresholds level_thresholds { get; set; }
4144
public int account_balance { get; set; }
4245
}
46+
47+
public class LootLockerGuestSessionResponse : LootLockerSessionResponse
48+
{
49+
public string player_identifier { get; set; }
50+
}
51+
4352
[System.Serializable]
4453
public class LootLockerLevel_Thresholds
4554
{
@@ -79,6 +88,34 @@ public static void Session(LootLockerGetRequest data, Action<LootLockerSessionRe
7988
}, false);
8089
}
8190

91+
public static void GuestSession(LootLockerGetRequest data, Action<LootLockerGuestSessionResponse> onComplete)
92+
{
93+
EndPointClass endPoint = LootLockerEndPoints.guestSessionRequest;
94+
95+
string json = "";
96+
if (data == null)
97+
{
98+
return;
99+
}
100+
101+
json = JsonConvert.SerializeObject(data);
102+
LootLockerServerRequest.CallAPI(endPoint.endPoint, endPoint.httpMethod, json, (serverResponse) =>
103+
{
104+
LootLockerGuestSessionResponse response = new LootLockerGuestSessionResponse();
105+
if (string.IsNullOrEmpty(serverResponse.Error))
106+
{
107+
response = JsonConvert.DeserializeObject<LootLockerGuestSessionResponse>(serverResponse.text);
108+
LootLockerConfig.current.UpdateToken(response.session_token, (data as LootLockerSessionRequest)?.player_identifier);
109+
}
110+
111+
response.text = serverResponse.text;
112+
response.success = serverResponse.success;
113+
response.Error = serverResponse.Error; response.statusCode = serverResponse.statusCode;
114+
onComplete?.Invoke(response);
115+
116+
}, false);
117+
}
118+
82119
public static void EndSession(LootLockerGetRequest data, Action<LootLockerSessionResponse> onComplete)
83120
{
84121
EndPointClass endPoint = LootLockerEndPoints.endingSession;

0 commit comments

Comments
 (0)