// Start void Start() { NetworkTransport.Init(); reliableChannel = config.AddChannel(QosType.Reliable); unreliableChannel = config.AddChannel(QosType.Unreliable); var hostTopology = new HostTopology(config, maxConnections); hostId = NetworkTransport.AddHost(hostTopology, port); receiveBuffer = new byte[bufferSize]; onConnect += (connectionId) => { Debug.Log("Player " + connectionId + " connected."); var player = new NetworkTarget(connectionId); NetworkPlayers.Add(player); // Send connected message player.Send(ServerMessage.Connected); }; onDisconnect += (connectionId) => { Debug.Log("Player " + connectionId + " disconnected."); NetworkPlayers.Remove(NetworkPlayers.Find(connectionId)); }; isStarted = true; }
// Only called by Unity on server public void uLink_OnPlayerDisconnected(uLink.NetworkPlayer player) { uLink.Network.RemoveRPCs(player); uLink.Network.DestroyPlayerObjects(player); NetworkPlayers.Remove(player); }