Skip to content

Commit

Permalink
Fixed Discord webhook test bug. Added server process priority setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Razzmatazzz committed Mar 6, 2021
1 parent 5863869 commit b574345
Show file tree
Hide file tree
Showing 8 changed files with 411 additions and 298 deletions.
32 changes: 16 additions & 16 deletions DiscordWebhookWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@
<TextBox x:Name="txtWebhook" HorizontalAlignment="Stretch" Margin="10,5,10,5" TextWrapping="Wrap" VerticalAlignment="Stretch" Grid.Row="1" Grid.ColumnSpan="3"/>
<Label Content="Webhook Messages" ToolTip="To disable the webhook for an event, just erase the messge" HorizontalAlignment="Left" Margin="10,10,0,5" VerticalAlignment="Top" Grid.Row="2" Grid.ColumnSpan="2"/>
<Label Content="Server Started" Margin="10,5,5,5" VerticalAlignment="Center" Grid.Row="3" Grid.Column="0"/>
<TextBox x:Name="OnStarted" Margin="5" Grid.Row="3" Grid.Column="1" />
<Button x:Name="btnTestServerStarted" Content="Test" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="3" Grid.Column="2" Click="btnTestServerStarted_Click"/>
<TextBox x:Name="txtOnStarted" Tag="OnStarted" Margin="5" Grid.Row="3" Grid.Column="1" />
<Button x:Name="btnTestServerStarted" Content="Test" Tag="OnStarted" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="3" Grid.Column="2" Click="btnTestWebhook_Click"/>
<Label Content="Server Start Failed" Margin="10,5,5,5" VerticalAlignment="Center" Grid.Row="4" Grid.Column="0"/>
<TextBox x:Name="OnStartFailed" Margin="5" Grid.Row="4" Grid.Column="1" />
<Button x:Name="btnTestServerStartFailed" Content="Test" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="4" Grid.Column="2" Click="btnTestServerStarted_Click"/>
<TextBox x:Name="txtOnStartFailed" Tag="OnStartFailed" Margin="5" Grid.Row="4" Grid.Column="1" />
<Button x:Name="btnTestServerStartFailed" Content="Test" Tag="OnStartFailed" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="4" Grid.Column="2" Click="btnTestWebhook_Click"/>
<Label Content="Server Stopped" Margin="10,5,5,5" VerticalAlignment="Center" Grid.Row="5" Grid.Column="0"/>
<TextBox x:Name="OnServerExited" Margin="5" Grid.Row="5" Grid.Column="1" />
<Button x:Name="btnTestServerStopped" Content="Test" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="5" Grid.Column="2" Click="btnTestServerStopped_Click"/>
<TextBox x:Name="txtOnServerExited" Tag="OnServerExited" Margin="5" Grid.Row="5" Grid.Column="1" />
<Button x:Name="btnTestServerStopped" Content="Test" Tag="OnServerExited" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="5" Grid.Column="2" Click="btnTestWebhook_Click"/>
<Label Content="Player Connected" Margin="10,5,5,5" VerticalAlignment="Center" Grid.Row="6" Grid.Column="0"/>
<TextBox x:Name="OnPlayerConnected" Margin="5" Grid.Row="6" Grid.Column="1" />
<Button x:Name="btnTestConnected" Content="Test" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="6" Grid.Column="2" Click="btnTestConnected_Click"/>
<TextBox x:Name="txtOnPlayerConnected" Tag="OnPlayerConnected" Margin="5" Grid.Row="6" Grid.Column="1" />
<Button x:Name="btnTestConnected" Content="Test" Tag="OnPlayerConnected" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="6" Grid.Column="2" Click="btnTestWebhook_Click"/>
<Label Content="Player Disconnected" Margin="10,5,5,5" VerticalAlignment="Center" Grid.Row="7" Grid.Column="0"/>
<TextBox x:Name="OnPlayerDisconnected" Margin="6" Grid.Row="7" Grid.Column="1" />
<Button x:Name="btnTestDisconnected" Content="Test" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="7" Grid.Column="2" Click="btnTestDisconnected_Click"/>
<TextBox x:Name="txtOnPlayerDisconnected" Tag="OnPlayerDisconnected" Margin="6" Grid.Row="7" Grid.Column="1" />
<Button x:Name="btnTestDisconnected" Content="Test" Tag="OnPlayerDisconnected" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="7" Grid.Column="2" Click="btnTestWebhook_Click"/>
<Label Content="Player Died" Margin="10,5,5,5" VerticalAlignment="Center" Grid.Row="8" Grid.Column="0"/>
<TextBox x:Name="OnPlayerDied" Margin="5" Grid.Row="8" Grid.Column="1" />
<Button x:Name="btnTestDied" Content="Test" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="8" Grid.Column="2" Click="btnTestDied_Click"/>
<TextBox x:Name="txtOnPlayerDied" Tag="OnPlayerDied" Margin="5" Grid.Row="8" Grid.Column="1" />
<Button x:Name="btnTestDied" Content="Test" Tag="OnPlayerDied" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="8" Grid.Column="2" Click="btnTestWebhook_Click"/>
<Label Content="Wrong Password" Margin="10,5,5,5" VerticalAlignment="Center" Grid.Row="9" Grid.Column="0"/>
<TextBox x:Name="OnFailedPassword" Margin="5" Grid.Row="9" Grid.Column="1" />
<Button x:Name="btnFailedPassword" Content="Test" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="9" Grid.Column="2" Click="btnFailedPassword_Click"/>
<TextBox x:Name="txtOnFailedPassword" Tag="OnFailedPassword" Margin="5" Grid.Row="9" Grid.Column="1" />
<Button x:Name="btnFailedPassword" Content="Test" Tag="OnFailedPassword" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="9" Grid.Column="2" Click="btnTestWebhook_Click"/>
<Label Content="Random Event" Margin="10,5,5,5" VerticalAlignment="Center" Grid.Row="10" Grid.Column="0"/>
<TextBox x:Name="OnRandomServerEvent" Margin="5" Grid.Row="10" Grid.Column="1" />
<Button x:Name="btnRandomServerEvent" Content="Test" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="10" Grid.Column="2" Click="btnRandomServerEvent_Click"/>
<TextBox x:Name="txtOnRandomServerEvent" Tag="OnRandomServerEvent" Margin="5" Grid.Row="10" Grid.Column="1" />
<Button x:Name="btnRandomServerEvent" Content="Test" Tag="OnRandomServerEvent" Margin="0,5,10,5" VerticalAlignment="Center" Grid.Row="10" Grid.Column="2" Click="btnTestWebhook_Click"/>
<Grid Grid.Row="11" Grid.ColumnSpan="3" HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
Expand Down
82 changes: 26 additions & 56 deletions DiscordWebhookWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ public DiscordWebhookWindow(ValheimServer server)

txtWebhook.Text = _server.DiscordWebhook;

ContextMenu contextMenu = new ContextMenu();
MenuItem defaultMenu = new MenuItem();
var contextMenu = new ContextMenu();
var defaultMenu = new MenuItem();
contextMenu.Items.Add(defaultMenu);
defaultMenu.Header = "Reset to default";
defaultMenu.Click += DefaultMenu_Click;

messageControls = new List<TextBox>();
messageControls.Add(OnPlayerConnected);
messageControls.Add(OnPlayerDisconnected);
messageControls.Add(OnPlayerDied);
messageControls.Add(OnFailedPassword);
messageControls.Add(OnRandomServerEvent);
messageControls.Add(OnStarted);
messageControls.Add(OnStartFailed);
messageControls.Add(OnServerExited);
foreach (TextBox textBox in messageControls)
messageControls = new();
messageControls.Add(txtOnPlayerConnected);
messageControls.Add(txtOnPlayerDisconnected);
messageControls.Add(txtOnPlayerDied);
messageControls.Add(txtOnFailedPassword);
messageControls.Add(txtOnRandomServerEvent);
messageControls.Add(txtOnStarted);
messageControls.Add(txtOnStartFailed);
messageControls.Add(txtOnServerExited);
foreach (var textBox in messageControls)
{
textBox.Text = server.GetWebhookMessage(textBox.Name);
textBox.Text = server.GetWebhookMessage(textBox.Tag.ToString());
textBox.ContextMenu = contextMenu;
textBox.ContextMenuOpening += TextBox_ContextMenuOpening;
}
Expand All @@ -62,66 +62,36 @@ private void TextBox_ContextMenuOpening(object sender, ContextMenuEventArgs e)

private void DefaultMenu_Click(object sender, RoutedEventArgs e)
{
clickedTextBox.Text = _server.DefaultWebhookMessages[clickedTextBox.Name];
}

private void btnTestConnected_Click(object sender, RoutedEventArgs e)
{
_server.SendDiscordWebhook(OnPlayerConnected.Name, new Player("Bjorn", "123456789101112"));
}

private void btnTestDisconnected_Click(object sender, RoutedEventArgs e)
{
_server.SendDiscordWebhook(OnPlayerDisconnected.Name, new Player("Bjorn", "123456789101112"));
}

private void btnTestDied_Click(object sender, RoutedEventArgs e)
{
_server.SendDiscordWebhook(OnPlayerDied.Name, new Player("Bjorn", "123456789101112"));
}

private void btnFailedPassword_Click(object sender, RoutedEventArgs e)
{
_server.SendDiscordWebhook(OnFailedPassword.Name, new Player("Bjorn", "123456789101112"));
}

private void btnRandomServerEvent_Click(object sender, RoutedEventArgs e)
{
_server.SendDiscordWebhook(OnRandomServerEvent.Name, null, "army_bonemass");
clickedTextBox.Text = ValheimServer.DiscordWebhookDefaultMessages[clickedTextBox.Tag.ToString()];
}

private void btnSave_Click(object sender, RoutedEventArgs e)
{
_server.DiscordWebhook = txtWebhook.Text;
foreach (TextBox textBox in messageControls)
foreach (var textBox in messageControls)
{
if (textBox.Text != null && _server.DefaultWebhookMessages.ContainsKey(textBox.Name) && textBox.Text != this._server.DefaultWebhookMessages[textBox.Name])
var webHookName = textBox.Tag.ToString();
if (textBox.Text != null && ValheimServer.DiscordWebhookDefaultMessages.ContainsKey(webHookName) && textBox.Text != ValheimServer.DiscordWebhookDefaultMessages[webHookName])
{
_server.DiscordWebhookMessages[textBox.Name] = textBox.Text;
_server.DiscordWebhookMessages[webHookName] = textBox.Text;
}
else if (_server.DefaultWebhookMessages.ContainsKey(textBox.Name) && textBox.Text == this._server.DefaultWebhookMessages[textBox.Name])
else if (ValheimServer.DiscordWebhookDefaultMessages.ContainsKey(webHookName) && textBox.Text == ValheimServer.DiscordWebhookDefaultMessages[webHookName])
{
if (_server.DiscordWebhookMessages.ContainsKey(textBox.Name))
if (_server.DiscordWebhookMessages.ContainsKey(webHookName))
{
_server.DiscordWebhookMessages.Remove(textBox.Name);
_server.DiscordWebhookMessages.Remove(webHookName);
}
}
}
DialogResult = true;
Close();
}

private void btnTestServerStarted_Click(object sender, RoutedEventArgs e)
{
_server.SendDiscordWebhook(OnStarted.Name, null, null);
}
private void btnTestServerStartFailed_Click(object sender, RoutedEventArgs e)
private void btnTestWebhook_Click(object sender, RoutedEventArgs e)
{
_server.SendDiscordWebhook(OnStartFailed.Name, null, null);
}
private void btnTestServerStopped_Click(object sender, RoutedEventArgs e)
{
_server.SendDiscordWebhook(OnStarted.Name, null, null);
var oldUrl = _server.DiscordWebhook;
_server.DiscordWebhook = txtWebhook.Text;
_server.SendDiscordWebhook(((Button)sender).Tag.ToString(), new Player("Bjorn", "123456789101112"), "army_bonemass");
_server.DiscordWebhook = oldUrl;
}

private void btnCancel_Click(object sender, RoutedEventArgs e)
Expand Down
8 changes: 4 additions & 4 deletions InstallSteamCmdWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void txtServerPath_MouseLeftButtonUp(object sender, MouseButtonEventArgs

private void btnInstallServer_Click(object sender, RoutedEventArgs e)
{
if (!File.Exists(txtServerPath.Text+"\\valheim_server.exe"))
if (!File.Exists($@"{txtServerPath.Text}\{ValheimServer.ExecutableName}"))
{
btnInstallServer.IsEnabled = false;
txtServerPath.MouseLeftButtonUp -= txtServerPath_MouseLeftButtonUp;
Expand All @@ -142,7 +142,7 @@ private void btnInstallServer_Click(object sender, RoutedEventArgs e)
else
{
Properties.Settings.Default.ServerInstallType = (int)ValheimServer.ServerInstallMethod.SteamCMD;
Properties.Settings.Default.ServerFilePath = txtServerPath.Text + "\\valheim_server.exe";
Properties.Settings.Default.ServerFilePath = txtServerPath.Text + $@"\{ValheimServer.ExecutableName}";
Properties.Settings.Default.SteamCMDPath = txtSteamCMDPath.Text;
Properties.Settings.Default.Save();
DialogResult = true;
Expand All @@ -154,10 +154,10 @@ private void SteamCmdProcess_Exited(object sender, EventArgs e)
{
this.Dispatcher.Invoke(() =>
{
if (File.Exists(txtServerPath.Text + "\\valheim_server.exe"))
if (File.Exists($@"{txtServerPath.Text}\{ValheimServer.ExecutableName}"))
{
Properties.Settings.Default.ServerInstallType = (int)ValheimServer.ServerInstallMethod.SteamCMD;
Properties.Settings.Default.ServerFilePath = txtServerPath.Text + "\\valheim_server.exe";
Properties.Settings.Default.ServerFilePath = $@"{txtServerPath.Text}\{ValheimServer.ExecutableName}";
Properties.Settings.Default.SteamCMDPath = txtSteamCMDPath.Text;
Properties.Settings.Default.Save();
DialogResult = true;
Expand Down
Loading

0 comments on commit b574345

Please sign in to comment.