Example #1
0
        public GameStateData Translate(NetworkCommandConnection input)
        {
            if (input == null)
            {
                return(null);
            }
            if (input.CommandName != NetworkCommandConstants.UpdateCommand)
            {
                return(null);
            }

            //data to general model + id assignment
            var types = input.CommandArgument.LoadType(true, false);

            var currentState = SerializationAdapter.DeserializeObject(input.Data, types.FirstOrDefault()) as GameStateData;

            if (currentState == null)
            {
                throw new ArgumentNullException(nameof(GameStateData));
            }

            if (string.IsNullOrWhiteSpace(currentState.Id) || Guid.Empty.ToString() == currentState.Id)
            {
                throw new InvalidOperationException("No registered game state");
            }

            var foundGameStateData = GameStatesDataLayer.GetGameStateByLoginToken(currentState.LoginToken);

            Console.WriteLine($"{nameof(NetworkCommandToUpdateGameState)}:found in GetGameStateByLoginToken:{foundGameStateData}");

            return(foundGameStateData);
        }
Example #2
0
        public GameStateData Translate(NetworkCommandConnection input)
        {
            if (input == null)
            {
                return(null);
            }
            if (input.CommandName != NetworkCommandConstants.InitializeCommand)
            {
                return(null);
            }

            //data to general model + id assignment
            var types        = input.CommandArgument.LoadType(true, false);
            var initialState = SerializationAdapter.DeserializeObject(input.Data, types.FirstOrDefault()) as GameStateData;

            types = null;
            if (initialState == null)
            {
                throw new ArgumentNullException(nameof(GameStateData));
            }

            /*
             * If the login token for the game state has not been found =>
             * This means the game state should be registered
             */
            try
            {
                return((string.IsNullOrWhiteSpace(initialState.Id) || Guid.Empty.ToString() == initialState.Id) ?
                       GameStatesDataLayer.RegisterGameStateData(initialState.LoginToken) :
                       GameStatesDataLayer.GetGameStateByLoginToken(initialState.LoginToken));
            }
            catch (NoLoginTokenException)
            {
                throw;
            }
        }