Exemplo n.º 1
0
function sendChat($d, $ip, $token)
{
    if ($obs = json_decode($d, true)) {
        if (!checkToken($ip, $token)) {
            return -1;
        } else {
            //check user room num before sending chat
            $room = filter_var($obs['room'], FILTER_SANITIZE_STRING);
            $text = htmlentities(preg_replace("/[^a-zA-Z ]*/", "", $obs['text']), ENT_QUOTES, "utf-8");
            if (sendChatData($room, $_SESSION['user_id'], $text) > 0) {
                echo getChatData();
            } else {
                return -1;
            }
        }
    } else {
        return -1;
    }
}
Exemplo n.º 2
0
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);
    }
}
Exemplo n.º 3
0
function chatData($d, $ip, $token)
{
    return getChatData();
}