aboutsummaryrefslogtreecommitdiff
path: root/backend/index.php
diff options
context:
space:
mode:
authorhitlerrip <git@hitler.rip>2025-07-29 20:27:10 +0200
committerhitlerrip <git@hitler.rip>2025-07-29 20:27:10 +0200
commit445d3200ba29e9be9b2563b92616bda6399f0577 (patch)
tree802a50012c74e454059e7171079ee5194239a869 /backend/index.php
parent551b95fa58bf62b4a0780e09b9cba434eae52786 (diff)
downloadhitler-clicker-445d3200ba29e9be9b2563b92616bda6399f0577.tar.gz
hitler-clicker-445d3200ba29e9be9b2563b92616bda6399f0577.tar.bz2
hitler-clicker-445d3200ba29e9be9b2563b92616bda6399f0577.zip
proper auth
added tokens and forced user to join a team on account creation, along with other minor changes
Diffstat (limited to 'backend/index.php')
-rw-r--r--backend/index.php37
1 files changed, 35 insertions, 2 deletions
diff --git a/backend/index.php b/backend/index.php
index dead696..2aba190 100644
--- a/backend/index.php
+++ b/backend/index.php
@@ -4,14 +4,47 @@ 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 , `team` VARCHAR(256) NOT NULL DEFAULT 'axis' , `clicks` INT(128) unsigned zerofill NOT NULL DEFAULT '0', PRIMARY KEY (`name`) ) ENGINE = InnoDB;");
+$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 '{ "status": "online" }';
+echo ' }';
?>