Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiplayer option to disable score multiplier #167

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public async Task OneNonExpiredItemExistsWhenChangingToHostOnlyMode()
}

[Fact]
public async Task UserMayOnlyAddLimitedNumberOfItems()
public async Task HostMayAddManyItems()
{
Database.Setup(d => d.GetBeatmapChecksumAsync(3333)).ReturnsAsync("3333");

Expand All @@ -189,29 +189,63 @@ public async Task UserMayOnlyAddLimitedNumberOfItems()
for (int i = 1; i < MultiplayerQueue.PER_USER_LIMIT; i++)
await addItem();

// First user is not allowed to add more items.
await Assert.ThrowsAsync<InvalidStateException>(addItem);
// Host should be allowed to add many items even in non-host-only queue modes.
await addItem();
await addItem();
await addItem();

async Task addItem() => await Hub.AddPlaylistItem(new MultiplayerPlaylistItem
{
BeatmapID = 3333,
BeatmapChecksum = "3333"
});
}

[Fact]
public async Task UserMayOnlyAddLimitedNumberOfItems()
{
Database.Setup(d => d.GetBeatmapChecksumAsync(3333)).ReturnsAsync("3333");

await Hub.JoinRoom(ROOM_ID);
await Hub.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers });

// Play initial beatmap to clear the queue.
await playBeatmap();

// Second user should be able to add items.
SetUserContext(ContextUser2);
await Hub.JoinRoom(ROOM_ID);
await addItem();

// Non-host user should be able to add items up to a defined limit.
for (int i = 0; i < MultiplayerQueue.PER_USER_LIMIT; i++)
await addItem();

// User is not allowed to add more items.
await Assert.ThrowsAsync<InvalidStateException>(addItem);

// Play a single map from the first user.
SetUserContext(ContextUser);
await Hub.ChangeState(MultiplayerUserState.Ready);
await Hub.StartMatch();
await LoadAndFinishGameplay(ContextUser);
await Hub.ChangeState(MultiplayerUserState.Idle);
await playBeatmap();

// User should now be able to add one more item.
SetUserContext(ContextUser2);

// The first user should now be able to add another item.
await addItem();
await Assert.ThrowsAsync<InvalidStateException>(addItem);

async Task addItem() => await Hub.AddPlaylistItem(new MultiplayerPlaylistItem
{
BeatmapID = 3333,
BeatmapChecksum = "3333"
});

async Task playBeatmap()
{
SetUserContext(ContextUser);

await Hub.ChangeState(MultiplayerUserState.Ready);
await Hub.StartMatch();
await LoadAndFinishGameplay(ContextUser);
await Hub.ChangeState(MultiplayerUserState.Idle);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void Configure(JwtBearerOptions options)
};
}

public void Configure(string name, JwtBearerOptions options)
public void Configure(string? name, JwtBearerOptions options)
=> Configure(options);

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions osu.Server.Spectator/Database/Models/multiplayer_room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ public class multiplayer_room
public database_queue_mode queue_mode { get; set; }
public ushort auto_start_duration { get; set; }
public bool auto_skip { get; set; }
public bool no_score_multiplier { get; set; }
}
}
3 changes: 2 additions & 1 deletion osu.Server.Spectator/Hubs/MultiplayerHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ private async Task<ServerMultiplayerRoom> retrieveRoom(long roomId)
MatchType = databaseRoom.type.ToMatchType(),
QueueMode = databaseRoom.queue_mode.ToQueueMode(),
AutoStartDuration = TimeSpan.FromSeconds(databaseRoom.auto_start_duration),
AutoSkip = databaseRoom.auto_skip
AutoSkip = databaseRoom.auto_skip,
NoScoreMultiplier = databaseRoom.no_score_multiplier
}
};

Expand Down
17 changes: 8 additions & 9 deletions osu.Server.Spectator/Hubs/MultiplayerQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,15 @@ public async Task AddItem(MultiplayerPlaylistItem item, MultiplayerRoomUser user

bool isHostOnly = room.Settings.QueueMode == QueueMode.HostOnly;

if (isHostOnly)
{
if (!user.Equals(room.Host))
throw new NotHostException();
bool isHost = user.Equals(room.Host);

if (room.Playlist.Count(i => i.OwnerID == user.UserID && !i.Expired) >= HOST_LIMIT)
throw new InvalidStateException($"Can't enqueue more than {HOST_LIMIT} items at once.");
}
else if (room.Playlist.Count(i => i.OwnerID == user.UserID && !i.Expired) >= PER_USER_LIMIT)
throw new InvalidStateException($"Can't enqueue more than {PER_USER_LIMIT} items at once.");
if (isHostOnly && !isHost)
throw new NotHostException();

int limit = isHost ? HOST_LIMIT : PER_USER_LIMIT;

if (room.Playlist.Count(i => i.OwnerID == user.UserID && !i.Expired) >= limit)
throw new InvalidStateException($"Can't enqueue more than {limit} items at once.");

using (var db = dbFactory.GetInstance())
{
Expand Down
8 changes: 6 additions & 2 deletions osu.Server.Spectator/StartupDevelopment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ public LocalAuthenticationHandler(
/// </summary>
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
{
if (!Context.Request.Headers.TryGetValue("user_id", out var userIdString))
userIdString = Interlocked.Increment(ref userIDCounter).ToString();
string? userIdString = null;

if (Context.Request.Headers.TryGetValue("user_id", out var userIdValue))
userIdString = userIdValue;

userIdString ??= Interlocked.Increment(ref userIDCounter).ToString();

var claim = new Claim(ClaimTypes.NameIdentifier, userIdString);

Expand Down
2 changes: 1 addition & 1 deletion osu.Server.Spectator/osu.Server.Spectator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="AWSSDK.S3" Version="3.7.103.36" />
<PackageReference Include="BouncyCastle.NetCore" Version="1.9.0" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.2.1" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="DogStatsD-CSharp-Client" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.4" />
Expand Down