Пример #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();
         }
     }
 }
Пример #2
0
 private function getlock($match, $model, $serv)
 {
     $Query = new SourceQuery();
     if (!is_null($serv)) {
         $server = $serv;
     } else {
         $server = $model->getServersByID($match->sid);
     }
     /*		if (is_null($server)) {
     			return '';
     		}*/
     $addr = explode(':', $server->addr);
     try {
         $Query->Connect($addr[0], $addr[1], 1, SourceQuery::SOURCE);
         $info = $Query->GetInfo();
         $players = $info['Players'];
         $serverLock = $model->getServerLock($match->id, $server->id, INTERVAL_LOCK);
         if ($players == 0 && is_null($serverLock)) {
             return 'Go to our server : ' . $server->addr . ' <a href="steam://connect/' . $server->addr . '" id="join" title="Join">Join</a>';
         }
     } catch (Exception $e) {
         return ' Error: ' . $e->getMessage();
         //echo $e->getMessage();
     } finally {
         $Query->Disconnect();
     }
     return ' Error: Server not found';
 }
Пример #3
0
use xPaw\SourceQuery\SourceQuery;
// 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>
	
Пример #4
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();
}
Пример #5
0
 public function startServer($model, $match)
 {
     $servers = $model->getServersList();
     //Header('Content-Type: text/plain');
     //Header('X-Content-Type-Options: nosniff');
     //define('SQ_TIMEOUT', 1);
     //define('SQ_ENGINE', SourceQuery::SOURCE);
     $Query = new SourceQuery();
     foreach ($servers as $server) {
         $addr = explode(':', $server->addr);
         //define('SQ_SERVER_ADDR', $addr[0]);
         //define('SQ_SERVER_PORT', $addr[1]);
         try {
             $Query->Connect($addr[0], $addr[1], 1, SourceQuery::SOURCE);
             $info = $Query->GetInfo();
             $players = $info['Players'];
             //print_r($Query->GetInfo());
             //print_r($Query->GetPlayers());
             //print_r($Query->GetRules());
             $serverLock = $model->getServerLock($server->id, INTERVAL_LOCK);
             if ($players == 0 && is_null($serverLock)) {
                 //$response['target_h']['#map_note'] = 'Go to our '. var_export($server->addr, true). ' '. var_export($match->id, true);
                 $response['target_h']['#map_note'] = 'Go to our server : ' . $server->addr . ' <a href="steam://connect/' . $server->addr . '" id="join" title="Join">Join</a>';
                 $model->setMatchServer($match->id, $server->id);
                 //update matches with server id
                 break;
             }
         } catch (Exception $e) {
             $response['target_h']['#map_note'] = 'error: ' . $e->getMessage();
             //echo $e->getMessage();
         } finally {
             $Query->Disconnect();
         }
     }
 }