Skip to content

Commit fe1880e

Browse files
committed
cleaning up
(cherry picked from commit fd9e635)
1 parent 6b3ac0f commit fe1880e

File tree

3 files changed

+24
-29
lines changed

3 files changed

+24
-29
lines changed

Assets/Scripts/Gameplay/ConnectionManagement/ConnectionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void ReceiveServerToClientSetDisconnectReason_CustomMessage(ulong clientID, Fast
150150
}
151151

152152
/// <summary>
153-
/// Sends a DisconnectReason to all connected clients. This should only be done on the server, prior to disconnecting the client.
153+
/// Sends a DisconnectReason to all connected clients. This should only be done on the server, prior to disconnecting the clients.
154154
/// </summary>
155155
/// <param name="status"> The reason for the upcoming disconnect.</param>
156156
public static void SendServerToAllClientsSetDisconnectReason(ConnectStatus status)

Assets/Scripts/Gameplay/ConnectionManagement/ConnectionState/ConnectedConnectionState.cs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,21 @@ public override void Exit() { }
2727

2828
public override void OnClientDisconnect(ulong clientId)
2929
{
30-
// This is also called on the Host when a different client disconnects. To make sure we only handle our own disconnection, verify that we are either
31-
// not a host (in which case we know this is about us) or that the clientID is the same as ours if we are the host.
32-
if (!NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsHost && NetworkManager.Singleton.LocalClientId == clientId)
30+
switch (m_ConnectionManager.DisconnectReason.Reason)
3331
{
34-
//On a client disconnect we want to take them back to the main menu.
35-
//We have to check here in SceneManager if our active scene is the main menu, as if it is, it means we timed out rather than a raw disconnect;
36-
switch (m_ConnectionManager.DisconnectReason.Reason)
37-
{
38-
case ConnectStatus.UserRequestedDisconnect:
39-
case ConnectStatus.HostEndedSession:
40-
m_QuitGameSessionPublisher.Publish(new QuitGameSessionMessage() {UserRequested = false}); // go through the normal leave flow
41-
m_ConnectionManager.ChangeState(ConnectionStateType.Offline);
42-
break;
43-
default:
44-
// try reconnecting
45-
m_ConnectionManager.ChangeState(ConnectionStateType.Reconnecting);
46-
break;
47-
}
48-
49-
m_ConnectStatusPublisher.Publish(m_ConnectionManager.DisconnectReason.Reason);
50-
m_ConnectionManager.DisconnectReason.Clear();
32+
case ConnectStatus.UserRequestedDisconnect:
33+
case ConnectStatus.HostEndedSession:
34+
m_QuitGameSessionPublisher.Publish(new QuitGameSessionMessage() {UserRequested = false}); // go through the normal leave flow
35+
m_ConnectionManager.ChangeState(ConnectionStateType.Offline);
36+
break;
37+
default:
38+
// try reconnecting
39+
m_ConnectionManager.ChangeState(ConnectionStateType.Reconnecting);
40+
break;
5141
}
42+
43+
m_ConnectStatusPublisher.Publish(m_ConnectionManager.DisconnectReason.Reason);
44+
m_ConnectionManager.DisconnectReason.Clear();
5245
}
5346

5447
public override void OnUserRequestedShutdown()

Assets/Scripts/Gameplay/ConnectionManagement/ConnectionState/HostingConnectionState.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Unity.Multiplayer.Samples.Utilities;
66
using Unity.Netcode;
77
using UnityEngine;
8-
using Object = UnityEngine.Object;
98

109
namespace Unity.Multiplayer.Samples.BossRoom
1110
{
@@ -30,7 +29,7 @@ void InjectDependencies(LobbyServiceFacade lobbyServiceFacade,
3029

3130
public override void Enter()
3231
{
33-
var gameState = Object.Instantiate(m_ConnectionManager.GameState);
32+
var gameState = UnityEngine.Object.Instantiate(m_ConnectionManager.GameState);
3433

3534
gameState.Spawn();
3635

@@ -41,7 +40,14 @@ public override void Enter()
4140
SceneLoaderWrapper.Instance.LoadScene("CharSelect", useNetworkSceneManager: true);
4241
}
4342

44-
public override void Exit() { }
43+
public override void Exit()
44+
{
45+
if (m_LobbyServiceFacade.CurrentUnityLobby != null)
46+
{
47+
m_LobbyServiceFacade.DeleteLobbyAsync(m_LobbyServiceFacade.CurrentUnityLobby.Id);
48+
}
49+
SessionManager<SessionPlayerData>.Instance.OnServerEnded();
50+
}
4551

4652
public override void OnClientConnected(ulong clientId)
4753
{
@@ -52,11 +58,7 @@ public override void OnClientDisconnect(ulong clientId)
5258
{
5359
if (clientId == m_ConnectionManager.NetworkManager.LocalClientId)
5460
{
55-
if (m_LobbyServiceFacade.CurrentUnityLobby != null)
56-
{
57-
m_LobbyServiceFacade.DeleteLobbyAsync(m_LobbyServiceFacade.CurrentUnityLobby.Id);
58-
}
59-
SessionManager<SessionPlayerData>.Instance.OnServerEnded();
61+
m_ConnectionManager.ChangeState(ConnectionStateType.Offline);
6062
}
6163
else
6264
{

0 commit comments

Comments
 (0)