/// <summary>
        /// Request suggestions - it will return matched command variant and current parameter suggestions.
        /// </summary>
        private void RequestSuggestions()
        {
            var text = this.inputTextBox.Text;

            if (this.lastText == text)
            {
                // already requested the same suggestion
                if (this.currentCommandVariant != null)
                {
                    this.SuggestionsProvidedHandler(this.currentCommandVariant,
                                                    this.currentSuggestions,
                                                    this.lastSuggestionRequestId);
                }

                return;
            }

            //this.currentSuggestions = null;
            //this.viewModelConsoleControl.SetSuggestions(null);

            this.lastText = text;
            var textPosition = (ushort)this.inputTextBox.CaretIndex;
            var requestId    = ++this.lastSuggestionRequestId;

            ConsoleCommandsSystem.ClientSuggestAutocomplete(text, textPosition, requestId);
        }
Esempio n. 2
0
        private static IEnumerable <string> GetCommandNameSuggestions(string startsWith)
        {
            foreach (var command in ConsoleCommandsSystem.SharedGetCommandNamesSuggestions(startsWith))
            {
                yield return(command.Name);

                if (command.Alias != null)
                {
                    yield return(command.Alias);
                }
            }
        }
Esempio n. 3
0
        protected override void ServerInitializeCharacterFirstTime(ServerInitializeData data)
        {
            base.ServerInitializeCharacterFirstTime(data);

            var character   = data.GameObject;
            var publicState = data.PublicState;

            if (!Api.IsEditor)
            {
                NewbieProtectionSystem.ServerRegisterNewbie(character);

                publicState.IsMale    = 1 == RandomHelper.Next(0, maxValueExclusive: 2); // male/female ratio: 50/50
                publicState.FaceStyle = SharedCharacterFaceStylesProvider
                                        .GetForGender(publicState.IsMale)
                                        .GenerateRandomFace();
            }
            else // if Editor
            {
                publicState.IsMale    = true;
                publicState.FaceStyle = SharedCharacterFaceStylesProvider
                                        .GetForGender(publicState.IsMale)
                                        .GetDefaultFaceInEditor();
            }

            ServerPlayerSpawnManager.ServerAddTorchItemIfNoItems(character);

            if (!Api.IsEditor)
            {
                return;
            }

            // the game is run as Editor
            // auto pwn in editor mode
            ConsoleCommandsSystem.SharedGetCommand <ConsoleAdminPwn>().Execute(player: character);
            // add all the skills
            ConsoleCommandsSystem.SharedGetCommand <ConsoleSkillsSetAll>().Execute(player: character);
            // add all the technologies
            ConsoleCommandsSystem.SharedGetCommand <ConsoleTechAddAll>().Execute(player: character);

            this.ServerRebuildFinalCacheIfNeeded(data.PrivateState, publicState);

            // add all the quests (and complete them)
            ConsoleCommandsSystem.SharedGetCommand <ConsoleQuestCompleteAll>().Execute(player: character);
        }
        public void UpdateSuggestionGhostOnly()
        {
            var text = this.inputTextBox.Text;

            if (text.Length == 0)
            {
                this.textBlockSuggestionGhost.Text = string.Empty;
                return;
            }

            var    stringBuilder = new StringBuilder(capacity: 100);
            string commandName;

            if (this.currentCommandVariant == null)
            {
                // get suggested command name
                if (text[0] == ConsoleCommandsSystem.ServerConsoleCommandPrefixOnClient)
                {
                    // cannot suggest server commands on client
                }
                else
                {
                    commandName = ConsoleCommandsSystem.SharedGetCommandNamesSuggestions(text)
                                  .FirstOrDefault()?.GetNameOrAlias(text);
                    stringBuilder.Append(commandName);
                }

                this.textBlockSuggestionGhost.Text = stringBuilder.ToString();
                return;
            }

            var consoleCommand = this.currentCommandVariant.ConsoleCommand;

            {
                var name = text.TrimStart(ConsoleCommandsSystem.ServerConsoleCommandPrefixOnClient);

                var indexOfSpace = name.IndexOf(' ');
                if (indexOfSpace > 0)
                {
                    name = name.Substring(0, indexOfSpace);
                }

                if (!consoleCommand.Name.StartsWith(name) &&
                    (consoleCommand.Alias == null ||
                     !consoleCommand.Alias.StartsWith(name)))
                {
                    // current command variant is different from what is displayed now
                    // remove ghost
                    this.textBlockSuggestionGhost.Text = string.Empty;
                    return;
                }
            }

            ConsoleCommandParser.ParseCommandNameAndArguments(
                text,
                textPosition: (ushort)this.inputTextBox.CaretIndex,
                commandName: out commandName,
                arguments: out var arguments,
                argumentIndexForSuggestion: out var argumentIndexForSuggestion);

            if (text[0] == ConsoleCommandsSystem.ServerConsoleCommandPrefixOnClient)
            {
                // append server command prefix
                stringBuilder.Append(ConsoleCommandsSystem.ServerConsoleCommandPrefixOnClient);
                text = text.Substring(1);
            }

            var isCommandNameParsedSuccessfully = this.currentCommandVariant != null &&
                                                  (commandName.Equals(consoleCommand.Name,
                                                                      StringComparison.OrdinalIgnoreCase) ||
                                                   commandName.Equals(
                                                       consoleCommand.Alias,
                                                       StringComparison.OrdinalIgnoreCase));

            if (!isCommandNameParsedSuccessfully)
            {
                // need to print ghost for the command name
                commandName = consoleCommand.GetNameOrAlias(commandName);
                stringBuilder.Append(commandName)
                .Append(' ');
            }
            else
            {
                // no need to print any ghost before for the current auto-complete argument
                // add padding before this argument
                var paddingCount = text.TrimEnd(' ').Length + 1;
                stringBuilder.Append(' ', repeatCount: paddingCount);
            }

            // skip all parameters before latest entered and then append the "ghost text" for all the remaining parameters
            var parametersToSkipCount = Math.Max(arguments.Count(a => !string.IsNullOrEmpty(a)),
                                                 argumentIndexForSuggestion);
            var parameters = this.currentCommandVariant.Parameters;

            {
                var isFirst = true;
                foreach (var commandParameter in parameters.Skip(parametersToSkipCount))
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        stringBuilder.Append(' ');
                    }

                    stringBuilder.Append(commandParameter.Name);
                }
            }

            this.textBlockSuggestionGhost.Text = stringBuilder.ToString();
        }
Esempio n. 5
0
 public static void ExecuteCommand(string command)
 {
     ConsoleCommandsSystem.SharedExecuteConsoleCommand(command);
 }
Esempio n. 6
0
        public string Execute(
            [CustomSuggestions(nameof(GetCommandNameSuggestions))]
            string searchCommand = null)
        {
            var allCommands = ConsoleCommandsSystem.AllCommands.ToList();

            if (Api.IsServer)
            {
                allCommands.RemoveAll(
                    // exclude client commands on Server-side
                    c => (c.Kind ^ ConsoleCommandKinds.Client) == default);
            }

            var currentCharacter = this.ExecutionContextCurrentCharacter;

            if (currentCharacter is not null)
            {
                var isOperator  = ServerOperatorSystem.SharedIsOperator(currentCharacter);
                var isModerator = ServerModeratorSystem.SharedIsModerator(currentCharacter);
                ConsoleCommandsSystem.SharedFilterAvailableCommands(allCommands, isOperator, isModerator);
            }

            var sb = new StringBuilder(capacity: 2047);

            sb.AppendLine().AppendLine();

            if (!string.IsNullOrEmpty(searchCommand))
            {
                var foundCommandsList =
                    allCommands.Where(
                        c => c.Name.StartsWith(searchCommand, StringComparison.OrdinalIgnoreCase) ||
                        c.Alias is not null &&
                        c.Alias.StartsWith(searchCommand, StringComparison.OrdinalIgnoreCase))
                    .ToList();
                if (foundCommandsList.Count == 0)
                {
                    sb.Append("No commands found.");
                    return(sb.ToString());
                }

                allCommands = foundCommandsList;
            }

            //AppendLegend(sb);
            //sb.AppendLine();
            sb.AppendLine("Commands: ");

            foreach (var consoleCommand in allCommands)
            {
                string prefix;
                switch (consoleCommand.Kind)
                {
                // add server suffix for server commands
                case ConsoleCommandKinds.ServerEveryone:
                case ConsoleCommandKinds.ServerOperator:
                case ConsoleCommandKinds.ServerModerator:
                    prefix = "/";
                    break;

                case ConsoleCommandKinds.ClientAndServerEveryone:
                case ConsoleCommandKinds.ClientAndServerOperatorOnly:
                    prefix = "(/)";
                    break;

                default:
                    prefix = string.Empty;
                    break;
                }

                AppendCommandInfo(sb, consoleCommand, prefix);
            }

            return(sb.ToString());
        }