function checkTurn($data, $ip, $token) { //check token if (!checkToken($ip, $token)) { return "verification_error"; } else { $data = explode("|", $data); $d = $data[0]; $gameId = $data[1]; if ($d == 0) { // 0 signifies it is not my turn on client $turn = 0; //it is not my turn, so I will check the DB to see if it has changed $turnData = json_decode(checkTurnData($gameId)); //there should be 2 results returned, we will iterate results to select correct row based upon player ID foreach ($turnData as $player) { if ($player->player == $_SESSION['user_id']) { //this is the correct row $turn = $player->turn; } } } // we will still check chat data for the game regardless of turn $chat = getChatData($gameId); if (is_null($chat)) { $chat = "no chat"; } $res = array($chat, $turn); return json_encode($res); } }
function checkTurn($d) { //Can they check is it my turn yet? //if true: return checkTurnData($d); }