예제 #1
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);
     }
 }
예제 #2
0
 /**
  * Apply this filter
  *
  * @param array         $result
  * @param \GameQ\Server $server
  *
  * @return array
  */
 public function apply(array $result, Server $server)
 {
     // No result passed so just return
     if (empty($result)) {
         return $result;
     }
     //$data = [ ];
     //$data['raw'][$server->id()] = $result;
     // Grab the normalize for this protocol for the specific server
     $this->normalize = $server->protocol()->getNormalize();
     // Do general information
     $result = array_merge($result, $this->check('general', $result));
     // Do player information
     if (isset($result['players']) && count($result['players']) > 0) {
         // Iterate
         foreach ($result['players'] as $key => $player) {
             $result['players'][$key] = array_merge($player, $this->check('player', $player));
         }
     } else {
         $result['players'] = [];
     }
     // Do team information
     if (isset($result['teams']) && count($result['teams']) > 0) {
         // Iterate
         foreach ($result['teams'] as $key => $team) {
             $result['teams'][$key] = array_merge($team, $this->check('team', $team));
         }
     } else {
         $result['teams'] = [];
     }
     //$data['filtered'][$server->id()] = $result;
     /*file_put_contents(
           sprintf('%s/../../../tests/Filters/Providers/Normalize/%s_1.json', __DIR__, $server->protocol()->getProtocol()),
           json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PARTIAL_OUTPUT_ON_ERROR)
       );*/
     // Return the normalized result
     return $result;
 }
예제 #3
0
 /**
  * Apply this filter
  *
  * @param array         $result
  * @param \GameQ\Server $server
  *
  * @return array
  */
 public function apply(array $result, Server $server)
 {
     // No result passed so just return
     if (empty($result)) {
         return $result;
     }
     //$data = [];
     //$data['raw'][ $server->id() ] = $result;
     // Switch based on the base (not game) protocol
     switch ($server->protocol()->getProtocol()) {
         case 'quake2':
         case 'quake3':
         case 'doom3':
             array_walk_recursive($result, [$this, 'stripQuake']);
             break;
         case 'unreal2':
         case 'ut3':
         case 'gamespy3':
             //not sure if gamespy3 supports ut colors but won't hurt
         //not sure if gamespy3 supports ut colors but won't hurt
         case 'gamespy2':
             array_walk_recursive($result, [$this, 'stripUnreal']);
             break;
     }
     /*$data['filtered'][ $server->id() ] = $result;
       file_put_contents(
           sprintf(
               '%s/../../../tests/Filters/Providers/Stripcolors\%s_1.json',
               __DIR__,
               $server->protocol()->getProtocol()
           ),
           json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PARTIAL_OUTPUT_ON_ERROR)
       );*/
     // Return the stripped result
     return $result;
 }
예제 #4
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());
     }
 }
예제 #5
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;
 }