-
Notifications
You must be signed in to change notification settings - Fork 447
OnClientDisconnectCallback not triggered if server disconnects client #2064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We possibly need to improve the documentation on this method. The intended usage of OnClientDisconnectedCallback is:
The original logic behind this was:
However, there are discussions about further improving the connect disconnect process and we are definitely looking at several possibilities that would provide some form of event even if it is the local system disconnecting itself and/or shutting itself down. Until we determine the better approach, if you could further describe your scenario where on the server-side you have script that disconnects the client but then in some other server-side script it requires the OnClientDisconnectedCallback to be triggered in order to (insert what that code does here). I might be able to provide a (hopefully) simple work around. |
OK, if that's the intended use that's fine, though indeed the documentation could be clearer. I was using this callback for cleanup and to have the client return itself to the login scene, but it was easy enough to work around. |
Just ran through the same issue. My 2 cents, if the current behavior stays, the name of this event needs to change, because it is simply not accurate, changing the documentation alone will still lead to confusion. When we encounter a clear and simple name, we often don't bother digging deeper into the documentation, this is a perfect example of that, the name "OnClientDisconnectedCallback" is very simple, clear and makes the intention obvious, yet the actual behavior is not reflective of the name; this event is not always raised as the name describes, |
@TheCaveOfWonders
Under the first line of thinking, this would always be "remote relative" and not specific to the instance running:
Under the second line of thinking, this would be relative to the local and remote instances:
I believe the correct path (at least my personal opinion) is to improve how NGO delivers notifications. Notifications for a client being disconnected should include additional information to distinguish between a local disconnection and a remote disconnection. Currently, it only delivers a client identifier that is no longer valid when a local player disconnects itself. The tough part with SDK development is determining when to make a change to an API that could require users to make changes on their end (i.e. a "breaking change") even if it will improve a weak spot/flaw in the original implementation. The more feedback we get for issues of this nature the more we can make clear justifications for temporary adjustments that might deviate from the original intention but will reduce the user pain associated with it. So, with that all said... 😸 Let me review over that area of code and see if I can whip up a quick PR that would lean towards the second line of thinking. |
I was about to open a bug report on this but found it here. I encountered the same problem. I saw the OnClientDisconnectCallback and was sure this would be called when the client is disconnected. When NetworkManager.Singleton.DisconnectClient is called, I expected this to also invoke the callback. I can see the reason behind, if I called Disconnect I already know that the client is disconnecting so I won't have to use the callback, but in general it makes sense that when a client disconnects it will also invoke the ClientDisconnect callback. |
@NoelStephensUnity Basically this used to not get called on the side that initiated the disconnect. |
I'm getting some behaviour that isn't as described in the NGO 1.6 documentation regarding OnClientDisconnect callback events. The documentation states:- "When disconnect notifications are triggered:
I'm experiencing something different. So for example if I have a Host (clientId==0) and 2 clients connected (clientId==1 & clientId==2), then if the Host shuts itself down (using NetworkManager.Singleton.Shutdown()) then I'm seeing the following:-
This isn't the behaviour in the documentation. According to the documentation, if I'm reading it correctly, the OnClientDisconnect event should be called on Client 1 for Client 1 disconnecting, on Client 2 for Client 2 disconnecting (Bullet 1 - since these disconnections were triggered by the host shutting itself down). The server/host shouldn't be notified (Bullet 2 - since the server/host initiated the disconnect). And Bullet 3 shouldn't apply since it's not a network interruption. So either the documentation is incorrect, or there is something else going on .. |
@LordDarkenon
However, it looks like the
I have upgraded this to a bug and we will address the issue. |
Unity 2022.3.17f1 If a client in 'client' mode disconnects - In both cases, disconnect is triggered by calling Should I provide a sample scene? Could this issue be reopened? |
Well, I will add this into the next update, but for the time being you can always subscribe to the Good catch and low hanging fruit to fix. |
#2822 will be in the next update. |
So for fix #2822 how will that work? If you shut down the Host-Server will OnClientDisconnected just be triggered on the Host-Client? Will OnClientDisconnected be triggered or not on other clients informing them that client0 disconnected? Just trying to anticipate the impact of this on my code, since by changing this you will impact existing code that since NGO 1.8.0 now doesn't expect OnClientDisconnected to be triggered on the Host-Client or other connected clients when the Host-Server (client 0) disconnects. In fact NGO 1.8.0 implemented a breaking change from NGO 1.7.1. In 1.7.1 if the host/server disconnected, then the clients got a disconnect message that client 0 disconnected. With NGO 1.8.0 the clients no longer get a message that client 0 disconnected if the host/server disconnects. This threw me when I updated to NGO 1.8.0, and after some debugging I realised what had changed, and had to go through my code and refactor it to take this into account. So I'd rather that the clients don't get a disconnect message if the host/server disconnects for #2822! |
Also the documentation for NGO 1.8.0 appears to be incorrect regarding Client DisconnectionNotifications (https://docs-multiplayer.unity3d.com/netcode/current/components/networkmanager/#client-disconnection-notifications). It states that :- When a server "logically" disconnects a client. When a client "logically" disconnects itself. In fact disconnection notifications are generated for both those situations - which I think is correct and logical. For example, if the server/host shuts down client 1 using NetworkManager.Singleton.DisconnectClient(1), both the server/host and client 1 get a disconnect message that clientId = 1 has disconnected. Also, for example, if client 1 shuts down (using NetworkManager.Singleton.ShutDown()), both the server/host and client 1 get a disconnect message that clientId = 1 has disconnected. As I said, I think this is logical and correct and it's the documentation that is wrong (and needs to be corrected because it's just confusing). |
Description
When the server disconnects a client through NetworkManager.Singleton.DisconnectClient([clientId]), OnClientDisconnectCallback is not triggered. It is triggered when the client disconnects itself.
Reproduce Steps
Actual Outcome
The function subscribed to OnClientDisconnectCallback is not called.
Expected Outcome
The function subscribed to OnClientDisconnectCallback is always called, regardless of how the client got disconnected.
Environment
Additional Context
Possibly related to #795
The text was updated successfully, but these errors were encountered: