Skip to content

Commit

Permalink
Fixed bases scoring system
Browse files Browse the repository at this point in the history
  • Loading branch information
javuto committed May 10, 2016
1 parent d26178a commit 6e79f46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/models/Level.php
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ public static function getBasesResponses(
public static async function genBaseScoring(
): Awaitable<void> {
$document_root = must_have_string(Utils::getSERVER(), 'DOCUMENT_ROOT');
$cmd = 'hhvm -vRepo.Central.Path=/tmp/.hhvm.hhbc_bases '.escapeshellarg($document_root).'/scripts/bases.php > /dev/null 2>&1 & echo $!';
$cmd = 'hhvm -vRepo.Central.Path=/tmp/.hhvm.hhbc_bases '.$document_root.'/scripts/bases.php > /dev/null 2>&1 & echo $!';
$pid = shell_exec($cmd);
await Control::genStartScriptLog(intval($pid), 'bases', $cmd);
}
Expand Down
18 changes: 10 additions & 8 deletions src/scripts/bases.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

require_once('/var/www/fbctf/vendor/autoload.php');

while ((Configuration::get('game')->getValue() === '1')) {
$conf_game = \HH\Asio\join(Configuration::gen('game'));
while ($conf_game->getValue() === '1') {
// Get all active base levels
$bases_endpoints = array();
foreach (Level::allActiveBases() as $base) {
foreach (\HH\Asio\join(Level::genAllActiveBases()) as $base) {
$endpoint = array(
'id' => $base->getId(),
'url' => Level::getBaseIP($base->getId())
'url' => \HH\Asio\join(Level::genBaseIP($base->getId()))
);
array_push($bases_endpoints, $endpoint);
}
Expand All @@ -20,18 +21,19 @@
$json_r = json_decode($response['response'])[0];
$teamname = $json_r->team;
// Give points to the team if exists
if (Team::teamExist($teamname)) {
$team = Team::getTeamByName($teamname);
Level::scoreBase($response['id'], $team->getId());
if (\HH\Asio\join(Team::genTeamExist($teamname))) {
$team = \HH\Asio\join(Team::genTeamByName($teamname));
\HH\Asio\join(Level::genScoreBase($response['id'], $team->getId()));
//echo "Points\n";
}
//echo "Base(".strval($response['id']).") taken by ".$teamname."\n";
} else {
$code = -1;
//echo "Base(".strval($response['id']).") is DOWN\n";
}
Level::logBaseEntry($response['id'], $code, strval($response['response']));
\HH\Asio\join(Level::genLogBaseEntry($response['id'], $code, strval($response['response'])));
}
// Wait until next iteration
sleep(intval(Configuration::get('bases_cycle')->getValue()));
$bases_cycle = \HH\Asio\join(Configuration::gen('bases_cycle'));
sleep(intval($bases_cycle->getValue()));
}

0 comments on commit 6e79f46

Please sign in to comment.