From 037606993a4c4ef635349ee536da6b2c9fa133e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Sun, 8 Jan 2023 23:47:47 +0100 Subject: [PATCH 01/30] test --- WEB/server.php | 1 + 1 file changed, 1 insertion(+) diff --git a/WEB/server.php b/WEB/server.php index 8e2ba21a..f61f2912 100644 --- a/WEB/server.php +++ b/WEB/server.php @@ -107,6 +107,7 @@ while(true) { if (method_exists($requestHandler, $request)) { $function=explode(' ',$request)[0]; echo ($function."\n"); + echo 'SUUUU'.$request; $response = $requestHandler->$function($client, $request); echo 'response : '.$response."\n"; } else { From e7576ba64b4e97e16ba7c7740a32cb2e3123d0f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Sun, 8 Jan 2023 23:54:43 +0100 Subject: [PATCH 02/30] test --- WEB/Model/RequestHandler.php | 13 +++++++------ WEB/server.php | 1 - 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/WEB/Model/RequestHandler.php b/WEB/Model/RequestHandler.php index 0a8cc1bc..b4b1de2a 100644 --- a/WEB/Model/RequestHandler.php +++ b/WEB/Model/RequestHandler.php @@ -17,13 +17,13 @@ class RequestHandler{ $socketsFromQueue[]=$socket; - echo 'ajout de la connecion au tableau des connections en attente'.count($socketsFromQueue).'\n'; + echo 'ajout de la connecion au tableau des connections en attente'.count($socketsFromQueue); // si le nombre de joueur par partie nécessaire est égal au nombre de connection encore dans la file d'attente // alors envoie à l'utilisateur de lancer la partie et ajoute l'ensemble de connection à un tableau de groupe de sockets avec comme paire clés valeurs // l'identifiant de la partie et l'ensemble de connections sinon envoie à tout les utilisateurs en file d'attente qu'il faut rafraichir la page de la file d'attente - echo 'nombre de joueurs en attente : '.count($socketsFromQueue).' nombre de joueurs par partie : '.$playerNumberPerGame.'\n'; + echo 'nombre de joueurs en attente : '.count($socketsFromQueue).' nombre de joueurs par partie : '.$playerNumberPerGame; if(count($socketsFromQueue)==$playerNumberPerGame) { echo 'lancement de la partie\n'; @@ -38,13 +38,14 @@ class RequestHandler{ echo "rafraichissement de la file d'attente\n"; $response="refreshQueue"; } - var_dump($socketsFromQueue); - var_dump($response); + // var_dump($socketsFromQueue); + // var_dump($response); foreach($socketsFromQueue as $sock) { - var_dump($sock); + // var_dump($sock); + echo 'envoie de la réponse au client : '.$response; $result=socket_write($sock,$response,strlen($response)) or die("N'a pas pu écrire à la socket\n"); - var_dump($result); + // var_dump($result); if($result==false) { echo "erreur d'écriture\n"; diff --git a/WEB/server.php b/WEB/server.php index f61f2912..8e2ba21a 100644 --- a/WEB/server.php +++ b/WEB/server.php @@ -107,7 +107,6 @@ while(true) { if (method_exists($requestHandler, $request)) { $function=explode(' ',$request)[0]; echo ($function."\n"); - echo 'SUUUU'.$request; $response = $requestHandler->$function($client, $request); echo 'response : '.$response."\n"; } else { From 7db0daba017caebf55c45c4d41cf6201407d29eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 00:03:00 +0100 Subject: [PATCH 03/30] test --- WEB/Model/RequestHandler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WEB/Model/RequestHandler.php b/WEB/Model/RequestHandler.php index b4b1de2a..0b672a1b 100644 --- a/WEB/Model/RequestHandler.php +++ b/WEB/Model/RequestHandler.php @@ -43,7 +43,7 @@ class RequestHandler{ foreach($socketsFromQueue as $sock) { // var_dump($sock); - echo 'envoie de la réponse au client : '.$response; + echo 'envoie de la réponse au client : '.$response ."\n"; $result=socket_write($sock,$response,strlen($response)) or die("N'a pas pu écrire à la socket\n"); // var_dump($result); if($result==false) @@ -51,6 +51,7 @@ class RequestHandler{ echo "erreur d'écriture\n"; } } + return $response; } public function quitQueue(Socket $client,String $request){ // supprime le socket de la liste des sockets en attente From 02d35df1fb9f4c83bd5ffa9932a9762371dab076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 00:05:06 +0100 Subject: [PATCH 04/30] test --- WEB/Client/Client.php | 52 ++++++++++++++++++++----------------------- WEB/server.php | 5 +++-- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/WEB/Client/Client.php b/WEB/Client/Client.php index 52993d68..1a01af44 100644 --- a/WEB/Client/Client.php +++ b/WEB/Client/Client.php @@ -1,64 +1,60 @@ -findUsersInQueue(); - $numberOfPlayer = count($userGroup); - header('Location : ' . $rep . $vues['queue']); + $numberOfPlayer=count($userGroup); + header('Location : '.$rep.$vues['main']); } - } else { + } + else{ echo "socket_read a échoué : " . socket_strerror(socket_last_error()) . "\n"; break; } - sleep(5); - $i++; - } - require $rep . $vues['erreur']; + } } } } \ No newline at end of file diff --git a/WEB/server.php b/WEB/server.php index 8e2ba21a..362de131 100644 --- a/WEB/server.php +++ b/WEB/server.php @@ -109,13 +109,14 @@ while(true) { echo ($function."\n"); $response = $requestHandler->$function($client, $request); echo 'response : '.$response."\n"; + socket_write($client,$response,strlen($response)); } else { $response = "Invalid request"; - // socket_write($client,$response,strlen($response)); + socket_write($client,$response,strlen($response)); } } else { $response = "Response is false"; - // socket_write($client,$response,strlen($response)); + socket_write($client,$response,strlen($response)); } } } From 0b580dd6bbf4a3f97e1e1f2ad568b989520e9334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 00:07:05 +0100 Subject: [PATCH 05/30] test --- WEB/Client/Client.php | 5 +++-- WEB/Controller/UserController.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/WEB/Client/Client.php b/WEB/Client/Client.php index 1a01af44..e6ff89fa 100644 --- a/WEB/Client/Client.php +++ b/WEB/Client/Client.php @@ -45,9 +45,10 @@ class Client{ echo "socket_read a réussi.\n"; if(strcmp($response,"refreshQueue")==0) { - $userGroup = $userModel->findUsersInQueue(); - $numberOfPlayer=count($userGroup); + // $userGroup = $userModel->findUsersInQueue(); + // $numberOfPlayer=count($userGroup); header('Location : '.$rep.$vues['main']); + break; } } else{ diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 5755ed37..1df09f7a 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -172,10 +172,10 @@ class UserController global $rep, $vues, $error; //$serverAdress,$port; $model = new UserModel(); // $model->addToQueue(); + require($rep . $vues['queue']); $client = Client::getInstance(); // new Queuing(); $client->Queuing(); - require($rep . $vues['queue']); } catch (Exception $e) { $error = $e->getMessage(); require($rep . $vues['erreur']); From 602ef12511a389f43f9fc09a6144edfddeebf576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 00:09:46 +0100 Subject: [PATCH 06/30] test --- WEB/Client/Client.php | 62 ++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/WEB/Client/Client.php b/WEB/Client/Client.php index e6ff89fa..3082634d 100644 --- a/WEB/Client/Client.php +++ b/WEB/Client/Client.php @@ -1,61 +1,63 @@ -findUsersInQueue(); - // $numberOfPlayer=count($userGroup); - header('Location : '.$rep.$vues['main']); - break; - } - } - else{ - echo "socket_read a échoué : " . socket_strerror(socket_last_error()) . "\n"; - break; - } - } + $response = ""; + $response = socket_read($socket, $BUFFER_SIZE); + echo $response; + // while (strcmp($response, "launchGame") != 0) { + // $response = socket_read($socket, $BUFFER_SIZE); + // if ($response != false) { + // echo "socket_read a réussi.\n"; + // if (strcmp($response, "refreshQueue") == 0) { + // // $userGroup = $userModel->findUsersInQueue(); + // // $numberOfPlayer=count($userGroup); + // header('Location : ' . $rep . $vues['main']); + // break; + // } + // } else { + // echo "socket_read a échoué : " . socket_strerror(socket_last_error()) . "\n"; + // break; + // } + // } } } } \ No newline at end of file From 9c799cfc47c5d4eedf2402b2cf4c93c09a49e3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 00:14:23 +0100 Subject: [PATCH 07/30] test --- WEB/Client/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WEB/Client/Client.php b/WEB/Client/Client.php index 3082634d..e0680f9f 100644 --- a/WEB/Client/Client.php +++ b/WEB/Client/Client.php @@ -41,7 +41,7 @@ class Client echo "socket_write a réussi.\n"; } $response = ""; - $response = socket_read($socket, $BUFFER_SIZE); + // $response = socket_read($socket, $BUFFER_SIZE); echo $response; // while (strcmp($response, "launchGame") != 0) { // $response = socket_read($socket, $BUFFER_SIZE); From 3b93613b1fbd21dcc26e55b9cfc6f082446ced53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 00:16:10 +0100 Subject: [PATCH 08/30] test --- WEB/Client/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WEB/Client/Client.php b/WEB/Client/Client.php index e0680f9f..fbfa7bb8 100644 --- a/WEB/Client/Client.php +++ b/WEB/Client/Client.php @@ -40,7 +40,7 @@ class Client } else { echo "socket_write a réussi.\n"; } - $response = ""; + $response = "AAA"; // $response = socket_read($socket, $BUFFER_SIZE); echo $response; // while (strcmp($response, "launchGame") != 0) { From b05e8067e95d6d6bd07dd7a448737e943dc0e231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 00:23:06 +0100 Subject: [PATCH 09/30] test --- WEB/Client/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WEB/Client/Client.php b/WEB/Client/Client.php index fbfa7bb8..e92f9f2a 100644 --- a/WEB/Client/Client.php +++ b/WEB/Client/Client.php @@ -18,7 +18,7 @@ class Client $userModel = new UserModel(); // pas d'arrêt d'éxécution du script (No timeout) - set_time_limit(0); + set_time_limit(20); $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("la socket n'a pas pu être créée ERROR : " . socket_strerror(socket_last_error()) . "\n"); // connecter la socket à l'adresse ip et au port du serveur $result = socket_set_block($socket); From bec438e716aa5895385899dfa39611cba08456b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 00:32:12 +0100 Subject: [PATCH 10/30] test --- WEB/Client/Client.php | 18 +++++++++--------- WEB/Model/RequestHandler.php | 24 ++++++++++++------------ WEB/server.php | 16 ++++++++-------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/WEB/Client/Client.php b/WEB/Client/Client.php index e92f9f2a..e941fc42 100644 --- a/WEB/Client/Client.php +++ b/WEB/Client/Client.php @@ -18,27 +18,27 @@ class Client $userModel = new UserModel(); // pas d'arrêt d'éxécution du script (No timeout) - set_time_limit(20); - $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("la socket n'a pas pu être créée ERROR : " . socket_strerror(socket_last_error()) . "\n"); + set_time_limit(0); + $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("la socket n'a pas pu être créée ERROR : " . socket_strerror(socket_last_error()) . "(Client : Queuing) \n"); // connecter la socket à l'adresse ip et au port du serveur $result = socket_set_block($socket); if ($result === false) { - echo "socket_set_block a échoué : " . socket_strerror(socket_last_error()) . "\n"; + echo "socket_set_block a échoué : " . socket_strerror(socket_last_error()) . " (Client : Queuing)\n"; } else { - echo "socket_set_block a réussi.\n"; + echo "socket_set_block a réussi. (Client : Queuing) \n"; } - $result = socket_connect($socket, $serverAdress, $port) or die("Impossible de se connecter au serveur ERROR : " . socket_strerror(socket_last_error()) . "\n"); + $result = socket_connect($socket, $serverAdress, $port) or die("Impossible de se connecter au serveur ERROR : " . socket_strerror(socket_last_error()) . "(Client : Queuing) \n"); if ($result === false) { // La connexion de la socket à l'adresse et au port a échoué - echo "socket_connect a échoué : " . socket_strerror(socket_last_error()) . "\n"; + echo "socket_connect a échoué : " . socket_strerror(socket_last_error()) . "(Client : Queuing)\n"; } else { - echo "socket_connect a réussi.\n"; + echo "socket_connect a réussi. (Client : Queuing)\n"; $request = "Queuing"; $result = socket_write($socket, $request, strlen($request)); if ($result === false) { - echo "socket_write a échoué : " . socket_strerror(socket_last_error()) . "\n"; + echo "socket_write a échoué : " . socket_strerror(socket_last_error()) . " (Client : Queuing)\n"; } else { - echo "socket_write a réussi.\n"; + echo "socket_write a réussi.(Client : Queuing)\n"; } $response = "AAA"; // $response = socket_read($socket, $BUFFER_SIZE); diff --git a/WEB/Model/RequestHandler.php b/WEB/Model/RequestHandler.php index 0b672a1b..0b8f7e0e 100644 --- a/WEB/Model/RequestHandler.php +++ b/WEB/Model/RequestHandler.php @@ -17,25 +17,25 @@ class RequestHandler{ $socketsFromQueue[]=$socket; - echo 'ajout de la connecion au tableau des connections en attente'.count($socketsFromQueue); + echo 'ajout de la connecion au tableau des connections en attente'.count($socketsFromQueue). '(Queuing : RequestHandler)'; // si le nombre de joueur par partie nécessaire est égal au nombre de connection encore dans la file d'attente // alors envoie à l'utilisateur de lancer la partie et ajoute l'ensemble de connection à un tableau de groupe de sockets avec comme paire clés valeurs // l'identifiant de la partie et l'ensemble de connections sinon envoie à tout les utilisateurs en file d'attente qu'il faut rafraichir la page de la file d'attente - echo 'nombre de joueurs en attente : '.count($socketsFromQueue).' nombre de joueurs par partie : '.$playerNumberPerGame; + echo 'nombre de joueurs en attente : '.count($socketsFromQueue).' nombre de joueurs par partie : '.$playerNumberPerGame.'(Queuing : RequestHandler)'; if(count($socketsFromQueue)==$playerNumberPerGame) { - echo 'lancement de la partie\n'; + echo "lancement de la partie (Queuing : RequestHandler)\n"; $response="launchGame"; $idPartie=$this->partie_gateway->findPartieInQueue(); - echo 'id de la partie : '.$idPartie; + echo 'id de la partie : '.$idPartie ." (Queuing : RequestHandler)\n"; $arraySocketGroup[$idPartie]=$socketsFromQueue; $socketsFromQueue=array(); } else { - echo "rafraichissement de la file d'attente\n"; + echo "rafraichissement de la file d'attente (Queuing : RequestHandler)\n"; $response="refreshQueue"; } // var_dump($socketsFromQueue); @@ -43,12 +43,12 @@ class RequestHandler{ foreach($socketsFromQueue as $sock) { // var_dump($sock); - echo 'envoie de la réponse au client : '.$response ."\n"; - $result=socket_write($sock,$response,strlen($response)) or die("N'a pas pu écrire à la socket\n"); + echo 'envoie de la réponse au client : '.$response ." (Queuing : RequestHandler)\n"; + $result=socket_write($sock,$response,strlen($response)) or die("N'a pas pu écrire à la socket (Queuing : RequestHandler)\n"); // var_dump($result); if($result==false) { - echo "erreur d'écriture\n"; + echo "erreur d'écriture (Queuing : RequestHandler)\n"; } } return $response; @@ -60,7 +60,7 @@ class RequestHandler{ // envoie à tous les utilisateurs en attente de rafraichir la page foreach($socketsFromQueue as $socket) { - socket_write($socket, $response, strlen($response)) or die("N'a pas pu envoyer la réponse au client\n"); + socket_write($socket, $response, strlen($response)) or die("N'a pas pu envoyer la réponse au client (Queuing : RequestHandler)\n"); } } public function quitGame(Socket $client,String $request){ @@ -70,7 +70,7 @@ class RequestHandler{ // envoie à tous les utilisateurs en attente de rafraichir la page foreach($this->arraySocketGroup[explode(" ",$request)[1]] as $socket) { - socket_write($socket, $response, strlen($response)) or die("N'a pas pu envoyer la réponse au client\n"); + socket_write($socket, $response, strlen($response)) or die("N'a pas pu envoyer la réponse au client (Queuing : RequestHandler)\n"); } } public function refreshDashBoard(Socket $client,String $request){ @@ -78,7 +78,7 @@ class RequestHandler{ // envoie à tous les utilisateurs en attente de rafraichir la page foreach($this->arraySocketGroup[explode(" ",$request)[1]] as $socket) { - socket_write($socket, $response, strlen($response)) or die("N'a pas pu envoyer la réponse au client\n"); + socket_write($socket, $response, strlen($response)) or die("N'a pas pu envoyer la réponse au client (Queuing : RequestHandler)\n"); } } public function finishGame(Socket $client,String $request){ @@ -88,7 +88,7 @@ class RequestHandler{ // envoie à tous les utilisateurs en attente de rafraichir la page foreach($this->arraySocketGroup[explode(" ",$request)[1]] as $socket) { - socket_write($socket, $response, strlen($response)) or die("N'a pas pu envoyer la réponse au client\n"); + socket_write($socket, $response, strlen($response)) or die("N'a pas pu envoyer la réponse au client (Queuing : RequestHandler)\n"); } } } \ No newline at end of file diff --git a/WEB/server.php b/WEB/server.php index 362de131..9b7749b8 100644 --- a/WEB/server.php +++ b/WEB/server.php @@ -67,12 +67,12 @@ $client=false; while(true) { // Commencer à écouter sur le port - $result = socket_listen($socket, 10) or die ("N'a pas pu configurer l'écoute sur la socket ERROR : ".socket_strerror(socket_last_error())."\n"); + $result = socket_listen($socket, 10) or die ("N'a pas pu configurer l'écoute sur la socket ERROR : ".socket_strerror(socket_last_error())." (Serveur) \n"); if ($result === false) { // L'écoute sur le port a échoué - echo "socket_listen a échoué : " . socket_strerror(socket_last_error()) . "\n"; + echo "socket_listen a échoué : " . socket_strerror(socket_last_error()) . " (Serveur)\n"; } else { - echo "socket listen sur le port :".$port."\n"; + echo "socket listen sur le port :".$port." (Serveur)\n"; // L'écoute sur le port a réussi } @@ -83,7 +83,7 @@ while(true) { $client=socket_accept($socket); if($client === false) { - echo "N'a pas pu accepter la connection entrante ERROR : ".socket_strerror(socket_last_error())."\n"; + echo "N'a pas pu accepter la connection entrante ERROR : ".socket_strerror(socket_last_error())." (Serveur)\n"; } else { @@ -93,7 +93,7 @@ while(true) { } var_dump($client); - echo "socket_strerror(socket_last_error()) : ".socket_strerror(socket_last_error())."\n"; + echo "socket_strerror(socket_last_error()) : ".socket_strerror(socket_last_error())." (Serveur)\n"; //si $client est dans le tableau des sockets à surveiller en lecture //Met la requête du client dans $request et verifie si la requête est valide @@ -106,10 +106,10 @@ while(true) { $requestHandler = new RequestHandler(); if (method_exists($requestHandler, $request)) { $function=explode(' ',$request)[0]; - echo ($function."\n"); + echo ($function." (Serveur) \n"); $response = $requestHandler->$function($client, $request); - echo 'response : '.$response."\n"; - socket_write($client,$response,strlen($response)); + echo 'response : '.$response." (Serveur)\n"; + // socket_write($client,$response,strlen($response)); } else { $response = "Invalid request"; socket_write($client,$response,strlen($response)); From 1ce5ccdb45eec58049c466271db440523f8c7ad7 Mon Sep 17 00:00:00 2001 From: johan Date: Mon, 9 Jan 2023 08:56:20 +0100 Subject: [PATCH 11/30] test --- WEB/Controller/UserController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 1df09f7a..42c9e972 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -172,10 +172,11 @@ class UserController global $rep, $vues, $error; //$serverAdress,$port; $model = new UserModel(); // $model->addToQueue(); + if (! function_exists('pcntl_fork')) die('PCNTL functions not available on this PHP installation'); require($rep . $vues['queue']); - $client = Client::getInstance(); + //$client = Client::getInstance(); // new Queuing(); - $client->Queuing(); + //$client->Queuing(); } catch (Exception $e) { $error = $e->getMessage(); require($rep . $vues['erreur']); From 04b35471b21bcd79c89e63b60607586f9443383b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 09:43:33 +0100 Subject: [PATCH 12/30] Test multi uniquement en Bd --- WEB/Controller/EnigmeGateway.php | 9 ++ WEB/Controller/PartieGateway.php | 258 ++++++++++++++++++++---------- WEB/Controller/UserController.php | 23 ++- WEB/Model/UserModel.php | 74 +++++---- 4 files changed, 247 insertions(+), 117 deletions(-) diff --git a/WEB/Controller/EnigmeGateway.php b/WEB/Controller/EnigmeGateway.php index f9545f15..67a8dd85 100644 --- a/WEB/Controller/EnigmeGateway.php +++ b/WEB/Controller/EnigmeGateway.php @@ -169,6 +169,15 @@ class EnigmeGateway $tabEnigme=EnigmeFactory::create($results); return $tabEnigme; } + + public function getRandomEnigme() : Enigme + { + $query = "SELECT * FROM Enigme WHERE ordre = 0 ORDER BY RANDOM() LIMIT 1"; + $this->con->executequery($query); + $results = $this->con->getResults(); + $tabEnigme=EnigmeFactory::create($results); + return $tabEnigme[0]; + } public function showAll(): void { $query = "SELECT * FROM Enigme"; diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index 8de62459..2c6d1a72 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -9,9 +9,9 @@ class PartieGateway public function __construct() { global $dsn, $rep, $vues, $error; - try{ - $con = new Connection($dsn); - $this->con = $con; + try { + $con = new Connection($dsn); + $this->con = $con; } catch (Exception $e) { $error = $e->getMessage(); require($rep . $vues['erreur']); @@ -21,7 +21,8 @@ class PartieGateway /** * @param array $listeUtilisateur */ - public function partieInQueueExists() : bool{ + public function partieInQueueExists(): bool + { $query = "SELECT count(*) FROM PARTICIPER WHERE etat = 0"; $this->con->executeQuery($query); $results = $this->con->getResults(); @@ -31,174 +32,263 @@ class PartieGateway return true; } - public function findPartieMaxId() : int{ + public function findPartieMaxId(): int + { $query = "SELECT max(id) FROM Partie"; $this->con->executeQuery($query); - $results=$this->con->getResults(); - if ($results[0]['max(id)']==NULL) + $results = $this->con->getResults(); + if ($results[0]['max(id)'] == NULL) return 0; else return $results[0]['max(id)']; } - public function creerPartieMulti(int $max, array $tabEnigme) : Partie{ - $partie=PartieFactory::createPartieMulti($max+1,$tabEnigme); - $query= "INSERT INTO Partie VALUES (:idPartie,CURRENT_DATE)"; - $this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER))); - if (count($partie->getListeEnigme()) != 0) { - foreach ($partie->getListeEnigme() as $Enigme) { - $query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)"; - $this->con->executeQuery($query, array( - ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), - ':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER) - ) - ); - } - } - return $partie; - } + // public function creerPartieMulti(int $max, array $tabEnigme) : Partie{ + // $partie=PartieFactory::createPartieMulti($max+1,$tabEnigme); + // $query= "INSERT INTO Partie VALUES (:idPartie,CURRENT_DATE)"; + // $this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER))); + // if (count($partie->getListeEnigme()) != 0) { + // foreach ($partie->getListeEnigme() as $Enigme) { + // $query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)"; + // $this->con->executeQuery($query, array( + // ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), + // ':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER) + // ) + // ); + // } + // } + // return $partie; + // } - public function rejoindrePartieMulti(int $idPartieInQueue,array $tabEnigme) : Partie{ - $partie = PartieFactory::createPartieMulti($idPartieInQueue,$tabEnigme); + public function rejoindrePartieMulti(int $idPartieInQueue, array $tabEnigme): Partie + { + $partie = PartieFactory::createPartieMulti($idPartieInQueue, $tabEnigme); return $partie; } - public function findPartieInQueue(){ - $query = "SELECT p.id - FROM Partie p, Participer pa - WHERE pa.etat=0 - AND pa.partie=p.id + public function findPartieInQueue() + { + $query = "SELECT partie + FROM Participer + WHERE etat=0 LIMIT 1"; $this->con->executeQuery($query); $results = $this->con->getResults(); - return $results[0]['id']; + if (empty($results)) { + return 0; + } + return $results[0]['partie']; } - public function creerPartieSolo(Utilisateur $utilisateur){ + public function creerPartieSolo(Utilisateur $utilisateur) + { $query = "SELECT * FROM Enigme WHERE points IS NULL OR points = 0"; $this->con->executeQuery($query); $results = $this->con->getResults(); - $query= "SELECT max(p.id) + $query = "SELECT max(p.id) FROM PARTIE p;"; $this->con->executeQuery($query); - $max=$this->con->getResults()[0]["max"]; - $partie=PartieFactory::createPartieSolo($max,$results); - $query= "INSERT INTO Partie VALUES (:idPartie,:idEnigme)"; + $max = $this->con->getResults()[0]["max"]; + $partie = PartieFactory::createPartieSolo($max, $results); + $query = "INSERT INTO Partie VALUES (:idPartie,:idEnigme)"; $this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER))); - foreach($partie->getListeEnigme() as $Enigme){ - $query= "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)"; + foreach ($partie->getListeEnigme() as $Enigme) { + $query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)"; $this->con->executeQuery($query, array( - ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), - ':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER))); + ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), + ':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER) + ) + ); } - foreach($partie->getListeEnigme() as $Enigme){ - $query= "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)"; + foreach ($partie->getListeEnigme() as $Enigme) { + $query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)"; $this->con->executeQuery($query, array( - ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), - ':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER))); + ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), + ':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER) + ) + ); } - $query= "INSERT INTO Participer VALUES (:idPartie, :idUtilisateur, TRUE)"; + $query = "INSERT INTO Participer VALUES (:idPartie, :idUtilisateur, TRUE)"; $this->con->executeQuery($query, array( - 'idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), - 'idUtilisateur' => array($utilisateur->getEmail(), SQLITE3_INTEGER))); + 'idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), + 'idUtilisateur' => array($utilisateur->getEmail(), SQLITE3_INTEGER) + ) + ); } - public function findLastPartie() : Partie + public function findLastPartie(): Partie { $query = "SELECT * FROM Partie ORDER BY id DESC LIMIT 1"; $this->con->executequery($query); $results = $this->con->getResults(); $row = $results[0]; - $partie=new Partie($row['id'],array()); + $partie = new Partie($row['id'], array()); $date = new DateTime($row['dateDebut']); $partie->setDatePartie($date); return $partie; } - public function createPartie(Enigme $enigme, Utilisateur $utilisateur){ - $query="INSERT INTO Partie VALUES (NULL,:date)"; + public function createPartie(Enigme $enigme, Utilisateur $utilisateur) + { + $query = "INSERT INTO Partie VALUES (NULL,:date)"; + $currentDate = date('Y-m-d H:i:s'); + $this->con->executeQuery($query, array( + "date" => array($currentDate, SQLITE3_TEXT) + ) + ); + $partie = $this->findLastPartie(); + $query = "INSERT INTO Contenir VALUES (:partie,:idEnigme,NULL)"; + $this->con->executeQuery($query, array( + "partie" => array($partie->getIdPartie(), SQLITE3_INTEGER), + "idEnigme" => array($enigme->getIdEnigme(), SQLITE3_INTEGER) + ) + ); + $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,NULL)"; + $this->con->executeQuery($query, array( + "partie" => array($partie->getIdPartie(), SQLITE3_INTEGER), + "utilisateur" => array($utilisateur->getEmail(), SQLITE3_TEXT) + ) + ); + } + + public function createPartieMulti(Enigme $enigme, string $mailUtilisateur) + { + $query = "INSERT INTO Partie VALUES (NULL,:date)"; $currentDate = date('Y-m-d H:i:s'); $this->con->executeQuery($query, array( - "date" => array($currentDate, SQLITE3_TEXT))); + "date" => array($currentDate, SQLITE3_TEXT) + ) + ); $partie = $this->findLastPartie(); - $query="INSERT INTO Contenir VALUES (:partie,:idEnigme,NULL)"; + $query = "INSERT INTO Contenir VALUES (:partie,:idEnigme,1)"; $this->con->executeQuery($query, array( "partie" => array($partie->getIdPartie(), SQLITE3_INTEGER), - "idEnigme" => array($enigme->getIdEnigme(), SQLITE3_INTEGER))); - $query="INSERT INTO Participer VALUES (:partie,:utilisateur,NULL)"; + "idEnigme" => array($enigme->getIdEnigme(), SQLITE3_INTEGER) + ) + ); + $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,0)"; $this->con->executeQuery($query, array( "partie" => array($partie->getIdPartie(), SQLITE3_INTEGER), - "utilisateur" => array($utilisateur->getEmail(), SQLITE3_TEXT))); + "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT) + ) + ); } - public function delete(int $idPartie){ - $query= "DELETE FROM Contenir WHERE partie = :enigmeId"; + public function delete(int $idPartie) + { + $query = "DELETE FROM Contenir WHERE partie = :enigmeId"; $this->con->executeQuery($query, array(':enigmeId' => array($idPartie, SQLITE3_INTEGER))); - $query= "DELETE FROM Participer WHERE partie = :enigmeId"; + $query = "DELETE FROM Participer WHERE partie = :enigmeId"; $this->con->executeQuery($query, array(':enigmeId' => array($idPartie, SQLITE3_INTEGER))); - $query= "DELETE FROM Partie WHERE id = :idPartie"; + $query = "DELETE FROM Partie WHERE id = :idPartie"; $this->con->executeQuery($query, array(':idPartie' => array($idPartie, SQLITE3_INTEGER))); } - public function deleteByEnigme(int $enigmeId){ - $query="SELECT partie FROM Contenir WHERE enigme = :enigmeId"; + public function deleteByEnigme(int $enigmeId) + { + $query = "SELECT partie FROM Contenir WHERE enigme = :enigmeId"; $this->con->executeQuery($query, array(':enigmeId' => array($enigmeId, SQLITE3_INTEGER))); $results = $this->con->getResults(); - $query= "DELETE FROM Contenir WHERE enigme = :enigmeId"; + $query = "DELETE FROM Contenir WHERE enigme = :enigmeId"; $this->con->executeQuery($query, array(':enigmeId' => array($enigmeId, SQLITE3_INTEGER))); - foreach($results as $row){ - $query="DELETE FROM Participer WHERE partie = :partieId"; + foreach ($results as $row) { + $query = "DELETE FROM Participer WHERE partie = :partieId"; $this->con->executeQuery($query, array(':partieId' => array($row['partie'], SQLITE3_INTEGER))); - $query= "DELETE FROM Partie WHERE id = :partieId"; + $query = "DELETE FROM Partie WHERE id = :partieId"; $this->con->executeQuery($query, array(':partieId' => array($row['partie'], SQLITE3_INTEGER))); } } - public function findPartieHistory() : array{ - $query="SELECT * FROM Partie"; + public function findPartieHistory(): array + { + $query = "SELECT * FROM Partie"; $this->con->executeQuery($query); $results = $this->con->getResults(); - $query= "SELECT max(p.id) + $query = "SELECT max(p.id) FROM PARTIE p;"; $this->con->executeQuery($query); - $max=$this->con->getResults()[0]["max"]; - $listePartieHistory=array(); - foreach($results as $row) - { + $max = $this->con->getResults()[0]["max"]; + $listePartieHistory = array(); + foreach ($results as $row) { $query = "SELECT e.* FROM Enigme e,Contenir c,Partie p WHERE p.id = c.partie AND c.enigme = e.id AND c.enCours = false; AND p.partie = :idPartie"; - $this->con->executeQuery($query,array( - "idPartie" => array($row["idPartie"],SQLITE3_INTEGER) - )); - $historiquePartie=$this->con->getResults(); - $listePartieHistory[]=PartieFactory::createPartieHistory($row["idPartie"],$historiquePartie); + $this->con->executeQuery($query, array( + "idPartie" => array($row["idPartie"], SQLITE3_INTEGER) + ) + ); + $historiquePartie = $this->con->getResults(); + $listePartieHistory[] = PartieFactory::createPartieHistory($row["idPartie"], $historiquePartie); } return $listePartieHistory; } - public function findPartieByEnigmeId(int $enigmeId) : Partie{ + public function findPartieByEnigmeId(int $enigmeId): Partie + { $query = "SELECT * FROM Partie p, Resoudre r WHERE r.enigme = :enigmeId AND r.partie = p.id"; $this->con->executeQuery($query, array( ':enigmeId' => array($enigmeId, SQLITE3_INTEGER) - )); + ) + ); $results = $this->con->getResults(); $row = $results[0]; - $partie=new Partie($row['id'],array()); + $partie = new Partie($row['id'], array()); $date = new DateTime($row['dateDebut']); $partie->setDatePartie($date); return $partie; } - public function showAll() : void{ - $query= "SELECT * FROM Partie"; + public function addToPartie(string $mailUtilisateur, int $idPartie) + { + global $playerNumberPerGame; + $player = $this->getPlayerNumber($idPartie); + if ($player == $playerNumberPerGame) { + throw new Exception("La partie est pleine"); + } + if ($player + 1 == $playerNumberPerGame) { + $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,1)"; + $this->con->executeQuery($query, array( + "partie" => array($idPartie, SQLITE3_INTEGER), + "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT))); + } + else { + $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,0)"; + $this->con->executeQuery($query, array( + "partie" => array($idPartie, SQLITE3_INTEGER), + "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT))); + } + } + public function getPlayerNumber(int $idPartie): int + { + $query = "SELECT count(*) FROM Participer WHERE partie = :idPartie"; + $this->con->executeQuery($query, array( + "idPartie" => array($idPartie, SQLITE3_INTEGER) + ) + ); + $results = $this->con->getResults(); + $row = $results[0]; + return $row['count(*)']; + } + public function getEtat($idPartie){ + $query = "SELECT etat FROM Participer WHERE partie = :idPartie"; + $this->con->executeQuery($query, array( + "idPartie" => array($idPartie, SQLITE3_INTEGER) + ) + ); + $results = $this->con->getResults(); + $row = $results[0]; + return $row['etat']; + } + public function showAll(): void + { + $query = "SELECT * FROM Partie"; $this->con->executeQuery($query); - $results=$this->con->getResults(); + $results = $this->con->getResults(); foreach ($results as $row) { echo $row['idPartie'] . '
'; } diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 1df09f7a..e2384ebb 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -169,13 +169,24 @@ class UserController public function goToQueue() { try { - global $rep, $vues, $error; //$serverAdress,$port; + global $rep, $vues, $error; $model = new UserModel(); - // $model->addToQueue(); - require($rep . $vues['queue']); - $client = Client::getInstance(); - // new Queuing(); - $client->Queuing(); + $utilisateur = $_SESSION['utilisateur']; + $reponse = $model->addToQueue($utilisateur->getEmail()); + $etat = $reponse[1]; + $idPartie = $reponse[0]; + if($etat == 1){ + // header("Location: index.php?action=launchGame"); + header("Location: index.php"); + } + else{ + echo "Vous êtes dans la fille d'attente\n"; + require($rep . $vues['queue']); + // while ($etat == 0){ + // $etat = $model->getEtatPartie($idPartie); + // } + // header("Location: index.php"); + } } catch (Exception $e) { $error = $e->getMessage(); require($rep . $vues['erreur']); diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index b178ccb4..ddc9219f 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -24,35 +24,51 @@ class UserModel require($rep . $view['erreur']); } } - public function addToQueue() - { - echo '1'; - $utilisateur = $_SESSION['utilisateur']; - if ($this->utilisateur_gateway->isAlreadyInqueue($utilisateur)) { - var_dump($this->utilisateur_gateway->queueFilled()); - if($this->utilisateur_gateway->queueFilled()) - { - header('Location: index.php?action=launchGame'); - } - return; + // public function addToQueue() + // { + // echo '1'; + // $utilisateur = $_SESSION['utilisateur']; + // if ($this->utilisateur_gateway->isAlreadyInqueue($utilisateur)) { + // var_dump($this->utilisateur_gateway->queueFilled()); + // if($this->utilisateur_gateway->queueFilled()) + // { + // header('Location: index.php?action=launchGame'); + // } + // return; + // } + // echo '2'; + // if (!$this->partie_gateway->partieInQueueExists()) { + // echo '3'; + // $tabEnigme = $this->enigme_gateway->findMultiEnigma(); + // $idNewPartie = $this->partie_gateway->findPartieMaxId(); + // $partie = $this->partie_gateway->creerPartieMulti($idNewPartie, $tabEnigme); + // } else { + // echo '4'; + // $idPartieInQueue = $this->partie_gateway->findPartieInQueue(); + // echo '5'; + // $tabEnigme = $this->enigme_gateway->findEnigmaFromPartie($idPartieInQueue); + // echo '6'; + // $partie = $this->partie_gateway->rejoindrePartieMulti($idPartieInQueue, $tabEnigme); + // echo '7'; + // } + // echo '8'; + // $this->utilisateur_gateway->addToQueue($utilisateur, $partie); + // } + + public function addToQueue($mailUtilisateur) : array{ + $idPartie=$this->partie_gateway->findPartieInQueue(); + if ($idPartie == 0){ + $enigme= $this->enigme_gateway->getRandomEnigme(); + $this->partie_gateway->createPartieMulti($enigme, $mailUtilisateur); + $idPartie=$this->partie_gateway->findPartieInQueue(); + $etat=$this->partie_gateway->getEtat($idPartie); + return array($idPartie, $etat); } - echo '2'; - if (!$this->partie_gateway->partieInQueueExists()) { - echo '3'; - $tabEnigme = $this->enigme_gateway->findMultiEnigma(); - $idNewPartie = $this->partie_gateway->findPartieMaxId(); - $partie = $this->partie_gateway->creerPartieMulti($idNewPartie, $tabEnigme); - } else { - echo '4'; - $idPartieInQueue = $this->partie_gateway->findPartieInQueue(); - echo '5'; - $tabEnigme = $this->enigme_gateway->findEnigmaFromPartie($idPartieInQueue); - echo '6'; - $partie = $this->partie_gateway->rejoindrePartieMulti($idPartieInQueue, $tabEnigme); - echo '7'; + else{ + $this->partie_gateway->addToPartie($mailUtilisateur, $idPartie); + $etat=$this->partie_gateway->getEtat($idPartie); + return array($idPartie, $etat); } - echo '8'; - $this->utilisateur_gateway->addToQueue($utilisateur, $partie); } public function findUserGroup() : int { @@ -124,4 +140,8 @@ class UserModel } return $this->enigme_gateway->findById($id)[0]; } + + public function getEtatPartie($idPartie){ + return $this->partie_gateway->getEtat($idPartie); + } } \ No newline at end of file From 982e40b6e7d491ad52c3ca1168e67bb3d69e6273 Mon Sep 17 00:00:00 2001 From: Pierre BALLANDRAS Date: Mon, 9 Jan 2023 09:48:22 +0100 Subject: [PATCH 13/30] file d'attente --- .../src/pages/Multijoueur/FileAttente.html | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 WEB/View/src/pages/Multijoueur/FileAttente.html diff --git a/WEB/View/src/pages/Multijoueur/FileAttente.html b/WEB/View/src/pages/Multijoueur/FileAttente.html new file mode 100644 index 00000000..0b4c6d43 --- /dev/null +++ b/WEB/View/src/pages/Multijoueur/FileAttente.html @@ -0,0 +1,73 @@ + + + + + + Scripted + + + + + + + + +
+
+
+
+

SCRIPT

+

RUSH

+
+
+

Waiting ...

+
+
+
+
+

Player 1

+
+
+
+

Player 2

+
+
+
+

Player 3

+
+
+
+

Player 4

+
+
+
+
+ +
+
+
+ +
+
+ + From 18e8a8d5c46a774eae786ce95eeed535d68cd308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 10:00:13 +0100 Subject: [PATCH 14/30] Correction --- WEB/Controller/EnigmeGateway.php | 3 +++ WEB/Controller/PartieGateway.php | 2 ++ 2 files changed, 5 insertions(+) diff --git a/WEB/Controller/EnigmeGateway.php b/WEB/Controller/EnigmeGateway.php index 67a8dd85..481deda5 100644 --- a/WEB/Controller/EnigmeGateway.php +++ b/WEB/Controller/EnigmeGateway.php @@ -175,6 +175,9 @@ class EnigmeGateway $query = "SELECT * FROM Enigme WHERE ordre = 0 ORDER BY RANDOM() LIMIT 1"; $this->con->executequery($query); $results = $this->con->getResults(); + if (empty($results)){ + throw new Exception("Aucune énigme mulitijoeur n'est disponible"); + } $tabEnigme=EnigmeFactory::create($results); return $tabEnigme[0]; } diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index 2c6d1a72..4571f09e 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -251,12 +251,14 @@ class PartieGateway throw new Exception("La partie est pleine"); } if ($player + 1 == $playerNumberPerGame) { + echo "La partie est pleine"; $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,1)"; $this->con->executeQuery($query, array( "partie" => array($idPartie, SQLITE3_INTEGER), "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT))); } else { + echo "La partie n'est pas pleine"; $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,0)"; $this->con->executeQuery($query, array( "partie" => array($idPartie, SQLITE3_INTEGER), From 770e64eb6ef1846075c5c8b0e03271e0afea760e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 10:02:32 +0100 Subject: [PATCH 15/30] Correction --- WEB/Controller/PartieGateway.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index 4571f09e..17eb0b0e 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -251,14 +251,14 @@ class PartieGateway throw new Exception("La partie est pleine"); } if ($player + 1 == $playerNumberPerGame) { - echo "La partie est pleine"; + echo "La partie est all"; $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,1)"; $this->con->executeQuery($query, array( "partie" => array($idPartie, SQLITE3_INTEGER), "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT))); } else { - echo "La partie n'est pas pleine"; + echo "La partie n'est pas alll"; $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,0)"; $this->con->executeQuery($query, array( "partie" => array($idPartie, SQLITE3_INTEGER), From 76769f9a0d4070f48c5d90d0ccf583fe8f30e210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 10:06:26 +0100 Subject: [PATCH 16/30] correction --- WEB/Controller/PartieGateway.php | 4 ++-- WEB/Controller/UserController.php | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index 17eb0b0e..8f3dcda0 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -251,14 +251,14 @@ class PartieGateway throw new Exception("La partie est pleine"); } if ($player + 1 == $playerNumberPerGame) { - echo "La partie est all"; + echo "La partie est all\n"; $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,1)"; $this->con->executeQuery($query, array( "partie" => array($idPartie, SQLITE3_INTEGER), "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT))); } else { - echo "La partie n'est pas alll"; + echo "La partie n'est pas all\n"; $query = "INSERT INTO Participer VALUES (:partie,:utilisateur,0)"; $this->con->executeQuery($query, array( "partie" => array($idPartie, SQLITE3_INTEGER), diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index e2384ebb..4f2223a9 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -177,15 +177,15 @@ class UserController $idPartie = $reponse[0]; if($etat == 1){ // header("Location: index.php?action=launchGame"); - header("Location: index.php"); + header("Location: index.php?action=goToPresentation"); } else{ echo "Vous êtes dans la fille d'attente\n"; require($rep . $vues['queue']); - // while ($etat == 0){ - // $etat = $model->getEtatPartie($idPartie); - // } - // header("Location: index.php"); + while ($etat == 0){ + $etat = $model->getEtatPartie($idPartie); + } + header("Location: index.php?action=goToPresentation"); } } catch (Exception $e) { $error = $e->getMessage(); From c7747448e50eb80117dc574cccdcc8f211c20a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 10:17:22 +0100 Subject: [PATCH 17/30] Test --- WEB/Controller/UserController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 4f2223a9..a4f7a898 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -182,10 +182,10 @@ class UserController else{ echo "Vous êtes dans la fille d'attente\n"; require($rep . $vues['queue']); - while ($etat == 0){ - $etat = $model->getEtatPartie($idPartie); - } - header("Location: index.php?action=goToPresentation"); + // while ($etat == 0){ + // $etat = $model->getEtatPartie($idPartie); + // } + // header("Location: index.php?action=goToPresentation"); } } catch (Exception $e) { $error = $e->getMessage(); From 364eeee8136c67dc8f47d109483bb6a0939412fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 10:26:13 +0100 Subject: [PATCH 18/30] test --- WEB/Controller/UserController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index a4f7a898..eb86be0f 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -174,7 +174,9 @@ class UserController $utilisateur = $_SESSION['utilisateur']; $reponse = $model->addToQueue($utilisateur->getEmail()); $etat = $reponse[1]; + echo $etat; $idPartie = $reponse[0]; + echo $idPartie; if($etat == 1){ // header("Location: index.php?action=launchGame"); header("Location: index.php?action=goToPresentation"); From dfacc6fbe36fe714aeb9b1cbb0f29fbaeb3c0ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 10:30:19 +0100 Subject: [PATCH 19/30] test --- WEB/Controller/UserController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index eb86be0f..cf610320 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -174,9 +174,9 @@ class UserController $utilisateur = $_SESSION['utilisateur']; $reponse = $model->addToQueue($utilisateur->getEmail()); $etat = $reponse[1]; - echo $etat; + echo $etat. " etat\n"; $idPartie = $reponse[0]; - echo $idPartie; + echo $idPartie . " idPartie\n"; if($etat == 1){ // header("Location: index.php?action=launchGame"); header("Location: index.php?action=goToPresentation"); From ceadf6cea485d7fa6aa98acba94819d65ec7c88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 10:34:44 +0100 Subject: [PATCH 20/30] Correction --- WEB/Controller/PartieGateway.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index 8f3dcda0..c98b22f3 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -283,8 +283,12 @@ class PartieGateway ) ); $results = $this->con->getResults(); - $row = $results[0]; - return $row['etat']; + foreach ($results as $row){ + if($row['etat'] == 1){ + return 1; + } + } + return 0; } public function showAll(): void { From 77700803eaa8241ad13b97ce715a4cfb2da1dffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 10:37:42 +0100 Subject: [PATCH 21/30] test --- WEB/Controller/UserController.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index cf610320..d5af6084 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -182,12 +182,14 @@ class UserController header("Location: index.php?action=goToPresentation"); } else{ - echo "Vous êtes dans la fille d'attente\n"; - require($rep . $vues['queue']); - // while ($etat == 0){ - // $etat = $model->getEtatPartie($idPartie); - // } - // header("Location: index.php?action=goToPresentation"); + // echo "Vous êtes dans la fille d'attente\n"; + // require($rep . $vues['queue']); + while ($etat == 0){ + $etat = $model->getEtatPartie($idPartie); + echo "Vous êtes dans la fille d'attente\n"; + require($rep . $vues['queue']); + } + header("Location: index.php?action=goToPresentation"); } } catch (Exception $e) { $error = $e->getMessage(); From 6955c0c5fe38fb8844ba6dc5034368ee94446f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 10:40:10 +0100 Subject: [PATCH 22/30] test --- WEB/Controller/UserController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index d5af6084..ec503fae 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -182,9 +182,10 @@ class UserController header("Location: index.php?action=goToPresentation"); } else{ - // echo "Vous êtes dans la fille d'attente\n"; - // require($rep . $vues['queue']); + echo "Vous êtes dans la fille d'attente\n"; + require($rep . $vues['queue']); while ($etat == 0){ + sleep(20); $etat = $model->getEtatPartie($idPartie); echo "Vous êtes dans la fille d'attente\n"; require($rep . $vues['queue']); From cc106a7989d7dd82ebddbd3deab179ea3948456b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 10:46:04 +0100 Subject: [PATCH 23/30] test --- WEB/Controller/UserController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index ec503fae..9b22f775 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -184,8 +184,9 @@ class UserController else{ echo "Vous êtes dans la fille d'attente\n"; require($rep . $vues['queue']); + sleep(5); while ($etat == 0){ - sleep(20); + sleep(5); $etat = $model->getEtatPartie($idPartie); echo "Vous êtes dans la fille d'attente\n"; require($rep . $vues['queue']); From 802c3f3f0c2a762be38c3f40361dcea1e3d6468d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 10:54:35 +0100 Subject: [PATCH 24/30] Correction --- WEB/Controller/UserController.php | 14 ++++++++++++++ WEB/View/src/pages/Multijoueur/Queue.php | 1 + 2 files changed, 15 insertions(+) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 9b22f775..114d5c75 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -34,6 +34,9 @@ class UserController case "goToQueue": $this->goToQueue(); break; + case "queuing": + $this->queuing(); + break; case "logout": $this->logout(); break; @@ -168,6 +171,17 @@ class UserController } public function goToQueue() { + try { + global $rep, $vues, $error; + $model = new UserModel(); + echo "Vous êtes dans la fille d'attente\n"; + require($rep . $vues['queue']); + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } + } + public function queuing(){ try { global $rep, $vues, $error; $model = new UserModel(); diff --git a/WEB/View/src/pages/Multijoueur/Queue.php b/WEB/View/src/pages/Multijoueur/Queue.php index c7ad92aa..4754614a 100644 --- a/WEB/View/src/pages/Multijoueur/Queue.php +++ b/WEB/View/src/pages/Multijoueur/Queue.php @@ -1,4 +1,5 @@ + Queuing From 9aea3e06923422b57d048059ee8cd047a6311c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 10:57:12 +0100 Subject: [PATCH 25/30] test --- WEB/Controller/UserController.php | 6 ------ WEB/View/src/pages/Multijoueur/Queue.php | 5 ++++- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 114d5c75..1e2b23c0 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -173,7 +173,6 @@ class UserController { try { global $rep, $vues, $error; - $model = new UserModel(); echo "Vous êtes dans la fille d'attente\n"; require($rep . $vues['queue']); } catch (Exception $e) { @@ -196,14 +195,9 @@ class UserController header("Location: index.php?action=goToPresentation"); } else{ - echo "Vous êtes dans la fille d'attente\n"; - require($rep . $vues['queue']); - sleep(5); while ($etat == 0){ sleep(5); $etat = $model->getEtatPartie($idPartie); - echo "Vous êtes dans la fille d'attente\n"; - require($rep . $vues['queue']); } header("Location: index.php?action=goToPresentation"); } diff --git a/WEB/View/src/pages/Multijoueur/Queue.php b/WEB/View/src/pages/Multijoueur/Queue.php index 4754614a..6f06cc3a 100644 --- a/WEB/View/src/pages/Multijoueur/Queue.php +++ b/WEB/View/src/pages/Multijoueur/Queue.php @@ -1,6 +1,9 @@ - Queuing + \ No newline at end of file From fc8d75234b5f55399146a02c81e63d83bf562ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 11:02:51 +0100 Subject: [PATCH 26/30] test --- WEB/Controller/UserController.php | 1 - WEB/View/src/pages/Multijoueur/Queue.php | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 1e2b23c0..1bacce75 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -173,7 +173,6 @@ class UserController { try { global $rep, $vues, $error; - echo "Vous êtes dans la fille d'attente\n"; require($rep . $vues['queue']); } catch (Exception $e) { $error = $e->getMessage(); diff --git a/WEB/View/src/pages/Multijoueur/Queue.php b/WEB/View/src/pages/Multijoueur/Queue.php index 6f06cc3a..8deb20ba 100644 --- a/WEB/View/src/pages/Multijoueur/Queue.php +++ b/WEB/View/src/pages/Multijoueur/Queue.php @@ -2,8 +2,5 @@ Queuing - + Confirmer \ No newline at end of file From 07f05a92ef2726e422f4c597123ded656f4782af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 11:06:35 +0100 Subject: [PATCH 27/30] Correction grpahique --- WEB/View/src/pages/Multijoueur/Queue.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/WEB/View/src/pages/Multijoueur/Queue.php b/WEB/View/src/pages/Multijoueur/Queue.php index 8deb20ba..8ac60ced 100644 --- a/WEB/View/src/pages/Multijoueur/Queue.php +++ b/WEB/View/src/pages/Multijoueur/Queue.php @@ -1,4 +1,14 @@ - + + + + + + + Scripted + + + + Queuing From c8c904d2b95301d94f14d17a43389f031e19dfaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 11:19:56 +0100 Subject: [PATCH 28/30] changement de page --- WEB/Config/Config.php | 2 +- .../src/pages/Multijoueur/{FileAttente.html => FileAttente.php} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename WEB/View/src/pages/Multijoueur/{FileAttente.html => FileAttente.php} (97%) diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index 16c6853e..c7f98763 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -29,7 +29,7 @@ $vues['adminSolo'] = 'View/src/pages/Admin/AdminSolo.php'; $vues['seeOrdre'] = 'View/src/pages/Admin/SeeOrdre.php'; $vues['modifOrdre'] = 'View/src/pages/Admin/ModifOrdre.php'; $vues['partie'] = 'View/src/pages/Multijoueur/Partie.php'; -$vues['queue'] = 'View/src/pages/Multijoueur/Queue.php'; +$vues['queue'] = 'View/src/pages/Multijoueur/FileAttente.php'; // Enigme $vues['enigmePage'] = 'View/src/pages/Enigme/EnigmePage.php'; diff --git a/WEB/View/src/pages/Multijoueur/FileAttente.html b/WEB/View/src/pages/Multijoueur/FileAttente.php similarity index 97% rename from WEB/View/src/pages/Multijoueur/FileAttente.html rename to WEB/View/src/pages/Multijoueur/FileAttente.php index 0b4c6d43..976dccc5 100644 --- a/WEB/View/src/pages/Multijoueur/FileAttente.html +++ b/WEB/View/src/pages/Multijoueur/FileAttente.php @@ -59,7 +59,7 @@
From 56b506dbb9fc63b19896e23553b7ca5bd835e7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 11:23:12 +0100 Subject: [PATCH 29/30] Correction graphique --- WEB/View/src/pages/Multijoueur/FileAttente.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WEB/View/src/pages/Multijoueur/FileAttente.php b/WEB/View/src/pages/Multijoueur/FileAttente.php index 976dccc5..88c60ec0 100644 --- a/WEB/View/src/pages/Multijoueur/FileAttente.php +++ b/WEB/View/src/pages/Multijoueur/FileAttente.php @@ -24,8 +24,8 @@ rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0" /> - - + +
From 1ddd10d2a95623b4cfdd70478a567a9126d579cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 9 Jan 2023 11:43:38 +0100 Subject: [PATCH 30/30] Test affiche joueur dans la fille d'attente --- WEB/Config/Config.php | 2 +- WEB/Controller/PartieGateway.php | 14 +++++++++ WEB/Controller/UserController.php | 2 ++ WEB/Model/UserModel.php | 9 ++++++ .../src/pages/Multijoueur/FileAttente.php | 30 ++++++++++++++++--- 5 files changed, 52 insertions(+), 5 deletions(-) diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index c7f98763..580d46cb 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -37,7 +37,7 @@ $vues['enigmePage'] = 'View/src/pages/Enigme/EnigmePage.php'; $BUFFER_SIZE = 1024; $serverAdress = "82.165.180.114"; $port= "3000"; -$playerNumberPerGame=2; +$playerNumberPerGame=3; //modules $modules = 'node_module/'; diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index c98b22f3..b03b3d3c 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -290,6 +290,20 @@ class PartieGateway } return 0; } + + public function getLesMailJoueurs($idPartie){ + $query = "SELECT utilisateur FROM Participer WHERE partie = :idPartie"; + $this->con->executeQuery($query, array( + "idPartie" => array($idPartie, SQLITE3_INTEGER) + ) + ); + $results = $this->con->getResults(); + $lesJoueurs = array(); + foreach ($results as $row){ + $lesJoueurs[] = $row['utilisateur']; + } + return $lesJoueurs; + } public function showAll(): void { $query = "SELECT * FROM Partie"; diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 1bacce75..7098f692 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -191,6 +191,8 @@ class UserController echo $idPartie . " idPartie\n"; if($etat == 1){ // header("Location: index.php?action=launchGame"); + $lesJoeurs = $model->getLesJoueurs($idPartie); + sleep(30); header("Location: index.php?action=goToPresentation"); } else{ diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index ddc9219f..de336288 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -144,4 +144,13 @@ class UserModel public function getEtatPartie($idPartie){ return $this->partie_gateway->getEtat($idPartie); } + + public function getLesJoueurs($idPartie){ + $lesMailJoeurs = $this->partie_gateway->getLesMailJoueurs($idPartie); + $lesJoueurs = array(); + foreach ($lesMailJoeurs as $mail){ + $lesJoueurs[] = $this->utilisateur_gateway->getUtilisateurByEmail($mail); + } + return $lesJoueurs; + } } \ No newline at end of file diff --git a/WEB/View/src/pages/Multijoueur/FileAttente.php b/WEB/View/src/pages/Multijoueur/FileAttente.php index 88c60ec0..ff335743 100644 --- a/WEB/View/src/pages/Multijoueur/FileAttente.php +++ b/WEB/View/src/pages/Multijoueur/FileAttente.php @@ -41,19 +41,41 @@
-

Player 1

+ + ' . $_SESSION['utilisateur']->getPseudo().'

'; ?>
-

Player 2

+ ' . $lesJoeurs[1]->getPseudo().'

'; + } + else{ + echo '

Player 2

'; + } + ?>
-

Player 3

+ ' . $lesJoeurs[2]->getPseudo().'

'; + } + else{ + echo '

Player 2

'; + } + ?>
-

Player 4

+ ' . $lesJoeurs[3]->getPseudo().'

'; + } + else{ + echo '

Player 2

'; + } + ?>