summaryrefslogtreecommitdiff
path: root/app/v1_php/api/question/index.php
blob: fd8985e073979cc0226ef000350396218bab418d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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 
}
';

?>