public async Task <LobbyDataWrapper> UpdateLobbySettingsAsync(LobbyDataWrapper lobbyData) { var currentUserName = identityService.GetCurrentUserName(); var oldLobby = lobbyStorage.GetLobby(lobbyData.Content.Id); if (oldLobby == null) { throw new ArgumentOutOfRangeException(nameof(lobbyData.Content.Id), "Lobby does not exist."); } if (currentUserName != oldLobby.Host) { throw new UnauthorizedAccessException("Not authorized to update this lobby's settings."); } if (!lobbyData.Content.ValidateSettings()) { throw new InvalidOperationException("Invalid settings for this lobby."); } lobbyData.Content.Host = oldLobby.Host; lobbyData.Content.Guests = oldLobby.Guests; lobbyData.Content.InvitedPlayers = oldLobby.InvitedPlayers; lobbyData.Content.Created = oldLobby.Created; lobbyData.Content.LastModified = DateTime.UtcNow; lobbyStorage.UpdateLobby(lobbyData.Content); var updatedLobby = mapper.Map <LobbyDataWrapper>(lobbyStorage.GetLobby(lobbyData.Content.Id)); await notificationService.NotifyAllExceptAsync(currentUserName, client => client.LobbyChanged(updatedLobby)); return(updatedLobby); }
public async Task ReceiveLobbyInvite(LobbyDataWrapper lobbyData) { var result = await dialogService.ShowConfirmation($"You have been invited to a {lobbyData.GameType.ToString()} lobby by {lobbyData.Content.Host}. Do you want to join them?"); if (result == ContentDialogResult.Primary) { try { if (lobbyStore.SelectedLobby != null) { await lobbyService.DisconnectFromCurrentLobbyAsync(); } var lobby = await lobbyService.JoinToLobbyAsync(lobbyData.Content.Id); lobbyStore.SelectedLobby = lobby.Content; await lobbyStore.UpdateLobby(lobby.Content); var messages = await messageService.GetMessagesOfLobbyAsync(lobbyData.Content.Id); await messageStore.SetMessages(messages); navigationService.Navigate(PageTokens.LobbyDetails.ToString(), null); } catch (FlurlHttpException e) { await dialogService.ShowError("Could not connect to the lobby"); } } }
public async Task LobbyChanged(LobbyDataWrapper lobbyData) { await lobbyStore.UpdateLobby(lobbyData.Content); }
public async Task LobbyAdded(LobbyDataWrapper lobbyData) { await lobbyStore.AddLobby(lobbyData.Content); }
public Task <LobbyDataWrapper> UpdateLobbySettingsAsync(LobbyDataWrapper lobbyData) { return(BASE_URL.WithOAuthBearerToken(userManagerService.AccessToken).AppendPathSegment($"api/lobbies/{lobbyData.Content.Id}").PutJsonAsync(lobbyData).ReceiveJson <LobbyDataWrapper>()); }