Files
Deathgarden_Rebirth-Rewrite/dist/app/Http/Controllers/Api/StatisticsController.php
Shaggy84675 8bb72bb2b7 Deliver launcher updates from signed CI release zips
Replace the manually set launcher version with releases uploaded from the
CI zip (exes, launcher-manifest.json and launcher-manifest.json.sig).

- New "Launcher" admin tool (renamed from Launcher Message): upload a
  release, switch the current one, delete old ones, set the launcher message
- Uploads are validated: manifest rules, size + SHA-256 of every exe, and
  the ECDSA manifest signature when LAUNCHER_UPDATE_PUBLIC_KEYS is set
- The same zip, manifest or version cannot be published twice; only the
  newest 5 releases are kept and the current one is never removed
- Serve the current release to the launcher at /launcher/{file},
  byte-for-byte and uncached, with range support for resumed downloads
- /download-launcher serves the newest framework build; the legacy
  /api/v1/launcher-version returns the current release version
- Remove the launcher version from the Versioning tool
- Fix the file input button highlighting when hovering the whole input
2026-11-14 14:15:45 +01:00

54 lines
1.9 KiB
PHP

<?php
namespace App\Http\Controllers\Api;
use App\Enums\Game\Matchmaking\MatchmakingSide;
use App\Enums\Game\Matchmaking\MatchStatus;
use App\Http\Controllers\Controller;
use App\Http\Responses\Api\Statistics\OnlinePlayersResponse;
use App\Models\Admin\LauncherMessage;
use App\Models\Admin\LauncherRelease;
use App\Models\Game\Matchmaking\QueuedPlayer;
use DB;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Response;
class StatisticsController extends Controller
{
// Renamed from 'online-players-response' so entries cached by the old code (whole JsonResponse) are not read
const CACHE_KEY = 'online-players-counts';
public function getOnlinePlayers()
{
// Only plain values are cached: objects must be allow-listed in cache.serializable_classes to unserialize
$counts = Cache::remember(static::CACHE_KEY, 10, function () {
$queuedHunters = QueuedPlayer::whereSide(MatchmakingSide::Hunter)->count();
$queuedRunners = QueuedPlayer::whereSide(MatchmakingSide::Runner)->count();
$inGamePlayers = DB::table('game_user')
->join('games', 'game_user.game_id', '=', 'games.id')
->whereIn('games.status', [
MatchStatus::Closed,
MatchStatus::Opened,
MatchStatus::Created,
])->count();
return [$queuedRunners, $queuedHunters, $inGamePlayers];
});
return Response::json(new OnlinePlayersResponse(...$counts));
}
/**
* Legacy endpoint for launchers that predate the signed update manifest: they compare this version and send players to the download page.
*/
public function getLauncherVersion(): ?string
{
return json_encode(LauncherRelease::current()?->version);
}
public function getLauncherMessage(): ?string
{
return json_encode(LauncherMessage::getMessage());
}
}