Ejemplo n.º 1
0
        Task IMultiplayerClient.UserBeatmapAvailabilityChanged(int userId, BeatmapAvailability beatmapAvailability)
        {
            if (Room == null)
            {
                return(Task.CompletedTask);
            }

            Scheduler.Add(() =>
            {
                var user = Room?.Users.SingleOrDefault(u => u.UserID == userId);

                // errors here are not critical - beatmap availability state is mostly for display.
                if (user == null)
                {
                    return;
                }

                user.BeatmapAvailability = beatmapAvailability;

                RoomUpdated?.Invoke();
            }, false);

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        public Task UserModsChanged(int userId, IEnumerable <APIMod> mods)
        {
            if (Room == null)
            {
                return(Task.CompletedTask);
            }

            Scheduler.Add(() =>
            {
                var user = Room?.Users.SingleOrDefault(u => u.UserID == userId);

                // errors here are not critical - user mods are mostly for display.
                if (user == null)
                {
                    return;
                }

                user.Mods = mods;

                RoomUpdated?.Invoke();
            }, false);

            return(Task.CompletedTask);
        }
Ejemplo n.º 3
0
        public Task LeaveRoom()
        {
            // The join may have not completed yet, so certain tasks that either update the room or reference the room should be cancelled.
            // This includes the setting of Room itself along with the initial update of the room settings on join.
            joinCancellationSource?.Cancel();

            // Leaving rooms is expected to occur instantaneously whilst the operation is finalised in the background.
            // However a few members need to be reset immediately to prevent other components from entering invalid states whilst the operation hasn't yet completed.
            // For example, if a room was left and the user immediately pressed the "create room" button, then the user could be taken into the lobby if the value of Room is not reset in time.
            var scheduledReset = scheduleAsync(() =>
            {
                apiRoom = null;
                Room    = null;
                CurrentMatchPlayingUserIds.Clear();

                RoomUpdated?.Invoke();
            });

            return(joinOrLeaveTaskChain.Add(async() =>
            {
                await scheduledReset;
                await LeaveRoomInternal();
            }));
        }