Ejemplo n.º 1
0
        /// <summary>
        /// Add a new key to the manager
        /// </summary>
        /// <param name="key">The key to add</param>
        /// <returns>The task</returns>
        public static async Task AddKeyAsync(Key key)
        {
            // Lock the method
            using (await AsyncLock.LockAsync())
            {
                // Check if it's the following key in any of the available codes
                if (Codes.All(x => x.Key.Length <= CurrentInput.Count || x.Key[CurrentInput.Count] != key))
                {
                    if (CurrentInput.Any())
                    {
                        CurrentInput.Clear();
                        RL.Logger?.LogDebugSource("The secret code inputs were reset due to an invalid key being pressed");
                    }

                    return;
                }

                // Add the key to the list
                CurrentInput.Add(key);

                // Attempt to get a completed code
                var task = Codes.FindItem(x => x.Key.SequenceEqual(CurrentInput)).Value;

                if (task == null)
                {
                    return;
                }

                CurrentInput.Clear();
                RL.Logger?.LogDebugSource("The secret code inputs were reset due to a valid code having been entered");

                // Run the task
                await task();
            }
        }