/** * Parse the response for a specific server * * @param \GameQ\Server $server * * @return array * @throws \Exception */ protected function doParseResponse(Server $server) { try { // @codeCoverageIgnoreStart // We want to save this server's response to a file (useful for unit testing) if (!is_null($this->capture_packets_file)) { file_put_contents($this->capture_packets_file, implode(PHP_EOL . '||' . PHP_EOL, $server->protocol()->packetResponse())); } // @codeCoverageIgnoreEnd // Get the server response $results = $server->protocol()->processResponse(); // Check for online before we do anything else $results['gq_online'] = count($results) > 0; } catch (ProtocolException $e) { // Check to see if we are in debug, if so bubble up the exception if ($this->debug) { throw new \Exception($e->getMessage(), $e->getCode(), $e); } // We ignore this server $results = ['gq_online' => false]; } // Now add some default stuff $results['gq_address'] = $server->ip(); $results['gq_port_client'] = $server->portClient(); $results['gq_port_query'] = $server->portQuery(); $results['gq_protocol'] = $server->protocol()->getProtocol(); $results['gq_type'] = (string) $server->protocol(); $results['gq_name'] = $server->protocol()->nameLong(); $results['gq_transport'] = $server->protocol()->transport(); // Process the join link if (!isset($results['gq_joinlink']) || empty($results['gq_joinlink'])) { $results['gq_joinlink'] = $server->getJoinLink(); } return $results; }
/** * Handle some work before sending the packets out to the server * * @param \GameQ\Server $server */ public function beforeSend(Server $server) { // Build the server code $this->server_code = implode('', array_map('chr', explode('.', $server->ip()))) . pack("S", $server->portClient()); // Loop over the packets and update them foreach ($this->packets as $packetType => $packet) { // Fill out the packet with the server info $this->packets[$packetType] = sprintf($packet, $this->server_code); } }