Added handling of the "playerId" parameter to InitOrGetGroups.

This commit is contained in:
Vari 2024-03-06 21:40:32 +01:00
parent 80e736d878
commit d1b8e65624
2 changed files with 14 additions and 1 deletions

View File

@ -14,6 +14,7 @@
use App\Http\Responses\Api\Player\InitOrGetGroupsResponse;
use App\Http\Responses\Api\Player\UpdateMetadataResponse;
use App\Models\Game\PickedChallenge;
use App\Models\User\User;
use Illuminate\Support\Facades\Auth;
use Ramsey\Uuid\Type\Hexadecimal;
use Ramsey\Uuid\Uuid;
@ -23,7 +24,15 @@ class MetadataController extends Controller
public function initOrGetGroups(InitOrGetGroupsRequest $request)
{
$response = new InitOrGetGroupsResponse();
$user = Auth::user();
// If the request has set a player Id, use it.
// if not use the current authenticated user from this session.
// This is important because the hosts requests the progression and metadata groups for the other players
// for tracking challenges and so on.
if($request->playerId !== null)
$user = User::find($request->playerId);
else
$user = Auth::user();
foreach (ItemGroupType::cases() as $group) {
if ($group == ItemGroupType::None)

View File

@ -11,6 +11,8 @@ class InitOrGetGroupsRequest extends FormRequest
public bool $skipMetadataGroups;
public ?string $playerId;
/**
* Determine if the user is authorized to make this request.
@ -30,6 +32,7 @@ public function rules(): array
return [
'data.skipProgressionGroups' => 'bool|required',
'data.skipMetadataGroups' => 'bool|required',
'data.playerId' => 'string'
];
}
@ -37,5 +40,6 @@ protected function passedValidation()
{
$this->skipProgressionGroups = $this->input('data.skipProgressionGroups');
$this->skipMetadataGroups = $this->input('data.skipMetadataGroups');
$this->playerId = $this->input('data.playerId');
}
}