Exemplo n.º 1
0
        private void updateLocalRoomSettings(MultiplayerRoomSettings settings)
        {
            if (Room == null)
            {
                return;
            }

            Schedule(() =>
            {
                if (Room == null)
                {
                    return;
                }

                Debug.Assert(apiRoom != null);

                // Update a few properties of the room instantaneously.
                Room.Settings      = settings;
                apiRoom.Name.Value = Room.Settings.Name;

                // The playlist update is delayed until an online beatmap lookup (below) succeeds.
                // In-order for the client to not display an outdated beatmap, the playlist is forcefully cleared here.
                apiRoom.Playlist.Clear();

                RoomChanged?.Invoke();

                var req      = new GetBeatmapSetRequest(settings.BeatmapID, BeatmapSetLookupType.BeatmapId);
                req.Success += res => updatePlaylist(settings, res);

                api.Queue(req);
            });
        }
        private Task updateLocalRoomSettings(MultiplayerRoomSettings settings, CancellationToken cancellationToken = default) => scheduleAsync(() =>
        {
            if (Room == null)
            {
                return;
            }

            Debug.Assert(apiRoom != null);

            // Update a few properties of the room instantaneously.
            Room.Settings      = settings;
            apiRoom.Name.Value = Room.Settings.Name;

            // The current item update is delayed until an online beatmap lookup (below) succeeds.
            // In-order for the client to not display an outdated beatmap, the current item is forcefully cleared here.
            CurrentMatchPlayingItem.Value = null;

            RoomUpdated?.Invoke();

            GetOnlineBeatmapSet(settings.BeatmapID, cancellationToken).ContinueWith(set => Schedule(() =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                updatePlaylist(settings, set.Result);
            }), TaskContinuationOptions.OnlyOnRanToCompletion);
        }, cancellationToken);
Exemplo n.º 3
0
        private void updatePlaylist(MultiplayerRoomSettings settings, APIBeatmapSet onlineSet)
        {
            if (Room == null || !Room.Settings.Equals(settings))
            {
                return;
            }

            Debug.Assert(apiRoom != null);

            var beatmapSet = onlineSet.ToBeatmapSet(rulesets);
            var beatmap    = beatmapSet.Beatmaps.Single(b => b.OnlineBeatmapID == settings.BeatmapID);

            beatmap.MD5Hash = settings.BeatmapChecksum;

            var ruleset = rulesets.GetRuleset(settings.RulesetID).CreateInstance();
            var mods    = settings.Mods.Select(m => m.ToMod(ruleset));

            PlaylistItem playlistItem = new PlaylistItem
            {
                ID      = playlistItemId,
                Beatmap = { Value = beatmap },
                Ruleset = { Value = ruleset.RulesetInfo },
            };

            playlistItem.RequiredMods.AddRange(mods);

            apiRoom.Playlist.Clear(); // Clearing should be unnecessary, but here for sanity.
            apiRoom.Playlist.Add(playlistItem);
        }
Exemplo n.º 4
0
        private Task updateLocalRoomSettings(MultiplayerRoomSettings settings, CancellationToken cancellationToken = default) => scheduleAsync(() =>
        {
            if (Room == null)
            {
                return;
            }

            Debug.Assert(apiRoom != null);

            // Update a few properties of the room instantaneously.
            Room.Settings      = settings;
            apiRoom.Name.Value = Room.Settings.Name;

            // The current item update is delayed until an online beatmap lookup (below) succeeds.
            // In-order for the client to not display an outdated beatmap, the current item is forcefully cleared here.
            CurrentMatchPlayingItem.Value = null;

            RoomUpdated?.Invoke();

            var req      = new GetBeatmapSetRequest(settings.BeatmapID, BeatmapSetLookupType.BeatmapId);
            req.Success += res =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                updatePlaylist(settings, res);
            };

            api.Queue(req);
        }, cancellationToken);
Exemplo n.º 5
0
        Task IMultiplayerClient.SettingsChanged(MultiplayerRoomSettings newSettings)
        {
            Debug.Assert(APIRoom != null);
            Debug.Assert(Room != null);

            Scheduler.Add(() =>
            {
                // ensure the new selected item is populated immediately.
                var playlistItem = APIRoom.Playlist.Single(p => p.ID == newSettings.PlaylistItemId);

                if (playlistItem != null)
                {
                    GetAPIBeatmap(playlistItem.BeatmapID).ContinueWith(b =>
                    {
                        // Should be called outside of the `Scheduler` logic (and specifically accessing `Exception`) to suppress an exception from firing outwards.
                        bool success = b.Exception == null;

                        Scheduler.Add(() =>
                        {
                            if (success)
                            {
                                playlistItem.Beatmap.Value = b.Result;
                            }

                            updateLocalRoomSettings(newSettings);
                        });
                    });
                }
            });

            return(Task.CompletedTask);
        }
Exemplo n.º 6
0
        public override Task ChangeSettings(MultiplayerRoomSettings settings)
        {
            if (!isConnected.Value)
            {
                return(Task.CompletedTask);
            }

            return(connection.InvokeAsync(nameof(IMultiplayerServer.ChangeSettings), settings));
        }
Exemplo n.º 7
0
        Task IMultiplayerClient.SettingsChanged(MultiplayerRoomSettings newSettings)
        {
            Debug.Assert(APIRoom != null);
            Debug.Assert(Room != null);

            Scheduler.Add(() => updateLocalRoomSettings(newSettings));

            return(Task.CompletedTask);
        }
Exemplo n.º 8
0
        private void updatePlaylist(MultiplayerRoomSettings settings, APIBeatmapSet onlineSet)
        {
            if (Room == null || !Room.Settings.Equals(settings))
            {
                return;
            }

            Debug.Assert(apiRoom != null);

            var beatmapSet = onlineSet.ToBeatmapSet(rulesets);
            var beatmap    = beatmapSet.Beatmaps.Single(b => b.OnlineBeatmapID == settings.BeatmapID);

            beatmap.MD5Hash = settings.BeatmapChecksum;

            var ruleset     = rulesets.GetRuleset(settings.RulesetID).CreateInstance();
            var mods        = settings.RequiredMods.Select(m => m.ToMod(ruleset));
            var allowedMods = settings.AllowedMods.Select(m => m.ToMod(ruleset));

            // Try to retrieve the existing playlist item from the API room.
            var playlistItem = apiRoom.Playlist.FirstOrDefault(i => i.ID == settings.PlaylistItemId);

            if (playlistItem != null)
            {
                updateItem(playlistItem);
            }
            else
            {
                // An existing playlist item does not exist, so append a new one.
                updateItem(playlistItem = new PlaylistItem());
                apiRoom.Playlist.Add(playlistItem);
            }

            CurrentMatchPlayingItem.Value = playlistItem;

            void updateItem(PlaylistItem item)
            {
                item.ID            = settings.PlaylistItemId == 0 ? defaultPlaylistItemId : settings.PlaylistItemId;
                item.Beatmap.Value = beatmap;
                item.Ruleset.Value = ruleset.RulesetInfo;
                item.RequiredMods.Clear();
                item.RequiredMods.AddRange(mods);
                item.AllowedMods.Clear();
                item.AllowedMods.AddRange(allowedMods);
            }
        }
Exemplo n.º 9
0
        private void updateLocalRoomSettings(MultiplayerRoomSettings settings)
        {
            if (Room == null)
            {
                return;
            }

            Debug.Assert(APIRoom != null);

            // Update a few properties of the room instantaneously.
            Room.Settings           = settings;
            APIRoom.Name.Value      = Room.Settings.Name;
            APIRoom.Password.Value  = Room.Settings.Password;
            APIRoom.QueueMode.Value = Room.Settings.QueueMode;
            RoomUpdated?.Invoke();

            CurrentMatchPlayingItem.Value = APIRoom.Playlist.SingleOrDefault(p => p.ID == settings.PlaylistItemId);
        }
Exemplo n.º 10
0
        private void updateLocalRoomSettings(MultiplayerRoomSettings settings)
        {
            if (Room == null)
            {
                return;
            }

            Debug.Assert(APIRoom != null);

            // Update a few properties of the room instantaneously.
            Room.Settings           = settings;
            APIRoom.Name.Value      = Room.Settings.Name;
            APIRoom.Password.Value  = Room.Settings.Password;
            APIRoom.Type.Value      = Room.Settings.MatchType;
            APIRoom.QueueMode.Value = Room.Settings.QueueMode;

            RoomUpdated?.Invoke();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Updates the local room settings with the given <see cref="MultiplayerRoomSettings"/>.
        /// </summary>
        /// <remarks>
        /// This updates both the joined <see cref="MultiplayerRoom"/> and the respective API <see cref="Room"/>.
        /// </remarks>
        /// <param name="settings">The new <see cref="MultiplayerRoomSettings"/> to update from.</param>
        private void updateLocalRoomSettings(MultiplayerRoomSettings settings)
        {
            if (Room == null)
            {
                return;
            }

            Debug.Assert(APIRoom != null);

            // Update a few properties of the room instantaneously.
            Room.Settings                     = settings;
            APIRoom.Name.Value                = Room.Settings.Name;
            APIRoom.Password.Value            = Room.Settings.Password;
            APIRoom.Type.Value                = Room.Settings.MatchType;
            APIRoom.QueueMode.Value           = Room.Settings.QueueMode;
            APIRoom.AutoStartDuration.Value   = Room.Settings.AutoStartDuration;
            APIRoom.CurrentPlaylistItem.Value = APIRoom.Playlist.Single(item => item.ID == settings.PlaylistItemId);

            RoomUpdated?.Invoke();
        }
Exemplo n.º 12
0
        private Task updateLocalRoomSettings(MultiplayerRoomSettings settings, CancellationToken cancellationToken = default) => scheduleAsync(() =>
        {
            if (Room == null)
            {
                return;
            }

            Debug.Assert(APIRoom != null);

            // Update a few properties of the room instantaneously.
            Room.Settings          = settings;
            APIRoom.Name.Value     = Room.Settings.Name;
            APIRoom.Password.Value = Room.Settings.Password;

            // The current item update is delayed until an online beatmap lookup (below) succeeds.
            // In-order for the client to not display an outdated beatmap, the current item is forcefully cleared here.
            CurrentMatchPlayingItem.Value = null;

            RoomUpdated?.Invoke();

            GetOnlineBeatmapSet(settings.BeatmapID, cancellationToken).ContinueWith(task => Schedule(() =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                APIBeatmapSet beatmapSet = task.Result;

                // The incoming response is deserialised without circular reference handling currently.
                // Because we require using metadata from this instance, populate the nested beatmaps' sets manually here.
                foreach (var b in beatmapSet.Beatmaps)
                {
                    b.BeatmapSet = beatmapSet;
                }

                updatePlaylist(settings, beatmapSet);
            }), TaskContinuationOptions.OnlyOnRanToCompletion);
        }, cancellationToken);
Exemplo n.º 13
0
 Task IMultiplayerClient.SettingsChanged(MultiplayerRoomSettings newSettings)
 {
     Scheduler.Add(() => updateLocalRoomSettings(newSettings));
     return(Task.CompletedTask);
 }
Exemplo n.º 14
0
 public abstract Task ChangeSettings(MultiplayerRoomSettings settings);
 Task IMultiplayerClient.SettingsChanged(MultiplayerRoomSettings newSettings)
 {
     updateLocalRoomSettings(newSettings);
     return(Task.CompletedTask);
 }