-
Notifications
You must be signed in to change notification settings - Fork 27
Remove GameQ and use "own" implementation for queries #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8d949d5
remove gameq and use "own" implementation for queries
Boy132 4884323
update readme
Boy132 be92047
remove gameq from workflow
Boy132 ca5b66b
better error handling
Boy132 2fae786
fix minecraft hostname
Boy132 f280dfd
pint
Boy132 c2cba24
more minecraft fixes
Boy132 082e40e
fix player mapping for minecraft query
Boy132 0aeab1d
fix player list on bedrock
Boy132 c617073
better check for allocation ip
Boy132 7f6a0d2
add new packages to workflow
Boy132 a0fd2f3
fix phpstan
Boy132 8575cc7
better array checks
Boy132 a60890d
use timeout instead of connectTimeout
Boy132 fd17f30
better null checks
Boy132 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
player-counter/src/Extensions/Query/QueryTypeSchemaInterface.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| namespace Boy132\PlayerCounter\Extensions\Query; | ||
|
|
||
| interface QueryTypeSchemaInterface | ||
| { | ||
| public function getId(): string; | ||
|
|
||
| public function getName(): string; | ||
|
|
||
| /** @return ?array{hostname: string, map: string, current_players: int, max_players: int, players: ?array<array{id: string, name: string}>} */ | ||
| public function process(string $ip, int $port): ?array; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
|
|
||
| namespace Boy132\PlayerCounter\Extensions\Query; | ||
|
|
||
| class QueryTypeService | ||
| { | ||
| /** @var QueryTypeSchemaInterface[] */ | ||
| private array $schemas = []; | ||
|
|
||
| public function get(string $id): ?QueryTypeSchemaInterface | ||
| { | ||
| return array_get($this->schemas, $id); | ||
| } | ||
|
|
||
| public function register(QueryTypeSchemaInterface $schema): void | ||
| { | ||
| if (array_key_exists($schema->getId(), $this->schemas)) { | ||
| return; | ||
| } | ||
|
|
||
| $this->schemas[$schema->getId()] = $schema; | ||
| } | ||
|
|
||
| /** @return array<string, string> */ | ||
| public function getMappings(): array | ||
| { | ||
| return collect($this->schemas)->mapWithKeys(fn ($schema) => [$schema->getId() => $schema->getName()])->all(); | ||
| } | ||
| } |
73 changes: 73 additions & 0 deletions
73
player-counter/src/Extensions/Query/Schemas/CitizenFXQueryTypeSchema.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| <?php | ||
|
|
||
| namespace Boy132\PlayerCounter\Extensions\Query\Schemas; | ||
|
|
||
| use Boy132\PlayerCounter\Extensions\Query\QueryTypeSchemaInterface; | ||
| use Exception; | ||
| use Illuminate\Support\Facades\Http; | ||
|
|
||
| class CitizenFXQueryTypeSchema implements QueryTypeSchemaInterface | ||
| { | ||
| public function getId(): string | ||
| { | ||
| return 'cfx'; | ||
| } | ||
|
|
||
| public function getName(): string | ||
| { | ||
| return 'CitizenFX'; | ||
| } | ||
|
|
||
| /** @return ?array{hostname: string, map: string, current_players: int, max_players: int, players: array<array{id: string, name: string}>} */ | ||
| public function process(string $ip, int $port): ?array | ||
| { | ||
| try { | ||
| $this->resolveSRV($ip, $port); | ||
|
|
||
| $http = Http::acceptJson() | ||
| ->timeout(5) | ||
| ->throw() | ||
| ->baseUrl("http://$ip:$port/"); | ||
|
|
||
| $info = $http->get('dynamic.json')->json(); | ||
| $players = $http->get('players.json')->json(); | ||
|
|
||
| if (!is_array($info) || !is_array($players)) { | ||
| return null; | ||
| } | ||
|
|
||
| return [ | ||
| 'hostname' => $info['hostname'], | ||
| 'map' => $info['mapname'], | ||
| 'current_players' => $info['clients'], | ||
| 'max_players' => $info['sv_maxclients'], | ||
| 'players' => array_map(fn ($player) => ['id' => (string) $player['id'], 'name' => (string) $player['name']], $players), | ||
| ]; | ||
| } catch (Exception $exception) { | ||
| report($exception); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| private function resolveSRV(string &$ip, int &$port): void | ||
| { | ||
| if (is_ip($ip)) { | ||
| return; | ||
| } | ||
Boy132 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $record = dns_get_record('_cfx._udp.' . $ip, DNS_SRV); | ||
|
|
||
| if (!$record) { | ||
| return; | ||
| } | ||
|
|
||
| if ($record[0]['target']) { | ||
| $ip = $record[0]['target']; | ||
| } | ||
|
|
||
| if ($record[0]['port']) { | ||
| $port = (int) $record[0]['port']; | ||
| } | ||
| } | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
player-counter/src/Extensions/Query/Schemas/GoldSourceQueryTypeSchema.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
|
|
||
| namespace Boy132\PlayerCounter\Extensions\Query\Schemas; | ||
|
|
||
| use xPaw\SourceQuery\SourceQuery; | ||
|
|
||
| class GoldSourceQueryTypeSchema extends SourceQueryTypeSchema | ||
| { | ||
| public function getId(): string | ||
| { | ||
| return 'goldsrc'; | ||
| } | ||
|
|
||
| public function getName(): string | ||
| { | ||
| return 'GoldSrc'; | ||
| } | ||
|
|
||
| /** @return ?array{hostname: string, map: string, current_players: int, max_players: int, players: array<array{id: string, name: string}>} */ | ||
| public function process(string $ip, int $port): ?array | ||
| { | ||
| return $this->run($ip, $port, SourceQuery::GOLDSOURCE); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.