diff --git a/agent-info.php b/agent-info.php deleted file mode 100644 index b4e1046..0000000 --- a/agent-info.php +++ /dev/null @@ -1,565 +0,0 @@ - - * @license MIT License - * @link https://git.keithsolomon.net/keith/Spacetraders - */ - -require_once __DIR__ . '/lib/spacetraders-api.php'; -require_once __DIR__ . '/lib/spacetraders-storage.php'; - -$config = require __DIR__ . '/lib/project-config.php'; - -$storage = new SpacetradersStorage( $config['db_path'] ); -$token = $storage->getAgentToken(); -$statusMessage = ''; -$errorMessage = ''; - -if (! is_string( $token ) || trim( $token ) === '') { - $envToken = getenv( 'SPACETRADERS_TOKEN' ); - if (is_string( $envToken ) && trim( $envToken ) !== '' ) { - $token = trim( $envToken ); - $storage->setAgentToken( $token ); - } -} - -if (! is_string( $token ) || trim( $token ) === '') { - $tokenError = 'No token found. Set one in config.php or SPACETRADERS_TOKEN.'; -} - -$agent = array(); -$ships = array(); -$contracts = array(); -$system = array(); -$systemWaypoints = array(); -$paginatedWaypoints = array(); -$marketDetails = array(); -$shipyardDetails = array(); -$selectedShipSymbol = ''; -$selectedWaypointSymbol = ''; -$waypointPageSize = 25; -$waypointPage = isset( $_GET['waypoint_page'] ) ? max( 1, (int) $_GET['waypoint_page'] ) : 1; -$waypointTotalPages = 1; - -if (! isset( $tokenError ) ) { - $client = new SpacetradersApi( - trim( $token ), - $config['api_base_url'], - (int) $config['api_timeout'], - $storage, - (int) $config['cache_ttl'] - ); - - if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset( $_POST['navigate_ship'] ) && isset( $_POST['ship_symbol'] ) && isset( $_POST['waypoint_symbol'] )) { - $selectedShipSymbol = trim( (string) $_POST['ship_symbol'] ); - $selectedWaypointSymbol = trim( (string) $_POST['waypoint_symbol'] ); - - if ($selectedShipSymbol !== '' && $selectedWaypointSymbol !== '' ) { - try { - $selectedShipResponse = $client->getShip( $selectedShipSymbol ); - $selectedShipData = $selectedShipResponse['data'] ?? array(); - $shipNavStatus = (string) ( $selectedShipData['nav']['status'] ?? '' ); - - if ($shipNavStatus === 'IN_TRANSIT' ) { - throw new SpacetradersApiException( - 'Selected ship is currently in transit and cannot navigate yet.' - ); - } - - if ($shipNavStatus === 'DOCKED' ) { - $client->orbitShip( $selectedShipSymbol ); - } - - $client->navigateShip( $selectedShipSymbol, $selectedWaypointSymbol ); - $storage->clearAllCache(); - $statusMessage = 'Navigation started for ' . $selectedShipSymbol . '.'; - } catch (SpacetradersApiException $e) { - $errorMessage = 'Unable to navigate ship: ' . $e->getMessage(); - } - } - } - - if (isset( $_GET['accept_contract'] ) && is_string( $_GET['accept_contract'] ) && trim( $_GET['accept_contract'] ) !== '') { - try { - $client->acceptContract( trim( $_GET['accept_contract'] ) ); - $storage->clearAllCache(); - $statusMessage = 'Contract accepted.'; - } catch (SpacetradersApiException $e) { - $errorMessage = 'Unable to accept contract: ' . $e->getMessage(); - } - } -} - -try { - if (! isset( $tokenError ) ) { - $agentResponse = $client->getMyAgent(); - $shipsResponse = $client->listMyShips(); - $contractsResponse = $client->listMyContracts(); - - $agent = $agentResponse['data'] ?? $agentResponse; - $ships = $shipsResponse['data'] ?? $shipsResponse; - $contracts = $contractsResponse['data'] ?? $contractsResponse; - - $currentSystemSymbol = ''; - if (isset( $ships[0]['nav']['systemSymbol'] ) && is_string( $ships[0]['nav']['systemSymbol'] ) ) { - $currentSystemSymbol = $ships[0]['nav']['systemSymbol']; - } - - if ($currentSystemSymbol === '' && isset( $agent['headquarters'] ) && is_string( $agent['headquarters'] ) ) { - $hqParts = explode( '-', $agent['headquarters'] ); - if (count( $hqParts ) >= 2 ) { - $currentSystemSymbol = $hqParts[0] . '-' . $hqParts[1]; - } - } - - if ($currentSystemSymbol !== '' ) { - $systemResponse = $client->getSystem( $currentSystemSymbol ); - $system = $systemResponse['data'] ?? $systemResponse; - - $page = 1; - $total = 0; - do { - $waypointsResponse = $client->listWaypoints( - $currentSystemSymbol, - array( - 'page' => $page, - 'limit' => 20, - ) - ); - $pageData = $waypointsResponse['data'] ?? array(); - if (! is_array( $pageData ) || empty( $pageData ) ) { - break; - } - - $systemWaypoints = array_merge( $systemWaypoints, $pageData ); - $total = (int) ( $waypointsResponse['meta']['total'] ?? count( $systemWaypoints ) ); - $page++; - } while (count( $systemWaypoints ) < $total); - - foreach ( $systemWaypoints as $waypoint ) { - $waypointSymbol = (string) ( $waypoint['symbol'] ?? '' ); - $traits = $waypoint['traits'] ?? array(); - $hasMarket = false; - $hasShipyard = false; - - foreach ( $traits as $trait ) { - $traitSymbol = (string) ( $trait['symbol'] ?? '' ); - if ($traitSymbol === 'MARKETPLACE' ) { - $hasMarket = true; - } - - if ($traitSymbol === 'SHIPYARD' ) { - $hasShipyard = true; - } - } - - if ($hasMarket ) { - $marketRecord = array( - 'waypoint' => $waypoint, - 'data' => array(), - 'error' => '', - ); - try { - $marketResponse = $client->getWaypointMarket( $currentSystemSymbol, $waypointSymbol ); - $marketRecord['data'] = $marketResponse['data'] ?? array(); - } catch (SpacetradersApiException $e) { - $marketRecord['error'] = $e->getMessage(); - } - - $marketDetails[] = $marketRecord; - } - - if ($hasShipyard ) { - $shipyardRecord = array( - 'waypoint' => $waypoint, - 'data' => array(), - 'error' => '', - ); - try { - $shipyardResponse = $client->getWaypointShipyard( $currentSystemSymbol, $waypointSymbol ); - $shipyardRecord['data'] = $shipyardResponse['data'] ?? array(); - } catch (SpacetradersApiException $e) { - $shipyardRecord['error'] = $e->getMessage(); - } - - $shipyardDetails[] = $shipyardRecord; - } - } - - $waypointCount = count( $systemWaypoints ); - if ($waypointCount > 0 ) { - $waypointTotalPages = (int) ceil( $waypointCount / $waypointPageSize ); - $waypointPage = min( $waypointPage, $waypointTotalPages ); - $offset = ( $waypointPage - 1 ) * $waypointPageSize; - $paginatedWaypoints = array_slice( $systemWaypoints, $offset, $waypointPageSize ); - } - } - } -} catch (SpacetradersApiException $e) { - $error = array( - 'error' => $e->getMessage(), - 'code' => $e->getCode(), - 'payload' => $e->getErrorPayload(), - ); - - if (PHP_SAPI === 'cli' ) { - fwrite( STDERR, json_encode( $error, JSON_PRETTY_PRINT ) . PHP_EOL ); - exit( 1 ); - } - - http_response_code( 500 ); - header( 'Content-Type: application/json; charset=utf-8' ); - echo json_encode( $error, JSON_PRETTY_PRINT ); -} -?> - - - -
- - -- Current System: - - - () - -
- - - -- Showing - - of waypoints -
-| Symbol | -Type | -Coordinates | -Traits | -
|---|---|---|---|
| - | - | - , - - | -- - | -
| Name | -Role | -Type | -Status | -Flight Mode | -Route | -||
|---|---|---|---|---|---|---|---|
| - - - - | -- | - | - - | - | - - | N/A | -N/A | - -
- Delivery Details: units delivered to -
- -- Payment: on Accept, on Fulfill -
- -Deadline To Accept:
-Deadline:
- -- Status: - - - - Accept? - - - -
-