smrealms /
smr
We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php declare(strict_types=1); |
||
| 2 | |||
| 3 | use Smr\Database; |
||
| 4 | use Smr\Request; |
||
| 5 | |||
| 6 | try { |
||
| 7 | require_once('../bootstrap.php'); |
||
| 8 | |||
| 9 | $session = Smr\Session::getInstance(); |
||
| 10 | |||
| 11 | $gameID = Request::getInt('game'); |
||
| 12 | if (!$session->hasAccount() || !SmrGame::gameExists($gameID)) { |
||
| 13 | header('Location: /login.php'); |
||
| 14 | exit; |
||
| 15 | } |
||
| 16 | $game = SmrGame::getGame($gameID); |
||
| 17 | $account = $session->getAccount(); |
||
| 18 | |||
| 19 | if (!$game->isEnabled() && !$account->hasPermission(PERMISSION_UNI_GEN)) { |
||
| 20 | create_error('You do not have permission to view this map!'); |
||
| 21 | } |
||
| 22 | |||
| 23 | $nodes = []; |
||
| 24 | $links = []; |
||
| 25 | |||
| 26 | // The d3 graph nodes are the galaxies |
||
| 27 | foreach ($game->getGalaxies() as $galaxy) { |
||
| 28 | $nodes[] = [ |
||
| 29 | 'name' => $galaxy->getName(), |
||
| 30 | 'id' => $galaxy->getGalaxyID(), |
||
| 31 | 'group' => array_search($galaxy->getGalaxyType(), SmrGalaxy::TYPES), |
||
| 32 | 'size' => $galaxy->getSize(), |
||
| 33 | ]; |
||
| 34 | } |
||
| 35 | |||
| 36 | // The d3 graph links are the warp connections between galaxies |
||
| 37 | $db = Database::getInstance(); |
||
| 38 | $dbResult = $db->read('SELECT sector_id, warp FROM sector WHERE warp !=0 AND game_id = ' . $db->escapeNumber($gameID)); |
||
| 39 | foreach ($dbResult->records() as $dbRecord) { |
||
| 40 | $warp1 = SmrSector::getSector($gameID, $dbRecord->getInt('sector_id')); |
||
| 41 | $warp2 = SmrSector::getSector($gameID, $dbRecord->getInt('warp')); |
||
| 42 | $links[] = [ |
||
| 43 | 'source' => $warp1->getGalaxy()->getName(), |
||
| 44 | 'target' => $warp2->getGalaxy()->getName(), |
||
| 45 | ]; |
||
| 46 | } |
||
| 47 | |||
| 48 | // Encode the data for use in the javascript |
||
| 49 | $data = json_encode([ |
||
| 50 | 'nodes' => $nodes, |
||
| 51 | 'links' => $links, |
||
| 52 | ]); |
||
| 53 | |||
| 54 | $template = Smr\Template::getInstance(); |
||
| 55 | $template->assign('GameName', $game->getName()); |
||
| 56 | $template->assign('GraphData', $data); |
||
| 57 | $template->display('map_warps.php'); |
||
| 58 | } catch (Throwable $e) { |
||
| 59 | handleException($e); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 60 | } |
||
| 61 |