예제 #1
0
 /**
  * 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;
 }
예제 #2
0
 /**
  * Before we send off the queries we need to update the packets
  *
  * @param \GameQ\Server $server
  *
  * @throws \GameQ\Exception\Protocol
  */
 public function beforeSend(Server $server)
 {
     // Check to make sure we have a query_port because it is required
     if (!isset($this->options[Server::SERVER_OPTIONS_QUERY_PORT]) || empty($this->options[Server::SERVER_OPTIONS_QUERY_PORT])) {
         throw new Exception(__METHOD__ . " Missing required setting '" . Server::SERVER_OPTIONS_QUERY_PORT . "'.");
     }
     // Let's loop the packets and set the proper pieces
     foreach ($this->packets as $packet_type => $packet) {
         // Update with the client port for the server
         $this->packets[$packet_type] = sprintf($packet, $server->portClient());
     }
 }
예제 #3
0
 /**
  * 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);
     }
 }