Exemple #1
0
        private void ctlChat_InputReceived(object sender, Lionsguard.InputReceivedEventArgs e)
        {
            RdlCommandParserErrorType errType = RdlCommandParserErrorType.None;
            RdlCommand cmd;

            if (RdlCommand.TryParse(e.Input, out cmd, out errType))
            {
                // Only echo say, shout, tell and emotes.
                this.EchoInput(cmd);

                if (this.ServerCommandType == CommandType.Player)
                {
                    ServerManager.Instance.SendCommand(cmd);
                }
                else
                {
                    ServerManager.Instance.SendUserCommand(cmd);
                }
            }
            else
            {
                switch (errType)
                {
                case RdlCommandParserErrorType.NoTargetForTell:
                    this.Write(MessageType.Error, "TELL requires the name of the person you wish to send a message.");
                    break;

                case RdlCommandParserErrorType.NoArgumentsSpecified:
                    this.Write(MessageType.Error, String.Format("No arguments were specified for the {0} command.", cmd.TypeName));
                    break;

                case RdlCommandParserErrorType.InvalidNumberOfArguments:
                    this.Write(MessageType.Error, String.Format("An invalid number of arguments were specified for the {0} command.", cmd.TypeName));
                    break;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Attempts to parse the input string into an RDL command.
        /// </summary>
        /// <param name="input">The input from a chat or command console.</param>
        /// <param name="command">An RdlCommand instance representing the parsed input.</param>
        /// <param name="errorType">The RdlCommandParserErrorType value of any parsing errors.</param>
        /// <returns>True if the input was successfully parsed; otherwise false. If false the errorType
        /// parameter will contain information regarding the reason parsing failed.</returns>
        public static bool TryParse(string input, out RdlCommand command, out RdlCommandParserErrorType errorType)
        {
            bool result = false;

            errorType = RdlCommandParserErrorType.None;
            command   = new RdlCommand();
            if (!input.StartsWith("/"))
            {
                input = String.Concat("/SAY ", input);
            }

            string[] words = input.Split(' ');
            if (words != null && words.Length > 0)
            {
                // First word is the command, minus the "/"
                command.TypeName = words[0].Replace("/", "").ToUpper();

                // Command shortcuts.
                if (command.TypeName == "'")
                {
                    command.TypeName = "SAY";
                }
                if (command.TypeName == "\"")
                {
                    command.TypeName = "SHOUT";
                }
                if (command.TypeName == ":")
                {
                    command.TypeName = "EMOTE";
                }
                if (command.TypeName == ";")
                {
                    command.TypeName = "EMOTE";
                }
                if (command.TypeName == "r")
                {
                    command.TypeName = "REPLY";
                }

                // Handle parsing of the command arguments based on common commands.
                switch (command.TypeName)
                {
                //case "SAY":
                //case "SHOUT":
                //case "EMOTE":
                //    // The remainder of the words should be re-joined to form the text of the message.
                //    if (words.Length >= 2)
                //    {
                //        command.Args.Add(JoinWords(words, 1));
                //        result = true;
                //    }
                //    else
                //    {
                //        errorType = RdlCommandParserErrorType.InvalidNumberOfArguments;
                //    }
                //    break;
                case "TELL":
                case "REPLY":
                    // The next word is the name of the TELL target, the words following can be joined
                    // to form the text of the message.
                    if (words.Length >= 2)
                    {
                        if (words.Length >= 3)
                        {
                            command.Args.Add(words[1]);
                            command.Args.Add(JoinWords(words, 2));
                            result = true;
                        }
                        else
                        {
                            errorType = RdlCommandParserErrorType.InvalidNumberOfArguments;
                        }
                    }
                    else
                    {
                        errorType = RdlCommandParserErrorType.NoTargetForTell;
                    }
                    break;

                default:
                    //// Just parse all the words as separate args.
                    //if (words.Length > 1)
                    //{
                    //    for (int i = 1; i < words.Length; i++)
                    //    {
                    //        command.Args.Add(words[i]);
                    //    }
                    //}

                    // The remainder of the words should be re-joined to form the text of the message.
                    if (words.Length >= 2)
                    {
                        command.Args.Add(JoinWords(words, 1));
                    }

                    // Allow no arguments.
                    result = true;
                    break;
                }
            }
            else
            {
                errorType = RdlCommandParserErrorType.NoArgumentsSpecified;
            }
            return(result);
        }