diff --git a/dist/.env.example b/dist/.env.example index 1aeed1a..b0dfb2c 100644 --- a/dist/.env.example +++ b/dist/.env.example @@ -80,7 +80,9 @@ STEAM_API_KEY=your-api-key # Leave empty if everyone can play ROLES_ALLOWED_TO_PLAY= -LAUNCHER_VERSION=1.0 +# Comma separated launcher update public keys (base64), the same keys as SigningKeys.ProductionKeys in the launcher. +# When set, uploaded launcher releases must carry a manifest signature that verifies against one of them. +LAUNCHER_UPDATE_PUBLIC_KEYS= # Username and Password for a steam account to generate a Session ticket, not needed otherwise DEV_STEAM_ACCOUNT_NAME= diff --git a/dist/app/Classes/Launcher/LauncherReleasePublisher.php b/dist/app/Classes/Launcher/LauncherReleasePublisher.php new file mode 100644 index 0000000..0064ccc --- /dev/null +++ b/dist/app/Classes/Launcher/LauncherReleasePublisher.php @@ -0,0 +1,250 @@ +warnings = []; + $this->prunedVersions = []; + + $zip = $this->openZip($zipPath); + + try { + $folder = $this->findReleaseFolder($zip); + $manifestJson = $this->readSmallFile($zip, $folder.LauncherRelease::MANIFEST_FILE_NAME, static::MAX_MANIFEST_BYTES); + $signature = $this->readSmallFile($zip, $folder.LauncherRelease::SIGNATURE_FILE_NAME, static::MAX_SIGNATURE_BYTES); + + $manifest = $this->validateManifest($manifestJson); + $this->validateSignature($manifestJson, $signature); + $this->collectWarnings($manifest); + + $this->store($zip, $folder, $manifest, $manifestJson, $signature); + } finally { + $zip->close(); + } + + $release = LauncherRelease::find($manifest['version']); + $release->makeCurrent(); + + $this->prunedVersions = LauncherRelease::pruneOldReleases()->pluck('version')->all(); + + return $release; + } + + protected function openZip(string $zipPath): ZipArchive + { + throw_unless(class_exists(ZipArchive::class), static::invalid('The PHP zip extension is not enabled on this server (extension=zip in php.ini).')); + + $zip = new ZipArchive; + throw_unless($zip->open($zipPath, ZipArchive::RDONLY) === true, static::invalid('The uploaded file is not a valid zip archive.')); + + return $zip; + } + + /** + * The manifest may sit at the zip root or inside a single top-level folder. Returns that folder with a trailing slash, or ''. + */ + protected function findReleaseFolder(ZipArchive $zip): string + { + $folders = $this->entryNames($zip) + ->filter(fn (string $name) => basename($name) === LauncherRelease::MANIFEST_FILE_NAME) + ->map(fn (string $name) => dirname($name) === '.' ? '' : dirname($name).'/') + ->filter(fn (string $folder) => substr_count($folder, '/') <= 1); + + throw_if($folders->isEmpty(), static::invalid('The zip does not contain '.LauncherRelease::MANIFEST_FILE_NAME.'.')); + throw_if($folders->count() > 1, static::invalid('The zip contains more than one '.LauncherRelease::MANIFEST_FILE_NAME.'.')); + + return $folders->first(); + } + + protected function readSmallFile(ZipArchive $zip, string $name, int $maxBytes): string + { + $stat = $zip->statName($name); + + throw_if($stat === false, static::invalid('The zip does not contain '.basename($name).'.')); + throw_if($stat['size'] > $maxBytes, static::invalid(basename($name).' is larger than allowed.')); + + return $zip->getFromName($name); + } + + /** + * @return array{product: string, channel: string, version: string, builds: array} + */ + protected function validateManifest(string $manifestJson): array + { + $manifest = json_decode($manifestJson, true); + throw_unless(is_array($manifest), static::invalid('The manifest is not valid JSON.')); + + $alreadyPublished = LauncherRelease::all()->firstWhere('manifestHash', hash('sha256', $manifestJson)); + throw_if($alreadyPublished !== null, static::invalid("This manifest has already been published as version {$alreadyPublished?->version}.")); + + $builds = $manifest['builds'] ?? null; + throw_if(is_array($builds) && $builds !== [] && array_is_list($builds), static::invalid('The manifest builds must be keyed by framework.')); + + // Framework keys contain dots (net11.0-windows), which the validator would read as nesting, so builds are validated as a list. + $validator = Validator::make([...$manifest, 'builds' => is_array($builds) ? array_values($builds) : $builds], [ + 'product' => ['required', 'string', 'in:'.LauncherRelease::PRODUCT], + 'channel' => ['required', 'string'], + 'version' => [ + 'required', 'string', 'regex:'.LauncherRelease::VERSION_PATTERN, + Rule::notIn(LauncherRelease::all()->pluck('version')), + ], + 'builds' => ['required', 'array', 'min:1'], + 'builds.*.file' => [ + 'required', 'string', 'regex:/^[A-Za-z0-9_+-][A-Za-z0-9._+-]*$/', 'not_regex:/\.\./', 'distinct', + 'not_in:'.LauncherRelease::MANIFEST_FILE_NAME.','.LauncherRelease::SIGNATURE_FILE_NAME, + ], + 'builds.*.size' => ['required', 'integer', 'min:1'], + 'builds.*.sha256' => ['required', 'string', 'regex:/^[0-9a-fA-F]{64}$/'], + ], [ + 'product.in' => 'The manifest product must be "'.LauncherRelease::PRODUCT.'".', + 'version.regex' => 'The manifest version must look like 1.2.3.', + 'version.not_in' => 'Version :input has already been published.', + 'builds.required' => 'The manifest lists no builds.', + ...collect(['regex', 'not_regex', 'not_in', 'distinct']) + ->mapWithKeys(fn (string $rule) => ["builds.*.file.{$rule}" => 'Build file ":input" has an invalid file name.']) + ->all(), + ]); + + throw_if($validator->fails(), static::invalid($validator->errors()->first())); + + return $manifest; + } + + protected function validateSignature(string $manifestJson, string $signature): void + { + throw_unless(ManifestSignature::isWellFormed($signature), static::invalid('The manifest signature file is malformed.')); + + if ($this->trustedPublicKeys === []) { + $this->warnings[] = 'The manifest signature was not verified because LAUNCHER_UPDATE_PUBLIC_KEYS is not set. The launcher still verifies it.'; + + return; + } + + throw_unless( + ManifestSignature::verify($manifestJson, $signature, $this->trustedPublicKeys), + static::invalid('The manifest signature does not match any trusted key.'), + ); + } + + /** + * @param array{channel: string, version: string} $manifest + */ + protected function collectWarnings(array $manifest): void + { + if ($manifest['channel'] !== LauncherRelease::STABLE_CHANNEL) { + $this->warnings[] = "The manifest channel is \"{$manifest['channel']}\". Production launchers only accept \"".LauncherRelease::STABLE_CHANNEL.'".'; + } + + $newestVersion = LauncherRelease::all()->first()?->version; + if ($newestVersion !== null && version_compare($manifest['version'], $newestVersion, '<')) { + $this->warnings[] = "Version {$manifest['version']} is older than {$newestVersion}, so launchers already on {$newestVersion} will not update to it."; + } + } + + /** + * @param array{version: string, builds: array} $manifest + */ + protected function store(ZipArchive $zip, string $folder, array $manifest, string $manifestJson, string $signature): void + { + $disk = LauncherRelease::disk(); + $version = $manifest['version']; + + try { + foreach ($manifest['builds'] as $build) { + $entryName = $this->findBuildEntry($zip, $folder, $build); + $path = LauncherRelease::path($version, $build['file']); + + $disk->writeStream($path, $zip->getStream($entryName)); + + throw_unless( + $disk->size($path) === $build['size'] && $disk->checksum($path, ['checksum_algo' => 'sha256']) === Str::lower($build['sha256']), + static::invalid("{$build['file']} does not match the size or SHA-256 in the manifest."), + ); + } + + // Stored byte-for-byte: the signature covers the exact manifest bytes. The manifest goes last. + $disk->put(LauncherRelease::path($version, LauncherRelease::SIGNATURE_FILE_NAME), $signature); + $disk->put(LauncherRelease::path($version, LauncherRelease::MANIFEST_FILE_NAME), $manifestJson); + } catch (Throwable $exception) { + $disk->deleteDirectory(LauncherRelease::path($version)); + + throw $exception; + } + } + + /** + * The entry with the manifest's file name, or else the single entry next to the manifest with the build's size and + * SHA-256 (CI may ship the exes under their versioned release names). The file is stored under the manifest's name. + * + * @param array{file: string, size: int, sha256: string} $build + */ + protected function findBuildEntry(ZipArchive $zip, string $folder, array $build): string + { + if ($zip->statName($folder.$build['file']) !== false) { + return $folder.$build['file']; + } + + $matches = $this->entryNames($zip) + ->filter(fn (string $name) => str_starts_with($name, $folder) && ! Str::contains(Str::after($name, $folder), '/')) + ->filter(fn (string $name) => $zip->statName($name)['size'] === $build['size']) + ->filter(fn (string $name) => hash_equals(Str::lower($build['sha256']), hash('sha256', $zip->getFromName($name)))); + + throw_unless($matches->count() === 1, static::invalid("The zip does not contain {$build['file']}.")); + + return $matches->first(); + } + + /** + * @return Collection + */ + protected function entryNames(ZipArchive $zip): Collection + { + return Collection::times($zip->numFiles, fn (int $number) => str_replace('\\', '/', (string) $zip->getNameIndex($number - 1))); + } + + protected static function invalid(string $message): ValidationException + { + return ValidationException::withMessages(['release' => $message]); + } +} diff --git a/dist/app/Classes/Launcher/ManifestSignature.php b/dist/app/Classes/Launcher/ManifestSignature.php new file mode 100644 index 0000000..f005234 --- /dev/null +++ b/dist/app/Classes/Launcher/ManifestSignature.php @@ -0,0 +1,58 @@ +contains(function (string $publicKey) use ($manifest, $derSignature) { + $pem = "-----BEGIN PUBLIC KEY-----\n".chunk_split(trim($publicKey), 64, "\n")."-----END PUBLIC KEY-----\n"; + + return @openssl_verify($manifest, $derSignature, $pem, OPENSSL_ALGO_SHA256) === 1; + }); + } + + /** + * openssl_verify() expects the DER encoding: SEQUENCE { INTEGER r, INTEGER s }. + */ + protected static function toDer(string $signature): string + { + $encodeInteger = function (string $bytes): string { + $bytes = ltrim($bytes, "\x00"); + + if ($bytes === '' || ord($bytes[0]) & 0x80) { + $bytes = "\x00".$bytes; + } + + return "\x02".chr(strlen($bytes)).$bytes; + }; + + $half = intdiv(strlen($signature), 2); + $sequence = $encodeInteger(substr($signature, 0, $half)).$encodeInteger(substr($signature, $half)); + + return "\x30".chr(strlen($sequence)).$sequence; + } +} diff --git a/dist/app/Http/Controllers/Api/StatisticsController.php b/dist/app/Http/Controllers/Api/StatisticsController.php index dccb892..084adb5 100644 --- a/dist/app/Http/Controllers/Api/StatisticsController.php +++ b/dist/app/Http/Controllers/Api/StatisticsController.php @@ -7,7 +7,7 @@ use App\Http\Controllers\Controller; use App\Http\Responses\Api\Statistics\OnlinePlayersResponse; use App\Models\Admin\LauncherMessage; -use App\Models\Admin\Versioning\LauncherVersion; +use App\Models\Admin\LauncherRelease; use App\Models\Game\Matchmaking\QueuedPlayer; use DB; use Illuminate\Support\Facades\Cache; @@ -38,9 +38,12 @@ public function getOnlinePlayers() 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(LauncherVersion::get()?->launcherVersion); + return json_encode(LauncherRelease::current()?->version); } public function getLauncherMessage(): ?string diff --git a/dist/app/Http/Controllers/Web/Admin/Tools/AdminToolController.php b/dist/app/Http/Controllers/Web/Admin/Tools/AdminToolController.php index 4408a00..4cdf7f0 100644 --- a/dist/app/Http/Controllers/Web/Admin/Tools/AdminToolController.php +++ b/dist/app/Http/Controllers/Web/Admin/Tools/AdminToolController.php @@ -4,7 +4,6 @@ use App\Enums\Auth\Permissions; use App\Http\Controllers\Controller; -use Illuminate\Http\Request; use Illuminate\Support\Facades\View; abstract class AdminToolController extends Controller @@ -31,7 +30,7 @@ final public static function getAllTools(): array GameNewsController::class, FileManagerController::class, VersioningController::class, - LauncherMessageController::class, + LauncherController::class, LogViewerController::class, MatchConfigurationController::class, UsersController::class, @@ -41,7 +40,8 @@ final public static function getAllTools(): array ]; } - public static function getNotificationText(): ?string { + public static function getNotificationText(): ?string + { return null; } @@ -65,7 +65,8 @@ final public static function getNeededPermission(): string return static::$neededPermission->value; } - final protected function overrideTitle(string $title): void { + final protected function overrideTitle(string $title): void + { View::share('title', $title); } } diff --git a/dist/app/Http/Controllers/Web/Admin/Tools/LauncherController.php b/dist/app/Http/Controllers/Web/Admin/Tools/LauncherController.php new file mode 100644 index 0000000..14fddd8 --- /dev/null +++ b/dist/app/Http/Controllers/Web/Admin/Tools/LauncherController.php @@ -0,0 +1,77 @@ + LauncherMessage::getMessage(), + 'currentRelease' => LauncherRelease::current(), + 'releases' => LauncherRelease::all(), + ]); + } + + public function saveMessage(SaveLauncherMessageRequest $request): RedirectResponse + { + $success = (new LauncherMessage($request->message, $request->url))->saveMessage(); + + return $success === true + ? back()->with('alert-success', 'Message Saved') + : back()->with('alert-error', 'Message Saving failed: '.e($success)); + } + + /** + * Rejections are validation errors on the "release" field, so they redirect back on their own. + */ + public function uploadRelease(UploadLauncherReleaseRequest $request, LauncherReleasePublisher $publisher): RedirectResponse + { + $release = $publisher->publish($request->file('release')->getRealPath()); + + $successMessage = "Launcher {$release->version} published"; + if ($publisher->prunedVersions !== []) { + $successMessage .= '. Removed old releases: '.implode(', ', $publisher->prunedVersions); + } + + return back()->with(array_filter([ + 'alert-success' => e($successMessage), + 'alert-warning' => collect($publisher->warnings)->map(fn (string $warning) => e($warning))->implode('
'), + ])); + } + + public function activateRelease(LauncherRelease $release): RedirectResponse + { + return $release->makeCurrent() + ? back()->with('alert-success', e("Launcher {$release->version} is now the current release")) + : back()->with('alert-error', 'Could not switch the current launcher release'); + } + + public function destroyRelease(LauncherRelease $release): RedirectResponse + { + if ($release->isCurrent()) { + return back()->with('alert-error', 'The current release cannot be deleted. Make another release current first.'); + } + + return $release->delete() + ? back()->with('alert-success', e("Launcher {$release->version} deleted")) + : back()->with('alert-error', e("Could not delete launcher {$release->version}")); + } +} diff --git a/dist/app/Http/Controllers/Web/Admin/Tools/LauncherMessageController.php b/dist/app/Http/Controllers/Web/Admin/Tools/LauncherMessageController.php deleted file mode 100644 index 5dc9030..0000000 --- a/dist/app/Http/Controllers/Web/Admin/Tools/LauncherMessageController.php +++ /dev/null @@ -1,41 +0,0 @@ - LauncherMessage::getMessage(), - ]); - } - - public function saveMessage(SaveLauncherMessageRequest $request) { - $newMessage = new LauncherMessage( - $request->message, - $request->url - ); - - $success = $newMessage->saveMessage(); - - if($success === true) - Session::flash('alert-success', 'Message Saved'); - else - Session::flash('alert-error', 'Message Saving failed: ' . $success); - - return back(); - } -} diff --git a/dist/app/Http/Controllers/Web/Admin/Tools/MatchConfigurationController.php b/dist/app/Http/Controllers/Web/Admin/Tools/MatchConfigurationController.php index 2db53ef..1b22742 100644 --- a/dist/app/Http/Controllers/Web/Admin/Tools/MatchConfigurationController.php +++ b/dist/app/Http/Controllers/Web/Admin/Tools/MatchConfigurationController.php @@ -5,18 +5,11 @@ use App\Enums\Auth\Permissions; use App\Enums\Game\ExperienceEventType; use App\Http\Requests\Api\Admin\Tools\SaveCurrencyConfiguration; -use App\Http\Requests\Api\Admin\Tools\SaveLauncherMessageRequest; use App\Http\Requests\Api\Admin\Tools\SaveMatchConfigurationRequest; use App\Http\Requests\Api\Admin\Tools\SaveMatchmakingConfigurationRequest; -use App\Http\Requests\Api\Admin\Tools\SaveVersioningRequest; use App\Models\Admin\CurrencyMultipliers; use App\Models\Admin\ExperienceMultipliers; -use App\Models\Admin\LauncherMessage; use App\Models\Admin\MatchmakingSettings; -use App\Models\Admin\Versioning\CurrentCatalogVersion; -use App\Models\Admin\Versioning\CurrentContentVersion; -use App\Models\Admin\Versioning\CurrentGameVersion; -use App\Models\Admin\Versioning\LauncherVersion; use Session; class MatchConfigurationController extends AdminToolController @@ -24,6 +17,7 @@ class MatchConfigurationController extends AdminToolController protected static string $name = 'Match Configuration'; protected static string $description = 'Manage Events & Game Modes'; + protected static string $iconComponent = 'icons.globe'; protected static Permissions $neededPermission = Permissions::FILE_UPLOAD; @@ -51,7 +45,7 @@ public function saveExperience(SaveMatchConfigurationRequest $request) Session::flash('alert-success', 'Configuration saved successfully.'); } catch (\Exception $e) { - Session::flash('alert-error', 'Configuration could not be saved, something went wrong: ' . $e->getMessage()); + Session::flash('alert-error', 'Configuration could not be saved, something went wrong: '.$e->getMessage()); } return back(); @@ -69,13 +63,14 @@ public function saveCurrency(SaveCurrencyConfiguration $request) Session::flash('alert-success', 'Configuration saved successfully.'); } catch (\Exception $e) { - Session::flash('alert-error', 'Configuration could not be saved, something went wrong: ' . $e->getMessage()); + Session::flash('alert-error', 'Configuration could not be saved, something went wrong: '.$e->getMessage()); } return back(); } - public function saveMatchmaking(SaveMatchmakingConfigurationRequest $request) { + public function saveMatchmaking(SaveMatchmakingConfigurationRequest $request) + { $matchmakingConfig = MatchmakingSettings::get(); try { @@ -83,12 +78,10 @@ public function saveMatchmaking(SaveMatchmakingConfigurationRequest $request) { $matchmakingConfig->save(); Session::flash('alert-success', 'Matchmaking configuration saved successfully.'); - } - catch (\Exception $e) { - Session::flash('alert-error', 'Matchmaking configuration could not be saved, something went wrong: ' . $e->getMessage()); + } catch (\Exception $e) { + Session::flash('alert-error', 'Matchmaking configuration could not be saved, something went wrong: '.$e->getMessage()); } return back(); } - -} \ No newline at end of file +} diff --git a/dist/app/Http/Controllers/Web/Admin/Tools/VersioningController.php b/dist/app/Http/Controllers/Web/Admin/Tools/VersioningController.php index 96c47ff..6ee45a0 100644 --- a/dist/app/Http/Controllers/Web/Admin/Tools/VersioningController.php +++ b/dist/app/Http/Controllers/Web/Admin/Tools/VersioningController.php @@ -3,20 +3,18 @@ namespace App\Http\Controllers\Web\Admin\Tools; use App\Enums\Auth\Permissions; -use App\Http\Requests\Api\Admin\Tools\SaveLauncherMessageRequest; use App\Http\Requests\Api\Admin\Tools\SaveVersioningRequest; -use App\Models\Admin\LauncherMessage; use App\Models\Admin\Versioning\CurrentCatalogVersion; use App\Models\Admin\Versioning\CurrentContentVersion; use App\Models\Admin\Versioning\CurrentGameVersion; -use App\Models\Admin\Versioning\LauncherVersion; use Session; class VersioningController extends AdminToolController { protected static string $name = 'Versioning'; - protected static string $description = 'Manage the Launcher & Game Versions'; + protected static string $description = 'Manage the Game, Content & Catalog Versions'; + protected static string $iconComponent = 'icons.arrow-left-right'; protected static Permissions $neededPermission = Permissions::FILE_UPLOAD; @@ -26,39 +24,39 @@ public function index() return view('admin.tools.versioning'); } - public function save(SaveVersioningRequest $request) { + public function save(SaveVersioningRequest $request) + { $errorMessage = ''; - $successMessage= ''; + $successMessage = ''; $success = (new CurrentGameVersion($request->gameVersion))->save(); - if($success === true) + if ($success === true) { $successMessage .= "Game version saved\n\n"; - else + } else { $errorMessage .= "Game version saving failed: ' . $success\n\n"; + } $success = (new CurrentContentVersion($request->contentVersion))->save(); - if($success === true) + if ($success === true) { $successMessage .= "Content version saved\n\n"; - else + } else { $errorMessage .= "Content version saving failed: ' . $success\n\n"; + } (new CurrentCatalogVersion($request->catalogVersion))->save(); - if($success === true) + if ($success === true) { $successMessage .= "Catalog version saved\n\n"; - else + } else { $errorMessage .= "Catalog version saving failed: ' . $success\n\n"; + } - (new LauncherVersion($request->launcherVersion))->save(); - if($success === true) - $successMessage .= "Launcher version saved\n\n"; - else - $errorMessage .= "Launcher version saving failed: ' . $success\n\n"; - - if($success !== '') + if ($success !== '') { Session::flash('alert-success', nl2br(trim($successMessage))); - if($errorMessage !== '') + } + if ($errorMessage !== '') { Session::flash('alert-error', nl2br(trim($errorMessage))); + } return back(); } -} \ No newline at end of file +} diff --git a/dist/app/Http/Controllers/Web/Homepage/HomepageController.php b/dist/app/Http/Controllers/Web/Homepage/HomepageController.php index 327c225..e84e49c 100644 --- a/dist/app/Http/Controllers/Web/Homepage/HomepageController.php +++ b/dist/app/Http/Controllers/Web/Homepage/HomepageController.php @@ -5,15 +5,14 @@ use App\Enums\Launcher\FileAction; use App\Enums\Launcher\Patchline; use App\Http\Controllers\Controller; -use App\Models\Admin\Versioning\LauncherVersion; +use App\Models\Admin\LauncherRelease; use App\Models\GameFile; -use App\Models\User\User; use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\View; use Illuminate\Foundation\Application; use Illuminate\Support\Facades\Response; -use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\View as CompView; +use Symfony\Component\HttpFoundation\BinaryFileResponse; class HomepageController extends Controller { @@ -23,6 +22,7 @@ public function index(): Factory|Application|View|\Illuminate\Contracts\Foundati community and is now playable again, featuring new balance changes for an improved experience.'); CompView::share('metaKeywords', ['Deathgarden', 'Rebirth']); + return view('web.home'); } @@ -35,16 +35,18 @@ public function download(): Factory|Application|View|\Illuminate\Contracts\Found static::setTitle('Deathgarden: Rebirth | Download'); CompView::share('metaKeywords', ['Deathgarden', 'Rebirth', 'Download', 'Launcher']); CompView::share('metaDescription', 'Download the official Deathgarden: Rebirth launcher to easily install and update the Deathgarden: Rebirth mod.'); + return view('web.download', ['files' => $files]); } - public function downloadLauncher() + public function downloadLauncher(): BinaryFileResponse { - // Put launcher .exe into storage/app folder - if(Storage::disk('local')->exists('Deathgarden Launcher_'.LauncherVersion::get()?->launcherVersion.'.exe')) - return Response::download(Storage::disk('local')->path('Deathgarden Launcher_'.LauncherVersion::get()?->launcherVersion.'.exe')); + $release = LauncherRelease::current() ?? abort(404); + $path = $release->servableFilePath($release->downloadBuild()['file'] ?? '') ?? abort(404); - abort(404); + return Response::download($path, "Deathgarden Launcher_{$release->version}.exe", [ + 'Cache-Control' => 'no-cache, no-store, must-revalidate', + ]); } public function patchNotes(): Factory|Application|View|\Illuminate\Contracts\Foundation\Application @@ -52,30 +54,35 @@ public function patchNotes(): Factory|Application|View|\Illuminate\Contracts\Fou static::setTitle('Deathgarden: Rebirth | Patch Notes'); CompView::share('metaKeywords', ['Deathgarden', 'Rebirth', 'patch', 'patchnnotes', 'patch notes']); CompView::share('metaDescription', 'Stay up to date with all the changes, improvements, and updates in Deathgarden: Rebirth. Below is a complete archive of every patch since the mods release.'); + return view('web.patch-notes'); } public function howToPlay(): Factory|Application|View|\Illuminate\Contracts\Foundation\Application { static::setTitle('Deathgarden: Rebirth | How to Play'); + return view('web.how-to-play'); } public function knownIssues(): Factory|Application|View|\Illuminate\Contracts\Foundation\Application { static::setTitle('Deathgarden: Rebirth | Known Issues'); + return view('web.known-issues'); } public function eula(): Factory|Application|View|\Illuminate\Contracts\Foundation\Application { static::setTitle('Deathgarden: Rebirth | End User License Agreement'); + return view('web.eula'); } public function credits(): Factory|Application|View|\Illuminate\Contracts\Foundation\Application { static::setTitle('Deathgarden: Rebirth | Credits'); + return view('web.credits'); } diff --git a/dist/app/Http/Controllers/Web/LauncherFileController.php b/dist/app/Http/Controllers/Web/LauncherFileController.php new file mode 100644 index 0000000..9029ab1 --- /dev/null +++ b/dist/app/Http/Controllers/Web/LauncherFileController.php @@ -0,0 +1,29 @@ +servableFilePath($fileName) ?? abort(404); + + return response()->file($path, [ + 'Content-Type' => match ($fileName) { + LauncherRelease::MANIFEST_FILE_NAME => 'application/json', + LauncherRelease::SIGNATURE_FILE_NAME => 'text/plain; charset=utf-8', + default => 'application/octet-stream', + }, + 'Cache-Control' => 'no-cache, no-store, must-revalidate', + ]); + } +} diff --git a/dist/app/Http/Requests/Api/Admin/Tools/SaveVersioningRequest.php b/dist/app/Http/Requests/Api/Admin/Tools/SaveVersioningRequest.php index 8785f42..d8d8c77 100644 --- a/dist/app/Http/Requests/Api/Admin/Tools/SaveVersioningRequest.php +++ b/dist/app/Http/Requests/Api/Admin/Tools/SaveVersioningRequest.php @@ -2,12 +2,11 @@ namespace App\Http\Requests\Api\Admin\Tools; +use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Foundation\Http\FormRequest; class SaveVersioningRequest extends FormRequest { - public string $launcherVersion; - public string $gameVersion; public string $contentVersion; @@ -17,12 +16,11 @@ class SaveVersioningRequest extends FormRequest /** * Get the validation rules that apply to the request. * - * @return array|string> + * @return array|string> */ public function rules(): array { return [ - 'launcherVersion' => 'required|string', 'gameVersion' => 'required|string', 'contentVersion' => 'required|string', 'catalogVersion' => 'required|string', @@ -31,7 +29,6 @@ public function rules(): array protected function passedValidation() { - $this->launcherVersion = $this->input('launcherVersion'); $this->gameVersion = $this->input('gameVersion'); $this->contentVersion = $this->input('contentVersion'); $this->catalogVersion = $this->input('catalogVersion'); diff --git a/dist/app/Http/Requests/Api/Admin/Tools/UploadLauncherReleaseRequest.php b/dist/app/Http/Requests/Api/Admin/Tools/UploadLauncherReleaseRequest.php new file mode 100644 index 0000000..8f973f3 --- /dev/null +++ b/dist/app/Http/Requests/Api/Admin/Tools/UploadLauncherReleaseRequest.php @@ -0,0 +1,23 @@ +|string> + */ + public function rules(): array + { + return [ + // CI zip: the exes, launcher-manifest.json and launcher-manifest.json.sig. + 'release' => ['required', File::types(['zip'])->max('500mb')], + ]; + } +} diff --git a/dist/app/Models/Admin/LauncherRelease.php b/dist/app/Models/Admin/LauncherRelease.php new file mode 100644 index 0000000..45e9d19 --- /dev/null +++ b/dist/app/Models/Admin/LauncherRelease.php @@ -0,0 +1,175 @@ + $builds Keyed by framework key, e.g. "net11.0-windows". + */ + public function __construct( + public string $version, + public string $channel, + public ?string $notes, + public ?Carbon $builtAt, + public array $builds, + public string $manifestHash, + ) {} + + public static function current(): ?static + { + $version = static::disk()->get(static::CURRENT_FILE); + + return $version === null ? null : static::find(trim($version)); + } + + public static function find(string $version): ?static + { + if (preg_match(static::VERSION_PATTERN, $version) !== 1) { + return null; + } + + $manifestJson = static::disk()->get(static::path($version, static::MANIFEST_FILE_NAME)); + $manifest = json_decode($manifestJson ?? '', true); + + if (! is_array($manifest)) { + return null; + } + + return new static( + $version, + $manifest['channel'] ?? '', + $manifest['notes'] ?? null, + isset($manifest['published']) ? Carbon::parse($manifest['published']) : null, + $manifest['builds'] ?? [], + hash('sha256', $manifestJson), + ); + } + + public static function findOrFail(string $version): static + { + return static::find($version) ?? abort(404); + } + + /** + * @return Collection Newest version first. + */ + public static function all(): Collection + { + return collect(static::disk()->directories('releases')) + ->map(fn (string $directory) => static::find(basename($directory))) + ->filter() + ->sort(fn (self $a, self $b) => version_compare($b->version, $a->version)) + ->values(); + } + + public function makeCurrent(): bool + { + return static::disk()->put(static::CURRENT_FILE, $this->version); + } + + public function isCurrent(): bool + { + return static::current()?->version === $this->version; + } + + /** + * Deletes the release folder. The current release is never deleted: launchers are downloading it. + */ + public function delete(): bool + { + return ! $this->isCurrent() && static::disk()->deleteDirectory(static::path($this->version)); + } + + /** + * Deletes the oldest versions beyond MAX_RELEASES, never the current release. + * + * @return Collection The deleted releases. + */ + public static function pruneOldReleases(): Collection + { + $currentVersion = static::current()?->version; + + return static::all() + ->reject(fn (self $release) => $release->version === $currentVersion) + ->slice($currentVersion === null ? static::MAX_RELEASES : static::MAX_RELEASES - 1) + ->filter(fn (self $release) => $release->delete()) + ->values(); + } + + public function isStable(): bool + { + return $this->channel === static::STABLE_CHANNEL; + } + + /** + * @return string[] + */ + public function frameworks(): array + { + return array_keys($this->builds); + } + + /** + * Absolute path of a file the launcher may download from this release, or null for anything the manifest doesn't list. + */ + public function servableFilePath(string $fileName): ?string + { + $servableFileNames = [static::MANIFEST_FILE_NAME, static::SIGNATURE_FILE_NAME, ...array_column($this->builds, 'file')]; + $path = static::path($this->version, $fileName); + + if (! in_array($fileName, $servableFileNames, true) || ! static::disk()->exists($path)) { + return null; + } + + return static::disk()->path($path); + } + + /** + * The build offered on the download page: the newest framework, e.g. net11.0-windows over net9.0-windows. + * + * @return array{file: string, size: int, sha256: string}|null + */ + public function downloadBuild(): ?array + { + return collect($this->builds) + ->sortKeysUsing(fn (string $a, string $b) => strnatcmp($b, $a)) + ->first(); + } + + public static function path(string $version, string $fileName = ''): string + { + return rtrim("releases/{$version}/{$fileName}", '/'); + } + + public static function disk(): FilesystemAdapter + { + return Storage::disk('launcher'); + } +} diff --git a/dist/app/Models/Admin/Versioning/LauncherVersion.php b/dist/app/Models/Admin/Versioning/LauncherVersion.php deleted file mode 100644 index 1c52ac5..0000000 --- a/dist/app/Models/Admin/Versioning/LauncherVersion.php +++ /dev/null @@ -1,17 +0,0 @@ - storage_path('app/patches'), 'throw' => false, ], + + // Launcher releases uploaded in the admin panel, served to the launcher under /launcher/{file} + 'launcher' => [ + 'driver' => 'local', + 'root' => storage_path('app/launcher'), + 'throw' => false, + ], ], /* diff --git a/dist/config/services.php b/dist/config/services.php index cbfac3e..bc6a028 100644 --- a/dist/config/services.php +++ b/dist/config/services.php @@ -35,8 +35,14 @@ ], ], + 'launcher' => [ + // Comma separated ECDSA P-256 public keys (base64 SubjectPublicKeyInfo DER), the same as the launcher's SigningKeys. + // When set, an uploaded launcher release is rejected unless its manifest signature verifies against one of them. + 'update_public_keys' => array_values(array_filter(array_map('trim', explode(',', (string) env('LAUNCHER_UPDATE_PUBLIC_KEYS', ''))))), + ], + 'steam' => [ - 'baseUrl'=> env('STEAM_API_URL'), + 'baseUrl' => env('STEAM_API_URL'), 'apiKey' => env('STEAM_API_KEY'), 'appID' => 555440, diff --git a/dist/resources/views/admin/tools/launcher-message.blade.php b/dist/resources/views/admin/tools/launcher-message.blade.php deleted file mode 100644 index 8f5ff89..0000000 --- a/dist/resources/views/admin/tools/launcher-message.blade.php +++ /dev/null @@ -1,43 +0,0 @@ -@props([ - 'message' => null -]) - -@php - use App\Models\Admin\LauncherMessage; - - /** @var ?LauncherMessage $message */ -@endphp - - -
-
- @csrf -
- - - - - - - -
- - - Save - -
-
-
\ No newline at end of file diff --git a/dist/resources/views/admin/tools/launcher.blade.php b/dist/resources/views/admin/tools/launcher.blade.php new file mode 100644 index 0000000..329a2ef --- /dev/null +++ b/dist/resources/views/admin/tools/launcher.blade.php @@ -0,0 +1,159 @@ +@props([ + 'launcherMessage' => null, + 'currentRelease' => null, + 'releases' => collect(), +]) + +@php + use App\Models\Admin\LauncherMessage; + use App\Models\Admin\LauncherRelease; + use Illuminate\Support\Collection; + + /** @var ?LauncherMessage $launcherMessage */ + /** @var ?LauncherRelease $currentRelease */ + /** @var Collection $releases */ +@endphp + + +
+

Launcher Release

+ +
+ @if($currentRelease) +
+
+
Current version
+
{{ $currentRelease->version }}
+
+
+
Channel
+
$currentRelease->isStable(), 'text-yellow-400' => ! $currentRelease->isStable()])> + {{ $currentRelease->channel }} +
+
+
+
Builds
+
{{ implode(', ', $currentRelease->frameworks()) }}
+
+ @if($currentRelease->builtAt) +
+
Built
+
{{ $currentRelease->builtAt->utc()->format('Y-m-d H:i') }} UTC
+
+ @endif +
+ @if($currentRelease->notes) +

{{ $currentRelease->notes }}

+ @endif + @else +

No launcher release published yet. Players can't download the launcher until one is uploaded.

+ @endif +
+ +
+ @csrf + +

+ Must contain {{ LauncherRelease::MANIFEST_FILE_NAME }}, + {{ LauncherRelease::SIGNATURE_FILE_NAME }} + and every exe the manifest lists. Each version can only be published once, and it goes live as soon as it is verified. + Only the newest {{ LauncherRelease::MAX_RELEASES }} releases are kept. +

+ +
+ + + + Publish + +
+ + @error('release') +

{{ $message }}

+ @enderror +
+ + @if($releases->isNotEmpty()) +

Uploaded releases ({{ $releases->count() }}/{{ LauncherRelease::MAX_RELEASES }})

+ + + + + + + + + + + + @foreach($releases as $release) + @php($isCurrent = $release->version === $currentRelease?->version) + + + + + + + + @endforeach + +
VersionChannelBuildsBuilt
{{ $release->version }} ! $release->isStable()])>{{ $release->channel }}{{ implode(', ', $release->frameworks()) }}{{ $release->builtAt?->utc()->format('Y-m-d H:i') ?? '-' }} + @if($isCurrent) + Current + @else +
+
+ @csrf + Make current +
+
+ @csrf + @method('DELETE') + + Delete + +
+
+ @endif +
+ @endif +
+ +
+
+ @csrf +
+ + + + + + + +
+ + + Save + +
+
+
diff --git a/dist/resources/views/admin/tools/versioning.blade.php b/dist/resources/views/admin/tools/versioning.blade.php index 4fdf6d7..9816c3e 100644 --- a/dist/resources/views/admin/tools/versioning.blade.php +++ b/dist/resources/views/admin/tools/versioning.blade.php @@ -7,7 +7,6 @@ use App\Models\Admin\Versioning\CurrentCatalogVersion; use App\Models\Admin\Versioning\CurrentContentVersion; use App\Models\Admin\Versioning\CurrentGameVersion; - use App\Models\Admin\Versioning\LauncherVersion; /** @var ?LauncherMessage $message */ @endphp @@ -17,18 +16,7 @@
@csrf
- - - - -