int IComparer.Compare(Object x, Object y) { newx = (DelayedCommand)x; newy = (DelayedCommand)y; result = cic.Compare(newx.time + newx.delay, newy.time + newy.delay); return(result); }
public void Remove(DelayedCommand delayedcommand) { lock (commands.SyncRoot) { commands.Remove(delayedcommand); } }
public DelayedCommand Pop() { lock (commands.SyncRoot) { DelayedCommand delayedcommand = (DelayedCommand)commands[0]; Remove(0); return(delayedcommand); } }
public virtual void Add(DelayedCommand delayedcommand) { // Some basic protection against deadlocks if (delayedcommand.delay < 1) { delayedcommand.delay = 1; } lock (commands.SyncRoot) { commands.Add(delayedcommand); commands.Sort(new DelayedCommandComparer()); } }
private bool DoTimedCommands(object sender, EventArgs e) { while (Convert.ToInt64(Lib.Delayedcommands.First.time + Lib.Delayedcommands.First.delay) <= Lib.GetTime()) { DelayedCommand dc = Lib.Delayedcommands.First; ICommand command = Lib.GetCommandByName(dc.command); if (command == null) { Lib.PrintLine(dc.command + " command not found. Please check to make sure TMC files are all installed."); Lib.Delayedcommands.Remove(dc); continue; } try { command.DoCommand(dc.actor, dc.command, dc.arguments.Trim()); // Only show prompt after running a command if the actor is a real user if (dc.actor["type"].ToString() == "user") { dc.actor.Showprompt(); } } catch (ThreadAbortException ex) { //Thread is most likely being aborted due to server shutdown return(false); } catch (Exception ex) { if (command != null) { Lib.PrintLine(DateTime.Now + " EXCEPTION running command " + command.Name + ": " + ex.Message + ex.StackTrace); } else { Lib.PrintLine(DateTime.Now + " EXCEPTION running command " + dc.command + ": " + ex.Message + ex.StackTrace); } return(false); } Lib.Delayedcommands.Remove(0); if (dc.loop) { Lib.Delayedcommands.Add(dc.actor, dc.command, dc.arguments, Lib.GetTime(), dc.delay, dc.loop); } } return(true); }