-
Notifications
You must be signed in to change notification settings - Fork 0
/
snailscore.php
96 lines (76 loc) · 2.26 KB
/
snailscore.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
$dbserver = "localhost";
$dbuser = "magicsnail";
$dbname = "magicsnail";
$dbpass = "EArCzlHOgKhi19gM";
$mymode = $_GET["mode"];
if (!isset($mymode)) {
die('Error 2');
}
if ($mymode != "get" && $mymode != "set" && $mymode != "redirecttobadge") {
die('Error 3');
}
if ($mymode == "set") {
$score = $_GET["score"];
if (!isset($score) || !is_numeric($score)) {
die('Error 4');
}
$conn = new mysqli($dbserver, $dbuser, $dbpass, $dbname);
if ($conn->connect_error) {
die("Error 61");
}
$stmt = $conn->prepare("INSERT INTO scores (score) VALUES (?)");
$stmt->bind_param("d", $score);
$stmt->execute();
$stmt->close();
$yourplace = $conn->prepare("select count(*) from scores where score > ?");
$yourplace->bind_param("d", $score);
$yourplace->execute();
$yourplace->bind_result($place);
$yourplace->fetch();
$yourplace->close();
$place = (int)$place+1;
$totalscores = $conn->prepare("select count(*) from scores");
$totalscores->execute();
$totalscores->bind_result($total);
$totalscores->fetch();
$totalscores->close();
echo $place . "/" . $total;
$conn->close();
}
if ($mymode == "get") {
$conn = new mysqli($dbserver, $dbuser, $dbpass, $dbname);
if ($conn->connect_error) {
die("Error 62");
}
$allscores = "select score from scores order by score desc LIMIT 12";
$allscores = $conn->query($allscores);
while($scorerow = $allscores->fetch_assoc()) {
echo $scorerow["score"] . ";";
}
$allscores->close();
$conn->close();
}
if ($mymode == "redirecttobadge") {
$conn = new mysqli($dbserver, $dbuser, $dbpass, $dbname);
if ($conn->connect_error) {
die("Error 63");
}
$highestscore = $conn->prepare("select max(score) from scores");
$highestscore->execute();
$highestscore->bind_result($score);
$highestscore->fetch();
$highestscore->close();
header('Location: https://img.shields.io/badge/highscore-' . $score . '-success');
$allscores->close();
$conn->close();
}
/*
CREATE TABLE `scores` (
`timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`score` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
http://tclinux.de/snailscore.php?mode=get
http://tclinux.de/snailscore.php?mode=redirecttobadge
http://tclinux.de/snailscore.php?mode=set&score=5600
*/