1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 11:42:56 +08:00

Make server authoritative in which mods the client should be using when gameplay starts

This commit is contained in:
Dean Herbert 2021-02-11 15:55:08 +09:00
parent 3344e9f27f
commit 21f66a19fd
2 changed files with 29 additions and 4 deletions

View File

@ -78,7 +78,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
managerUpdated = beatmapManager.ItemUpdated.GetBoundCopy();
managerUpdated.BindValueChanged(beatmapUpdated);
UserMods.BindValueChanged(_ => updateMods());
UserMods.BindValueChanged(_ => UpdateMods());
}
public override void OnEntering(IScreen last)
@ -97,7 +97,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
{
base.OnResuming(last);
beginHandlingTrack();
updateMods();
UpdateMods();
}
public override bool OnExiting(IScreen next)
@ -128,7 +128,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
.Where(m => SelectedItem.Value.AllowedMods.Any(a => m.GetType() == a.GetType()))
.ToList();
updateMods();
UpdateMods();
Ruleset.Value = SelectedItem.Value.Ruleset.Value;
}
@ -145,7 +145,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
}
private void updateMods()
protected virtual void UpdateMods()
{
if (SelectedItem.Value == null)
return;

View File

@ -271,6 +271,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
UserMods.BindValueChanged(onUserModsChanged);
client.LoadRequested += onLoadRequested;
client.RoomUpdated += onRoomUpdated;
isConnected = client.IsConnected.GetBoundCopy();
isConnected.BindValueChanged(connected =>
@ -367,6 +368,27 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
}
}
private void onRoomUpdated()
{
UpdateMods(); // user mods may have changed.
}
protected override void UpdateMods()
{
if (SelectedItem.Value == null || client.LocalUser == null)
return;
// update local mods based on room's reported status for the local user (omitting the base call implementation).
// this makes the server authoritative, and avoids the local user potentially settings mods that the server is not aware of (ie. if the match was started during the selection being changed).
var localUserMods = client.LocalUser.Mods.ToList();
Schedule(() =>
{
var ruleset = Ruleset.Value.CreateInstance();
Mods.Value = localUserMods.Select(m => m.ToMod(ruleset)).Concat(SelectedItem.Value.RequiredMods).ToList();
});
}
private void onLoadRequested()
{
Debug.Assert(client.Room != null);
@ -384,7 +406,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
base.Dispose(isDisposing);
if (client != null)
{
client.RoomUpdated -= onRoomUpdated;
client.LoadRequested -= onLoadRequested;
}
}
private class UserModSelectOverlay : LocalPlayerModSelectOverlay