public override void Execute(CommandEntry entry) { if (entry.Arguments.Count < 1) { ShowUsage(entry); } else { string modechoice = entry.GetArgument(0); switch (modechoice.ToLower()) { case "full": entry.Queue.Debug = DebugMode.FULL; entry.Good("Queue debug mode set to <{color.emphasis}>full<{color.base}>."); break; case "minimal": entry.Queue.Debug = DebugMode.MINIMAL; entry.Good("Queue debug mode set to <{color.emphasis}>minimal<{color.base}>."); break; case "none": entry.Queue.Debug = DebugMode.NONE; entry.Good("Queue debug mode set to <{color.emphasis}>none<{color.base}>."); break; default: entry.Bad("Unknown debug mode '<{color.emphasis}>" + modechoice + "<{color.base}>'."); break; } } }
public override void Execute(CommandQueue queue, CommandEntry entry) { if (entry.Arguments.Count < 1) { ShowUsage(queue, entry); return; } ListTag list = ListTag.For(entry.GetArgument(queue, 0)); string message = "Kicked by the server."; if (entry.Arguments.Count >= 2) { message = "Kicked by the server: " + entry.GetArgument(queue, 1); } for (int i = 0; i < list.ListEntries.Count; i++) { PlayerEntity pl = TheServer.GetPlayerFor(list.ListEntries[i].ToString()); if (pl == null) { entry.Bad(queue, "Unknown player " + TagParser.Escape(list.ListEntries[i].ToString())); } else { pl.Kick(message); } } }
public override void Execute(CommandQueue queue, CommandEntry entry) { if (entry.Arguments.Count < 1) { ShowUsage(queue, entry); return; } Location start = TheClient.Player.GetEyePosition(); Location forward = TheClient.Player.ForwardVector(); Location end = start + forward * 5; switch (entry.GetArgument(queue, 0).ToLowerFast()) { case "cylinder": TheClient.Particles.Engine.AddEffect(ParticleEffectType.CYLINDER, (o) => start, (o) => end, (o) => 0.01f, 5f, Location.One, Location.One, true, TheClient.Textures.GetTexture("common/smoke")); break; case "line": TheClient.Particles.Engine.AddEffect(ParticleEffectType.LINE, (o) => start, (o) => end, (o) => 1f, 5f, Location.One, Location.One, true, TheClient.Textures.GetTexture("common/smoke")); break; case "explosion_small": TheClient.Particles.Explode(end, 2, 40); break; case "explosion_large": TheClient.Particles.Explode(end, 5); break; case "path_mark": TheClient.Particles.PathMark(end, () => TheClient.Player.GetPosition()); break; default: entry.Bad(queue, "Unknown effect name."); return; } entry.Good(queue, "Created effect."); }
public override void Execute(CommandQueue queue, CommandEntry entry) { if (entry.Arguments.Count < 1) { entry.Bad(queue, "Must specify a slot number!"); return; } if (TheClient.Player.ServerFlags.HasFlag(YourStatusFlags.RELOADING)) { return; } int slot = Math.Abs(Utilities.StringToInt(entry.GetArgument(queue, 0))) % (TheClient.Items.Count + 1); TheClient.SetHeldItemSlot(slot, DEFAULT_RENDER_EXTRA_ITEMS); }
public override void Execute(CommandEntry entry) { int count = 1; if (entry.Arguments.Count > 0) { count = StringToInt(entry.GetArgument(0)); } if (count <= 0) { ShowUsage(entry); return; } CommandEntry Owner = entry.BlockOwner; while (entry.Queue.CommandList.Length > 0 && count > 0) { if (Owner == null) { entry.Bad("Tried to break <{color.emphasis}>" + count + "<{color.base}> more brace" + (count == 1 ? "" : "s") + " than there are!"); return; } CommandEntry compOwner = entry.Queue.GetCommand(0).BlockOwner; if (compOwner == Owner) { entry.Queue.RemoveCommand(0); } else { Owner = compOwner; count--; } } count--; if (count > 0) { entry.Bad("Tried to break <{color.emphasis}>" + count + "<{color.base}> more brace" + (count == 1 ? "": "s") + " than there are!"); } else { entry.Good("Broke through all layers."); } }
public override void Execute(CommandEntry entry) { if (entry.Marker == 0) { entry.Bad("Must use +, -, or !"); } else if (entry.Marker == 1) { ClientMain.ThePlayer.Downward = true; } else if (entry.Marker == 2) { ClientMain.ThePlayer.Downward = false; } else if (entry.Marker == 3) { ClientMain.ThePlayer.Downward = !ClientMain.ThePlayer.Downward; } }
public override void Execute(CommandEntry entry) { if (entry.Arguments.Count < 1) { ShowUsage(entry); } else { string fname = entry.GetArgument(0); CommandScript script = entry.Queue.CommandSystem.GetScript(fname); if (script != null) { entry.Good("Inserting '<{color.emphasis}>" + TagParser.Escape(fname) + "<{color.base}>'..."); entry.Queue.AddCommandsNow(script.GetEntries()); } else { entry.Bad("Cannot insert script '<{color.emphasis}>" + TagParser.Escape(fname) + "<{color.base}>': file does not exist!"); } } }
public override void Execute(CommandEntry entry) { if (entry.Arguments.Count < 1) { ShowUsage(entry); } else { string delay = entry.GetArgument(0); float seconds = StringToFloat(delay); if (entry.Queue.Delayable) { entry.Good("Delaying for <{color.emphasis}>" + seconds + "<{color.base}> seconds."); entry.Queue.Wait = seconds; } else { entry.Bad("Cannot delay, inside an instant queue!"); } } }
public static void Execute(CommandQueue queue, CommandEntry entry) { if (entry.Arguments.Count < 1) { ShowUsage(queue, entry); return; } Client TheClient = (entry.Command as TesteffectCommand).TheClient; Location start = TheClient.Player.GetEyePosition(); Location forward = TheClient.Player.ForwardVector(); Location end = start + forward * 5; switch (entry.GetArgument(queue, 0).ToLowerFast()) { case "cylinder": TheClient.Particles.Engine.AddEffect(ParticleEffectType.CYLINDER, (o) => start, (o) => end, (o) => 0.01f, 5f, Location.One, Location.One, true, TheClient.Textures.GetTexture("common/smoke")); break; case "line": TheClient.Particles.Engine.AddEffect(ParticleEffectType.LINE, (o) => start, (o) => end, (o) => 1f, 5f, Location.One, Location.One, true, TheClient.Textures.GetTexture("common/smoke")); break; case "explosion_small": TheClient.Particles.Explode(end, 2, 40); break; case "explosion_large": TheClient.Particles.Explode(end, 5); break; case "path_mark": TheClient.Particles.PathMark(end, () => TheClient.Player.GetPosition()); break; default: entry.Bad(queue, "Unknown effect name."); return; } entry.Good(queue, "Created effect."); }
public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry) { PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0)); bool primary = entry.GetArgument(queue, 1) == "primary"; bool start = BooleanTag.TryFor(entry.GetArgumentObject(queue, 2)).Internal; if (player.Internal.player.equipment.useable == null) { entry.Bad(queue, "Failed to use item, holding nothing."); return; } if (primary) { if (start) { player.Internal.player.equipment.useable.startPrimary(); } else { player.Internal.player.equipment.useable.stopPrimary(); } } else { if (start) { player.Internal.player.equipment.useable.startSecondary(); } else { player.Internal.player.equipment.useable.stopSecondary(); } } player.Internal.player.equipment.useable.tick(); player.Internal.player.equipment.useable.tock(player.Internal.player.input.clock); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Player is " + (start ? "now" : "no longer") + " using the " + (primary ? "primary" : "secondary") + " mode on their held item!"); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0)); bool primary = entry.GetArgument(queue, 1) == "primary"; bool start = BooleanTag.TryFor(entry.GetArgumentObject(queue, 2)).Internal; if (player.Internal.player.equipment.useable == null) { entry.Bad(queue, "Failed to use item, holding nothing."); return; } if (primary) { if (start) { player.Internal.player.equipment.useable.startPrimary(); } else { player.Internal.player.equipment.useable.stopPrimary(); } } else { if (start) { player.Internal.player.equipment.useable.startSecondary(); } else { player.Internal.player.equipment.useable.stopSecondary(); } } player.Internal.player.equipment.useable.tick(); player.Internal.player.equipment.useable.tock(player.Internal.player.input.clock); if (entry.ShouldShowGood(queue)) { entry.Good(queue, "Player is " + (start ? "now" : "no longer") + " using the " + (primary ? "primary" : "secondary") + " mode on their held item!"); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { if (entry.Arguments.Count < 1) { ShowUsage(queue, entry); return; } string arg = entry.GetArgument(queue, 0).ToLowerFast(); bool success = false; bool is_all = arg == "all"; bool is_textures = arg == "textures"; bool is_blocks = arg == "blocks"; if (is_textures || is_all) { success = true; TheClient.Textures.Empty(); TheClient.Textures.InitTextureSystem(TheClient.Files); } if (is_blocks || is_textures || is_all) { success = true; MaterialHelpers.Populate(TheClient.Files); // TODO: Delay TBlock generation with time! TheClient.TBlock.Generate(TheClient, TheClient.CVars, TheClient.Textures, true); } if (arg == "chunks" || is_blocks || is_textures || is_all) { // TODO: Efficiency of this method! // TODO: Ensure this method allows for success = true; TheClient.TheRegion.RenderingNow.Clear(); Location pos = TheClient.Player.GetPosition(); double delay = 0.0; double adder = 5.0 / TheClient.TheRegion.LoadedChunks.Count; Vector3i lpos = Vector3i.Zero; double ldelay = 0.0; foreach (Chunk chunk in TheClient.TheRegion.LoadedChunks.Values.OrderBy((c) => (c.WorldPosition.ToLocation() * new Location(Constants.CHUNK_WIDTH)).DistanceSquared_Flat(pos))) { delay += adder; if (chunk.WorldPosition != lpos) { ldelay = delay; lpos = chunk.WorldPosition; } TheClient.Schedule.ScheduleSyncTask(() => { if (chunk.IsAdded) { chunk.OwningRegion.UpdateChunk(chunk); } }, ldelay); } } if (arg == "screen" || is_all) { success = true; TheClient.UpdateWindow(); } if (arg == "shaders" || is_all) { success = true; TheClient.Shaders.Clear(); TheClient.ShadersCheck(); } if (arg == "audio" || is_all) { success = true; TheClient.Sounds.Init(TheClient, TheClient.CVars); } if (!success) { entry.Bad(queue, "Invalid argument."); } else { entry.Good(queue, "Successfully reloaded specified values."); } }
public override void Execute(CommandQueue queue, CommandEntry entry) { if (entry.Marker == 0 || entry.Marker == 3) { queue.HandleError(entry, "Must use + or -"); } else if (TheClient.Player.ServerFlags.HasFlag(YourStatusFlags.RELOADING)) { return; } else if (entry.Marker == 1) { if (entry.Arguments.Count < 1) { entry.Bad(queue, "Must specify a use type and a slot number!"); return; } if (TheClient.PrevQuickItem != -1) { return; } string useType = entry.GetArgument(queue, 0).ToLowerFast(); if (useType != "hold" && useType != "throw" && useType != "click" && useType != "alt" && useType != "drop") { entry.Bad(queue, "Invalid use type!"); return; } TheClient.PrevQuickItem = TheClient.QuickBarPos; TheClient.QuickItemUseType = useType; int slot = Math.Abs(Utilities.StringToInt(entry.GetArgument(queue, 1))) % (TheClient.Items.Count + 1); TheClient.SetHeldItemSlot(slot); switch (useType) { case "hold": break; case "throw": break; case "click": TheClient.Player.Click = true; break; case "alt": TheClient.Player.AltClick = true; break; case "drop": break; } } else if (entry.Marker == 2) { if (TheClient.PrevQuickItem == -1) { return; } TheClient.SetHeldItemSlot(TheClient.PrevQuickItem); TheClient.PrevQuickItem = -1; switch (TheClient.QuickItemUseType) { case "hold": break; case "throw": break; case "click": TheClient.Player.Click = false; break; case "alt": TheClient.Player.AltClick = false; break; case "drop": break; } } }
public override void Execute(CommandQueue queue, CommandEntry entry) { if (entry.Arguments.Count < 1) { ShowUsage(queue, entry); return; } string arg = entry.GetArgument(queue, 0).ToLowerFast(); bool success = false; bool is_all = arg == "all"; if (arg == "blocks" || is_all) { success = true; MaterialHelpers.Populate(TheClient.Files); TheClient.TBlock.Generate(TheClient, TheClient.CVars, TheClient.Textures); TheClient.TheRegion.RenderingNow.Clear(); foreach (Chunk chunk in TheClient.TheRegion.LoadedChunks.Values) { chunk.OwningRegion.UpdateChunk(chunk); } } if (arg == "chunks" || is_all) { success = true; TheClient.TheRegion.RenderingNow.Clear(); foreach (Chunk chunk in TheClient.TheRegion.LoadedChunks.Values) { chunk.OwningRegion.UpdateChunk(chunk); } } if (arg == "screen" || is_all) { success = true; TheClient.UpdateWindow(); } if (arg == "shaders" || is_all) { success = true; TheClient.Shaders.Clear(); TheClient.ShadersCheck(); } if (arg == "audio" || is_all) { success = true; TheClient.Sounds.Init(TheClient, TheClient.CVars); } if (arg == "textures" || is_all) { success = true; TheClient.Textures.Empty(); TheClient.Textures.InitTextureSystem(TheClient); TheClient.TBlock.Generate(TheClient, TheClient.CVars, TheClient.Textures); } if (!success) { entry.Bad(queue, "Invalid argument."); } else { entry.Good(queue, "Successfully reloaded specified values."); } }
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!"); } } }
public override void Execute(CommandEntry entry) { if (entry.Arguments.Count < 1) { ShowUsage(entry); } else { string type = entry.GetArgument(0); if (type == "\0CALLBACK") { if (entry.BlockOwner.Command.Name == "foreach" || entry.BlockOwner.Block == null || entry.BlockOwner.Block.Count == 0 || entry.BlockOwner.Block[entry.BlockOwner.Block.Count - 1] != entry) { ForeachCommandData data = (ForeachCommandData)entry.BlockOwner.Data; data.Index++; if (data.Index > data.List.Count) { entry.Good("Foreach loop ending, reached target."); } else { entry.Good("Foreach loop continuing at index <{color.emphasis}>" + data.Index + "/" + data.List.Count + "<{color.base}>..."); entry.Queue.SetVariable("foreach_index", new TextTag(data.Index.ToString())); entry.Queue.SetVariable("foreach_total", new TextTag(data.List.Count.ToString())); entry.Queue.SetVariable("foreach_value", data.List[data.Index - 1]); entry.Queue.SetVariable("foreach_list", new ListTag(data.List)); entry.Queue.AddCommandsNow(entry.BlockOwner.Block); } } else { entry.Bad("Foreach CALLBACK invalid: not a real callback!"); } } else if (type.ToLower() == "stop") { bool hasnext = false; for (int i = 0; i < entry.Queue.CommandList.Length; i++) { if (entry.Queue.GetCommand(i).Command is ForeachCommand && entry.Queue.GetCommand(i).Arguments[0] == "\0CALLBACK") { hasnext = true; break; } } if (hasnext) { entry.Good("Stopping foreach loop."); while (entry.Queue.CommandList.Length > 0) { if (entry.Queue.GetCommand(0).Command is ForeachCommand && entry.Queue.GetCommand(0).Arguments[0] == "\0CALLBACK") { entry.Queue.RemoveCommand(0); break; } entry.Queue.RemoveCommand(0); } } else { entry.Bad("Cannot stop foreach: not in one!"); } } else if (type.ToLower() == "next") { bool hasnext = false; for (int i = 0; i < entry.Queue.CommandList.Length; i++) { if (entry.Queue.GetCommand(0).Command is ForeachCommand && entry.Queue.GetCommand(0).Arguments[0] == "\0CALLBACK") { hasnext = true; break; } } if (hasnext) { entry.Good("Skipping to next foreach entry..."); while (entry.Queue.CommandList.Length > 0) { if (entry.Queue.GetCommand(0).Command is ForeachCommand && entry.Queue.GetCommand(0).Arguments[0] == "\0CALLBACK") { break; } entry.Queue.RemoveCommand(0); } } else { entry.Bad("Cannot stop foreach: not in one!"); } } else if (type.ToLower() == "start" && entry.Arguments.Count > 1) { ListTag list = new ListTag(entry.GetArgument(1)); int target = list.ListEntries.Count; if (target <= 0) { entry.Good("Not looping."); return; } ForeachCommandData data = new ForeachCommandData(); data.Index = 1; data.List = list.ListEntries; entry.Data = data; if (entry.Block != null) { entry.Good("Foreach looping <{color.emphasis}>" + target + "<{color.base}> times..."); CommandEntry callback = new CommandEntry("foreach \0CALLBACK", null, entry, this, new List<string> { "\0CALLBACK" }, "foreach", 0); entry.Block.Add(callback); entry.Queue.SetVariable("foreach_index", new TextTag("1")); entry.Queue.SetVariable("foreach_total", new TextTag(target.ToString())); entry.Queue.SetVariable("foreach_value", list.ListEntries[0]); entry.Queue.SetVariable("foreach_list", list); entry.Queue.AddCommandsNow(entry.Block); } else { entry.Bad("Foreach invalid: No block follows!"); } } else { ShowUsage(entry); } } }
public override void Execute(CommandEntry entry) { IfCommandData data = new IfCommandData(); data.Result = 0; entry.Data = data; if (entry.Arguments.Count < 1) { ShowUsage(entry); } else { if (entry.Arguments[0] == "\0CALLBACK") { return; } if (entry.Block == null) { entry.Bad("If invalid: No block follows!"); return; } List<string> parsedargs = new List<string>(entry.Arguments.Count); for (int i = 0; i < entry.Arguments.Count; i++) { parsedargs.Add(entry.GetArgument(i)); } bool success = TryIf(parsedargs); if (success) { entry.Good("If is true, executing..."); data.Result = 1; entry.Block.Add(new CommandEntry("if \0CALLBACK", null, entry, this, new List<string> { "\0CALLBACK" }, "if", 0)); entry.Queue.AddCommandsNow(entry.Block); } else { entry.Good("If is false, doing nothing!"); } } }
public override void Execute(CommandEntry entry) { if (entry.Arguments.Count < 1) { ShowUsage(entry); } else { string count = entry.GetArgument(0); if (count == "\0CALLBACK") { if (entry.BlockOwner.Command.Name == "while" || entry.BlockOwner.Block == null || entry.BlockOwner.Block.Count == 0 || entry.BlockOwner.Block[entry.BlockOwner.Block.Count - 1] != entry) { WhileCommandData data = (WhileCommandData)entry.BlockOwner.Data; data.Index++; List<string> comp = new List<string>(); for (int i = 0; i < data.ComparisonArgs.Count; i++) { comp.Add(entry.Queue.CommandSystem.TagSystem.ParseTags( data.ComparisonArgs[i], TextStyle.Color_Simple, entry.Queue.Variables, entry.Queue.Debug)); } if (IfCommand.TryIf(comp)) { entry.Good("While loop at index <{color.emphasis}>" + data.Index + "<{color.base}>..."); entry.Queue.SetVariable("while_index", new TextTag(data.Index.ToString())); entry.Queue.AddCommandsNow(entry.BlockOwner.Block); } else { entry.Good("While loop ending, reached 'false'."); } } else { entry.Bad("While CALLBACK invalid: not a real callback!"); } } else if (count.ToLower() == "stop") { bool hasnext = false; for (int i = 0; i < entry.Queue.CommandList.Length; i++) { if (entry.Queue.GetCommand(i).Command is WhileCommand && entry.Queue.GetCommand(i).Arguments[0] == "\0CALLBACK") { hasnext = true; break; } } if (hasnext) { entry.Good("Stopping while loop."); while (entry.Queue.CommandList.Length > 0) { if (entry.Queue.GetCommand(0).Command is WhileCommand && entry.Queue.GetCommand(0).Arguments[0] == "\0CALLBACK") { entry.Queue.RemoveCommand(0); break; } entry.Queue.RemoveCommand(0); } } else { entry.Bad("Cannot stop while: not in one!"); } } else if (count.ToLower() == "next") { bool hasnext = false; for (int i = 0; i < entry.Queue.CommandList.Length; i++) { if (entry.Queue.GetCommand(i).Command is WhileCommand && entry.Queue.GetCommand(i).Arguments[0] == "\0CALLBACK") { hasnext = true; break; } } if (hasnext) { entry.Good("Skipping to next repeat entry..."); while (entry.Queue.CommandList.Length > 0) { if (entry.Queue.GetCommand(0).Command is WhileCommand && entry.Queue.GetCommand(0).Arguments[0] == "\0CALLBACK") { break; } entry.Queue.RemoveCommand(0); } } else { entry.Bad("Cannot stop while: not in one!"); } } else { List<string> parsedargs = new List<string>(entry.Arguments.Count + 1); parsedargs.Add(count); for (int i = 1; i < entry.Arguments.Count; i++) { parsedargs.Add(entry.GetArgument(i)); } bool success = IfCommand.TryIf(parsedargs); if (!success) { entry.Good("Not looping."); return; } WhileCommandData data = new WhileCommandData(); data.Index = 1; data.ComparisonArgs = new List<string>(entry.Arguments); entry.Data = data; if (entry.Block != null) { entry.Good("While looping..."); CommandEntry callback = new CommandEntry("while \0CALLBACK", null, entry, this, new List<string> { "\0CALLBACK" }, "while", 0); entry.Block.Add(callback); entry.Queue.SetVariable("while_index", new TextTag("1")); entry.Queue.AddCommandsNow(entry.Block); } else { entry.Bad("While invalid: No block follows!"); } } } }
public override void Execute(CommandEntry entry) { if (entry.Arguments.Count < 1) { ShowUsage(entry); } else { string count = entry.GetArgument(0); if (count == "\0CALLBACK") { if (entry.BlockOwner.Command.Name == "repeat" || entry.BlockOwner.Block == null || entry.BlockOwner.Block.Count == 0 || entry.BlockOwner.Block[entry.BlockOwner.Block.Count - 1] != entry) { RepeatCommandData data = (RepeatCommandData)entry.BlockOwner.Data; data.Index++; if (data.Index > data.Total) { entry.Good("Repeating ending, reached target."); } else { entry.Good("Repeating at index <{color.emphasis}>" + data.Index + "/" + data.Total + "<{color.base}>..."); entry.Queue.SetVariable("repeat_index", new TextTag(data.Index.ToString())); entry.Queue.SetVariable("repeat_total", new TextTag(data.Total.ToString())); entry.Queue.AddCommandsNow(entry.BlockOwner.Block); } } else { entry.Bad("Repeat CALLBACK invalid: not a real callback!"); } } else if (count.ToLower() == "stop") { bool hasnext = false; for (int i = 0; i < entry.Queue.CommandList.Length; i++) { if (entry.Queue.GetCommand(i).Command is RepeatCommand && entry.Queue.GetCommand(i).Arguments[0] == "\0CALLBACK") { hasnext = true; break; } } if (hasnext) { entry.Good("Stopping repeat loop."); while (entry.Queue.CommandList.Length > 0) { if (entry.Queue.GetCommand(0).Command is RepeatCommand && entry.Queue.GetCommand(0).Arguments[0] == "\0CALLBACK") { entry.Queue.RemoveCommand(0); break; } entry.Queue.RemoveCommand(0); } } else { entry.Bad("Cannot stop repeat: not in one!"); } } else if (count.ToLower() == "next") { bool hasnext = false; for (int i = 0; i < entry.Queue.CommandList.Length; i++) { if (entry.Queue.GetCommand(i).Command is RepeatCommand && entry.Queue.GetCommand(i).Arguments[0] == "\0CALLBACK") { hasnext = true; break; } } if (hasnext) { entry.Good("Skipping to next repeat entry..."); while (entry.Queue.CommandList.Length > 0) { if (entry.Queue.GetCommand(0).Command is RepeatCommand && entry.Queue.GetCommand(0).Arguments[0] == "\0CALLBACK") { break; } entry.Queue.RemoveCommand(0); } } else { entry.Bad("Cannot stop repeat: not in one!"); } } else { int target = StringToInt(count); if (target <= 0) { entry.Good("Not repeating."); return; } RepeatCommandData data = new RepeatCommandData(); data.Total = target; data.Index = 1; entry.Data = data; if (entry.Block != null) { entry.Good("Repeating <{color.emphasis}>" + target + "<{color.base}> times..."); CommandEntry callback = new CommandEntry("repeat \0CALLBACK", null, entry, this, new List<string> { "\0CALLBACK" }, "repeat", 0); entry.Block.Add(callback); entry.Queue.SetVariable("repeat_index", new TextTag("1")); entry.Queue.SetVariable("repeat_total", new TextTag(target.ToString())); entry.Queue.AddCommandsNow(entry.Block); } else { entry.Bad("Repeat invalid: No block follows!"); } } } }
public override void Execute(CommandEntry entry) { if (entry.Arguments.Count < 1) { ShowUsage(entry); return; } string type = entry.GetArgument(0).ToLower(); if (type == "stop") { bool hasnext = false; for (int i = 0; i < entry.Queue.CommandList.Length; i++) { if (entry.Queue.GetCommand(i).CommandLine == "call \0CALLBACK") { hasnext = true; break; } } if (hasnext) { entry.Good("Stopping function call."); while (entry.Queue.CommandList.Length > 0) { if (entry.Queue.GetCommand(0).CommandLine == "call \0CALLBACK") { entry.Queue.RemoveCommand(0); break; } entry.Queue.RemoveCommand(0); } } else { entry.Bad("Cannot stop function call: not in one!"); } return; } else if (type == "define") { if (entry.Arguments.Count < 2) { ShowUsage(entry); return; } string name = entry.GetArgument(1).ToLower(); if (entry.Block == null) { entry.Bad("Function invalid: No block follows!"); return; } if (entry.Queue.CommandSystem.Functions.ContainsKey(name)) { if (entry.Arguments.Count > 2 && entry.GetArgument(2).ToLower() == "quiet_fail") { entry.Good("Function '<{color.emphasis}>" + TagParser.Escape(name) + "<{color.base}>' already exists!"); } else { entry.Bad("Function '<{color.emphasis}>" + TagParser.Escape(name) + "<{color.base}>' already exists!"); } } else { entry.Queue.CommandSystem.Functions.Add(name, new CommandScript(name, CommandScript.DisOwn(entry.Block, entry))); entry.Good("Function '<{color.emphasis}>" + TagParser.Escape(name) + "<{color.base}>' defined."); } } else { ShowUsage(entry); } }
/// <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; } }
public override void Execute(CommandEntry entry) { if (entry.Arguments.Count < 1) { ShowUsage(entry); return; } string type = entry.GetArgument(0).ToLower(); if (type == "removescript") { if (entry.Arguments.Count < 2) { ShowUsage(entry); return; } string target = entry.GetArgument(1).ToLower(); if (target == "all") { int count = entry.Queue.CommandSystem.Scripts.Count; entry.Queue.CommandSystem.Scripts.Clear(); entry.Good("Script cache cleared of <{color.emphasis}>" + count + "<{color.base}> script" + (count == 1 ? ".": "s.")); } else { if (entry.Queue.CommandSystem.Scripts.Remove(target)) { entry.Good("Script '<{color.emphasis}>" + TagParser.Escape(target) + "<{color.base}>' removed from the script cache."); } else { if (entry.Arguments.Count > 2 && entry.GetArgument(2).ToLower() == "quiet_fail") { entry.Good("Script '<{color.emphasis}>" + TagParser.Escape(target) + "<{color.base}>' does not exist in the script cache!"); } else { entry.Bad("Script '<{color.emphasis}>" + TagParser.Escape(target) + "<{color.base}>' does not exist in the script cache!"); } } } } else if (type == "removefunction") { if (entry.Arguments.Count < 2) { ShowUsage(entry); return; } string target = entry.GetArgument(1).ToLower(); if (target == "all") { int count = entry.Queue.CommandSystem.Functions.Count; entry.Queue.CommandSystem.Functions.Clear(); entry.Good("Script cache cleared of <{color.emphasis}>" + count + "<{color.base}> function" + (count == 1 ? "." : "s.")); } else { if (entry.Queue.CommandSystem.Functions.Remove(target)) { entry.Good("Function '<{color.emphasis}>" + TagParser.Escape(target) + "<{color.base}>' removed from the script cache."); } else { if (entry.Arguments.Count > 2 && entry.GetArgument(2).ToLower() == "quiet_fail") { entry.Good("Function '<{color.emphasis}>" + TagParser.Escape(target) + "<{color.base}>' does not exist in the script cache!"); } else { entry.Bad("Function '<{color.emphasis}>" + TagParser.Escape(target) + "<{color.base}>' does not exist in the script cache!"); } } } } else { ShowUsage(entry); } }
public override void Execute(CommandEntry entry) { if (entry.Arguments.Count < 2) { ShowUsage(entry); return; } string type = entry.GetArgument(0).ToLower(); string eventname = entry.GetArgument(1).ToLower(); if (type == "clear" && eventname == "all") { foreach (KeyValuePair<string, ScriptEvent> evt in entry.Queue.CommandSystem.Events) { evt.Value.Handlers.Clear(); } entry.Good("Cleared all events."); return; } ScriptEvent theEvent; if (!entry.Queue.CommandSystem.Events.TryGetValue(eventname, out theEvent)) { entry.Bad("Unknown event '<{color.emphasis}>" + TagParser.Escape(eventname) + "<{color.base}>'."); return; } if (type == "clear") { int count = theEvent.Handlers.Count; theEvent.Handlers.Clear(); entry.Good("Cleared <{color.emphasis}>" + count + "<{color.base}> event handler" + (count == 1 ? "." : "s.")); } else if (type == "remove") { if (entry.Arguments.Count < 3) { ShowUsage(entry); return; } string name = entry.GetArgument(2).ToLower(); bool success = false; for (int i = 0; i < theEvent.Handlers.Count; i++) { if (theEvent.Handlers[i].Value.Name == "eventhandler_" + theEvent.Name + "_" + name) { theEvent.Handlers.RemoveAt(i); success = true; break; } } if (success) { entry.Good("Removed event handler '<{color.emphasis}>" + TagParser.Escape(name) + "<{color.base}>'."); } else { if (entry.Arguments.Count > 3 && entry.GetArgument(3).ToLower() == "quiet_fail") { entry.Good("Unknown event handler '<{color.emphasis}>" + TagParser.Escape(name) + "<{color.base}>'."); } else { entry.Bad("Unknown event handler '<{color.emphasis}>" + TagParser.Escape(name) + "<{color.base}>'."); } } } else if (type == "add") { if (entry.Arguments.Count < 3) { ShowUsage(entry); return; } string name = entry.GetArgument(2).ToLower(); if (entry.Block == null) { entry.Bad("Event command invalid: No block follows!"); return; } bool success = false; for (int i = 0; i < theEvent.Handlers.Count; i++) { if (theEvent.Handlers[i].Value.Name == "eventhandler_" + theEvent.Name + "_" + name) { theEvent.Handlers.RemoveAt(i); success = true; break; } } int priority = 0; if (entry.Arguments.Count > 3) { priority = FreneticUtilities.StringToInt(entry.GetArgument(3)); } if (success) { if (entry.Arguments.Count > 4 && entry.GetArgument(4).ToLower() == "quiet_fail") { entry.Good("Handler '<{color.emphasis}>" + TagParser.Escape(name) + "<{color.base}>' already exists!"); } else { entry.Bad("Handler '<{color.emphasis}>" + TagParser.Escape(name) + "<{color.base}>' already exists!"); } } else { theEvent.Handlers.Add(new KeyValuePair<int, CommandScript>(priority, new CommandScript("eventhandler_" + theEvent.Name + "_" + name, CommandScript.DisOwn(entry.Block, entry)) { Debug = DebugMode.MINIMAL })); theEvent.Sort(); entry.Good("Handler '<{color.emphasis}>" + TagParser.Escape(name) + "<{color.base}>' defined for event '<{color.emphasis}>" + TagParser.Escape(theEvent.Name) + "<{color.base}>'."); } } else { ShowUsage(entry); } }
public override void Execute(CommandEntry entry) { IfCommandData data = new IfCommandData(); data.Result = 0; entry.Data = data; CommandEntry IfEntry = null; CommandEntry Holder = entry.Queue.LastCommand; while (IfEntry == null && Holder != null) { if (Holder.BlockOwner == entry.BlockOwner) { if (Holder.Command.Name == "if" || Holder.Command.Name == "else") { IfEntry = Holder; } break; } Holder = Holder.BlockOwner; } if (IfEntry == null) { entry.Bad("Else invalid: IF command did not preceed!"); return; } if (((IfCommandData)IfEntry.Data).Result == 1) { entry.Good("Else continuing, IF passed."); return; } if (entry.Arguments.Count >= 1) { string ifbit = entry.GetArgument(0); if (ifbit.ToLower() != "if") { ShowUsage(entry); return; } else { List<string> parsedargs = new List<string>(entry.Arguments.Count); for (int i = 1; i < entry.Arguments.Count; i++) { parsedargs.Add(entry.GetArgument(i)); } bool success = IfCommand.TryIf(parsedargs); if (entry.Block != null) { if (success) { entry.Good("Else if is true, executing..."); data.Result = 1; entry.Queue.AddCommandsNow(entry.Block); } else { entry.Good("Else If is false, doing nothing!"); } } } } else { if (entry.Block != null) { entry.Good("Else is valid, executing..."); data.Result = 1; entry.Queue.AddCommandsNow(entry.Block); } else { entry.Bad("Else invalid: No block follows!"); } } }