public void WaitForConnection() { try { InitServer(); Console.WriteLine("Сервер запущен.."); while (true) { TcpClient NewClient = tcpListener.AcceptTcpClient(); Console.WriteLine("Поключился клиент : " + NewClient.Client.RemoteEndPoint.ToString()); GwentClient ClientObj = new GwentClient(NewClient, this); if (ClientsQuery.Count >= 1) { List <GwentClient> Pair = FindPairs(ClientObj, ClientsQuery); Console.WriteLine("Клиенты обьеденились в группу : " + Pair[0].Client.Client.RemoteEndPoint.ToString() + " " + Pair[1].Client.Client.RemoteEndPoint.ToString()); Thread NewThread = new Thread(() => Game(Pair)); NewThread.Start(); } else { if (ClientObj != null) { Console.WriteLine("В очередь добавлен клиент : " + NewClient.Client.RemoteEndPoint.ToString()); ClientsQuery.Add(ClientObj); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private List <GwentClient> FindPairs(GwentClient client, List <GwentClient> Query) { List <GwentClient> Pair = new List <GwentClient>(); Pair.Add(client); Pair.Add(ClientsQuery[0]); ClientsQuery.RemoveAt(0); return(Pair); }
private bool SendToClient(GwentClient Client, Package pkg) { Client.SendMessage(pkg); Package RecievedRkg = Client.GetMessage(); if ((RecievedRkg as ICommandable).Command != ConfigurationManager.AppSettings["IsGood"]) { return(false); } else { return(true); } }
private void AddToQuery(GwentClient Client) { ClientsQuery.Add(Client); }
private Package GetFromClient(GwentClient Client) { Package RecivedPkg = Client.GetMessage(); return(RecivedPkg); }