diff --git a/README.md b/src/README.md similarity index 100% rename from README.md rename to src/README.md diff --git a/src/Types/PaymentData.cs b/src/Types/PaymentData.cs index 0a93126..8185f8f 100644 --- a/src/Types/PaymentData.cs +++ b/src/Types/PaymentData.cs @@ -1,9 +1,9 @@ -namespace spworlds.Types; - -public class PaymentData -{ - public int Amount; - public string RedirectUrl; - public string WebHookUrl; - public string Data; +namespace spworlds.Types; + +public class PaymentData +{ + public int Amount; + public string RedirectUrl; + public string WebHookUrl; + public string Data; } \ No newline at end of file diff --git a/src/Types/SkinPart.cs b/src/Types/SkinPart.cs index 85c020f..47f5d8f 100644 --- a/src/Types/SkinPart.cs +++ b/src/Types/SkinPart.cs @@ -1,12 +1,12 @@ -namespace spworlds.Types; - -public enum SkinPart -{ - face, - front, - front_full, - head, - bust, - full, - skin -} +namespace spworlds.Types; + +public enum SkinPart +{ + face, + front, + front_full, + head, + bust, + full, + skin +} diff --git a/src/Types/User.cs b/src/Types/User.cs index 149a1b4..810e685 100644 --- a/src/Types/User.cs +++ b/src/Types/User.cs @@ -1,37 +1,37 @@ -using spworlds; -using System.Text.Json.Nodes; -namespace spworlds.Types; - -public class User -{ - public string Name { get; } - public string Uuid { get; } - public JsonNode profile { get; } - - public bool IsPlayer() => Name != null ? true : false; - - public User(string name, string uuid, JsonNode profile) - { - Name = name; - Uuid = uuid; - this.profile = profile; - } - - public static async Task CreateUser(string name) - { - string uuid; - JsonNode profile; - using(HttpClient client = new()) - { - uuid = (string)JsonNode.Parse(await client.GetStringAsync($"https://api.mojang.com/users/profiles/minecraft/{name}"))["id"]; - profile = JsonNode.Parse(await client.GetStringAsync($"https://sessionserver.mojang.com/session/minecraft/profile/{uuid}")); - } - User user = new(name, uuid, profile); - return user; - } - - public string GetSkinPart(SkinPart skinPart, string size = "64") - { - return (string)$"https://visage.surgeplay.com/{skinPart}/{size}/{this.profile["profileId"]}"; - } -} +using spworlds; +using System.Text.Json.Nodes; +namespace spworlds.Types; + +public class User +{ + public string Name { get; } + public string Uuid { get; } + public JsonNode profile { get; } + + public bool IsPlayer() => Name != null ? true : false; + + public User(string name, string uuid, JsonNode profile) + { + Name = name; + Uuid = uuid; + this.profile = profile; + } + + public static async Task CreateUser(string name) + { + string uuid; + JsonNode profile; + using(HttpClient client = new()) + { + uuid = (string)JsonNode.Parse(await client.GetStringAsync($"https://api.mojang.com/users/profiles/minecraft/{name}"))["id"]; + profile = JsonNode.Parse(await client.GetStringAsync($"https://sessionserver.mojang.com/session/minecraft/profile/{uuid}")); + } + User user = new(name, uuid, profile); + return user; + } + + public string GetSkinPart(SkinPart skinPart, string size = "64") + { + return (string)$"https://visage.surgeplay.com/{skinPart}/{size}/{this.profile["profileId"]}"; + } +} diff --git a/src/bin/Debug/net6.0/spworlds.deps.json b/src/bin/Debug/net6.0/spworlds.deps.json new file mode 100644 index 0000000..bb3eb6d --- /dev/null +++ b/src/bin/Debug/net6.0/spworlds.deps.json @@ -0,0 +1,23 @@ +{ + "runtimeTarget": { + "name": ".NETCoreApp,Version=v6.0", + "signature": "" + }, + "compilationOptions": {}, + "targets": { + ".NETCoreApp,Version=v6.0": { + "spworlds/1.0.4": { + "runtime": { + "spworlds.dll": {} + } + } + } + }, + "libraries": { + "spworlds/1.0.4": { + "type": "project", + "serviceable": false, + "sha512": "" + } + } +} \ No newline at end of file diff --git a/src/bin/Debug/net6.0/spworlds.dll b/src/bin/Debug/net6.0/spworlds.dll new file mode 100644 index 0000000..d970090 Binary files /dev/null and b/src/bin/Debug/net6.0/spworlds.dll differ diff --git a/src/bin/Debug/net6.0/spworlds.pdb b/src/bin/Debug/net6.0/spworlds.pdb new file mode 100644 index 0000000..0f3960e Binary files /dev/null and b/src/bin/Debug/net6.0/spworlds.pdb differ diff --git a/src/bin/Debug/spworlds.1.0.1.nupkg b/src/bin/Debug/spworlds.1.0.1.nupkg new file mode 100644 index 0000000..cd390ba Binary files /dev/null and b/src/bin/Debug/spworlds.1.0.1.nupkg differ diff --git a/src/bin/Debug/spworlds.1.0.4.nupkg b/src/bin/Debug/spworlds.1.0.4.nupkg new file mode 100644 index 0000000..8f91155 Binary files /dev/null and b/src/bin/Debug/spworlds.1.0.4.nupkg differ diff --git a/src/obj/Debug/net6.0/ref/spworlds.dll b/src/obj/Debug/net6.0/ref/spworlds.dll new file mode 100644 index 0000000..7e62e07 Binary files /dev/null and b/src/obj/Debug/net6.0/ref/spworlds.dll differ diff --git a/src/obj/Debug/net6.0/refint/spworlds.dll b/src/obj/Debug/net6.0/refint/spworlds.dll new file mode 100644 index 0000000..7e62e07 Binary files /dev/null and b/src/obj/Debug/net6.0/refint/spworlds.dll differ diff --git a/src/obj/Debug/net6.0/spworlds.AssemblyInfo.cs b/src/obj/Debug/net6.0/spworlds.AssemblyInfo.cs index c77ec52..072678a 100644 --- a/src/obj/Debug/net6.0/spworlds.AssemblyInfo.cs +++ b/src/obj/Debug/net6.0/spworlds.AssemblyInfo.cs @@ -14,12 +14,12 @@ using System.Reflection; [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyDescriptionAttribute("данная библиотека предназначена для работы с сайтом spworlds. Ознакомиться с доку" + "ментацией можно в гитхабе проекта")] -[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.1.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.1")] +[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.4.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.4")] [assembly: System.Reflection.AssemblyProductAttribute("spworlds")] [assembly: System.Reflection.AssemblyTitleAttribute("spworlds")] -[assembly: System.Reflection.AssemblyVersionAttribute("1.0.1.0")] +[assembly: System.Reflection.AssemblyVersionAttribute("1.0.4.0")] [assembly: System.Reflection.AssemblyMetadataAttribute("RepositoryUrl", "https://github.com/Mih4n/spworlds")] -// Создано классом WriteCodeFragment MSBuild. +// Generated by the MSBuild WriteCodeFragment class. diff --git a/src/obj/Debug/net6.0/spworlds.AssemblyInfoInputs.cache b/src/obj/Debug/net6.0/spworlds.AssemblyInfoInputs.cache index 78e8d16..817694a 100644 --- a/src/obj/Debug/net6.0/spworlds.AssemblyInfoInputs.cache +++ b/src/obj/Debug/net6.0/spworlds.AssemblyInfoInputs.cache @@ -1 +1 @@ -3b79596e0f193799e87c2d642144700f8551bcf8 +4fc85608e250b55334138dc0a2960a1ccc317f15 diff --git a/src/obj/Debug/net6.0/spworlds.csproj.FileListAbsolute.txt b/src/obj/Debug/net6.0/spworlds.csproj.FileListAbsolute.txt index a5f2b70..5b6476e 100644 --- a/src/obj/Debug/net6.0/spworlds.csproj.FileListAbsolute.txt +++ b/src/obj/Debug/net6.0/spworlds.csproj.FileListAbsolute.txt @@ -2,3 +2,10 @@ C:\Users\losev\OneDrive\Рабочий стол\spworlds\spworlds-csharp-library C:\Users\losev\OneDrive\Рабочий стол\spworlds\spworlds-csharp-library\src\obj\Debug\net6.0\spworlds.AssemblyInfoInputs.cache C:\Users\losev\OneDrive\Рабочий стол\spworlds\spworlds-csharp-library\src\obj\Debug\net6.0\spworlds.AssemblyInfo.cs C:\Users\losev\OneDrive\Рабочий стол\spworlds\spworlds-csharp-library\src\obj\Debug\net6.0\spworlds.csproj.CoreCompileInputs.cache +C:\Users\losev\OneDrive\Рабочий стол\spworlds\spworlds-csharp-library\src\bin\Debug\net6.0\spworlds.deps.json +C:\Users\losev\OneDrive\Рабочий стол\spworlds\spworlds-csharp-library\src\bin\Debug\net6.0\spworlds.dll +C:\Users\losev\OneDrive\Рабочий стол\spworlds\spworlds-csharp-library\src\bin\Debug\net6.0\spworlds.pdb +C:\Users\losev\OneDrive\Рабочий стол\spworlds\spworlds-csharp-library\src\obj\Debug\net6.0\spworlds.dll +C:\Users\losev\OneDrive\Рабочий стол\spworlds\spworlds-csharp-library\src\obj\Debug\net6.0\refint\spworlds.dll +C:\Users\losev\OneDrive\Рабочий стол\spworlds\spworlds-csharp-library\src\obj\Debug\net6.0\spworlds.pdb +C:\Users\losev\OneDrive\Рабочий стол\spworlds\spworlds-csharp-library\src\obj\Debug\net6.0\ref\spworlds.dll diff --git a/src/obj/Debug/net6.0/spworlds.dll b/src/obj/Debug/net6.0/spworlds.dll new file mode 100644 index 0000000..d970090 Binary files /dev/null and b/src/obj/Debug/net6.0/spworlds.dll differ diff --git a/src/obj/Debug/net6.0/spworlds.pdb b/src/obj/Debug/net6.0/spworlds.pdb new file mode 100644 index 0000000..0f3960e Binary files /dev/null and b/src/obj/Debug/net6.0/spworlds.pdb differ diff --git a/src/obj/Debug/spworlds.1.0.1.nuspec b/src/obj/Debug/spworlds.1.0.1.nuspec new file mode 100644 index 0000000..7df4dd0 --- /dev/null +++ b/src/obj/Debug/spworlds.1.0.1.nuspec @@ -0,0 +1,20 @@ + + + + spworlds + 1.0.1 + Mih4n + MIT + https://licenses.nuget.org/MIT + README.md + данная библиотека предназначена для работы с сайтом spworlds. Ознакомиться с документацией можно в гитхабе проекта + + + + + + + + + + \ No newline at end of file diff --git a/src/obj/Debug/spworlds.1.0.4.nuspec b/src/obj/Debug/spworlds.1.0.4.nuspec new file mode 100644 index 0000000..6aee453 --- /dev/null +++ b/src/obj/Debug/spworlds.1.0.4.nuspec @@ -0,0 +1,20 @@ + + + + spworlds + 1.0.4 + Mih4n + MIT + https://licenses.nuget.org/MIT + README.md + данная библиотека предназначена для работы с сайтом spworlds. Ознакомиться с документацией можно в гитхабе проекта + + + + + + + + + + \ No newline at end of file diff --git a/src/obj/project.assets.json b/src/obj/project.assets.json index 13f5896..9b26777 100644 --- a/src/obj/project.assets.json +++ b/src/obj/project.assets.json @@ -12,7 +12,7 @@ "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {} }, "project": { - "version": "1.0.1", + "version": "1.0.4", "restore": { "projectUniqueName": "C:\\Users\\losev\\OneDrive\\Рабочий стол\\spworlds\\spworlds-csharp-library\\src\\spworlds.csproj", "projectName": "spworlds", diff --git a/src/obj/project.nuget.cache b/src/obj/project.nuget.cache index 5048a3a..c5e56ad 100644 --- a/src/obj/project.nuget.cache +++ b/src/obj/project.nuget.cache @@ -1,6 +1,6 @@ { "version": 2, - "dgSpecHash": "BcScqcBajGeCpumrD0XHCVXubY8iGSvVtyfgtqEr1b+ZFER5tFI/jvxsd7fM+aNBX0ZgxKhrR3Trd/3mtyDYsQ==", + "dgSpecHash": "AxJ7bOs4Z9l6KXy2n7OAAZz8U1o7V0AmVQguUWJj3EBLeI36WOpEuQH9YGUPP6QALFeUBw9dZ2Q8IM0H/2kaqA==", "success": true, "projectFilePath": "C:\\Users\\losev\\OneDrive\\Рабочий стол\\spworlds\\spworlds-csharp-library\\src\\spworlds.csproj", "expectedPackageFiles": [], diff --git a/src/obj/spworlds.csproj.nuget.dgspec.json b/src/obj/spworlds.csproj.nuget.dgspec.json index fe9171f..56f68a8 100644 --- a/src/obj/spworlds.csproj.nuget.dgspec.json +++ b/src/obj/spworlds.csproj.nuget.dgspec.json @@ -5,7 +5,7 @@ }, "projects": { "C:\\Users\\losev\\OneDrive\\Рабочий стол\\spworlds\\spworlds-csharp-library\\src\\spworlds.csproj": { - "version": "1.0.1", + "version": "1.0.4", "restore": { "projectUniqueName": "C:\\Users\\losev\\OneDrive\\Рабочий стол\\spworlds\\spworlds-csharp-library\\src\\spworlds.csproj", "projectName": "spworlds", diff --git a/src/spworlds.cs b/src/spworlds.cs index 3a4a485..d242a76 100644 --- a/src/spworlds.cs +++ b/src/spworlds.cs @@ -1,120 +1,120 @@ -using System.Net.Http.Headers; -using System.Text.Json; -using System.Text; -using System.Text.Json.Nodes; -using System.Security.Cryptography; -using System.Runtime.InteropServices; - -using spworlds.Types; -namespace spworlds; - -public class SPWorlds -{ - private readonly HttpClient client; - private string token; - - public SPWorlds(string id, string token) - { - client = new HttpClient(); - var BearerToken = $"{id}:{token}"; - this.token = token; - string Base64BearerToken = Convert.ToBase64String(Encoding.UTF8.GetBytes(BearerToken)); - - client.BaseAddress = new Uri("https://spworlds.ru/api/public/"); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Base64BearerToken); - } - - private async Task ValidateWebHook(string webHook, string bodyHash) - { - byte[] body = Encoding.UTF8.GetBytes(bodyHash); - byte[] webhook = Encoding.UTF8.GetBytes(webHook); - var key = new HMACSHA256(Encoding.UTF8.GetBytes(token)); - string webhook64 = Convert.ToBase64String(key.ComputeHash(webhook)); - return webhook64.Equals(body); - } - - private async Task SendRequest(string endpoint, Boolean getResult = true, Dictionary? body = null) - { - string respond; - string jsonBody; - - if (body == null) - { - return respond = client.GetAsync(endpoint).Result.Content.ReadAsStringAsync().Result; - } - else - { - jsonBody = JsonSerializer.Serialize(body); - var payload = new StringContent(jsonBody, Encoding.UTF8, "application/json"); - - if (getResult) - return respond = client.PostAsync(endpoint, payload).Result.Content.ReadAsStringAsync().Result; - else - await client.PostAsync(endpoint, payload); - } - - return null; - } - - public async Task GetBalance() - { - string respond = await SendRequest("card"); - - var card = JsonObject.Parse(respond); - var balance = card["balance"]; - - return (int)balance; - } - - public async Task CreateTransaction(string receiver, int amount, string comment) - { - var transitionInfo = new Dictionary - { - { "receiver", receiver }, - { "amount", amount }, - { "comment", comment } - }; - - await SendRequest(endpoint: "transactions", body: transitionInfo); - } - - public async Task GetUser(string discordId) - { - string userName = (string)JsonObject.Parse(await SendRequest($"users/{discordId}"))["username"]; - User user = await User.CreateUser(userName); - return (User)user; - } - - public async Task InitPayment(int amount, string redirectUrl, string webhookUrl, string data) - { - var paymentInfo = new Dictionary - { - { "amount", amount }, - { "redirectUrl", redirectUrl }, - { "webhookUrl", webhookUrl }, - { "data", data } - }; - - var payment = JsonObject.Parse(await SendRequest(endpoint: $"payment", body: paymentInfo)); - var url = payment["url"]; - - return (string)url; - } - - public async Task InitPayment(PaymentData paymentData) - { - var paymentInfo = new Dictionary - { - { "amount", paymentData.Amount }, - { "redirectUrl", paymentData.RedirectUrl }, - { "webhookUrl", paymentData.WebHookUrl }, - { "data", paymentData.Data } - }; - - var payment = JsonObject.Parse(await SendRequest(endpoint: $"payment", body: paymentInfo)); - var url = payment["url"]; - - return (string)url; - } -} - +using System.Net.Http.Headers; +using System.Text.Json; +using System.Text; +using System.Text.Json.Nodes; +using System.Security.Cryptography; +using System.Runtime.InteropServices; + +using spworlds.Types; +namespace spworlds; + +public class SPWorlds +{ + private readonly HttpClient client; + private string token; + + public SPWorlds(string id, string token) + { + client = new HttpClient(); + var BearerToken = $"{id}:{token}"; + this.token = token; + string Base64BearerToken = Convert.ToBase64String(Encoding.UTF8.GetBytes(BearerToken)); + + client.BaseAddress = new Uri("https://spworlds.ru/api/public/"); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Base64BearerToken); + } + + private async Task ValidateWebHook(string webHook, string bodyHash) + { + byte[] body = Encoding.UTF8.GetBytes(bodyHash); + byte[] webhook = Encoding.UTF8.GetBytes(webHook); + var key = new HMACSHA256(Encoding.UTF8.GetBytes(token)); + string webhook64 = Convert.ToBase64String(key.ComputeHash(webhook)); + return webhook64.Equals(body); + } + + private async Task SendRequest(string endpoint, Boolean getResult = true, Dictionary? body = null) + { + string respond; + string jsonBody; + + if (body == null) + { + return respond = client.GetAsync(endpoint).Result.Content.ReadAsStringAsync().Result; + } + else + { + jsonBody = JsonSerializer.Serialize(body); + var payload = new StringContent(jsonBody, Encoding.UTF8, "application/json"); + + if (getResult) + return respond = client.PostAsync(endpoint, payload).Result.Content.ReadAsStringAsync().Result; + else + await client.PostAsync(endpoint, payload); + } + + return null; + } + + public async Task GetBalance() + { + string respond = await SendRequest("card"); + + var card = JsonObject.Parse(respond); + var balance = card["balance"]; + + return (int)balance; + } + + public async Task CreateTransaction(string receiver, int amount, string comment) + { + var transitionInfo = new Dictionary + { + { "receiver", receiver }, + { "amount", amount }, + { "comment", comment } + }; + + await SendRequest(endpoint: "transactions", body: transitionInfo); + } + + public async Task GetUser(string discordId) + { + string userName = (string)JsonObject.Parse(await SendRequest($"users/{discordId}"))["username"]; + User user = await User.CreateUser(userName); + return (User)user; + } + + public async Task InitPayment(int amount, string redirectUrl, string webhookUrl, string data) + { + var paymentInfo = new Dictionary + { + { "amount", amount }, + { "redirectUrl", redirectUrl }, + { "webhookUrl", webhookUrl }, + { "data", data } + }; + + var payment = JsonObject.Parse(await SendRequest(endpoint: $"payment", body: paymentInfo)); + var url = payment["url"]; + + return (string)url; + } + + public async Task InitPayment(PaymentData paymentData) + { + var paymentInfo = new Dictionary + { + { "amount", paymentData.Amount }, + { "redirectUrl", paymentData.RedirectUrl }, + { "webhookUrl", paymentData.WebHookUrl }, + { "data", paymentData.Data } + }; + + var payment = JsonObject.Parse(await SendRequest(endpoint: $"payment", body: paymentInfo)); + var url = payment["url"]; + + return (string)url; + } +} + diff --git a/src/spworlds.csproj b/src/spworlds.csproj index d127f1b..0805ba6 100644 --- a/src/spworlds.csproj +++ b/src/spworlds.csproj @@ -7,7 +7,7 @@ spworlds данная библиотека предназначена для работы с сайтом spworlds. Ознакомиться с документацией можно в гитхабе проекта MIT - 1.0.1 + 1.0.4 Mih4n Mih4n https://github.com/Mih4n/spworlds