Skip to content

Commit 7ebe629

Browse files
Merge branch 'develop' into fix/fixing-connection-management-test
2 parents 26c4425 + 0c98045 commit 7ebe629

File tree

5 files changed

+62
-25
lines changed

5 files changed

+62
-25
lines changed

Assets/Scripts/Gameplay/GameState/ClientMainMenuState.cs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,31 @@ namespace Unity.BossRoom.Gameplay.GameState
2222
/// </remarks>
2323
public class ClientMainMenuState : GameStateBehaviour
2424
{
25-
public override GameState ActiveState { get { return GameState.MainMenu; } }
26-
27-
[SerializeField] NameGenerationData m_NameGenerationData;
28-
[SerializeField] LobbyUIMediator m_LobbyUIMediator;
29-
[SerializeField] IPUIMediator m_IPUIMediator;
30-
[SerializeField] Button m_LobbyButton;
31-
[SerializeField] GameObject m_SignInSpinner;
32-
[SerializeField] UIProfileSelector m_UIProfileSelector;
33-
[SerializeField] UITooltipDetector m_UGSSetupTooltipDetector;
34-
35-
[Inject] AuthenticationServiceFacade m_AuthServiceFacade;
36-
[Inject] LocalLobbyUser m_LocalUser;
37-
[Inject] LocalLobby m_LocalLobby;
38-
[Inject] ProfileManager m_ProfileManager;
25+
public override GameState ActiveState => GameState.MainMenu;
26+
27+
[SerializeField]
28+
NameGenerationData m_NameGenerationData;
29+
[SerializeField]
30+
LobbyUIMediator m_LobbyUIMediator;
31+
[SerializeField]
32+
IPUIMediator m_IPUIMediator;
33+
[SerializeField]
34+
Button m_LobbyButton;
35+
[SerializeField]
36+
GameObject m_SignInSpinner;
37+
[SerializeField]
38+
UIProfileSelector m_UIProfileSelector;
39+
[SerializeField]
40+
UITooltipDetector m_UGSSetupTooltipDetector;
41+
42+
[Inject]
43+
AuthenticationServiceFacade m_AuthServiceFacade;
44+
[Inject]
45+
LocalLobbyUser m_LocalUser;
46+
[Inject]
47+
LocalLobby m_LocalLobby;
48+
[Inject]
49+
ProfileManager m_ProfileManager;
3950

4051
protected override void Awake()
4152
{
@@ -61,17 +72,12 @@ protected override void Configure(IContainerBuilder builder)
6172
builder.RegisterComponent(m_IPUIMediator);
6273
}
6374

64-
6575
private async void TrySignIn()
6676
{
6777
try
6878
{
69-
var unityAuthenticationInitOptions = new InitializationOptions();
70-
var profile = m_ProfileManager.Profile;
71-
if (profile.Length > 0)
72-
{
73-
unityAuthenticationInitOptions.SetProfile(profile);
74-
}
79+
var unityAuthenticationInitOptions =
80+
m_AuthServiceFacade.GenerateAuthenticationOptions(m_ProfileManager.Profile);
7581

7682
await m_AuthServiceFacade.InitializeAndSignInAsync(unityAuthenticationInitOptions);
7783
OnAuthSignIn();
@@ -92,6 +98,7 @@ private void OnAuthSignIn()
9298
Debug.Log($"Signed in. Unity Player ID {AuthenticationService.Instance.PlayerId}");
9399

94100
m_LocalUser.ID = AuthenticationService.Instance.PlayerId;
101+
95102
// The local LobbyUser object will be hooked into UI before the LocalLobby is populated during lobby join, so the LocalLobby must know about it already when that happens.
96103
m_LocalLobby.AddUser(m_LocalUser);
97104
}
@@ -103,6 +110,7 @@ private void OnSignInFailed()
103110
m_LobbyButton.interactable = false;
104111
m_UGSSetupTooltipDetector.enabled = true;
105112
}
113+
106114
if (m_SignInSpinner)
107115
{
108116
m_SignInSpinner.SetActive(false);

Assets/Scripts/Gameplay/UI/UIProfileSelector.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public class UIProfileSelector : MonoBehaviour
2626
[Inject] IObjectResolver m_Resolver;
2727
[Inject] ProfileManager m_ProfileManager;
2828

29+
// Authentication service only accepts profile names of 30 characters or under
30+
const int k_AuthenticationMaxProfileLength = 30;
31+
2932
void Awake()
3033
{
3134
m_ProfileListItemPrototype.gameObject.SetActive(false);
@@ -44,7 +47,8 @@ public void SanitizeProfileNameInputText()
4447

4548
string SanitizeProfileName(string dirtyString)
4649
{
47-
return Regex.Replace(dirtyString, "[^a-zA-Z0-9]", "");
50+
var output = Regex.Replace(dirtyString, "[^a-zA-Z0-9]", "");
51+
return output[..Math.Min(output.Length, k_AuthenticationMaxProfileLength)];
4852
}
4953

5054
public void OnNewProfileButtonPressed()

Assets/Scripts/UnityServices/Auth/AuthenticationServiceFacade.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,28 @@ namespace Unity.BossRoom.UnityServices.Auth
1010
{
1111
public class AuthenticationServiceFacade
1212
{
13-
[Inject] IPublisher<UnityServiceErrorMessage> m_UnityServiceErrorMessagePublisher;
13+
[Inject]
14+
IPublisher<UnityServiceErrorMessage> m_UnityServiceErrorMessagePublisher;
15+
16+
public InitializationOptions GenerateAuthenticationOptions(string profile)
17+
{
18+
try
19+
{
20+
var unityAuthenticationInitOptions = new InitializationOptions();
21+
if (profile.Length > 0)
22+
{
23+
unityAuthenticationInitOptions.SetProfile(profile);
24+
}
25+
26+
return unityAuthenticationInitOptions;
27+
}
28+
catch (Exception e)
29+
{
30+
var reason = $"{e.Message} ({e.InnerException?.Message})";
31+
m_UnityServiceErrorMessagePublisher.Publish(new UnityServiceErrorMessage("Authentication Error", reason, UnityServiceErrorMessage.Service.Authentication, e));
32+
throw;
33+
}
34+
}
1435

1536
public async Task InitializeAndSignInAsync(InitializationOptions initializationOptions)
1637
{
@@ -37,6 +58,7 @@ public async Task SwitchProfileAndReSignInAsync(string profile)
3758
{
3859
AuthenticationService.Instance.SignOut();
3960
}
61+
4062
AuthenticationService.Instance.SwitchProfile(profile);
4163

4264
try
@@ -67,6 +89,7 @@ public async Task<bool> EnsurePlayerIsAuthorized()
6789
{
6890
var reason = $"{e.Message} ({e.InnerException?.Message})";
6991
m_UnityServiceErrorMessagePublisher.Publish(new UnityServiceErrorMessage("Authentication Error", reason, UnityServiceErrorMessage.Service.Authentication, e));
92+
7093
//not rethrowing for authentication exceptions - any failure to authenticate is considered "handled failure"
7194
return false;
7295
}
@@ -78,6 +101,5 @@ public async Task<bool> EnsurePlayerIsAuthorized()
78101
throw;
79102
}
80103
}
81-
82104
}
83105
}

Assets/Scripts/Utils/ProfileManager.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ static string GetProfile()
8080
var hashedBytes = new MD5CryptoServiceProvider()
8181
.ComputeHash(Encoding.UTF8.GetBytes(Application.dataPath));
8282
Array.Resize(ref hashedBytes, 16);
83-
return new Guid(hashedBytes).ToString("N");
83+
// Authentication service only allows profile names of maximum 30 characters. We're generating a GUID based
84+
// on the project's path. Truncating the first 30 characters of said GUID string suffices for uniqueness.
85+
return new Guid(hashedBytes).ToString("N")[..30];
8486
#else
8587
return "";
8688
#endif

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1717
* Replaced our custom pool implementation using queues with ObjectPool (#824)
1818
* Upgraded Boss Room to NGO 1.3.1 (#828) NetworkPrefabs inside NetworkManager's NetworkPrefabs list have been converted to NetworkPrefabsList ScriptableObject.
1919
* Upgraded Boss Room to NGO 1.4.0 (#829)
20+
* Profile names generated are now only 30 characters or under to fit Authentication Service requirements (#831)
2021

2122
### Cleanup
2223
* Clarified a TODO comment inside ClientCharacter, detailing how anticipation should only be executed on owning client players (#786)

0 commit comments

Comments
 (0)