11using System ;
2+ using BossRoom . Scripts . Shared . Net . UnityServices . Auth ;
23using TMPro ;
34using Unity . Multiplayer . Samples . BossRoom . Client ;
45using Unity . Multiplayer . Samples . BossRoom . Shared . Infrastructure ;
@@ -21,6 +22,7 @@ public class LobbyUIMediator : MonoBehaviour
2122 [ SerializeField ] TextMeshProUGUI m_PlayerNameLabel ;
2223 [ SerializeField ] GameObject m_LoadingSpinner ;
2324
25+ AuthenticationServiceFacade m_AuthenticationServiceFacade ;
2426 LobbyServiceFacade m_LobbyServiceFacade ;
2527 LocalLobbyUser m_LocalUser ;
2628 LocalLobby m_LocalLobby ;
@@ -32,6 +34,7 @@ public class LobbyUIMediator : MonoBehaviour
3234
3335 [ Inject ]
3436 void InjectDependenciesAndInitialize (
37+ AuthenticationServiceFacade authenticationServiceFacade ,
3538 LobbyServiceFacade lobbyServiceFacade ,
3639 LocalLobbyUser localUser ,
3740 LocalLobby localLobby ,
@@ -40,6 +43,7 @@ void InjectDependenciesAndInitialize(
4043 ClientGameNetPortal clientGameNetPortal
4144 )
4245 {
46+ m_AuthenticationServiceFacade = authenticationServiceFacade ;
4347 m_NameGenerationData = nameGenerationData ;
4448 m_LocalUser = localUser ;
4549 m_LobbyServiceFacade = lobbyServiceFacade ;
@@ -72,6 +76,14 @@ public async void CreateLobbyRequest(string lobbyName, bool isPrivate, int maxPl
7276
7377 BlockUIWhileLoadingIsInProgress ( ) ;
7478
79+ bool playerIsAuthorized = await m_AuthenticationServiceFacade . EnsurePlayerIsAuthorized ( ) ;
80+
81+ if ( ! playerIsAuthorized )
82+ {
83+ UnblockUIAfterLoadingIsComplete ( ) ;
84+ return ;
85+ }
86+
7587 var lobbyCreationAttempt = await m_LobbyServiceFacade . TryCreateLobbyAsync ( lobbyName , maxPlayers , isPrivate ) ;
7688
7789 if ( lobbyCreationAttempt . Success )
@@ -102,6 +114,14 @@ public async void QueryLobbiesRequest(bool blockUI)
102114 BlockUIWhileLoadingIsInProgress ( ) ;
103115 }
104116
117+ bool playerIsAuthorized = await m_AuthenticationServiceFacade . EnsurePlayerIsAuthorized ( ) ;
118+
119+ if ( ! playerIsAuthorized )
120+ {
121+ UnblockUIAfterLoadingIsComplete ( ) ;
122+ return ;
123+ }
124+
105125 await m_LobbyServiceFacade . RetrieveAndPublishLobbyListAsync ( ) ;
106126 UnblockUIAfterLoadingIsComplete ( ) ;
107127 }
@@ -110,6 +130,14 @@ public async void JoinLobbyWithCodeRequest(string lobbyCode)
110130 {
111131 BlockUIWhileLoadingIsInProgress ( ) ;
112132
133+ bool playerIsAuthorized = await m_AuthenticationServiceFacade . EnsurePlayerIsAuthorized ( ) ;
134+
135+ if ( ! playerIsAuthorized )
136+ {
137+ UnblockUIAfterLoadingIsComplete ( ) ;
138+ return ;
139+ }
140+
113141 var result = await m_LobbyServiceFacade . TryJoinLobbyAsync ( null , lobbyCode ) ;
114142
115143 if ( result . Success )
@@ -126,6 +154,14 @@ public async void JoinLobbyRequest(LocalLobby lobby)
126154 {
127155 BlockUIWhileLoadingIsInProgress ( ) ;
128156
157+ bool playerIsAuthorized = await m_AuthenticationServiceFacade . EnsurePlayerIsAuthorized ( ) ;
158+
159+ if ( ! playerIsAuthorized )
160+ {
161+ UnblockUIAfterLoadingIsComplete ( ) ;
162+ return ;
163+ }
164+
129165 var result = await m_LobbyServiceFacade . TryJoinLobbyAsync ( lobby . LobbyID , lobby . LobbyCode ) ;
130166
131167 if ( result . Success )
@@ -142,6 +178,14 @@ public async void QuickJoinRequest()
142178 {
143179 BlockUIWhileLoadingIsInProgress ( ) ;
144180
181+ bool playerIsAuthorized = await m_AuthenticationServiceFacade . EnsurePlayerIsAuthorized ( ) ;
182+
183+ if ( ! playerIsAuthorized )
184+ {
185+ UnblockUIAfterLoadingIsComplete ( ) ;
186+ return ;
187+ }
188+
145189 var result = await m_LobbyServiceFacade . TryQuickJoinLobbyAsync ( ) ;
146190
147191 if ( result . Success )
0 commit comments