Skip to content

Commit 5013353

Browse files
Erik Bylundkirre-bylund
authored andcommitted
Updates after testing
1 parent 9132b7b commit 5013353

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

Runtime/Client/LootLockerServerRequest.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public struct LootLockerServerRequest
418418

419419
#region Make ServerRequest and call send (3 functions)
420420

421-
public static void CallAPI(string endPoint, LootLockerHTTPMethod httpMethod, string body = null, Action<LootLockerResponse> onComplete = null, bool useAuthToken = true, LootLocker.LootLockerEnums.LootLockerCallerRole callerRole = LootLocker.LootLockerEnums.LootLockerCallerRole.User)
421+
public static void CallAPI(string endPoint, LootLockerHTTPMethod httpMethod, string body = null, Action<LootLockerResponse> onComplete = null, bool useAuthToken = true, LootLocker.LootLockerEnums.LootLockerCallerRole callerRole = LootLocker.LootLockerEnums.LootLockerCallerRole.User, Dictionary<string, string> additionalHeaders = null)
422422
{
423423
if (RateLimiter.Get().AddRequestAndCheckIfRateLimitHit())
424424
{
@@ -453,6 +453,14 @@ public static void CallAPI(string endPoint, LootLockerHTTPMethod httpMethod, str
453453
if (LootLockerConfig.current != null)
454454
headers.Add(LootLockerConfig.current.dateVersion.key, LootLockerConfig.current.dateVersion.value);
455455

456+
if (additionalHeaders != null)
457+
{
458+
foreach (var additionalHeader in additionalHeaders)
459+
{
460+
headers.Add(additionalHeader.Key, additionalHeader.Value);
461+
}
462+
}
463+
456464
LootLockerBaseServerAPI.I.SwitchURL(callerRole);
457465

458466
new LootLockerServerRequest(endPoint, httpMethod, body, headers, callerRole: callerRole).Send((response) => { onComplete?.Invoke(response); });

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,7 @@ public static void ClearLocalSession()
807807
#endregion
808808

809809
#region Remote Sessions
810+
810811
/// <summary>
811812
/// Start a remote session
812813
/// If you want to let your local user sign in using another device then you use this method. First you will get the lease information needed to allow a secondary device to authenticate.
@@ -816,15 +817,17 @@ public static void ClearLocalSession()
816817
/// <param name="remoteSessionLeaseInformation">Will be invoked once to provide the lease information that the secondary device can use to authenticate</param>
817818
/// <param name="remoteSessionLeaseStatusUpdate">Will be invoked intermittently to update the status lease process</param>
818819
/// <param name="onComplete">Invoked when the remote session process has run to completion containing either a valid session or information on why the process failed</param>
819-
public static Guid StartRemoteSession(Action<LootLockerLeaseRemoteSessionResponse> remoteSessionLeaseInformation, Action<LootLockerRemoteSessionStatusPollingResponse> remoteSessionLeaseStatusUpdate, Action<LootLockerStartRemoteSessionResponse> onComplete)
820+
/// <param name="pollingIntervalSeconds">Optional: How often to poll the status of the remote session process</param>
821+
/// <param name="timeOutAfterMinutes">Optional: How long to allow the process to take in it's entirety</param>
822+
public static Guid StartRemoteSession(Action<LootLockerLeaseRemoteSessionResponse> remoteSessionLeaseInformation, Action<LootLockerRemoteSessionStatusPollingResponse> remoteSessionLeaseStatusUpdate, Action<LootLockerStartRemoteSessionResponse> onComplete, float pollingIntervalSeconds = 1.0f, float timeOutAfterMinutes = 5.0f)
820823
{
821824
if (!CheckInitialized(true))
822825
{
823826
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerStartRemoteSessionResponse>());
824827
return Guid.Empty;
825828
}
826829

827-
return LootLockerAPIManager.RemoteSessionPoller.GetInstance().StartRemoteSessionWithContinualPolling(remoteSessionLeaseInformation, remoteSessionLeaseStatusUpdate, onComplete);
830+
return LootLockerAPIManager.RemoteSessionPoller.GetInstance().StartRemoteSessionWithContinualPolling(remoteSessionLeaseInformation, remoteSessionLeaseStatusUpdate, onComplete, pollingIntervalSeconds, timeOutAfterMinutes);
828831
}
829832

830833
/// <summary>

Runtime/Game/Requests/RemoteSessionRequest.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public class LootLockerLeaseRemoteSessionResponse : LootLockerResponse
105105
public class LootLockerRemoteSessionStatusPollingResponse : LootLockerResponse
106106
{
107107
/// <summary>
108-
/// The current status of this lease process. If this is not of the status Authorized, the rest of the fields in this object will be empty.
108+
/// The current status of this lease process.
109109
/// </summary>
110110
public LootLockerRemoteSessionLeaseStatus lease_status { get; set; }
111111
}
@@ -166,8 +166,6 @@ static void OnEnterPlaymodeInEditor(EnterPlayModeOptions options)
166166
}
167167
#endif
168168

169-
private static readonly double _leasingProcessTimeoutLimitInMinutes = 5.0d;
170-
private static readonly float _leasingProcessPollingIntervalSeconds = 1.0f;
171169
private static readonly int _leasingProcessPollingRetryLimit = 5;
172170

173171
private class LootLockerRemoteSessionProcess
@@ -176,6 +174,7 @@ private class LootLockerRemoteSessionProcess
176174
public string LeaseNonce;
177175
public LootLockerRemoteSessionLeaseStatus LastUpdatedStatus;
178176
public DateTime LeasingProcessTimeoutTime;
177+
public float PollingIntervalSeconds = 1.0f;
179178
public DateTime LastUpdatedAt;
180179
public int Retries = 0;
181180
public bool ShouldCancel;
@@ -202,7 +201,11 @@ private static void RemoveRemoteSessionProcess(Guid processGuid)
202201

203202
protected IEnumerator ContinualPollingAction(Guid processGuid)
204203
{
205-
yield return new WaitForSeconds(_leasingProcessPollingIntervalSeconds);
204+
if (!_remoteSessionsProcesses.TryGetValue(processGuid, out var preProcess))
205+
{
206+
yield break;
207+
}
208+
yield return new WaitForSeconds(preProcess.PollingIntervalSeconds);
206209
while (_remoteSessionsProcesses.TryGetValue(processGuid, out var process))
207210
{
208211
// Check if we should continue the polling
@@ -221,6 +224,7 @@ protected IEnumerator ContinualPollingAction(Guid processGuid)
221224
{
222225
LootLockerStartRemoteSessionResponse canceledResponse = new LootLockerStartRemoteSessionResponse
223226
{
227+
success = false,
224228
lease_status = LootLockerRemoteSessionLeaseStatus.Cancelled
225229
};
226230
process.ProcessCompletedCallbackAction?.Invoke(canceledResponse);
@@ -246,7 +250,7 @@ protected IEnumerator ContinualPollingAction(Guid processGuid)
246250
{
247251
// Recoverable error
248252
processAfterStatusCheck.Retries++;
249-
yield return new WaitForSeconds(_leasingProcessPollingIntervalSeconds);
253+
yield return new WaitForSeconds(processAfterStatusCheck.PollingIntervalSeconds);
250254
continue;
251255
}
252256

@@ -256,6 +260,7 @@ protected IEnumerator ContinualPollingAction(Guid processGuid)
256260
yield break;
257261
}
258262

263+
// Authorized = We're done
259264
if (startSessionResponse.lease_status == LootLockerRemoteSessionLeaseStatus.Authorized)
260265
{
261266
processAfterStatusCheck.ProcessCompletedCallbackAction?.Invoke(startSessionResponse);
@@ -269,16 +274,19 @@ protected IEnumerator ContinualPollingAction(Guid processGuid)
269274
startSessionResponse);
270275
processAfterStatusCheck.UpdateCallbackAction?.Invoke(pollingResponse);
271276
processAfterStatusCheck.LastUpdatedAt = DateTime.UtcNow;
277+
processAfterStatusCheck.LastUpdatedStatus = pollingResponse.lease_status;
272278

273279
// Sleep for a bit before checking again
274-
yield return new WaitForSeconds(_leasingProcessPollingIntervalSeconds);
280+
yield return new WaitForSeconds(processAfterStatusCheck.PollingIntervalSeconds);
275281
}
276282
}
277283

278284
public Guid StartRemoteSessionWithContinualPolling(
279285
Action<LootLockerLeaseRemoteSessionResponse> remoteSessionLeaseInformation,
280286
Action<LootLockerRemoteSessionStatusPollingResponse> remoteSessionLeaseStatusUpdateCallback,
281-
Action<LootLockerStartRemoteSessionResponse> remoteSessionCompleted)
287+
Action<LootLockerStartRemoteSessionResponse> remoteSessionCompleted,
288+
float pollingIntervalSeconds = 1.0f,
289+
float timeOutAfterMinutes = 5.0f)
282290
{
283291
if (_remoteSessionsProcesses.Count > 0)
284292
{
@@ -292,7 +300,8 @@ public Guid StartRemoteSessionWithContinualPolling(
292300
LootLockerRemoteSessionProcess lootLockerRemoteSessionProcess = new LootLockerRemoteSessionProcess()
293301
{
294302
LastUpdatedAt = DateTime.UtcNow,
295-
LeasingProcessTimeoutTime = DateTime.UtcNow.AddMinutes(_leasingProcessTimeoutLimitInMinutes),
303+
LeasingProcessTimeoutTime = DateTime.UtcNow.AddMinutes(timeOutAfterMinutes),
304+
PollingIntervalSeconds = pollingIntervalSeconds,
296305
UpdateCallbackAction = remoteSessionLeaseStatusUpdateCallback,
297306
ProcessCompletedCallbackAction = remoteSessionCompleted
298307
};
@@ -310,6 +319,7 @@ public Guid StartRemoteSessionWithContinualPolling(
310319
remoteSessionLeaseInformation?.Invoke(leaseRemoteSessionResponse);
311320
return;
312321
}
322+
remoteSessionLeaseInformation?.Invoke(leaseRemoteSessionResponse);
313323

314324
process.LeaseCode = leaseRemoteSessionResponse.code;
315325
process.LeaseNonce = leaseRemoteSessionResponse.nonce;
@@ -365,7 +375,7 @@ private void StartRemoteSession(string leaseCode, string nonce, Action<LootLocke
365375
CurrentPlatform.Set(Platforms.Remote);
366376
LootLockerConfig.current.token = response.session_token;
367377
LootLockerConfig.current.refreshToken = response.refresh_token;
368-
LootLockerConfig.current.deviceID = response.player_identifier;
378+
LootLockerConfig.current.deviceID = response.player_ulid;
369379
}
370380

371381
onComplete?.Invoke(response);

0 commit comments

Comments
 (0)