* @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(); if (! isset( $tokenError ) ) { $client = new SpacetradersApi( trim( $token ), $config['api_base_url'], (int) $config['api_timeout'], $storage, (int) $config['cache_ttl'] ); 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; } } 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 ); } ?>
| 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?