!!$loginIsOk, "whoami" => "".$user ) ); return; } 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 echo JSON_encode(game2array($user, isset($_GET['pgid']) ? $_GET['pgid'] : null)); } else if($action == 1) { // "Set partie" // Requête POST : http://serveur/server.php?action=1&user=foo&passwd=bar&gid=1234&pgid=12357&0=0&1=-1&2=22&3=13&9=-1 if (!isset($_GET['pgid']) || !isset($_GET['answers'])) throw new Exception("La requête est incomplète", 2); setGameGetScore($user, $_GET['pgid'], $_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 JSON_encode(true); else echo JSON_encode(false); } else if($action == 5) { // Get relations (JSON) echo getGameRelations(); } 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']); userPrefs($user); } elseif ($action == 9) { session_destroy(); echo '{"disconnected":true}'; } elseif ($action == 10) { // Set J'aime / J'aime pas if (!isset($_GET['value']) || !isset($_GET['pgid'])) throw new Exception("La requête est incomplète", 2); setJAimePgid($user, $_GET['pgid'], intval($_GET['value'])); echo '{"JAimePas":true}'; } elseif ($action == 11) { // bonus création de parties if (!isset($_GET['value'])) throw new Exception("La requête est incomplète", 2); addGameCreationBonus($user, $_GET['value']); } else { throw new Exception("Commande inconnue", 2); } } function server() { if(isset($_GET['callback'])) { echo $_GET['callback'].'('; header("Content-Type: application/javascript; charset=utf-8"); } else { header("Content-Type: application/json; charset=utf-8"); } ob_start(); try { main(); ob_end_flush(); } catch (Exception $e) { ob_end_clean(); $code = $e->getCode(); $msg = $e->getMessage(); if ($code != 10 && $code != 3) $msg = "Erreur ".$code." : " . $msg; echo JSON_encode( Array( "error" => $code, "msg" => $msg, "isError" => true ) ); logError($e->getCode(), $e->getMessage(), date("c")); closeDB(); } if(isset($_GET['callback'])) echo ')'; } server(); ?>