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=`
This commit is contained in:
Vari
2024-09-02 00:12:22 +02:00
parent e97d70ecb4
commit 9eee06dc2e
3 changed files with 19 additions and 0 deletions

4
dist/.env.example vendored
View File

@@ -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

View File

@@ -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'));
}
}

2
dist/config/app.php vendored
View File

@@ -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