Beispiel #1
0
        private void ServerRemote_GetSuggestions(string text, ushort textPosition, byte requestId)
        {
            var byCharacter = ServerRemoteContext.Character;
            var suggestions = ServerSuggestAutocomplete(
                text,
                byCharacter,
                textPosition,
                out var consoleCommandVariant);

            BaseConsoleCommand consoleCommand = null;
            byte variantIndex = 0;

            if (consoleCommandVariant is not null)
            {
                consoleCommand = consoleCommandVariant.ConsoleCommand;
                var variants = consoleCommand.Variants;
                for (byte index = 0; index < variants.Count; index++)
                {
                    if (consoleCommandVariant == variants[index])
                    {
                        variantIndex = index;
                        break;
                    }
                }
            }

            var consoleCommandName = consoleCommand?.Name;

            this.CallClient(
                byCharacter,
                _ => _.ClientRemote_GetSuggestionsCallback(consoleCommandName,
                                                           variantIndex,
                                                           suggestions,
                                                           requestId));
        }
Beispiel #2
0
 public static void ServerOnConsoleCommandResult(
     ICharacter byCharacter,
     BaseConsoleCommand command,
     string result)
 {
     Instance.CallClient(byCharacter,
                         _ => _.ClientRemote_ConsoleCommandResult(command.Name, result));
 }
Beispiel #3
0
 public ConsoleCommandVariant(BaseConsoleCommand consoleCommand, ScriptingMethodInfo methodInfo)
 {
     this.ConsoleCommand = consoleCommand;
     this.MethodInfo     = methodInfo;
     this.Parameters     = this.MethodInfo.GetParameters()
                           .Select(p => new CommandParameter(p))
                           .ToArray();
 }
Beispiel #4
0
 public ConsoleCommandData(
     BaseConsoleCommand consoleCommand,
     string[] arguments,
     byte argumentIndexForSuggestion)
 {
     this.ConsoleCommand             = consoleCommand;
     this.arguments                  = arguments;
     this.argumentIndexForSuggestion = argumentIndexForSuggestion;
 }
        private void ClientRemote_GetSuggestionsCallback(
            BaseConsoleCommand consoleCommand,
            byte variantIndex,
            IReadOnlyList <string> suggestions,
            byte requestId)
        {
            var commandVariant = consoleCommand?.Variants[variantIndex];

            ClientSuggestionsCallback.Invoke(commandVariant, suggestions ?? EmptySuggestionsArray, requestId);
        }
        public static ConsoleCommandData SharedParseCommand(
            string text,
            out string commandName,
            ushort textPosition = 0)
        {
            if (string.IsNullOrEmpty(text))
            {
                commandName = string.Empty;
                return(null);
            }

            ConsoleCommandParser.ParseCommandNameAndArguments(
                text,
                textPosition,
                out commandName,
                out var arguments,
                out var argumentIndexForSuggestion);

            BaseConsoleCommand consoleCommand = null;

            foreach (var command in allCommands)
            {
                if (command.GetNameOrAlias(commandName)
                    .Equals(commandName, StringComparison.OrdinalIgnoreCase))
                {
                    consoleCommand = command;
                    break;
                }
            }

            if (consoleCommand == null)
            {
                // unknown command
                return(null);
            }

            var kind = consoleCommand.Kind;

            if (IsClient &&
                (kind & ConsoleCommandKinds.Client) == 0)
            {
                // non-client command
                return(null);
            }

            if (IsServer &&
                (kind & ConsoleCommandKinds.ServerOperator) == 0 &&
                (kind & ConsoleCommandKinds.ServerEveryone) == 0)
            {
                // non-server command
                return(null);
            }

            return(new ConsoleCommandData(consoleCommand, arguments, (byte)argumentIndexForSuggestion));
        }
Beispiel #7
0
        private static BaseConsoleCommand SharedFindConsoleCommandByName(string commandName)
        {
            if (string.IsNullOrEmpty(commandName))
            {
                return(null);
            }

            BaseConsoleCommand consoleCommand = null;

            foreach (var command in allCommands)
            {
                if (command.GetNameOrAlias(commandName)
                    .Equals(commandName, StringComparison.OrdinalIgnoreCase))
                {
                    consoleCommand = command;
                    break;
                }
            }

            return(consoleCommand);
        }