Exemplo n.º 1
0
 public function getServers($regionCode = MasterServer::REGION_ALL, $filter = "")
 {
     $failCount = 0;
     $finished = false;
     $portNumber = 0;
     $hostName = "0.0.0.0";
     do {
         $this->socket->send(new A2M_GET_SERVERS_BATCH2_Packet($regionCode, "{$hostName}:{$portNumber}", $filter));
         try {
             $serverStringArray = $this->socket->getReply()->getServers();
             foreach ($serverStringArray as $serverString) {
                 $serverString = explode(":", $serverString);
                 $hostName = $serverString[0];
                 $portNumber = $serverString[1];
                 if ($hostName != "0.0.0.0" && $portNumber != 0) {
                     $serverArray[] = array($hostName, $portNumber);
                 } else {
                     $finished = true;
                 }
             }
             $failCount = 0;
         } catch (TimeoutException $e) {
             $failCount++;
             if (failCount == 4) {
                 throw $e;
             }
         }
     } while (!$finished);
     return $serverArray;
 }
 /**
  * Sends a constructed heartbeat to the master server
  *
  * This can be used to check server versions externally.
  *
  * @deprecated
  * @param array $data The heartbeat data to send to the master server
  * @return array The reply from the master server – usually zero or more
  *         packets. Zero means either the heartbeat was accepted by the
  *         master or there was a timeout. So usually it's best to repeat a
  *         heartbeat a few times when not receiving any packets.
  * @throws SteamCondenserException if heartbeat data is missing the
  *         challenge number or the reply cannot be parsed
  */
 public function sendHeartbeat($data)
 {
     while (true) {
         try {
             $this->socket->send(new S2M_HEARTBEAT2_Packet($data));
             $replyPackets = array();
             try {
                 do {
                     $replyPackets[] = $this->socket->getReply();
                 } while (true);
             } catch (TimeoutException $e) {
             }
             return $replyPackets;
         } catch (Exception $e) {
             if ($this->rotateIp()) {
                 throw $e;
             }
         }
     }
 }