Beispiel #1
0
        public CmdResult ExecuteXmlCommand(string cmd, object session, OutputDelegate outputDelegate)
        {
            outputDelegate = outputDelegate ?? WriteLine;
            CmdResult res = null;

            outputDelegate("<xml>");
            outputDelegate("<cmdtext>" + cmd + "</cmdtext>"); //strinbg
            outputDelegate("<output>");                       //string
            try
            {
                res = BotClient.ExecuteCommand(cmd, session, outputDelegate, CMDFLAGS.Foregrounded);
            }
            finally
            {
                string verb = GetType().Name;
                res = res ?? ACmdResult.Complete(verb, "cannot process " + cmd, false);
                outputDelegate("\n</output>");
                outputDelegate("<message>" + res.Message + "</message>");             //string
                outputDelegate("<success>" + res.Success + "</success>");             //True/False
                outputDelegate("<invalidArgs>" + res.InvalidArgs + "</invalidArgs>"); //True/False
                outputDelegate("<completedSynchronously>" + res.CompletedSynchronously + "</completedSynchronously>");
                //True/False
                outputDelegate("<isCompleted>" + res.IsCompleted + "</isCompleted>"); //True/False
                outputDelegate("</xml>");
            }
            return(res);
        }
        public CmdResult ExecuteTask(string scripttype, TextReader reader, OutputDelegate WriteLine)
        {
            var    si = ScriptManager.LoadScriptInterpreter(scripttype, this, _LispTaskInterperter);
            object o  = si.Read(scripttype, reader, WriteLine);

            if (o is CmdResult)
            {
                return((CmdResult)o);
            }
            string verb = "ExecuteTask " + scripttype;

            if (o == null)
            {
                return(ACmdResult.Complete(verb, "void", true));
            }
            if (si.Eof(o))
            {
                return(ACmdResult.Complete(verb, "EOF " + o, true));
            }
            o = si.Eval(o);
            if (o is CmdResult)
            {
                return((CmdResult)o);
            }
            verb = "ExecuteTask " + o;
            if (o == null)
            {
                return(ACmdResult.Complete(verb, "void", true));
            }
            if (si.Eof(o))
            {
                return(ACmdResult.Complete(verb, "EOF " + o, true));
            }
            return(ACmdResult.Complete(verb, "" + o, true));
        }
Beispiel #3
0
        public CmdResult ExecuteCommand(string s, object session, OutputDelegate outputDelegate, CMDFLAGS needResult)
        {
            string       verb = GetType().Name;
            StringWriter sw   = new StringWriter();

            if (s == null)
            {
                return(ACmdResult.Complete(verb, "null cmd", false));
            }
            s = s.Trim();
            if (s == "")
            {
                return(ACmdResult.Complete(verb, "empty cmd", false));
            }
            if (TheBot.useServitor)
            {
                TheBot.updateRTP2Sevitor();
                string input = s;
                string res   = "";
                input = input.Replace("aiml @withuser null -", "");
                input = input.Replace("withuser null", "");
                input = input.Replace("aiml @", "");
                input = input.Replace("- ?", "");
                bool r = true;
                TheBot.servitor.curBot.saySapi      = true;
                TheBot.servitor.curBot.sayProcessor = new sayProcessorDelegate(webSayResponse);
                if (input.Length > 1)
                {
                    res = TheBot.servitor.respondToChat(input, TheBot.LastUser);
                    if ((res != null) && (res.Length > 0))
                    {
                        responseQueue.Enqueue(res);
                    }
                    res = "";
                    // Give the servitor a chance to do something;
                    int ticks = 0;
                    while ((ticks < 25) && (responseQueue.Count == 0))
                    {
                        Thread.Sleep(200);
                        ticks++;
                    }
                    while (responseQueue.Count > 0)
                    {
                        res += responseQueue.Dequeue() + " ";
                    }
                    if (outputDelegate != null)
                    {
                        outputDelegate(res);
                    }
                    WriteLine(res);
                    TheBot.updateServitor2RTP();
                }
                else
                {
                    res = "";
                    // Give the servitor a chance to do something;
                    int ticks = 0;
                    while ((ticks < 3) && (responseQueue.Count == 0))
                    {
                        Thread.Sleep(200);
                        ticks++;
                    }
                    while (responseQueue.Count > 0)
                    {
                        res += responseQueue.Dequeue() + " ";
                    }
                    if (outputDelegate != null)
                    {
                        outputDelegate(res);
                    }
                    WriteLine(res);
                }
                return(ACmdResult.Complete(verb, res, r));
            }
            else
            {
                if (s.StartsWith("aiml"))
                {
                    s = s.Substring(4).Trim();
                    if (s.StartsWith("@ "))
                    {
                        s = "@withuser" + s.Substring(1);
                    }
                }
                if (!s.StartsWith("@"))
                {
                    s = "@" + s;
                }
                //     sw.WriteLine("AIMLTRACE " + s);
                User myUser = null;// TheBot.LastUser;
                //OutputDelegate del = outputDelegate ?? sw.WriteLine;
                bool r = TheBot.BotDirective(myUser, s, sw.WriteLine);
                sw.Flush();
                string res = sw.ToString();
                // for now legacy
                //res = res.Replace("menevalue=", "mene value=");
                if (outputDelegate != null)
                {
                    outputDelegate(res);
                }
                WriteLine(res);
                return(ACmdResult.Complete(verb, res, r));
            }
        }
        public CmdResult ExecuteBotCommand(string text, object session, OutputDelegate WriteLine, CMDFLAGS needResult)
        {
            text = ClientManager.GetCommandText(text);
            try
            {
                if (text.StartsWith("("))
                {
                    InvokeJoin("ExecuteBotCommand " + text);
                    return(ACmdResult.Complete("evalLispString", evalLispString(text).ToString(), true));
                }

                text = text.Replace("\"", "").Replace("  ", " ");
                string verb = text.Split(' ')[0];
                verb = verb.ToLower();

                Command act = GetCommand(verb, false);
                if (act != null)
                {
                    if (act is GridMasterCommand)
                    {
                        if (!WorldSystem.IsGridMaster)
                        {
                            throw new NoSuchCommand("I am not gridMaster " + text + ".");
                            return(null);
                        }
                    }
                    if (act is RegionMasterCommand)
                    {
                        if (!IsRegionMaster)
                        {
                            throw new NoSuchCommand("I am not regionMaster " + text + ".");
                            return(null);
                        }
                    }
                    try
                    {
                        string args = (text.Length > verb.Length) ? text.Substring(verb.Length + 1) : "";
                        return(DoCmdAct(act, verb, args, session, WriteLine, needResult));
                    }
                    catch (Exception e)
                    {
                        if (e is NoSuchCommand)
                        {
                            throw e;
                        }
                        LogException("ExecuteBotCommand Command " + text, e);
                        return(ACmdResult.Complete("ExecuteBotCommand", "ExecuteBotCommand " + text + "cuased " + e, false));
                    }
                }
                else
                {
                    if (WorldSystem == null || WorldSystem.SimAssetSystem == null)
                    {
                        return(ACmdResult.Complete(verb, "no world yet for gesture", false));
                    }
                    UUID assetID = WorldSystem.SimAssetSystem.GetAssetUUID(text, AssetType.Gesture);
                    if (assetID != UUID.Zero)
                    {
                        return(ExecuteBotCommand("play " + assetID, session, WriteLine, needResult));
                    }
                    assetID = WorldSystem.SimAssetSystem.GetAssetUUID(text, AssetType.Unknown);
                    if (assetID != UUID.Zero)
                    {
                        return(ExecuteBotCommand("play " + assetID, session, WriteLine, needResult));
                    }
                    throw new NoSuchCommand(verb);
                }
            }
            catch (Exception e)
            {
                if (e is NoSuchCommand)
                {
                    throw e;
                }
                LogException("ExecuteBotCommand " + text, e);
                return(null);
            }
        }