コード例 #1
0
        /// <summary>
        /// Parses a ChatCommand instance from string input and available data.
        /// </summary>
        /// <param name="Text">Text input to parse</param>
        /// <param name="DataController">Reference to DataController instance</param>
        /// <param name="Config">Reference to Config instance</param>
        /// <returns></returns>
        public static ChatCommand Parse(string Text, DataController DataController, Config Config)
        {
            string command = null;
            string lower   = null;
            string text    = null;
            string alias   = null;

            string[]    splitted    = null;
            ChatCommand returnValue = null;

            /**********************************************************************/
            // checks

            if (Text == null || DataController == null || Config == null)
            {
                return(null);
            }

            lower = Text.Trim();

            if (String.Equals(lower, String.Empty))
            {
                return(null);
            }

            /**********************************************************************/
            // resolve aliases

            int idx = lower.IndexOf(DELIMITER);

            if (idx == -1)
            {
                // only one word which might be an alias
                KeyValuePairString aliascmd = Config.Aliases.GetItemByKey(lower);

                if (aliascmd != null)
                {
                    lower = aliascmd.Value;
                }
            }
            else
            {
                // first word might be alias, but there is more
                alias = lower.Substring(0, idx);

                KeyValuePairString aliascmd = Config.Aliases.GetItemByKey(alias);

                if (aliascmd != null)
                {
                    lower = aliascmd.Value + lower.Substring(idx + 1);
                }
            }

            /**********************************************************************/

            // split up by delimiter
            splitted = lower.Split(DELIMITER);

            // check
            if (splitted.Length == 0)
            {
                return(null);
            }

            // command is first argument
            command = splitted[0];

            // select command
            switch (command)
            {
            case ChatCommandSay.KEY1:
            case ChatCommandSay.KEY2:
            case ChatCommandSay.KEY3:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandSay(text);
                }
                break;

            case ChatCommandEmote.KEY1:
            case ChatCommandEmote.KEY2:
            case ChatCommandEmote.KEY3:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandEmote(text);
                }
                break;

            case ChatCommandYell.KEY1:
            case ChatCommandYell.KEY2:
            case ChatCommandYell.KEY3:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandYell(text);
                }
                break;

            case ChatCommandBroadcast.KEY1:
            case ChatCommandBroadcast.KEY2:
            case ChatCommandBroadcast.KEY3:
            case ChatCommandBroadcast.KEY4:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandBroadcast(text);
                }
                break;

            case ChatCommandGuild.KEY1:
            case ChatCommandGuild.KEY2:
            case ChatCommandGuild.KEY3:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandGuild(text);
                }
                break;

            case ChatCommandAppeal.KEY1:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandAppeal(text);
                }
                break;

            case ChatCommandTell.KEY1:
            case ChatCommandTell.KEY2:
            case ChatCommandTell.KEY3:
                returnValue = ParseTell(splitted, lower, DataController);
                break;

            case ChatCommandCast.KEY1:
            case ChatCommandCast.KEY2:
            case ChatCommandCast.KEY3:
            case ChatCommandCast.KEY4:
                returnValue = ParseCast(splitted, lower, DataController);
                break;

            case ChatCommandDeposit.KEY1:
            case ChatCommandDeposit.KEY2:
                if (splitted.Length == 2)
                {
                    uint amount = 0;

                    if (UInt32.TryParse(splitted[1], out amount))
                    {
                        returnValue = new ChatCommandDeposit(amount);
                    }
                }
                break;

            case ChatCommandWithDraw.KEY1:
            case ChatCommandWithDraw.KEY2:
            case ChatCommandWithDraw.KEY3:
                if (splitted.Length == 2)
                {
                    uint amount = 0;

                    if (UInt32.TryParse(splitted[1], out amount))
                    {
                        returnValue = new ChatCommandWithDraw(amount);
                    }
                }
                break;

            case ChatCommandBalance.KEY1:
            case ChatCommandBalance.KEY2:
                if (splitted.Length == 1)
                {
                    returnValue = new ChatCommandBalance();
                }
                break;

            case ChatCommandSuicide.KEY1:
            case ChatCommandSuicide.KEY2:
                if (splitted.Length == 1)
                {
                    returnValue = new ChatCommandSuicide();
                }
                break;

            case ChatCommandDM.KEY1:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandDM(text);
                }
                break;

            case ChatCommandGo.KEY1:
            case ChatCommandGo.KEY2:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandGo(text);
                }
                break;

            case ChatCommandGoPlayer.KEY1:
                returnValue = ParseGoPlayer(splitted, lower, DataController);
                break;

            case ChatCommandGetPlayer.KEY1:
                returnValue = ParseGetPlayer(splitted, lower, DataController);
                break;

            case ChatCommandRest.KEY1:
            case ChatCommandRest.KEY2:
                returnValue = new ChatCommandRest();
                break;

            case ChatCommandStand.KEY1:
            case ChatCommandStand.KEY2:
                returnValue = new ChatCommandStand();
                break;

            case ChatCommandQuit.KEY1:
                returnValue = new ChatCommandQuit();
                break;

            case ChatCommandDance.KEY1:
            case ChatCommandDance.KEY2:
                returnValue = new ChatCommandDance();
                break;

            case ChatCommandPoint.KEY1:
            case ChatCommandPoint.KEY2:
                returnValue = new ChatCommandPoint();
                break;

            case ChatCommandWave.KEY1:
            case ChatCommandWave.KEY2:
                returnValue = new ChatCommandWave();
                break;

#if !VANILLA
            case ChatCommandTempSafe.KEY1:
                returnValue = ParseTempSafe(splitted, lower, DataController);
                break;

            case ChatCommandGrouping.KEY1:
                returnValue = ParseGrouping(splitted, lower, DataController);
                break;

            case ChatCommandAutoLoot.KEY1:
                returnValue = ParseAutoLoot(splitted, lower, DataController);
                break;

            case ChatCommandAutoCombine.KEY1:
                returnValue = ParseAutoCombine(splitted, lower, DataController);
                break;

            case ChatCommandReagentBag.KEY1:
                returnValue = ParseReagentBag(splitted, lower, DataController);
                break;

            case ChatCommandSpellPower.KEY1:
                returnValue = ParseSpellPower(splitted, lower, DataController);
                break;

            case ChatCommandTime.KEY1:
            case ChatCommandTime.KEY2:
                if (splitted.Length == 1)
                {
                    returnValue = new ChatCommandTime();
                }
                break;

#if !OPENMERIDIAN
            case ChatCommandInvite.KEY1:
            case ChatCommandInvite.KEY2:
            case ChatCommandInvite.KEY3:
                returnValue = ParseInvite(splitted, lower, DataController);
                break;
#endif
#endif
            }

            return(returnValue);
        }
コード例 #2
0
        /// <summary>
        /// Parses a ChatCommand instance from string input and available data.
        /// </summary>
        /// <param name="Text">Text input to parse</param>
        /// <param name="DataController">Reference to DataController instance</param>
        /// <param name="Config">Reference to Config instance</param>
        /// <returns></returns>
        public static ChatCommand Parse(string Text, DataController DataController, Config Config)
        {
            string command          = null;
            string lower            = null;
            string text             = null;
            string alias            = null;
            string[] splitted       = null;
            ChatCommand returnValue = null;

            /**********************************************************************/
            // checks

            if (Text == null || DataController == null || Config == null)
                return null;

            lower = Text.Trim();

            if (String.Equals(lower, String.Empty))
                return null;

            /**********************************************************************/
            // resolve aliases

            int idx = lower.IndexOf(DELIMITER);
            if (idx == -1)
            {
                // only one word which might be an alias
                KeyValuePairString aliascmd = Config.Aliases.GetItemByKey(lower);

                if (aliascmd != null)
                    lower = aliascmd.Value;
            }
            else
            {
                // first word might be alias, but there is more
                alias = lower.Substring(0, idx);

                KeyValuePairString aliascmd = Config.Aliases.GetItemByKey(alias);

                if (aliascmd != null)
                    lower = aliascmd.Value + lower.Substring(idx + 1);
            }

            /**********************************************************************/

            // split up by delimiter
            splitted = lower.Split(DELIMITER);

            // check
            if (splitted.Length == 0)
                return null;

            // command is first argument
            command = splitted[0];

            // select command
            switch (command)
            {
                case ChatCommandSay.KEY1:
                case ChatCommandSay.KEY2:
                    if (splitted.Length > 1)
                    {
                        text = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                        returnValue = new ChatCommandSay(text);
                    }
                    break;

                case ChatCommandEmote.KEY1:
                case ChatCommandEmote.KEY2:
                    if (splitted.Length > 1)
                    {
                        text = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                        returnValue = new ChatCommandEmote(text);
                    }
                    break;

                case ChatCommandYell.KEY1:
                case ChatCommandYell.KEY2:
                    if (splitted.Length > 1)
                    {
                        text = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                        returnValue = new ChatCommandYell(text);
                    }
                    break;

                case ChatCommandBroadcast.KEY1:
                case ChatCommandBroadcast.KEY2:
                    if (splitted.Length > 1)
                    {
                        text = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                        returnValue = new ChatCommandBroadcast(text);
                    }
                    break;

                case ChatCommandGuild.KEY1:
                case ChatCommandGuild.KEY2:
                    if (splitted.Length > 1)
                    {
                        text = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                        returnValue = new ChatCommandGuild(text);
                    }
                    break;

                case ChatCommandTell.KEY1:
                case ChatCommandTell.KEY2:
                    returnValue = ParseTell(splitted, lower, DataController);
                    break;

                case ChatCommandCast.KEY1:
                case ChatCommandCast.KEY2:
                    returnValue = ParseCast(splitted, lower, DataController);
                    break;

                case ChatCommandDeposit.KEY1:
                    if (splitted.Length == 2)
                    {
                        uint amount = 0;

                        if (UInt32.TryParse(splitted[1], out amount))
                            returnValue = new ChatCommandDeposit(amount);
                    }
                    break;

                case ChatCommandWithDraw.KEY1:
                    if (splitted.Length == 2)
                    {
                        uint amount = 0;

                        if (UInt32.TryParse(splitted[1], out amount))
                            returnValue = new ChatCommandWithDraw(amount);
                    }
                    break;

                case ChatCommandSuicide.KEY1:
                    if (splitted.Length == 1)
                    {
                        returnValue = new ChatCommandSuicide();
                    }
                    break;

                case ChatCommandDM.KEY1:
                    if (splitted.Length > 1)
                    {
                        text = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                        returnValue = new ChatCommandDM(text);
                    }
                    break;

                case ChatCommandGo.KEY1:
                case ChatCommandGo.KEY2:
                    if (splitted.Length > 1)
                    {
                        text = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                        returnValue = new ChatCommandGo(text);
                    }
                    break;

                case ChatCommandGoPlayer.KEY1:
                    returnValue = ParseGoPlayer(splitted, lower, DataController);
                    break;

                case ChatCommandGetPlayer.KEY1:
                    returnValue = ParseGetPlayer(splitted, lower, DataController);
                    break;

                case ChatCommandRest.KEY1:
                    returnValue = new ChatCommandRest();
                    break;

                case ChatCommandStand.KEY1:
                    returnValue = new ChatCommandStand();
                    break;

                case ChatCommandQuit.KEY1:
                    returnValue = new ChatCommandQuit();
                    break;
            #if !VANILLA
                case ChatCommandTempSafe.KEY1:
                    returnValue = ParseTempSafe(splitted, lower, DataController);
                    break;

                case ChatCommandGrouping.KEY1:
                    returnValue = ParseGrouping(splitted, lower, DataController);
                    break;
            #endif
            }

            return returnValue;
        }
コード例 #3
0
        /// <summary>
        /// Parses a ChatCommand instance from string input and available data.
        /// </summary>
        /// <param name="Text">Text input to parse</param>
        /// <param name="DataController">Reference to DataController instance</param>
        /// <returns></returns>
        public static ChatCommand Parse(string Text, DataController DataController)
        {
            string command = null;
            string lower   = null;
            string text    = null;

            string[]    splitted    = null;
            ChatCommand returnValue = null;

            // null check
            if (Text == null)
            {
                return(null);
            }

            // trim text
            lower = Text.Trim();

            // empty string check
            if (String.Equals(lower, String.Empty))
            {
                return(null);
            }

            // split up by delimiter
            splitted = lower.Split(DELIMITER);

            // check
            if (splitted.Length == 0)
            {
                return(null);
            }

            // command is first argument
            command = splitted[0];

            // select command
            switch (command)
            {
            case ChatCommandSay.KEY1:
            case ChatCommandSay.KEY2:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandSay(text);
                }
                break;

            case ChatCommandEmote.KEY1:
            case ChatCommandEmote.KEY2:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandEmote(text);
                }
                break;

            case ChatCommandYell.KEY1:
            case ChatCommandYell.KEY2:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandYell(text);
                }
                break;

            case ChatCommandBroadcast.KEY1:
            case ChatCommandBroadcast.KEY2:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandBroadcast(text);
                }
                break;

            case ChatCommandGuild.KEY1:
            case ChatCommandGuild.KEY2:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandGuild(text);
                }
                break;

            case ChatCommandTell.KEY1:
            case ChatCommandTell.KEY2:
                returnValue = ParseTell(splitted, lower, DataController);
                break;

            case ChatCommandCast.KEY1:
            case ChatCommandCast.KEY2:
                returnValue = ParseCast(splitted, lower, DataController);
                break;

            case ChatCommandWithDraw.KEY1:
                if (splitted.Length == 2)
                {
                    uint amount = 0;

                    if (UInt32.TryParse(splitted[1], out amount))
                    {
                        returnValue = new ChatCommandWithDraw(amount);
                    }
                }
                break;

            case ChatCommandSuicide.KEY1:
                if (splitted.Length == 1)
                {
                    returnValue = new ChatCommandSuicide();
                }
                break;

            case ChatCommandDM.KEY1:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandDM(text);
                }
                break;

            case ChatCommandGo.KEY1:
            case ChatCommandGo.KEY2:
                if (splitted.Length > 1)
                {
                    text        = String.Join(DELIMITER.ToString(), splitted, 1, splitted.Length - 1);
                    returnValue = new ChatCommandGo(text);
                }
                break;

            case ChatCommandGoPlayer.KEY1:
                returnValue = ParseGoPlayer(splitted, lower, DataController);
                break;

            case ChatCommandGetPlayer.KEY1:
                returnValue = ParseGetPlayer(splitted, lower, DataController);
                break;

            case ChatCommandRest.KEY1:
                returnValue = new ChatCommandRest();
                break;

            case ChatCommandStand.KEY1:
                returnValue = new ChatCommandStand();
                break;

#if !VANILLA
            case ChatCommandTempSafe.KEY1:
                returnValue = ParseTempSafe(splitted, lower, DataController);
                break;

            case ChatCommandGrouping.KEY1:
                returnValue = ParseGrouping(splitted, lower, DataController);
                break;
#endif
            }

            return(returnValue);
        }