mirror of
https://github.com/CannedNet/CannedNet.git
synced 2026-10-25 15:09:23 -07:00
fix crashes and logging in
This commit is contained in:
@@ -1,38 +1,38 @@
|
||||
{
|
||||
"Accounts": "https://cannednet.lapis.codes/accounts",
|
||||
"AI": "https://cannednet.lapis.codes/ai",
|
||||
"API": "https://cannednet.lapis.codes/api",
|
||||
"Auth": "https://cannednet.lapis.codes/auth",
|
||||
"BugReporting": "https://cannednet.lapis.codes/bugreporting",
|
||||
"Cards": "https://cannednet.lapis.codes/cards",
|
||||
"CDN": "https://cannednet.lapis.codes/cdn",
|
||||
"Chat": "https://cannednet.lapis.codes/chat",
|
||||
"Clubs": "https://cannednet.lapis.codes/clubs",
|
||||
"CMS": "https://cannednet.lapis.codes/cms",
|
||||
"Commerce": "https://cannednet.lapis.codes/commerce",
|
||||
"Data": "https://cannednet.lapis.codes/data",
|
||||
"DataCollection": "https://cannednet.lapis.codes/datacollection",
|
||||
"Discovery": "https://cannednet.lapis.codes/discovery",
|
||||
"Econ": "https://cannednet.lapis.codes/econ",
|
||||
"GameLogs": "https://cannednet.lapis.codes/gamelogs",
|
||||
"Geo": "https://cannednet.lapis.codes/geo",
|
||||
"Images": "https://cannednet.lapis.codes/img",
|
||||
"Leaderboard": "https://cannednet.lapis.codes/leaderboard",
|
||||
"Link": "https://cannednet.lapis.codes/link",
|
||||
"Lists": "https://cannednet.lapis.codes/lists",
|
||||
"Matchmaking": "https://cannednet.lapis.codes/match",
|
||||
"Moderation": "https://cannednet.lapis.codes/moderation",
|
||||
"Notifications": "https://cannednet.lapis.codes/notify",
|
||||
"PlatformNotifications": "https://cannednet.lapis.codes/platformnotifications",
|
||||
"PlayerSettings": "https://cannednet.lapis.codes/playersettings",
|
||||
"RoomComments": "https://cannednet.lapis.codes/roomcomments",
|
||||
"RoomieIntegrations": "https://cannednet.lapis.codes/roomieintegrations",
|
||||
"Rooms": "https://cannednet.lapis.codes/rooms",
|
||||
"Storage": "https://cannednet.lapis.codes/storage",
|
||||
"Strings": "https://cannednet.lapis.codes/strings",
|
||||
"StringsCDN": "https://cannednet.lapis.codes/stringscdn",
|
||||
"Studio": "https://cannednet.lapis.codes/studio",
|
||||
"Thorn": "https://cannednet.lapis.codes/thorn",
|
||||
"Videos": "https://cannednet.lapis.codes/videos",
|
||||
"Accounts": "https://cannednet.lapis.codes",
|
||||
"AI": "https://cannednet.lapis.codes",
|
||||
"API": "https://cannednet.lapis.codes",
|
||||
"Auth": "https://cannednet.lapis.codes",
|
||||
"BugReporting": "https://cannednet.lapis.codes",
|
||||
"Cards": "https://cannednet.lapis.codes",
|
||||
"CDN": "https://cannednet.lapis.codes",
|
||||
"Chat": "https://cannednet.lapis.codes",
|
||||
"Clubs": "https://cannednet.lapis.codes",
|
||||
"CMS": "https://cannednet.lapis.codes",
|
||||
"Commerce": "https://cannednet.lapis.codes",
|
||||
"Data": "https://cannednet.lapis.codes",
|
||||
"DataCollection": "https://cannednet.lapis.codes",
|
||||
"Discovery": "https://cannednet.lapis.codes",
|
||||
"Econ": "https://cannednet.lapis.codes",
|
||||
"GameLogs": "https://cannednet.lapis.codes",
|
||||
"Geo": "https://cannednet.lapis.codes",
|
||||
"Images": "https://cannednet.lapis.codes",
|
||||
"Leaderboard": "https://cannednet.lapis.codes",
|
||||
"Link": "https://cannednet.lapis.codes",
|
||||
"Lists": "https://cannednet.lapis.codes",
|
||||
"Matchmaking": "https://cannednet.lapis.codes",
|
||||
"Moderation": "https://cannednet.lapis.codes",
|
||||
"Notifications": "https://cannednet.lapis.codes",
|
||||
"PlatformNotifications": "https://cannednet.lapis.codes",
|
||||
"PlayerSettings": "https://cannednet.lapis.codes",
|
||||
"RoomComments": "https://cannednet.lapis.codes",
|
||||
"RoomieIntegrations": "https://cannednet.lapis.codes",
|
||||
"Rooms": "https://cannednet.lapis.codes",
|
||||
"Storage": "https://cannednet.lapis.codes",
|
||||
"Strings": "https://cannednet.lapis.codes",
|
||||
"StringsCDN": "https://cannednet.lapis.codes",
|
||||
"Studio": "https://cannednet.lapis.codes",
|
||||
"Thorn": "https://cannednet.lapis.codes",
|
||||
"Videos": "https://cannednet.lapis.codes",
|
||||
"WWW": "https://cannednet.lapis.codes"
|
||||
}
|
||||
+17
-9
@@ -1,3 +1,4 @@
|
||||
using System.Security.Claims;
|
||||
using CannedNet.Data;
|
||||
using CannedNet.Hubs;
|
||||
using CannedNet.Services;
|
||||
@@ -47,18 +48,25 @@ public static class Program
|
||||
{
|
||||
ValidateIssuerSigningKey = true,
|
||||
IssuerSigningKey = securityKey,
|
||||
ValidateIssuer = true,
|
||||
ValidIssuer = "https://lapis.codes",
|
||||
ValidateAudience = true,
|
||||
ValidAudience = "https://lapis.codes/resources",
|
||||
|
||||
ValidateIssuer = false,
|
||||
ValidIssuer = "https://lapis.codes",
|
||||
|
||||
ValidateAudience = false,
|
||||
ValidAudiences = new[]
|
||||
{
|
||||
"https://lapis.codes",
|
||||
"https://lapis.codes/resources"
|
||||
},
|
||||
|
||||
ValidateLifetime = true,
|
||||
ClockSkew = TimeSpan.Zero,
|
||||
|
||||
// sub is account id
|
||||
NameClaimType = "sub",
|
||||
|
||||
NameClaimType = ClaimTypes.NameIdentifier,
|
||||
RoleClaimType = "role"
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
builder.Services.AddAuthorization();
|
||||
|
||||
@@ -66,10 +74,10 @@ public static class Program
|
||||
|
||||
app.MapHub<NotificationsHub>("/hub/v1");
|
||||
app.UseHttpsRedirection();
|
||||
//app.UseRequestLogging();
|
||||
app.MapControllers();
|
||||
app.UseRequestLogging();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
||||
IHubContext<NotificationsHub> hubContext = app.Services.GetRequiredService<IHubContext<NotificationsHub>>();
|
||||
NotificationService.SetHubContext(hubContext);
|
||||
|
||||
@@ -56,7 +56,7 @@ public class APIController : ControllerBase
|
||||
public async Task<IResult> GetPlayersV1Progression(string id) => Results.Content($"{{\"PlayerId\":{id},\"Level\":1,\"XP\":0}}", "application/json");
|
||||
|
||||
[HttpPost("playerReputation/v2/bulk")]
|
||||
public async Task<IResult> PostPlayerReputationV2Bulk(HttpRequest httpRequest, AppDbContext db) {
|
||||
public async Task<IResult> PostPlayerReputationV2Bulk(AppDbContext db) {
|
||||
/*var ids = await ParseFormIds(httpRequest);
|
||||
|
||||
if (!ids.Any())
|
||||
@@ -83,8 +83,8 @@ public class APIController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPost("players/v2/progression/bulk")]
|
||||
public async Task<IResult> PostProgressionBulkV2(HttpRequest httpRequest, AppDbContext db) {
|
||||
List<int> ids = await ParseFormIds(httpRequest);
|
||||
public async Task<IResult> PostProgressionBulkV2(AppDbContext db) {
|
||||
List<int> ids = await ParseFormIds(HttpContext.Request);
|
||||
|
||||
if (!ids.Any())
|
||||
return Results.Json(new List<PlayerProgressionBulkResponse>());
|
||||
@@ -98,8 +98,8 @@ public class APIController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPost("v1/progression/bulk")]
|
||||
public async Task<IResult> PostProgressionBulkV1(HttpRequest httpRequest, AppDbContext db) {
|
||||
List<int> ids = await ParseFormIds(httpRequest);
|
||||
public async Task<IResult> PostProgressionBulkV1(AppDbContext db) {
|
||||
List<int> ids = await ParseFormIds(HttpContext.Request);
|
||||
|
||||
if (!ids.Any())
|
||||
return Results.Json(new List<PlayerProgressionBulkResponse>());
|
||||
@@ -116,11 +116,11 @@ public class APIController : ControllerBase
|
||||
|
||||
[HttpPost("avatar/v2/set")]
|
||||
[Authorize]
|
||||
public async Task<IResult> SetAvatarV2(HttpRequest request, AppDbContext db, JwtTokenService jwtService)
|
||||
public async Task<IResult> SetAvatarV2(AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
int id = User.Identity.Name != null && int.TryParse(User.Identity.Name, out var parsedId) ? parsedId : -1;
|
||||
request.EnableBuffering();
|
||||
var avatarUpdate = await System.Text.Json.JsonSerializer.DeserializeAsync<PlayerAvatar>(request.Body);
|
||||
HttpContext.Request.EnableBuffering();
|
||||
var avatarUpdate = await System.Text.Json.JsonSerializer.DeserializeAsync<PlayerAvatar>(HttpContext.Request.Body);
|
||||
|
||||
if (avatarUpdate == null)
|
||||
return Results.BadRequest();
|
||||
@@ -158,7 +158,7 @@ public class APIController : ControllerBase
|
||||
|
||||
[HttpGet("settings/v2")]
|
||||
[Authorize]
|
||||
public async Task<IResult> GetSettings(HttpRequest request, AppDbContext db, JwtTokenService jwtService)
|
||||
public async Task<IResult> GetSettings(AppDbContext db, JwtTokenService jwtService)
|
||||
{
|
||||
int id = User.Identity.Name != null && int.TryParse(User.Identity.Name, out var parsedId) ? parsedId : -1;
|
||||
|
||||
@@ -212,7 +212,7 @@ public class APIController : ControllerBase
|
||||
|
||||
[HttpGet("accounts/v1/getBio")]
|
||||
[Authorize]
|
||||
public async Task<IResult> GetAccountBio(HttpRequest request, AppDbContext db)
|
||||
public async Task<IResult> GetAccountBio(AppDbContext db)
|
||||
{
|
||||
int accountId = User.Identity.Name != null && int.TryParse(User.Identity.Name, out var parsedId) ? parsedId : -1;
|
||||
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
using CannedNet.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
||||
namespace CannedNet.Services.Controllers;
|
||||
|
||||
//TODO: remove duplicate code(most of it is checking if the user is authenticated, ASP.NET has stuff for this)
|
||||
[ApiController, Route("account")]
|
||||
public class AccountsController : ControllerBase
|
||||
{
|
||||
[HttpGet("me")]
|
||||
public async Task<IResult> Me(HttpRequest request, AppDbContext db, JwtTokenService jwtService) {
|
||||
string authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(authHeader) || !authHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||
return Results.Unauthorized();
|
||||
|
||||
string token = authHeader.Substring("Bearer ".Length);
|
||||
string? accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId) || !int.TryParse(accountId.AsSpan(), out int id))
|
||||
[Authorize]
|
||||
public async Task<IResult> Me(AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(User.Identity?.Name, out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
Account? account = await db.Accounts.FindAsync(id);
|
||||
@@ -48,21 +42,23 @@ public class AccountsController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("bulk")]
|
||||
public async Task<IResult> Bulk(HttpRequest request, AppDbContext db) {
|
||||
StringValues ids = request.Query["id"];
|
||||
public async Task<IResult> Bulk(AppDbContext db)
|
||||
{
|
||||
StringValues ids = HttpContext.Request.Query["id"];
|
||||
List<int> accountIds = [];
|
||||
|
||||
foreach (string? id in ids) {
|
||||
if (int.TryParse(id, out int accountId)) {
|
||||
foreach (string? id in ids)
|
||||
{
|
||||
if (int.TryParse(id, out int accountId))
|
||||
accountIds.Add(accountId);
|
||||
}
|
||||
}
|
||||
|
||||
List<Account> accounts = await db.Accounts
|
||||
.Where(a => accountIds.Contains(a.AccountId.Value))
|
||||
.ToListAsync();
|
||||
|
||||
List<Account> result = accounts.Select(a => new Account {
|
||||
List<Account> result = accounts.Select(a => new Account
|
||||
{
|
||||
AccountId = a.AccountId,
|
||||
ProfileImage = a.ProfileImage ?? "DefaultProfileImage.jpg",
|
||||
IsJunior = a.IsJunior,
|
||||
@@ -78,7 +74,8 @@ public class AccountsController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<IResult> Id(HttpRequest request, string id, AppDbContext db) {
|
||||
public async Task<IResult> Id(string id, AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(id, out int accountId))
|
||||
return Results.BadRequest();
|
||||
|
||||
@@ -86,7 +83,8 @@ public class AccountsController : ControllerBase
|
||||
if (account == null)
|
||||
return Results.NotFound();
|
||||
|
||||
Account result = new() {
|
||||
Account result = new()
|
||||
{
|
||||
AccountId = account.AccountId,
|
||||
ProfileImage = account.ProfileImage ?? "DefaultProfileImage.jpg",
|
||||
IsJunior = account.IsJunior,
|
||||
@@ -102,26 +100,33 @@ public class AccountsController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPost("create")]
|
||||
public async Task<IResult> Create(HttpRequest httpRequest, AppDbContext db) {
|
||||
public async Task<IResult> Create(AppDbContext db)
|
||||
{
|
||||
var request = HttpContext.Request;
|
||||
int platform = 0;
|
||||
string platformId = "";
|
||||
|
||||
if (httpRequest.ContentLength is > 0) {
|
||||
try {
|
||||
string contentType = httpRequest.ContentType ?? "";
|
||||
httpRequest.EnableBuffering();
|
||||
if (request.ContentLength is > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
string contentType = request.ContentType ?? "";
|
||||
request.EnableBuffering();
|
||||
|
||||
using StreamReader reader = new(httpRequest.Body, leaveOpen: true);
|
||||
using StreamReader reader = new(request.Body, leaveOpen: true);
|
||||
string body = await reader.ReadToEndAsync();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(body) && contentType.Contains("application/x-www-form-urlencoded")) {
|
||||
foreach (string pair in body.Split('&')) {
|
||||
if (!string.IsNullOrWhiteSpace(body) && contentType.Contains("application/x-www-form-urlencoded"))
|
||||
{
|
||||
foreach (string pair in body.Split('&'))
|
||||
{
|
||||
string[] keyValue = pair.Split('=');
|
||||
if (keyValue.Length != 2) continue;
|
||||
string key = Uri.UnescapeDataString(keyValue[0]);
|
||||
string value = Uri.UnescapeDataString(keyValue[1]);
|
||||
|
||||
switch (key) {
|
||||
switch (key)
|
||||
{
|
||||
case "platform" when int.TryParse(value, out var parsedPlatform):
|
||||
platform = parsedPlatform;
|
||||
break;
|
||||
@@ -132,13 +137,14 @@ public class AccountsController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
httpRequest.Body.Position = 0;
|
||||
request.Body.Position = 0;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
int accountId = new Random().Next(10000, 99999);
|
||||
Account account = new() {
|
||||
Account account = new()
|
||||
{
|
||||
AccountId = accountId,
|
||||
ProfileImage = "DefaultProfileImage.jpg",
|
||||
IsJunior = false,
|
||||
@@ -152,8 +158,10 @@ public class AccountsController : ControllerBase
|
||||
|
||||
db.Accounts.Add(account);
|
||||
|
||||
if (!string.IsNullOrEmpty(platformId)) {
|
||||
db.CachedLogins.Add(new CachedLogin {
|
||||
if (!string.IsNullOrEmpty(platformId))
|
||||
{
|
||||
db.CachedLogins.Add(new CachedLogin
|
||||
{
|
||||
AccountId = accountId,
|
||||
Platform = (PlatformType)platform,
|
||||
PlatformID = platformId,
|
||||
@@ -164,12 +172,11 @@ public class AccountsController : ControllerBase
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
// create players dorm room
|
||||
int maxRoomId = await db.Rooms.MaxAsync(r => (int?)r.RoomId) ?? 0;
|
||||
int maxId = await db.Rooms.MaxAsync(r => (int?)r.Id) ?? 0;
|
||||
int dormRoomId = maxRoomId + 1;
|
||||
//int dormId = maxId + 1;
|
||||
Room dormRoom = new Room {
|
||||
Room dormRoom = new Room
|
||||
{
|
||||
Id = maxId + 1,
|
||||
RoomId = dormRoomId,
|
||||
Name = "DormRoom",
|
||||
@@ -200,8 +207,8 @@ public class AccountsController : ControllerBase
|
||||
};
|
||||
db.Rooms.Add(dormRoom);
|
||||
|
||||
// Create a sub room for the dorm
|
||||
SubRoom dormSubRoom = new SubRoom {
|
||||
SubRoom dormSubRoom = new SubRoom
|
||||
{
|
||||
RoomId = dormRoomId,
|
||||
SubRoomId = 1,
|
||||
Name = "DormRoom",
|
||||
@@ -209,7 +216,7 @@ public class AccountsController : ControllerBase
|
||||
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);
|
||||
@@ -219,28 +226,27 @@ public class AccountsController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("me/displayname")]
|
||||
public async Task<IResult> PutMeDisplayName(HttpRequest request, AppDbContext db, JwtTokenService jwtService) {
|
||||
string authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(authHeader) || !authHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||
return Results.Unauthorized();
|
||||
|
||||
string token = authHeader.Substring("Bearer ".Length);
|
||||
string? accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId) || !int.TryParse(accountId.AsSpan(), out var id))
|
||||
[Authorize]
|
||||
public async Task<IResult> PutMeDisplayName(AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(User.Identity?.Name, out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
var request = HttpContext.Request;
|
||||
string newDisplayName = "";
|
||||
|
||||
if (request.ContentLength is > 0) {
|
||||
try {
|
||||
if (request.ContentLength is > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
request.EnableBuffering();
|
||||
using StreamReader reader = new(request.Body, leaveOpen: true);
|
||||
string body = await reader.ReadToEndAsync();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(body)) {
|
||||
foreach (string pair in body.Split('&')) {
|
||||
if (!string.IsNullOrWhiteSpace(body))
|
||||
{
|
||||
foreach (string pair in body.Split('&'))
|
||||
{
|
||||
string[] keyValue = pair.Split('=');
|
||||
if (keyValue.Length != 2) continue;
|
||||
string key = Uri.UnescapeDataString(keyValue[0]);
|
||||
@@ -267,29 +273,27 @@ public class AccountsController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("me/username")]
|
||||
public async Task<IResult> PutMeUsername(HttpRequest request, AppDbContext db, JwtTokenService jwtService) {
|
||||
string authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(authHeader) ||
|
||||
!authHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||
return Results.Unauthorized();
|
||||
|
||||
string token = authHeader.Substring("Bearer ".Length);
|
||||
string? accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId) || !int.TryParse(accountId.AsSpan(), out int id))
|
||||
[Authorize]
|
||||
public async Task<IResult> PutMeUsername(AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(User.Identity?.Name, out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
var request = HttpContext.Request;
|
||||
string newAccountName = "";
|
||||
|
||||
if (request.ContentLength is > 0) {
|
||||
try {
|
||||
if (request.ContentLength is > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
request.EnableBuffering();
|
||||
using StreamReader reader = new(request.Body, leaveOpen: true);
|
||||
string body = await reader.ReadToEndAsync();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(body)) {
|
||||
foreach (string pair in body.Split('&')) {
|
||||
if (!string.IsNullOrWhiteSpace(body))
|
||||
{
|
||||
foreach (string pair in body.Split('&'))
|
||||
{
|
||||
string[] keyValue = pair.Split('=');
|
||||
if (keyValue.Length != 2) continue;
|
||||
string key = Uri.UnescapeDataString(keyValue[0]);
|
||||
@@ -316,7 +320,8 @@ public class AccountsController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("{id}/bio")]
|
||||
public async Task<IResult> GetBio(string id, AppDbContext db) {
|
||||
public async Task<IResult> GetBio(string id, AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(id, out int accountId))
|
||||
return Results.BadRequest();
|
||||
|
||||
@@ -328,29 +333,27 @@ public class AccountsController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("me/bio")]
|
||||
public async Task<IResult> PutMeBio(HttpRequest request, AppDbContext db, JwtTokenService jwtService) {
|
||||
string authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(authHeader) ||
|
||||
!authHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||
return Results.Unauthorized();
|
||||
|
||||
string token = authHeader.Substring("Bearer ".Length);
|
||||
string? accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId) || !int.TryParse(accountId.AsSpan(), out int id))
|
||||
[Authorize]
|
||||
public async Task<IResult> PutMeBio(AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(User.Identity?.Name, out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
var request = HttpContext.Request;
|
||||
string newBio = "";
|
||||
|
||||
if (request.ContentLength is > 0) {
|
||||
try {
|
||||
if (request.ContentLength is > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
request.EnableBuffering();
|
||||
using StreamReader reader = new StreamReader(request.Body, leaveOpen: true);
|
||||
string body = await reader.ReadToEndAsync();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(body)) {
|
||||
foreach (string pair in body.Split('&')) {
|
||||
if (!string.IsNullOrWhiteSpace(body))
|
||||
{
|
||||
foreach (string pair in body.Split('&'))
|
||||
{
|
||||
string[] keyValue = pair.Split('=');
|
||||
if (keyValue.Length != 2) continue;
|
||||
string key = Uri.UnescapeDataString(keyValue[0]);
|
||||
@@ -368,14 +371,17 @@ public class AccountsController : ControllerBase
|
||||
|
||||
PlayerBio? bio = await db.PlayerBios.FirstOrDefaultAsync(b => b.accountId == id);
|
||||
|
||||
if (bio == null) {
|
||||
bio = new PlayerBio {
|
||||
if (bio == null)
|
||||
{
|
||||
bio = new PlayerBio
|
||||
{
|
||||
accountId = id,
|
||||
bio = newBio
|
||||
};
|
||||
db.PlayerBios.Add(bio);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
bio.bio = newBio;
|
||||
db.PlayerBios.Update(bio);
|
||||
}
|
||||
@@ -386,29 +392,27 @@ public class AccountsController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("me/profileimage")]
|
||||
public async Task<IResult> PutMeProfileImage(HttpRequest request, AppDbContext db, JwtTokenService jwtService) {
|
||||
string authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(authHeader) ||
|
||||
!authHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||
return Results.Unauthorized();
|
||||
|
||||
string token = authHeader.Substring("Bearer ".Length);
|
||||
string? accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId) || !int.TryParse(accountId.AsSpan(), out int id))
|
||||
[Authorize]
|
||||
public async Task<IResult> PutMeProfileImage(AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(User.Identity?.Name, out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
var request = HttpContext.Request;
|
||||
string newProfileImage = "";
|
||||
|
||||
if (request.ContentLength is > 0) {
|
||||
try {
|
||||
if (request.ContentLength is > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
request.EnableBuffering();
|
||||
using StreamReader reader = new(request.Body, leaveOpen: true);
|
||||
string body = await reader.ReadToEndAsync();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(body)) {
|
||||
foreach (var pair in body.Split('&')) {
|
||||
if (!string.IsNullOrWhiteSpace(body))
|
||||
{
|
||||
foreach (var pair in body.Split('&'))
|
||||
{
|
||||
string[] keyValue = pair.Split('=');
|
||||
if (keyValue.Length != 2) continue;
|
||||
string key = Uri.UnescapeDataString(keyValue[0]);
|
||||
@@ -435,19 +439,12 @@ public class AccountsController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("parentalcontrol/me")]
|
||||
public async Task<IResult> ParentalControl(HttpRequest request, JwtTokenService jwtService) {
|
||||
string authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(authHeader) ||
|
||||
!authHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||
[Authorize]
|
||||
public async Task<IResult> ParentalControl()
|
||||
{
|
||||
if (!int.TryParse(User.Identity?.Name, out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
string token = authHeader.Substring("Bearer ".Length);
|
||||
string? accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId) || !int.TryParse(accountId.AsSpan(), out _))
|
||||
return Results.Unauthorized();
|
||||
|
||||
return Results.Content($"{{\"accountId\":{accountId},\"disallowInAppPurchases\":false}}", "application/json");
|
||||
return Results.Content($"{{\"accountId\":{id},\"disallowInAppPurchases\":false}}", "application/json");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,17 +24,17 @@ public class AuthController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPost("connect/token")]
|
||||
public async Task<IResult> ConnectToken(HttpRequest httpRequest, AppDbContext db, JwtTokenService jwtService) {
|
||||
public async Task<IResult> ConnectToken(AppDbContext db, JwtTokenService jwtService) {
|
||||
string accountId = "";
|
||||
string platformId = "";
|
||||
string platform = "";
|
||||
|
||||
if (httpRequest.ContentLength is > 0)
|
||||
if (HttpContext.Request.ContentLength is > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
httpRequest.EnableBuffering();
|
||||
using StreamReader reader = new (httpRequest.Body, leaveOpen: true);
|
||||
HttpContext.Request.EnableBuffering();
|
||||
using StreamReader reader = new (HttpContext.Request.Body, leaveOpen: true);
|
||||
string body = await reader.ReadToEndAsync();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(body))
|
||||
@@ -56,7 +56,7 @@ public class AuthController : ControllerBase
|
||||
}
|
||||
}
|
||||
}
|
||||
httpRequest.Body.Position = 0;
|
||||
HttpContext.Request.Body.Position = 0;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
@@ -85,11 +85,11 @@ public class AuthController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPost("api/accounts/v1/forplatformids")]
|
||||
public async Task<IResult> AccountsForPlatformIds(HttpRequest request, AppDbContext db) {
|
||||
public async Task<IResult> AccountsForPlatformIds(AppDbContext db) {
|
||||
|
||||
request.EnableBuffering();
|
||||
request.Body.Position = 0;
|
||||
using var reader = new StreamReader(request.Body);
|
||||
HttpContext.Request.EnableBuffering();
|
||||
HttpContext.Request.Body.Position = 0;
|
||||
using var reader = new StreamReader(HttpContext.Request.Body);
|
||||
string body = await reader.ReadToEndAsync();
|
||||
|
||||
List<string> ids = [];
|
||||
|
||||
@@ -238,14 +238,14 @@ public class EconController : ControllerBase
|
||||
|
||||
[HttpPost("api/settings/v2/set")]
|
||||
[Authorize]
|
||||
public async Task<IResult> SetSettings(HttpRequest request, AppDbContext db)
|
||||
public async Task<IResult> SetSettings(AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(User.Identity?.Name, out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
request.EnableBuffering();
|
||||
request.Body.Position = 0;
|
||||
using var reader = new StreamReader(request.Body);
|
||||
HttpContext.Request.EnableBuffering();
|
||||
HttpContext.Request.Body.Position = 0;
|
||||
using var reader = new StreamReader(HttpContext.Request.Body);
|
||||
var body = await reader.ReadToEndAsync();
|
||||
|
||||
Console.WriteLine($"Settings request body: {body}");
|
||||
@@ -383,13 +383,11 @@ public class EconController : ControllerBase
|
||||
|
||||
[HttpGet("api/avatar/v3/saved")]
|
||||
[Authorize]
|
||||
public async Task<IResult> GetSavedAvatars(HttpRequest request, AppDbContext db)
|
||||
public async Task<IResult> GetSavedAvatars(AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(User.Identity?.Name, out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
request.EnableBuffering();
|
||||
|
||||
var items = await db.SavedOutfits
|
||||
.Where(i => i.OwnerAccountId == id)
|
||||
.ToListAsync();
|
||||
|
||||
@@ -23,9 +23,9 @@ public class MatchmakingController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("player")]
|
||||
public async Task<IResult> GetPlayer(HttpRequest request, AppDbContext db)
|
||||
public async Task<IResult> GetPlayer(AppDbContext db)
|
||||
{
|
||||
var id = request.Query["id"].FirstOrDefault();
|
||||
var id = HttpContext.Request.Query["id"].FirstOrDefault();
|
||||
if (string.IsNullOrEmpty(id) || !int.TryParse(id, out var accountId))
|
||||
{
|
||||
var json = System.IO.File.ReadAllText("JSON/getplayer.json");
|
||||
@@ -83,20 +83,20 @@ public class MatchmakingController : ControllerBase
|
||||
|
||||
[HttpPost("goto/room/{room}")]
|
||||
[Authorize]
|
||||
public async Task<IResult> GotoRoom(HttpRequest request, string room, AppDbContext db)
|
||||
public async Task<IResult> GotoRoom(string room, AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(User.Identity?.Name, out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
request.EnableBuffering();
|
||||
request.Body.Position = 0;
|
||||
var form = await request.ReadFormAsync();
|
||||
HttpContext.Request.EnableBuffering();
|
||||
HttpContext.Request.Body.Position = 0;
|
||||
var form = await HttpContext.Request.ReadFormAsync();
|
||||
int joinMode = 0;
|
||||
if (int.TryParse(form["JoinMode"].ToString(), out var mode))
|
||||
{
|
||||
joinMode = mode;
|
||||
}
|
||||
request.Body.Position = 0;
|
||||
HttpContext.Request.Body.Position = 0;
|
||||
|
||||
Room? roomData = null;
|
||||
var roomLower = room.ToLower();
|
||||
@@ -223,20 +223,20 @@ public class MatchmakingController : ControllerBase
|
||||
|
||||
[HttpPost("matchmake/{room}")]
|
||||
[Authorize]
|
||||
public async Task<IResult> MatchmakeRoom(HttpRequest request, string room, AppDbContext db)
|
||||
public async Task<IResult> MatchmakeRoom(string room, AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(User.Identity?.Name, out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
request.EnableBuffering();
|
||||
request.Body.Position = 0;
|
||||
var form = await request.ReadFormAsync();
|
||||
HttpContext.Request.EnableBuffering();
|
||||
HttpContext.Request.Body.Position = 0;
|
||||
var form = await HttpContext.Request.ReadFormAsync();
|
||||
int joinMode = 0;
|
||||
if (int.TryParse(form["JoinMode"].ToString(), out var mode))
|
||||
{
|
||||
joinMode = mode;
|
||||
}
|
||||
request.Body.Position = 0;
|
||||
HttpContext.Request.Body.Position = 0;
|
||||
|
||||
Room? roomData = null;
|
||||
var roomLower = room.ToLower();
|
||||
@@ -391,18 +391,18 @@ public class MatchmakingController : ControllerBase
|
||||
|
||||
[HttpPost("player/heartbeat")]
|
||||
[Authorize]
|
||||
public async Task<IResult> PlayerHeartbeat(HttpRequest request, AppDbContext db)
|
||||
public async Task<IResult> PlayerHeartbeat(AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(User.Identity?.Name, out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
request.EnableBuffering();
|
||||
request.Body.Position = 0;
|
||||
using var reader = new StreamReader(request.Body);
|
||||
HttpContext.Request.EnableBuffering();
|
||||
HttpContext.Request.Body.Position = 0;
|
||||
using var reader = new StreamReader(HttpContext.Request.Body);
|
||||
var body = await reader.ReadToEndAsync();
|
||||
|
||||
request.Body.Position = 0;
|
||||
var form = await request.ReadFormAsync();
|
||||
HttpContext.Request.Body.Position = 0;
|
||||
var form = await HttpContext.Request.ReadFormAsync();
|
||||
var loginLock = form["LoginLock"].ToString();
|
||||
|
||||
HeartbeatRequest? heartbeat = null;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace CannedNet.Services.Controllers;
|
||||
[ApiController, Route("playersettings")]
|
||||
public class PlayerSettingsController : ControllerBase
|
||||
{
|
||||
[HttpGet("playersettings")]
|
||||
[HttpGet("/playersettings")]
|
||||
[Authorize]
|
||||
public async Task<IResult> GetPlayerSettings(AppDbContext db)
|
||||
{
|
||||
@@ -63,18 +63,18 @@ public class PlayerSettingsController : ControllerBase
|
||||
return Results.Json(settings);
|
||||
}
|
||||
|
||||
[HttpPut("playersettings")]
|
||||
[HttpPut("/playersettings")]
|
||||
[Authorize]
|
||||
public async Task<IResult> PutPlayerSettings(HttpRequest request, AppDbContext db)
|
||||
public async Task<IResult> PutPlayerSettings(AppDbContext db)
|
||||
{
|
||||
if (!int.TryParse(User.Identity?.Name, out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
var settings = new List<PlayerSetting>();
|
||||
|
||||
if (request.ContentType?.Contains("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase) == true)
|
||||
if (HttpContext.Request.ContentType?.Contains("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase) == true)
|
||||
{
|
||||
var form = await request.ReadFormAsync();
|
||||
var form = await HttpContext.Request.ReadFormAsync();
|
||||
var key = form["key"].FirstOrDefault();
|
||||
var value = form["value"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(key))
|
||||
@@ -82,11 +82,11 @@ public class PlayerSettingsController : ControllerBase
|
||||
}
|
||||
else
|
||||
{
|
||||
request.EnableBuffering();
|
||||
request.Body.Position = 0;
|
||||
using var reader = new StreamReader(request.Body, leaveOpen: true);
|
||||
HttpContext.Request.EnableBuffering();
|
||||
HttpContext.Request.Body.Position = 0;
|
||||
using var reader = new StreamReader(HttpContext.Request.Body, leaveOpen: true);
|
||||
var body = await reader.ReadToEndAsync();
|
||||
request.Body.Position = 0;
|
||||
HttpContext.Request.Body.Position = 0;
|
||||
|
||||
Console.WriteLine($"Settings request body: {body}");
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ namespace CannedNet.Services.Controllers;
|
||||
public class RoomsController : ControllerBase
|
||||
{
|
||||
[HttpGet("rooms")]
|
||||
public async Task<IResult> GetRooms(HttpRequest request, AppDbContext db)
|
||||
public async Task<IResult> GetRooms(AppDbContext db)
|
||||
{
|
||||
var idParam = request.Query["id"].FirstOrDefault();
|
||||
var nameParam = request.Query["name"].FirstOrDefault();
|
||||
var idParam = HttpContext.Request.Query["id"].FirstOrDefault();
|
||||
var nameParam = HttpContext.Request.Query["name"].FirstOrDefault();
|
||||
|
||||
if (string.IsNullOrEmpty(idParam) && string.IsNullOrEmpty(nameParam))
|
||||
return Results.BadRequest("Either 'id' or 'name' query parameter is required");
|
||||
|
||||
@@ -33,11 +33,11 @@ public class JwtTokenService
|
||||
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
new Claim("iss", "https://api.lapis.codes"),
|
||||
new Claim("iss", "https://lapis.codes"),
|
||||
new Claim("nbf", ((DateTimeOffset)now).ToUnixTimeSeconds().ToString()),
|
||||
new Claim("iat", ((DateTimeOffset)now).ToUnixTimeSeconds().ToString()),
|
||||
new Claim("exp", ((DateTimeOffset)exp).ToUnixTimeSeconds().ToString()),
|
||||
new Claim("aud", "https://api.lapis.codes/resources"),
|
||||
new Claim("aud", "https://lapis.codes/resources"),
|
||||
new Claim("amr", "cached_login"),
|
||||
new Claim("client_id", "recroom"),
|
||||
new Claim("sub", accountId),
|
||||
|
||||
Reference in New Issue
Block a user