mirror of
https://github.com/CannedNet/CannedNet.git
synced 2026-10-25 23:18:54 -07:00
fixed rooms + various endpoints
This commit is contained in:
@@ -547,7 +547,6 @@ public class APIService
|
||||
});
|
||||
app.MapPost("/api/CampusCard/v1/UpdateAndGetSubscription", async (HttpRequest request, AppDbContext db) =>
|
||||
{
|
||||
// TODO ADD FUNCTIONALITY
|
||||
return Results.Json(new { subscription = (object?)null, platformAccountSubscribedPlayerId = (object?)null });
|
||||
});
|
||||
app.MapGet("/api/storefronts/v4/balance/2", async (HttpRequest request, AppDbContext db) =>
|
||||
@@ -580,6 +579,58 @@ public class APIService
|
||||
var roomid = request.Query["roomId"];
|
||||
return "[]";
|
||||
});
|
||||
app.MapGet("/api/accounts/v1/getBio", async (HttpRequest request, AppDbContext db) =>
|
||||
{
|
||||
// TODO: store bio's in db
|
||||
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(authHeader) || !authHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||
return Results.Unauthorized();
|
||||
|
||||
var token = authHeader.Substring("Bearer ".Length);
|
||||
var accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId) || !int.TryParse(accountId.AsSpan(), out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
return Results.Json(new { accountId = id, bio = "" });
|
||||
});
|
||||
app.MapPost("/api/accounts/v1/forplatformids", async (HttpRequest request, AppDbContext db) =>
|
||||
{
|
||||
request.EnableBuffering();
|
||||
request.Body.Position = 0;
|
||||
using var reader = new StreamReader(request.Body);
|
||||
var body = await reader.ReadToEndAsync();
|
||||
|
||||
var ids = new List<string>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(body))
|
||||
{
|
||||
foreach (var pair in body.Split('&'))
|
||||
{
|
||||
var keyValue = pair.Split('=');
|
||||
if (keyValue.Length == 2 && keyValue[0] == "Ids")
|
||||
{
|
||||
var idString = Uri.UnescapeDataString(keyValue[1]);
|
||||
ids = idString.Split(',').ToList();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var results = new List<object>();
|
||||
foreach (var platformId in ids)
|
||||
{
|
||||
var cachedLogin = await db.CachedLogins.FirstOrDefaultAsync(c => c.PlatformID == platformId);
|
||||
if (cachedLogin != null)
|
||||
{
|
||||
results.Add(new { accountId = cachedLogin.AccountId, platformId = platformId });
|
||||
}
|
||||
}
|
||||
|
||||
return Results.Json(results);
|
||||
});
|
||||
app.MapGet("/api/storefronts/v3/giftdropstore/3", async (HttpRequest request, AppDbContext db) =>
|
||||
{
|
||||
var json = File.ReadAllText("JSON/storefront3.json");
|
||||
|
||||
@@ -188,5 +188,63 @@ public class AccountsService
|
||||
|
||||
return Results.Content($"{{\"accountId\":{accountId},\"disallowInAppPurchases\":false}}", "application/json");
|
||||
});
|
||||
|
||||
app.MapPut("/account/me/displayname", async (HttpRequest request, AppDbContext db) =>
|
||||
{
|
||||
// TODO: get what the server should actually respond with, OK fails.
|
||||
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(authHeader) || !authHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||
return Results.Unauthorized();
|
||||
|
||||
var token = authHeader.Substring("Bearer ".Length);
|
||||
var accountId = jwtService.ValidateAndGetAccountId(token);
|
||||
|
||||
if (string.IsNullOrEmpty(accountId))
|
||||
return Results.Unauthorized();
|
||||
|
||||
if (!int.TryParse(accountId.AsSpan(), out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
string newDisplayName = "";
|
||||
|
||||
if (request.ContentLength.HasValue && request.ContentLength > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
request.EnableBuffering();
|
||||
using var reader = new StreamReader(request.Body, leaveOpen: true);
|
||||
var body = await reader.ReadToEndAsync();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(body))
|
||||
{
|
||||
foreach (var pair in body.Split('&'))
|
||||
{
|
||||
var keyValue = pair.Split('=');
|
||||
if (keyValue.Length == 2)
|
||||
{
|
||||
var key = Uri.UnescapeDataString(keyValue[0]);
|
||||
var value = Uri.UnescapeDataString(keyValue[1]);
|
||||
|
||||
if (key == "displayName")
|
||||
newDisplayName = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
request.Body.Position = 0;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
var account = await db.Accounts.FindAsync(id);
|
||||
if (account == null)
|
||||
return Results.NotFound();
|
||||
|
||||
account.DisplayName = newDisplayName;
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Results.Ok();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class MatchmakingService
|
||||
{
|
||||
photonRoomId = Guid.NewGuid().ToString();
|
||||
|
||||
var existingInstance = await db.RoomInstances.FirstOrDefaultAsync(r => r.OwnerAccountId == id);
|
||||
var existingInstance = await db.RoomInstances.FirstOrDefaultAsync(r => r.OwnerAccountId == id && r.roomId == roomData.RoomId);
|
||||
|
||||
if (existingInstance != null)
|
||||
{
|
||||
@@ -270,7 +270,7 @@ public class MatchmakingService
|
||||
isInProgress = roomInstance.isInProgress,
|
||||
EncryptVoiceChat = roomInstance.EncryptVoiceChat
|
||||
} : null,
|
||||
isOnline = roomInstance != null && roomInstance.roomId != 1,
|
||||
isOnline = roomInstance != null,
|
||||
appVersion = heartbeat.appVersion ?? "",
|
||||
platform = heartbeat.platform
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user