Beispiel #1
0
 /**
  * Handle the event.
  *
  * @param  ServersUpdate  $event
  * @return void
  */
 public function handle(ServersUpdate $event)
 {
     $servers = Server::all()->where('active', 1);
     if ($servers) {
         foreach ($servers as $server) {
             $data = new SourceQuery();
             try {
                 $engine = $server->engine >= 1 ? 1 : 0;
                 $data->Connect($server->ip, $server->port, 3, $engine);
                 $information = $data->GetInfo();
                 $players = $data->GetPlayers();
                 $rules = $data->GetRules();
             } catch (\Exception $e) {
                 $information = '';
                 $players = '';
                 $rules = '';
             }
             $server->information = json_encode($information);
             $server->players = json_encode($data->GetPlayers($players));
             $server->rules = json_encode($data->GetRules($rules));
             $server->save();
         }
     }
 }
Beispiel #2
0
<?php

require __DIR__ . '/../SourceQuery/bootstrap.php';
use xPaw\SourceQuery\SourceQuery;
// For the sake of this example
Header('Content-Type: text/plain');
Header('X-Content-Type-Options: nosniff');
// Edit this ->
define('SQ_SERVER_ADDR', '162.251.166.186');
define('SQ_SERVER_PORT', 27016);
define('SQ_TIMEOUT', 1);
define('SQ_ENGINE', SourceQuery::SOURCE);
// Edit this <-
$Query = new SourceQuery();
try {
    $Query->Connect(SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE);
    print_r($Query->GetInfo());
    print_r($Query->GetPlayers());
    print_r($Query->GetRules());
} catch (Exception $e) {
    echo $e->getMessage();
} finally {
    $Query->Disconnect();
}
Beispiel #3
0
 private function LinkOnlinePlayers()
 {
     // $Timer = MicroTime(true);
     //    $online = new SSQL().Players(new IPEndPoint(IPAddress.Parse(ipString), port))).ToList();
     $Query = new SourceQuery();
     try {
         $Query->Connect(SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE);
         //$Query->SetUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound
         // $Info = $Query->GetInfo();
         $queryPlayers = $Query->GetPlayers();
         // $Rules = $Query->GetRules();
         // $Timer = Number_Format( MicroTime( true ) - $Timer, 4, '.', '' );
         foreach ($queryPlayers as $key => $var) {
             $var = (object) $var;
             if (empty($var->Name)) {
                 continue;
             }
             foreach ($this->Players as $key => $value) {
                 if ($value->SteamName == $var->Name) {
                     $this->Players[$value->Id]->Online = true;
                 }
             }
         }
     } catch (Exception $e) {
         $Exception = $e;
         die($Exception->getMessage());
     } finally {
         $Query->Disconnect();
     }
 }
Beispiel #4
0
// Edit this ->
define('SQ_SERVER_ADDR', 'localhost');
define('SQ_SERVER_PORT', 27015);
define('SQ_TIMEOUT', 3);
define('SQ_ENGINE', SourceQuery::SOURCE);
// Edit this <-
$Timer = MicroTime(true);
$Query = new SourceQuery();
$Info = array();
$Rules = array();
$Players = array();
try {
    $Query->Connect(SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE);
    //$Query->SetUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound
    $Info = $Query->GetInfo();
    $Players = $Query->GetPlayers();
    $Rules = $Query->GetRules();
} catch (Exception $e) {
    $Exception = $e;
} finally {
    $Query->Disconnect();
}
$Timer = Number_Format(MicroTime(true) - $Timer, 4, '.', '');
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Source Query PHP Library</title>
	
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">