コード例 #1
0
ファイル: MarkCommand.cs プロジェクト: truency/Frenetic
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="entry">Entry to be executed.</param>
 public override void Execute(CommandEntry entry)
 {
     if (entry.Arguments.Count < 1)
     {
         ShowUsage(entry);
     }
     entry.Good("Passing mark.");
 }
コード例 #2
0
ファイル: AbstractCommand.cs プロジェクト: truency/Frenetic
 /// <summary>
 /// Displays the usage information on a command to the console.
 /// </summary>
 /// <param name="entry">The CommandEntry data to get usage help from..</param>
 public static void ShowUsage(CommandEntry entry)
 {
     entry.Bad("<{color.emphasis}>" + TagParser.Escape(entry.Command.Name) + "<{color.base}>: " + TagParser.Escape(entry.Command.Description));
     entry.Bad("<{color.cmdhelp}>Usage: /" + TagParser.Escape(entry.Name) + " " + TagParser.Escape(entry.Command.Arguments));
     if (entry.Command.IsDebug)
     {
         entry.Bad("Note: This command is intended for debugging purposes.");
     }
 }
コード例 #3
0
ファイル: DetermineCommand.cs プロジェクト: truency/Frenetic
 public override void Execute(CommandEntry entry)
 {
     string determ = null;
     if (entry.Arguments.Count > 0)
     {
         determ = entry.GetArgument(0);
     }
     entry.Queue.Determinations.Add(determ);
     entry.Good("<{color.info}>Determination of the queue set to '<{color.emphasis}>" + TagParser.Escape(determ) + "<{color.info}>'.");
 }
コード例 #4
0
ファイル: CommandEntry.cs プロジェクト: truency/Frenetic
 /// <summary>
 /// Full constructor, recommended.
 /// </summary>
 public CommandEntry(string _commandline, List<CommandEntry> _block, CommandEntry _owner,
     AbstractCommand _command, List<string> _arguments, string _name, int _marker)
 {
     CommandLine = _commandline;
     Block = _block;
     BlockOwner = _owner;
     Command = _command;
     Arguments = _arguments;
     Name = _name;
     Marker = _marker;
 }
コード例 #5
0
ファイル: EchoCommand.cs プロジェクト: truency/Frenetic
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="entry">Entry to be executed.</param>
 public override void Execute(CommandEntry entry)
 {
     if (entry.Arguments.Count < 1)
     {
         ShowUsage(entry);
     }
     else
     {
         string args = entry.AllArguments();
         entry.Info(TextStyle.Color_Simple + TagParser.Escape(args));
     }
 }
コード例 #6
0
ファイル: DefineCommand.cs プロジェクト: truency/Frenetic
 public override void Execute(CommandEntry entry)
 {
     if (entry.Arguments.Count < 2)
     {
         ShowUsage(entry);
     }
     else
     {
         string target = entry.GetArgument(0);
         string newvalue = entry.GetArgument(1);
         entry.Queue.SetVariable(target, new TextTag(newvalue));
         entry.Good("Queue variable '<{color.emphasis}>" + TagParser.Escape(target.ToLower()) +
             "<{color.base}>' set to '<{color.emphasis}>" + TagParser.Escape(newvalue) + "<{color.base}>'.");
     }
 }
コード例 #7
0
ファイル: ToggleCommand.cs プロジェクト: truency/Frenetic
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="entry">Entry to be executed.</param>
 public override void Execute(CommandEntry entry)
 {
     if (entry.Arguments.Count < 1)
     {
         ShowUsage(entry);
     }
     else
     {
         string target = entry.GetArgument(0);
         CVar cvar = entry.Output.CVarSys.Get(target);
         if (cvar == null)
         {
             entry.Bad("CVar '<{color.emphasis}>" + TagParser.Escape(cvar.Name)
                 + "<{color.base}>' does not exist!");
             return;
         }
         if (cvar.Flags.HasFlag(CVarFlag.ServerControl))
         {
             entry.Bad("CVar '<{color.emphasis}>" + TagParser.Escape(cvar.Name)
                 + "<{color.base}>' cannot be modified, it is server controlled!");
         }
         if (cvar.Flags.HasFlag(CVarFlag.ReadOnly))
         {
             entry.Bad("CVar '<{color.emphasis}>" + TagParser.Escape(cvar.Name)
                 + "<{color.base}>' cannot be modified, it is a read-only system variable!");
         }
         else if (cvar.Flags.HasFlag(CVarFlag.InitOnly) && !entry.Output.Initializing)
         {
             entry.Bad("CVar '<{color.emphasis}>" + TagParser.Escape(cvar.Name)
                 + "<{color.base}>' cannot be modified after game initialization.");
         }
         else if (cvar.Flags.HasFlag(CVarFlag.Delayed) && !entry.Output.Initializing)
         {
             cvar.Set(cvar.ValueB ? "false" : "true");
             entry.Good("<{color.info}>CVar '<{color.emphasis}>" + TagParser.Escape(cvar.Name) +
                 "<{color.info}>' is delayed, and its value will be calculated after the game is reloaded.");
         }
         else
         {
             cvar.Set(cvar.ValueB ? "false" : "true");
             entry.Good("<{color.info}>CVar '<{color.emphasis}>" + TagParser.Escape(cvar.Name) +
                 "<{color.info}>' set to '<{color.emphasis}>" + TagParser.Escape(cvar.Value) + "<{color.info}>'.");
         }
     }
 }
コード例 #8
0
ファイル: UndefineCommand.cs プロジェクト: truency/Frenetic
 public override void Execute(CommandEntry entry)
 {
     if (entry.Arguments.Count < 1)
     {
         ShowUsage(entry);
     }
     else
     {
         string target = entry.GetArgument(0);
         if (entry.Queue.Variables.ContainsKey(target.ToLower()))
         {
             entry.Queue.Variables.Remove(target.ToLower());
             entry.Good("Queue variable '<{color.emphasis}>" + TagParser.Escape(target.ToLower()) + "<{color.base}>' removed'.");
         }
         else
         {
             entry.Bad("Unknown queue variable '<{color.emphasis}>" + TagParser.Escape(target.ToLower()) + "<{color.base}>'.");
         }
     }
 }
コード例 #9
0
ファイル: GotoCommand.cs プロジェクト: truency/Frenetic
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="entry">Entry to be executed.</param>
 public override void Execute(CommandEntry entry)
 {
     if (entry.Arguments.Count < 1)
     {
         ShowUsage(entry);
         return;
     }
     string targ = entry.GetArgument(0);
     bool hasnext = false;
     for (int i = 0; i < entry.Queue.CommandList.Length; i++)
     {
         if (entry.Queue.GetCommand(i).Command is MarkCommand
             && entry.Queue.GetCommand(i).Arguments[0] == targ)
         {
             hasnext = true;
             break;
         }
     }
     if (hasnext)
     {
         entry.Good("Going to mark.");
         while (entry.Queue.CommandList.Length > 0)
         {
             if (entry.Queue.GetCommand(0).Command is MarkCommand
                 && entry.Queue.GetCommand(0).Arguments[0] == targ)
             {
                 entry.Queue.RemoveCommand(0);
                 break;
             }
             entry.Queue.RemoveCommand(0);
         }
     }
     else
     {
         entry.Bad("Cannot goto marked location: unknown marker!");
     }
 }
コード例 #10
0
ファイル: CvarinfoCommand.cs プロジェクト: truency/Frenetic
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="entry">Entry to be executed.</param>
 public override void Execute(CommandEntry entry)
 {
     if (entry.Arguments.Count < 1)
     {
         entry.Info("Listing <{color.emphasis}>" + entry.Output.CVarSys.CVars.Count + "<{color.base}> CVars...");
         for (int i = 0; i < entry.Output.CVarSys.CVars.Count; i++)
         {
             CVar cvar = entry.Output.CVarSys.CVarList[i];
             entry.Info("<{color.emphasis}>" + (i + 1).ToString() + "<{color.simple}>)<{color.emphasis}> " + TagParser.Escape(cvar.Info()));
         }
     }
     else
     {
         string target = entry.GetArgument(0).ToLower();
         List<CVar> cvars = new List<CVar>();
         for (int i = 0; i < entry.Output.CVarSys.CVars.Count; i++)
         {
             if (entry.Output.CVarSys.CVarList[i].Name.StartsWith(target))
             {
                 cvars.Add(entry.Output.CVarSys.CVarList[i]);
             }
         }
         if (cvars.Count == 0)
         {
             entry.Bad("CVar '<{color.emphasis}>" + TagParser.Escape(target) + "<{color.base}>' does not exist!");
         }
         else
         {
             entry.Info("Listing <{color.emphasis}>" + cvars.Count + "<{color.base}> CVars...");
             for (int i = 0; i < cvars.Count; i++)
             {
                 CVar cvar = cvars[i];
                 entry.Info("<{color.emphasis}>" + (i + 1).ToString() + "<{color.simple}>)<{color.emphasis}> " + TagParser.Escape(cvar.Info()));
             }
         }
     }
 }
コード例 #11
0
ファイル: NoopCommand.cs プロジェクト: truency/Frenetic
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="entry">Entry to be executed.</param>
 public override void Execute(CommandEntry entry)
 {
 }
コード例 #12
0
ファイル: SetCommand.cs プロジェクト: truency/Frenetic
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="entry">Entry to be executed.</param>
 public override void Execute(CommandEntry entry)
 {
     if (entry.Arguments.Count < 2)
     {
         ShowUsage(entry);
     }
     else
     {
         string target = entry.GetArgument(0);
         string newvalue = entry.GetArgument(1);
         string a2 = entry.Arguments.Count > 2 ? entry.GetArgument(2).ToLower(): "";
         bool force = a2 == "force";
         bool remove = a2 == "remove";
         bool do_not_save = a2 == "do_not_save";
         if (remove)
         {
             CVar Cvar = entry.Output.CVarSys.Get(target);
             if (Cvar == null)
             {
                 entry.Good("CVar '<{color.emphasis}>" + TagParser.Escape(target)
                     + "<{color.base}>' cannot be removed, it doesn't exist!");
             }
             else if (!Cvar.Flags.HasFlag(CVarFlag.UserMade))
             {
                 entry.Bad("CVar '<{color.emphasis}>" + TagParser.Escape(Cvar.Name)
                     + "<{color.base}>' cannot be removed, it wasn't user made!");
             }
             else
             {
                 Cvar.Set("");
                 entry.Output.CVarSys.CVars.Remove(Cvar.Name);
                 entry.Output.CVarSys.CVarList.Remove(Cvar);
                 entry.Good("<{color.info}>CVar '<{color.emphasis}>" + TagParser.Escape(Cvar.Name) +
                     "<{color.info}>' removed.");
             }
             return;
         }
         CVar cvar = entry.Output.CVarSys.AbsoluteSet(target, newvalue, force, do_not_save ? CVarFlag.DoNotSave: CVarFlag.None);
         if (cvar.Flags.HasFlag(CVarFlag.ServerControl) && !force)
         {
             entry.Bad("CVar '<{color.emphasis}>" + TagParser.Escape(cvar.Name)
                 + "<{color.base}>' cannot be modified, it is server controlled!");
             return;
         }
         if (cvar.Flags.HasFlag(CVarFlag.ReadOnly))
         {
             entry.Bad("CVar '<{color.emphasis}>" + TagParser.Escape(cvar.Name)
                 + "<{color.base}>' cannot be modified, it is a read-only system variable!");
         }
         else if (cvar.Flags.HasFlag(CVarFlag.InitOnly) && !entry.Output.Initializing)
         {
             entry.Bad("CVar '<{color.emphasis}>" + TagParser.Escape(cvar.Name)
                 + "<{color.base}>' cannot be modified after game initialization.");
         }
         else if (cvar.Flags.HasFlag(CVarFlag.Delayed) && !entry.Output.Initializing)
         {
             entry.Good("CVar '<{color.emphasis}>" + TagParser.Escape(cvar.Name) +
                 "<{color.base}>' is delayed, and its value will be calculated after the game is reloaded.");
         }
         else
         {
             entry.Good("CVar '<{color.emphasis}>" + TagParser.Escape(cvar.Name) +
                 "<{color.base}>' set to '<{color.emphasis}>" + TagParser.Escape(cvar.Value) + "<{color.base}>'.");
         }
     }
 }
コード例 #13
0
ファイル: AbstractCommand.cs プロジェクト: truency/Frenetic
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="entry">Entry to be executed.</param>
 public abstract void Execute(CommandEntry entry);
コード例 #14
0
ファイル: CommandScript.cs プロジェクト: truency/Frenetic
 /// <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;
 }
コード例 #15
0
ファイル: Commands.cs プロジェクト: truency/Frenetic
 /// <summary>
 /// Executes a single command.
 /// </summary>
 /// <param name="entry">The command entry to execute.</param>
 /// <param name="queue">The queue that is executing it.</param>
 public void ExecuteCommand(CommandEntry entry, CommandQueue queue)
 {
     try
     {
         entry.Queue = queue;
         entry.Output = Output;
         if (entry.Command == DebugInvalidCommand)
         {
             // Last try - perhaps a command was registered after the script was loaded.
             AbstractCommand cmd;
             if (RegisteredCommands.TryGetValue(entry.Name.ToLower(), out cmd))
             {
                 entry.Command = cmd;
             }
         }
         entry.Command.Execute(entry);
     }
     catch (Exception ex)
     {
         Output.Bad("Command '" + TextStyle.Color_Standout + TagParser.Escape(entry.CommandLine) +
             TextStyle.Color_Error + "' threw an error: " + TagParser.Escape(ex.ToString()), DebugMode.NONE);
     }
 }
コード例 #16
0
ファイル: CommandScript.cs プロジェクト: truency/Frenetic
 /// <summary>
 /// Removes an entry's ownership over the list of entries, and returns them in a new list of duplicates.
 /// </summary>
 /// <param name="entries">The list of entries.</param>
 /// <param name="baseentry">The entry that is no longer an owner.</param>
 /// <returns>The new entry list.</returns>
 public static List<CommandEntry> DisOwn(List<CommandEntry> entries, CommandEntry baseentry)
 {
     List<CommandEntry> newentries = new List<CommandEntry>();
     for (int i = 0; i < entries.Count; i++)
     {
         newentries.Add(entries[i].Duplicate());
         if (newentries[i].BlockOwner == baseentry)
         {
             newentries[i].BlockOwner = null;
         }
     }
     return newentries;
 }
コード例 #17
0
ファイル: CommandQueue.cs プロジェクト: truency/Frenetic
 /// <summary>
 /// Recalculates and advances the command queue.
 /// <param name="Delta">The time passed this tick.</param>
 /// </summary>
 public void Tick(float Delta)
 {
     if (Delayable && (LastCommand != null && LastCommand.Command.Waitable && LastCommand.WaitFor && !LastCommand.Finished))
     {
         return;
     }
     if (Delayable && Wait > 0f)
     {
         Wait -= Delta;
         if (Wait > 0f)
         {
             return;
         }
         Wait = 0f;
     }
     while (CommandList.Length > 0)
     {
         CommandEntry CurrentCommand = CommandList.Pop();
         if (CurrentCommand == null)
         {
             continue;
         }
         CommandSystem.ExecuteCommand(CurrentCommand, this);
         LastCommand = CurrentCommand;
         if (Delayable && ((Wait > 0f) || (LastCommand.Command.Waitable && LastCommand.WaitFor && !LastCommand.Finished)))
         {
             return;
         }
     }
     if (Complete != null)
     {
         Complete(this, new CommandQueueEventArgs(this));
     }
     Running = false;
 }
コード例 #18
0
ファイル: CommandEntry.cs プロジェクト: truency/Frenetic
 /// <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 };
 }
コード例 #19
0
ファイル: CommandEntry.cs プロジェクト: truency/Frenetic
 /// <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);
 }
コード例 #20
0
ファイル: CommandEntry.cs プロジェクト: truency/Frenetic
 /// <summary>
 /// Returns a duplicate of this command entry.
 /// </summary>
 /// <param name="NewOwner">The new owner of the command entry.</param>
 /// <returns>The duplicate entry.</returns>
 public CommandEntry Duplicate(CommandEntry NewOwner = null)
 {
     CommandEntry entry = new CommandEntry();
     entry.Arguments = new List<string>(Arguments);
     if (Block == null)
     {
         entry.Block = null;
     }
     else
     {
         entry.Block = new List<CommandEntry>();
         for (int i = 0; i < Block.Count; i++)
         {
             entry.Block.Add(Block[i].Duplicate(entry));
         }
     }
     entry.BlockOwner = NewOwner;
     entry.Command = Command;
     entry.CommandLine = CommandLine;
     entry.Name = Name;
     entry.Output = Output;
     entry.Queue = Queue;
     if (Data != null)
     {
         entry.Data = Data.Duplicate();
     }
     else
     {
         entry.Data = null;
     }
     entry.Marker = Marker;
     return entry;
 }