public function process()
 {
     $db = db::getInstance();
     $user = user::getInstance();
     include './models/game.class.php';
     // récupérer le gameid si il existe
     $game = false;
     $this->gameid = isset($_REQUEST['gameid']) ? intval($_REQUEST['gameid']) : false;
     if ($this->gameid !== false) {
         $game = new game();
         if (!$game->read($this->gameid)) {
             $this->gameid = false;
             trigger_error('Game not found!', E_USER_ERROR);
         }
         if (!isset($game->userids[$user->id])) {
             $this->gameid = false;
             trigger_error('Not your game!', E_USER_ERROR);
         }
     }
     /*// fermer toute grille en cours pour cet utilisateur
     		$sql = 'UPDATE gamesstatus
     					SET gridstatus = ' . intval(GRIDSTATUS_FINISHED) . '
     					WHERE userid = ' . intval($user->id) . '
     						AND gridstatus = ' . intval(GRIDSTATUS_STARTED);
     		$db->query($sql);*/
     // déterminer le type de partie à partir du mode
     $gametype = false;
     switch ($this->mode) {
         case 'game.launch.practice.allwords':
             $gametype = GAMETYPE_PRACTICE_ALLWORDS;
             break;
         case 'game.launch.practice.longest':
             $gametype = GAMETYPE_PRACTICE_LONGEST;
             break;
         case 'game.launch.practice.constraints':
             $gametype = GAMETYPE_PRACTICE_CONSTRAINTS;
             break;
         case 'game.launch.practice.full':
             $gametype = GAMETYPE_PRACTICE_FULL;
             break;
     }
     // créer une nouvelle partie
     if (!$this->gameid) {
         $userids = array($user->id);
         $game = new game();
         $this->gameid = $game->create($userids, $gametype, $user->get_lang());
     }
     return $this->display();
 }
     }
     // change the team profile
     if (!$team->changeProfile($gameId, $profile)) {
         rollbackAndDie();
     }
     break;
     // ------------------------------
     // create
     // ------------------------------
 // ------------------------------
 // create
 // ------------------------------
 case 'create':
     header('Content-Type: application/json');
     if (isset($_GET['roundTime'])) {
         $game->create(intval(htmlspecialchars($_GET['roundTime'])));
     } else {
         $game->create();
     }
     if (!empty($game->getStatus())) {
         echo json_encode(array('gameId' => $game->getGameId(), 'gameToken' => $game->getGameToken()), JSON_PRETTY_PRINT);
     }
     break;
     // ------------------------------
     // join
     // ------------------------------
 // ------------------------------
 // join
 // ------------------------------
 case 'join':
     // check inputs
    public function process()
    {
        $user = user::getInstance();
        $db = db::getInstance();
        include './models/game.class.php';
        /*// fermer toute grille en cours pour cet utilisateur
        		$sql = 'UPDATE gamesstatus
        					SET gridstatus = ' . intval(GRIDSTATUS_FINISHED) . '
        					WHERE userid = ' . intval($user->id) . '
        						AND gridstatus = ' . intval(GRIDSTATUS_STARTED);
        		$db->query($sql);*/
        // lire l'invitation
        $invitid = isset($_REQUEST['invitid']) ? intval($_REQUEST['invitid']) : 0;
        $gameid = isset($_REQUEST['gameid']) ? intval($_REQUEST['gameid']) : 0;
        // lire sur invitid
        if ($invitid) {
            $sql = 'SELECT *
						FROM invitations
						WHERE invitid = ' . intval($invitid);
            $result = $db->query($sql);
            $data = ($row = $result->fetch_assoc()) ? $row : false;
            if ($data === false) {
                trigger_error('No invitation', E_USER_ERROR);
            }
            // invitation reçue
            if (intval($data['touserid']) === $user->id) {
                $gametype = GAMETYPE_BATTLE;
                $userids = array($user->id, intval($row['fromuserid']));
                $game = new game();
                $this->gameid = $game->create($userids, $gametype, $user->get_lang());
                $sql = 'UPDATE invitations
							SET gameid = ' . $this->gameid . '
							WHERE invitid = ' . intval($invitid);
                $db->query($sql);
            } else {
                $this->gameid = $row['gameid'];
                $sql = 'DELETE FROM invitations
							WHERE invitid = ' . intval($invitid);
                $db->query($sql);
            }
        } else {
            $this->gameid = intval($gameid);
            $game = new game();
            if (!$game->read($this->gameid)) {
                trigger_error('No game!', E_USER_ERROR);
            }
        }
        // lire les grilles terminées pour trouver le prochain type de grille
        $grid_counts = array();
        $last_grid = 0;
        $sql = 'SELECT userid, COUNT(gridid) AS count_gridid
					FROM gamesstatus
					WHERE gameid = ' . intval($this->gameid) . '
						AND gridstatus = ' . intval(GRIDSTATUS_FINISHED) . '
					GROUP BY userid';
        $result = $db->query($sql);
        while ($row = $result->fetch_assoc()) {
            $grid_counts[intval($row['userid'])] = intval($row['count_gridid']);
            if (intval($row['count_gridid']) > $last_grid && intval($row['userid']) != $user->id) {
                $last_grid = intval($row['count_gridid']);
            }
        }
        if (isset($grid_counts[$user->id])) {
            if ($grid_counts && $last_grid < intval($grid_counts[$user->id])) {
                redirect('game.result&gameid=' . intval($this->gameid));
                exit;
                trigger_error('Wait for the other!', E_USER_ERROR);
            }
        }
        return $this->display();
    }