mirror of
https://github.com/Deathgarden-Rebirth/Deathgarden_Rebirth-Rewrite.git
synced 2026-09-07 18:56:00 -05:00
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:
4
dist/.env.example
vendored
4
dist/.env.example
vendored
@@ -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
|
||||
|
||||
@@ -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
2
dist/config/app.php
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user