Skip to content

Commit

Permalink
Added webhook for server updated. Server IP and port can now be inclu…
Browse files Browse the repository at this point in the history
…ed in webhooks.
  • Loading branch information
Razzmatazzz committed Apr 4, 2021
1 parent c3d9961 commit d81d644
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 30 deletions.
13 changes: 9 additions & 4 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ui:WindowHelper.UseModernWindowStyle="True"
xmlns:local="clr-namespace:ValheimServerWarden"
mc:Ignorable="d"
Title="Valheim Server Warden" Height="475" Width="800" Closed="Window_Closed" StateChanged="Window_StateChanged" Closing="Window_Closing" Icon="/Resources/vsw2_256.png" IsVisibleChanged="Window_IsVisibleChanged">
Title="Valheim Server Warden" Height="475" Width="800" Closed="Window_Closed" StateChanged="Window_StateChanged" Closing="Window_Closing" Icon="/Resources/vsw2_256.png" IsVisibleChanged="Window_IsVisibleChanged" Loaded="Window_Loaded">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down Expand Up @@ -145,14 +145,19 @@
<Button x:Name="btnUpdateCheck" Content="Check Now" Margin="5,5" VerticalAlignment="Center" Click="btnUpdateCheck_Click" Grid.Column="1"/>
</Grid>
<Grid Grid.Row="3">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<CheckBox x:Name="chkRunningServerCheck" Content="Check for running servers on start" ToolTip="Check for any running servers on app start and provide the option to shut them down" Margin="10,5" Grid.Column="0" Checked="chkRunningServerCheck_Checked" Unchecked="chkRunningServerCheck_Checked"/>
<CheckBox x:Name="chkStopOnClose" Content="Stop running servers on app close" ToolTip="Instead of preventing app closing when there are running servers, stop all running servers" Margin="10,5" Grid.Column="1" Checked="chkStopOnClose_Checked" Unchecked="chkStopOnClose_Checked"/>
<CheckBox x:Name="chkRunningServerCheck" Content="Check for running servers on start" ToolTip="Check for any running servers on app start and provide the option to shut them down" Margin="10,5" Grid.Row="0" Grid.Column="0" Checked="chkRunningServerCheck_Checked" Unchecked="chkRunningServerCheck_Checked"/>
<CheckBox x:Name="chkStopOnClose" Content="Stop running servers on app close" ToolTip="Instead of preventing app closing when there are running servers, stop all running servers" Margin="10,5" Grid.Row="0" Grid.Column="1" Checked="chkStopOnClose_Checked" Unchecked="chkStopOnClose_Checked"/>
<CheckBox x:Name="chkStartMinimized" Content="Start minimized" ToolTip="Minimize app on startup" Margin="10,5" Grid.Row="1" Grid.Column="0" Checked="chkStartMinimized_Checked" Unchecked="chkStartMinimized_Checked"/>
<CheckBox x:Name="chkLog" Content="Create log file" ToolTip="Write app log outpute to a file (useful for troubleshooting)" Margin="10,5" Grid.Row="1" Grid.Column="1" Checked="chkLog_Checked" Unchecked="chkLog_Checked"/>
</Grid>
<CheckBox x:Name="chkLog" Content="Create log file" ToolTip="Write app log outpute to a file (useful for troubleshooting)" Margin="10,5" Grid.Row="4" Checked="chkLog_Checked" Unchecked="chkLog_Checked"/>
</Grid>
</TabItem>
<TabItem Header="Log">
Expand Down
15 changes: 15 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public MainWindow()
chkLog.IsChecked = Properties.Settings.Default.WriteAppLog;
chkRunningServerCheck.IsChecked = Properties.Settings.Default.RunningServerCheck;
chkStopOnClose.IsChecked = Properties.Settings.Default.StopOnClose;
chkStartMinimized.IsChecked = Properties.Settings.Default.StartMinimized;
if (Properties.Settings.Default.AutoCheckUpdate)
{
checkForUpdate();
Expand Down Expand Up @@ -1312,5 +1313,19 @@ private void chkStopOnClose_Checked(object sender, RoutedEventArgs e)
Properties.Settings.Default.StopOnClose = chkStopOnClose.IsChecked.GetValueOrDefault();
Properties.Settings.Default.Save();
}

private void chkStartMinimized_Checked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.StartMinimized = chkStartMinimized.IsChecked.GetValueOrDefault();
Properties.Settings.Default.Save();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
if (Properties.Settings.Default.StartMinimized)
{
this.WindowState = WindowState.Minimized;
}
}
}
}
12 changes: 12 additions & 0 deletions Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@
<Setting Name="StopOnClose" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="StartMinimized" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
24 changes: 2 additions & 22 deletions ServerDetailsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public partial class ServerDetailsWindow : Window
public event EventHandler<ServerEventArgs> ShowLog;
private ValheimServer _server;
private string _steamPath;
private string _externalIP;
private System.Timers.Timer resourceTimer;
public ValheimServer Server
{
Expand Down Expand Up @@ -84,7 +83,6 @@ public ServerDetailsWindow(ValheimServer server)
Debug.WriteLine("Error searching for Steam path");
Debug.WriteLine(ex);
}
GetExternalIP();
LoadLists();

foreach (var entry in Server.LogEntries)
Expand Down Expand Up @@ -304,24 +302,6 @@ private void UpdateServerResourcesUsed()
lblMemory.Content = Server.MemoryUsed.ToString("N0") + " MB";
});
}

private void GetExternalIP()
{
new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;
try
{
_externalIP = new WebClient().DownloadString("http://icanhazip.com");
}
catch (Exception ex)
{
Debug.WriteLine("Error getting external IP.");
Debug.WriteLine(ex);
}
}).Start();
}

private void LoadLists()
{
try
Expand Down Expand Up @@ -551,7 +531,7 @@ private void btnConnect_Click(object sender, RoutedEventArgs e)
private void menuConnectLink_Click(object sender, RoutedEventArgs e)
{
// also test steam://run/892970//%2Bconnect%20{_externalIP}%3A{this.Server.Port}
Clipboard.SetText($"steam://connect/{_externalIP}:{this.Server.Port + 1}");
Clipboard.SetText($"steam://connect/{ValheimServer.ExternalIP}:{this.Server.Port + 1}");
}

private void chkAutoRestart_Checked(object sender, RoutedEventArgs e)
Expand All @@ -572,7 +552,7 @@ private void btnDiscordWebhook_Click(object sender, RoutedEventArgs e)
private void menuConnectCheckExternal_Click(object sender, RoutedEventArgs e)
{
//Process.Start("cmd", $"/C start https://southnode.net/form_get.php?ip={_externalIP}");
Process.Start("cmd", $"/C start https://geekstrom.de/valheim/check/?host={WebUtility.UrlEncode($"{_externalIP}:{Server.Port + 1}")}");
Process.Start("cmd", $"/C start https://geekstrom.de/valheim/check/?host={WebUtility.UrlEncode($"{ValheimServer.ExternalIP}:{Server.Port + 1}")}");
}

private void btnSteamCmd_Click(object sender, RoutedEventArgs e)
Expand Down
30 changes: 29 additions & 1 deletion ValheimServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.IO;
using System.Globalization;
using RazzTools;
using System.Net;

namespace ValheimServerWarden
{
Expand All @@ -36,7 +37,7 @@ public enum ServerInstallMethod
public static string DefaultSaveDir { get { return $@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\AppData\LocalLow\IronGate\Valheim"; } }
public static string ExecutableName { get { return "valheim_server.exe"; } }
public static Dictionary<string, string> DiscordWebhookDefaultMessages { get; } = new Dictionary<string, string> {
{"OnStarted", "Server {Server.Name} has started." },
{"OnStarted", "Server {Server.Name} has started on {Server.IP}:{Server.Port} ({Server.Version})." },
{"OnStartFailed", "Server {Server.Name} failed to start." },
{"OnStopped", "Server {Server.Name} has stopped." },
{"OnFailedPassword", "User with SteamID {Player.SteamID} tried to join with an invalid password." },
Expand Down Expand Up @@ -138,6 +139,7 @@ public event DataReceivedEventHandler ErrorDataReceived
private bool inTxn = false;
private int stopAttempts;
private bool disposed = false;
private static string externalIP;

public string Name
{
Expand Down Expand Up @@ -439,6 +441,30 @@ public double MemoryUsed
}
//[JsonIgnore]
public string Version { get; set; }
[JsonIgnore]
public static string ExternalIP
{
get
{
return externalIP;
}
}
static ValheimServer()
{
new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;
try
{
externalIP = new WebClient().DownloadString("http://icanhazip.com").Trim();
}
catch (Exception ex)
{
Debug.WriteLine("Error getting external IP.");
Debug.WriteLine(ex);
}
}).Start();
}
public ValheimServer(string name, int port, string world, string password, bool pubserver, bool autostart, bool rawlog, int restarthours, bool updateonrestart, int updatecheckminutes, string discordwebhook, Dictionary<string,string> discordmessages, Dictionary<string, string> discordservereventnames, ServerInstallMethod install, string instpath, ProcessPriorityClass processpriority, bool umodupdating)
{
this.data.name = name;
Expand Down Expand Up @@ -581,6 +607,8 @@ public void SendDiscordWebhook(string EventName, Player player, string serverEve
message = message.Replace("{Server.Name}", this.DisplayName);
message = message.Replace("{Server.PlayerCount}", this.PlayerCount.ToString());
message = message.Replace("{Server.Version}", this.Version);
message = message.Replace("{Server.IP}", ValheimServer.ExternalIP);
message = message.Replace("{Server.Port}", this.Port.ToString());
if (player != null)
{
message = message.Replace("{Player.Name}", player.Name);
Expand Down
6 changes: 3 additions & 3 deletions ValheimServerWarden.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<StartupObject>ValheimServerWarden.App</StartupObject>
<Version>0.4.16</Version>
<AssemblyVersion>0.4.16.0</AssemblyVersion>
<Version>0.4.17</Version>
<AssemblyVersion>0.4.17.0</AssemblyVersion>
<Product>ValheimServerWarden</Product>
<Authors>Razzmatazz</Authors>
<ApplicationIcon>Resources\vsw2.ico</ApplicationIcon>
<PackageId>ValheimServerWarden</PackageId>
<AssemblyName>Valheim Server Warden</AssemblyName>
<FileVersion>0.4.16.0</FileVersion>
<FileVersion>0.4.17.0</FileVersion>
<Company>ValheimServerWarden</Company>
</PropertyGroup>

Expand Down

0 comments on commit d81d644

Please sign in to comment.