-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSkyveInterface.cs
123 lines (105 loc) · 3.61 KB
/
SkyveInterface.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.Collections.Generic;
using System.Net.Http;
using Newtonsoft.Json;
namespace AssetPacksManager;
public enum PackageStability
{
Unknown = -1,
Stable = 1,
NotEnoughInformation = 2,
HasIssues = 3,
Broken = 4,
BrokenFromPatch = 5,
BrokenFromNewVersion = 10,
StableNoNewFeatures = 6,
StableNoFutureUpdates = 7,
HasIssuesNoFutureUpdates = 8,
BreaksOnPatch = 9,
NotReviewed = 0,
Incompatible = 99,
AssetNotReviewed = 98,
Local = 97,
AuthorRetired = 96,
BrokenFromPatchSafe = 95,
AssetIncompatible = 94,
BrokenFromPatchUpdated = 93,
BrokenFromNewVersionSafe = 92,
}
public static class SkyveInterface
{
private static ApmLogger Logger;
private const bool Initialized = false;
private static HttpClient _client;
private static string url = $"https://skyve-mod.com/v2/api/CompatibilityData/";
private static void Init()
{
Logger = Mod.Logger;
_client = new HttpClient();
_client.Timeout = new TimeSpan(0, 0, 10);
}
public static void CheckPlaysetStatus(List<AssetPack> assetPacks)
{
if (!Initialized)
Init();
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add("API_KEY", "MPHIoIlbsrmDCYWFLDZaUaMGD0p1l282ARrXhHt4");
request.Headers.Add("USER_ID", "");
try
{
HttpResponseMessage response = _client.SendAsync(request).Result;
response.EnsureSuccessStatusCode();
string responseBody = response.Content.ReadAsStringAsync().Result;
var data = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(responseBody);
foreach (var mod in data)
{
if (mod.ContainsKey("stability"))
{
int stability = int.Parse(mod.TryGetValue("stability", out var value) ? value.ToString() : "-1");
if (mod.TryGetValue("id", out var idString))
{
foreach (var pack in assetPacks)
{
int id = int.Parse(idString.ToString());
if (pack.ID == id)
{
pack.Stability = (PackageStability) stability;
break;
}
}
}
}
}
}
catch (Exception e)
{
Logger.Info($"Skyve Playset status check failed: {e.Message}");
}
}
public static PackageStability CheckModStatus(int id)
{
if (!Initialized)
Init();
var request = new HttpRequestMessage(HttpMethod.Get, url + id);
request.Headers.Add("API_KEY", "MPHIoIlbsrmDCYWFLDZaUaMGD0p1l282ARrXhHt4");
request.Headers.Add("USER_ID", "");
try
{
HttpResponseMessage response = _client.SendAsync(request).Result;
response.EnsureSuccessStatusCode();
string responseBody = response.Content.ReadAsStringAsync().Result;
Logger.Info(responseBody);
var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(responseBody);
if (data.ContainsKey("stability"))
{
int stability = int.Parse(data.TryGetValue("stability", out var value) ? value.ToString() : "-1");
return (PackageStability) stability;
}
}
catch (Exception)
{
// ignored
}
return PackageStability.Unknown;
}
}