blob: dc97812353777843f1563862f133f89caa7b29b2 (
plain) (
blame)
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
|
<?php
/* hitler-clicker
* api for setting up database and returning total team clicks
* © 2025 hitler.rip <git@hitler.rip>
* licensed under AGPLv3-or-later; see LICENSE.md for more information
*/
header('Content-Type: application/json; charset=UTF-8');
try {
$pdo = new PDO("mysql:host=127.0.0.1;dbname=hitlerclicker", "root", "aA1234Aa");
} catch(PDOException $e) {
echo "$e";
die('{ "status": "database offline" }');
};
/*
$query = $pdo->prepare("DROP TABLE `hitlerclicker`.`stats`");
$query->execute();
$query = $pdo->prepare("DROP TABLE `hitlerclicker`.`users`");
$query->execute();
*/
$query = $pdo->prepare("CREATE TABLE IF NOT EXISTS `hitlerclicker`.`stats` ( `team` VARCHAR(256) NOT NULL DEFAULT uuid() , `clicks` INT(128) unsigned zerofill NOT NULL DEFAULT '0', PRIMARY KEY (`team`) ) ENGINE = InnoDB;");
$query->execute();
$query = $pdo->prepare("CREATE TABLE IF NOT EXISTS `hitlerclicker`.`users` ( `name` VARCHAR(256) NOT NULL DEFAULT uuid() , `password` VARCHAR(256) NOT NULL , `token` VARCHAR(256) NOT NULL DEFAULT uuid() , `team` VARCHAR(256) NOT NULL DEFAULT 'axis' , `clicks` INT(128) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`name`) ) ENGINE = InnoDB;");
$query->execute();
$query = $pdo->prepare("INSERT IGNORE INTO `stats` (`team`) VALUES (:team)");
$query->execute([ "team" => "axis" ]);
$query = $pdo->prepare("INSERT IGNORE INTO `stats` (`team`) VALUES (:team)");
$query->execute([ "team" => "allies" ]);
$query = $pdo->prepare("INSERT IGNORE INTO `stats` (`team`) VALUES (:team)");
$query->execute([ "team" => "soviet" ]);
$query = $pdo->prepare("SELECT team, clicks FROM stats WHERE team LIKE '%' ORDER BY clicks DESC");
$query->execute();
$found = $query->fetchALL(PDO::FETCH_ASSOC);
echo '{ "status": "online", ';
$i = 0;
foreach($found as $row):
$i++;
if ($i === sizeof($found)) {
echo " \"$row[team]\": \"$row[clicks]\" ";
} else {
echo " \"$row[team]\": \"$row[clicks]\", ";
};
endforeach;
echo ' }';
?>
|