65 lines
2.7 KiB
PHP
65 lines
2.7 KiB
PHP
<?php
|
|
require_once 'core/classes.php';
|
|
require_once 'core/classes/user.php';
|
|
header('content-Type: text/plain'); // set the content type to text plain
|
|
ob_start();
|
|
session_start();
|
|
if($maintenance && $pagename !== "Maintenance") {
|
|
header("Location: /maintenance" // is maintenance enabled??
|
|
);
|
|
}
|
|
$user = new User($con, $_SESSION['user'] ?? 0);
|
|
if(!$user->isLoggedIn()) {
|
|
header('location: /login'); // alr hes not signed in so get him out of here
|
|
exit;
|
|
}
|
|
$placeid = $_GET['placeid'];
|
|
if (!isset($placeid)) {
|
|
die("No placeid"); // placeid was not found AND FUTURE MARIO HERE USE GOD DAMN DIE()
|
|
}
|
|
$username = $user->getUsername();
|
|
$id = $user->getID($con, $user->getUsername());
|
|
function generateRandomString($length = 25) {
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$randomString .= $characters[random_int(0, $charactersLength - 1)];
|
|
}
|
|
return $randomString;
|
|
} // pls don't hurt me
|
|
$checkifuser = $con->prepare('SELECT COUNT(*) FROM games WHERE id=:placeid'); // check if the game even exists
|
|
$checkifuser->bindParam(':placeid', $placeid);
|
|
$checkifuser->execute();
|
|
$momentoftruth = $checkifuser->fetchColumn();
|
|
if ($momentoftruth == 1) {
|
|
$checktoken = $con->prepare('SELECT COUNT(*) FROM tokens WHERE placeid=:placeid AND passedplacelauncher=:passedplacelauncher AND passedjoinscript=:passedjoinscript');
|
|
$checktoken->bindParam(':placeid', $placeid);
|
|
$funnyint = '0';
|
|
$checktoken->bindParam(':passedplacelauncher', $funnyint);
|
|
$checktoken->bindParam(':passedjoinscript', $funnyint);
|
|
$checktoken->execute();
|
|
$getintforchecktoken = $checktoken->fetchColumn();
|
|
if ($getintforchecktoken == '1') {
|
|
$fbi2 = $con->prepare('SELECT token FROM tokens WHERE placeid=:placeid AND passedplacelauncher=:passedplacelauncher AND passedjoinscript=:passedjoinscript');
|
|
$fbi2->bindParam(':placeid', $placeid);
|
|
$fbi2->bindParam(':passedplacelauncher', $funnyint);
|
|
$fbi2->bindParam(':passedjoinscript', $funnyint);
|
|
$fbi2->execute();
|
|
$china3 = $fbi2->fetch(PDO::FETCH_BOTH);
|
|
$token = $china3['token'];
|
|
die($token); // DIE!
|
|
} elseif ($getintforchecktoken == '0') {
|
|
$token = generateRandomString(500);
|
|
$fbi = $con->prepare('INSERT INTO tokens (token, placeid, userid) VALUES (:token, :placeid, :userid)'); // make the token valid
|
|
$fbi->bindParam(':token', $token);
|
|
$fbi->bindParam(':placeid', $placeid);
|
|
$fbi->bindParam(':userid', $id);
|
|
$fbi->execute();
|
|
die($token); // HE FINALLY USED DIE
|
|
}
|
|
} else {
|
|
die('No PlaceId found'); // reminder to use die
|
|
}
|
|
?>
|