Skip to content

Commit

Permalink
Ping test 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinecraft committed Jun 8, 2024
1 parent 8e17e70 commit af48c94
Show file tree
Hide file tree
Showing 191 changed files with 1,779 additions and 1,742 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ BACKUP_DISK=local
BACKUP_ARCHIVE_PASSWORD=null
BACKUP_NOTIFICATION_EMAIL=

# Cloud Backup(works with cloudflare r2 or s3)
# Storage & Cloud Backup(works with cloudflare r2 or s3)
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
Expand Down
20 changes: 20 additions & 0 deletions app/Http/Controllers/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,24 @@ public function queryServerWithWebQueryProtocol(Server $server, MinecraftServerQ
return response()->json(['message' => __('Web Query Failed')], 500);
}
}

public function pingServerWithWebQueryProtocol(Server $server, MinecraftServerQueryService $queryService, GeolocationService $geolocationService)
{
try {
// Check if we got cache
$hasCache = Cache::get('server:webping:' . $server->id);
if ($hasCache) {
return json_decode($hasCache, true);
}

$queryData = $queryService->getServerPingWithPluginWebQueryProtocol($server->ip_address, $server->webquery_port);
if ($queryData) {
Cache::put('server:webping:' . $server->id, json_encode($queryData), 60);
}

return ($queryData);
} catch (\Exception $exception) {
return response()->json(['message' => __('Web Query Failed')], 500);
}
}
}
9 changes: 9 additions & 0 deletions app/Services/MinecraftServerQueryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,13 @@ public function getServerStatusWithPluginWebQueryProtocol($serverHost, $serverPo

return $data;
}

public function getServerPingWithPluginWebQueryProtocol($serverHost, $serverPort)
{
$webQuery = new MinecraftWebQuery($serverHost, $serverPort);
$data = $webQuery->getPing();
$data = collect($data['data'])->recursive();

return $data;
}
}
7 changes: 7 additions & 0 deletions app/Utils/MinecraftQuery/MinecraftWebQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ public function getStatusQuery()
return $status;
}

public function getPing()
{
$data = $this->sendQuery('ping');

return $data;
}

public function checkPlayerOnline($playerUuid): bool
{
if (! Str::isUuid($playerUuid)) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit af48c94

Please sign in to comment.