2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-12-22 11:50:37 +08:00
|
|
|
|
|
2024-05-03 17:10:59 +08:00
|
|
|
|
using System;
|
2018-12-22 11:50:37 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-07-10 16:26:42 +08:00
|
|
|
|
using osu.Framework.IO.Network;
|
2022-06-20 21:02:15 +08:00
|
|
|
|
using osu.Game.Extensions;
|
2020-07-22 17:29:50 +08:00
|
|
|
|
using osu.Game.Online.API;
|
2024-05-03 17:10:59 +08:00
|
|
|
|
using osu.Game.Online.Rooms.RoomStatuses;
|
2020-12-25 23:50:00 +08:00
|
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
2018-12-22 11:50:37 +08:00
|
|
|
|
|
2020-12-25 12:38:11 +08:00
|
|
|
|
namespace osu.Game.Online.Rooms
|
2018-12-22 11:50:37 +08:00
|
|
|
|
{
|
|
|
|
|
public class GetRoomsRequest : APIRequest<List<Room>>
|
|
|
|
|
{
|
2020-12-07 20:59:38 +08:00
|
|
|
|
private readonly RoomStatusFilter status;
|
|
|
|
|
private readonly string category;
|
2018-12-22 11:50:37 +08:00
|
|
|
|
|
2020-12-07 20:59:38 +08:00
|
|
|
|
public GetRoomsRequest(RoomStatusFilter status, string category)
|
2018-12-22 11:50:37 +08:00
|
|
|
|
{
|
2020-12-07 20:59:38 +08:00
|
|
|
|
this.status = status;
|
|
|
|
|
this.category = category;
|
2018-12-22 11:50:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 16:26:42 +08:00
|
|
|
|
protected override WebRequest CreateWebRequest()
|
2018-12-22 11:50:37 +08:00
|
|
|
|
{
|
2020-07-10 16:26:42 +08:00
|
|
|
|
var req = base.CreateWebRequest();
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2020-12-07 20:59:38 +08:00
|
|
|
|
if (status != RoomStatusFilter.Open)
|
2022-06-20 21:02:15 +08:00
|
|
|
|
req.AddParameter("mode", status.ToString().ToSnakeCase().ToLowerInvariant());
|
2020-07-10 18:54:09 +08:00
|
|
|
|
|
2020-12-07 20:59:38 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(category))
|
|
|
|
|
req.AddParameter("category", category);
|
2020-07-10 16:26:42 +08:00
|
|
|
|
|
|
|
|
|
return req;
|
2018-12-22 11:50:37 +08:00
|
|
|
|
}
|
2020-07-10 16:26:42 +08:00
|
|
|
|
|
2024-05-03 17:10:59 +08:00
|
|
|
|
protected override void PostProcess()
|
|
|
|
|
{
|
|
|
|
|
base.PostProcess();
|
|
|
|
|
|
|
|
|
|
if (Response != null)
|
|
|
|
|
{
|
|
|
|
|
// API doesn't populate status so let's do it here.
|
|
|
|
|
foreach (var room in Response)
|
|
|
|
|
{
|
|
|
|
|
if (room.EndDate.Value != null && DateTimeOffset.Now >= room.EndDate.Value)
|
|
|
|
|
room.Status.Value = new RoomStatusEnded();
|
2024-05-03 17:11:29 +08:00
|
|
|
|
else if (room.HasPassword.Value)
|
|
|
|
|
room.Status.Value = new RoomStatusOpenPrivate();
|
2024-05-03 17:10:59 +08:00
|
|
|
|
else
|
|
|
|
|
room.Status.Value = new RoomStatusOpen();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 16:26:42 +08:00
|
|
|
|
protected override string Target => "rooms";
|
2018-12-22 11:50:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|