diff options
author | Julien Sere <jsere> | 2011-01-22 13:53:33 +0000 |
---|---|---|
committer | Julien Sere <jsere> | 2011-01-22 13:53:33 +0000 |
commit | 738943804f2e4005e1948ed19e0d02e4cd1df431 (patch) | |
tree | 19a9b074ebe4dfd32e4f9a5d81b45c70845b016f /app/v1_php/api | |
parent | 12f6cc3a6f90a67c1d922dd3d46a368b1066dee1 (diff) | |
download | 2011-usi-738943804f2e4005e1948ed19e0d02e4cd1df431.tar.gz 2011-usi-738943804f2e4005e1948ed19e0d02e4cd1df431.tar.bz2 2011-usi-738943804f2e4005e1948ed19e0d02e4cd1df431.zip |
On est bloqué à cause du long-polling... Pas de syncrho en php sous Windows
git-svn-id: file:///var/svn/2011-usi/trunk@9 db941bf7-0cb3-4dda-9634-87faf64f93a7
Diffstat (limited to 'app/v1_php/api')
-rw-r--r-- | app/v1_php/api/login/form.html | 20 | ||||
-rw-r--r-- | app/v1_php/api/login/index.php | 23 | ||||
-rw-r--r-- | app/v1_php/api/question/.htaccess | 3 | ||||
-rw-r--r-- | app/v1_php/api/question/index.php | 77 |
4 files changed, 123 insertions, 0 deletions
diff --git a/app/v1_php/api/login/form.html b/app/v1_php/api/login/form.html new file mode 100644 index 0000000..d514e10 --- /dev/null +++ b/app/v1_php/api/login/form.html @@ -0,0 +1,20 @@ +<html> +<head> +</head> + +<body> +<form method="POST" action="index.php"> + <div class="form_line"> + <label name="mail">mail</label> + <input type="text" name="mail"></input> + </div> + <div class="form_line"> + <label name="password">password</label> + <input type="text" name="password"></input> + </div> + <div class="form_line"> + <input type="submit" /> + </div> +</form> +</body> +</html> diff --git a/app/v1_php/api/login/index.php b/app/v1_php/api/login/index.php new file mode 100644 index 0000000..6cd1d77 --- /dev/null +++ b/app/v1_php/api/login/index.php @@ -0,0 +1,23 @@ +<?php + +/* +Table User +*/ + +require_once("../mysql_connect.inc.php"); + +$mail=mysql_real_escape_string($_POST['mail']); +$password=mysql_real_escape_string($_POST['password']); + +$req="SELECT 1 FROM User WHERE mail='$mail' AND password='$password' LIMIT 1"; +$res=mysql_query($req); + +if ( mysql_num_rows($res) !== 1 ) { + header("erreur", true, 400); + exit(); +} + +header("OK : CREATED", true, 201); +setcookie("session_key", rand(0, 1024*1024*1024*2-1)); //TODO unicité + +?> diff --git a/app/v1_php/api/question/.htaccess b/app/v1_php/api/question/.htaccess new file mode 100644 index 0000000..caad873 --- /dev/null +++ b/app/v1_php/api/question/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine On +RewriteRule ^([0-9]*)$ index.php?n=$1 + diff --git a/app/v1_php/api/question/index.php b/app/v1_php/api/question/index.php new file mode 100644 index 0000000..fd8985e --- /dev/null +++ b/app/v1_php/api/question/index.php @@ -0,0 +1,77 @@ +<?php + +phpinfo(); + +set_time_limit(0); +//header('Content-type: text/plain'); +//require_once("../mysql_connect.inc.php"); + +//var_dump($_REQUEST); + + +/* +$mail=mysql_real_escape_string($_POST['mail']); +$password=mysql_real_escape_string($_POST['password']); + +$req="SELECT 1 FROM User WHERE mail='$mail' AND password='$password' LIMIT 1"; +$res=mysql_query($req); + +if ( mysql_num_rows($res) !== 1 ) { + header("erreur", true, 400); + exit(); +} + +header("OK : CREATED", true, 201); +setcookie("session_key", rand(0, 1024*1024*1024*2-1)); //TODO unicité +*/ + + + + +echo "Attente des autres joueurs\n"; + +// Long pooling +$shm = shm_attach( "42", 4, 0666 ); + +if ( !$sem || !$shm ) { + header("Problème semaphore/shared memory", true, 400); +} + +//TODO : debut section critique +if ( ! shm_has_var($shm, 'nbj') ) { + shm_put_var($shm, 'nbj', 1); +} else { + shm_get_var($shm, 'nbj'); + $nbj++; + $res=shm_put_var($shm, 'nbj', $nbj); + if ( $res!==true ) { + header("Problème shm_put_var", true, 400); + exit(); + } +} +echo "Il y a $nbj joueurs\n"; +//TODO : Fin section critique + +$go=false; +while (!$go) { + shm_get_var($shm, 'nbj'); + if ( $nbj === 2) { + $go=true; + } + sleep(1); +} + + +//TODO Récupérer la question en base ? +echo ' +{ +"question" : "question ' . $_GET['n'] . '", +"answer_1" : "string", +"answer_2" : "string", +"answer_3" : "string", +"answer_4" : "string", +"score" : number +} +'; + +?> |