Esempio n. 1
0
 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);
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
 private void AddToQuery(GwentClient Client)
 {
     ClientsQuery.Add(Client);
 }
Esempio n. 5
0
        private Package GetFromClient(GwentClient Client)
        {
            Package RecivedPkg = Client.GetMessage();

            return(RecivedPkg);
        }