!!$loginIsOk, "whoami" => "".$user ) ); return; } // Sinon tout est bon on effectue l'opération correspondant à la commande passée. // TODO : en production, utiliser : header("Content-Type: application/json; charset=utf-8"); header("Content-Type: text/plain; charset=utf-8"); if ($action == 2) { // "Create partie" // Requête POST : http://serveur/server.php?action=2&nb=2&mode=normal&user=foo&passwd=bar if (!isset($_GET['nb']) || !isset($_GET['mode'])) { throw new Exception("La requête est incomplète", 2); } createGame(intval($_GET['nb']), $_GET['mode']); echo '{"success":1}'; } else if($action == 0) { // "Get partie" // Requête POST : http://serveur/server.php?action=0&user=foo&passwd=bar getGame($user); } else if($action == 1) { // "Set partie" // Requête POST : http://serveur/server.php?action=1&mode=normal&user=foo&passwd=bar&gid=1234&pgid=12357&0=0&1=-1&2=22&3=13&9=-1 if (!isset($_GET['pgid']) || !isset($_GET['gid']) || !isset($_GET['answers'])) { throw new Exception("La requête est incomplète", 2); } setGameGetScore($user, $_GET['pgid'], $_GET['gid'], $_GET['answers']); } else if($action == 4) { // CheckWord if (!isset($_GET['word'])) throw new Exception("La requête est incomplète", 2); if(wordExist($_GET['word'])) echo "true"; else echo "false"; } else if($action == 5) { // Get relations (JSON) echo getGameRelationsJSON(); } else if($action == 6) { if (!isset($_GET['game'])) throw new Exception("La requête est incomplète", 2); decodeAndInsertGame($user,$_GET['game']); } elseif ($action == 7) { // Get user prefs userPrefs($user); } elseif ($action == 8) { // Set user pref if (!isset($_GET['key']) || !isset($_GET['value'])) throw new Exception("La requête est incomplète", 2); setUserPref($user, $_GET['key'], $_GET['value']); } else { throw new Exception("Commande inconnue", 2); } } function server() { if(isset($_GET['callback'])) echo $_GET['callback'].'('; ob_start(); try { main(); ob_end_flush(); } catch (Exception $e) { ob_end_clean(); echo json_encode( Array( "error" => $e->getCode(), "msg" => "".$e->getMessage(), "isError" => true ) ); logError($e->getCode(), $e->getMessage(), date("c")); closeDB(); } if(isset($_GET['callback'])) echo ')'; } server(); ?>