summaryrefslogtreecommitdiff
path: root/app/v1_php/api/game/index.php
blob: 154d9054fabf00ffd1f497a93da5f41dc0104074 (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
<?php

/*
Table Game 
*/

require_once("../mysql_connect.inc.php");

$authentication_key=$_POST['authentication_key'];

if ($authentication_key !== "azertyuiop") {
	header("Clé d'authentification non reconnue", true, 401);
	exit();
}

$parameters=json_decode($_POST['parameters'], true);
if ( !is_array($parameters) || !is_numeric($parameters['longpollingduration']) ){
	header("Erreur paramètres", true, 400);
	exit();
}

$longpollingduration=$parameters['longpollingduration'];
$nbusersthreshold=$parameters['nbusersthreshold'];
$questiontimeframe=$parameters['questiontimeframe'];
$nbquestions=$parameters['nbquestions'];

if ( $parameters['flushusertable'] === "true" ) {
	$req="TRUNCATE TABLE User;";
	mysql_query($req);
	//TODO check result
}

$req="INSERT INTO Game VALUES (NULL, $longpollingduration, $nbusersthreshold, $questiontimeframe, $nbquestions)";
$res=mysql_query($req);


echo mysql_error();

if ( $res===true && mysql_affected_rows() === 1 ) {
	header("OK : CREATED", true, 201);
} else {
	header("erreur", true, 400);
}
?>