/**
  * Get players on the server
  *
  * @throws SourceQueryException
  *
  * @return bool|array Returns array with players on success, false on failure
  */
 public function GetPlayers()
 {
     if (!$this->Connected) {
         return false;
     }
     switch ($this->GetChallenge(self::A2S_PLAYER, self::S2A_PLAYER)) {
         case self::GETCHALLENGE_FAILED:
             return false;
         case self::GETCHALLENGE_ALL_CLEAR:
             $this->Socket->Write(self::A2S_PLAYER, $this->Challenge);
             $this->Socket->Read();
             $Type = $this->Buffer->GetByte();
             if ($Type == 0) {
                 return false;
             } else {
                 if ($Type != self::S2A_PLAYER) {
                     throw new SourceQueryException('GetPlayers: Packet header mismatch. (0x' . DecHex($Type) . ')');
                 }
             }
             break;
     }
     $Players = array();
     $Count = $this->Buffer->GetByte();
     while ($Count-- > 0 && $this->Buffer->Remaining() > 0) {
         $Player['Id'] = $this->Buffer->GetByte();
         // PlayerID, is it just always 0?
         $Player['Name'] = $this->Buffer->GetString();
         $Player['Frags'] = $this->Buffer->GetLong();
         $Player['Time'] = (int) $this->Buffer->GetFloat();
         $Player['TimeF'] = GMDate($Player['Time'] > 3600 ? "H:i:s" : "i:s", $Player['Time']);
         $Players[] = $Player;
     }
     return $Players;
 }
Example #2
0
 /**
  * Get players on the server
  *
  * @throws InvalidPacketException
  *
  * @return bool|array Returns array with players on success, false on failure
  */
 public function GetPlayers()
 {
     if (!$this->Connected) {
         return false;
     }
     switch ($this->GetChallenge(self::A2S_PLAYER, self::S2A_PLAYER)) {
         case self::GETCHALLENGE_FAILED:
             return false;
         case self::GETCHALLENGE_ALL_CLEAR:
             $this->Socket->Write(self::A2S_PLAYER, $this->Challenge);
             $this->Socket->Read(14000);
             // Moronic Arma 3 developers do not split their packets, so we have to read more data
             // This violates the protocol spec, and they probably should fix it: https://developer.valvesoftware.com/wiki/Server_queries#Protocol
             $Type = $this->Buffer->GetByte();
             if ($Type === 0) {
                 return false;
             } else {
                 if ($Type !== self::S2A_PLAYER) {
                     throw new InvalidPacketException('GetPlayers: Packet header mismatch. (0x' . DecHex($Type) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH);
                 }
             }
             break;
     }
     $Players = array();
     $Count = $this->Buffer->GetByte();
     while ($Count-- > 0 && $this->Buffer->Remaining() > 0) {
         $Player['Id'] = $this->Buffer->GetByte();
         // PlayerID, is it just always 0?
         $Player['Name'] = $this->Buffer->GetString();
         $Player['Frags'] = $this->Buffer->GetLong();
         $Player['Time'] = (int) $this->Buffer->GetFloat();
         $Player['TimeF'] = GMDate($Player['Time'] > 3600 ? "H:i:s" : "i:s", $Player['Time']);
         $Players[] = $Player;
     }
     return $Players;
 }