You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Test-Miroir/SourceQuery/QueryResponse/PlayersQueryResponse.php

45 lines
1.0 KiB

<?php
declare(strict_types=1);
/**
* @author Pavel Djundik
*
* @see https://xpaw.me
* @see https://github.com/xPaw/PHP-Source-Query
*
* @license GNU Lesser General Public License, version 2.1
*
* @internal
*/
namespace xPaw\SourceQuery\QueryResponse;
use xPaw\SourceQuery\Buffer;
use xPaw\SourceQuery\Exception\InvalidPacketException;
class PlayersQueryResponse
{
/**
* @throws InvalidPacketException
*/
public static function fromBuffer(Buffer $buffer): array
{
$players = [];
$count = $buffer->getByte();
while ($count-- > 0 && !$buffer->isEmpty()) {
$player = [];
$player['Id'] = $buffer->getByte(); // PlayerID, is it just always 0?
$player['Name'] = $buffer->getString();
$player['Frags'] = $buffer->getLong();
$player['Time'] = (int) $buffer->getFloat();
$player['TimeF'] = gmdate(($player['Time'] > 3600 ? 'H:i:s' : 'i:s'), $player['Time']);
$players[] = $player;
}
return $players;
}
}