From 9eee06dc2eef082fe811119a71f74eccfb2a14bd Mon Sep 17 00:00:00 2001 From: Vari Date: Mon, 2 Sep 2024 00:12:22 +0200 Subject: [PATCH] Added Check to game steam login to verify if the user needs to have a special role to play the game. the role/s can be set in the .env with `ROLES_ALLOWED_TO_PLAY=` --- dist/.env.example | 4 ++++ .../Controllers/Api/Auth/SteamAuthController.php | 13 +++++++++++++ dist/config/app.php | 2 ++ 3 files changed, 19 insertions(+) diff --git a/dist/.env.example b/dist/.env.example index 1c87e60..854a7d8 100644 --- a/dist/.env.example +++ b/dist/.env.example @@ -49,6 +49,10 @@ SAIL_XDEBUG_CONFIG="client_host=172.23.0.3" STEAM_API_URL=https://api.steampowered.com/ STEAM_API_KEY=your-api-key +# What roles are allowed to login from the game, as a comma seperated list. +# Leave empty if everyone can play +ROLES_ALLOWED_TO_PLAY= + LAUNCHER_VERSION=1.0 # Username and Password for a steam account to generate a Session ticket, not needed otherwise diff --git a/dist/app/Http/Controllers/Api/Auth/SteamAuthController.php b/dist/app/Http/Controllers/Api/Auth/SteamAuthController.php index 237b351..28aa296 100644 --- a/dist/app/Http/Controllers/Api/Auth/SteamAuthController.php +++ b/dist/app/Http/Controllers/Api/Auth/SteamAuthController.php @@ -31,6 +31,13 @@ public function login(SteamLoginRequest $request) } $foundUser = User::firstOrCreate(['steam_id' => $steamResponse->steamId], ['source' => 'GAME', 'steam_id' => $steamResponse->steamId]); + + if(!$this->checkIfPlayAllowed($foundUser)) { + $log->notice('User with SteamID "{id}" denied login. User has not sufficent roele', ['id' => $steamResponse->steamId]); + return response('Unauthorized: Not Allowed', 401); + } + + Auth::login($foundUser); $this->fillSteamData($foundUser); @@ -64,4 +71,10 @@ protected function fillSteamData(User &$user): void $user->avatar_full = $player->avatarFull; $user->save(); } + + protected function checkIfPlayAllowed(User &$user): bool { + if(config('app.roles_allowed_to_play') === null) + return true; + return $user->hasAnyRole(config('app.roles_allowed_to_play')); + } } \ No newline at end of file diff --git a/dist/config/app.php b/dist/config/app.php index 53f8a53..8b578ff 100644 --- a/dist/config/app.php +++ b/dist/config/app.php @@ -128,6 +128,8 @@ 'launcher_version' => env('LAUNCHER_VERSION', 'null'), + 'roles_allowed_to_play' => env('ROLES_ALLOWED_TO_PLAY', '') === '' ? null : explode(',', env('ROLES_ALLOWED_TO_PLAY', 'null')), + /* |-------------------------------------------------------------------------- | Maintenance Mode Driver