summaryrefslogtreecommitdiff
path: root/app/v1_php/api/question/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/v1_php/api/question/index.php')
-rw-r--r--app/v1_php/api/question/index.php77
1 files changed, 77 insertions, 0 deletions
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
+}
+';
+
+?>