This commit is contained in:
Riley S 2021-03-08 02:48:49 -05:00
parent cdeaae7600
commit 448eaa97a7
3 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>ConsoleApp1</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1-beta1" />
<PackageReference Include="SteamQueryNet" Version="1.0.6" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,61 @@
using System;
using System.Threading.Tasks;
using SteamQueryNet;
using SteamQueryNet.Interfaces;
namespace ConsoleApp1
{
struct server_metrics
{
public uint openSlots; //NUMOPENPUBCONN
}
class ArkServer
{
public string ConnectionInfo { get; }
public uint openSlots { get; }
public ArkServer(string address)
{
ConnectionInfo = address;
}
}
class Program
{
private static string hostname = "join.unfesports.com";
private static ArkServer[] servers = //Todo, make this an arg ... maybe validate hostname, or just pass port.
{
new ArkServer($"{hostname}:27015"),
new ArkServer($"{hostname}:27016"),
new ArkServer($"{hostname}:27017"),
new ArkServer($"{hostname}:27018"),
new ArkServer($"{hostname}:27019")
};
static async Task Main(string[] args)
{
Console.WriteLine("Enumerating Servers");
for (int i = 0; i < 5; ++i)
{
string myHostAndPort = $"join.unfesports.com:{27015+i}";
IServerQuery serverQuery = new ServerQuery(myHostAndPort);
var a = await serverQuery.GetServerInfoAsync();
var b = await serverQuery.GetRulesAsync();
Console.WriteLine($"Map: {a.Map} - {a.Name} - {a.Version}");
server_metrics serverMetrics = new server_metrics();
foreach (var c in b)
{
if (c.Name == "NUMOPENPUBCONN")
{
serverMetrics.openSlots = uint.Parse(c.Value);
}
Console.WriteLine($"{c.Name} / {c.Value}");
}
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(serverMetrics));
}
}
}
}

16
TestProject.sln Normal file
View File

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArkStatusMonitor", "ArkStatusMonitor\ArkStatusMonitor.csproj", "{93538365-4FAC-4674-9A30-95DECDD27E47}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{93538365-4FAC-4674-9A30-95DECDD27E47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93538365-4FAC-4674-9A30-95DECDD27E47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93538365-4FAC-4674-9A30-95DECDD27E47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93538365-4FAC-4674-9A30-95DECDD27E47}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal