Skip to content

Commit 2850d90

Browse files
authored
Allow argument of roll referee hub operation to be nullable (#461)
* Make `RefereeHub` inherit `LoggingHub` Mostly because I'm starting to look at sentry issues from the referee hub and noticing that they're missing the user ID which is useful information, and in other hubs it is supplied by `LoggingHub` and its related hub filter. It'll also add some datadog monitoring which may come in useful going forward as well. Not sure why I never did this. I think I convinced myself that the generics didn't work in my usage because of it being tied to `StatefulUserHub`, but on closer inspection, no, that's not the case. * Allow argument of `Roll` referee hub operation to be nullable Spotted via #459. I reproduced this by calling `Roll(roomId, null)` from a JS client. You could argue that the user was at fault here for passing `null` rather than `{}` or something, but you could also argue that there's no reason not to make this work with a nullable for user convenience. While I'm not clairvoyant I can't see a future where rolling has a required parameter in it either.
1 parent 7bab117 commit 2850d90

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

osu.Server.Spectator/Hubs/Referee/IRefereeHubServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public interface IRefereeHubServer
141141
/// Initiates a random roll in the room.
142142
/// Corresponds to the <c>!roll</c> command on bancho.
143143
/// </summary>
144-
Task Roll(long roomId, RollRequest request);
144+
Task Roll(long roomId, RollRequest? request);
145145

146146
/// <summary>
147147
/// Moves the user to a different team in the given <paramref name="roomId"/>.

osu.Server.Spectator/Hubs/Referee/RefereeHub.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Linq;
88
using System.Threading.Tasks;
99
using Microsoft.AspNetCore.Authorization;
10-
using Microsoft.AspNetCore.SignalR;
1110
using Microsoft.Extensions.Logging;
1211
using osu.Game.Online.API.Requests.Responses;
1312
using osu.Game.Online.Multiplayer;
@@ -29,11 +28,10 @@
2928
namespace osu.Server.Spectator.Hubs.Referee
3029
{
3130
[Authorize(ConfigureJwtBearerOptions.REFEREE_CLIENT_SCHEME)]
32-
public class RefereeHub : Hub, IRefereeHubServer
31+
public class RefereeHub : LoggingHub<IRefereeHubClient>, IRefereeHubServer
3332
{
3433
private readonly IDatabaseFactory databaseFactory;
3534
private readonly ISharedInterop sharedInterop;
36-
private readonly ILogger<RefereeHub> logger;
3735
private readonly IMultiplayerRoomController roomController;
3836
private readonly MultiplayerEventDispatcher eventDispatcher;
3937
private readonly EntityStore<RefereeClientState> refereeStates;
@@ -49,9 +47,9 @@ public RefereeHub(
4947
EntityStore<RefereeClientState> refereeStates,
5048
EntityStore<MultiplayerClientState> playerStates,
5149
ChatFilters chatFilters)
50+
: base(loggerFactory)
5251
{
5352
this.databaseFactory = databaseFactory;
54-
logger = loggerFactory.CreateLogger<RefereeHub>();
5553
this.sharedInterop = sharedInterop;
5654
this.roomController = roomController;
5755
this.eventDispatcher = eventDispatcher;
@@ -76,14 +74,15 @@ public override async Task OnConnectedAsync()
7674
await base.OnConnectedAsync();
7775
}
7876

77+
[Obsolete]
7978
public async Task Ping(string message)
8079
{
8180
string? username;
8281

8382
using (var db = databaseFactory.GetInstance())
8483
username = await db.GetUsernameAsync(Context.GetUserId());
8584

86-
await Clients.Caller.SendAsync(nameof(IRefereeHubClient.Pong), $"Hi {username}! Here's your message back: {message}");
85+
await Clients.Caller.Pong($"Hi {username}! Here's your message back: {message}");
8786
}
8887

8988
public async Task<RoomJoinedResponse> MakeRoom(MakeRoomRequest request)
@@ -632,7 +631,7 @@ private static void ensurePlaylistItemValid(MultiplayerPlaylistItem playlistItem
632631
}
633632
}
634633

635-
public async Task Roll(long roomId, RollRequest request)
634+
public async Task Roll(long roomId, RollRequest? request)
636635
{
637636
using (var userUsage = await refereeStates.GetForUse(Context.GetUserId()))
638637
{
@@ -649,7 +648,7 @@ public async Task Roll(long roomId, RollRequest request)
649648
if (user == null)
650649
ThrowHelper.ThrowUserNotInRoom();
651650

652-
await roomUsage.Item.MatchController.HandleUserRequest(user, new Game.Online.Multiplayer.RollRequest { Max = request.Max });
651+
await roomUsage.Item.MatchController.HandleUserRequest(user, new Game.Online.Multiplayer.RollRequest { Max = request?.Max });
653652
}
654653
}
655654
}
@@ -823,6 +822,6 @@ private static void ensureIsReferee(long roomId, ItemUsage<RefereeClientState> u
823822
}
824823

825824
private void log(string message, ServerMultiplayerRoom? room, LogLevel level = LogLevel.Information)
826-
=> logger.Log(level, "[user:{userId}] [room:{roomId}] {message}", Context.UserIdentifier, room?.RoomID.ToString() ?? "none", message);
825+
=> Log($"[room:{room?.RoomID.ToString() ?? "none"}] {message}", level);
827826
}
828827
}

osu.Server.Spectator/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public void ConfigureServices(IServiceCollection services)
5555
.AddHubOptions<RefereeHub>(options =>
5656
{
5757
options.SupportedProtocols?.Remove("messagepack");
58+
options.AddFilter<LoggingHubFilter>();
5859
});
5960

6061
services.AddHubEntities()

0 commit comments

Comments
 (0)