Skip to content

Commit 6b89c9b

Browse files
committed
Adding base online state to reduce duplication
1 parent 9e83512 commit 6b89c9b

File tree

8 files changed

+29
-26
lines changed

8 files changed

+29
-26
lines changed

Assets/Scripts/ConnectionManagement/ConnectionState/ClientConnectingState.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Unity.Multiplayer.Samples.BossRoom
1313
/// entering. If successful, transitions to the ClientConnected state. If not, transitions to the Offline state. If
1414
/// given a disconnect reason first, transitions to the DisconnectingWithReason state.
1515
/// </summary>
16-
class ClientConnectingState : ConnectionState
16+
class ClientConnectingState : OnlineState
1717
{
1818
[Inject]
1919
protected LobbyServiceFacade m_LobbyServiceFacade;
@@ -39,12 +39,6 @@ public override void OnClientDisconnect(ulong _)
3939
m_ConnectionManager.ChangeState(m_ConnectionManager.m_Offline);
4040
}
4141

42-
public override void OnUserRequestedShutdown()
43-
{
44-
m_ConnectStatusPublisher.Publish(ConnectStatus.UserRequestedDisconnect);
45-
m_ConnectionManager.ChangeState(m_ConnectionManager.m_Offline);
46-
}
47-
4842
public override void OnDisconnectReasonReceived(ConnectStatus disconnectReason)
4943
{
5044
m_ConnectStatusPublisher.Publish(disconnectReason);

Assets/Scripts/ConnectionManagement/ConnectionState/ClientReconnectingState.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ public override void OnClientDisconnect(ulong _)
5959
}
6060
}
6161

62-
public override void OnUserRequestedShutdown()
63-
{
64-
m_ConnectStatusPublisher.Publish(ConnectStatus.UserRequestedDisconnect);
65-
m_ConnectionManager.ChangeState(m_ConnectionManager.m_Offline);
66-
}
67-
6862
public override void OnDisconnectReasonReceived(ConnectStatus disconnectReason)
6963
{
7064
m_ConnectStatusPublisher.Publish(disconnectReason);

Assets/Scripts/ConnectionManagement/ConnectionState/ConnectionState.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Unity.Multiplayer.Samples.BossRoom
88
{
99
/// <summary>
10-
/// Base class representing a connection state. Contains a static member for each possible state.
10+
/// Base class representing a connection state.
1111
/// </summary>
1212
abstract class ConnectionState
1313
{
@@ -40,9 +40,6 @@ public virtual void OnDisconnectReasonReceived(ConnectStatus disconnectReason) {
4040

4141
public virtual void ApprovalCheck(NetworkManager.ConnectionApprovalRequest request, NetworkManager.ConnectionApprovalResponse response) { }
4242

43-
public virtual void OnTransportFailure()
44-
{
45-
m_ConnectionManager.ChangeState(m_ConnectionManager.m_Offline);
46-
}
43+
public virtual void OnTransportFailure() { }
4744
}
4845
}

Assets/Scripts/ConnectionManagement/ConnectionState/DisconnectingWithReasonState.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Unity.Multiplayer.Samples.BossRoom
55
/// Since our disconnect process runs in multiple steps host side, this state is the first step client side. This
66
/// state simply waits for the actual disconnect, then transitions to the offline state.
77
/// </summary>
8-
class DisconnectingWithReasonState : ConnectionState
8+
class DisconnectingWithReasonState : OnlineState
99
{
1010
public override void Enter() { }
1111

@@ -15,10 +15,5 @@ public override void OnClientDisconnect(ulong _)
1515
{
1616
m_ConnectionManager.ChangeState(m_ConnectionManager.m_Offline);
1717
}
18-
19-
public override void OnUserRequestedShutdown()
20-
{
21-
m_ConnectionManager.ChangeState(m_ConnectionManager.m_Offline);
22-
}
2318
}
2419
}

Assets/Scripts/ConnectionManagement/ConnectionState/HostingState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Unity.Multiplayer.Samples.BossRoom
1313
/// Connection state corresponding to a listening host. Handles incoming client connections. When shutting down or
1414
/// being timed out, transitions to the Offline state.
1515
/// </summary>
16-
class HostingState : ConnectionState
16+
class HostingState : OnlineState
1717
{
1818
[Inject]
1919
LobbyServiceFacade m_LobbyServiceFacade;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Unity.Multiplayer.Samples.BossRoom
2+
{
3+
/// <summary>
4+
/// Base class representing an online connection state.
5+
/// </summary>
6+
abstract class OnlineState : ConnectionState
7+
{
8+
9+
public override void OnUserRequestedShutdown()
10+
{
11+
m_ConnectStatusPublisher.Publish(ConnectStatus.UserRequestedDisconnect);
12+
m_ConnectionManager.ChangeState(m_ConnectionManager.m_Offline);
13+
}
14+
15+
public override void OnTransportFailure()
16+
{
17+
m_ConnectionManager.ChangeState(m_ConnectionManager.m_Offline);
18+
}
19+
}
20+
}

Assets/Scripts/ConnectionManagement/ConnectionState/OnlineState.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/ConnectionManagement/ConnectionState/StartingHostState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Unity.Multiplayer.Samples.BossRoom
1111
/// Connection state corresponding to a host starting up. Starts the host when entering the state. If successful,
1212
/// transitions to the Hosting state, if not, transitions back to the Offline state.
1313
/// </summary>
14-
class StartingHostState : ConnectionState
14+
class StartingHostState : OnlineState
1515
{
1616
[Inject]
1717
LobbyServiceFacade m_LobbyServiceFacade;

0 commit comments

Comments
 (0)