* @license MIT License * @version GIT: * @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 = ''; $ship = array(); $shipList = array(); $shipSymbol = isset( $_GET['ship'] ) ? trim( (string) $_GET['ship'] ) : ''; 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.'; } if (! isset( $tokenError ) ) { $client = new SpacetradersApi( trim( $token ), $config['api_base_url'], (int) $config['api_timeout'], $storage, (int) $config['cache_ttl'] ); } try { if (! isset( $tokenError ) ) { $shipListResponse = $client->listMyShips(); $shipList = $shipListResponse['data'] ?? array(); if ($shipSymbol === '' && ! empty( $shipList ) ) { $shipSymbol = (string) ( $shipList[0]['symbol'] ?? '' ); } if ($shipSymbol !== '' ) { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset( $_POST['ship_action'] ) ) { $action = (string) $_POST['ship_action']; switch ($action) { case 'orbit': $client->orbitShip( $shipSymbol ); $statusMessage = 'Ship set to orbit.'; break; case 'dock': $client->dockShip( $shipSymbol ); $statusMessage = 'Ship docked.'; break; case 'extract': $client->extractResources( $shipSymbol ); $statusMessage = 'Resource extraction started.'; break; case 'survey': $client->surveyWaypoint( $shipSymbol ); $statusMessage = 'Survey completed.'; break; case 'siphon': $client->siphonResources( $shipSymbol ); $statusMessage = 'Siphon action completed.'; break; case 'refuel': $client->refuelShip( $shipSymbol ); $statusMessage = 'Ship refueled.'; break; case 'sell_all_cargo': $shipResponse = $client->getShip( $shipSymbol ); $shipData = $shipResponse['data'] ?? array(); $shipStatus = (string) ( $shipData['nav']['status'] ?? '' ); if ($shipStatus === 'IN_TRANSIT' ) { throw new SpacetradersApiException( 'Ship is in transit and cannot sell cargo right now.' ); } if ($shipStatus !== 'DOCKED' ) { $client->dockShip( $shipSymbol ); } $inventory = (array) ( $shipData['cargo']['inventory'] ?? array() ); $soldItems = 0; foreach ( $inventory as $item ) { $tradeSymbol = (string) ( $item['symbol'] ?? '' ); $units = (int) ( $item['units'] ?? 0 ); if ($tradeSymbol === '' || $units <= 0 ) { continue; } try { $client->sellCargo( $shipSymbol, $tradeSymbol, $units ); $soldItems++; } catch (SpacetradersApiException $e) { // Continue selling other items. } } $statusMessage = 'Attempted to sell all cargo item types. Sold: ' . $soldItems . '.'; break; case 'sell_cargo_item': $tradeSymbol = trim( (string) ( $_POST['trade_symbol'] ?? '' ) ); $units = (int) ( $_POST['units'] ?? 0 ); if ($tradeSymbol === '' || $units <= 0 ) { throw new SpacetradersApiException( 'Trade symbol and units are required to sell cargo.' ); } $shipResponse = $client->getShip( $shipSymbol ); $shipData = $shipResponse['data'] ?? array(); $shipStatus = (string) ( $shipData['nav']['status'] ?? '' ); if ($shipStatus === 'IN_TRANSIT' ) { throw new SpacetradersApiException( 'Ship is in transit and cannot sell cargo right now.' ); } if ($shipStatus !== 'DOCKED' ) { $client->dockShip( $shipSymbol ); } $client->sellCargo( $shipSymbol, $tradeSymbol, $units ); $statusMessage = 'Sold ' . number_format( $units ) . ' units of ' . $tradeSymbol . '.'; break; case 'jettison_all_cargo': $shipResponse = $client->getShip( $shipSymbol ); $shipData = $shipResponse['data'] ?? array(); $shipStatus = (string) ( $shipData['nav']['status'] ?? '' ); if ($shipStatus === 'IN_TRANSIT' ) { throw new SpacetradersApiException( 'Ship is in transit and cannot jettison cargo right now.' ); } $inventory = (array) ( $shipData['cargo']['inventory'] ?? array() ); $jettisonedItems = 0; foreach ( $inventory as $item ) { $tradeSymbol = (string) ( $item['symbol'] ?? '' ); $units = (int) ( $item['units'] ?? 0 ); if ($tradeSymbol === '' || $units <= 0 ) { continue; } try { $client->jettisonCargo( $shipSymbol, $tradeSymbol, $units ); $jettisonedItems++; } catch (SpacetradersApiException $e) { // Continue attempting the rest. } } $statusMessage = 'Attempted to jettison all cargo item types. Jettisoned: ' . $jettisonedItems . '.'; break; case 'jettison_cargo_item': $tradeSymbol = trim( (string) ( $_POST['trade_symbol'] ?? '' ) ); $units = (int) ( $_POST['units'] ?? 0 ); if ($tradeSymbol === '' || $units <= 0 ) { throw new SpacetradersApiException( 'Trade symbol and units are required to jettison cargo.' ); } $shipResponse = $client->getShip( $shipSymbol ); $shipData = $shipResponse['data'] ?? array(); $shipStatus = (string) ( $shipData['nav']['status'] ?? '' ); if ($shipStatus === 'IN_TRANSIT' ) { throw new SpacetradersApiException( 'Ship is in transit and cannot jettison cargo right now.' ); } $client->jettisonCargo( $shipSymbol, $tradeSymbol, $units ); $statusMessage = 'Jettisoned ' . number_format( $units ) . ' units of ' . $tradeSymbol . '.'; break; } if ($statusMessage !== '' ) { $storage->clearAllCache(); } } $shipResponse = $client->getShip( $shipSymbol ); $ship = $shipResponse['data'] ?? $shipResponse; } } } catch (SpacetradersApiException $e) { $errorMessage = $e->getMessage(); } ?> Spacetraders - Ship Details
Agent Info Mining Fleet Buy Ships Configuration

Ship Details

0 && $fuelCurrent < $fuelCapacity; ?>

Ship Controls

0) : ?>

Role: | Status: | Fuel: /

Overview

Symbol:

Name:

Role:

Faction:

Navigation

Status:

Flight Mode:

System:

Waypoint:

Frame / Engine / Reactor

Frame:

Engine:

Reactor:

Cargo / Fuel

Cargo: /

Fuel: /

Cooldown Remaining: s

Mounts

No mounts equipped.

Modules

No modules installed.

Cargo Inventory

Cargo hold is empty.

Symbol Name Units Description Sell Jettison
0 ) : ?>
0 ) : ?>