Skip to content

Commit 9bb5f85

Browse files
committed
feat: Authentication Listener knows the difference between a Connect and Auth login
1 parent 580ed42 commit 9bb5f85

File tree

6 files changed

+33
-16
lines changed

6 files changed

+33
-16
lines changed

Assets/Scripts/StandardSamples/Services/AchievementsService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private static string ProductUserIdToString(ProductUserId productUserId)
107107
return buffer;
108108
}
109109

110-
protected async override void OnLoggedIn()
110+
protected async override void OnLoggedIn(AuthenticationListener.AuthenticationLevelChangeType changeType)
111111
{
112112
await RefreshAsync();
113113
}

Assets/Scripts/StandardSamples/Services/EOSService.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,30 +159,32 @@ protected bool TryGetProductUserId(out ProductUserId productUserId)
159159

160160
}
161161

162-
private void OnAuthenticationChanged(bool authenticated)
162+
private void OnAuthenticationChanged(bool authenticated, AuthenticationListener.AuthenticationLevelChangeType changeType)
163163
{
164164
if (authenticated)
165165
{
166-
OnLoggedIn();
166+
OnLoggedIn(changeType);
167167
}
168168
else
169169
{
170-
OnLoggedOut();
170+
OnLoggedOut(changeType);
171171
}
172172
}
173173

174174
/// <summary>
175175
/// Implement this method to perform tasks when a user authenticates.
176176
/// By default, there is no action taken.
177177
/// </summary>
178-
protected virtual void OnLoggedIn() { }
178+
/// <param name="changeType">The type of authentication change.</param>
179+
protected virtual void OnLoggedIn(AuthenticationListener.AuthenticationLevelChangeType changeType) { }
179180

180181
/// <summary>
181182
/// If there are tasks that need to be done when logged out, consider
182183
/// overriding the Reset() function as that is where such things should
183184
/// be done.
184185
/// </summary>
185-
protected void OnLoggedOut()
186+
/// <param name="changeType">The type of authentication change.</param>
187+
protected void OnLoggedOut(AuthenticationListener.AuthenticationLevelChangeType changeType)
186188
{
187189
Reset();
188190
}

Assets/Scripts/StandardSamples/Services/PlayerDataStorageService.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,12 @@ private void FinishFileUpload(string fileName, Action fileUploadCallback = null)
372372
/// <list type="bullet">
373373
/// <item><description><c>QueryFileList()</c></description></item>
374374
/// </list>
375-
protected override void OnLoggedIn()
375+
protected override void OnLoggedIn(AuthenticationListener.AuthenticationLevelChangeType changeType)
376376
{
377-
QueryFileList();
377+
if (changeType == AuthenticationListener.AuthenticationLevelChangeType.Connect)
378+
{
379+
QueryFileList();
380+
}
378381
}
379382

380383
protected override Task InternalRefreshAsync()

Assets/Scripts/StandardSamples/Services/StatsService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static void Log(string toPrint)
9494
UnityEngine.Debug.Log(toPrint);
9595
}
9696

97-
protected async override void OnLoggedIn()
97+
protected async override void OnLoggedIn(AuthenticationListener.AuthenticationLevelChangeType changeType)
9898
{
9999
if (TryGetProductUserId(out ProductUserId userId))
100100
{

Assets/Scripts/StandardSamples/UI/Common/SampleMenu.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ protected SampleMenu(bool startsHidden = true, bool requiresAuthentication = tru
162162
/// <param name="authenticated">
163163
/// True if the state has changed to authenticated, false otherwise.
164164
/// </param>
165-
private void OnAuthenticationChanged(bool authenticated)
165+
/// <param name="authenticationChangeType">
166+
/// What kind of authentication change this is.</param>
167+
private void OnAuthenticationChanged(bool authenticated, AuthenticationListener.AuthenticationLevelChangeType authenticationChangeType)
166168
{
167169
if (authenticated || !RequiresAuthentication)
168170
{

com.playeveryware.eos/Runtime/Core/AuthenticationListener.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ namespace PlayEveryWare.EpicOnlineServices
3434
/// </summary>
3535
public class AuthenticationListener: IAuthInterfaceEventListener, IConnectInterfaceEventListener, IDisposable
3636
{
37+
/// <summary>
38+
/// Identifies the kind of authentication change.
39+
/// </summary>
40+
public enum AuthenticationLevelChangeType
41+
{
42+
Auth,
43+
Connect
44+
}
45+
3746
/// <summary>
3847
/// Used to describe functions that handle change in authentication
3948
/// state.
@@ -42,7 +51,7 @@ public class AuthenticationListener: IAuthInterfaceEventListener, IConnectInterf
4251
/// True if the authentication state has changed to authenticated, False
4352
/// otherwise.
4453
/// </param>
45-
public delegate void AuthenticationChangedEventHandler(bool authenticated);
54+
public delegate void AuthenticationChangedEventHandler(bool authenticated, AuthenticationLevelChangeType changeType);
4655

4756
/// <summary>
4857
/// Event that triggers when the state of authentication has changed.
@@ -104,7 +113,8 @@ public bool IsAuthenticated
104113
/// </summary>
105114
/// <param name="attemptedState"></param>
106115
/// <param name="attemptResult"></param>
107-
private void TriggerAuthenticationChangedEvent(bool attemptedState, Result attemptResult)
116+
/// <param name="changeType">The type of authentication change.</param>
117+
private void TriggerAuthenticationChangedEvent(bool attemptedState, Result attemptResult, AuthenticationLevelChangeType changeType)
108118
{
109119
// If the attempt to change the state of authentication did not
110120
// succeed, then log a warning and stop.
@@ -119,7 +129,7 @@ private void TriggerAuthenticationChangedEvent(bool attemptedState, Result attem
119129

120130
// Trigger the event indicating that the state of authentication for
121131
// the user has changed.
122-
AuthenticationChanged?.Invoke(attemptedState);
132+
AuthenticationChanged?.Invoke(attemptedState, changeType);
123133
}
124134

125135
/// <summary>
@@ -130,7 +140,7 @@ private void TriggerAuthenticationChangedEvent(bool attemptedState, Result attem
130140
/// </param>
131141
public void OnAuthLogin(LoginCallbackInfo loginCallbackInfo)
132142
{
133-
TriggerAuthenticationChangedEvent(true, loginCallbackInfo.ResultCode);
143+
TriggerAuthenticationChangedEvent(true, loginCallbackInfo.ResultCode, AuthenticationLevelChangeType.Auth);
134144
}
135145

136146
/// <summary>
@@ -141,7 +151,7 @@ public void OnAuthLogin(LoginCallbackInfo loginCallbackInfo)
141151
/// </param>
142152
public void OnAuthLogout(LogoutCallbackInfo logoutCallbackInfo)
143153
{
144-
TriggerAuthenticationChangedEvent(false, logoutCallbackInfo.ResultCode);
154+
TriggerAuthenticationChangedEvent(false, logoutCallbackInfo.ResultCode, AuthenticationLevelChangeType.Auth);
145155
}
146156

147157
/// <summary>
@@ -152,7 +162,7 @@ public void OnAuthLogout(LogoutCallbackInfo logoutCallbackInfo)
152162
/// </param>
153163
public void OnConnectLogin(Epic.OnlineServices.Connect.LoginCallbackInfo loginCallbackInfo)
154164
{
155-
TriggerAuthenticationChangedEvent(true, loginCallbackInfo.ResultCode);
165+
TriggerAuthenticationChangedEvent(true, loginCallbackInfo.ResultCode, AuthenticationLevelChangeType.Connect);
156166
}
157167

158168
/// <summary>

0 commit comments

Comments
 (0)