public XandO(Client P1, NotificableClient NotificableP2, List <Game> Games, string Username) { this.Games = Games; Player1 = new XandO_Player(P1); Thread TimeOut = new Thread(() => { while (this.Player2 == null) { Thread.Sleep(1000); } }); TimeOut.Start(); new Thread(() => { if (!TimeOut.Join(TimeSpan.FromSeconds(20))) { Player1.Dispose(); Games.Remove(this); } }).Start(); NotificableP2.Send(new string[] { _Details.GameInvitation_XandO, base.GameId, Username }); }
private void RedirectClient(object newClient) { TcpClient Client = (TcpClient)newClient; NetworkStream ns = Client.GetStream(); string[] Request = CryptDecryptData.DecryptData(_Utils.ReadStreamString(ns)); //1.GameType //2.Intent-p1,p2 // -p1 //3.GameId switch (Request[0]) { case _Details.Game_XandO: { if (Request[1] == "CREATE") { string NrTel_P1 = Request[2]; string NrTel_P2 = Request[3]; NotificableClient NotificableP2 = null; foreach (Excursie e in Excursii) { foreach (NotificableClient nc in e.NotificableClients) { if (nc.NumarTelefon == NrTel_P2) { NotificableP2 = nc; } } } XandO newBounceGame = new XandO(new Client(Client, ns), NotificableP2, Games, GetUserName(NrTel_P1)); Games.Add((Game)newBounceGame); } if (Request[1] == "JOIN") { string GameId = Request[2]; bool IfExist = false; foreach (XandO bg in Games.ToList()) { if (bg.GameId == GameId) { IfExist = true; bg.Join(new Client(Client, ns)); break; } } if (IfExist) { } else { } } } break; case _Details.Game_Bounce: { if (Request[1] == "CREATE") { string NrTel_P1 = Request[2]; string NrTel_P2 = Request[3]; NotificableClient NotificableP2 = null; foreach (Excursie e in Excursii) { foreach (NotificableClient nc in e.NotificableClients) { if (nc.NumarTelefon == NrTel_P2) { NotificableP2 = nc; } } } BounceGame newBounceGame = new BounceGame(new Client(Client, ns), NotificableP2, Games, GetUserName(NrTel_P1)); Games.Add(newBounceGame); } if (Request[1] == "JOIN") { string GameId = Request[2]; bool IfExist = false; foreach (BounceGame bg in Games) { if (bg.GameId == GameId) { IfExist = true; bg.Join(new Client(Client, ns)); break; } } if (IfExist) { } else { } } } break; } }