private void _ConnectClient(TcpClient client) { if (killServer) { return; } Trace.TraceInformation("Client connected"); var stream = client.GetStream(); LoginToken?token = _ReadLoginToken(stream, 4000); var timeOut = stream.ReadTimeout; if (token == null) { return; } Account theAccount = game.Settings.Accounts.FirstOrDefault (a => a.LoginToken.TokenString == token.Value.TokenString); int indexC; if (theAccount != null) { indexC = game.Settings.Accounts.IndexOf(theAccount); } else { indexC = numberOfGamers; } try { var packet = new ConnectionResponse() { SelfId = indexC, Settings = game.Settings }; Serializer.SerializeWithLengthPrefix <GameDataPacket>(stream, packet, PrefixStyle.Base128); stream.Flush(); } catch (IOException) { try { stream.Close(); } catch (Exception) { } return; } ServerGamer gamer = Gamers[indexC]; gamer.AddStream(stream); gamer.IsSpectator = (indexC == numberOfGamers); if (indexC != numberOfGamers) { gamer.StartReceiver(); SetOnlineStatus(indexC, OnlineStatus.Online); } }