Exemple #1
0
        public static void MainParser(mcPage aPage, string CommandString)
        {
            System.Reflection.MethodInfo m;
            Type t;
            string CurrentLine;
            string[] Lines;
            string MyCmd;
            string Parameters;
            int i;
            int a;

            CommandString = CommandString.Replace('\r','\n');
            Lines = CommandString.Split('\n');

            for(i = 0; i < Lines.Length; i++)
            {
                CurrentLine = Lines[i];
                if(CurrentLine.Length < 1)
                    continue;
                if(CurrentLine[0] == '/')
                {
                    a = CurrentLine.IndexOf(" ");
                    if (a == -1)
                    {
                        //one-word command, no params
                        MyCmd = CurrentLine.Substring(1);
                        Parameters = null;
                    }
                    else
                    {
                        //more complex :/
                        MyCmd = CurrentLine.Substring(1, a - 1);
                        Parameters = CurrentLine.Substring(a);
                    }
                    /* Try and invoke it now. */
                    mcCommands MyScript = new mcCommands();
                    t = MyScript.GetType();
                    m = t.GetMethod("cmd" + MyCmd, BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.IgnoreCase | BindingFlags.Public);
                    if (m == null)
                    {
                        /* no command, send it raw. */
                        aPage.Server.IRCSend(MyCmd + " " + Parameters);
                    }
                    else
                    {
                        try
                        {
                            object[] anObj = new object[] {aPage, Parameters};
                            m.Invoke(null, anObj);
                            anObj = null;
                        }
                        catch (TargetInvocationException ex)
                        {
                            aPage.MessageInfo("Scripting error, error dump follows:");
                            aPage.MessageInfo(ex.ToString());
                        }
                    }
                }
                else
                {
                    cmdSay(aPage, CurrentLine);
                }
            }
        }
Exemple #2
0
        public static void MainParser(mcPage aPage, string CommandString)
        {
            System.Reflection.MethodInfo m;
            Type   t;
            string CurrentLine;

            string[] Lines;
            string   MyCmd;
            string   Parameters;
            int      i;
            int      a;

            CommandString = CommandString.Replace('\r', '\n');
            Lines         = CommandString.Split('\n');

            for (i = 0; i < Lines.Length; i++)
            {
                CurrentLine = Lines[i];
                if (CurrentLine.Length < 1)
                {
                    continue;
                }
                if (CurrentLine[0] == '/')
                {
                    a = CurrentLine.IndexOf(" ");
                    if (a == -1)
                    {
                        //one-word command, no params
                        MyCmd      = CurrentLine.Substring(1);
                        Parameters = null;
                    }
                    else
                    {
                        //more complex :/
                        MyCmd      = CurrentLine.Substring(1, a - 1);
                        Parameters = CurrentLine.Substring(a);
                    }
                    /* Try and invoke it now. */
                    mcCommands MyScript = new mcCommands();
                    t = MyScript.GetType();
                    m = t.GetMethod("cmd" + MyCmd, BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.IgnoreCase | BindingFlags.Public);
                    if (m == null)
                    {
                        /* no command, send it raw. */
                        aPage.Server.IRCSend(MyCmd + " " + Parameters);
                    }
                    else
                    {
                        try
                        {
                            object[] anObj = new object[] { aPage, Parameters };
                            m.Invoke(null, anObj);
                            anObj = null;
                        }
                        catch (TargetInvocationException ex)
                        {
                            aPage.MessageInfo("Scripting error, error dump follows:");
                            aPage.MessageInfo(ex.ToString());
                        }
                    }
                }
                else
                {
                    cmdSay(aPage, CurrentLine);
                }
            }
        }