Skip to content

Commit fd759f7

Browse files
authored
Merge pull request #47 from bdach/wrong-cs-limits
2 parents e138fa1 + 0c9fe12 commit fd759f7

File tree

3 files changed

+100
-7
lines changed

3 files changed

+100
-7
lines changed

osu.Server.BeatmapSubmission.Tests/BeatmapSubmissionControllerTest.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,75 @@ public async Task TestPatchPackage_FailsIfCreatorDoesNotMatchHostUsername()
15721572
Assert.Contains("At least one difficulty has a specified creator that isn't the beatmap host's username.", (await response.Content.ReadFromJsonAsync<ErrorResponse>())!.Error);
15731573
}
15741574

1575+
[Theory]
1576+
[InlineData(0, 0.3, true)]
1577+
[InlineData(0, 10, true)]
1578+
[InlineData(3, 2, true)]
1579+
[InlineData(3, 7.5, false)]
1580+
[InlineData(3, 18, true)]
1581+
public async Task TestPatchPackage_FailsOnIncorrectCircleSize(short playmode, float circleSize, bool shouldSucceed)
1582+
{
1583+
using var db = await DatabaseAccess.GetConnectionAsync();
1584+
await db.ExecuteAsync("INSERT INTO `phpbb_users` (`user_id`, `username`, `username_clean`, `country_acronym`, `user_permissions`, `user_sig`, `user_occ`, `user_interests`) VALUES (1000, 'test', 'test', 'JP', '', '', '', '')");
1585+
1586+
await db.ExecuteAsync(@"INSERT INTO `osu_beatmapsets` (`beatmapset_id`, `user_id`, `creator`, `approved`, `thread_id`, `active`, `submit_date`) VALUES (241526, 1000, 'test user', -1, 0, -1, CURRENT_TIMESTAMP)");
1587+
1588+
foreach (uint beatmapId in new uint[] { 557815, 557814, 557821, 557816, 557817, 557818, 557812, 557810, 557811, 557820, 557813, 557819 })
1589+
await db.ExecuteAsync(@"INSERT INTO `osu_beatmaps` (`beatmap_id`, `user_id`, `beatmapset_id`, `approved`) VALUES (@beatmapId, 1000, 241526, -1)", new { beatmapId = beatmapId });
1590+
1591+
using (var dstStream = File.OpenWrite(Path.Combine(beatmapStorage.BaseDirectory, "241526")))
1592+
using (var srcStream = TestResources.GetResource(osz_filename)!)
1593+
await srcStream.CopyToAsync(dstStream);
1594+
await db.ExecuteAsync(@"INSERT INTO `beatmapset_versions` (`beatmapset_id`) VALUES (241526)");
1595+
1596+
var request = new HttpRequestMessage(HttpMethod.Patch, "/beatmapsets/241526");
1597+
1598+
using var content = new MultipartFormDataContent($"{Guid.NewGuid()}----");
1599+
content.Add(new StringContent(
1600+
$"""
1601+
osu file format v14
1602+
1603+
[General]
1604+
Mode:{playmode}
1605+
1606+
[Metadata]
1607+
Title:Renatus
1608+
TitleUnicode:Renatus
1609+
Artist:Soleily
1610+
ArtistUnicode:Soleily
1611+
Creator:test
1612+
Version:Platter 2
1613+
Source:
1614+
Tags:MBC7 Unisphere 地球ヤバイEP Chikyu Yabai
1615+
BeatmapID:557810
1616+
BeatmapSetID:241526
1617+
1618+
[Difficulty]
1619+
HPDrainRate:5
1620+
CircleSize:{circleSize}
1621+
OverallDifficulty:8
1622+
ApproachRate:8
1623+
SliderMultiplier:1.75
1624+
SliderTickRate:2
1625+
"""
1626+
), "filesChanged", osu_filename);
1627+
content.Add(new StringContent("Soleily - Renatus (test) [Platter].osu"), "filesDeleted");
1628+
request.Content = content;
1629+
request.Headers.Add(HeaderBasedAuthenticationHandler.USER_ID_HEADER, "1000");
1630+
1631+
var response = await Client.SendAsync(request);
1632+
1633+
if (shouldSucceed)
1634+
Assert.True(response.IsSuccessStatusCode);
1635+
else
1636+
{
1637+
Assert.False(response.IsSuccessStatusCode);
1638+
1639+
Assert.Contains(playmode == 3 ? "The key count of the beatmap is invalid." : "The circle size of the beatmap is out of range.",
1640+
(await response.Content.ReadFromJsonAsync<ErrorResponse>())!.Error);
1641+
}
1642+
}
1643+
15751644
[Fact]
15761645
public async Task TestSubmitGuestDifficulty_OldStyle()
15771646
{

osu.Server.BeatmapSubmission/Models/Database/osu_beatmap.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
using System.ComponentModel.DataAnnotations;
77
using osu.Game.Beatmaps;
8+
using osu.Game.Beatmaps.Formats;
89
using osu.Server.BeatmapSubmission.Models.Database.Validation;
910

1011
namespace osu.Server.BeatmapSubmission.Models.Database
1112
{
12-
public class osu_beatmap
13+
public class osu_beatmap : IValidatableObject
1314
{
1415
public uint beatmap_id { get; set; }
1516
public uint? beatmapset_id { get; set; }
@@ -45,7 +46,6 @@ public class osu_beatmap
4546
[Range(0.0, 10.0, ErrorMessage = "The drain rate of the beatmap is out of range.")]
4647
public float diff_drain { get; set; }
4748

48-
[Range(1.0, 18.0, ErrorMessage = "The circle size / key count of the beatmap is out of range.")]
4949
public float diff_size { get; set; }
5050

5151
[Range(0.0, 10.0, ErrorMessage = "The overall difficulty of the beatmap is out of range.")]
@@ -69,5 +69,29 @@ public class osu_beatmap
6969
// deleted_at skipped on purpose
7070

7171
public float bpm { get; set; }
72+
73+
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
74+
{
75+
switch (playmode)
76+
{
77+
case 0:
78+
case 1:
79+
case 2:
80+
{
81+
if (diff_size < 0 || diff_size > 10)
82+
yield return new ValidationResult("The circle size of the beatmap is out of range.");
83+
84+
break;
85+
}
86+
87+
case 3:
88+
{
89+
if (diff_size != (int)diff_size || diff_size < 1 || diff_size > LegacyBeatmapDecoder.MAX_MANIA_KEY_COUNT)
90+
yield return new ValidationResult("The key count of the beatmap is invalid.");
91+
92+
break;
93+
}
94+
}
95+
}
7296
}
7397
}

osu.Server.BeatmapSubmission/osu.Server.BeatmapSubmission.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
<PackageReference Include="DogStatsD-CSharp-Client" Version="8.0.0" />
2020
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" />
2121
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10"/>
22-
<PackageReference Include="ppy.osu.Game" Version="2025.304.0" />
23-
<PackageReference Include="ppy.osu.Game.Rulesets.Catch" Version="2025.304.0" />
24-
<PackageReference Include="ppy.osu.Game.Rulesets.Mania" Version="2025.304.0" />
25-
<PackageReference Include="ppy.osu.Game.Rulesets.Osu" Version="2025.304.0" />
26-
<PackageReference Include="ppy.osu.Game.Rulesets.Taiko" Version="2025.304.0" />
22+
<PackageReference Include="ppy.osu.Game" Version="2025.420.0" />
23+
<PackageReference Include="ppy.osu.Game.Rulesets.Catch" Version="2025.420.0" />
24+
<PackageReference Include="ppy.osu.Game.Rulesets.Mania" Version="2025.420.0" />
25+
<PackageReference Include="ppy.osu.Game.Rulesets.Osu" Version="2025.420.0" />
26+
<PackageReference Include="ppy.osu.Game.Rulesets.Taiko" Version="2025.420.0" />
2727
<PackageReference Include="ppy.osu.Server.OsuQueueProcessor" Version="2024.1111.0" />
2828
<PackageReference Include="Sentry.AspNetCore" Version="5.2.0" />
2929
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.3.1" />

0 commit comments

Comments
 (0)