diff --git a/routes/API/Equipment.cs b/routes/API/Equipment.cs new file mode 100644 index 0000000..9a750f8 --- /dev/null +++ b/routes/API/Equipment.cs @@ -0,0 +1,11 @@ +namespace Stella.Routes.API +{ + public class Equipment + { + [ServerAPI.GET("/api/equipment/v2/getUnlocked")] + public List ReturnGetUnlockedEquipment() + { + return []; + } + } +} \ No newline at end of file diff --git a/routes/API/GameConfigs.cs b/routes/API/GameConfigs.cs new file mode 100644 index 0000000..7fdbe1e --- /dev/null +++ b/routes/API/GameConfigs.cs @@ -0,0 +1,27 @@ +using Stella.Models; + +namespace Stella.Routes.API +{ + public class GameConfigs + { + [ServerAPI.GET("/api/gameconfigs/v1/all")] + public List ReturnGameConfigs() + { + return [ + new GameConfig { Key = "VR.ForceVerification", Value = "1" }, + new GameConfig { Key = "Door.Creative.Title", Value = "PUZZLE" }, + new GameConfig { Key = "Door.Creative.Query", Value = "#puzzle" }, + new GameConfig { Key = "Door.Featured.Title", Value = "FEATURED" }, + new GameConfig { Key = "Door.Featured.Query", Value = "#featured" }, + new GameConfig { Key = "Door.Quests.Title", Value = "QUESTS" }, + new GameConfig { Key = "Door.Quests.Query", Value = "#rro #quest" }, + new GameConfig { Key = "Door.Shooters.Title", Value = "PVP" }, + new GameConfig { Key = "Door.Shooters.Query", Value = "#rro #pvp" }, + new GameConfig { Key = "Door.Sports.Title", Value = "Sports and Rec" }, + new GameConfig { Key = "Door.Sports.Query", Value = "#rro #sport" }, + new GameConfig { Key = "splitTestHardOverrides", Value = "" }, + new GameConfig { Key = "splitTestSoftOverrides", Value = "" } + ]; + } + } +} \ No newline at end of file diff --git a/routes/API/Images.cs b/routes/API/Images.cs new file mode 100644 index 0000000..406a803 --- /dev/null +++ b/routes/API/Images.cs @@ -0,0 +1,142 @@ +using MongoDB.Driver; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Formats.Jpeg; +using SixLabors.ImageSharp.Formats.Png; +using SixLabors.ImageSharp.Processing; +using Stella.Models; +using System.Text.Json; + +namespace Stella.Routes.API +{ + public class Images + { + [ServerAPI.GET("/api/images/v2/named")] + public List ReturnGetImagesNamed() + { + return []; + } + + [ServerAPI.POST("/api/images/v4/uploadsaved")] + [ServerAPI.UseAuthorization] + public async Task ReturnUploadSaved(HttpContext ctx, MongoDB.User user) + { + SavedImageMetaDTO? imgMeta = JsonSerializer.Deserialize(ctx.Request.Form["imgMeta"]!); + string fileName = $"{imgMeta?.savedImageType}-{user.DisplayName!.ToPascalCase()}-{DateTime.UtcNow.Year}.{DateTime.UtcNow.Month}.{DateTime.UtcNow.Day}-{DateTime.UtcNow.Hour}.{DateTime.UtcNow.Minute}.{DateTime.UtcNow.Second}.jpg"; + IFormFile image = ctx.Request.Form.Files["image"]!; + + if (image == null || image.Length == 0) + throw new Exception("No image uploaded, buddy."); + if (image.ContentType != "image/jpeg") + throw new Exception("Upload images that are only ingame buddy"); + if (image.FileName != "image.dat") + throw new Exception("Upload images that are only ingame buddy"); + + + if (image != null && image.Length > 0) + { + string savePath = Path.Combine("Data", "Images", fileName); + + using FileStream stream = new(savePath, FileMode.Create); + await image.CopyToAsync(stream); + } + + if (imgMeta.roomId == 0 || imgMeta.roomId == -1) + { + imgMeta.roomId = user.OtherData.DormRoomId; + } + + if (imgMeta?.savedImageType == SavedImageType.ShareCamera) + { + await Logs.SendWebhookAsync( + fileName, + user.Username, + MongoDB.roomsCollection.Find(u => u.Room.RoomId == user.OtherData.DormRoomId).FirstOrDefault().Room.Name + ); + } + + return new ImageNameDTO + { + ImageName = fileName + }; + } + + [ServerAPI.GET("/img/{imageName}")] + public IResult GetImages(HttpContext ctx, string imageName) + { + string imagePath = Path.Combine("Data", "Images", imageName.EndsWith(".jpg") ? imageName : imageName + ".jpg"); + + if (!File.Exists(imagePath)) + return Results.NotFound(); + + byte[] imageBytes = File.ReadAllBytes(imagePath); + + bool Square = false; + + string? cropSquare = ctx.Request.Query["cropSquare"]; + + if (!string.IsNullOrEmpty(cropSquare) && (cropSquare == "1" || cropSquare == "true")) + { + Square = true; + } + + int width = 512; + int height = 0; + + string? H = ctx.Request.Query["height"]; + string? W = ctx.Request.Query["width"]; + if (!string.IsNullOrEmpty(W) && W.All(char.IsDigit)) + { + width = int.Parse(W); + if (width == 256) + { + width = 512; + } + } + if (!string.IsNullOrEmpty(H) && H.All(char.IsDigit)) + { + height = int.Parse(H); + } + + using (Image I = Image.Load(imageBytes)) + { + if (Square) + { + Size NewSize = new() + { + Width = width, + Height = height + }; + int size = Math.Min(I.Width, I.Height); + Rectangle CropRectangle = new() + { + X = (I.Width - size) / 2, + Y = (I.Height - size) / 2, + Width = size, + Height = size + }; + int Resize = Math.Max(width, height); + I.Mutate(x => x.Crop(CropRectangle).Resize(Resize, Resize)); + } + else + { + Size NewSize = new() + { + Width = width, + Height = height + }; + I.Mutate(x => x.Resize(NewSize)); + } + using MemoryStream ms = new(); + I.Save(ms, new JpegEncoder()); + imageBytes = ms.ToArray(); + } + + if (ctx.Request.Query["sig"] == "p1") + { + ctx.Response.Headers["Content-Signature"] = "key-id=KEY:RSA:p1.rec.net; data=" + Signatures.Sign(imageBytes); + } + + return Results.File(imageBytes, "image/jpg"); + } + } +} \ No newline at end of file diff --git a/routes/API/Messages.cs b/routes/API/Messages.cs new file mode 100644 index 0000000..80a198e --- /dev/null +++ b/routes/API/Messages.cs @@ -0,0 +1,11 @@ +namespace Stella.Routes.API +{ + public class GetMessages + { + [ServerAPI.GET("/api/messages/v2/get")] + public List MessagesGet() + { + return []; + } + } +} diff --git a/routes/API/Objectives.cs b/routes/API/Objectives.cs new file mode 100644 index 0000000..917037d --- /dev/null +++ b/routes/API/Objectives.cs @@ -0,0 +1,26 @@ +namespace Stella.Routes.API +{ + public class Objectives + { + [ServerAPI.GET("/api/objectives/v1/myprogress")] + [ServerAPI.UseAuthorization] + public dynamic ReturnGetObjectivesProgress() + { + return new + { + Objectives = new[] + { + new { Index = 2, Group = 0, Progress = 0, VisualProgress = 0, IsCompleted = false, IsRewarded = false, HasClaimedReward = false }, + new { Index = 1, Group = 0, Progress = 0, VisualProgress = 0, IsCompleted = false, IsRewarded = false, HasClaimedReward = false }, + new { Index = 0, Group = 0, Progress = 0, VisualProgress = 0, IsCompleted = false, IsRewarded = false, HasClaimedReward = false }, + new { Index = 6, Group = 2, Progress = 0, VisualProgress = 0, IsCompleted = false, IsRewarded = false, HasClaimedReward = false } + }, + ObjectiveGroups = new[] + { + new { Group = 0, IsCompleted = false, ClearedAt = "2025-11-08T00:00:00Z" }, + new { Group = 2, IsCompleted = false, ClearedAt = "2025-11-08T00:00:00Z" } + } + }; + } + } +} \ No newline at end of file