From 458542de55f23321567c9f72dba39fd94d073ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 11 Dec 2024 12:35:24 +0900 Subject: [PATCH] Add capability to filter by room status To address https://osu.ppy.sh/community/forums/topics/2013293. Normally wouldn't detour for this but the second message in that thread pissed me off. I feel like people will start to exploit this now so maybe I shouldn't admit to it. --- app/Models/Multiplayer/Room.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/Models/Multiplayer/Room.php b/app/Models/Multiplayer/Room.php index 8ea4ebc3674..c54cbcccad8 100644 --- a/app/Models/Multiplayer/Room.php +++ b/app/Models/Multiplayer/Room.php @@ -77,6 +77,7 @@ class Room extends Model const PLAYLIST_QUEUE_MODE = 'host_only'; const REALTIME_DEFAULT_QUEUE_MODE = 'host_only'; const REALTIME_QUEUE_MODES = [ 'host_only', 'all_players', 'all_players_round_robin' ]; + const REALTIME_STATUSES = ['idle', 'playing']; public ?array $preloadedRecentParticipants = null; @@ -149,6 +150,7 @@ public static function search(array $rawParams, ?int $maxLimit = null) 'mode', 'season_id:int', 'sort', + 'status', 'type_group', 'user:any', ], ['null_missing' => true]); @@ -157,6 +159,7 @@ public static function search(array $rawParams, ?int $maxLimit = null) $user = $params['user']; $seasonId = $params['season_id']; $sort = $params['sort']; + $status = $params['status']; $category = $params['category']; $typeGroup = $params['type_group']; @@ -173,6 +176,14 @@ public static function search(array $rawParams, ?int $maxLimit = null) $query = static::whereIn('type', static::TYPE_GROUPS[$typeGroup]); + if (!in_array($status, static::REALTIME_STATUSES)) { + $status = null; + } + + if (isset($status)) { + $query->where('status', $status); + } + if (isset($seasonId)) { $query->whereRelation('seasons', 'seasons.id', $seasonId); }