Skip to content

Commit

Permalink
Merge pull request #6 from WolffunGame/feature/fix_exception
Browse files Browse the repository at this point in the history
Feature/fix exception
  • Loading branch information
HoCongThanh authored Oct 23, 2023
2 parents eead45d + cd8e4e5 commit a263c96
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 27 additions & 3 deletions Assets/FishNet/Runtime/Managing/Server/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,24 @@ private void Transport_OnRemoteConnectionState(RemoteConnectionStateArgs args)
{
NetworkManager.Log($"Remote connection started for Id {id}.");
NetworkConnection conn = new NetworkConnection(NetworkManager, id, args.TransportIndex, true);
Clients.Add(args.ConnectionId, conn);
OnRemoteConnectionState?.Invoke(conn, args);

if(Clients.TryGetValue(args.ConnectionId, out var prevConn))
{
// Some error occured, that still connection in Dictionary
Clients.Remove(args.ConnectionId);
}

Clients.TryAdd(args.ConnectionId, conn);

try
{
OnRemoteConnectionState?.Invoke(conn, args);
}
catch (Exception ex)
{
NetworkManager.LogError($"Exception occured when do OnRemoteConnectionState callback: {ex.Message}");
}

//Connection is no longer valid. This can occur if the user changes the state using the OnRemoteConnectionState event.
if (!conn.IsValid)
return;
Expand All @@ -431,7 +447,15 @@ private void Transport_OnRemoteConnectionState(RemoteConnectionStateArgs args)
if (Clients.TryGetValueIL2CPP(id, out NetworkConnection conn))
{
conn.SetDisconnecting(true);
OnRemoteConnectionState?.Invoke(conn, args);

try
{
OnRemoteConnectionState?.Invoke(conn, args);
}
catch (Exception ex)
{
NetworkManager.LogError($"Exception occured when do OnRemoteConnectionState callback: {ex.Message}");
}
Clients.Remove(id);
Objects.ClientDisconnected(conn);
BroadcastClientConnectionChange(false, conn);
Expand Down
2 changes: 1 addition & 1 deletion Assets/FishNet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.fishnet",
"displayName": "FishNet - Unity Networking Evolved",
"description": "FishNet - Unity Networking Evolved",
"version": "3.7.26",
"version": "3.7.27",
"unity": "2021.3",
"license": "MIT",
"repository": {
Expand Down

0 comments on commit a263c96

Please sign in to comment.