예제 #1
0
include_once 'dbscore.class.php';
$data = json_decode(file_get_contents("php://input"));
$response = [];
if ($data->gameid == "" || $data->gameid == 0) {
    $response['success'] = false;
    $response['message'] = 'Invalid User Id';
}
if ($data->name == "" || $data->name == null) {
    $response['success'] = false;
    $response['message'] = 'Invalid name';
}
if ($data->score == "" || $data->score == null) {
    $response['success'] = false;
    $response['message'] = 'Invalid score';
}
if ($data->token == "" || $data->token == null) {
    $response['success'] = false;
    $response['message'] = 'Could not save token';
}
$dbscore = new dbscore();
$success = $dbscore->updateHighScore($data->gameid, $data->name, $data->score, $data->token);
if ($success) {
    $response['success'] = true;
    $response['message'] = '';
} else {
    $response['success'] = false;
    $response['message'] = 'Could not save prediction';
}
$jsonResponse = json_encode($response);
print_r($jsonResponse);
예제 #2
0
<?php

include_once 'dbscore.class.php';
$response = [];
$gameid = '';
$score = 0;
$gameid = $_GET['gameid'];
if (isset($_GET['score'])) {
    $score = $_GET['score'];
}
if ($gameid == "" || $gameid == 0) {
    $response['success'] = false;
    $response['message'] = 'Invalid Game Id';
} else {
    if ($score != 0) {
        $dbscore = new dbscore();
        $isHighScore = false;
        $isHighScore = $dbscore->checkHighScore($gameid, $score);
        if ($isHighScore) {
            $token = $dbscore->createHighScore($gameid, $score);
            $response['ishighscore'] = "yes";
            $response['highscoretoken'] = $token;
            $response['highscores'] = $dbscore->loadHighScores($gameid);
        }
    } else {
        $dbscore = new dbscore();
        $response = $dbscore->loadHighScores($gameid);
    }
}
$jsonResponse = json_encode($response);
print_r($jsonResponse);