Is it possible to send additional data when connecting to or disconnecting from a server? I would like to make it so when a client connects to a server with a password, the client can immediately send a password for authorization. Also, I would like for the server to be able to append data to a disconnection to notify the player why they were disconnected (ex: password authorization failed, kicked, banned, etc).
I have tried this on the server-side to disconnect clients that send an incorrect password:
byte[] buffer = new byte[] { (byte)NetworkMessage.AuthorizationFailure };
byte error;
NetworkTransport.Send(hostId, connectionId, NetworkManager.reliableChannel, buffer, buffer.Length, out error);
Disconnect(connectionId);
But the disconnect event always gets received by the client before the authorization failure network message. I could just remove the server-side disconnect call and make the client disconnect themselves when the client receives the AuthorizationFailure message, but this can be exploited without adding more security measures (the client can just ignore the AuthorizationFailure message to avoid disconnection). It would be much easier if I could attach the data to the same packet used to send the disconnect event to the client.