This commit is contained in:
Raidenxd2
2026-08-07 04:45:59 -04:00
commit 255b572a6f
219 changed files with 1652469 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
using System.Text.Json;
using Microsoft.AspNetCore.Mvc;
namespace asdfasdf.APIs;
public static class PlayerSettingsAPI
{
public static void Init(WebApplication app)
{
app.MapGet("/playersettings", (HttpRequest request) =>
{
foreach (var user in Auth.currentUsers)
{
if (user.token == request.Headers.Authorization[0])
{
return user.ps;
}
}
return null;
});
app.MapPut("/playersettings", ([FromForm] string key, [FromForm] string value, HttpRequest request) =>
{
List<PlayerSetting> ps = null;
int id = 0;
foreach (var user in Auth.currentUsers)
{
if (user.token == request.Headers.Authorization[0])
{
ps = user.ps;
id = user.id;
}
}
if (ps.Exists(x => x.Key == key))
{
app.Logger.LogInformation("Removing setting " + key);
ps.Remove(ps.Find(x => x.Key == key));
}
app.Logger.LogInformation("Adding setting " + key + " with value " + value);
ps.Add(new(){Key = key, Value = value});
File.WriteAllText("ServerData/Accounts/" + id + "/PlayerSettings.json", JsonSerializer.Serialize(ps));
ApiResponseNoValue response = new()
{
success = true
};
return response;
}).DisableAntiforgery();
}
}