Counter-Strike/cli/client.php
Daniel Maixner c46b72ef36 initial
2022-09-11 14:11:27 +02:00

42 lines
967 B
PHP

<?php
use Socket\Raw\Factory;
require __DIR__ . '/../vendor/autoload.php';
/////
$loginCode = $argv[1] ?? 'dcode';
$port = (int)($argv[2] ?? 8080);
$command = ($argv[3] ?? '');
$address = "udp://localhost:$port";
/////
$factory = new Factory();
$socket = $factory->createClient($address, 4);
$socket->write('login ' . $loginCode);
while (true) {
$response = $socket->read(1024);
if ($command) {
$socket->write($command);
continue;
}
echo PHP_EOL . PHP_EOL . PHP_EOL . "--------------------------";
echo "Server data:" . PHP_EOL;
var_dump($response);
echo "--------------------------" . PHP_EOL . PHP_EOL . PHP_EOL;
$request = readline("Send command: ");
if ($request === false) {
break;
}
$request = trim($request);
while ($socket->selectRead()) {// drain socket
$socket->read(10241024);
}
if ($request !== '') {
$socket->write($request);
}
}
$socket->close();