diff --git a/API/NWN.MasterList.csproj b/API/NWN.MasterList.csproj
index 0f1863a..eef2ea0 100644
--- a/API/NWN.MasterList.csproj
+++ b/API/NWN.MasterList.csproj
@@ -5,7 +5,6 @@
NWN.MasterList
true
NWN-dotnet
- enable
Neverwinter Nights;NWN;
MIT
true
@@ -18,6 +17,5 @@
-
diff --git a/API/src/Client.cs b/API/src/Client.cs
index 88aaece..f533e18 100644
--- a/API/src/Client.cs
+++ b/API/src/Client.cs
@@ -1,37 +1,11 @@
-using System.Collections.Generic;
-using System.Net.Http;
-using System.Threading.Tasks;
-using Newtonsoft.Json;
-using NWN.MasterList.Data;
+using System.Net.Http;
namespace NWN.MasterList {
public class Client {
- private static HttpClient _client { get; set; }
- public List Servers { get; set; }
-
- public static async Task> GetServers() {
- string response = await _client.GetStringAsync("https://api.nwn.beamdog.net/v1/servers");
- return JsonConvert.DeserializeObject>(response);
- }
-
- public static async Task GetServer(string publicKey) {
- string response = await _client.GetStringAsync($"https://api.nwn.beamdog.net/v1/servers/{publicKey}");
- return JsonConvert.DeserializeObject(response);
- }
-
- public static async Task GetServer(string ip, int port) {
- string response = await _client.GetStringAsync($"https://api.nwn.beamdog.net/v1/servers/{ip}/{port}");
- return JsonConvert.DeserializeObject(response);
- }
-
- public static async Task GetMe() {
- string response = await _client.GetStringAsync("https://api.nwn.beamdog.net/v1/me");
- return JsonConvert.DeserializeObject(response);
- }
+ public static HttpClient HttpClient { get; set; }
public Client() {
- _client = new HttpClient();
- Servers = GetServers().Result;
+ HttpClient = new HttpClient();
}
}
}
diff --git a/API/src/Data/Manifest.cs b/API/src/Data/Manifest.cs
index d8cf707..f9b94b0 100644
--- a/API/src/Data/Manifest.cs
+++ b/API/src/Data/Manifest.cs
@@ -1,10 +1,10 @@
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace NWN.MasterList.Data {
public struct Manifest {
- [JsonProperty("required")]
+ [JsonPropertyName("required")]
public bool Required { get; set; }
- [JsonProperty("hash")]
- public string? Hash { get; set; }
+ [JsonPropertyName("hash")]
+ public string Hash { get; set; }
}
}
\ No newline at end of file
diff --git a/API/src/Data/Me.cs b/API/src/Data/Me.cs
index 214ebdd..855cfc6 100644
--- a/API/src/Data/Me.cs
+++ b/API/src/Data/Me.cs
@@ -1,11 +1,11 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace NWN.MasterList.Data {
public struct Me {
- [JsonProperty("address")]
+ [JsonPropertyName("address")]
public string Address { get; set; }
- [JsonProperty("servers")]
+ [JsonPropertyName("servers")]
public List Servers { get; set; }
}
}
\ No newline at end of file
diff --git a/API/src/Data/NwServer.cs b/API/src/Data/NwServer.cs
index d40188b..bf37bb5 100644
--- a/API/src/Data/NwServer.cs
+++ b/API/src/Data/NwServer.cs
@@ -1,66 +1,62 @@
-using System;
-using System.Collections.Generic;
-using System.Net.Http;
-using System.Threading.Tasks;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace NWN.MasterList.Data {
public struct NwServer {
- [JsonProperty("first_seen")]
+ [JsonPropertyName("first_seen")]
public int FirstSeen { get; set; }
- [JsonProperty("last_advertisement")]
+ [JsonPropertyName("last_advertisement")]
public int LastAdvertisement { get; set; }
- [JsonProperty("session_name")]
+ [JsonPropertyName("session_name")]
public string SessionName { get; set; }
- [JsonProperty("module_name")]
+ [JsonPropertyName("module_name")]
public string ModuleName { get; set; }
- [JsonProperty("module_description")]
+ [JsonPropertyName("module_description")]
public string ModuleDescription { get; set; }
- [JsonProperty("passworded")]
+ [JsonPropertyName("passworded")]
public bool Passworded { get; set; }
- [JsonProperty("min_level")]
+ [JsonPropertyName("min_level")]
public int MinLevel { get; set; }
- [JsonProperty("max_level")]
+ [JsonPropertyName("max_level")]
public int MaxLevel { get; set; }
- [JsonProperty("current_players")]
+ [JsonPropertyName("current_players")]
public int CurrentPlayers { get; set; }
- [JsonProperty("max_players")]
+ [JsonPropertyName("max_players")]
public int MaxPlayers { get; set; }
- [JsonProperty("build")]
+ [JsonPropertyName("build")]
public string Build { get; set; }
- [JsonProperty("rev")]
+ [JsonPropertyName("rev")]
public int Revision { get; set; }
- [JsonProperty("pvp")]
+ [JsonPropertyName("pvp")]
public int PVP { get; set; }
- [JsonProperty("servervault")]
+ [JsonPropertyName("servervault")]
public bool ServerVault { get; set; }
- [JsonProperty("elc")]
+ [JsonPropertyName("elc")]
public bool ELC { get; set; }
- [JsonProperty("ilr")]
+ [JsonPropertyName("ilr")]
public bool ILR { get; set; }
- [JsonProperty("one_party")]
+ [JsonPropertyName("one_party")]
public bool OneParty { get; set; }
- [JsonProperty("player_pause")]
+ [JsonPropertyName("player_pause")]
public bool PlayerPause { get; set; }
- [JsonProperty("os")]
+ [JsonPropertyName("os")]
public int OS { get; set; }
- [JsonProperty("language")]
+ [JsonPropertyName("language")]
public int Language { get; set; }
- [JsonProperty("game_type")]
+ [JsonPropertyName("game_type")]
public int GameType { get; set; }
- [JsonProperty("latency")]
+ [JsonPropertyName("latency")]
public int Latency { get; set; }
- [JsonProperty("host")]
+ [JsonPropertyName("host")]
public string IP { get; set; }
- [JsonProperty("port")]
+ [JsonPropertyName("port")]
public int Port { get; set; }
- [JsonProperty("kx_pk")]
+ [JsonPropertyName("kx_pk")]
public string KxPk { get; set; }
- [JsonProperty("sign_pk")]
+ [JsonPropertyName("sign_pk")]
public string SignPk { get; set; }
- [JsonProperty("connecthint")]
+ [JsonPropertyName("connecthint")]
public string ConnectHint { get; set; }
- [JsonProperty("nwsync")]
+ [JsonPropertyName("nwsync")]
public NwSync NwSync { get; set; }
}
}
\ No newline at end of file
diff --git a/API/src/Data/NwSync.cs b/API/src/Data/NwSync.cs
index 074d70a..b05aee5 100644
--- a/API/src/Data/NwSync.cs
+++ b/API/src/Data/NwSync.cs
@@ -1,11 +1,11 @@
using System.Collections.Generic;
-using Newtonsoft.Json;
+using System.Text.Json.Serialization;
namespace NWN.MasterList.Data {
public struct NwSync {
- [JsonProperty("manifests")]
- public List? Manifests { get; set; }
- [JsonProperty("url")]
- public string? URL { get; set; }
+ [JsonPropertyName("manifests")]
+ public List Manifests { get; set; }
+ [JsonPropertyName("url")]
+ public string URL { get; set; }
}
}
\ No newline at end of file
diff --git a/API/src/Helper.cs b/API/src/Helper.cs
index 7f6a15a..10b8286 100644
--- a/API/src/Helper.cs
+++ b/API/src/Helper.cs
@@ -1,13 +1,38 @@
using System.Collections.Generic;
using System.Linq;
+using System.Text.Json;
+using System.Threading.Tasks;
using NWN.MasterList.Data;
namespace NWN.MasterList {
- public class Helper {
- public static int MasterListPositionFromSessionName(List servers, string sessionName) =>
+ public static class Helper {
+ public static string jsonUrl = "https://api.nwn.beamdog.net/v1/";
+
+ public static int MasterListPositionFromSessionName(this Client client, List servers, string sessionName) =>
servers.Where(s => s.SessionName == sessionName).Select(self => servers.IndexOf(self)).FirstOrDefault();
- public static IOrderedEnumerable GetAllFirstSeen(List servers) =>
- servers.OrderByDescending(x => x.FirstSeen);
+ public async static Task> GetAllFirstSeen(this Client client) {
+ var response = await client.GetServers();
+ return response.OrderByDescending(x => x.FirstSeen);
+ }
+ public static async Task> GetServers(this Client client) {
+ string response = await Client.HttpClient.GetStringAsync($"{jsonUrl}/servers");
+ return JsonSerializer.Deserialize>(response);
+ }
+
+ public static async Task GetServer(this Client client, string publicKey) {
+ string response = await Client.HttpClient.GetStringAsync($"{jsonUrl}/servers{publicKey}");
+ return JsonSerializer.Deserialize(response);
+ }
+
+ public static async Task GetServer(this Client client, string ip, int port) {
+ string response = await Client.HttpClient.GetStringAsync($"{jsonUrl}/servers/{ip}/{port}");
+ return JsonSerializer.Deserialize(response);
+ }
+
+ public static async Task GetMe(this Client client) {
+ string response = await Client.HttpClient.GetStringAsync(jsonUrl);
+ return JsonSerializer.Deserialize(response);
+ }
}
}
\ No newline at end of file
diff --git a/README.md b/README.md
index 84c0c87..97fa50d 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,3 @@
-# NWN.MasterList
\ No newline at end of file
+# NWN.MasterList
+
+
diff --git a/Test/NWN.MasterList.Test.csproj b/Test/NWN.MasterList.Test.csproj
index 8eed291..c015de0 100644
--- a/Test/NWN.MasterList.Test.csproj
+++ b/Test/NWN.MasterList.Test.csproj
@@ -1,14 +1,18 @@
-
- net5.0
- 9.0
- enable
-
-
-
-
-
-
-
-
-
+
+ net5.0
+ 9.0
+ enable
+
+
+
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Test/src/Client.Test.cs b/Test/src/Client.Test.cs
index 80b3a7e..c0131b3 100644
--- a/Test/src/Client.Test.cs
+++ b/Test/src/Client.Test.cs
@@ -1,11 +1,21 @@
using Xunit;
-namespace NWN.MasterList.Test {
- public class Client {
- [Fact]
- public void GetServersTest() {
- var connection = new MasterList.Client();
- Assert.NotEmpty(connection.Servers);
+namespace NWN.MasterList.Test
+{
+ public class Client
+ {
+ [Fact]
+ public async void GetServersTest()
+ {
+ var connection = new MasterList.Client();
+ Assert.NotEmpty(await connection.GetServers());
+ }
+
+ [Fact]
+ public async void TestGetAllFirstSeen()
+ {
+ var connection = new MasterList.Client();
+ Assert.NotEmpty(await connection.GetAllFirstSeen());
+ }
}
- }
}
\ No newline at end of file