Counter-Strike/cli/client.php

47 lines
1.0 KiB
PHP
Raw Normal View History

2022-08-13 12:40:42 +02:00
<?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);
2022-10-16 13:53:26 +02:00
if ($command === 'afk') {
sleep(1);
exit;
}
2022-08-13 12:40:42 +02:00
while (true) {
2022-10-06 20:35:28 +02:00
$response = $socket->read(10241024);
2022-08-13 12:40:42 +02:00
if ($command) {
2022-10-16 13:53:26 +02:00
$socket->write($command);
2022-08-13 12:40:42 +02:00
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);
2022-10-05 16:09:55 +02:00
while ($socket->selectRead()) { // drain socket
2022-08-13 12:40:42 +02:00
$socket->read(10241024);
}
if ($request !== '') {
$socket->write($request);
}
}
$socket->close();