Skip to content

Commit 817f52d

Browse files
committed
adding support for deleted lobby events
1 parent 506368b commit 817f52d

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

Assets/Scripts/UnityServices/Lobbies/LobbyServiceFacade.cs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class LobbyServiceFacade : IDisposable, IStartable
3737

3838
public Lobby CurrentUnityLobby { get; private set; }
3939

40-
LobbyEventCallbacks m_LobbyEventCallbacks;
4140
ILobbyEvents m_LobbyEvents;
4241

4342
bool m_IsTracking = false;
@@ -90,8 +89,6 @@ public Task EndTracking()
9089
var task = Task.CompletedTask;
9190
if (CurrentUnityLobby != null)
9291
{
93-
CurrentUnityLobby = null;
94-
9592
var lobbyId = m_LocalLobby?.LobbyID;
9693

9794
if (!string.IsNullOrEmpty(lobbyId))
@@ -105,9 +102,6 @@ public Task EndTracking()
105102
task = LeaveLobbyAsync(lobbyId);
106103
}
107104
}
108-
109-
m_LocalUser.ResetState();
110-
m_LocalLobby?.Reset(m_LocalUser);
111105
}
112106

113107
m_LobbyEvents?.UnsubscribeAsync();
@@ -222,27 +216,44 @@ public Task EndTracking()
222216
return (false, null);
223217
}
224218

225-
async void OnLobbyChanges(ILobbyChanges changes)
219+
void ResetLobby()
226220
{
227-
Debug.Log("Lobby updated");
228-
changes.ApplyToLobby(CurrentUnityLobby);
229-
m_LocalLobby.ApplyRemoteData(CurrentUnityLobby);
221+
CurrentUnityLobby = null;
222+
m_LocalUser.ResetState();
223+
m_LocalLobby?.Reset(m_LocalUser);
230224

231-
// as client, check if host is still in lobby
232-
if (!m_LocalUser.IsHost)
225+
// no need to disconnect Netcode, it should already be handled by Netcode's callback to disconnect
226+
}
227+
228+
async void OnLobbyChanges(ILobbyChanges changes)
229+
{
230+
if (changes.LobbyDeleted)
233231
{
234-
foreach (var lobbyUser in m_LocalLobby.LobbyUsers)
232+
Debug.Log("Lobby deleted");
233+
ResetLobby();
234+
}
235+
else
236+
{
237+
Debug.Log("Lobby updated");
238+
changes.ApplyToLobby(CurrentUnityLobby);
239+
m_LocalLobby.ApplyRemoteData(CurrentUnityLobby);
240+
241+
// as client, check if host is still in lobby
242+
if (!m_LocalUser.IsHost)
235243
{
236-
if (lobbyUser.Value.IsHost)
244+
foreach (var lobbyUser in m_LocalLobby.LobbyUsers)
237245
{
238-
return;
246+
if (lobbyUser.Value.IsHost)
247+
{
248+
return;
249+
}
239250
}
240-
}
241251

242-
m_UnityServiceErrorMessagePub.Publish(new UnityServiceErrorMessage("Host left the lobby", "Disconnecting.", UnityServiceErrorMessage.Service.Lobby));
243-
await EndTracking();
252+
m_UnityServiceErrorMessagePub.Publish(new UnityServiceErrorMessage("Host left the lobby", "Disconnecting.", UnityServiceErrorMessage.Service.Lobby));
253+
await EndTracking();
244254

245-
// no need to disconnect Netcode, it should already be handled by Netcode's callback to disconnect
255+
// no need to disconnect Netcode, it should already be handled by Netcode's callback to disconnect
256+
}
246257
}
247258
}
248259

@@ -278,7 +289,7 @@ async void SubscribeToJoinedLobby()
278289
lobbyEventCallbacks.LobbyChanged += OnLobbyChanges;
279290
lobbyEventCallbacks.KickedFromLobby += OnKickedFromLobby;
280291
lobbyEventCallbacks.LobbyEventConnectionStateChanged += OnLobbyEventConnectionStateChanged;
281-
m_LobbyEvents = await m_LobbyApiInterface.SubscribeToLobby(m_LocalLobby.LobbyID, m_LobbyEventCallbacks);
292+
m_LobbyEvents = await m_LobbyApiInterface.SubscribeToLobby(m_LocalLobby.LobbyID, lobbyEventCallbacks);
282293
m_JoinedLobbyContentHeartbeat.BeginTracking();
283294
}
284295

@@ -338,6 +349,7 @@ public async Task LeaveLobbyAsync(string lobbyId)
338349
try
339350
{
340351
await m_LobbyApiInterface.RemovePlayerFromLobby(uasId, lobbyId);
352+
ResetLobby();
341353
}
342354
catch (LobbyServiceException e)
343355
{
@@ -376,6 +388,7 @@ public async Task DeleteLobbyAsync(string lobbyId)
376388
try
377389
{
378390
await m_LobbyApiInterface.DeleteLobby(lobbyId);
391+
ResetLobby();
379392
}
380393
catch (LobbyServiceException e)
381394
{

0 commit comments

Comments
 (0)