Skip to content

Commit

Permalink
Added support for Counter-Strike 2. Fixed support for FiveM and Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
George-Cristian TUDORAN committed Sep 28, 2023
1 parent 351518f commit 34df35f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 📊 Game Server Query

Current version: **1.0.23**
Current version: **1.0.24**

### [Inspiration: GameQ by AustinB](https://github.com/Austinb/GameQ)

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gasjki/game-server-query",
"description": "GameServerQuery - Extended PHP game server query library based on GameQ.",
"version": "1.0.23",
"version": "1.0.24",
"type": "library",
"license": "LGPL-3.0+",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php declare(strict_types = 1);

namespace GameServerQuery\Protocol\Games\Source;

use GameServerQuery\Protocol\Types\SourceProtocol;

/**
* Class CounterStrike2Protocol
* @package GameServerQuery\Protocol\Games\Source
*/
class CounterStrike2Protocol extends SourceProtocol
{

}
16 changes: 10 additions & 6 deletions src/GameServerQuery/Protocol/Games/Source/RustProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ protected function processRules(Buffer $buffer, Result $result): void
{
parent::processRules($buffer, $result);

if ($keywords = $result->getRule('keywords')) {
//get max players from mp of keywords and num players from cp keyword
preg_match_all('/(mp|cp)(\d+)/', $keywords, $matches);

$result->addInformation(Result::GENERAL_SLOTS_SUBCATEGORY, (int) $matches[2][0]);
$result->addInformation(Result::GENERAL_ONLINE_PLAYERS_SUBCATEGORY, (int) $matches[2][1]);
if (!$result->hasRule('keywords')) {
return;
}

$keywords = $result->getRule('keywords');

// Get max players from mp of keywords and num players from cp keyword.
preg_match_all('/(mp|cp)(\d+)/', $keywords, $matches);

$result->addInformation(Result::GENERAL_SLOTS_SUBCATEGORY, (int) $matches[2][0]);
$result->addInformation(Result::GENERAL_ONLINE_PLAYERS_SUBCATEGORY, (int) $matches[2][1]);
}
}
17 changes: 10 additions & 7 deletions src/GameServerQuery/Query/Types/FiveMQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class FiveMQuery extends AbstractQuery
{
/**
* @inheritDoc
* @throws \JsonException
*/
public function execute(): array
{
Expand Down Expand Up @@ -46,7 +45,6 @@ public function execute(): array
* Read server's players.
*
* @return array
* @throws \JsonException
*/
private function readServerPlayersUrl(): array
{
Expand All @@ -59,12 +57,17 @@ private function readServerPlayersUrl(): array
],
];

$data = @\file_get_contents($url, false, stream_context_create($opts));
try {
$data = @\file_get_contents($url, false, stream_context_create($opts));
$response = \json_decode($data, true, 512, JSON_THROW_ON_ERROR);

if (\is_bool($data)) {
if (!\is_array($response)) {
return [];
}

return $response;
} catch (\JsonException) {
return [];
}

return \json_decode($data, true, 512, JSON_THROW_ON_ERROR);
}
}
}

0 comments on commit 34df35f

Please sign in to comment.