le-pere-noel-secret/public/index.php

59 lines
1.4 KiB
PHP
Raw Normal View History

2020-10-31 18:34:26 +01:00
<?php
require __DIR__.'/../etc/config.php';
require __DIR__.'/../etc/database.php';
2020-10-31 18:34:26 +01:00
$_ = [
'canPlay' => false,
'player' => null,
];
2020-11-01 13:13:56 +01:00
$personRequested = (string) ($_GET['p'] ?? '');
2020-10-31 18:34:26 +01:00
foreach ($persons as $hash => $person) {
2020-11-01 13:13:56 +01:00
if ($personRequested === (string) $hash) {
2020-10-31 18:34:26 +01:00
$_['player'] = $person;
$_['hash'] = $personRequested;
}
}
if ($_['player']) {
$_['result'] = getData('result.'.$_['player']);
$_['canPlay'] = empty($_['result']);
$in = getData('in', $persons);
$out = getData('out', []);
if ($_['canPlay'] && isset($_GET['go'])) {
$result = null;
while ($result === null) {
$key = array_rand($in);
$value = $in[$key];
$ok = $value !== $_['player'];
foreach ($restrictions as $restriction) {
if (in_array($value, $restriction) && in_array($_['player'], $restriction)) {
$ok = false;
}
}
if ($ok) {
$result = $value;
setData('result.'.$_['player'], $result);
unset($in[$key]);
$out[] = $value;
$_['canPlay'] = false;
$_['result'] = $result;
}
}
setData('in', $in);
setData('out', $out);
saveDatabase();
}
}
require __DIR__.'/../template/index.php';