public async Task JoinRoom(Room room)
        {
            var cancellationSource = joinCancellationSource = new CancellationTokenSource();

            await joinOrLeaveTaskChain.Add(async() =>
            {
                if (Room != null)
                {
                    throw new InvalidOperationException("Cannot join a multiplayer room while already in one.");
                }

                Debug.Assert(room.RoomID.Value != null);

                // Join the server-side room.
                var joinedRoom = await JoinRoom(room.RoomID.Value.Value).ConfigureAwait(false);
                Debug.Assert(joinedRoom != null);

                // Populate users.
                Debug.Assert(joinedRoom.Users != null);
                await Task.WhenAll(joinedRoom.Users.Select(PopulateUser)).ConfigureAwait(false);

                // Update the stored room (must be done on update thread for thread-safety).
                await scheduleAsync(() =>
                {
                    Room    = joinedRoom;
                    apiRoom = room;
                    defaultPlaylistItemId = apiRoom.Playlist.FirstOrDefault()?.ID ?? 0;
                }, cancellationSource.Token).ConfigureAwait(false);

                // Update room settings.
                await updateLocalRoomSettings(joinedRoom.Settings, cancellationSource.Token).ConfigureAwait(false);
            }, cancellationSource.Token).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        public async Task ReceiveSyncMessage(int roomId, string authToken, VideoSyncMessage videoSyncMessage)
        {
            AuthUser?authUser = await _authService.GetUser(authToken);

            if (authUser == null)
            {
                return;
            }

            User?user = await _userService.CreateOrGetByAuthUser(authUser);

            if (user == null)
            {
                return;
            }

            Room?room = await _roomService.Get(roomId);

            if (room == null || room.CreatedByUserId != user.UserId)
            {
                return;
            }

            await Clients.OthersInGroup(roomId.ToString()).SendAsync("VideoSyncMessage", videoSyncMessage);
        }
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;
                CurrentMatchPlayingItem.Value = null;
                PlayingUserIds.Clear();

                RoomUpdated?.Invoke();
            });

            return(joinOrLeaveTaskChain.Add(async() =>
            {
                await scheduledReset.ConfigureAwait(false);
                await LeaveRoomInternal().ConfigureAwait(false);
            }));
        }
Ejemplo n.º 4
0
        public LevelObjectViewModel(LevelViewModel level, Room?room, LevelObject levelObject)
            : base(LevelEditViewModel.Current.UndoRedo, levelObject)
        {
            Level     = level;
            this.room = room;
            Model     = levelObject;

            DetermineVisuals();
        }
Ejemplo n.º 5
0
        public bool Equals(Room?other)
        {
            if (other == null)
            {
                return(false);
            }

            return(RoomId == other.RoomId);
        }
Ejemplo n.º 6
0
        void ProcessData(MessageReceivedEventArgs e, DarkRiftReader reader, byte[] data, int length)
        {
            Room?room = GetRoomForPlayer(e.Client);

            if (room == null)
            {
                return;
            }

            Room playersRoom = room.Value;

            if (playersRoom.Host == e.Client)
            {
                // If the host sent this message then read the ids the host wants this data to be sent to and send it to them.
                var sendingTo = reader.ReadUInt16s().ToList();
                using (DarkRiftWriter writer = DarkRiftWriter.Create())
                {
                    writer.Write(length);
                    writer.Write(data);
                    using (Message sendDataMessage = Message.Create((ushort)OpCodes.GetData, writer))
                    {
                        for (int i = 0; i < playersRoom.Clients.Count; i++)
                        {
                            if (sendingTo.Contains(playersRoom.Clients[i].ID))
                            {
                                sendingTo.Remove(playersRoom.Clients[i].ID);

                                playersRoom.Clients[i].SendMessage(sendDataMessage, e.SendMode);
                            }
                        }
                    }
                }
            }
            else
            {
                // Else we are a client of this room so send the data to the host
                using (DarkRiftWriter writer = DarkRiftWriter.Create())
                {
                    writer.Write(length);
                    writer.Write(data);
                    writer.Write(e.Client.ID);
                    using (Message sendDataMessage = Message.Create((ushort)OpCodes.GetData, writer))
                    {
                        playersRoom.Host.SendMessage(sendDataMessage, e.SendMode);
                    }
                }
            }

            readBuffers.Return(data, true);
        }
Ejemplo n.º 7
0
        public virtual Task LeaveRoom()
        {
            if (Room == null)
            {
                return(Task.CompletedTask);
            }

            apiRoom = null;
            Room    = null;

            Schedule(() => RoomChanged?.Invoke());

            return(Task.CompletedTask);
        }
Ejemplo n.º 8
0
        private void CreateExit(IMap map)
        {
            Room?exit = null;

            while (exit == null)
            {
                exit = CreateRoom(map, isEntrance: false, isExit: true);
            }
            Debug.Assert(map.Rooms.Any(r => r.IsExit));

            var midPoint = map.GetCellAt(exit.Bounds.Center());

            midPoint.Type = CellType.StairCaseDown;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Joins the <see cref="MultiplayerRoom"/> for a given API <see cref="Room"/>.
        /// </summary>
        /// <param name="room">The API <see cref="Room"/>.</param>
        /// <param name="password">An optional password to use for the join operation.</param>
        public async Task JoinRoom(Room room, string?password = null)
        {
            if (Room != null)
            {
                throw new InvalidOperationException("Cannot join a multiplayer room while already in one.");
            }

            var cancellationSource = joinCancellationSource = new CancellationTokenSource();

            await joinOrLeaveTaskChain.Add(async() =>
            {
                Debug.Assert(room.RoomID.Value != null);

                // Join the server-side room.
                var joinedRoom = await JoinRoom(room.RoomID.Value.Value, password ?? room.Password.Value).ConfigureAwait(false);
                Debug.Assert(joinedRoom != null);

                // Populate users.
                Debug.Assert(joinedRoom.Users != null);
                await Task.WhenAll(joinedRoom.Users.Select(PopulateUser)).ConfigureAwait(false);

                // Update the stored room (must be done on update thread for thread-safety).
                await runOnUpdateThreadAsync(() =>
                {
                    Debug.Assert(Room == null);

                    Room    = joinedRoom;
                    APIRoom = room;

                    Debug.Assert(joinedRoom.Playlist.Count > 0);

                    APIRoom.Playlist.Clear();
                    APIRoom.Playlist.AddRange(joinedRoom.Playlist.Select(createPlaylistItem));
                    APIRoom.CurrentPlaylistItem.Value = APIRoom.Playlist.Single(item => item.ID == joinedRoom.Settings.PlaylistItemId);

                    Debug.Assert(LocalUser != null);
                    addUserToAPIRoom(LocalUser);

                    foreach (var user in joinedRoom.Users)
                    {
                        updateUserPlayingState(user.UserID, user.State);
                    }

                    updateLocalRoomSettings(joinedRoom.Settings);

                    OnRoomJoined();
                }, cancellationSource.Token).ConfigureAwait(false);
            }, cancellationSource.Token).ConfigureAwait(false);
        }
Ejemplo n.º 10
0
        public virtual Task LeaveRoom()
        {
            Scheduler.Add(() =>
            {
                if (Room == null)
                {
                    return;
                }

                apiRoom = null;
                Room    = null;

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

            return(Task.CompletedTask);
        }
Ejemplo n.º 11
0
        public virtual Task LeaveRoom()
        {
            Scheduler.Add(() =>
            {
                if (Room == null)
                {
                    return;
                }

                apiRoom = null;
                Room    = null;
                CurrentMatchPlayingUserIds.Clear();

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

            return(Task.CompletedTask);
        }
Ejemplo n.º 12
0
        public async Task JoinRoom(Room room, string?password = null)
        {
            var cancellationSource = joinCancellationSource = new CancellationTokenSource();

            await joinOrLeaveTaskChain.Add(async() =>
            {
                if (Room != null)
                {
                    throw new InvalidOperationException("Cannot join a multiplayer room while already in one.");
                }

                Debug.Assert(room.RoomID.Value != null);

                // Join the server-side room.
                var joinedRoom = await JoinRoom(room.RoomID.Value.Value, password ?? room.Password.Value).ConfigureAwait(false);
                Debug.Assert(joinedRoom != null);

                // Populate users.
                Debug.Assert(joinedRoom.Users != null);
                await Task.WhenAll(joinedRoom.Users.Select(PopulateUser)).ConfigureAwait(false);

                // Update the stored room (must be done on update thread for thread-safety).
                await scheduleAsync(() =>
                {
                    Room    = joinedRoom;
                    APIRoom = room;

                    Debug.Assert(LocalUser != null);
                    addUserToAPIRoom(LocalUser);

                    foreach (var user in joinedRoom.Users)
                    {
                        updateUserPlayingState(user.UserID, user.State);
                    }

                    OnRoomJoined();
                }, cancellationSource.Token).ConfigureAwait(false);

                // Update room settings.
                await updateLocalRoomSettings(joinedRoom.Settings, cancellationSource.Token).ConfigureAwait(false);
            }, cancellationSource.Token).ConfigureAwait(false);
        }
        protected override async Task <MultiplayerRoom> JoinRoom(long roomId, string?password = null)
        {
            serverSideAPIRoom = roomManager.ServerSideRooms.Single(r => r.RoomID.Value == roomId);

            if (password != serverSideAPIRoom.Password.Value)
            {
                throw new InvalidOperationException("Invalid password.");
            }

            serverSidePlaylist.Clear();
            serverSidePlaylist.AddRange(serverSideAPIRoom.Playlist.Select(item => new MultiplayerPlaylistItem(item)));
            lastPlaylistItemId = serverSidePlaylist.Max(item => item.ID);

            var localUser = new MultiplayerRoomUser(api.LocalUser.Value.Id)
            {
                User = api.LocalUser.Value
            };

            var room = new MultiplayerRoom(roomId)
            {
                Settings =
                {
                    Name              = serverSideAPIRoom.Name.Value,
                    MatchType         = serverSideAPIRoom.Type.Value,
                    Password          = password,
                    QueueMode         = serverSideAPIRoom.QueueMode.Value,
                    AutoStartDuration = serverSideAPIRoom.AutoStartDuration.Value
                },
                Playlist = serverSidePlaylist.ToList(),
                Users    = { localUser },
                Host     = localUser
            };

            await updatePlaylistOrder(room).ConfigureAwait(false);
            await updateCurrentItem(room, false).ConfigureAwait(false);

            RoomSetupAction?.Invoke(room);
            RoomSetupAction = null;

            return(room);
        }
Ejemplo n.º 14
0
        public async Task JoinRoom(Room room)
        {
            if (Room != null)
            {
                throw new InvalidOperationException("Cannot join a multiplayer room while already in one.");
            }

            Debug.Assert(room.RoomID.Value != null);

            apiRoom        = room;
            playlistItemId = room.Playlist.SingleOrDefault()?.ID ?? 0;

            Room = await JoinRoom(room.RoomID.Value.Value);

            Debug.Assert(Room != null);

            var users = getRoomUsers();

            await Task.WhenAll(users.Select(PopulateUser));

            updateLocalRoomSettings(Room.Settings);
        }
Ejemplo n.º 15
0
        IEnumerator JoinOtherRelayAndMatch(Room?roomValue, string ID)
        {
            var room = new Room();

            // using load balancer, we NEED the server's relay address
            if (roomValue.HasValue)
            {
                room = roomValue.Value;
            }
            else
            {
                _serverListUpdated = false;
                RequestServerList();

                yield return(new WaitUntil(() => _serverListUpdated));

                var foundRoom = GetServerForID(ID);

                if (foundRoom.HasValue)
                {
                    room = foundRoom.Value;
                }
                else
                {
                    Debug.LogWarning("LRM | Client tried to join a server that does not exist!");
                    OnClientDisconnected?.Invoke();
                    yield break;
                }
            }

            // Wait for disconnection
            DisconnectFromRelay();

            while (IsAuthenticated())
            {
                yield return(null);
            }

            endpointServerPort = room.relayInfo.endpointPort;
            Connect(room.relayInfo.address, room.relayInfo.port);

            while (!IsAuthenticated())
            {
                yield return(null);
            }

            int pos = 0;

            _directConnected = false;
            _clientSendBuffer.WriteByte(ref pos, (byte)OpCodes.JoinServer);
            _clientSendBuffer.WriteString(ref pos, room.serverId);
            _clientSendBuffer.WriteBool(ref pos, _directConnectModule != null);

            string local = GetLocalIp();

            _clientSendBuffer.WriteString(ref pos, local ?? "0.0.0.0");

            _isClient = true;

            clientToServerTransport.ClientSend(new System.ArraySegment <byte>(_clientSendBuffer, 0, pos), 0);
        }
Ejemplo n.º 16
0
 //---------------------------------------------------
 public RandomEvent(string n, string succeed, string fail, CharacterGroup char1, CharacterGroup char2, Room?rReq, TimeOfDay?tod, Comparison comp1, Comparison comp2, StatEffect[] succEff, StatEffect[] failEff)
 {
     mName = n; succeedString = succeed; failString = fail; mCharacter1 = char1; mCharacter2 = char2; mRoomReq = rReq; mTimeReq = tod; statCheck1 = comp1; statCheck2 = comp2; succeedEffects = succEff; failEffects = failEff;
 }
Ejemplo n.º 17
0
 public bool Equals(Room?other)
 => !ReferenceEquals(null, other) && _id == other._id;
Ejemplo n.º 18
0
 public bool Equals(Room?other) =>
 this == other ||
 (other is not null && TopLeft.Equals(other.TopLeft) && BottomRight.Equals(other.BottomRight));
Ejemplo n.º 19
0
        public Task <List <CheckinRecordModel> > QueryCheckinRecordsAsync(int?workPlanId, DateTimeOffset?date, string?userId, Room?classroom, int beforeId = -1)
        {
            IQueryable <CheckinRecord> records = dbContext.Records;

            if (workPlanId is not null)
            {
                records = records.Where(i => i.WorkPlanId == workPlanId);
            }
            if (date is not null)
            {
                records = records.Include(i => i.WorkPlan).Where(i => i.WorkPlan.DayIndex == date.Value.GetDayIndex());
            }
            if (userId is not null)
            {
                records = records.Where(i => i.UserId == userId);
            }
            if (classroom is not null)
            {
                records = records.Include(i => i.WorkPlan).Where(i => i.WorkPlan.ClassRoom == classroom);
            }

            if (beforeId != -1)
            {
                records = records.Where(i => i.Id < beforeId);
            }

            return(records.OrderByDescending(i => i.Id).Take(20).Select(i => new CheckinRecordModel(i.Id, null, i.Overtime, i.OvertimeMinutes, i.Note)).ToListAsync());
        }
Ejemplo n.º 20
0
 public Task <List <CheckinRecordModel> > QueryCheckinRecordsAsync(int?workPlanId, DateTimeOffset?date, string?userId, Room?classroom, int beforeId = -1) => throw new NotImplementedException();
Ejemplo n.º 21
0
 public ActorViewModel(LevelViewModel level, Room?room, Actor actor)
     : base(level, room, actor)
 {
 }