-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* readme * url * Client (#9) * readme * Client * trim * Xunit (#10) * readme * fix xunit * TestGetAllFirstSeen * Update publish.yml * cleanup * forgot some ?'s * cleanup Co-authored-by: Scott Milliorn <[email protected]>
- Loading branch information
Showing
10 changed files
with
110 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NwServer> Servers { get; set; } | ||
|
||
public static async Task<List<NwServer>> GetServers() { | ||
string response = await _client.GetStringAsync("https://api.nwn.beamdog.net/v1/servers"); | ||
return JsonConvert.DeserializeObject<List<NwServer>>(response); | ||
} | ||
|
||
public static async Task<NwServer> GetServer(string publicKey) { | ||
string response = await _client.GetStringAsync($"https://api.nwn.beamdog.net/v1/servers/{publicKey}"); | ||
return JsonConvert.DeserializeObject<NwServer>(response); | ||
} | ||
|
||
public static async Task<NwServer> GetServer(string ip, int port) { | ||
string response = await _client.GetStringAsync($"https://api.nwn.beamdog.net/v1/servers/{ip}/{port}"); | ||
return JsonConvert.DeserializeObject<NwServer>(response); | ||
} | ||
|
||
public static async Task<Me> GetMe() { | ||
string response = await _client.GetStringAsync("https://api.nwn.beamdog.net/v1/me"); | ||
return JsonConvert.DeserializeObject<Me>(response); | ||
} | ||
public static HttpClient HttpClient { get; set; } | ||
|
||
public Client() { | ||
_client = new HttpClient(); | ||
Servers = GetServers().Result; | ||
HttpClient = new HttpClient(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NwServer> Servers { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Manifest>? Manifests { get; set; } | ||
[JsonProperty("url")] | ||
public string? URL { get; set; } | ||
[JsonPropertyName("manifests")] | ||
public List<Manifest> Manifests { get; set; } | ||
[JsonPropertyName("url")] | ||
public string URL { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NwServer> 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<NwServer> servers, string sessionName) => | ||
servers.Where(s => s.SessionName == sessionName).Select(self => servers.IndexOf(self)).FirstOrDefault(); | ||
|
||
public static IOrderedEnumerable<NwServer> GetAllFirstSeen(List<NwServer> servers) => | ||
servers.OrderByDescending(x => x.FirstSeen); | ||
public async static Task<IOrderedEnumerable<NwServer>> GetAllFirstSeen(this Client client) { | ||
var response = await client.GetServers(); | ||
return response.OrderByDescending(x => x.FirstSeen); | ||
} | ||
public static async Task<List<NwServer>> GetServers(this Client client) { | ||
string response = await Client.HttpClient.GetStringAsync($"{jsonUrl}/servers"); | ||
return JsonSerializer.Deserialize<List<NwServer>>(response); | ||
} | ||
|
||
public static async Task<NwServer> GetServer(this Client client, string publicKey) { | ||
string response = await Client.HttpClient.GetStringAsync($"{jsonUrl}/servers{publicKey}"); | ||
return JsonSerializer.Deserialize<NwServer>(response); | ||
} | ||
|
||
public static async Task<NwServer> GetServer(this Client client, string ip, int port) { | ||
string response = await Client.HttpClient.GetStringAsync($"{jsonUrl}/servers/{ip}/{port}"); | ||
return JsonSerializer.Deserialize<NwServer>(response); | ||
} | ||
|
||
public static async Task<Me> GetMe(this Client client) { | ||
string response = await Client.HttpClient.GetStringAsync(jsonUrl); | ||
return JsonSerializer.Deserialize<Me>(response); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# NWN.MasterList | ||
# NWN.MasterList | ||
|
||
<https://api.nwn.beamdog.net/v1/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<LangVersion>9.0</LangVersion> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\API\NWN.MasterList.csproj" /> | ||
</ItemGroup> | ||
</Project> | ||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<LangVersion>9.0</LangVersion> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\API\NWN.MasterList.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} | ||
} |