Example #1
0
 /// <summary>
 /// Executes the run command.
 /// </summary>
 /// <param name="entry">The command details to be ran.</param>
 public override void Execute(CommandEntry entry)
 {
     if (entry.Arguments.Count < 1)
     {
         ShowUsage(entry);
         entry.Finished = true;
         return;
     }
     string fname = entry.GetArgument(0).ToLower();
     ScriptRanPreEventArgs args = new ScriptRanPreEventArgs();
     args.ScriptName = fname;
     if (OnScriptRanPreEvent != null)
     {
         OnScriptRanPreEvent.Fire(args);
     }
     if (args.Cancelled)
     {
         entry.Bad("Script running cancelled via the ScriptRanPreEvent.");
         return;
     }
     CommandScript script = entry.Queue.CommandSystem.GetScript(args.ScriptName);
     if (script != null)
     {
         ScriptRanEventArgs args2 = new ScriptRanEventArgs();
         args2.Script = script;
         if (OnScriptRanEvent != null)
         {
             OnScriptRanEvent.Fire(args2);
         }
         if (args2.Cancelled)
         {
             entry.Bad("Script running cancelled via the ScriptRanEvent.");
             return;
         }
         if (script == null)
         {
             entry.Bad("Script running nullified via the ScriptRanEvent.");
             return;
         }
         script = args2.Script;
         entry.Good("Running '<{color.emphasis}>" + TagParser.Escape(fname) + "<{color.base}>'...");
         CommandQueue queue;
         entry.Queue.CommandSystem.ExecuteScript(script, null, out queue);
         if (!queue.Running)
         {
             entry.Finished = true;
         }
         else
         {
             EntryFinisher fin = new EntryFinisher() { Entry = entry };
             queue.Complete += fin.Complete;
         }
         ScriptRanPostEventArgs args4 = new ScriptRanPostEventArgs();
         args4.Script = script;
         args4.Determinations = new List<string>(queue.Determinations);
         if (OnScriptRanPostEvent != null)
         {
             OnScriptRanPostEvent.Fire(args4);
         }
         ListTag list = new ListTag(queue.Determinations);
         entry.Queue.SetVariable("run_determinations", list);
     }
     else
     {
         entry.Bad("Cannot run script '<{color.emphasis}>" + TagParser.Escape(fname) + "<{color.base}>': file does not exist!");
         entry.Finished = true;
     }
 }
Example #2
0
 public override void Execute(CommandEntry entry)
 {
     if (entry.Arguments.Count < 2)
     {
         ShowUsage(entry);
     }
     else
     {
         string type = entry.GetArgument(0).ToLower();
         bool run = false;
         if (type == "run")
         {
             run = true;
         }
         else if (type == "inject")
         {
             run = false;
         }
         else
         {
             ShowUsage(entry);
             return;
         }
         string fname = entry.GetArgument(1);
         if (fname == "\0CALLBACK")
         {
             return;
         }
         fname = fname.ToLower();
         CommandScript script = entry.Queue.CommandSystem.GetFunction(fname);
         if (script != null)
         {
             entry.Good("Calling '<{color.emphasis}>" + TagParser.Escape(fname) + "<{color.base}>' (" + (run ? "run": "inject") + ")...");
             List<CommandEntry> block = script.GetEntries();
             block.Add(new CommandEntry("call \0CALLBACK", null, entry,
                     this, new List<string> { "\0CALLBACK" }, "call", 0));
             if (run)
             {
                 CommandQueue queue;
                 entry.Queue.CommandSystem.ExecuteScript(script, null, out queue);
                 if (!queue.Running)
                 {
                     entry.Finished = true;
                 }
                 else
                 {
                     EntryFinisher fin = new EntryFinisher() { Entry = entry };
                     queue.Complete += new EventHandler<CommandQueueEventArgs>(fin.Complete);
                 }
                 ListTag list = new ListTag(queue.Determinations);
                 entry.Queue.SetVariable("call_determinations", list);
             }
             else
             {
                 entry.Queue.AddCommandsNow(block);
             }
         }
         else
         {
             entry.Bad("Cannot call function '<{color.emphasis}>" + TagParser.Escape(fname) + "<{color.base}>': it does not exist!");
         }
     }
 }