Example #1
4
    }
    if (count($scores) > 10) {
        $junk = array_pop($scores);
    }
    $fh = fopen($inf, 'w') or die("0");
    if (flock($fh, LOCK_EX)) {
        // do an exclusive lock
        foreach ($scores as $item) {
            fwrite($fh, "{$item}\n");
        }
        flock($fh, LOCK_UN);
        // release the lock
    } else {
        die("2");
    }
    fclose($fh);
}
if (isset($_POST['ts']) && isset($_COOKIE['token']) && $_COOKIE['token'] == md5('j c tunnel' . $_POST['ts']) && isset($_POST['name'])) {
    $playerName = htmlspecialchars($_POST['name']);
    $playerScore = htmlspecialchars($_POST['highscore']);
    addScore($playerName, $playerScore);
    echo "1";
} else {
    if (isset($_POST['score'])) {
        $playerScore = htmlspecialchars($_POST['score']);
        $result = checkScore($playerScore);
        echo "{$result}";
    } else {
        showScores();
    }
}
Example #2
1
    // Remove excess scores
    while (count($scores) > $maxScores) {
        array_pop($scores);
    }
    // Open the scores file for reading
    $scoresFile = fopen("highscores.txt", "w") or die("Unable to open file!");
    // Write the scores
    $i;
    $len = count($scores);
    foreach ($scores as $name => $score) {
        fwrite($scoresFile, $name . " " . strval($score));
        if ($i < $len - 1) {
            fwrite($scoresFile, "\n");
        }
        $i += 1;
    }
    // Close the file
    fclose($scoresFile);
}
if (!empty($_POST["data"])) {
    $score = $_POST["data"];
    if (!empty($_POST["name_data"])) {
        $name = $_POST["name_data"];
    } else {
        $name = "noone";
    }
    addScore($score, $name);
}
?>
</body>
</html>
Example #3
0
// Ensure running over HTTPS
if ($_SERVER["HTTPS"] != "on") {
    // reportError("Only available through HTTPS", 1);
    die("fail");
}
// Ensure if they're adding a score that they've given a score to add
if ($_POST["action"] == "add" && !isset($_POST["score"])) {
    die("no score provided");
}
if ($_POST["action"] == "add") {
    if (!isset($_POST["name"])) {
        $name = "Anonymous";
    } else {
        $name = $_POST["name"];
    }
    if (!addScore($name, $_POST["score"])) {
        die("fail");
    } else {
        die("ok");
    }
}
?>
<html>
<head>
<title>ArcTetris Highscores</title>
<style>
h1 {
	font-family: Arial, Helvetica, sans-serif;
	text-align: center;
}
.scores {
Example #4
0
addToArr("notes.subj", $usersubj);
if (count($qarr) != 0) {
    $t = implode(" AND ", $qarr);
}
$warr = explode(" ", $userq);
foreach ($warr as $x) {
    $query = "SELECT indextable.notesid, indextable.occurrence\r\n\t\t  FROM indextable INNER JOIN notes ON indextable.notesid = notes.id\r\n\t\t  WHERE indextable.word = '{$x}' ";
    if (isset($t)) {
        $query .= " AND " . $t;
    }
    $q = $conn->query($query);
    if ($q->num_rows != 0) {
        while ($r = $q->fetch_assoc()) {
            $id = $r['indextable.notesid'];
            $occ = $r['indextable.occurrence'];
            addScore($id, 1 + $occ / 100);
        }
    }
}
$i = 0;
arsort($scorearr);
$res = array();
foreach ($scorearr as $v => $k) {
    if ($i == 30 || $k <= 0) {
        break;
    }
    $q = $conn->query("SELECT id, exttype, title,preview FROM notes WHERE approved = 1 AND id = {$v}");
    $r = $q->fetch_assoc();
    $res[] = $r;
    $i++;
}
Example #5
0
/*
|--------------------------------------------------------------------------
| Post Score
|--------------------------------------------------------------------------
|
|
*/
global $scoresDb;
$score = (int) $_POST['score'];
if ($score && is_numeric($score)) {
    try {
        $scoresDb = new PDO('sqlite:scores.db');
        $scoresDb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        // Create table messages
        $scoresDb->exec("CREATE TABLE IF NOT EXISTS scores (\n                    id INTEGER PRIMARY KEY,\n                    score INT,\n                    initials TEXT,\n                    time INTEGER)");
        addScore($score);
        $scoresDb = null;
    } catch (Exception $e) {
        die("Could not add score to db" . $e->getMessage());
    }
}
function addScore($score)
{
    global $scoresDb;
    if ($scoresDb) {
        $insert = "INSERT INTO scores (score, time) VALUES(:score, :time)";
        $stmt = $scoresDb->prepare($insert);
        $stmt->bindParam(':score', $score);
        $stmt->bindParam(':time', time());
        $stmt->execute();
    }
Example #6
0
<?php

session_start();
header("Content-Type:text/plain;charset=utf-8");
include_once 'fun.inc.php';
linkDB();
$uid = $_SESSION["uid"];
$semester = $_POST["term"];
$type_name = $_POST["kind"];
$class_chinese_name = $_POST["course"];
$score = $_POST["grade"];
/*
	$uid = 1;
	$semester = 1;
	$type_name = "基础课";
	$class_chinese_name = "C语言";
	$score = 82;
*/
$back = addScore($uid, $semester, $type_name, $class_chinese_name, $score);
$data = array("success" => $back);
echo json_encode($data, JSON_UNESCAPED_UNICODE);
Example #7
0
<?php

/* Tabla
CREATE TABLE puntuaciones (  id_jugador int(5) auto_increment,  nombre varchar(255),  mensaje varchar(255),  puntuacion int (11),  PRIMARY KEY (id_jugador) );
*/
mysql_connect('server', 'user', 'pass');
mysql_select_db('db');
switch ($_GET['action']) {
    case 'addScore':
        addScore($_GET['nombre'], $_GET['puntuacion']);
        break;
    case 'addMessage':
        addMessage($_GET['id'], $_GET['mensage']);
        break;
}
function listScores()
{
    $query = 'SELECT * FROM puntuaciones order by puntuacion desc';
    $result = mysql_query($query);
    return $result;
}
function addScore($score, $nombre)
{
    return mysql_query("INSERT INTO puntuaciones values (null, " . $nombre . ", '', " . $score . ")");
}
function addMessage($id, $message)
{
    return mysql_query("UPDATE puntuaciones set mensaje = '" . $message . "' where id_jugador = " . $id);
}
Example #8
0
<?php

include "buzz.php";
function buzzHandler1($message)
{
    echo "901";
    die;
}
set_error_handler("buzzHandler");
$mode = $_GET["mode"];
if ($mode == "scores") {
    addScore(addslashes($_GET["username"]), intval($_GET["score"]));
} else {
    if ($mode == "info") {
        function buzzHandler2($message)
        {
            echo "\n\n\n";
            die;
        }
        set_error_handler("buzzHandler2");
        $details = getUserScores(addslashes($_GET["username"]));
        if (count($details) > 0) {
            echo round(pow(1.01, 1000 - $details[0][2])) . "\n";
        } else {
            echo "0\n";
        }
        $list = getHighScores(1);
        echo round(pow(1.01, 1000 - $list[0][2])) . "\n";
        echo $list[0][1] . "\n";
        echo "0.1";
        restore_error_handler();
Example #9
-1
#foreach ($_POST as $i => $value) {
#echo $_POST[$i], "\n";
#}
#echo "GET size=", count($_GET), "\n";
#foreach ($_GET as $i => $value) {
#echo $_GET[$i], "\n";
#}
#echo "------------------------------------\n";
if (connectToDb() == 1) {
    if ($_POST['mode'] == "test") {
        echo "Test successful. User="******"add") {
            echo addScore($_GET['user'], $_GET['score'], $_GET['desc']);
        } elseif ($_POST['mode'] == "add") {
            echo addScore($_POST['user'], $_POST['score'], $_POST['desc']);
        } elseif ($_GET['mode'] == "rss") {
            echoRSS();
        } else {
            ?>
<html>
   <head>
       <title>Scourge High Scores</title>
       <link rel=StyleSheet href="scourge.css" type="text/css">
   </head>
   <body>
<?php 
            # save the version of scourge sent:
            # echo $_SERVER['HTTP_USER_AGENT'];
            displayList();
            ?>