~skye/poker/act/join.php

view raw


<?php

require '../com.php';
require '../src/room.php';

try {
	form_has_get([
		"h" => [1, 64]
	]);
} catch (Exception $e) {
	exit(page_err("invalid form parameters: " . $e->getMessage()));
}

/* leave old room if ?clr is set */
if (isset($_GET["clr"]) && isset($_SESSION["room"])) {
	unset($_SESSION["room"]);
}

$db = new Database("../run/poker.db");
$me = whoami($db);
if (!$me) {
	exit(page_err("not logged in"));
}

$h = $_GET["h"];
$r = Room::from_hash($h);

/* add yourself to the room */
$r->new_user($me->id);

/* set the room hash in session & redirect to room */
$_SESSION["room"] = $h;
header("Location: /act/room.php?h=$h");

?>