Example #1
0
 /**
  * Closes all open connections
  */
 public function Disconnect()
 {
     $this->Connected = false;
     $this->Challenge = 0;
     $this->Buffer->Reset();
     $this->Socket->Close();
     if ($this->Rcon) {
         $this->Rcon->Close();
         $this->Rcon = null;
     }
 }
 /**
  * Opens connection to server
  *
  * @param string $Ip Server ip
  * @param int $Port Server port
  * @param int $Timeout Timeout period
  * @param int $Engine Engine the server runs on (goldsource, source)
  *
  * @throws SourceQueryException
  * @throws InvalidArgumentException If timeout is not an integer
  */
 public function Connect($Ip, $Port, $Timeout = 3, $Engine = self::SOURCE)
 {
     $this->Disconnect();
     $this->Buffer->Reset();
     $this->Challenge = 0;
     if (!is_int($Timeout) || $Timeout < 0) {
         throw new InvalidArgumentException('Timeout must be an integer.');
     }
     if (!$this->Socket->Open($Ip, (int) $Port, $Timeout, (int) $Engine)) {
         throw new SourceQueryException('Can\'t connect to the server.');
     }
     $this->Connected = true;
 }