mirror of
https://github.com/CannedNet/CannedNet.git
synced 2026-10-27 07:58:59 -07:00
PROBABLY BROKEN BUT OK
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"Hosting": {
|
||||
"Url": "http://*:5000"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"Hosting": {
|
||||
"Url": "http://*:5005"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"Hosting": {
|
||||
"Url": "http://*:5002"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"Hosting": {
|
||||
"Url": "http://*:5007"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"Hosting": {
|
||||
"Url": "http://*:5003"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"Hosting": {
|
||||
"Url": "http://*:5009"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"Hosting": {
|
||||
"Url": "http://*:5010"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"Hosting": {
|
||||
"Url": "http://*:5008"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"Hosting": {
|
||||
"Url": "http://*:5004"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"Hosting": {
|
||||
"Url": "http://*:5001"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"Hosting": {
|
||||
"Url": "http://*:5006"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,26 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.11" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.8" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.2.2" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.19.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<_ContentIncludedByDefault Remove="AppConfigs\appsettings.Accounts.json" />
|
||||
<_ContentIncludedByDefault Remove="AppConfigs\appsettings.API.json" />
|
||||
<_ContentIncludedByDefault Remove="AppConfigs\appsettings.Auth.json" />
|
||||
<_ContentIncludedByDefault Remove="AppConfigs\appsettings.CDN.json" />
|
||||
<_ContentIncludedByDefault Remove="AppConfigs\appsettings.Chat.json" />
|
||||
<_ContentIncludedByDefault Remove="AppConfigs\appsettings.Clubs.json" />
|
||||
<_ContentIncludedByDefault Remove="AppConfigs\appsettings.Commerce.json" />
|
||||
<_ContentIncludedByDefault Remove="AppConfigs\appsettings.Image.json" />
|
||||
<_ContentIncludedByDefault Remove="AppConfigs\appsettings.Match.json" />
|
||||
<_ContentIncludedByDefault Remove="AppConfigs\appsettings.Notify.json" />
|
||||
<_ContentIncludedByDefault Remove="AppConfigs\appsettings.NS.json" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv5tZ6wY8g3rXpMqrXnvA
|
||||
eLL9dx0tk8Cqt5C3dGVsNxFvrH6isfrsQDSZ8XWC/LAx/U9l4ouOJExx9rgxr3up
|
||||
XywAHZVLtFr00KbMRtKP4PrNGNfQpIou3weCJg1Gh3mtgHfwU/jJuc0UYdHLRpVv
|
||||
JCtn4VLf6/UjdatN5wc4qK/yXQh6MgBFI+IuGlaMoCdn5MbzK6bX7CFzQ8Ch8Oeh
|
||||
8HikSbfuHenudaE74Z04HYqGMx3Yzq+2Fd9XdNjvYgcaR9HJdfVAB2vkuNo3/Kv1
|
||||
axCjouJIl3SPp+6a6Nc36Qo67VSf4AOusgepDjAacXmndn3qux1wMEugl7B6Xi4W
|
||||
WQIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
@@ -1,26 +1,38 @@
|
||||
{
|
||||
"Auth": "https://auth.lapis.codes",
|
||||
"API": "https://api.lapis.codes",
|
||||
"WWW": "https://www.lapis.codes",
|
||||
"Notifications": "https://notify.lapis.codes",
|
||||
"Images": "https://img.lapis.codes",
|
||||
"CDN": "https://cdn.lapis.codes",
|
||||
"Commerce": "https://commerce.lapis.codes",
|
||||
"Matchmaking": "https://match.lapis.codes",
|
||||
"Storage": "https://cdn.lapis.codes",
|
||||
"Chat": "https://chatrr.lapis.codes",
|
||||
"Leaderboard": "https://leaderboard.lapis.codes",
|
||||
"Accounts": "https://accounts.lapis.codes",
|
||||
"Link": "https://link.lapis.codes",
|
||||
"RoomComments": "https://roomcomments.lapis.codes",
|
||||
"Clubs": "https://clubs.lapis.codes",
|
||||
"Rooms": "https://rooms.lapis.codes",
|
||||
"PlatformNotifications": "https://api.lapis.codes",
|
||||
"Moderation": "https://api.lapis.codes",
|
||||
"DataCollection": "https://api.lapis.codes",
|
||||
"BugReporting": "https://api.lapis.codes",
|
||||
"Discovery": "https://api.lapis.codes",
|
||||
"PlayerSettings": "https://api.lapis.codes",
|
||||
"Rendering": "https://api.lapis.codes",
|
||||
"Launcher": "https://launcher.lapis.codes"
|
||||
"Accounts": "https://cn-test.lapiscreates.tech/accounts",
|
||||
"AI": "https://cn-test.lapiscreates.tech/ai",
|
||||
"API": "https://cn-test.lapiscreates.tech/api",
|
||||
"Auth": "https://cn-test.lapiscreates.tech/auth",
|
||||
"BugReporting": "https://cn-test.lapiscreates.tech/bugreporting",
|
||||
"Cards": "https://cn-test.lapiscreates.tech/cards",
|
||||
"CDN": "https://cn-test.lapiscreates.tech/cdn",
|
||||
"Chat": "https://cn-test.lapiscreates.tech/chat",
|
||||
"Clubs": "https://cn-test.lapiscreates.tech/clubs",
|
||||
"CMS": "https://cn-test.lapiscreates.tech/cms",
|
||||
"Commerce": "https://cn-test.lapiscreates.tech/commerce",
|
||||
"Data": "https://cn-test.lapiscreates.tech/data",
|
||||
"DataCollection": "https://cn-test.lapiscreates.tech/datacollection",
|
||||
"Discovery": "https://cn-test.lapiscreates.tech/discovery",
|
||||
"Econ": "https://cn-test.lapiscreates.tech/econ",
|
||||
"GameLogs": "https://cn-test.lapiscreates.tech/gamelogs",
|
||||
"Geo": "https://cn-test.lapiscreates.tech/geo",
|
||||
"Images": "https://cn-test.lapiscreates.tech/img",
|
||||
"Leaderboard": "https://cn-test.lapiscreates.tech/leaderboard",
|
||||
"Link": "https://cn-test.lapiscreates.tech/link",
|
||||
"Lists": "https://cn-test.lapiscreates.tech/lists",
|
||||
"Matchmaking": "https://cn-test.lapiscreates.tech/match",
|
||||
"Moderation": "https://cn-test.lapiscreates.tech/moderation",
|
||||
"Notifications": "https://cn-test.lapiscreates.tech",
|
||||
"PlatformNotifications": "https://cn-test.lapiscreates.tech",
|
||||
"PlayerSettings": "https://cn-test.lapiscreates.tech/playersettings",
|
||||
"RoomComments": "https://cn-test.lapiscreates.tech/roomcomments",
|
||||
"RoomieIntegrations": "https://cn-test.lapiscreates.tech/roomieintegrations",
|
||||
"Rooms": "https://cn-test.lapiscreates.tech/rooms",
|
||||
"Storage": "https://cn-test.lapiscreates.tech/storage",
|
||||
"Strings": "https://cn-test.lapiscreates.tech/strings",
|
||||
"StringsCDN": "https://cn-test.lapiscreates.tech/stringscdn",
|
||||
"Studio": "https://cn-test.lapiscreates.tech/studio",
|
||||
"Thorn": "https://cn-test.lapiscreates.tech/thorn",
|
||||
"Videos": "https://cn-test.lapiscreates.tech/videos",
|
||||
"WWW": "https://cn-test.lapiscreates.tech"
|
||||
}
|
||||
+86
-32
@@ -1,48 +1,102 @@
|
||||
using CannedNet;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json.Serialization;
|
||||
using CannedNet.Data;
|
||||
using CannedNet.Hubs;
|
||||
using CannedNet.Services;
|
||||
using CannedNet.Services.Infrastructure;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
var apps = new List<(WebApplication App, ServiceRegistry Service)>();
|
||||
namespace CannedNet;
|
||||
|
||||
foreach (var service in Services.All)
|
||||
public static class Program
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder();
|
||||
|
||||
builder.Services.AddLogging(logging =>
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
logging.AddConsole();
|
||||
logging.SetMinimumLevel(LogLevel.Debug);
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
string connectionString = builder.Configuration.GetConnectionString("DefaultConnection")
|
||||
?? "Host=localhost;Port=5432;Database=cannednet;Username=postgres;Password=postgres";
|
||||
|
||||
builder.Services.AddControllers()
|
||||
.AddJsonOptions(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.PropertyNamingPolicy = null;
|
||||
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
|
||||
});
|
||||
|
||||
service.ConfigureBuilder(builder);
|
||||
builder.WebHost.UseUrls($"http://*:{service.Port}");
|
||||
builder.Configuration.AddJsonFile($"AppConfigs/appsettings.{service.Name}.json", optional: true, reloadOnChange: true);
|
||||
builder.Services.AddDbContext<AppDbContext>(options => options.UseNpgsql(connectionString));
|
||||
builder.Services.AddSingleton<NotificationService>();
|
||||
builder.Services.AddScoped<StorefrontFillService>();
|
||||
builder.Services.AddSingleton<JwtTokenService>();
|
||||
builder.Services.AddSingleton<ConfigService>();
|
||||
builder.Services.AddSignalR();
|
||||
|
||||
apps.Add((builder.Build(), service));
|
||||
}
|
||||
builder.Services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
})
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
var rsa = JwtTokenService.GetRsaInstance();
|
||||
|
||||
using var scope = apps[0].App.Services.CreateScope();
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<CannedNet.Data.AppDbContext>();
|
||||
try
|
||||
{
|
||||
dbContext.Database.Migrate();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
dbContext.Database.EnsureCreated();
|
||||
}
|
||||
// TODO: make validissuer and validaudiences/validaudience configurable
|
||||
// TODO: make this key load from config, DO NOT USE THIS KEY IN PROD SERVERS!!!
|
||||
var securityKey = new RsaSecurityKey(rsa) { KeyId = "7C2F041398671515B0862CB23FAF95B03" };
|
||||
|
||||
// automatically fill out storefronts tables from the JSON's
|
||||
var seedingService = scope.ServiceProvider.GetRequiredService<StorefrontFillService>();
|
||||
await seedingService.FillStorefrontsAsync();
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuerSigningKey = true,
|
||||
IssuerSigningKey = securityKey,
|
||||
ValidateIssuer = false,
|
||||
ValidIssuer = "https://auth.lapis.codes",
|
||||
ValidateAudience = false,
|
||||
ValidAudiences = new[]
|
||||
{
|
||||
"https://auth.lapis.codes",
|
||||
"https://auth.lapis.codes/resources"
|
||||
},
|
||||
ValidateLifetime = true,
|
||||
ClockSkew = TimeSpan.Zero,
|
||||
NameClaimType = ClaimTypes.NameIdentifier,
|
||||
RoleClaimType = ClaimTypes.Role
|
||||
};
|
||||
});
|
||||
|
||||
var jwtService = scope.ServiceProvider.GetRequiredService<JwtTokenService>();
|
||||
builder.Services.AddAuthorization();
|
||||
|
||||
WebApplication app = builder.Build();
|
||||
|
||||
foreach (var (app, service) in apps)
|
||||
{
|
||||
service.MapEndpoints(app, jwtService);
|
||||
app.UseRequestLogging();
|
||||
}
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
app.MapHub<NotificationsHub>("/hub/v1");
|
||||
|
||||
await Task.WhenAll(apps.Select(t => t.App.RunAsync()));
|
||||
IHubContext<NotificationsHub> hubContext = app.Services.GetRequiredService<IHubContext<NotificationsHub>>();
|
||||
NotificationService.SetHubContext(hubContext);
|
||||
|
||||
using IServiceScope scope = app.Services.CreateScope();
|
||||
AppDbContext db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
|
||||
try
|
||||
{
|
||||
await db.Database.MigrateAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await db.Database.EnsureCreatedAsync();
|
||||
}
|
||||
|
||||
StorefrontFillService seedingService = scope.ServiceProvider.GetRequiredService<StorefrontFillService>();
|
||||
await seedingService.FillStorefrontsAsync();
|
||||
|
||||
Signatures.Init();
|
||||
|
||||
await app.RunAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace CannedNet.Services;
|
||||
|
||||
public class ConfigService
|
||||
{
|
||||
public ConfigData Config { get; } = new();
|
||||
}
|
||||
|
||||
public class ConfigData
|
||||
{
|
||||
public bool WhitelistOn { get; set; }
|
||||
public List<string> WhitelistedPlatformIds { get; set; } = [];
|
||||
public bool EnableAccountCreation { get; set; } = true;
|
||||
public List<string> AdminAccountIds { get; set; } = [];
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using CannedNet;
|
||||
using CannedNet.Data;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
@@ -11,38 +12,55 @@ using CannedNet.Services.Infrastructure;
|
||||
|
||||
namespace CannedNet.Services.Controllers;
|
||||
|
||||
public class APIController
|
||||
[ApiController]
|
||||
[Route("api")]
|
||||
public class APIController : ControllerBase
|
||||
{
|
||||
public WebApplicationBuilder Initialize(string[]? args = null) => ServiceExtensions.CreateRecNetBuilder(args);
|
||||
private readonly JwtTokenService _jwtService;
|
||||
private readonly StorefrontFillService _storefrontService;
|
||||
private readonly NotificationService _notificationService;
|
||||
|
||||
public void MapEndpoints(WebApplication app)
|
||||
public APIController(JwtTokenService jwtService, StorefrontFillService storefrontService, NotificationService notificationService)
|
||||
{
|
||||
var jwtService = app.Services.GetRequiredService<JwtTokenService>();
|
||||
var storefrontService = app.Services.GetRequiredService<StorefrontFillService>();
|
||||
var notificationService = app.Services.GetRequiredService<NotificationService>();
|
||||
_jwtService = jwtService;
|
||||
_storefrontService = storefrontService;
|
||||
_notificationService = notificationService;
|
||||
}
|
||||
|
||||
app.MapGet("/api/config/v1/amplitude", () => Results.Ok(new
|
||||
[HttpGet("config/v1/amplitude")]
|
||||
public IResult GetAmplitudeConfig() => Results.Ok(new
|
||||
{
|
||||
AmplitudeKey = "a",
|
||||
StatSigKey = "a",
|
||||
RudderStackKey = "a",
|
||||
UseRudderStack = false
|
||||
}));
|
||||
});
|
||||
|
||||
app.MapGet("/api/config/v2", () => Results.Content(File.ReadAllText("JSON/configv2.json"), "application/json"));
|
||||
app.MapGet("/api/versioncheck/v4", () => Results.Content("{\"VersionStatus\":0}", "application/json"));
|
||||
app.MapGet("/api/gameconfigs/v1/all", () => Results.Content(File.ReadAllText("JSON/gameconfigs.json"), "application/json"));
|
||||
[HttpGet("config/v2")]
|
||||
public IResult GetConfigV2() => Results.Content(System.IO.File.ReadAllText("JSON/configv2.json"), "application/json");
|
||||
|
||||
app.MapGet("/api/relationships/v2/get", () => Results.Content("[]", "application/json"));
|
||||
app.MapGet("/api/messages/v2/get", () => Results.Content("[]", "application/json"));
|
||||
[HttpGet("versioncheck/v4")]
|
||||
public IResult GetVersionCheck() => Results.Content("{\"VersionStatus\":0}", "application/json");
|
||||
|
||||
app.MapGet("/api/playerReputation/v1/{id}", (string id) =>
|
||||
Results.Content($"{{\"AccountId\":{id},\"Noteriety\":0,\"CheerGeneral\":0,\"CheerHelpful\":0,\"CheerCreative\":0,\"CheerGreatHost\":0,\"CheerSportsman\":0,\"CheerCredit\":20,\"SelectedCheer\":null}}", "application/json"));
|
||||
[HttpGet("gameconfigs/v1/all")]
|
||||
public IResult GetGameConfigs() => Results.Content(System.IO.File.ReadAllText("JSON/gameconfigs.json"), "application/json");
|
||||
|
||||
app.MapGet("/api/players/v1/progression/{id}", (string id) =>
|
||||
Results.Content($"{{\"PlayerId\":{id},\"Level\":1,\"XP\":0}}", "application/json"));
|
||||
[HttpGet("relationships/v2/get")]
|
||||
public IResult GetRelationships() => Results.Content("[]", "application/json");
|
||||
|
||||
app.MapPost("/api/playerReputation/v1/bulk", async (HttpRequest httpRequest, AppDbContext db) =>
|
||||
[HttpGet("messages/v2/get")]
|
||||
public IResult GetMessages() => Results.Content("[]", "application/json");
|
||||
|
||||
[HttpGet("playerReputation/v1/{id}")]
|
||||
public IResult GetPlayerReputation(string id) =>
|
||||
Results.Content($"{{\"AccountId\":{id},\"Noteriety\":0,\"CheerGeneral\":0,\"CheerHelpful\":0,\"CheerCreative\":0,\"CheerGreatHost\":0,\"CheerSportsman\":0,\"CheerCredit\":20,\"SelectedCheer\":null}}", "application/json");
|
||||
|
||||
[HttpGet("players/v1/progression/{id}")]
|
||||
public IResult GetPlayerProgression(string id) =>
|
||||
Results.Content($"{{\"PlayerId\":{id},\"Level\":1,\"XP\":0}}", "application/json");
|
||||
|
||||
[HttpPost("playerReputation/v1/bulk")]
|
||||
public async Task<IResult> BulkPlayerReputation(HttpRequest httpRequest, AppDbContext db)
|
||||
{
|
||||
/*var ids = await ParseFormIds(httpRequest);
|
||||
|
||||
@@ -65,11 +83,12 @@ public class APIController
|
||||
return Results.Json(reputations);*/
|
||||
|
||||
// TODO: implement real endpoint from grabbing from db
|
||||
var json = File.ReadAllText("JSON/bulkprogression.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/bulkprogression.json");
|
||||
return Results.Content(json, "application/json");
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPost("/api/players/v1/progression/bulk", async (HttpRequest httpRequest, AppDbContext db) =>
|
||||
[HttpPost("players/v1/progression/bulk")]
|
||||
public async Task<IResult> BulkPlayerProgression(HttpRequest httpRequest, AppDbContext db)
|
||||
{
|
||||
var ids = await ParseFormIds(httpRequest);
|
||||
|
||||
@@ -82,9 +101,10 @@ public class APIController
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Json(progressions);
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPost("/api/v1/progression/bulk", async (HttpRequest httpRequest, AppDbContext db) =>
|
||||
[HttpPost("v1/progression/bulk")]
|
||||
public async Task<IResult> BulkProgression(HttpRequest httpRequest, AppDbContext db)
|
||||
{
|
||||
var ids = await ParseFormIds(httpRequest);
|
||||
|
||||
@@ -97,9 +117,9 @@ public class APIController
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Json(progressions);
|
||||
});
|
||||
|
||||
app.MapGet("/api/avatar/v4/items", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
[HttpGet("avatar/v4/items")]
|
||||
public async Task<IResult> GetAvatarItems(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -107,7 +127,7 @@ public class APIController
|
||||
return Results.Unauthorized();
|
||||
|
||||
var token = authHeader.Substring("Bearer ".Length);
|
||||
var accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
var accountId = _jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId))
|
||||
return Results.Unauthorized();
|
||||
@@ -279,9 +299,10 @@ public class APIController
|
||||
var allItems = ownedItems.Cast<object>().Concat(defaultItems).ToList();
|
||||
|
||||
return Results.Json(allItems);
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("/api/avatar/v2", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpGet("avatar/v2")]
|
||||
public async Task<IResult> GetAvatar(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -289,7 +310,7 @@ public class APIController
|
||||
return Results.Unauthorized();
|
||||
|
||||
var token = authHeader.Substring("Bearer ".Length);
|
||||
var accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
var accountId = _jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId))
|
||||
return Results.Unauthorized();
|
||||
@@ -321,9 +342,10 @@ public class APIController
|
||||
SkinColor = avatar.SkinColor,
|
||||
HairColor = avatar.HairColor
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPost("/api/avatar/v2/set", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpPost("avatar/v2/set")]
|
||||
public async Task<IResult> SetAvatar(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -331,7 +353,7 @@ public class APIController
|
||||
return Results.Unauthorized();
|
||||
|
||||
var token = authHeader.Substring("Bearer ".Length);
|
||||
var accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
var accountId = _jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId))
|
||||
return Results.Unauthorized();
|
||||
@@ -361,9 +383,10 @@ public class APIController
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Ok(avatar);
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("/api/avatar/v3/saved", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpGet("avatar/v3/saved")]
|
||||
public async Task<IResult> GetSavedOutfits(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -371,7 +394,7 @@ public class APIController
|
||||
return Results.Unauthorized();
|
||||
|
||||
var token = authHeader.Substring("Bearer ".Length);
|
||||
var accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
var accountId = _jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId))
|
||||
return Results.Unauthorized();
|
||||
@@ -386,19 +409,21 @@ public class APIController
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Json(items);
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("/api/PlayerReporting/v1/moderationBlockDetails", () =>
|
||||
Results.Content("{\"ReportCategory\":0,\"Duration\":0,\"GameSessionId\":0,\"IsHostKick\":false,\"Message\":\"\",\"PlayerIdReporter\":null,\"IsBan\":false}", "application/json"));
|
||||
[HttpGet("PlayerReporting/v1/moderationBlockDetails")]
|
||||
public IResult GetModerationBlockDetails() =>
|
||||
Results.Content("{\"ReportCategory\":0,\"Duration\":0,\"GameSessionId\":0,\"IsHostKick\":false,\"Message\":\"\",\"PlayerIdReporter\":null,\"IsBan\":false}", "application/json");
|
||||
|
||||
app.MapGet("/api/PlayerReporting/v1/voteToKickReasons", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpGet("PlayerReporting/v1/voteToKickReasons")]
|
||||
public async Task<IResult> GetVoteToKickReasons(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var json = File.ReadAllText("JSON/vtkreasons.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/vtkreasons.json");
|
||||
return Results.Content(json, "application/json");
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("/api/settings/v2" +
|
||||
"", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpGet("settings/v2")]
|
||||
public async Task<IResult> GetSettings(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -406,7 +431,7 @@ public class APIController
|
||||
return Results.Unauthorized();
|
||||
|
||||
var token = authHeader.Substring("Bearer ".Length);
|
||||
var accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
var accountId = _jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId))
|
||||
return Results.Unauthorized();
|
||||
@@ -460,9 +485,10 @@ public class APIController
|
||||
}
|
||||
|
||||
return Results.Json(settings);
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPost("/api/settings/v2/set", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpPost("settings/v2/set")]
|
||||
public async Task<IResult> SetSettings(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -470,7 +496,7 @@ public class APIController
|
||||
return Results.Unauthorized();
|
||||
|
||||
var token = authHeader.Substring("Bearer ".Length);
|
||||
var accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
var accountId = _jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId))
|
||||
return Results.Unauthorized();
|
||||
@@ -514,14 +540,16 @@ public class APIController
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Ok();
|
||||
});
|
||||
|
||||
app.MapGet("/api/equipment/v2/getUnlocked", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
[HttpGet("equipment/v2/getUnlocked")]
|
||||
public async Task<IResult> GetUnlockedEquipment(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
// TODO ADD FUNCTIONALITY
|
||||
return "[]";
|
||||
});
|
||||
app.MapGet("/api/consumables/v2/getUnlocked", async (HttpRequest request, AppDbContext db, JwtTokenService jwtService) =>
|
||||
return Results.Content("[]", "application/json");
|
||||
}
|
||||
|
||||
[HttpGet("consumables/v2/getUnlocked")]
|
||||
public async Task<IResult> GetUnlockedConsumables(HttpRequest request, AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
if (string.IsNullOrEmpty(authHeader) || !authHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||
@@ -538,14 +566,18 @@ public class APIController
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Json(consumables);
|
||||
});
|
||||
app.MapGet("/api/objectives/v1/myprogress", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("objectives/v1/myprogress")]
|
||||
public async Task<IResult> GetMyProgress(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
// TODO ADD FUNCTIONALITY
|
||||
var json = File.ReadAllText("JSON/tempmyprogress.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/tempmyprogress.json");
|
||||
return Results.Content(json, "application/json");
|
||||
});
|
||||
app.MapGet("/api/avatar/v2/gifts", async (HttpRequest request, AppDbContext db, JwtTokenService jwtService) =>
|
||||
}
|
||||
|
||||
[HttpGet("avatar/v2/gifts")]
|
||||
public async Task<IResult> GetAvatarGifts(HttpRequest request, AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -570,27 +602,37 @@ public class APIController
|
||||
{
|
||||
return Results.Problem($"Error retrieving gifts: {ex.Message}");
|
||||
}
|
||||
});
|
||||
app.MapGet("/api/gamerewards/v1/pending", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("gamerewards/v1/pending")]
|
||||
public async Task<IResult> GetPendingGameRewards(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
// TODO ADD FUNCTIONALITY
|
||||
return "[]";
|
||||
});
|
||||
app.MapGet("/api/communityboard/v2/current", async (HttpRequest request, AppDbContext db) =>
|
||||
return Results.Content("[]", "application/json");
|
||||
}
|
||||
|
||||
[HttpGet("communityboard/v2/current")]
|
||||
public async Task<IResult> GetCommunityBoard(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var json = File.ReadAllText("JSON/communityboard.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/communityboard.json");
|
||||
return Results.Content(json, "application/json");
|
||||
});
|
||||
app.MapGet("/api/playerevents/v1/all", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("playerevents/v1/all")]
|
||||
public async Task<IResult> GetPlayerEvents(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
// TODO ADD FUNCTIONALITY
|
||||
return Results.Content("{\"Created\":[],\"Responses\":[]}", "application/json");
|
||||
});
|
||||
app.MapPost("/api/CampusCard/v1/UpdateAndGetSubscription", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpPost("CampusCard/v1/UpdateAndGetSubscription")]
|
||||
public async Task<IResult> UpdateAndGetSubscription(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
return Results.Json(new { subscription = (object?)null, platformAccountSubscribedPlayerId = (object?)null });
|
||||
});
|
||||
app.MapGet("/api/storefronts/v4/balance/2", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("storefronts/v4/balance/2")]
|
||||
public async Task<IResult> GetBalance(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -598,7 +640,7 @@ public class APIController
|
||||
return Results.Unauthorized();
|
||||
|
||||
var token = authHeader.Substring("Bearer ".Length);
|
||||
var accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
var accountId = _jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId))
|
||||
return Results.Unauthorized();
|
||||
@@ -611,33 +653,45 @@ public class APIController
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Json(balance);
|
||||
});
|
||||
app.MapGet("/api/storefronts/v1/p2p/betaEnabled", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("storefronts/v1/p2p/betaEnabled")]
|
||||
public async Task<IResult> GetP2PBetaEnabled(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
return "false";
|
||||
});
|
||||
app.MapGet("/api/announcement/v1/get", async (HttpRequest request, AppDbContext db) =>
|
||||
return Results.Content("false", "application/json");
|
||||
}
|
||||
|
||||
[HttpGet("announcement/v1/get")]
|
||||
public async Task<IResult> GetAnnouncement(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var json = File.ReadAllText("JSON/announcements.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/announcements.json");
|
||||
return Results.Content(json, "application/json");
|
||||
});
|
||||
app.MapGet("/api/roomkeys/v1/mine", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("roomkeys/v1/mine")]
|
||||
public async Task<IResult> GetMyRoomKeys(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
// TODO ADD FUNCTIONALITY
|
||||
return "[]";
|
||||
});
|
||||
app.MapGet("/api/quickPlay/v1/getandclear", async (HttpRequest request, AppDbContext db) =>
|
||||
return Results.Content("[]", "application/json");
|
||||
}
|
||||
|
||||
[HttpGet("quickPlay/v1/getandclear")]
|
||||
public async Task<IResult> GetQuickPlay(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
// TODO ADD FUNCTIONALITY
|
||||
return Results.Content("{\"RoomName\":null,\"ActionCode\":null,\"TargetPlayerId\":null}", "application/json");
|
||||
});
|
||||
app.MapGet("/api/roomkeys/v1/room", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("roomkeys/v1/room")]
|
||||
public async Task<IResult> GetRoomKeys(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
// TODO ADD FUNCTIONALITY
|
||||
var roomid = request.Query["roomId"];
|
||||
return "[]";
|
||||
});
|
||||
app.MapGet("/api/accounts/v1/getBio", async (HttpRequest request, AppDbContext db) =>
|
||||
return Results.Content("[]", "application/json");
|
||||
}
|
||||
|
||||
[HttpGet("accounts/v1/getBio")]
|
||||
public async Task<IResult> GetBio(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -645,7 +699,7 @@ public class APIController
|
||||
return Results.Unauthorized();
|
||||
|
||||
var token = authHeader.Substring("Bearer ".Length);
|
||||
var accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
var accountId = _jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId) || !int.TryParse(accountId.AsSpan(), out var id))
|
||||
return Results.Unauthorized();
|
||||
@@ -655,8 +709,10 @@ public class APIController
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Json(bio);
|
||||
});
|
||||
app.MapPost("/api/accounts/v1/forplatformids", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpPost("accounts/v1/forplatformids")]
|
||||
public async Task<IResult> ForPlatformIds(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
request.EnableBuffering();
|
||||
request.Body.Position = 0;
|
||||
@@ -690,14 +746,16 @@ public class APIController
|
||||
}
|
||||
|
||||
return Results.Json(results);
|
||||
});
|
||||
app.MapGet("/api/storefronts/v3/giftdropstore/3", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("storefronts/v3/giftdropstore/3")]
|
||||
public async Task<IResult> GetGiftDropStore3(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var storefronts = await storefrontService.GetStorefrontsAsync();
|
||||
var storefronts = await _storefrontService.GetStorefrontsAsync();
|
||||
var storefront = storefronts.FirstOrDefault(s => s.StorefrontType == 2 && s.Name == "watch_store");
|
||||
if (storefront == null)
|
||||
{
|
||||
var json = File.ReadAllText("JSON/storefront3.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/storefront3.json");
|
||||
return Results.Content(json, "application/json");
|
||||
}
|
||||
var storeItems = storefront.Items.Select(item => new
|
||||
@@ -741,14 +799,18 @@ public class APIController
|
||||
}).ToList();
|
||||
var response = new { storefront.Id, storefront.Name, storefront.StorefrontType, storefront.NextUpdate, StoreItems = storeItems };
|
||||
return Results.Ok(response);
|
||||
});
|
||||
app.MapGet("/api/challenge/v2/getCurrent", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("challenge/v2/getCurrent")]
|
||||
public async Task<IResult> GetCurrentChallenge(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var json = File.ReadAllText("JSON/weeklychallenge.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/weeklychallenge.json");
|
||||
return Results.Content(json, "application/json");
|
||||
//return "{}";
|
||||
});
|
||||
app.MapGet("/roomserver/rooms/bulk", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("/roomserver/rooms/bulk")]
|
||||
public async Task<IResult> GetBulkRooms(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var idParam = request.Query["id"].FirstOrDefault();
|
||||
var nameParam = request.Query["name"].FirstOrDefault();
|
||||
@@ -850,9 +912,10 @@ public class APIController
|
||||
}).ToList();
|
||||
|
||||
return Results.Json(response);
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("/roomserver/rooms/hot", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpGet("/roomserver/rooms/hot")]
|
||||
public async Task<IResult> GetHotRooms(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var tagFilter = request.Query["tag"].FirstOrDefault()?.ToLower();
|
||||
|
||||
@@ -960,9 +1023,10 @@ public class APIController
|
||||
};
|
||||
|
||||
return Results.Json(response);
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("/roomserver/roomsandplaylists/hot", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpGet("/roomserver/roomsandplaylists/hot")]
|
||||
public async Task<IResult> GetHotRoomsAndPlaylists(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
// should sort by popularity but idk how to yet so we just d it by id order
|
||||
var allRooms = await db.Rooms
|
||||
@@ -1057,15 +1121,18 @@ public class APIController
|
||||
};
|
||||
|
||||
return Results.Json(response);
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("/roomserver/rooms/createdby/me", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpGet("/roomserver/rooms/createdby/me")]
|
||||
public async Task<IResult> GetMyCreatedRooms(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
// TODO ADD FUNCTIONALITY
|
||||
var json = File.ReadAllText("JSON/ownedrooms.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/ownedrooms.json");
|
||||
return Results.Content(json, "application/json");
|
||||
});
|
||||
app.MapGet("/roomserver/rooms/{id}", async (HttpRequest request, AppDbContext db, string id) =>
|
||||
}
|
||||
|
||||
[HttpGet("/roomserver/rooms/{id}")]
|
||||
public async Task<IResult> GetRoom(HttpRequest request, AppDbContext db, string id)
|
||||
{
|
||||
// this sucked to do
|
||||
if (!int.TryParse(id, out var roomId))
|
||||
@@ -1185,29 +1252,37 @@ public class APIController
|
||||
};
|
||||
|
||||
return Results.Json(response);
|
||||
});
|
||||
app.MapGet("/api/images/v2/named", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("images/v2/named")]
|
||||
public async Task<IResult> GetNamedImages(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var json = File.ReadAllText("JSON/namedimages.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/namedimages.json");
|
||||
return Results.Content(json, "application/json");
|
||||
});
|
||||
app.MapPost("/api/objectives/v1/updateobjective", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpPost("objectives/v1/updateobjective")]
|
||||
public async Task<IResult> UpdateObjective(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
// TODO: implement saving daily
|
||||
return Results.Ok();
|
||||
});
|
||||
app.MapPost("/api/PlayerReporting/v1/hile", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpPost("PlayerReporting/v1/hile")]
|
||||
public async Task<IResult> Hile(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
// stops crashing the game due to bepinex winhttp.dll (or melonloader version.dll)
|
||||
return Results.Ok();
|
||||
});
|
||||
app.MapGet("/api/storefronts/v3/giftdropstore/300", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("storefronts/v3/giftdropstore/300")]
|
||||
public async Task<IResult> GetGiftDropStore300(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var storefronts = await storefrontService.GetStorefrontsAsync();
|
||||
var storefronts = await _storefrontService.GetStorefrontsAsync();
|
||||
var storefront = storefronts.FirstOrDefault(s => s.StorefrontType == 300 && s.Name == "rc_cafe_storefront");
|
||||
if (storefront == null)
|
||||
{
|
||||
var json = File.ReadAllText("JSON/cafestorefront.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/cafestorefront.json");
|
||||
return Results.Content(json, "application/json");
|
||||
}
|
||||
var storeItems = storefront.Items.Select(item => new
|
||||
@@ -1251,14 +1326,16 @@ public class APIController
|
||||
}).ToList();
|
||||
var response = new { storefront.Id, storefront.Name, storefront.StorefrontType, storefront.NextUpdate, StoreItems = storeItems };
|
||||
return Results.Ok(response);
|
||||
});
|
||||
app.MapGet("/api/storefronts/v3/giftdropstore/2", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("storefronts/v3/giftdropstore/2")]
|
||||
public async Task<IResult> GetGiftDropStore2(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var storefronts = await storefrontService.GetStorefrontsAsync();
|
||||
var storefronts = await _storefrontService.GetStorefrontsAsync();
|
||||
var storefront = storefronts.FirstOrDefault(s => s.StorefrontType == 2 && s.Name == "rec_center_store");
|
||||
if (storefront == null)
|
||||
{
|
||||
var json = File.ReadAllText("JSON/storefront12.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/storefront12.json");
|
||||
return Results.Content(json, "application/json");
|
||||
}
|
||||
var storeItems = storefront.Items.Select(item => new
|
||||
@@ -1302,8 +1379,10 @@ public class APIController
|
||||
}).ToList();
|
||||
var response = new { storefront.Id, storefront.Name, storefront.StorefrontType, storefront.NextUpdate, StoreItems = storeItems };
|
||||
return Results.Ok(response);
|
||||
});
|
||||
app.MapPost("/api/storefronts/v2/buyItem", async (HttpRequest request, BuyItemRequest buyRequest, AppDbContext db, JwtTokenService jwtService) =>
|
||||
}
|
||||
|
||||
[HttpPost("storefronts/v2/buyItem")]
|
||||
public async Task<IResult> BuyItem(HttpRequest request, [FromBody] BuyItemRequest buyRequest, AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -1436,7 +1515,7 @@ public class APIController
|
||||
|
||||
try
|
||||
{
|
||||
var purchaseNotification = notificationService.CreateNotification(
|
||||
var purchaseNotification = _notificationService.CreateNotification(
|
||||
PushNotificationId.StorefrontBalancePurchase,
|
||||
id: storefrontItem.Id,
|
||||
toAccountId: id,
|
||||
@@ -1448,7 +1527,7 @@ public class APIController
|
||||
{ "CurrencyType", buyRequest.CurrencyType }
|
||||
}
|
||||
);
|
||||
await notificationService.SendNotificationToPlayer(id, purchaseNotification);
|
||||
await _notificationService.SendNotificationToPlayer(id, purchaseNotification);
|
||||
}
|
||||
catch (Exception notifEx)
|
||||
{
|
||||
@@ -1462,9 +1541,10 @@ public class APIController
|
||||
{
|
||||
return Results.Problem($"Error processing purchase: {ex.Message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPost("/api/avatar/v2/gifts/generate", async (HttpRequest request, AppDbContext db, JwtTokenService jwtService) =>
|
||||
[HttpPost("avatar/v2/gifts/generate")]
|
||||
public async Task<IResult> GenerateGift(HttpRequest request, AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -1622,9 +1702,10 @@ public class APIController
|
||||
{
|
||||
return Results.Problem($"Error generating gift: {ex.Message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPost("/api/avatar/v2/gifts/consume/", async (HttpRequest request, AppDbContext db, JwtTokenService jwtService) =>
|
||||
[HttpPost("avatar/v2/gifts/consume/")]
|
||||
public async Task<IResult> ConsumeGift(HttpRequest request, AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -1752,22 +1833,28 @@ public class APIController
|
||||
{
|
||||
return Results.Problem($"Error consuming gift: {ex.Message}");
|
||||
}
|
||||
});
|
||||
app.MapGet("/api/rooms/v1/filters", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("rooms/v1/filters")]
|
||||
public async Task<IResult> GetRoomFilters(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var json = File.ReadAllText("JSON/roomfilters.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/roomfilters.json");
|
||||
return Results.Content(json, "application/json");
|
||||
});
|
||||
app.MapGet("/roomserver/rooms/{id}/interactionby/me", async (HttpRequest request, AppDbContext db, string id) =>
|
||||
}
|
||||
|
||||
[HttpGet("/roomserver/rooms/{id}/interactionby/me")]
|
||||
public async Task<IResult> GetInteractionByMe(HttpRequest request, AppDbContext db, string id)
|
||||
{
|
||||
// TODO: implement
|
||||
return Results.Content("{\"Cheered\":false,\"Favorited\":false}", "application/json");
|
||||
});
|
||||
app.MapPost("/api/images/v4/uploadsaved", async (HttpContext context) =>
|
||||
}
|
||||
|
||||
[HttpPost("images/v4/uploadsaved")]
|
||||
public async Task<IResult> UploadSavedImage()
|
||||
{
|
||||
try
|
||||
{
|
||||
var form = await context.Request.ReadFormAsync();
|
||||
var form = await Request.ReadFormAsync();
|
||||
var file = form.Files.FirstOrDefault();
|
||||
|
||||
if (file == null)
|
||||
@@ -1787,7 +1874,7 @@ public class APIController
|
||||
var savedFileName = imageId + extension;
|
||||
var filePath = Path.Combine(ImagesDir, savedFileName);
|
||||
|
||||
using (var fileStream = File.Create(filePath))
|
||||
using (var fileStream = System.IO.File.Create(filePath))
|
||||
{
|
||||
await file.CopyToAsync(fileStream);
|
||||
}
|
||||
@@ -1801,7 +1888,6 @@ public class APIController
|
||||
{
|
||||
return Results.Problem($"Error uploading image: {ex.Message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static object[]? TryDeserializeTags(string json)
|
||||
@@ -1874,3 +1960,5 @@ public class APIController
|
||||
ImagesDir = dir;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
using CannedNet.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using CannedNet.Services;
|
||||
using CannedNet.Services.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CannedNet.Services.Controllers;
|
||||
|
||||
public class AccountsController
|
||||
[ApiController]
|
||||
public class AccountsController : ControllerBase
|
||||
{
|
||||
public WebApplicationBuilder Initialize(string[]? args = null) => ServiceExtensions.CreateRecNetBuilder(args);
|
||||
|
||||
public void MapEndpoints(WebApplication app, JwtTokenService jwtService)
|
||||
{
|
||||
app.MapGet("/", (HttpRequest request) =>
|
||||
{
|
||||
return Results.Ok("FUCKL MYSJDIOJD");
|
||||
});
|
||||
|
||||
app.MapGet("/account/me", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpGet("/account/me")]
|
||||
public async Task<IResult> AccountMe(HttpRequest request, AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -56,9 +48,10 @@ public class AccountsController
|
||||
};
|
||||
|
||||
return Results.Ok(selfAccount);
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("/account/bulk", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpGet("/account/bulk")]
|
||||
public async Task<IResult> AccountBulk(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var ids = request.Query["id"];
|
||||
var accountIds = new List<int>();
|
||||
@@ -89,9 +82,10 @@ public class AccountsController
|
||||
}).ToList();
|
||||
|
||||
return Results.Json(result);
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("/account/{id}", async (HttpRequest request, string id, AppDbContext db) =>
|
||||
[HttpGet("/account/{id}")]
|
||||
public async Task<IResult> AccountById(string id, AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(id, out var accountId))
|
||||
return Results.BadRequest();
|
||||
@@ -114,9 +108,10 @@ public class AccountsController
|
||||
};
|
||||
|
||||
return Results.Json(result);
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPost("/account/create", async (HttpRequest httpRequest, AppDbContext db) =>
|
||||
[HttpPost("/account/create")]
|
||||
public async Task<IResult> AccountCreate(HttpRequest httpRequest, AppDbContext db)
|
||||
{
|
||||
int platform = 0;
|
||||
string platformId = "";
|
||||
@@ -153,17 +148,17 @@ public class AccountsController
|
||||
catch { }
|
||||
}
|
||||
|
||||
var accountId = new Random().Next(10000, 99999);
|
||||
var newAccountId = new Random().Next(10000, 99999);
|
||||
var account = new Account
|
||||
{
|
||||
AccountId = accountId,
|
||||
AccountId = newAccountId,
|
||||
ProfileImage = "DefaultProfileImage.jpg",
|
||||
IsJunior = false,
|
||||
Platforms = 0,
|
||||
PersonalPronouns = 0,
|
||||
IdentityFlags = 0,
|
||||
Username = $"Player{accountId}",
|
||||
DisplayName = $"Player{accountId}",
|
||||
Username = $"Player{newAccountId}",
|
||||
DisplayName = $"Player{newAccountId}",
|
||||
CreatedAt = DateTime.UtcNow
|
||||
};
|
||||
|
||||
@@ -173,7 +168,7 @@ public class AccountsController
|
||||
{
|
||||
db.CachedLogins.Add(new CachedLogin
|
||||
{
|
||||
AccountId = accountId,
|
||||
AccountId = newAccountId,
|
||||
Platform = (PlatformType)platform,
|
||||
PlatformID = platformId,
|
||||
LastLoginTime = DateTime.UtcNow,
|
||||
@@ -183,18 +178,16 @@ public class AccountsController
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
// create players dorm room
|
||||
var maxRoomId = await db.Rooms.MaxAsync(r => (int?)r.RoomId) ?? 0;
|
||||
var maxId = await db.Rooms.MaxAsync(r => (int?)r.Id) ?? 0;
|
||||
var dormRoomId = maxRoomId + 1;
|
||||
var dormId = maxId + 1;
|
||||
var dormRoom = new Room
|
||||
{
|
||||
Id = maxId + 1,
|
||||
RoomId = dormRoomId,
|
||||
Name = "DormRoom",
|
||||
Description = "Your personal room",
|
||||
CreatorAccountId = accountId,
|
||||
CreatorAccountId = newAccountId,
|
||||
ImageName = "",
|
||||
State = 0,
|
||||
Accessibility = 0,
|
||||
@@ -220,7 +213,6 @@ public class AccountsController
|
||||
};
|
||||
db.Rooms.Add(dormRoom);
|
||||
|
||||
// Create a sub room for the dorm
|
||||
var dormSubRoom = new SubRoom
|
||||
{
|
||||
RoomId = dormRoomId,
|
||||
@@ -230,7 +222,7 @@ public class AccountsController
|
||||
IsSandbox = false,
|
||||
MaxPlayers = 4,
|
||||
Accessibility = 0,
|
||||
UnitySceneId = "76d98498-60a1-430c-ab76-b54a29b7a163", // Dorm scene ID
|
||||
UnitySceneId = "76d98498-60a1-430c-ab76-b54a29b7a163",
|
||||
DataSavedAt = DateTime.UtcNow
|
||||
};
|
||||
db.SubRooms.Add(dormSubRoom);
|
||||
@@ -238,8 +230,10 @@ public class AccountsController
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Results.Ok(RecNetResultWithValue<Account>.Ok(account));
|
||||
});
|
||||
app.MapGet("/parentalcontrol/me", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpGet("/parentalcontrol/me")]
|
||||
public IResult ParentalControlMe(HttpRequest request, JwtTokenService jwtService)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -252,13 +246,11 @@ public class AccountsController
|
||||
if (string.IsNullOrEmpty(accountId))
|
||||
return Results.Unauthorized();
|
||||
|
||||
if (!int.TryParse(accountId.AsSpan(), out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
return Results.Content($"{{\"accountId\":{accountId},\"disallowInAppPurchases\":false}}", "application/json");
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPut("/account/me/displayname", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpPut("/account/me/displayname")]
|
||||
public async Task<IResult> UpdateDisplayName(HttpRequest request, AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -312,9 +304,10 @@ public class AccountsController
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Results.Ok(RecNetResult.Ok());
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPut("/account/me/username", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpPut("/account/me/username")]
|
||||
public async Task<IResult> UpdateUsername(HttpRequest request, AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -368,9 +361,10 @@ public class AccountsController
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Results.Ok(RecNetResult.Ok());
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("/account/{id}/bio", async (HttpRequest request, string id, AppDbContext db) =>
|
||||
[HttpGet("/account/{id}/bio")]
|
||||
public async Task<IResult> GetAccountBio(string id, AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(id, out var accountId))
|
||||
return Results.BadRequest();
|
||||
@@ -383,9 +377,10 @@ public class AccountsController
|
||||
}
|
||||
|
||||
return Results.Json(new { accountId = bio.accountId, bio = bio.bio });
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPut("/account/me/bio", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpPut("/account/me/bio")]
|
||||
public async Task<IResult> UpdateBio(HttpRequest request, AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -451,9 +446,10 @@ public class AccountsController
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Results.Json(new { success = true });
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPut("/account/me/profileimage", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpPut("/account/me/profileimage")]
|
||||
public async Task<IResult> UpdateProfileImage(HttpRequest request, AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -507,6 +503,5 @@ public class AccountsController
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Results.Ok(RecNetResult.Ok());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,32 @@
|
||||
using CannedNet;
|
||||
using CannedNet.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using CannedNet.Services;
|
||||
using CannedNet.Services.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CannedNet.Services.Controllers;
|
||||
|
||||
public class AuthController
|
||||
[ApiController]
|
||||
public class AuthController : ControllerBase
|
||||
{
|
||||
public WebApplicationBuilder Initialize(string[]? args = null) => ServiceExtensions.CreateRecNetBuilder(args);
|
||||
|
||||
public void MapEndpoints(WebApplication app)
|
||||
[HttpGet("/eac/challenge")]
|
||||
public async Task<IResult> EacChallenge()
|
||||
{
|
||||
var jwtService = app.Services.GetRequiredService<JwtTokenService>();
|
||||
|
||||
app.MapGet("/eac/challenge", () =>
|
||||
{
|
||||
var file = File.ReadAllText("JSON/eacchallenge.txt");
|
||||
string file = await System.IO.File.ReadAllTextAsync("JSON/eacchallenge.txt");
|
||||
return Results.Content(file, "text/plain");
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("/cachedlogin/forplatformid/{platform}/{id}", async (string platform, string id, AppDbContext db) =>
|
||||
[HttpGet("/cachedlogin/forplatformid/{platform}/{id}")]
|
||||
public async Task<IResult> CachedLoginForPlatformId(string platform, string id, AppDbContext db)
|
||||
{
|
||||
var platformType = int.Parse(platform);
|
||||
var logins = await db.CachedLogins
|
||||
int platformType = int.Parse(platform);
|
||||
List<CachedLogin> logins = await db.CachedLogins
|
||||
.Where(c => c.Platform == (PlatformType)platformType && c.PlatformID == id)
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Json(logins.Any() ? logins : new List<object>());
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPost("/connect/token", async (HttpRequest httpRequest, AppDbContext db) =>
|
||||
[HttpPost("/connect/token")]
|
||||
public async Task<IResult> ConnectToken(HttpRequest httpRequest, AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
string accountId = "";
|
||||
string platformId = "";
|
||||
@@ -87,12 +83,11 @@ public class AuthController
|
||||
scope = "offline_access profile rn rn.accounts rn.accounts.gc rn.api rn.chat rn.clubs rn.commerce rn.match.read rn.match.write rn.notify rn.rooms rn.storage",
|
||||
key = "8oQ+e+WQaOBPbEcakhqs3dwZZdOmmyDUmJSD9u4AHMY="
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("/role/developer/{id}", async (HttpRequest request, AppDbContext db, string id) =>
|
||||
[HttpGet("/role/developer/{id}")]
|
||||
public IResult GetDeveloperRole(string id)
|
||||
{
|
||||
// TODO: implement
|
||||
return Results.Ok(RecNetResult.Ok());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
using CannedNet.Services.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CannedNet.Services.Controllers;
|
||||
|
||||
public class CDNController
|
||||
[ApiController]
|
||||
public class CDNController : ControllerBase
|
||||
{
|
||||
public WebApplicationBuilder Initialize(string[]? args = null) => ServiceExtensions.CreateRecNetBuilder(args);
|
||||
|
||||
public void MapEndpoints(WebApplication app)
|
||||
[HttpGet("/config/LoadingScreenTipData")]
|
||||
public IResult LoadingScreenTipData()
|
||||
{
|
||||
app.MapGet("/config/LoadingScreenTipData", (HttpRequest request) =>
|
||||
{
|
||||
var json = File.ReadAllText("JSON/loadingscreentipdata.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/loadingscreentipdata.json");
|
||||
return Results.Content(json, "application/json");
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPost("/upload", async (HttpContext context) =>
|
||||
[HttpPost("/upload")]
|
||||
public async Task<IResult> Upload()
|
||||
{
|
||||
try
|
||||
{
|
||||
var context = HttpContext;
|
||||
|
||||
var form = await context.Request.ReadFormAsync();
|
||||
var file = form.Files.FirstOrDefault();
|
||||
|
||||
@@ -43,7 +44,7 @@ public class CDNController
|
||||
Directory.CreateDirectory("Images");
|
||||
}
|
||||
|
||||
using (var fileStream = File.Create(filePath))
|
||||
using (var fileStream = System.IO.File.Create(filePath))
|
||||
{
|
||||
await file.CopyToAsync(fileStream);
|
||||
}
|
||||
@@ -57,6 +58,5 @@ public class CDNController
|
||||
{
|
||||
return Results.Problem($"Error uploading image: {ex.Message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
using CannedNet.Services.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CannedNet.Services.Controllers;
|
||||
|
||||
public class ChatController
|
||||
[ApiController]
|
||||
public class ChatController : ControllerBase
|
||||
{
|
||||
public WebApplicationBuilder Initialize(string[]? args = null) => ServiceExtensions.CreateRecNetBuilder(args);
|
||||
|
||||
public void MapEndpoints(WebApplication app)
|
||||
[HttpGet("/thread")]
|
||||
public IResult Thread()
|
||||
{
|
||||
app.MapGet("/thread", () => Results.Content("[]", "application/json"));
|
||||
return Results.Content("[]", "application/json");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
using CannedNet.Services.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CannedNet.Services.Controllers;
|
||||
|
||||
public class ClubsController
|
||||
[ApiController]
|
||||
public class ClubsController : ControllerBase
|
||||
{
|
||||
public WebApplicationBuilder Initialize(string[]? args = null) => ServiceExtensions.CreateRecNetBuilder(args);
|
||||
|
||||
public void MapEndpoints(WebApplication app)
|
||||
{
|
||||
app.MapGet("/club/home/me", () =>
|
||||
[HttpGet("/club/home/me")]
|
||||
public IResult ClubHomeMe()
|
||||
{
|
||||
return Results.NotFound();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,13 @@
|
||||
using CannedNet.Services.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CannedNet.Services.Controllers;
|
||||
|
||||
public class CommerceController
|
||||
[ApiController]
|
||||
public class CommerceController : ControllerBase
|
||||
{
|
||||
public WebApplicationBuilder Initialize(string[]? args = null) => ServiceExtensions.CreateRecNetBuilder(args);
|
||||
|
||||
public void MapEndpoints(WebApplication app)
|
||||
{
|
||||
app.MapGet("/purchase/v1/hasspentmoney", (HttpRequest request) =>
|
||||
[HttpGet("/purchase/v1/hasspentmoney")]
|
||||
public IResult HasSpentMoney()
|
||||
{
|
||||
return Results.NotFound();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,17 @@
|
||||
using System.Net.Mime;
|
||||
using CannedNet.Services.Infrastructure;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CannedNet.Services.Controllers;
|
||||
|
||||
public class ImageController
|
||||
[ApiController]
|
||||
public class ImageController : ControllerBase
|
||||
{
|
||||
private static readonly byte[] PlaceholderJpeg;
|
||||
private static readonly string ImagesDir;
|
||||
|
||||
static ImageController()
|
||||
{
|
||||
@@ -20,26 +22,28 @@ public class ImageController
|
||||
using var ms = new MemoryStream();
|
||||
image.SaveAsJpeg(ms, new JpegEncoder { Quality = 50 });
|
||||
PlaceholderJpeg = ms.ToArray();
|
||||
|
||||
var dir = "Images";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
ImagesDir = dir;
|
||||
}
|
||||
|
||||
public WebApplicationBuilder Initialize(string[]? args = null)
|
||||
=> ServiceExtensions.CreateRecNetBuilder(args);
|
||||
|
||||
public void MapEndpoints(WebApplication app)
|
||||
[HttpGet("/{imageName}")]
|
||||
public async Task<IResult> GetImage(string imageName)
|
||||
{
|
||||
var imagesDir = Path.Combine("Images");
|
||||
Directory.CreateDirectory(imagesDir);
|
||||
var context = HttpContext;
|
||||
|
||||
app.MapGet("/{imageName}", async (HttpContext context, string imageName) =>
|
||||
{
|
||||
var filePath = Path.Combine(imagesDir, imageName);
|
||||
var filePath = Path.Combine(ImagesDir, imageName);
|
||||
|
||||
byte[] imageBytes;
|
||||
string contentType;
|
||||
|
||||
if (File.Exists(filePath))
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
imageBytes = await File.ReadAllBytesAsync(filePath);
|
||||
imageBytes = await System.IO.File.ReadAllBytesAsync(filePath);
|
||||
var ext = Path.GetExtension(imageName).ToLowerInvariant();
|
||||
contentType = ext switch
|
||||
{
|
||||
@@ -66,17 +70,17 @@ public class ImageController
|
||||
return Results.File(imageBytes, contentType);
|
||||
}
|
||||
|
||||
using var image = Image.Load(imageBytes);
|
||||
using var loadedImage = Image.Load(imageBytes);
|
||||
|
||||
var resizeWidth = 0;
|
||||
var resizeHeight = 0;
|
||||
|
||||
if (!string.IsNullOrEmpty(cropSquare) && cropSquare != "0" && cropSquare != "false")
|
||||
{
|
||||
var size = Math.Min(image.Width, image.Height);
|
||||
var x = (image.Width - size) / 2;
|
||||
var y = (image.Height - size) / 2;
|
||||
image.Mutate(img => img.Crop(new Rectangle(x, y, size, size)));
|
||||
var size = Math.Min(loadedImage.Width, loadedImage.Height);
|
||||
var x = (loadedImage.Width - size) / 2;
|
||||
var y = (loadedImage.Height - size) / 2;
|
||||
loadedImage.Mutate(img => img.Crop(new Rectangle(x, y, size, size)));
|
||||
}
|
||||
|
||||
if (int.TryParse(widthStr, out var w))
|
||||
@@ -87,15 +91,14 @@ public class ImageController
|
||||
|
||||
if (resizeWidth > 0 || resizeHeight > 0)
|
||||
{
|
||||
image.Mutate(x => x.Resize(resizeWidth, resizeHeight));
|
||||
loadedImage.Mutate(x => x.Resize(resizeWidth, resizeHeight));
|
||||
}
|
||||
|
||||
using var output = new MemoryStream();
|
||||
await image.SaveAsJpegAsync(output, new JpegEncoder { Quality = 85 });
|
||||
await loadedImage.SaveAsJpegAsync(output, new JpegEncoder { Quality = 85 });
|
||||
imageBytes = output.ToArray();
|
||||
SignImageResponse(context, ref imageBytes);
|
||||
return Results.File(imageBytes, "image/jpeg");
|
||||
});
|
||||
}
|
||||
|
||||
private static void SignImageResponse(HttpContext context, ref byte[] imageBytes)
|
||||
|
||||
@@ -2,38 +2,36 @@ using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using CannedNet.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using CannedNet.Services;
|
||||
using CannedNet.Services.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CannedNet.Services.Controllers;
|
||||
|
||||
public class MatchmakingController
|
||||
[ApiController]
|
||||
public class MatchmakingController : ControllerBase
|
||||
{
|
||||
public WebApplicationBuilder Initialize(string[]? args = null) => ServiceExtensions.CreateRecNetBuilder(args);
|
||||
|
||||
public void MapEndpoints(WebApplication app)
|
||||
[HttpPost("/player/login")]
|
||||
public IResult PlayerLogin()
|
||||
{
|
||||
var jwtService = app.Services.GetRequiredService<JwtTokenService>();
|
||||
return Results.Ok();
|
||||
}
|
||||
|
||||
app.MapPost("/player/login", () => Results.Ok());
|
||||
|
||||
app.MapGet("/player", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpGet("/player")]
|
||||
public async Task<IResult> GetPlayer(HttpRequest request, AppDbContext db)
|
||||
{
|
||||
var id = request.Query["id"].FirstOrDefault();
|
||||
if (string.IsNullOrEmpty(id) || !int.TryParse(id, out var accountId))
|
||||
{
|
||||
var json = File.ReadAllText("JSON/getplayer.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/getplayer.json");
|
||||
return Results.Content(json, "application/json");
|
||||
}
|
||||
|
||||
var account = await db.Accounts.FindAsync(accountId);
|
||||
if (account == null)
|
||||
{
|
||||
var json = File.ReadAllText("JSON/getplayer.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/getplayer.json");
|
||||
return Results.Content(json, "application/json");
|
||||
}
|
||||
|
||||
// Get the player's active room instance
|
||||
var roomInstance = await db.RoomInstances
|
||||
.Where(r => r.OwnerAccountId == accountId)
|
||||
.OrderByDescending(r => r.Id)
|
||||
@@ -74,9 +72,10 @@ public class MatchmakingController
|
||||
};
|
||||
|
||||
return Results.Json(result);
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPost("/goto/room/{room}", async (HttpRequest request, string room, AppDbContext db) =>
|
||||
[HttpPost("/goto/room/{room}")]
|
||||
public async Task<IResult> GotoRoom(string room, HttpRequest request, AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -130,7 +129,6 @@ public class MatchmakingController
|
||||
int subRoomId = subRoom?.SubRoomId ?? 0;
|
||||
int maxCapacity = subRoom?.MaxPlayers ?? 4;
|
||||
|
||||
|
||||
RoomInstance? instanceToUse;
|
||||
string photonRoomId;
|
||||
|
||||
@@ -224,13 +222,11 @@ public class MatchmakingController
|
||||
}
|
||||
};
|
||||
return Results.Json(response);
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPost("/goto/none", (HttpRequest request) =>
|
||||
[HttpPost("/goto/none")]
|
||||
public IResult GotoNone()
|
||||
{
|
||||
// dormroom location id : 76d98498-60a1-430c-ab76-b54a29b7a163
|
||||
// offline dorm
|
||||
|
||||
return Results.Json(new
|
||||
{
|
||||
errorCode = 0,
|
||||
@@ -254,9 +250,10 @@ public class MatchmakingController
|
||||
EncryptVoiceChat = false
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
app.MapPost("/player/heartbeat", async (HttpRequest request, AppDbContext db) =>
|
||||
[HttpPost("/player/heartbeat")]
|
||||
public async Task<IResult> PlayerHeartbeat(HttpRequest request, AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
@@ -290,13 +287,11 @@ public class MatchmakingController
|
||||
if (heartbeat == null)
|
||||
heartbeat = new HeartbeatRequest();
|
||||
|
||||
// Get the player's active room instance (most recent one)
|
||||
var roomInstance = await db.RoomInstances
|
||||
.Where(r => r.OwnerAccountId == id)
|
||||
.OrderByDescending(r => r.Id)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
|
||||
return Results.Json(new
|
||||
{
|
||||
playerId = heartbeat.playerId != 0 ? heartbeat.playerId : id,
|
||||
@@ -327,16 +322,18 @@ public class MatchmakingController
|
||||
appVersion = heartbeat.appVersion ?? "",
|
||||
platform = heartbeat.platform
|
||||
});
|
||||
});
|
||||
app.MapPut("/player/statusvisibility", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpPut("/player/statusvisibility")]
|
||||
public IResult PlayerStatusVisibility()
|
||||
{
|
||||
// TODO ADD FUNCTIONALITY
|
||||
return Results.Ok();
|
||||
});
|
||||
app.MapPost("/roominstance/{id}/reportjoinresult", async (HttpRequest request, AppDbContext db) =>
|
||||
}
|
||||
|
||||
[HttpPost("/roominstance/{id}/reportjoinresult")]
|
||||
public IResult ReportJoinResult(string id)
|
||||
{
|
||||
return Results.Ok();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
using CannedNet.Services.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace CannedNet.Services.Controllers;
|
||||
|
||||
public class NSController
|
||||
[ApiController]
|
||||
[Route("ns")]
|
||||
public class NSController : ControllerBase
|
||||
{
|
||||
public WebApplicationBuilder Initialize(string[]? args = null) => ServiceExtensions.CreateRecNetBuilder(args);
|
||||
|
||||
public void MapEndpoints(WebApplication app)
|
||||
[HttpGet]
|
||||
public IResult Index()
|
||||
{
|
||||
// Rec Room automatically calls this and sets the endpoints that correspond to services in the JSON file. These will be moved to the main server config once I get there.
|
||||
app.MapGet("/", () =>
|
||||
{
|
||||
var json = File.ReadAllText("JSON/endpoints.json");
|
||||
var json = System.IO.File.ReadAllText("JSON/endpoints.json");
|
||||
return Results.Content(json, "application/json");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
using CannedNet.Hubs;
|
||||
using CannedNet.Services.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace CannedNet.Services.Controllers;
|
||||
|
||||
public class NotifyController
|
||||
[ApiController]
|
||||
public class NotifyController : ControllerBase
|
||||
{
|
||||
public WebApplicationBuilder Initialize(string[]? args = null) => ServiceExtensions.CreateRecNetBuilder(args);
|
||||
|
||||
public void MapEndpoints(WebApplication app)
|
||||
[HttpGet("/hub/v1")]
|
||||
public void HubEndpoint()
|
||||
{
|
||||
app.MapHub<NotificationsHub>("/hub/v1");
|
||||
|
||||
var hubContext = app.Services.GetRequiredService<IHubContext<NotificationsHub>>();
|
||||
NotificationService.SetHubContext(hubContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
using CannedNet.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CannedNet.Services.Infrastructure;
|
||||
|
||||
public static class ServiceExtensions
|
||||
{
|
||||
public static void ConfigureRecNetServices(this WebApplicationBuilder builder)
|
||||
{
|
||||
builder.Services.ConfigureHttpJsonOptions(options =>
|
||||
options.SerializerOptions.PropertyNamingPolicy = null);
|
||||
|
||||
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection")
|
||||
?? "Host=localhost;Port=5432;Database=cannednet;Username=postgres;Password=postgres";
|
||||
|
||||
builder.Services.AddDbContext<AppDbContext>(options =>
|
||||
options.UseNpgsql(connectionString));
|
||||
|
||||
builder.Services.AddScoped<JwtTokenService>();
|
||||
builder.Services.AddSingleton<NotificationService>();
|
||||
builder.Services.AddScoped<StorefrontFillService>();
|
||||
builder.Services.AddSignalR();
|
||||
}
|
||||
|
||||
public static void ConfigureHostUrl(this WebApplicationBuilder builder, string defaultUrl)
|
||||
{
|
||||
var url = builder.Configuration["Hosting:Url"];
|
||||
builder.WebHost.UseUrls(string.IsNullOrWhiteSpace(url) ? defaultUrl : url);
|
||||
}
|
||||
|
||||
public static WebApplicationBuilder CreateRecNetBuilder(string[]? args) =>
|
||||
WebApplication.CreateBuilder(args ?? []);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using System.Net.Mime;
|
||||
using CannedNet.Services.Controllers;
|
||||
|
||||
namespace CannedNet.Services.Infrastructure;
|
||||
|
||||
public class ServiceRegistry
|
||||
{
|
||||
public required string Name { get; init; }
|
||||
public required int Port { get; init; }
|
||||
public required Type ServiceType { get; init; }
|
||||
public required Action<WebApplicationBuilder> ConfigureBuilder { get; init; }
|
||||
public required Action<WebApplication, JwtTokenService> MapEndpoints { get; init; }
|
||||
}
|
||||
|
||||
public static class Services
|
||||
{
|
||||
public static readonly List<ServiceRegistry> All =
|
||||
[
|
||||
new() { Name = "NS", Port = 5001, ServiceType = typeof(NSController), ConfigureBuilder = b => b.ConfigureRecNetServices(), MapEndpoints = (app, _) => new NSController().MapEndpoints(app) },
|
||||
new() { Name = "API", Port = 5000, ServiceType = typeof(APIController), ConfigureBuilder = b => b.ConfigureRecNetServices(), MapEndpoints = (app, _) => new APIController().MapEndpoints(app) },
|
||||
new() { Name = "Auth", Port = 5002, ServiceType = typeof(AuthController), ConfigureBuilder = b => b.ConfigureRecNetServices(), MapEndpoints = (app, jwt) => new AuthController().MapEndpoints(app) },
|
||||
new() { Name = "Chat", Port = 5003, ServiceType = typeof(ChatController), ConfigureBuilder = b => b.ConfigureRecNetServices(), MapEndpoints = (app, _) => new ChatController().MapEndpoints(app) },
|
||||
new() { Name = "Match", Port = 5004, ServiceType = typeof(MatchmakingController), ConfigureBuilder = b => b.ConfigureRecNetServices(), MapEndpoints = (app, _) => new MatchmakingController().MapEndpoints(app) },
|
||||
new() { Name = "Accounts", Port = 5005, ServiceType = typeof(AccountsController), ConfigureBuilder = b => b.ConfigureRecNetServices(), MapEndpoints = (app, jwt) => new AccountsController().MapEndpoints(app, jwt) },
|
||||
new() { Name = "Notify", Port = 5006, ServiceType = typeof(NotifyController), ConfigureBuilder = b => b.ConfigureRecNetServices(), MapEndpoints = (app, _) => new NotifyController().MapEndpoints(app) },
|
||||
new() { Name = "CDN", Port = 5007, ServiceType = typeof(CDNController), ConfigureBuilder = b => b.ConfigureRecNetServices(), MapEndpoints = (app, _) => new CDNController().MapEndpoints(app) },
|
||||
new() { Name = "Image", Port = 5008, ServiceType = typeof(ImageController), ConfigureBuilder = b => b.ConfigureRecNetServices(), MapEndpoints = (app, _) => new ImageController().MapEndpoints(app) },
|
||||
new() { Name = "Clubs", Port = 5009, ServiceType = typeof(ClubsController), ConfigureBuilder = b => b.ConfigureRecNetServices(), MapEndpoints = (app, _) => new ClubsController().MapEndpoints(app) },
|
||||
new() { Name = "Commerce", Port = 5010, ServiceType = typeof(CommerceController), ConfigureBuilder = b => b.ConfigureRecNetServices(), MapEndpoints = (app, _) => new CommerceController().MapEndpoints(app) }
|
||||
];
|
||||
}
|
||||
@@ -12,6 +12,8 @@ public class JwtTokenService
|
||||
private readonly SigningCredentials _signingCredentials;
|
||||
private const string KeyId = "7C2F041398671515B0862CB23FAF95B03";
|
||||
|
||||
public static RSA GetRsaInstance() => _rsa;
|
||||
|
||||
public JwtTokenService()
|
||||
{
|
||||
_securityKey = new RsaSecurityKey(_rsa) { KeyId = KeyId };
|
||||
|
||||
Reference in New Issue
Block a user