Exemple #1
0
        public bool UpdateGameState(UpdateGameEvent updateOperation, out GameState gameState)
        {
            // try to get the game state
            if (this.gameDict.TryGet(updateOperation.GameId, out gameState) == false)
            {
                if (updateOperation.Reinitialize)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Reinitialize: Add Game State {0}", updateOperation.GameId);
                    }

                    this.AddGameState(gameState);
                }
                else
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Game not found: {0}", updateOperation.GameId);
                    }
                    return(false);
                }
            }

            bool oldVisible = gameState.IsVisbleInLobby;
            bool changed    = gameState.Update(updateOperation);

            if (changed)
            {
                if (gameState.IsVisbleInLobby)
                {
                    this.changedGames[gameState.Id] = gameState;

                    if (oldVisible == false)
                    {
                        this.removedGames.Remove(gameState.Id);
                    }
                }
                else
                {
                    if (oldVisible)
                    {
                        this.changedGames.Remove(gameState.Id);
                        this.removedGames.Add(gameState.Id);
                    }
                }

                if (log.IsDebugEnabled)
                {
                    LogGameState("UpdateGameState: ", gameState);
                }
            }

            return(true);
        }
Exemple #2
0
        public virtual bool UpdateGameState(UpdateGameEvent updateOperation, IncomingGameServerPeer incomingGameServerPeer, out GameState gameState)
        {
            if (!GetOrAddUpdatedGameState(updateOperation, out gameState))
            {
                return(false);
            }

            bool oldVisible = gameState.IsVisbleInLobby;
            bool changed    = gameState.Update(updateOperation);

            if (!changed)
            {
                return(false);
            }

            if (log.IsDebugEnabled)
            {
                LogGameState("UpdateGameState: ", gameState);
            }

            this.HandleVisibility(gameState, oldVisible);

            return(true);
        }
        public virtual bool UpdateGameState(UpdateGameEvent updateOperation, IncomingGameServerPeer incomingGameServerPeer, out GameState gameState)
        {
            if (!GetOrAddUpdatedGameState(updateOperation, out gameState))
            {
                return false;
            }

            bool oldVisible = gameState.IsVisbleInLobby;
            bool changed = gameState.Update(updateOperation);

            if (!changed)
            {
                return false;
            }

            if (log.IsDebugEnabled)
            {
                LogGameState("UpdateGameState: ", gameState);
            }

            this.HandleVisibility(gameState, oldVisible);

            return true;
        }
        public bool UpdateGameState(UpdateGameEvent updateOperation, IncomingGameServerPeer incomingGameServerPeer, out GameState gameState)
        {
            // try to get the game state 
            if (this.gameDict.TryGet(updateOperation.GameId, out gameState) == false)
            {
                if (updateOperation.Reinitialize)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Reinitialize: Add Game State {0}", updateOperation.GameId);
                    }

                    if (!this.Lobby.Application.TryGetGame(updateOperation.GameId, out gameState))
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.DebugFormat("Could not find game to reinitialize: {0}", updateOperation.GameId);
                        }

                        return false;
                    }

                    this.gameDict.Add(updateOperation.GameId, gameState);
                    if (this.IsGameJoinable(gameState))
                    {
                        this.gameDatabase.InsertGameState(updateOperation.GameId, gameState.Properties);
                    }
                }
                else
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Game not found: {0}", updateOperation.GameId);
                    }
                    return false;
                }
            }

            bool oldIsJoinable = this.IsGameJoinable(gameState);
            bool oldVisible = gameState.IsVisbleInLobby;
            bool changed = gameState.Update(updateOperation);

            if (changed)
            {
                if (gameState.IsVisbleInLobby)
                {
                    this.changedGames[gameState.Id] = gameState;

                    if (oldVisible == false)
                    {
                        this.removedGames.Remove(gameState.Id);
                    }
                }
                else
                {
                    if (oldVisible)
                    {
                        this.changedGames.Remove(gameState.Id);
                        this.removedGames.Add(gameState.Id);
                    }
                }

                if (log.IsDebugEnabled)
                {
                    LogGameState("UpdateGameState: ", gameState);
                }

                var newIsJoinable = this.IsGameJoinable(gameState);
                if (newIsJoinable != oldIsJoinable)
                {
                    if (newIsJoinable)
                    {
                        this.gameDatabase.InsertGameState(gameState.Id, gameState.Properties);
                        if (log.IsDebugEnabled)
                        {
                            log.DebugFormat("GameState added to database: reason=Became joinable, gameId={0}", gameState.Id);
                        }
                    }
                    else
                    {
                        this.gameDatabase.Delete(gameState.Id);
                        if (log.IsDebugEnabled)
                        {
                            log.DebugFormat("GameState removed from database: reason=Became not joinable, gameId={0}", gameState.Id);
                        }
                    }
                }
                else
                {
                    if (oldIsJoinable)
                    {
                        this.gameDatabase.Update(gameState.Id, gameState.Properties);
                    }
                }
            }

            return true;
        }
        public bool UpdateGameState(UpdateGameEvent updateOperation, out GameState gameState)
        {
            // try to get the game state
            if (this.gameDict.TryGet(updateOperation.GameId, out gameState) == false)
            {
                if (updateOperation.Reinitialize)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Reinitialize: Add Game State {0}", updateOperation.GameId);
                    }

                    this.AddGameState(gameState);

                }
                else
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Game not found: {0}", updateOperation.GameId);
                    }
                    return false;
                }
            }

            bool oldVisible = gameState.IsVisbleInLobby;
            bool changed = gameState.Update(updateOperation);

            if (changed)
            {
                if (gameState.IsVisbleInLobby)
                {
                    this.changedGames[gameState.Id] = gameState;

                    if (oldVisible == false)
                    {
                        this.removedGames.Remove(gameState.Id);
                    }
                }
                else
                {
                    if (oldVisible)
                    {
                        this.changedGames.Remove(gameState.Id);
                        this.removedGames.Add(gameState.Id);
                    }
                }

                if (log.IsDebugEnabled)
                {
                    LogGameState("UpdateGameState: ", gameState);
                }
            }

            return true;
        }
Exemple #6
0
        public bool UpdateGameState(UpdateGameEvent updateOperation, IncomingGameServerPeer incomingGameServerPeer, out GameState gameState)
        {
            // try to get the game state
            if (this.gameDict.TryGet(updateOperation.GameId, out gameState) == false)
            {
                if (updateOperation.Reinitialize)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Reinitialize: Add Game State {0}", updateOperation.GameId);
                    }

                    if (!this.Lobby.Application.TryGetGame(updateOperation.GameId, out gameState))
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.DebugFormat("Could not find game to reinitialize: {0}", updateOperation.GameId);
                        }

                        return(false);
                    }

                    this.gameDict.Add(updateOperation.GameId, gameState);
                    if (this.IsGameJoinable(gameState))
                    {
                        this.gameDatabase.InsertGameState(updateOperation.GameId, gameState.Properties);
                    }
                }
                else
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Game not found: {0}", updateOperation.GameId);
                    }
                    return(false);
                }
            }

            bool oldIsJoinable = this.IsGameJoinable(gameState);
            bool oldVisible    = gameState.IsVisbleInLobby;
            bool changed       = gameState.Update(updateOperation);

            if (changed)
            {
                if (gameState.IsVisbleInLobby)
                {
                    this.changedGames[gameState.Id] = gameState;

                    if (oldVisible == false)
                    {
                        this.removedGames.Remove(gameState.Id);
                    }
                }
                else
                {
                    if (oldVisible)
                    {
                        this.changedGames.Remove(gameState.Id);
                        this.removedGames.Add(gameState.Id);
                    }
                }

                if (log.IsDebugEnabled)
                {
                    LogGameState("UpdateGameState: ", gameState);
                }

                var newIsJoinable = this.IsGameJoinable(gameState);
                if (newIsJoinable != oldIsJoinable)
                {
                    if (newIsJoinable)
                    {
                        this.gameDatabase.InsertGameState(gameState.Id, gameState.Properties);
                        if (log.IsDebugEnabled)
                        {
                            log.DebugFormat("GameState added to database: reason=Became joinable, gameId={0}", gameState.Id);
                        }
                    }
                    else
                    {
                        this.gameDatabase.Delete(gameState.Id);
                        if (log.IsDebugEnabled)
                        {
                            log.DebugFormat("GameState removed from database: reason=Became not joinable, gameId={0}", gameState.Id);
                        }
                    }
                }
                else
                {
                    if (oldIsJoinable)
                    {
                        this.gameDatabase.Update(gameState.Id, gameState.Properties);
                    }
                }
            }

            return(true);
        }