private static void OnTimerTick(object sender, EventArgs e) { MainWindow main = ((MainWindow)Application.Current.MainWindow); if (main.Debug) { OutputHandler.Log($"Running: {running} Failed attempts: {failedAttempts}"); } if (running) { failedAttempts = 0; } else { if (failedAttempts == 60) { OutputHandler.Log("Server is idle... checking if it's still responding!", Level.WARN); CommandExecutor.Command("list"); } if (failedAttempts >= 90) { OutputHandler.Log("Server has not responded in a long time! Restarting...", Level.WARN); main.JavaServer.Stop(); main.JavaServer.Start(); failedAttempts = 0; } else { failedAttempts++; } } running = false; }
public static void Display(MainWindow window) { Application.Current.Dispatcher.Invoke(new Action(() => { window.PlayerListGrid.Children.Clear(); int index = 1; foreach (Player player in PlayerList) { Label username = new Label { Content = player.Username, Name = $"player_{player.Username}" }; Grid.SetRow(username, index); Grid.SetColumn(username, 1); window.PlayerListGrid.Children.Add(username); Button ban = new Button { Content = "Ban", Name = $"action_{player.Username}", Margin = new Thickness(2, 2, 2, 2) }; Button kick = new Button { Content = "Kick", Name = $"action_{player.Username}", Margin = new Thickness(2, 2, 2, 2) }; Button mute = new Button { Content = "Mute", Name = $"action_{player.Username}", Margin = new Thickness(2, 2, 2, 2) }; ban.Click += (sender, args) => { CommandExecutor.Command($"ban {player.Username}"); }; kick.Click += (sender, args) => { CommandExecutor.Command($"kick {player.Username}"); }; mute.Click += (sender, args) => { CommandExecutor.Command($"mute {player.Username}"); }; Grid.SetRow(ban, index); Grid.SetColumn(ban, 2); Grid.SetRow(kick, index); Grid.SetColumn(kick, 3); Grid.SetRow(mute, index); Grid.SetColumn(mute, 4); window.PlayerListGrid.Children.Add(ban); window.PlayerListGrid.Children.Add(kick); window.PlayerListGrid.Children.Add(mute); index++; } })); }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { e.Cancel = true; CommandExecutor.Command("stop"); e.Cancel = false; }
protected static void Ban(String username) { CommandExecutor.Command("/ban " + username); }