private void button1_Click(object sender, EventArgs e) { if (isEditing) { timedCommandArray.RemoveCommandItem(editing); lstbox.Items.Remove(lstbox.SelectedItem); } List <string> list = new List <string>( textBox2.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)); TimedCommandItem cm = new TimedCommandItem(textBox1.Text, checkBox1.Checked, Decimal.ToInt32(numericUpDown2.Value), Decimal.ToInt32(numericUpDown1.Value), checkBox2.Checked, list); timedCommandArray.AddTimedCommand(cm); lstbox.Items.Add(new NewItem { Command = cm.GetName(), Cmd = cm }); SaveSettings(); this.Close(); }
public TimedCommandForm(TimedCommandItem cmd, ListBox lsbx) { this.lstbox = lsbx; FormBorderStyle = FormBorderStyle.FixedSingle; MaximizeBox = false; isEditing = true; InitializeComponent(); button1.Text = "Apply Edit"; textBox1.Text = cmd.GetName(); numericUpDown2.Value = cmd.GetTime(); checkBox1.Checked = cmd.RunEveryXMin(); numericUpDown1.Value = cmd.GetEveryXMin(); for (int x = 0; x < cmd.GetCommands().Count(); x++) { textBox2.AppendText(cmd.GetCommands()[x] + System.Environment.NewLine); } editing = cmd; }
public void AddTimedCommand(TimedCommandItem tci) { timedCommands.Add(tci); }
public void RemoveCommandItem(TimedCommandItem tci) { timedCommands.Remove(tci); }
public void Tick() { while (true) { try { for (int x = 0; x < timedCommandArray.GetCommandList().Count(); x++) { TimedCommandItem c = timedCommandArray.GetCommandList()[x]; if (c.IsEnabled()) { if (c.RunEveryXMin()) { if (c.lastRan == null) { c.lastRan = DateTime.Now; c.NextRun = c.lastRan.AddMinutes(c.GetEveryXMin()); for (int y = 0; y < c.GetCommands().Count(); y++) { for (int con = 0; con < connectionList.Count; con++) { Connection cn = connectionList[con]; if (cn.IsConnected()) { if (c.RunEveryXMin()) { if (cn.server.serverData.numPlayers >= 1) { cn.SendToRcon(c.GetCommands()[y]); } } else { cn.SendToRcon(c.GetCommands()[y]); } } } } } else if (DateTime.Now >= c.NextRun) { c.lastRan = DateTime.Now; c.NextRun = c.lastRan.AddMinutes(c.GetEveryXMin()); for (int y = 0; y < c.GetCommands().Count(); y++) { for (int con = 0; con < connectionList.Count; con++) { Connection cn = connectionList[con]; if (cn.IsConnected()) { cn.SendToRcon(c.GetCommands()[y]); } } } } } else { if (DateTime.Now.Hour == c.GetTime() && c.hasRan == false) { c.hasRan = true; for (int y = 0; y < c.GetCommands().Count(); y++) { for (int con = 0; con < connectionList.Count; con++) { Connection cn = connectionList[con]; cn.SendToRcon(c.GetCommands()[y]); } } } } if (!c.RunEveryXMin() && DateTime.Now.Hour != c.GetTime() && c.hasRan == true) { c.hasRan = false; } } } Invalidate(); Thread.Sleep(20); } catch (Exception) { } } }