UNET - Disconnect a Player during OnServerAddPlayer

Hi guys,

I’m looking for a way to kick a player during OnServerAddPlayer in my custom UNETManager. I’ve seen similar topics around here but none are attempting to do the disconnect this early.

Network.CloseConnection needs a NetworkPlayer, which I don’t have yet. All I have is a NetworkConnection. If I call Disconnect on that NetworkConnection it does kick the player but generates a few errors on the Server (Failed to send internal buffer channel:0 bytesToSend:1302
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate())

Any advice? Thanks in advance.

public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
{
    if (TestToSeeIfPlayerCanConnect())
    {
        // Carry on connecting as normal...
    }
    else
    {
         // this causes errors
         conn.Disconnect();
    }
}

Well from tinkering around it seems that doing:

conn.Dispose();
conn.Disconnect();

seems to work without generating errors (although there is a warning). Whether or not this is the right approach remains to be seen, if anyone has any better ideas then please let me know!