diff --git a/Examples/Example.php b/Examples/Example.php index 59ed770..9ad9b85 100644 --- a/Examples/Example.php +++ b/Examples/Example.php @@ -6,29 +6,21 @@ require __DIR__ . '/../vendor/autoload.php'; use xPaw\SourceQuery\SourceQuery; use xPaw\SourceQuery\Socket\SourceSocket; -use xPaw\SourceQuery\Socket\SocketType; // For the sake of this example header('Content-Type: text/plain'); header('X-Content-Type-Options: nosniff'); -// Edit this -> -define('SQ_SERVER_ADDR', 'localhost'); -define('SQ_SERVER_PORT', 27015); -define('SQ_TIMEOUT', 1); -define('SQ_ENGINE', SocketType::SOURCE); -// Edit this <- - -$Query = new SourceQuery(new SourceSocket()); +$query = new SourceQuery(new SourceSocket()); try { - $Query->connect(SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE); + $query->connect('localhost', 27015, 1); - print_r($Query->getInfo()); - print_r($Query->getPlayers()); - print_r($Query->getRules()); -} catch (Exception $e) { - echo $e->getMessage(); + print_r($query->getInfo()); + print_r($query->getPlayers()); + print_r($query->getRules()); +} catch (Exception $exception) { + echo $exception->getMessage(); } finally { - $Query->disconnect(); + $query->disconnect(); } diff --git a/Examples/RconExample.php b/Examples/RconExample.php index 641043e..f367bbc 100644 --- a/Examples/RconExample.php +++ b/Examples/RconExample.php @@ -6,29 +6,21 @@ require __DIR__ . '/../vendor/autoload.php'; use xPaw\SourceQuery\SourceQuery; use xPaw\SourceQuery\Socket\SourceSocket; -use xPaw\SourceQuery\Socket\SocketType; // For the sake of this example header('Content-Type: text/plain'); header('X-Content-Type-Options: nosniff'); -// Edit this -> -define('SQ_SERVER_ADDR', 'localhost'); -define('SQ_SERVER_PORT', 27015); -define('SQ_TIMEOUT', 1); -define('SQ_ENGINE', SocketType::SOURCE); -// Edit this <- - -$Query = new SourceQuery(new SourceSocket()); +$query = new SourceQuery(new SourceSocket()); try { - $Query->connect(SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE); + $query->connect('localhost', 27015, 1); - $Query->setRconPassword('my_awesome_password'); + $query->setRconPassword('my_awesome_password'); - var_dump($Query->rcon('say hello')); -} catch (Exception $e) { - echo $e->getMessage(); + var_dump($query->rcon('say hello')); +} catch (Exception $exception) { + echo $exception->getMessage(); } finally { - $Query->disconnect(); + $query->disconnect(); } diff --git a/Examples/View.php b/Examples/View.php index 083a45b..bcccc40 100644 --- a/Examples/View.php +++ b/Examples/View.php @@ -6,38 +6,30 @@ require __DIR__ . '/../vendor/autoload.php'; use xPaw\SourceQuery\SourceQuery; use xPaw\SourceQuery\Socket\SourceSocket; -use xPaw\SourceQuery\Socket\SocketType; -// Edit this -> -define('SQ_SERVER_ADDR', 'localhost'); -define('SQ_SERVER_PORT', 27015); -define('SQ_TIMEOUT', 3); -define('SQ_ENGINE', SocketType::SOURCE); -// Edit this <- +$timer = microtime(true); -$Timer = microtime(true); +$query = new SourceQuery(new SourceSocket()); -$Query = new SourceQuery(new SourceSocket()); - -$Info = []; -$Rules = []; -$Players = []; -$Exception = null; +$info = []; +$rules = []; +$players = []; +$exception = null; try { - $Query->connect(SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE); + $query->connect('localhost', 27015, 3); //$Query->SetUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound - $Info = $Query->getInfo(); - $Players = $Query->getPlayers(); - $Rules = $Query->getRules(); + $info = $query->getInfo(); + $players = $query->getPlayers(); + $rules = $query->getRules(); } catch (Exception $e) { - $Exception = $e; + $exception = $e; } finally { - $Query->disconnect(); + $query->disconnect(); } -$Timer = number_format(microtime(true) - $Timer, 4, '.', ''); +$timer = number_format(microtime(true) - $timer, 4, '.', ''); ?> @@ -47,7 +39,7 @@ $Timer = number_format(microtime(true) - $Timer, 4, '.', '');