diff --git a/agent-info.php b/agent-info.php index 95192f3..b4e1046 100644 --- a/agent-info.php +++ b/agent-info.php @@ -35,6 +35,16 @@ if (! is_string( $token ) || trim( $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( @@ -45,6 +55,35 @@ if (! isset( $tokenError ) ) { (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'] ) ); @@ -65,6 +104,101 @@ try { $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( @@ -107,6 +241,10 @@ try {
@@ -135,6 +273,172 @@ try { System: ++ Current System: + + + () + +
+ + + ++ Showing - + of waypoints +
+| Symbol | +Type | +Coordinates | +Traits | +
|---|---|---|---|
| + | + | + , + + | ++ + | +
| + | + + + + | @@ -218,5 +529,37 @@ try { endforeach; ?> + + |