/// <summary> /// An endless coroutine which handles when new clients are connected, /// and instantiates internal clients on unity threads. /// </summary> /// <returns></returns> public IEnumerator WaitForClients() { while (true) { while (HeadlessServer.tcpClients.Count > 0) { if (HeadlessServer.tcpClients.TryDequeue(out TcpClient tcpClient)) { HeadlessServerClient client = new HeadlessServerClient(tcpClient); StartCoroutine(client.ListenForMessages()); } } yield return(null); } }
public static void Disconnect(HeadlessServerClient disconnectedClient) { HeadlessServerActor disconnectedActor = null; foreach (HeadlessServerActor actor in Players) { if (actor.Client == disconnectedClient) { disconnectedActor = actor; SendDisconnectNotification(disconnectedActor.PlayerID); } } if (disconnectedActor != null) { Players.Remove(disconnectedActor); Clients.Remove(disconnectedClient); } }