@@ -662,9 +662,21 @@ public function startPlay(User $user, PlaylistItem $playlistItem, array $rawPara
662
662
{
663
663
priv_check_user ($ user , 'MultiplayerScoreSubmit ' , $ this )->ensureCan ();
664
664
665
- $ this ->assertValidStartPlay ($ user , $ playlistItem );
665
+ $ params = get_params ($ rawParams , null , [
666
+ 'beatmap_hash ' ,
667
+ 'beatmap_id:int ' ,
668
+ 'build_id ' ,
669
+ 'ruleset_id:int ' ,
670
+ ], ['null_missing ' => true ]);
671
+
672
+ if (!$ playlistItem ->freestyle ) {
673
+ $ params ['beatmap_id ' ] = $ playlistItem ->beatmap_id ;
674
+ $ params ['ruleset_id ' ] = $ playlistItem ->ruleset_id ;
675
+ }
666
676
667
- return $ this ->getConnection ()->transaction (function () use ($ playlistItem , $ rawParams , $ user ) {
677
+ $ this ->assertValidStartPlay ($ user , $ playlistItem , $ params );
678
+
679
+ return $ this ->getConnection ()->transaction (function () use ($ params , $ playlistItem , $ user ) {
668
680
$ agg = UserScoreAggregate::new ($ user , $ this );
669
681
if ($ agg ->wasRecentlyCreated ) {
670
682
$ this ->incrementInstance ('participant_count ' );
@@ -676,11 +688,11 @@ public function startPlay(User $user, PlaylistItem $playlistItem, array $rawPara
676
688
$ playlistItemAgg ->updateUserAttempts ();
677
689
678
690
return ScoreToken::create ([
679
- 'beatmap_hash ' => get_string ( $ rawParams ['beatmap_hash ' ] ?? null ) ,
680
- 'beatmap_id ' => $ playlistItem -> beatmap_id ,
681
- 'build_id ' => $ rawParams ['build_id ' ],
691
+ 'beatmap_hash ' => $ params ['beatmap_hash ' ],
692
+ 'beatmap_id ' => $ params [ ' beatmap_id ' ] ,
693
+ 'build_id ' => $ params ['build_id ' ],
682
694
'playlist_item_id ' => $ playlistItem ->getKey (),
683
- 'ruleset_id ' => $ playlistItem -> ruleset_id ,
695
+ 'ruleset_id ' => $ params [ ' ruleset_id ' ] ,
684
696
'user_id ' => $ user ->getKey (),
685
697
]);
686
698
});
@@ -741,14 +753,21 @@ private function assertValidStartGame()
741
753
}
742
754
}
743
755
744
- private function assertValidStartPlay (User $ user , PlaylistItem $ playlistItem)
756
+ private function assertValidStartPlay (User $ user , PlaylistItem $ playlistItem, array $ params ): void
745
757
{
746
758
// todo: check against room's end time (to see if player has enough time to play this beatmap) and is under the room's max attempts limit
747
759
748
760
if ($ this ->hasEnded ()) {
749
761
throw new InvariantException ('Room has already ended. ' );
750
762
}
751
763
764
+ if ($ playlistItem ->freestyle ) {
765
+ // assert the beatmap_id is part of playlist item's beatmapset
766
+ if ($ playlistItem ->beatmap ->beatmapset_id !== Beatmap::find ($ params ['beatmap_id ' ])?->beatmapset_id) {
767
+ throw new InvariantException ('Specified beatmap_id is not allowed ' );
768
+ }
769
+ }
770
+
752
771
$ userId = $ user ->getKey ();
753
772
if ($ this ->max_attempts !== null ) {
754
773
$ roomStats = $ this ->userHighScores ()->where ('user_id ' , $ userId )->first ();
0 commit comments