示例#1
0
 /**
  * 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();
     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;
 }
示例#2
0
 /**
  * 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 InvalidArgumentException
  * @throws TimeoutException
  */
 public function Connect($Ip, $Port, $Timeout = 3, $Engine = self::SOURCE)
 {
     $this->Disconnect();
     if (!is_int($Timeout) || $Timeout < 0) {
         throw new InvalidArgumentException('Timeout must be an integer.', InvalidArgumentException::TIMEOUT_NOT_INTEGER);
     }
     if (!$this->Socket->Open($Ip, (int) $Port, $Timeout, (int) $Engine)) {
         throw new TimeoutException('Could not connect to server.', TimeoutException::TIMEOUT_CONNECT);
     }
     $this->Connected = true;
 }
 /**
  * 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;
     switch ($this->Socket->Engine) {
         case SourceQuery::GOLDSOURCE:
             $this->Rcon = new SourceQueryGoldSourceRcon($this->Buffer, $this->Socket);
             break;
         case SourceQuery::SOURCE:
             $this->Rcon = new SourceQuerySourceRcon($this->Buffer, $this->Socket);
             break;
     }
 }