Exemplo n.º 1
0
 /// <summary>
 /// Prepares the tag system.
 /// </summary>
 public void Init(Commands _system)
 {
     CommandSystem = _system;
     Register(new ColorTags());
     Register(new CVarTags());
     Register(new EscapeTags());
     Register(new ListTags());
     Register(new TernaryTags());
     Register(new TextTags());
     Register(new UnescapeTags());
     Register(new UtilTags());
     Register(new VarTags());
     // TODO: CVars, ...
 }
Exemplo n.º 2
0
 /// <summary>
 /// Converts a list of command strings to a CommandEntry list, handling any { braced } blocks inside.
 /// </summary>
 /// <param name="from">The command strings.</param>
 /// <param name="entry">The entry that owns this block.</param>
 /// <param name="system">The command system to create this block inside.</param>
 /// <returns>A list of entries with blocks separated.</returns>
 public static List<CommandEntry> CreateBlock(List<string> from, CommandEntry entry, Commands system)
 {
     List<CommandEntry> toret = new List<CommandEntry>();
     List<string> Temp = null;
     int blocks = 0;
     for (int i = 0; i < from.Count; i++)
     {
         if (from[i] == "{")
         {
             blocks++;
             if (blocks == 1)
             {
                 Temp = new List<string>();
             }
             else
             {
                 Temp.Add("{");
             }
         }
         else if (from[i] == "}")
         {
             blocks--;
             if (blocks == 0)
             {
                 if (toret.Count == 0)
                 {
                     List<CommandEntry> block = CreateBlock(Temp, entry, system);
                     toret.AddRange(block);
                 }
                 else
                 {
                     List<CommandEntry> block = CreateBlock(Temp, toret[toret.Count - 1], system);
                     toret[toret.Count - 1].Block = block;
                 }
             }
             else if (blocks < 0)
             {
                 blocks = 0;
             }
             else
             {
                 Temp.Add("}");
             }
         }
         else if (blocks > 0)
         {
             Temp.Add(from[i]);
         }
         else
         {
             CommandEntry centry = CommandEntry.FromInput(from[i], null, entry, system);
             if (centry != null)
             {
                 toret.Add(centry);
             }
         }
     }
     if (toret.Count == 0 && entry != null)
     {
         return null;
     }
     return toret;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a new queue for this script.
 /// </summary>
 /// <param name="system">The command system to make the queue in.</param>
 /// <returns>The created queue.</returns>
 public CommandQueue ToQueue(Commands system)
 {
     CommandQueue queue = new CommandQueue(this, GetEntries(), system);
     queue.Debug = Debug;
     return queue;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Separates a string list of command inputs (separated by newlines, semicolons, ...)
 /// and returns a queue object containing all the input commands
 /// </summary>
 /// <param name="name">The name of the script.</param>
 /// <param name="commands">The command string to parse.</param>
 /// <param name="system">The command system to create the script within.</param>
 /// <returns>A list of command strings.</returns>
 public static CommandScript SeparateCommands(string name, string commands, Commands system)
 {
     List<string> CommandList = new List<string>();
     int start = 0;
     bool quoted = false;
     for (int i = 0; i < commands.Length; i++)
     {
         if (commands[i] == '"')
         {
             quoted = !quoted;
         }
         else if ((commands[i] == '\n') || (!quoted && commands[i] == ';'))
         {
             if (start < i)
             {
                 CommandList.Add(commands.Substring(start, i - start).Trim());
             }
             start = i + 1;
             quoted = false;
         }
     }
     if (start < commands.Length)
     {
         CommandList.Add(commands.Substring(start).Trim());
     }
     return new CommandScript(name, CreateBlock(CommandList, null, system));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a script by file name.
 /// File is /scripts/filename.cfg
 /// </summary>
 /// <param name="filename">The name of the file to execute.</param>
 /// <param name="system">The command system to get the script for.</param>
 /// <returns>A command script, or null of the file does not exist.</returns>
 public static CommandScript GetByFileName(string filename, Commands system)
 {
     try
     {
         string fname = filename + ".cfg";
         return SeparateCommands(filename, system.Output.ReadTextFile(fname), system);
     }
     catch (System.IO.FileNotFoundException)
     {
         return null;
     }
     catch (Exception ex)
     {
         system.Output.Bad("Generating script for file '" + TagParser.Escape(filename)
             + "': " + TagParser.Escape(ex.ToString()), DebugMode.NONE);
         return null;
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Constructs a new CommandQueue - generally kept to the Frenetic internals.
 /// TODO: IList _commands -> ListQueue?
 /// </summary>
 public CommandQueue(CommandScript _script, IList<CommandEntry> _commands, Commands _system)
 {
     Script = _script;
     CommandList = new ListQueue<CommandEntry>(_commands);
     CommandSystem = _system;
     Variables = new Dictionary<string, TemplateObject>();
     Debug = DebugMode.FULL;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Constructs the script event's base data.
 /// Called only by implementing script events.
 /// </summary>
 /// <param name="_system">The command system this event exists within.</param>
 /// <param name="_name">The name of the event.</param>
 /// <param name="cancellable">Whether the event can be cancelled.</param>
 public ScriptEvent(Commands _system, string _name, bool cancellable)
 {
     System = _system;
     Name = _name.ToLower();
     Cancellable = cancellable;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a CommandEntry from the given input and queue information.
 /// </summary>
 /// <param name="command">The command line text itself.</param>
 /// <param name="_block">The command block that held this entry.</param>
 /// <param name="_owner">The command entry that owns the block that held this entry.</param>
 /// <param name="system">The command system to work from.</param>
 /// <returns>The command system.</returns>
 public static CommandEntry FromInput(string command, List<CommandEntry> _block, CommandEntry _owner, Commands system)
 {
     if (command.StartsWith("//"))
     {
         return null;
     }
     if (command.StartsWith("/"))
     {
         command = command.Substring(1);
     }
     command = command.Replace('\0', ' ');
     List<string> args = new List<string>();
     int start = 0;
     bool quoted = false;
     for (int i = 0; i < command.Length; i++)
     {
         if (command[i] == '"')
         {
             quoted = !quoted;
         }
         else if (!quoted && command[i] == ' ' && (i - start > 0))
         {
             string arg = command.Substring(start, i - start).Trim().Replace("\"", "");
             if (arg.Length > 0)
             {
                 args.Add(arg);
             }
             start = i + 1;
         }
     }
     if (command.Length - start > 0)
     {
         string arg = command.Substring(start, command.Length - start).Trim().Replace("\"", "");
         if (arg.Length > 0)
         {
             args.Add(arg);
         }
     }
     if (args.Count == 0)
     {
         return null;
     }
     int marker = 0;
     string BaseCommand = args[0];
     if (BaseCommand.StartsWith("+") && BaseCommand.Length > 1)
     {
         marker = 1;
         BaseCommand = BaseCommand.Substring(1);
     }
     else if (BaseCommand.StartsWith("-") && BaseCommand.Length > 1)
     {
         marker = 2;
         BaseCommand = BaseCommand.Substring(1);
     }
     else if (BaseCommand.StartsWith("!") && BaseCommand.Length > 1)
     {
         marker = 3;
         BaseCommand = BaseCommand.Substring(1);
     }
     bool waitfor = false;
     if (BaseCommand.StartsWith("&") && BaseCommand.Length > 1)
     {
         waitfor = true;
         BaseCommand = BaseCommand.Substring(1);
     }
     string BaseCommandLow = BaseCommand.ToLower();
     args.RemoveAt(0);
     AbstractCommand cmd;
     if (system.RegisteredCommands.TryGetValue(BaseCommandLow, out cmd))
     {
         return new CommandEntry(command, _block, _owner, cmd, args, BaseCommand, marker) { WaitFor = waitfor };
     }
     return CreateInvalidOutput(BaseCommand, _block, args, _owner, system, command, marker, waitfor);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Create an entry that represents invalid output.
 /// </summary>
 public static CommandEntry CreateInvalidOutput(string name, List<CommandEntry> _block,
     List<string> _arguments, CommandEntry _owner, Commands system, string line, int marker, bool waitfor)
 {
     _arguments.Insert(0, name);
     return new CommandEntry(line, _block, _owner, system.DebugInvalidCommand, _arguments, name, marker) { WaitFor = waitfor };
 }