summaryrefslogtreecommitdiff
path: root/tdd/tdd-protocol.php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-11-14 00:02:29 +0100
committeremkael <emkael@tlen.pl>2018-11-14 00:15:51 +0100
commite80a2610d5b29b35fa7a787bb5e8ae72c856c2c8 (patch)
treef12c608e07acd7c4c52654c4a49b662f1718a1aa /tdd/tdd-protocol.php
parent9e6bd1bd8eeb3aa9dd3ca43dbe7f798b88c46dd0 (diff)
Matching tournament prefixes and rounds in board DB against URI parts, not the other way around.
Fixes #1
Diffstat (limited to 'tdd/tdd-protocol.php')
-rw-r--r--tdd/tdd-protocol.php46
1 files changed, 27 insertions, 19 deletions
diff --git a/tdd/tdd-protocol.php b/tdd/tdd-protocol.php
index 7130599..f8a6e3e 100644
--- a/tdd/tdd-protocol.php
+++ b/tdd/tdd-protocol.php
@@ -1,31 +1,39 @@
<?php
-$prefix = $_GET['prefix'];
-$round = (int)$_GET['round'];
-$board = (int)$_GET['board'];
-
require_once('tdd-bootstrap.php');
refresh_board_database();
-$protocol = new Protocol($prefix, $round, $board);
-
-// security check
-$html_filename = $protocol->get_filename();
-$len = strlen($html_filename);
-$request_uri_ending = substr($_SERVER['REQUEST_URI'], -$len-1);
-if($request_uri_ending != '/' . $html_filename) {
+// parsing URI parts from full request string
+$uri = explode('b-', basename($_SERVER['REQUEST_URI']));
+if (count($uri) < 2) {
die('This script cannot be called directly!');
}
-//
-$deals_by_tables = load_deals_for_tables($prefix, $round, $board);
-if (count($deals_by_tables) > 0) {
- foreach($deals_by_tables as $table => $deal) {
- $protocol->set_deal($table, $deal);
+$board = (int)(array_pop($uri));
+$roundPrefix = implode('b-', $uri);
+
+try {
+ // GET parameters pre-parsed by mod_rewrite are used for HTML fallback
+ // in case {$prefix}{$round} combo is not matched against board DB
+ $protocol = new Protocol($_GET['prefix'], $_GET['round'], $board);
+ $html_filename = $protocol->get_filename();
+ foreach ($board_database as $prefix => $rounds) {
+ foreach ($rounds as $round => $boards) {
+ if ($prefix . $round === $roundPrefix) {
+ $deals_by_tables = load_deals_for_tables($board_database, $prefix, $round, $board);
+ if (count($deals_by_tables) > 0) {
+ foreach($deals_by_tables as $table => $deal) {
+ $protocol->set_deal($table, $deal);
+ }
+ echo $protocol->output();
+ exit(0);
+ }
+ }
+ }
}
- echo $protocol->output();
-}
-else {
readfile($html_filename);
+} catch (Exception $e) {
+ header('HTTP/1.0 404 Not Found');
+ die();
}