Merge branch 'master' of https://codefirst.iut.uca.fr/git/nathan.boileau/Scripted
continuous-integration/drone/push Build is passing Details

ServeurDeTest
nathan boileau 2 years ago
commit d48610d89a

@ -16,49 +16,48 @@ class Client
{ {
global $port, $serverAdress, $rep, $vues, $BUFFER_SIZE; global $port, $serverAdress, $rep, $vues, $BUFFER_SIZE;
$userModel = new UserModel(); $userModel = new UserModel();
// pas d'arrêt d'éxécution du script (No timeout) // pas d'arrêt d'éxécution du script (No timeout)
set_time_limit(0); 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()) . "\n"); $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 // connecter la socket à l'adresse ip et au port du serveur
$result = socket_set_block($socket); $result = socket_set_block($socket);
if ($result === false) { 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 { } 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) { if ($result === false) {
// La connexion de la socket à l'adresse et au port a échoué // 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 { } else {
echo "socket_connect a réussi.\n"; echo "socket_connect a réussi. (Client : Queuing)\n";
$request = "Queuing"; $request = "Queuing";
$result = socket_write($socket, $request, strlen($request)); $result = socket_write($socket, $request, strlen($request));
if ($result === false) { 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 { } else {
echo "socket_write a réussi.\n"; echo "socket_write a réussi.(Client : Queuing)\n";
}
$response = "";
$i = 0;
while ($i != 2) {
$response = socket_read($socket, $BUFFER_SIZE);
echo $response;
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['queue']);
}
} else {
echo "socket_read a échoué : " . socket_strerror(socket_last_error()) . "\n";
break;
}
sleep(5);
$i++;
} }
require $rep . $vues['erreur']; $response = "AAA";
// $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;
// }
// }
} }
} }
} }

@ -29,7 +29,7 @@ $vues['adminSolo'] = 'View/src/pages/Admin/AdminSolo.php';
$vues['seeOrdre'] = 'View/src/pages/Admin/SeeOrdre.php'; $vues['seeOrdre'] = 'View/src/pages/Admin/SeeOrdre.php';
$vues['modifOrdre'] = 'View/src/pages/Admin/ModifOrdre.php'; $vues['modifOrdre'] = 'View/src/pages/Admin/ModifOrdre.php';
$vues['partie'] = 'View/src/pages/Multijoueur/Partie.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 // Enigme
$vues['enigmePage'] = 'View/src/pages/Enigme/EnigmePage.php'; $vues['enigmePage'] = 'View/src/pages/Enigme/EnigmePage.php';
@ -37,7 +37,7 @@ $vues['enigmePage'] = 'View/src/pages/Enigme/EnigmePage.php';
$BUFFER_SIZE = 1024; $BUFFER_SIZE = 1024;
$serverAdress = "82.165.180.114"; $serverAdress = "82.165.180.114";
$port= "3000"; $port= "3000";
$playerNumberPerGame=2; $playerNumberPerGame=3;
//modules //modules
$modules = 'node_module/'; $modules = 'node_module/';

@ -169,6 +169,18 @@ class EnigmeGateway
$tabEnigme=EnigmeFactory::create($results); $tabEnigme=EnigmeFactory::create($results);
return $tabEnigme; 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();
if (empty($results)){
throw new Exception("Aucune énigme mulitijoeur n'est disponible");
}
$tabEnigme=EnigmeFactory::create($results);
return $tabEnigme[0];
}
public function showAll(): void public function showAll(): void
{ {
$query = "SELECT * FROM Enigme"; $query = "SELECT * FROM Enigme";

@ -9,9 +9,9 @@ class PartieGateway
public function __construct() public function __construct()
{ {
global $dsn, $rep, $vues, $error; global $dsn, $rep, $vues, $error;
try{ try {
$con = new Connection($dsn); $con = new Connection($dsn);
$this->con = $con; $this->con = $con;
} catch (Exception $e) { } catch (Exception $e) {
$error = $e->getMessage(); $error = $e->getMessage();
require($rep . $vues['erreur']); require($rep . $vues['erreur']);
@ -21,7 +21,8 @@ class PartieGateway
/** /**
* @param array $listeUtilisateur * @param array $listeUtilisateur
*/ */
public function partieInQueueExists() : bool{ public function partieInQueueExists(): bool
{
$query = "SELECT count(*) FROM PARTICIPER WHERE etat = 0"; $query = "SELECT count(*) FROM PARTICIPER WHERE etat = 0";
$this->con->executeQuery($query); $this->con->executeQuery($query);
$results = $this->con->getResults(); $results = $this->con->getResults();
@ -31,174 +32,283 @@ class PartieGateway
return true; return true;
} }
public function findPartieMaxId() : int{ public function findPartieMaxId(): int
{
$query = "SELECT max(id) FROM Partie"; $query = "SELECT max(id) FROM Partie";
$this->con->executeQuery($query); $this->con->executeQuery($query);
$results=$this->con->getResults(); $results = $this->con->getResults();
if ($results[0]['max(id)']==NULL) if ($results[0]['max(id)'] == NULL)
return 0; return 0;
else else
return $results[0]['max(id)']; return $results[0]['max(id)'];
} }
public function creerPartieMulti(int $max, array $tabEnigme) : Partie{ // public function creerPartieMulti(int $max, array $tabEnigme) : Partie{
$partie=PartieFactory::createPartieMulti($max+1,$tabEnigme); // $partie=PartieFactory::createPartieMulti($max+1,$tabEnigme);
$query= "INSERT INTO Partie VALUES (:idPartie,CURRENT_DATE)"; // $query= "INSERT INTO Partie VALUES (:idPartie,CURRENT_DATE)";
$this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER))); // $this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER)));
if (count($partie->getListeEnigme()) != 0) { // if (count($partie->getListeEnigme()) != 0) {
foreach ($partie->getListeEnigme() as $Enigme) { // foreach ($partie->getListeEnigme() as $Enigme) {
$query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)"; // $query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)";
$this->con->executeQuery($query, array( // $this->con->executeQuery($query, array(
':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), // ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER) // ':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER)
) // )
); // );
} // }
} // }
return $partie; // return $partie;
} // }
public function rejoindrePartieMulti(int $idPartieInQueue,array $tabEnigme) : Partie{ public function rejoindrePartieMulti(int $idPartieInQueue, array $tabEnigme): Partie
$partie = PartieFactory::createPartieMulti($idPartieInQueue,$tabEnigme); {
$partie = PartieFactory::createPartieMulti($idPartieInQueue, $tabEnigme);
return $partie; return $partie;
} }
public function findPartieInQueue(){ public function findPartieInQueue()
$query = "SELECT p.id {
FROM Partie p, Participer pa $query = "SELECT partie
WHERE pa.etat=0 FROM Participer
AND pa.partie=p.id WHERE etat=0
LIMIT 1"; LIMIT 1";
$this->con->executeQuery($query); $this->con->executeQuery($query);
$results = $this->con->getResults(); $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 $query = "SELECT * FROM Enigme
WHERE points IS NULL OR points = 0"; WHERE points IS NULL OR points = 0";
$this->con->executeQuery($query); $this->con->executeQuery($query);
$results = $this->con->getResults(); $results = $this->con->getResults();
$query= "SELECT max(p.id) $query = "SELECT max(p.id)
FROM PARTIE p;"; FROM PARTIE p;";
$this->con->executeQuery($query); $this->con->executeQuery($query);
$max=$this->con->getResults()[0]["max"]; $max = $this->con->getResults()[0]["max"];
$partie=PartieFactory::createPartieSolo($max,$results); $partie = PartieFactory::createPartieSolo($max, $results);
$query= "INSERT INTO Partie VALUES (:idPartie,:idEnigme)"; $query = "INSERT INTO Partie VALUES (:idPartie,:idEnigme)";
$this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER))); $this->con->executeQuery($query, array(':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER)));
foreach($partie->getListeEnigme() as $Enigme){ foreach ($partie->getListeEnigme() as $Enigme) {
$query= "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)"; $query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER))); ':idEnigme' => array($Enigme->getIdEnigme(), SQLITE3_INTEGER)
)
);
} }
foreach($partie->getListeEnigme() as $Enigme){ foreach ($partie->getListeEnigme() as $Enigme) {
$query= "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)"; $query = "INSERT INTO Contenir VALUES (:idPartie, :idEnigme)";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), ':idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
':idEnigme' => array($Enigme->getIdEnigme(), 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( $this->con->executeQuery($query, array(
'idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER), 'idPartie' => array($partie->getIdPartie(), SQLITE3_INTEGER),
'idUtilisateur' => array($utilisateur->getEmail(), 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"; $query = "SELECT * FROM Partie ORDER BY id DESC LIMIT 1";
$this->con->executequery($query); $this->con->executequery($query);
$results = $this->con->getResults(); $results = $this->con->getResults();
$row = $results[0]; $row = $results[0];
$partie=new Partie($row['id'],array()); $partie = new Partie($row['id'], array());
$date = new DateTime($row['dateDebut']); $date = new DateTime($row['dateDebut']);
$partie->setDatePartie($date); $partie->setDatePartie($date);
return $partie; return $partie;
} }
public function createPartie(Enigme $enigme, Utilisateur $utilisateur){ public function createPartie(Enigme $enigme, Utilisateur $utilisateur)
$query="INSERT INTO Partie VALUES (NULL,:date)"; {
$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'); $currentDate = date('Y-m-d H:i:s');
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
"date" => array($currentDate, SQLITE3_TEXT))); "date" => array($currentDate, SQLITE3_TEXT)
)
);
$partie = $this->findLastPartie(); $partie = $this->findLastPartie();
$query="INSERT INTO Contenir VALUES (:partie,:idEnigme,NULL)"; $query = "INSERT INTO Contenir VALUES (:partie,:idEnigme,1)";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
"partie" => array($partie->getIdPartie(), SQLITE3_INTEGER), "partie" => array($partie->getIdPartie(), SQLITE3_INTEGER),
"idEnigme" => array($enigme->getIdEnigme(), SQLITE3_INTEGER))); "idEnigme" => array($enigme->getIdEnigme(), SQLITE3_INTEGER)
$query="INSERT INTO Participer VALUES (:partie,:utilisateur,NULL)"; )
);
$query = "INSERT INTO Participer VALUES (:partie,:utilisateur,0)";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
"partie" => array($partie->getIdPartie(), SQLITE3_INTEGER), "partie" => array($partie->getIdPartie(), SQLITE3_INTEGER),
"utilisateur" => array($utilisateur->getEmail(), SQLITE3_TEXT))); "utilisateur" => array($mailUtilisateur, SQLITE3_TEXT)
)
);
} }
public function delete(int $idPartie){ public function delete(int $idPartie)
$query= "DELETE FROM Contenir WHERE partie = :enigmeId"; {
$query = "DELETE FROM Contenir WHERE partie = :enigmeId";
$this->con->executeQuery($query, array(':enigmeId' => array($idPartie, SQLITE3_INTEGER))); $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))); $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))); $this->con->executeQuery($query, array(':idPartie' => array($idPartie, SQLITE3_INTEGER)));
} }
public function deleteByEnigme(int $enigmeId){ public function deleteByEnigme(int $enigmeId)
$query="SELECT partie FROM Contenir WHERE enigme = :enigmeId"; {
$query = "SELECT partie FROM Contenir WHERE enigme = :enigmeId";
$this->con->executeQuery($query, array(':enigmeId' => array($enigmeId, SQLITE3_INTEGER))); $this->con->executeQuery($query, array(':enigmeId' => array($enigmeId, SQLITE3_INTEGER)));
$results = $this->con->getResults(); $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))); $this->con->executeQuery($query, array(':enigmeId' => array($enigmeId, SQLITE3_INTEGER)));
foreach($results as $row){ foreach ($results as $row) {
$query="DELETE FROM Participer WHERE partie = :partieId"; $query = "DELETE FROM Participer WHERE partie = :partieId";
$this->con->executeQuery($query, array(':partieId' => array($row['partie'], SQLITE3_INTEGER))); $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))); $this->con->executeQuery($query, array(':partieId' => array($row['partie'], SQLITE3_INTEGER)));
} }
} }
public function findPartieHistory() : array{ public function findPartieHistory(): array
$query="SELECT * FROM Partie"; {
$query = "SELECT * FROM Partie";
$this->con->executeQuery($query); $this->con->executeQuery($query);
$results = $this->con->getResults(); $results = $this->con->getResults();
$query= "SELECT max(p.id) $query = "SELECT max(p.id)
FROM PARTIE p;"; FROM PARTIE p;";
$this->con->executeQuery($query); $this->con->executeQuery($query);
$max=$this->con->getResults()[0]["max"]; $max = $this->con->getResults()[0]["max"];
$listePartieHistory=array(); $listePartieHistory = array();
foreach($results as $row) foreach ($results as $row) {
{
$query = "SELECT e.* FROM Enigme e,Contenir c,Partie p $query = "SELECT e.* FROM Enigme e,Contenir c,Partie p
WHERE p.id = c.partie WHERE p.id = c.partie
AND c.enigme = e.id AND c.enigme = e.id
AND c.enCours = false; AND c.enCours = false;
AND p.partie = :idPartie"; AND p.partie = :idPartie";
$this->con->executeQuery($query,array( $this->con->executeQuery($query, array(
"idPartie" => array($row["idPartie"],SQLITE3_INTEGER) "idPartie" => array($row["idPartie"], SQLITE3_INTEGER)
)); )
$historiquePartie=$this->con->getResults(); );
$listePartieHistory[]=PartieFactory::createPartieHistory($row["idPartie"],$historiquePartie); $historiquePartie = $this->con->getResults();
$listePartieHistory[] = PartieFactory::createPartieHistory($row["idPartie"], $historiquePartie);
} }
return $listePartieHistory; return $listePartieHistory;
} }
public function findPartieByEnigmeId(int $enigmeId) : Partie{ public function findPartieByEnigmeId(int $enigmeId): Partie
{
$query = "SELECT * FROM Partie p, Resoudre r $query = "SELECT * FROM Partie p, Resoudre r
WHERE r.enigme = :enigmeId WHERE r.enigme = :enigmeId
AND r.partie = p.id"; AND r.partie = p.id";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
':enigmeId' => array($enigmeId, SQLITE3_INTEGER) ':enigmeId' => array($enigmeId, SQLITE3_INTEGER)
)); )
);
$results = $this->con->getResults(); $results = $this->con->getResults();
$row = $results[0]; $row = $results[0];
$partie=new Partie($row['id'],array()); $partie = new Partie($row['id'], array());
$date = new DateTime($row['dateDebut']); $date = new DateTime($row['dateDebut']);
$partie->setDatePartie($date); $partie->setDatePartie($date);
return $partie; return $partie;
} }
public function showAll() : void{ public function addToPartie(string $mailUtilisateur, int $idPartie)
$query= "SELECT * FROM Partie"; {
global $playerNumberPerGame;
$player = $this->getPlayerNumber($idPartie);
if ($player == $playerNumberPerGame) {
throw new Exception("La partie est pleine");
}
if ($player + 1 == $playerNumberPerGame) {
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 all\n";
$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();
foreach ($results as $row){
if($row['etat'] == 1){
return 1;
}
}
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";
$this->con->executeQuery($query); $this->con->executeQuery($query);
$results=$this->con->getResults(); $results = $this->con->getResults();
foreach ($results as $row) { foreach ($results as $row) {
echo $row['idPartie'] . '</br>'; echo $row['idPartie'] . '</br>';
} }

@ -34,6 +34,9 @@ class UserController
case "goToQueue": case "goToQueue":
$this->goToQueue(); $this->goToQueue();
break; break;
case "queuing":
$this->queuing();
break;
case "logout": case "logout":
$this->logout(); $this->logout();
break; break;
@ -169,18 +172,41 @@ class UserController
public function goToQueue() public function goToQueue()
{ {
try { try {
global $rep, $vues, $error; //$serverAdress,$port; global $rep, $vues, $error;
$model = new UserModel();
// $model->addToQueue();
$client = Client::getInstance();
// new Queuing();
$client->Queuing();
require($rep . $vues['queue']); require($rep . $vues['queue']);
} catch (Exception $e) { } catch (Exception $e) {
$error = $e->getMessage(); $error = $e->getMessage();
require($rep . $vues['erreur']); require($rep . $vues['erreur']);
} }
} }
public function queuing(){
try {
global $rep, $vues, $error;
$model = new UserModel();
$utilisateur = $_SESSION['utilisateur'];
$reponse = $model->addToQueue($utilisateur->getEmail());
$etat = $reponse[1];
echo $etat. " etat\n";
$idPartie = $reponse[0];
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{
while ($etat == 0){
sleep(5);
$etat = $model->getEtatPartie($idPartie);
}
header("Location: index.php?action=goToPresentation");
}
} catch (Exception $e) {
$error = $e->getMessage();
require($rep . $vues['erreur']);
}
}
public function launchGame(){ public function launchGame(){
try { try {
global $rep, $vues, $error; global $rep, $vues, $error;

@ -17,39 +17,41 @@ class RequestHandler{
$socketsFromQueue[]=$socket; $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). '(Queuing : RequestHandler)';
// si le nombre de joueur par partie nécessaire est égal au nombre de connection encore dans la file d'attente // 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 // 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 // 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.'(Queuing : RequestHandler)';
if(count($socketsFromQueue)==$playerNumberPerGame) if(count($socketsFromQueue)==$playerNumberPerGame)
{ {
echo 'lancement de la partie\n'; echo "lancement de la partie (Queuing : RequestHandler)\n";
$response="launchGame"; $response="launchGame";
$idPartie=$this->partie_gateway->findPartieInQueue(); $idPartie=$this->partie_gateway->findPartieInQueue();
echo 'id de la partie : '.$idPartie; echo 'id de la partie : '.$idPartie ." (Queuing : RequestHandler)\n";
$arraySocketGroup[$idPartie]=$socketsFromQueue; $arraySocketGroup[$idPartie]=$socketsFromQueue;
$socketsFromQueue=array(); $socketsFromQueue=array();
} }
else else
{ {
echo "rafraichissement de la file d'attente\n"; echo "rafraichissement de la file d'attente (Queuing : RequestHandler)\n";
$response="refreshQueue"; $response="refreshQueue";
} }
var_dump($socketsFromQueue); // var_dump($socketsFromQueue);
var_dump($response); // var_dump($response);
foreach($socketsFromQueue as $sock) foreach($socketsFromQueue as $sock)
{ {
var_dump($sock); // var_dump($sock);
$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";
var_dump($result); $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) if($result==false)
{ {
echo "erreur d'écriture\n"; echo "erreur d'écriture (Queuing : RequestHandler)\n";
} }
} }
return $response;
} }
public function quitQueue(Socket $client,String $request){ public function quitQueue(Socket $client,String $request){
// supprime le socket de la liste des sockets en attente // supprime le socket de la liste des sockets en attente
@ -58,7 +60,7 @@ class RequestHandler{
// envoie à tous les utilisateurs en attente de rafraichir la page // envoie à tous les utilisateurs en attente de rafraichir la page
foreach($socketsFromQueue as $socket) 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){ public function quitGame(Socket $client,String $request){
@ -68,7 +70,7 @@ class RequestHandler{
// envoie à tous les utilisateurs en attente de rafraichir la page // envoie à tous les utilisateurs en attente de rafraichir la page
foreach($this->arraySocketGroup[explode(" ",$request)[1]] as $socket) 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){ public function refreshDashBoard(Socket $client,String $request){
@ -76,7 +78,7 @@ class RequestHandler{
// envoie à tous les utilisateurs en attente de rafraichir la page // envoie à tous les utilisateurs en attente de rafraichir la page
foreach($this->arraySocketGroup[explode(" ",$request)[1]] as $socket) 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){ public function finishGame(Socket $client,String $request){
@ -86,7 +88,7 @@ class RequestHandler{
// envoie à tous les utilisateurs en attente de rafraichir la page // envoie à tous les utilisateurs en attente de rafraichir la page
foreach($this->arraySocketGroup[explode(" ",$request)[1]] as $socket) 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");
} }
} }
} }

@ -24,35 +24,51 @@ class UserModel
require($rep . $view['erreur']); require($rep . $view['erreur']);
} }
} }
public function addToQueue() // public function addToQueue()
{ // {
echo '1'; // echo '1';
$utilisateur = $_SESSION['utilisateur']; // $utilisateur = $_SESSION['utilisateur'];
if ($this->utilisateur_gateway->isAlreadyInqueue($utilisateur)) { // if ($this->utilisateur_gateway->isAlreadyInqueue($utilisateur)) {
var_dump($this->utilisateur_gateway->queueFilled()); // var_dump($this->utilisateur_gateway->queueFilled());
if($this->utilisateur_gateway->queueFilled()) // if($this->utilisateur_gateway->queueFilled())
{ // {
header('Location: index.php?action=launchGame'); // header('Location: index.php?action=launchGame');
} // }
return; // 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'; else{
if (!$this->partie_gateway->partieInQueueExists()) { $this->partie_gateway->addToPartie($mailUtilisateur, $idPartie);
echo '3'; $etat=$this->partie_gateway->getEtat($idPartie);
$tabEnigme = $this->enigme_gateway->findMultiEnigma(); return array($idPartie, $etat);
$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 findUserGroup() : int { public function findUserGroup() : int {
@ -124,4 +140,17 @@ class UserModel
} }
return $this->enigme_gateway->findById($id)[0]; return $this->enigme_gateway->findById($id)[0];
} }
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;
}
} }

@ -0,0 +1,95 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Scripted</title>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css"
integrity="sha384-r4NyP46KrjDleawBgD5tp8Y7UzmLA05oM1iAEQ17CSuDqnUK2+k9luXQOfXJCJ4I"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"
></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js"
integrity="sha384-oesi62hOLfzrys4LxRF63OJCXdXDipiYWBnvTl9Y9/TRlw5xlKIEHpNyvvDShgf/"
crossorigin="anonymous"
></script>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0"
/>
<link rel="stylesheet" href="./View/src/CSS/Main2.css" />
<link rel="stylesheet" href="./View/src/CSS/FirstTest.css">
</head>
<body>
<div>
<div id="imgMain" style="background: #050E15;">
<div class="grid">
<div class="row">
<h2 class="text-center mt-3 mr-5" style="color: #00CCFF; font-weight: 1000;font-style: italic;">SCRIPT</h2>
<h2 class="text-center ml-5" style="color: #D400D4; font-weight:bold ; font-size:4em;font-style: italic;">RUSH</h2>
</div>
<div class="row pt-5">
<h3 class="text-center">Waiting ...</h3>
</div>
<div class="row d-flex ">
<div class="col d-flex flex-column align-items-center">
<div style="background-color: red; height: 75px; width: 75px;"></div>
<!-- <p class="pt-3">Player 1</p> -->
<?php echo ' <p class="pt-3">' . $_SESSION['utilisateur']->getPseudo().'</p>'; ?>
</div>
<div class="col d-flex flex-column align-items-center">
<div style="background-color: blue; height: 75px; width: 75px;"></div>
<?php
if (isset($lesJoeurs[1])){
echo ' <p class="pt-3">' . $lesJoeurs[1]->getPseudo().'</p>';
}
else{
echo ' <p class="pt-3">Player 2</p>';
}
?>
</div>
<div class="col d-flex flex-column align-items-center">
<div style="background-color: yellow; height: 75px; width: 75px;"></div>
<?php
if (isset($lesJoeurs[2])){
echo ' <p class="pt-3">' . $lesJoeurs[2]->getPseudo().'</p>';
}
else{
echo ' <p class="pt-3">Player 2</p>';
}
?>
</div>
<div class="col d-flex flex-column align-items-center">
<div style="background-color: green; height: 75px; width: 75px;"></div>
<?php
if (isset($lesJoeurs[3])){
echo ' <p class="pt-3">' . $lesJoeurs[3]->getPseudo().'</p>';
}
else{
echo ' <p class="pt-3">Player 2</p>';
}
?>
</div>
</div>
<div class="row">
<div class="row pt-5 text-center" style="cursor: pointer; height: 20%">
<div class="col">
<a class="btn" href="index.php?action=queuing">
<span>LANCER</span>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

@ -1,5 +1,16 @@
<html> <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Scripted</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css" integrity="sha384-r4NyP46KrjDleawBgD5tp8Y7UzmLA05oM1iAEQ17CSuDqnUK2+k9luXQOfXJCJ4I" crossorigin="anonymous" />
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js" integrity="sha384-oesi62hOLfzrys4LxRF63OJCXdXDipiYWBnvTl9Y9/TRlw5xlKIEHpNyvvDShgf/" crossorigin="anonymous"></script>
</head>
<body> <body>
Queuing Queuing
</body> </body>
<a name="" id="" class="btn btn-primary" href="index.php?action=queuing" role="button">Confirmer</a>
</html> </html>

@ -67,12 +67,12 @@ $client=false;
while(true) { while(true) {
// Commencer à écouter sur le port // 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) { if ($result === false) {
// L'écoute sur le port a échoué // 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 { } 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 // L'écoute sur le port a réussi
} }
@ -83,7 +83,7 @@ while(true) {
$client=socket_accept($socket); $client=socket_accept($socket);
if($client === false) 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 else
{ {
@ -93,7 +93,7 @@ while(true) {
} }
var_dump($client); 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 //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 //Met la requête du client dans $request et verifie si la requête est valide
@ -106,16 +106,17 @@ while(true) {
$requestHandler = new RequestHandler(); $requestHandler = new RequestHandler();
if (method_exists($requestHandler, $request)) { if (method_exists($requestHandler, $request)) {
$function=explode(' ',$request)[0]; $function=explode(' ',$request)[0];
echo ($function."\n"); echo ($function." (Serveur) \n");
$response = $requestHandler->$function($client, $request); $response = $requestHandler->$function($client, $request);
echo 'response : '.$response."\n"; echo 'response : '.$response." (Serveur)\n";
// socket_write($client,$response,strlen($response));
} else { } else {
$response = "Invalid request"; $response = "Invalid request";
// socket_write($client,$response,strlen($response)); socket_write($client,$response,strlen($response));
} }
} else { } else {
$response = "Response is false"; $response = "Response is false";
// socket_write($client,$response,strlen($response)); socket_write($client,$response,strlen($response));
} }
} }
} }

Loading…
Cancel
Save