Merge pull request #13853 from frenzibyte/disallow-custom-ruleset-score-submission

Disallow custom rulesets from attempting to submit scores
This commit is contained in:
Dean Herbert 2021-07-11 15:21:38 +09:00 committed by GitHub
commit e0b2356bb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 21 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Screens; using osu.Framework.Screens;
@ -10,6 +11,7 @@ using osu.Game.Online.Rooms;
using osu.Game.Online.Solo; using osu.Game.Online.Solo;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Judgements; using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Ranking; using osu.Game.Screens.Ranking;
@ -17,17 +19,26 @@ using osu.Game.Tests.Beatmaps;
namespace osu.Game.Tests.Visual.Gameplay namespace osu.Game.Tests.Visual.Gameplay
{ {
public class TestScenePlayerScoreSubmission : OsuPlayerTestScene public class TestScenePlayerScoreSubmission : PlayerTestScene
{ {
protected override bool AllowFail => allowFail; protected override bool AllowFail => allowFail;
private bool allowFail; private bool allowFail;
private Func<RulesetInfo, IBeatmap> createCustomBeatmap;
private Func<Ruleset> createCustomRuleset;
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API; private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
protected override bool HasCustomSteps => true; protected override bool HasCustomSteps => true;
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) protected override TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false);
protected override Ruleset CreatePlayerRuleset() => createCustomRuleset?.Invoke() ?? new OsuRuleset();
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => createCustomBeatmap?.Invoke(ruleset) ?? createTestBeatmap(ruleset);
private IBeatmap createTestBeatmap(RulesetInfo ruleset)
{ {
var beatmap = (TestBeatmap)base.CreateBeatmap(ruleset); var beatmap = (TestBeatmap)base.CreateBeatmap(ruleset);
@ -36,14 +47,12 @@ namespace osu.Game.Tests.Visual.Gameplay
return beatmap; return beatmap;
} }
protected override TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false);
[Test] [Test]
public void TestNoSubmissionOnResultsWithNoToken() public void TestNoSubmissionOnResultsWithNoToken()
{ {
prepareTokenResponse(false); prepareTokenResponse(false);
CreateTest(() => allowFail = false); createPlayerTest();
AddUntilStep("wait for token request", () => Player.TokenCreationRequested); AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
@ -63,7 +72,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
prepareTokenResponse(true); prepareTokenResponse(true);
CreateTest(() => allowFail = false); createPlayerTest();
AddUntilStep("wait for token request", () => Player.TokenCreationRequested); AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
@ -82,7 +91,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
prepareTokenResponse(false); prepareTokenResponse(false);
CreateTest(() => allowFail = false); createPlayerTest();
AddUntilStep("wait for token request", () => Player.TokenCreationRequested); AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
@ -99,7 +108,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
prepareTokenResponse(true); prepareTokenResponse(true);
CreateTest(() => allowFail = true); createPlayerTest(true);
AddUntilStep("wait for token request", () => Player.TokenCreationRequested); AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
@ -114,7 +123,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
prepareTokenResponse(true); prepareTokenResponse(true);
CreateTest(() => allowFail = true); createPlayerTest(true);
AddUntilStep("wait for token request", () => Player.TokenCreationRequested); AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
@ -131,7 +140,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
prepareTokenResponse(true); prepareTokenResponse(true);
CreateTest(() => allowFail = false); createPlayerTest();
AddUntilStep("wait for token request", () => Player.TokenCreationRequested); AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
@ -144,7 +153,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
prepareTokenResponse(true); prepareTokenResponse(true);
CreateTest(() => allowFail = false); createPlayerTest();
AddUntilStep("wait for token request", () => Player.TokenCreationRequested); AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
@ -154,18 +163,49 @@ namespace osu.Game.Tests.Visual.Gameplay
AddAssert("ensure failing submission", () => Player.SubmittedScore?.ScoreInfo.Passed == false); AddAssert("ensure failing submission", () => Player.SubmittedScore?.ScoreInfo.Passed == false);
} }
private void addFakeHit() [Test]
public void TestNoSubmissionOnLocalBeatmap()
{ {
AddUntilStep("wait for first result", () => Player.Results.Count > 0); prepareTokenResponse(true);
AddStep("force successfuly hit", () => createPlayerTest(false, r =>
{ {
Player.ScoreProcessor.RevertResult(Player.Results.First()); var beatmap = createTestBeatmap(r);
Player.ScoreProcessor.ApplyResult(new OsuJudgementResult(Beatmap.Value.Beatmap.HitObjects.First(), new OsuJudgement()) beatmap.BeatmapInfo.OnlineBeatmapID = null;
return beatmap;
});
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
addFakeHit();
AddStep("exit", () => Player.Exit());
AddAssert("ensure no submission", () => Player.SubmittedScore == null);
}
[Test]
public void TestNoSubmissionOnCustomRuleset()
{ {
Type = HitResult.Great, prepareTokenResponse(true);
});
}); createPlayerTest(false, createRuleset: () => new OsuRuleset { RulesetInfo = { ID = 10 } });
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
addFakeHit();
AddStep("exit", () => Player.Exit());
AddAssert("ensure no submission", () => Player.SubmittedScore == null);
}
private void createPlayerTest(bool allowFail = false, Func<RulesetInfo, IBeatmap> createBeatmap = null, Func<Ruleset> createRuleset = null)
{
CreateTest(() => AddStep("set up requirements", () =>
{
this.allowFail = allowFail;
createCustomBeatmap = createBeatmap;
createCustomRuleset = createRuleset;
}));
} }
private void prepareTokenResponse(bool validToken) private void prepareTokenResponse(bool validToken)
@ -188,5 +228,19 @@ namespace osu.Game.Tests.Visual.Gameplay
}; };
}); });
} }
private void addFakeHit()
{
AddUntilStep("wait for first result", () => Player.Results.Count > 0);
AddStep("force successfuly hit", () =>
{
Player.ScoreProcessor.RevertResult(Player.Results.First());
Player.ScoreProcessor.ApplyResult(new OsuJudgementResult(Beatmap.Value.Beatmap.HitObjects.First(), new OsuJudgement())
{
Type = HitResult.Great,
});
});
}
} }
} }

View File

@ -6,6 +6,7 @@ using System.Diagnostics;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Online.Solo; using osu.Game.Online.Solo;
using osu.Game.Rulesets;
using osu.Game.Scoring; using osu.Game.Scoring;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
@ -27,7 +28,7 @@ namespace osu.Game.Screens.Play
if (!(Beatmap.Value.BeatmapInfo.OnlineBeatmapID is int beatmapId)) if (!(Beatmap.Value.BeatmapInfo.OnlineBeatmapID is int beatmapId))
return null; return null;
if (!(Ruleset.Value.ID is int rulesetId)) if (!(Ruleset.Value.ID is int rulesetId) || Ruleset.Value.ID > ILegacyRuleset.MAX_LEGACY_RULESET_ID)
return null; return null;
return new CreateSoloScoreRequest(beatmapId, rulesetId, Game.VersionHash); return new CreateSoloScoreRequest(beatmapId, rulesetId, Game.VersionHash);

View File

@ -57,7 +57,9 @@ namespace osu.Game.Tests.Visual
protected void LoadPlayer() protected void LoadPlayer()
{ {
var ruleset = Ruleset.Value.CreateInstance(); var ruleset = CreatePlayerRuleset();
Ruleset.Value = ruleset.RulesetInfo;
var beatmap = CreateBeatmap(ruleset.RulesetInfo); var beatmap = CreateBeatmap(ruleset.RulesetInfo);
Beatmap.Value = CreateWorkingBeatmap(beatmap); Beatmap.Value = CreateWorkingBeatmap(beatmap);