private void JoinLobby(object parameter) { Guid lobbyId = (Guid)parameter; DinnergeddonServiceReference.Lobby lobbyToJoin = _proxy.GetLobbyById(lobbyId); Guid userId = customPrincipal.Identity.Id; if (!IsJoinedInALobby(userId)) { //_proxy.GetLobbyById(lobbyId); if (lobbyToJoin.IsPrivate) { pd = new InputPasswordDialog() { DataContext = new InputPasswordViewModel() }; pd.Show(); string password = ""; Mediator.Subscribe("PassWordCorrect", new Action <object>((x) => { App.Current.Dispatcher.Invoke((Action) delegate { pd.Close(); //_proxy.JoinLobby(userId, lobbyId, password); }); password = x as String; JoinPrivateLobby(customPrincipal.Identity.Id, lobbyId, password); })); } else { Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { lobbyToJoin = _proxy.JoinLobby(userId, lobbyId); })); if (lobbyToJoin == null) { MessageBox.Show("Joining this lobby is not possible", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { OpenLobby(lobbyToJoin.Id); } } } else { if (IsJoinedInTheLobby(userId, lobbyId)) { // _proxy.GetLobbyById(lobbyId); OpenLobby(lobbyId); } else { MessageBox.Show("You already joined a lobby", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void OnLobbyUpdated(object sender, LobbyEventArgs args) { DinnergeddonServiceReference.Lobby updatedLobby = args.Lobby; DinnergeddonServiceReference.Lobby lobbyToUpdate = _lobbies.Where(x => x.Id == updatedLobby.Id).FirstOrDefault(); lobbyToUpdate.Players = updatedLobby.Players; lobbyToUpdate.Limit = updatedLobby.Limit; Guid lid = lobbyToUpdate.Id; Guid uId = updatedLobby.Id; // _proxy.GetLobbyById(updatedLobby.Id); //if (!IsJoinedInTheLobby(customPrincipal.Identity.Id, lobbyToUpdate.Id)) //{ // IsJoined = false; // JoinedLobby = null; //} //OnPropertyChanged("Lobbies"); bool isJoined = false; foreach (Account a in lobbyToUpdate.Players) { if (a.Id == customPrincipal.Identity.Id) { isJoined = true; JoinedLobby = lobbyToUpdate; } } if (!isJoined) { if (!IsJoinedInALobby(customPrincipal.Identity.Id)) { IsJoined = false; JoinedLobby = null; } } }
private void LobbyJoined(object parameter) { Guid lobbyId = (Guid)parameter; DinnergeddonServiceReference.Lobby lobby = _proxy.GetLobbyById(lobbyId); _lobby = lobby; LobbyName = _lobby.Name; JoinedPlayers = new ObservableCollection <Account>(_lobby.Players.ToList()); // LobbyServiceReference.Lobby joinedLobby = _proxy.GetLobbyById((Guid)parameter); }
//private void OnLobbiesRecieved(object sender, IEnumerable<DinnergeddonServiceReference.Lobby> lobbies) //{ // Lobbies = new ObservableCollection<DinnergeddonServiceReference.Lobby>(lobbies); //} //private void OnLobbyRecieved(object sender, LobbyEventArgs args) //{ // JoinedLobby = args.Lobby; // _currentLobby = args.Lobby; //} private void OnLobbyCreated(object sender, LobbyEventArgs args) { DinnergeddonServiceReference.Lobby createdLobby = args.Lobby; App.Current.Dispatcher.Invoke((Action) delegate { _lobbies.Add(createdLobby); }); Lobbies = _lobbies; OnPropertyChanged("Lobbies"); }
private void JoinPrivateLobby(Guid userId, Guid lobbyId, string password) { DinnergeddonServiceReference.Lobby lobbyToJoin = null; lobbyToJoin = _proxy.JoinLobby(userId, lobbyId, password); if (lobbyToJoin == null) { MessageBox.Show("Joining this lobby is not possible", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { OpenLobby(lobbyToJoin.Id); } }
private async void OpenLobby(object parameter) { Guid lobbyId = (Guid)parameter; DinnergeddonServiceReference.Lobby lobby = null; Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { lobby = _proxy.GetLobbyById(lobbyId); })); //Mediator.Notify("SendLobbyId", _currentLobby.Id); Mediator.Notify("OpenLobby", lobby.Id); //notify LobbyView to set its lobby field Mediator.Notify("LobbyJoined", lobby.Id); JoinedLobby = lobby; IsJoined = true; }
private bool IsJoinedInTheLobby(Guid userId, Guid lobbyId) { DinnergeddonServiceReference.Lobby lobby = null; Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { lobby = _proxy.GetLobbyById(lobbyId); })); //Lobbies = new ObservableCollection<LobbyServiceReference.Lobby>(_proxy.GetLobbies().ToList()); if (lobby == null) { return(false); } foreach (Account a in lobby.Players) { if (a.Id == userId) { return(true); } } return(false); }