Exemple #1
0
        private static DestructuredChatCommand ParseCommand(string rawData)
        {
            // Split on ][, in order to isolate parts of the command.
            // [0]: [CHANNELROUTER] RECEIVED MESSAGE ON Server(0): [CHAT
            // [1]: sender=Retrom_Gall
            // [2]: receiverType=CHANNEL
            // [3]: receiver=Server
            // [4]: message=!FEEDBACK 1 Test]
            string[] dataParts        = rawData.Split(new[] { "][" }, StringSplitOptions.None);
            string   sourcePlayerName = dataParts[1].Replace("sender=", string.Empty);

            // Get command...
            string command = dataParts[4].Replace("message=", string.Empty);

            // Trim off final ] of command...
            command = command.Substring(0, command.Length - 1);

            var result = new DestructuredChatCommand
            {
                SourcePlayerName = sourcePlayerName,
                Command          = command
            };

            return(result);
        }
Exemple #2
0
        public bool TryParseCommand(string rawData, out string[] args)
        {
            args = null;
            var cmdArgs = new List <string>();

            DestructuredChatCommand chatCommand = null;
            bool isChatCommand = ChatCommander.TryParseCommand(rawData, out chatCommand);

            if (!isChatCommand)
            {
                return(false);
            }

            bool isThisCommand = chatCommand.Command.StartsWith(Token);

            if (isThisCommand)
            {
                // !FEEDBACK [HELP | 1-5] [Details...]
                string parsedCommand = chatCommand.Command.ToUpper();

                // Step 1 - Move past the command invocation...
                cmdArgs.Add(chatCommand.SourcePlayerName);
                parsedCommand = parsedCommand.Substring(Token.Length + 1, parsedCommand.Length - (Token.Length + 1));

                // Step 2 - Get the rating...
                var firstArgParts = parsedCommand.Split(' ');
                if (firstArgParts[0] == "HELP")
                {
                    cmdArgs.Add(firstArgParts[0]);
                }
                else
                {
                    short rating;
                    bool  isNumeric = short.TryParse(firstArgParts[0], out rating);
                    if (isNumeric && rating > 0 && rating < 6)
                    {
                        cmdArgs.Add(firstArgParts[0]);
                    }
                    else
                    {
                        cmdArgs.Add("HELP");
                    }
                }

                // Step 3 - Remove the first arg, and use the rest of the string as the details.
                int firstArgEndPosition = firstArgParts[0].Length + 1;
                parsedCommand = parsedCommand
                                .Substring(firstArgEndPosition, parsedCommand.Length - firstArgEndPosition)
                                .Trim();

                if (!string.IsNullOrEmpty(parsedCommand))
                {
                    cmdArgs.Add(parsedCommand);
                }

                args = cmdArgs.ToArray();
            }

            return(isThisCommand);
        }
Exemple #3
0
        public static bool TryParseCommand(string rawData, out DestructuredChatCommand command)
        {
            command = null;
            if (!IsMessage(rawData))
            {
                return(false);
            }

            command = ParseCommand(rawData);
            return(command.IsCommand);
        }
Exemple #4
0
        public bool TryParseCommand(string rawData, out string[] args)
        {
            args = null;
            var cmdArgs = new List <string>();

            DestructuredChatCommand chatCommand = null;
            bool isChatCommand = ChatCommander.TryParseCommand(rawData, out chatCommand);

            if (!isChatCommand)
            {
                return(false);
            }

            bool isThisCommand = chatCommand.Command.StartsWith(Token);

            if (isThisCommand)
            {
                // !NETWORTH ME|HELP
                string parsedCommand = chatCommand.Command.ToUpper();

                // Step 1 - Move past the command invocation...
                cmdArgs.Add(chatCommand.SourcePlayerName);
                parsedCommand = parsedCommand.Replace($"{Token} ", string.Empty);

                // Step 2 - Trim what's left, look at what the string starts with.
                parsedCommand = parsedCommand.Trim();
                if (parsedCommand.StartsWith("ME"))
                {
                    cmdArgs.Add("ME");
                }
                else if (parsedCommand.StartsWith("HELP"))
                {
                    cmdArgs.Add("HELP");
                }
                else
                {
                    cmdArgs.Add("HELP");
                }

                args = cmdArgs.ToArray();
            }

            return(isThisCommand);
        }
        public bool TryParseCommand(string rawData, out string[] args)
        {
            args = null;
            var cmdArgs = new List <string>();

            DestructuredChatCommand chatCommand = null;
            bool isChatCommand = ChatCommander.TryParseCommand(rawData, out chatCommand);

            if (!isChatCommand)
            {
                return(false);
            }

            bool isThisCommand = chatCommand.Command.StartsWith(Token);

            if (isThisCommand)
            {
                // !BOUNTY [Player] [Amount]
                // Step 1 - Move past the command invocation...
                cmdArgs.Add(chatCommand.SourcePlayerName);
                var parsedCommand = chatCommand.Command.Replace($"{Token} ", string.Empty);

                // Step 2 - Separate the Player from the Amount...
                // If there aren't two arguments, default to HELP mode.
                string[] cmdParts = parsedCommand.Split(' ');
                if (cmdParts.Length != 2)
                {
                    cmdArgs.Add("HELP");
                }
                else
                {
                    string targetPlayerName = cmdParts[0];
                    string amount           = cmdParts[1];

                    cmdArgs.Add(targetPlayerName);
                    cmdArgs.Add(amount);
                }

                args = cmdArgs.ToArray();
            }

            return(isThisCommand);
        }
        public bool TryParseCommand(string rawData, out string[] args)
        {
            args = null;
            var cmdArgs = new List <string>();

            DestructuredChatCommand chatCommand = null;
            bool isChatCommand = ChatCommander.TryParseCommand(rawData, out chatCommand);

            if (!isChatCommand)
            {
                return(false);
            }

            bool isThisCommand = chatCommand.Command.StartsWith(Token);

            if (isThisCommand)
            {
                // !CASHOUT
                string parsedCommand = chatCommand.Command.ToUpper();

                // Step 1 - Move past the command invocation...
                cmdArgs.Add(chatCommand.SourcePlayerName);
                parsedCommand = parsedCommand.Replace($"{Token}", string.Empty);

                // Step 2 - If there's anything left over, show Help text.
                parsedCommand = parsedCommand.Trim();
                if (!string.IsNullOrEmpty(parsedCommand))
                {
                    cmdArgs.Add("HELP");
                }

                args = cmdArgs.ToArray();
            }

            return(isThisCommand);
        }