summaryrefslogtreecommitdiff
path: root/app/v1_php/api/game/index.php
blob: a8658acb4810f00d538636e78f7f27456161223d (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 
Unique key : 
*/

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

$authentication_key=$_POST['authentication_key'];

if ($authentication_key !== "azertyuiop") {
	// header 401, "Clé d'authentification non reconnue"
	echo "401, Clé d'authentification non reconnue\n";
}

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

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

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

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

if ( mysql_num_rows() === 1 ) {
	//TODO header 201, "OK : CREATED"
	echo "header 201, OK : CREATED\n";
} else {
	// header 400, "Erreur"
	echo "header 400, Erreur insertion SQL\n";
}
?>