1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 14:52:55 +08:00
osu-lazer/osu.Game/Online/Rooms/GetRoomsRequest.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.8 KiB
C#
Raw Normal View History

// 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.
using System;
using System.Collections.Generic;
using osu.Framework.IO.Network;
using osu.Game.Extensions;
using osu.Game.Online.API;
using osu.Game.Online.Rooms.RoomStatuses;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
2020-12-25 12:38:11 +08:00
namespace osu.Game.Online.Rooms
{
public class GetRoomsRequest : APIRequest<List<Room>>
{
2020-12-07 20:59:38 +08:00
private readonly RoomStatusFilter status;
private readonly string category;
2020-12-07 20:59:38 +08:00
public GetRoomsRequest(RoomStatusFilter status, string category)
{
2020-12-07 20:59:38 +08:00
this.status = status;
this.category = category;
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
2019-04-01 11:44:46 +08:00
2020-12-07 20:59:38 +08:00
if (status != RoomStatusFilter.Open)
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);
return req;
}
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();
else if (room.HasPassword.Value)
room.Status.Value = new RoomStatusOpenPrivate();
else
room.Status.Value = new RoomStatusOpen();
}
}
}
protected override string Target => "rooms";
}
}