Skip to content

Commit b5d88c2

Browse files
committed
feat: Add support for fetching game info and auto fetch title/env id in remote session flow
1 parent c1a4db3 commit b5d88c2

File tree

6 files changed

+127
-33
lines changed

6 files changed

+127
-33
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ public class LootLockerEndPoints
265265
// Misc
266266
[Header("Misc")]
267267
public static EndPointClass ping = new EndPointClass("ping", LootLockerHTTPMethod.GET);
268+
public static EndPointClass gameInfo = new EndPointClass("info/v1", LootLockerHTTPMethod.POST);
268269

269270
// Reports
270271
[Header("Reports")]

Runtime/Editor/LogViewer/LootLockerLogViewerUI.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ public void InitializeLogViewerUI(VisualElement root, Action onBack = null)
6565
showAdminRequests = false;
6666
FilterLogs();
6767
}
68+
69+
public void RemoveLogViewerUI()
70+
{
71+
UnregisterLogListener();
72+
}
73+
6874
private void InitializeLogViewerEventHandlers(Action onBack)
6975
{
7076
if (logViewerBackBtn != null)
@@ -83,7 +89,8 @@ private void InitializeLogViewerEventHandlers(Action onBack)
8389
if (logSearchField != null)
8490
logSearchField.RegisterValueChangedCallback(evt => { searchFilter = evt.newValue; FilterLogs(); });
8591
if (logLevelDropdown != null)
86-
logLevelDropdown.RegisterValueChangedCallback(evt => {
92+
logLevelDropdown.RegisterValueChangedCallback(evt =>
93+
{
8794
if (evt.newValue == "All")
8895
{
8996
showAllLogLevels = true;
@@ -99,7 +106,8 @@ private void InitializeLogViewerEventHandlers(Action onBack)
99106
if (showAdminToggle != null)
100107
{
101108
showAdminToggle.value = false;
102-
showAdminToggle.RegisterValueChangedCallback(evt => {
109+
showAdminToggle.RegisterValueChangedCallback(evt =>
110+
{
103111
showAdminRequests = evt.newValue;
104112
FilterLogs();
105113
});
@@ -132,13 +140,15 @@ public void RegisterLogListener()
132140
if (string.IsNullOrEmpty(logListenerIdentifier))
133141
{
134142
logListenerIdentifier = LootLockerLogger.RegisterListener(this);
143+
LootLockerLogger.RegisterHttpLogListener(this);
135144
}
136145
}
137146
public void UnregisterLogListener()
138147
{
139148
if (!string.IsNullOrEmpty(logListenerIdentifier))
140149
{
141150
LootLockerLogger.UnregisterListener(logListenerIdentifier);
151+
LootLockerLogger.UnregisterHttpLogListener(this);
142152
logListenerIdentifier = null;
143153
}
144154
}
@@ -354,7 +364,8 @@ private void AddHttpLogEntryToUI(LootLockerLogger.LootLockerHttpLogEntry entry)
354364
}
355365

356366
// Insert the summaryRow into the Foldout's Toggle
357-
foldout.schedule.Execute(() => {
367+
foldout.schedule.Execute(() =>
368+
{
358369
var toggle = foldout.Q<Toggle>(className: "unity-foldout__toggle");
359370
if (toggle != null)
360371
{
@@ -366,7 +377,8 @@ private void AddHttpLogEntryToUI(LootLockerLogger.LootLockerHttpLogEntry entry)
366377
}
367378
});
368379

369-
foldout.schedule.Execute(() => {
380+
foldout.schedule.Execute(() =>
381+
{
370382
var headerLabel = summaryLabel;
371383
if (headerLabel != null)
372384
{
@@ -440,6 +452,11 @@ private void UpdateLogStatus()
440452
status += $" | Network: {networkRequests} req, {networkResponses} resp, {networkErrors} errors";
441453
logStatusLabel.text = status;
442454
}
455+
456+
public void Dispose()
457+
{
458+
UnregisterLogListener();
459+
}
443460
}
444461
}
445462
#endif

Runtime/Editor/LogViewer/LootLockerLogViewerWindow.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ public void CreateGUI()
5151
logViewerUI = new LogViewerUI();
5252
logViewerUI.InitializeLogViewerUI(root);
5353
}
54+
55+
public void OnDestroy()
56+
{
57+
if (logViewerUI != null)
58+
{
59+
logViewerUI.Dispose();
60+
logViewerUI = null;
61+
}
62+
}
5463
}
5564
}
5665
#endif

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,16 +1547,12 @@ public static void TransferIdentityProvidersBetweenAccounts(string FromPlayerWit
15471547
/// While the process is ongoing, the remoteSessionLeaseStatusUpdate action (if one is provided) will be invoked intermittently (about once a second) to update you on the status of the process.
15481548
/// When the process has come to an end (whether successfully or not), the onComplete action will be invoked with the updated information.
15491549
/// </summary>
1550-
/// <param name="titleId">The Title ID of the game</param>
1551-
/// <param name="environmentId">The Environment ID of the game and environment</param>
15521550
/// <param name="remoteSessionLeaseInformation">Will be invoked once to provide the lease information that the secondary device can use to authenticate</param>
15531551
/// <param name="remoteSessionLeaseStatusUpdate">Will be invoked intermittently to update the status lease process</param>
15541552
/// <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>
15551553
/// <param name="pollingIntervalSeconds">Optional: How often to poll the status of the remote session process</param>
15561554
/// <param name="timeOutAfterMinutes">Optional: How long to allow the process to take in its entirety</param>
15571555
public static Guid StartRemoteSession(
1558-
string titleId,
1559-
string environmentId,
15601556
Action<LootLockerLeaseRemoteSessionResponse> remoteSessionLeaseInformation,
15611557
Action<LootLockerRemoteSessionStatusPollingResponse> remoteSessionLeaseStatusUpdate,
15621558
Action<LootLockerStartRemoteSessionResponse> onComplete,
@@ -1571,8 +1567,6 @@ public static Guid StartRemoteSession(
15711567

15721568
return LootLockerAPIManager.RemoteSessionPoller.StartRemoteSessionWithContinualPolling(
15731569
LootLockerRemoteSessionLeaseIntent.login,
1574-
titleId,
1575-
environmentId,
15761570
remoteSessionLeaseInformation,
15771571
remoteSessionLeaseStatusUpdate,
15781572
onComplete,
@@ -1587,17 +1581,13 @@ public static Guid StartRemoteSession(
15871581
/// While the process is ongoing, the remoteSessionLeaseStatusUpdate action (if one is provided) will be invoked intermittently (about once a second) to update you on the status of the process.
15881582
/// When the process has come to an end (whether successfully or not), the onComplete action will be invoked with the updated information.
15891583
/// </summary>
1590-
/// <param name="titleId">The Title ID of the game</param>
1591-
/// <param name="environmentId">The Environment ID of the game and environment</param>
15921584
/// <param name="forPlayerWithUlid">Execute the request for the specified player (the player that you intend to link the remote account into)</param>
15931585
/// <param name="remoteSessionLeaseInformation">Will be invoked once to provide the lease information that the secondary device can use to authenticate</param>
15941586
/// <param name="remoteSessionLeaseStatusUpdate">Will be invoked intermittently to update the status lease process</param>
15951587
/// <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>
15961588
/// <param name="pollingIntervalSeconds">Optional: How often to poll the status of the remote session process</param>
15971589
/// <param name="timeOutAfterMinutes">Optional: How long to allow the process to take in its entirety</param>
15981590
public static Guid StartRemoteSessionForLinking(
1599-
string titleId,
1600-
string environmentId,
16011591
string forPlayerWithUlid,
16021592
Action<LootLockerLeaseRemoteSessionResponse> remoteSessionLeaseInformation,
16031593
Action<LootLockerRemoteSessionStatusPollingResponse> remoteSessionLeaseStatusUpdate,
@@ -1613,8 +1603,6 @@ public static Guid StartRemoteSessionForLinking(
16131603

16141604
return LootLockerAPIManager.RemoteSessionPoller.StartRemoteSessionWithContinualPolling(
16151605
LootLockerRemoteSessionLeaseIntent.link,
1616-
titleId,
1617-
environmentId,
16181606
remoteSessionLeaseInformation,
16191607
remoteSessionLeaseStatusUpdate,
16201608
onComplete,
@@ -7245,6 +7233,21 @@ public static void Ping(Action<LootLockerPingResponse> onComplete, string forPla
72457233
LootLockerAPIManager.Ping(forPlayerWithUlid, onComplete);
72467234
}
72477235

7236+
/// <summary>
7237+
/// Get meta information about the game
7238+
/// </summary>
7239+
/// <param name="onComplete">onComplete Action for handling the response</param>
7240+
public static void GetGameInfo(Action<LootLockerGameInfoResponse> onComplete)
7241+
{
7242+
if (!CheckInitialized(true))
7243+
{
7244+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerGameInfoResponse>(""));
7245+
return;
7246+
}
7247+
7248+
LootLockerAPIManager.GetGameInfo(onComplete);
7249+
}
7250+
72487251
/// <summary>
72497252
/// Get the Platform the user last used. This can be used to know what login method to prompt.
72507253
/// </summary>

Runtime/Game/Requests/MiscRequests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,51 @@
33

44
namespace LootLocker.Requests
55
{
6+
//==================================================
7+
// Data Definitions
8+
//==================================================
9+
/// <summary>
10+
/// Information about the currently configured game in LootLocker.
11+
/// </summary>
12+
public class LootLockerGameInfo
13+
{
14+
// The title ID of the game (uniquely identifies the game in LootLocker)
15+
public string title_id { get; set; }
16+
// The environment ID of the game (identifies which environment instance of the title this game refers to in LootLocker)
17+
public string environment_id { get; set; }
18+
// The id of the game (uniquely identifies the game in LootLocker)
19+
public int game_id { get; set; }
20+
// The name of the game as configured in LootLocker
21+
public string name { get; set; }
22+
};
23+
24+
//==================================================
25+
// Response Definitions
26+
//==================================================
627
public class LootLockerPingResponse : LootLockerResponse
728
{
829
public string date { get; set; }
930
}
1031

32+
/// <summary>
33+
/// Represents a response from the LootLocker API containing game information.
34+
/// </summary>
35+
public class LootLockerGameInfoResponse : LootLockerResponse
36+
{
37+
public LootLockerGameInfo info { get; set; }
38+
}
39+
40+
//==================================================
41+
// Request Definitions
42+
//==================================================
43+
/// <summary>
44+
/// Represents a request to get game information from the LootLocker API.
45+
/// </summary>
46+
[Serializable]
47+
public class LootLockerGameInfoRequest
48+
{
49+
public string api_key { get; set; }
50+
};
1151
}
1252

1353
namespace LootLocker
@@ -20,5 +60,11 @@ public static void Ping(string forPlayerWithUlid, Action<LootLockerPingResponse>
2060

2161
LootLockerServerRequest.CallAPI(forPlayerWithUlid, endPoint.endPoint, endPoint.httpMethod, null, (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
2262
}
63+
64+
public static void GetGameInfo(Action<LootLockerGameInfoResponse> onComplete)
65+
{
66+
string body = LootLockerJson.SerializeObject(new LootLockerGameInfoRequest { api_key = LootLockerConfig.current.apiKey });
67+
LootLockerServerRequest.CallAPI("", LootLockerEndPoints.gameInfo.endPoint, LootLockerEndPoints.gameInfo.httpMethod, body, (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); }, useAuthToken: false);
68+
}
2369
}
2470
}

Runtime/Game/Requests/RemoteSessionRequest.cs

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,14 @@ static void OnEnterPlaymodeInEditor(EnterPlayModeOptions options)
229229
#region Public Methods
230230
public static Guid StartRemoteSessionWithContinualPolling(
231231
LootLockerRemoteSessionLeaseIntent leaseIntent,
232-
string titleId,
233-
string environmentId,
234232
Action<LootLockerLeaseRemoteSessionResponse> remoteSessionLeaseInformation,
235233
Action<LootLockerRemoteSessionStatusPollingResponse> remoteSessionLeaseStatusUpdateCallback,
236234
Action<LootLockerStartRemoteSessionResponse> remoteSessionCompleted,
237235
float pollingIntervalSeconds = 1.0f,
238236
float timeOutAfterMinutes = 5.0f,
239237
string forPlayerWithUlid = null)
240238
{
241-
return GetInstance()._StartRemoteSessionWithContinualPolling(leaseIntent, titleId, environmentId, remoteSessionLeaseInformation,
239+
return GetInstance()._StartRemoteSessionWithContinualPolling(leaseIntent, remoteSessionLeaseInformation,
242240
remoteSessionLeaseStatusUpdateCallback, remoteSessionCompleted, pollingIntervalSeconds,
243241
timeOutAfterMinutes, forPlayerWithUlid);
244242
}
@@ -370,8 +368,6 @@ protected IEnumerator ContinualPollingAction(Guid processGuid)
370368

371369
private Guid _StartRemoteSessionWithContinualPolling(
372370
LootLockerRemoteSessionLeaseIntent leaseIntent,
373-
string titleId,
374-
string environmentId,
375371
Action<LootLockerLeaseRemoteSessionResponse> remoteSessionLeaseInformation,
376372
Action<LootLockerRemoteSessionStatusPollingResponse> remoteSessionLeaseStatusUpdateCallback,
377373
Action<LootLockerStartRemoteSessionResponse> remoteSessionCompleted,
@@ -400,25 +396,47 @@ private Guid _StartRemoteSessionWithContinualPolling(
400396
};
401397
AddRemoteSessionProcess(processGuid, lootLockerRemoteSessionProcess);
402398

403-
LeaseRemoteSession(leaseIntent, titleId, environmentId, forPlayerWithUlid, leaseRemoteSessionResponse =>
399+
LootLockerAPIManager.GetGameInfo(gameInfoResponse =>
404400
{
405-
if (!_remoteSessionsProcesses.TryGetValue(processGuid, out var process))
401+
if (!gameInfoResponse.success)
406402
{
403+
if (!_remoteSessionsProcesses.TryGetValue(processGuid, out var process))
404+
{
405+
return;
406+
}
407+
RemoveRemoteSessionProcess(processGuid);
408+
remoteSessionLeaseInformation?.Invoke(new LootLockerLeaseRemoteSessionResponse
409+
{
410+
success = gameInfoResponse.success,
411+
statusCode = gameInfoResponse.statusCode,
412+
text = gameInfoResponse.text,
413+
errorData = gameInfoResponse.errorData,
414+
requestContext = gameInfoResponse.requestContext,
415+
status = LootLockerRemoteSessionLeaseStatus.Failed
416+
});
407417
return;
408418
}
409-
if (!leaseRemoteSessionResponse.success)
419+
420+
LeaseRemoteSession(leaseIntent, gameInfoResponse.info.title_id, gameInfoResponse.info.environment_id, forPlayerWithUlid, leaseRemoteSessionResponse =>
410421
{
411-
RemoveRemoteSessionProcess(processGuid);
422+
if (!_remoteSessionsProcesses.TryGetValue(processGuid, out var process))
423+
{
424+
return;
425+
}
426+
if (!leaseRemoteSessionResponse.success)
427+
{
428+
RemoveRemoteSessionProcess(processGuid);
429+
remoteSessionLeaseInformation?.Invoke(leaseRemoteSessionResponse);
430+
return;
431+
}
412432
remoteSessionLeaseInformation?.Invoke(leaseRemoteSessionResponse);
413-
return;
414-
}
415-
remoteSessionLeaseInformation?.Invoke(leaseRemoteSessionResponse);
416433

417-
process.LeaseCode = leaseRemoteSessionResponse.code;
418-
process.LeaseNonce = leaseRemoteSessionResponse.nonce;
419-
process.LastUpdatedStatus = leaseRemoteSessionResponse.status;
420-
process.LastUpdatedAt = DateTime.UtcNow;
421-
StartCoroutine(ContinualPollingAction(processGuid));
434+
process.LeaseCode = leaseRemoteSessionResponse.code;
435+
process.LeaseNonce = leaseRemoteSessionResponse.nonce;
436+
process.LastUpdatedStatus = leaseRemoteSessionResponse.status;
437+
process.LastUpdatedAt = DateTime.UtcNow;
438+
StartCoroutine(ContinualPollingAction(processGuid));
439+
});
422440
});
423441
return processGuid;
424442
}

0 commit comments

Comments
 (0)