예제 #1
0
        private async Task <LobbyGame> DisconnectedUserInternalAsync(string connectionId)
        {
            if (!UsersByConnectionId.ContainsKey(connectionId))
            {
                Logger.LogError($"Got user disconnect for unknown connection Id '{connectionId}'");
                return(null);
            }

            var user = UsersByConnectionId[connectionId];

            await subscriber.PublishAsync(RedisChannels.UserDisconnect, JsonConvert.SerializeObject(user));

            var game = FindGameForUser(user.Name);

            if (game == null || game.Started)
            {
                return(null);
            }

            game.PlayerDisconnected(user.Name);

            if (!game.IsEmpty())
            {
                return(game);
            }

            GamesById.Remove(game.Id);
            await subscriber.PublishAsync(RedisChannels.RemoveGame, game.Id.ToString());

            return(game);
        }
예제 #2
0
        public async Task <LobbyGame> LeaveGameAsync(string connectionId)
        {
            if (!UsersByConnectionId.ContainsKey(connectionId))
            {
                Logger.LogError($"Got leave game message for unknown connection id '{connectionId}'");
                return(null);
            }

            var user = UsersByConnectionId[connectionId];
            var game = FindGameForUser(user.Name);

            if (game == null || game.Started)
            {
                return(null);
            }

            game.PlayerLeave(user.Name);

            if (!game.IsEmpty())
            {
                await subscriber.PublishAsync(RedisChannels.UpdateGame, JsonConvert.SerializeObject(game));

                return(game);
            }

            GamesById.Remove(game.Id);

            await subscriber.PublishAsync(RedisChannels.RemoveGame, game.Id.ToString());

            return(game);
        }
예제 #3
0
        public void RemoveGame(Guid gameId)
        {
            if (!GamesById.ContainsKey(gameId))
            {
                Logger.LogWarning($"Got close for game {gameId} that we didn't know about");
                return;
            }

            GamesById.Remove(gameId);
        }
예제 #4
0
        private void DbClasses_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            DbHelper.Instance.IsChanged = true;

            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                if (sender is ObservableCollection <Player> )
                {
                    PlayersById.Add(((Player)e.NewItems[0]).Id, (Player)e.NewItems[0]);
                    m_Logger.Debug("Added a player: " + (Player)e.NewItems[0]);
                    NotifyPropertyChanged("PlayersSorted");
                }
                else if (sender is ObservableCollection <GameFamily> )
                {
                    GameFamiliesById.Add(((GameFamily)e.NewItems[0]).Id, (GameFamily)e.NewItems[0]);
                    m_Logger.Debug("Added a game family: " + (GameFamily)e.NewItems[0]);
                    NotifyPropertyChanged("GameFamiliesFiltered");
                }
                else if (sender is ObservableCollection <Location> )
                {
                    LocationsById.Add(((Location)e.NewItems[0]).Id, (Location)e.NewItems[0]);
                    m_Logger.Debug("Added a Location: " + (Location)e.NewItems[0]);
                    NotifyPropertyChanged("LocationsSorted");
                }
                else if (sender is ObservableCollection <Game> )
                {
                    GamesById.Add(((Game)e.NewItems[0]).Id, (Game)e.NewItems[0]);
                    m_Logger.Debug("Added a Game: " + (Game)e.NewItems[0]);
                    NotifyPropertyChanged("GamesPointBased");
                    NotifyPropertyChanged("GamesSorted");
                }
                else if (sender is ObservableCollection <Result> )
                {
                    Result v_Result = (Result)e.NewItems[0];

                    // Hooking up the notifications for the new object.
                    v_Result.PropertyChanged += Result_PropertyChanged;

                    foreach (Score i_Score in v_Result.Scores)
                    {
                        i_Score.PropertyChanged += Result_PropertyChanged;
                    }

                    NotifyPropertyChanged("ResultsOrdered");
                }
                else
                {
                    throw new NotImplementedException(String.Format("Adding of [{0}] is not supported.", sender.GetType()));
                }
            }
            else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
            {
                if (sender is ObservableCollection <Player> )
                {
                    PlayersById.Remove(((Player)e.OldItems[0]).Id);
                    NotifyPropertyChanged("PlayersSorted");
                }
                else if (sender is ObservableCollection <GameFamily> )
                {
                    GameFamiliesById.Remove(((GameFamily)e.OldItems[0]).Id);
                    NotifyPropertyChanged("GameFamiliesFiltered");
                }
                else if (sender is ObservableCollection <Location> )
                {
                    LocationsById.Remove(((Location)e.OldItems[0]).Id);
                    NotifyPropertyChanged("LocationsSorted");
                }
                else if (sender is ObservableCollection <Game> )
                {
                    GamesById.Remove(((Game)e.OldItems[0]).Id);
                    NotifyPropertyChanged("GamesPointBased");
                    NotifyPropertyChanged("GamesSorted");
                }
                else if (sender is ObservableCollection <Result> )
                {
                    NotifyPropertyChanged("ResultsOrdered");
                }
                else
                {
                    throw new NotImplementedException(String.Format("Removing of [{0}] is not supported.", sender.GetType()));
                }
            }
            else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset)
            {
                m_Logger.Debug("Resetting collection for [" + sender.GetType() + "].");

                if (sender is ObservableCollection <Player> )
                {
                    PlayersById.Clear();
                    NotifyPropertyChanged("PlayersSorted");
                }
                else if (sender is ObservableCollection <GameFamily> )
                {
                    GameFamiliesById.Clear();
                    NotifyPropertyChanged("GameFamiliesFiltered");
                }
                else if (sender is ObservableCollection <Location> )
                {
                    LocationsById.Clear();
                    NotifyPropertyChanged("LocationsSorted");
                }
                else if (sender is ObservableCollection <Game> )
                {
                    GamesById.Clear();
                    NotifyPropertyChanged("GamesPointBased");
                    NotifyPropertyChanged("GamesSorted");
                }
                else if (sender is ObservableCollection <Result> )
                {
                    NotifyPropertyChanged("ResultsOrdered");
                }
                else
                {
                    throw new NotImplementedException(String.Format("Resetting of [{0}] is not supported.", sender.GetType()));
                }
            }
            else
            {
                throw new NotImplementedException(String.Format("Action {0} not supported on collection.", e.Action));
            }
        }