Skip to content

Commit

Permalink
Updated commentary in API for library. Added option for server metric…
Browse files Browse the repository at this point in the history
… polling in client application. Added "Day" counter to GetUptimeToString. Added new CI/Build pipeline to build client app.
  • Loading branch information
Balphagore committed Apr 8, 2024
1 parent 2b4e0c9 commit 45e00d5
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/nuget-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
on:
workflow_dispatch:
push:
tags:
- '*'
Expand Down
78 changes: 78 additions & 0 deletions .github/workflows/publish-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: publish-client-multi-platform

on:
workflow_dispatch:
push:
tags:
- '*'

jobs:
build-library:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1'

# Lib
- name: Build and Pack Library
run: |
dotnet build Palworld.RESTSharp/Palworld.RESTSharp.csproj --configuration Release
dotnet pack Palworld.RESTSharp/Palworld.RESTSharp.csproj --configuration Release --output nupkg
# add as artifact
- name: Upload NuGet Package
uses: actions/upload-artifact@v2
with:
name: nuget-package
path: nupkg

build-windows-client-x64:
needs: build-library
runs-on: windows-latest

steps:
- uses: actions/checkout@v2

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0' # my pref

- name: Restore and Build Client Application
run: |
dotnet restore Palworld.RESTSharp.Client/Palworld.RESTSharp.Client.csproj
dotnet publish Palworld.RESTSharp.Client/Palworld.RESTSharp.Client.csproj -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -o publish/win-x64
- name: Upload WinForms Application
uses: actions/upload-artifact@v2
with:
name: windows-client
path: publish/win-x64

build-windows-client-x32:
needs: build-library
runs-on: windows-latest

steps:
- uses: actions/checkout@v2

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0' # my pref

- name: Restore and Build Client Application
run: |
dotnet restore Palworld.RESTSharp.Client/Palworld.RESTSharp.Client.csproj
dotnet publish Palworld.RESTSharp.Client/Palworld.RESTSharp.Client.csproj -c Release -r win-x86 --self-contained true -p:PublishSingleFile=true -o publish/win-x86
- name: Upload WinForms Application
uses: actions/upload-artifact@v2
with:
name: windows-client
path: publish/win-x64
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) [year] [fullname]
Copyright (c) 2024 BalphagoreVR

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
58 changes: 45 additions & 13 deletions Palworld.RESTSharp.Client/FormMain.Designer.cs

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

48 changes: 42 additions & 6 deletions Palworld.RESTSharp.Client/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private void tAPIOptions_AfterSelectAsync(object sender, TreeViewEventArgs e)
txtReasonMessage = new TextBox();
lblReason = new Label() { Text = "Shutdown Message" };
Label lblDelay = new Label() { Text = "Delay (Seconds)" };

txtReasonMessage.Dock = DockStyle.Top;
txtReasonMessage.PlaceholderText = "Enter reason for shutdown";
panelRequestParameters.Controls.Add(txtReasonMessage);
Expand Down Expand Up @@ -278,8 +278,10 @@ private async void btnSaveConfig_Click(object sender, EventArgs e)
this.Text = _defaultTitle;
_connected = true;
this.Text = _defaultTitle + $" - {serverInfo.serverName}";

UpdateServerMetricCounterAsync();
}
else
else // Disconnected
{
txtconfigURL.ReadOnly = false;
txtConfigPassword.ReadOnly = false;
Expand All @@ -290,14 +292,31 @@ private async void btnSaveConfig_Click(object sender, EventArgs e)
this.Text = _defaultTitle;
}
}
catch(PalworldRESTSharpClientUnauthorizedException pex)
catch (PalworldRESTSharpClientUnauthorizedException pex)
{
MessageBox.Show(pex.Message, "Invalid Password");
}
catch(Exception ex)
catch (Exception ex)
{
MessageBox.Show(ex.Message,"Error connecting");
MessageBox.Show(ex.Message, "Error connecting");
}
}

private async Task UpdateServerMetricCounterAsync()
{
while (_connected && cbTrackMetrics.Checked)
{
ServerMetric serverMetric = await palworldRESTAPIClient.GetServerMetricsASync();
if (serverMetric != null)
{
stsPlayerCount.Text = $"Players: {serverMetric.totalPlayers}/{serverMetric.maxPlayers}";
stsServerUptimeAndFPS.Text = $"Uptime: {serverMetric.GetUptimeString()} | FPS: {serverMetric.serverFPS}";
}
await Task.Delay(1000);
}

stsPlayerCount.Text = "";
stsServerUptimeAndFPS.Text = "";
}

private async void Execute()
Expand Down Expand Up @@ -370,6 +389,9 @@ private async void Execute()
lbServerMetrics.Items.Add($"Frame Rate: {serverMetric.serverFrameRate}");
lbServerMetrics.Items.Add($"Max Players: {serverMetric.maxPlayers}");
lbServerMetrics.Items.Add($"Uptime: {serverMetric.upTime}");

stsPlayerCount.Text = $"Players: {serverMetric.totalPlayers}/{serverMetric.maxPlayers}";
stsServerUptimeAndFPS.Text = $"Uptime: {serverMetric.GetUptimeString()} | FPS: {serverMetric.serverFPS}";
panelResponse.Controls.Add(lbServerMetrics);
}

Expand Down Expand Up @@ -511,7 +533,7 @@ private async void Execute()
break;
}
}
catch(Exception ex)
catch (Exception ex)
{
MessageBox.Show($"{ex.Message}\n\nException:\n{ex.StackTrace}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Expand All @@ -523,5 +545,19 @@ private async void btnExecute_Click(object sender, EventArgs e)

connectionStatus.Text = "Executed";
}

private void cbTrackMetrics_CheckedChanged(object sender, EventArgs e)
{
if (cbTrackMetrics.Checked)
{
// Show user a warning and prompt to continue or cancel.
DialogResult result = MessageBox.Show("Tracking server metrics will periodically poll the REST API resulting in excessive log spam in the server console. Do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

if (result == DialogResult.No)
{
cbTrackMetrics.Checked = false;
}
}
}
}
}
3 changes: 3 additions & 0 deletions Palworld.RESTSharp.Client/FormMain.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="statusStrip1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down
2 changes: 2 additions & 0 deletions Palworld.RESTSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Palworld.RESTSharp.Client",
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionFiles", "SolutionFiles", "{541EFF06-8B59-48BB-8C93-7B8DC7DA4089}"
ProjectSection(SolutionItems) = preProject
LICENSE.txt = LICENSE.txt
.github\workflows\nuget-publish.yml = .github\workflows\nuget-publish.yml
.github\workflows\publish-client.yml = .github\workflows\publish-client.yml
README.md = README.md
RestSharpLogo-128.png = RestSharpLogo-128.png
RestSharpLogo-32.png = RestSharpLogo-32.png
Expand Down
5 changes: 4 additions & 1 deletion Palworld.RESTSharp/Models/ServerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public class ServerInfo
[JsonProperty("description")]
public string description { get; set; }


/// <summary>
/// Returns the string representation of the server info.
/// </summary>
/// <returns>Server name, version, and description in a single line.</returns>
public override string ToString() => $"[{serverName}][{version}][{description}]";
}
}
7 changes: 6 additions & 1 deletion Palworld.RESTSharp/Models/ServerMetric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ public class ServerMetric
[JsonProperty("uptime")]
public int upTime { get; set; }

/// <summary>
/// Gets the uptime of the server expressed in hours, minutes, and seconds.
/// </summary>
/// <returns></returns>
public string GetUptimeString()
{
int days = upTime / 86400;
int hours = upTime / 3600;
int minutes = (upTime % 3600) / 60;
int seconds = upTime % 60;
return $"{hours}h {minutes}m {seconds}s";
return $"{days}d {hours}h {minutes}m {seconds}s";
}
}
}

0 comments on commit 45e00d5

Please sign in to comment.