Repository navigation
Fix player-counter plugin to support RakNet and newer NetherNet transport mode on Bedrock MC Servers #176
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
base: main
Are you sure you want to change the base?
Fix player-counter plugin to support RakNet and newer NetherNet transport mode on Bedrock MC Servers #176
Changes from all commits
6699819
0dd1a44
d22b7cd
7f1126f
5d18949
0506deb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,4 +19,4 @@ | |
| "xpaw/php-minecraft-query": "^5.0.0", | ||
| "xpaw/php-source-query-class": "^6.0.0" | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |||||||||||||||||||||
| use App\Models\Server; | ||||||||||||||||||||||
| use Boy132\PlayerCounter\Extensions\Query\QueryTypeSchemaInterface; | ||||||||||||||||||||||
| use Exception; | ||||||||||||||||||||||
| use Illuminate\Support\Facades\Http; | ||||||||||||||||||||||
| use xPaw\MinecraftQuery; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| class MinecraftBedrockQueryTypeSchema implements QueryTypeSchemaInterface | ||||||||||||||||||||||
|
|
@@ -21,29 +22,66 @@ 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(Server $server, string $ip, int $port): ?array | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return $this->tryQueryNetherNet($server, $ip, $port) ?? $this->tryQueryRakNet($server, $ip, $port); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** @return ?array{hostname: string, map: string, current_players: int, max_players: int, players: null} */ | ||||||||||||||||||||||
| private function tryQueryNetherNet(Server $server, string $ip, int $port): ?array | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| $response = Http::acceptJson() | ||||||||||||||||||||||
| ->connectTimeout(2) | ||||||||||||||||||||||
| ->timeout(5) | ||||||||||||||||||||||
| ->withoutRedirecting() | ||||||||||||||||||||||
| ->get("http://{$ip}:{$port}/v1/join"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (!$response->successful()) { | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||
| return null; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $info = $response->json(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (!is_array($info)) { | ||||||||||||||||||||||
| return null; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High A 2xx NetherNet response with null
Suggested change
🤖 Copy this AI Prompt to have your agent fix this: |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return [ | ||||||||||||||||||||||
| 'hostname' => is_string($info['name']) ? $info['name'] : $server->name, | ||||||||||||||||||||||
| 'map' => is_string($info['level']) ? $info['level'] : 'world', | ||||||||||||||||||||||
| 'current_players' => is_int($info['players']) ? $info['players'] : 0, | ||||||||||||||||||||||
| 'max_players' => is_int($info['maxPlayers']) ? $info['maxPlayers'] : 0, | ||||||||||||||||||||||
| 'players' => null, // Bedrock has no player list | ||||||||||||||||||||||
| ]; | ||||||||||||||||||||||
| } catch (Exception) { | ||||||||||||||||||||||
| return null; // Either invalid or server may use RakNet | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** @return ?array{hostname: string, map: string, current_players: int, max_players: int, players: null} */ | ||||||||||||||||||||||
| private function tryQueryRakNet(Server $server, string $ip, int $port): ?array | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| $query = new MinecraftQuery(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| $query->ConnectBedrock($ip, $port, 5, true); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $info = $query->GetInfo(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (!is_array($info)) { | ||||||||||||||||||||||
| return null; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return [ | ||||||||||||||||||||||
| 'hostname' => $info['HostName'], | ||||||||||||||||||||||
| 'map' => $info['Map'], | ||||||||||||||||||||||
| 'current_players' => $info['Players'], | ||||||||||||||||||||||
| 'max_players' => $info['MaxPlayers'], | ||||||||||||||||||||||
| 'hostname' => is_string($info['HostName']) ? $info['HostName'] : 'Unknown', | ||||||||||||||||||||||
| 'map' => is_string($info['Map']) ? $info['Map'] : 'world', | ||||||||||||||||||||||
| 'current_players' => is_int($info['Players']) ? $info['Players'] : 0, | ||||||||||||||||||||||
| 'max_players' => is_int($info['MaxPlayers']) ? $info['MaxPlayers'] : 0, | ||||||||||||||||||||||
| 'players' => null, // Bedrock has no player list | ||||||||||||||||||||||
| ]; | ||||||||||||||||||||||
| } catch (Exception $exception) { | ||||||||||||||||||||||
| report($exception); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return null; | ||||||||||||||||||||||
| return null; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.