-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding disconnect reason to client disconnect (#820)
BREAKING CHANGE: Client.Disconnected now has a Reason argument
- Loading branch information
1 parent
89aca7b
commit e597570
Showing
20 changed files
with
328 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using Mirage.SocketLayer; | ||
|
||
namespace Mirage | ||
{ | ||
/// <summary> | ||
/// Reason why Client was stopped or disconnected | ||
/// </summary> | ||
/// <remarks> | ||
/// Use different enums than SocketLayer so that: | ||
/// User doesn't need to add reference to socket layer to use event; | ||
/// Give high level reason so that they are easierto understand by the end user. | ||
/// </remarks> | ||
[Serializable] | ||
public enum ClientStoppedReason | ||
{ | ||
/// <summary>No reason given</summary> | ||
None = 0, | ||
|
||
/// <summary>Connecting timed out | ||
/// <para>Server not sending replies</para></summary> | ||
Timeout = 1, | ||
/// <summary>Connection disconnect called locally</summary> | ||
LocalConnectionClosed = 2, | ||
/// <summary>Connection disconnect called on server</summary> | ||
RemoteConnectionClosed = 3, | ||
|
||
/// <summary>Server rejected connecting because it was full</summary> | ||
ServerFull = 4, | ||
/// <summary>Server did not reply</summary> | ||
ConnectingTimeout = 5, | ||
/// <summary>Disconnect called locally before server replies with connected</summary> | ||
ConnectingCancel = 6, | ||
} | ||
|
||
|
||
internal static class StoppedReasonExtensions | ||
{ | ||
public static ClientStoppedReason ToClientStoppedReason(this DisconnectReason reason) | ||
{ | ||
switch (reason) | ||
{ | ||
default: | ||
case DisconnectReason.None: return ClientStoppedReason.None; | ||
case DisconnectReason.Timeout: return ClientStoppedReason.Timeout; | ||
case DisconnectReason.RequestedByRemotePeer: return ClientStoppedReason.RemoteConnectionClosed; | ||
case DisconnectReason.RequestedByLocalPeer: return ClientStoppedReason.LocalConnectionClosed; | ||
} | ||
} | ||
|
||
public static ClientStoppedReason ToClientStoppedReason(this RejectReason reason) | ||
{ | ||
switch (reason) | ||
{ | ||
default: | ||
case RejectReason.None: return ClientStoppedReason.None; | ||
case RejectReason.Timeout: return ClientStoppedReason.ConnectingTimeout; | ||
case RejectReason.ServerFull: return ClientStoppedReason.ServerFull; | ||
case RejectReason.ClosedByPeer: return ClientStoppedReason.ConnectingCancel; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using UnityEngine.Events; | ||
|
||
namespace Mirage.Events | ||
{ | ||
[Serializable] public class DisconnectEvent : UnityEvent<ClientStoppedReason> { } | ||
|
||
/// <summary> | ||
/// Event fires from a <see cref="NetworkClient">NetworkClient</see> when it fails to connect to the server | ||
/// </summary> | ||
[Serializable] public class DisconnectAddLateEvent : AddLateEvent<ClientStoppedReason, DisconnectEvent> { } | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Mirage/Runtime/Events/DisconnectAddLateEvent.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.