public async void Host() { Start(); Hosting = true; _running = true; var unicast = _game.LobbyManager.Unicast; _server = new TcpListener(unicast.Address, Port); _server.Start(); while (_running) { if (_cancelTokenSource == null || _cancelTokenSource.IsCancellationRequested) { _cancelTokenSource = new CancellationTokenSource(); _cancelToken = _cancelTokenSource.Token; } var client = await Task.Run( () => _server.AcceptTcpClientAsync(), _cancelToken); var skirmishClient = new SkirmishClient(this, client); var result = this.AddClient(skirmishClient); if (!result) { skirmishClient.Close(); } } _server.Stop(); }
private bool AddClient(SkirmishClient skirmishClient) { var slot = _slots.Where(x => x.Type == SkirmishSlot.SlotType.Open).First(); if (slot == null) { return(false); } slot.Type = SkirmishSlot.SlotType.Human; slot.Client = skirmishClient; skirmishClient.Run(); return(true); }