From 50a7e49c466e6297273bfc4584f4b6bd64139d72 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 24 Jul 2026 15:43:17 +0000 Subject: [PATCH] Upload files to "routes/API" --- routes/API/QuickPlay.cs | 18 ++++ routes/API/Relationships.cs | 17 +++ routes/API/Rooms.cs | 204 ++++++++++++++++++++++++++++++++++++ routes/API/Settings.cs | 37 +++++++ routes/API/VersionCheck.cs | 70 +++++++++++++ 5 files changed, 346 insertions(+) create mode 100644 routes/API/QuickPlay.cs create mode 100644 routes/API/Relationships.cs create mode 100644 routes/API/Rooms.cs create mode 100644 routes/API/Settings.cs create mode 100644 routes/API/VersionCheck.cs diff --git a/routes/API/QuickPlay.cs b/routes/API/QuickPlay.cs new file mode 100644 index 0000000..cff5722 --- /dev/null +++ b/routes/API/QuickPlay.cs @@ -0,0 +1,18 @@ +using Stella.Models; + +namespace Stella.Routes.API +{ + public class QuickPlay + { + [ServerAPI.GET("/api/quickPlay/v1/getandclear")] + [ServerAPI.UseAuthorization] + public dynamic ReturnGetAndClear(MongoDB.User user) + { + return new PlayerQuickPlayDTO + { + RoomName = null, + TargetPlayerId = user.AccountId + }; + } + } +} \ No newline at end of file diff --git a/routes/API/Relationships.cs b/routes/API/Relationships.cs new file mode 100644 index 0000000..c3599f7 --- /dev/null +++ b/routes/API/Relationships.cs @@ -0,0 +1,17 @@ +namespace Stella.Routes.API +{ + public class GetRelationships + { + [ServerAPI.GET("/api/relationships/v2/get")] + public List RelationshipsGet() + { + return []; + } + + [ServerAPI.POST("/api/relationships/v1/bulkignoreplatformusers")] + public List BulkIgnorePlatformUsers() + { + return []; + } + } +} \ No newline at end of file diff --git a/routes/API/Rooms.cs b/routes/API/Rooms.cs new file mode 100644 index 0000000..b07bcd9 --- /dev/null +++ b/routes/API/Rooms.cs @@ -0,0 +1,204 @@ +using System.Linq; +using System.Net; +using System.Text.Json; +using Microsoft.AspNetCore.Mvc; +using MongoDB.Bson; +using MongoDB.Bson.IO; +using MongoDB.Driver; +using Stella.Models; + +namespace Stella.Routes.API +{ + public class Rooms + { + [ServerAPI.GET("/api/rooms/v4/details/{RoomId}")] + public RoomDetailsDTO ReturnGetRoomInfoById(long RoomId) + { + var room = MongoDB.roomsCollection.Find(u => u.Room.RoomId == RoomId).FirstOrDefault(); + + return new RoomDetailsDTO + { + Room = room.Room, + Scenes = room.Scenes, + CoOwners = room.CoOwners, + InvitedCoOwners = room.InvitedCoOwners, + Moderators = room.Moderators, + InvitedModerators = room.InvitedModerators, + Hosts = room.Hosts, + InvitedHosts = room.InvitedHosts, + CheerCount = room.CheerCount, + FavoriteCount = room.FavoriteCount, + VisitCount = room.VisitCount, + Tags = room.Tags + }; + } + + [ServerAPI.GET("/api/rooms/v2/baserooms")] + public async Task> GetBaseRooms(int id) + { + var roomDoc = await MongoDB.roomsCollection + .Find(u => u.Room.RoomId == 29) + .FirstOrDefaultAsync(); + + return new List { roomDoc.Room }; + } + + + + [ServerAPI.GET("/api/rooms/v2/{RoomId}")] + public RoomDTO ReturnGetRoomById(long RoomId) + { + var room = MongoDB.roomsCollection.Find(u => u.Room.RoomId == RoomId).FirstOrDefault(); + + return room.Room; + } + + [ServerAPI.GET("/api/rooms/v2/myrooms")] + [ServerAPI.UseAuthorization] + public async Task> ReturnMyRooms(MongoDB.User user) + { + int userIdInt = (int)user.AccountId; + + var myRooms = await MongoDB.roomsCollection.Find(r => (r.Room.CreatorPlayerId == userIdInt || r.CoOwners.Contains(userIdInt)) && !r.Room.IsDormRoom).ToListAsync(); + + return myRooms.Select(r => r.Room).ToList(); + } + + + + + [ServerAPI.GET("/api/rooms/v2/hot")] + public async Task GetHotRooms(string? roomScoreType, string? tags) + { + var filter = Builders.Filter.Empty; + + var rooms = await MongoDB.roomsCollection.Find(filter).Limit(50).ToListAsync(); + + if (rooms.Count == 0) + { + return new {}; + } + + var filtered = rooms.Where(r => r != null && r.Room.Accessibility == Accessibility.Public).Select(r => r.Room).ToList(); + + if (filtered.Count == 0) + { + return new {}; + } + + return filtered.Select(r => new RoomOrPlaylist + { + RoomOrPlaylistId = r.RoomId, + Name = r.Name, + State = r.State, + SupportsLevelVoting = r.SupportsLevelVoting, + SupportsMobile = r.SupportsMobile, + SupportsScreens = r.SupportsScreens, + SupportsTeleportVR = r.SupportsTeleportVR, + SupportsVRLow = r.SupportsVRLow, + SupportsWalkVR = r.SupportsWalkVR, + Accessibility = r.Accessibility, + AllowsJuniors = r.AllowsJuniors, + CloningAllowed = r.CloningAllowed, + CreatorPlayerId = r.CreatorPlayerId, + CustomRoomWarning = r.CustomRoomWarning, + Description = r.Description, + DisableMicAutoMute = r.DisableMicAutoMute, + ImageName = r.ImageName, + IsAGRoom = r.IsAGRoom, + IsDormRoom = r.IsDormRoom, + RoomWarningMask = r.WarningMask, + Type = RoomOrPlaylistType.Room + }); + } + + [ServerAPI.GET("/api/rooms/v2/name/{RoomName}")] + [ServerAPI.UseAuthorization] + public dynamic ReturnGetRoomInfoByName(string RoomName, MongoDB.User user) + { + RoomName = RoomName.Replace("+", " "); + + MongoDB.RoomDetailsMongoDB room; + if (RoomName.Equals("dormroom", StringComparison.CurrentCultureIgnoreCase)) + { + room = MongoDB.roomsCollection.Find(u => u.Room.RoomId == user.OtherData.DormRoomId).FirstOrDefault(); + room.Room.Name = "DormRoom"; + } + else + { + room = MongoDB.roomsCollection.Find(u => u.Room.Name == RoomName).FirstOrDefault(); + } + + return room.Room; + } + + [ServerAPI.POST("/api/rooms/v1/clone")] + [ServerAPI.UseAuthorization] + public async Task CloneRoom(HttpContext ctx, MongoDB.User user) + { + using var reader = new StreamReader(ctx.Request.Body); + var body = await reader.ReadToEndAsync(); + + var json1 = JsonSerializer.Deserialize>(body); + + var roomName = json1?["Name"].GetString(); + + var original = await MongoDB.roomsCollection.Find(u => u.Room.RoomId == 29).FirstOrDefaultAsync(); + + var bannedJson = await File.ReadAllTextAsync("Data/bannednames.json"); + var bannedObj = JsonSerializer.Deserialize>>(bannedJson); + var bannedWords = bannedObj?["banned"] ?? new List(); + + if (!string.IsNullOrWhiteSpace(roomName) && bannedWords.Any(word => roomName.Contains(word, StringComparison.OrdinalIgnoreCase))) + { + return new + { + Result = 1 + }; + } + + if (original == null) + { + throw new Exception("couldnt find maker room"); + } + + var max = await MongoDB.roomsCollection.Find(_ => true).SortByDescending(r => r.Room.RoomId).FirstOrDefaultAsync(); + + int newId = (int)((max?.Room.RoomId ?? 29) + 1); + + string json = JsonSerializer.Serialize(original); + var newRoomDoc = JsonSerializer.Deserialize(json)!; + + newRoomDoc.Id = ObjectId.GenerateNewId().ToString(); + + newRoomDoc.Room.RoomId = newId; + newRoomDoc.Room.CreatorPlayerId = (int)user.AccountId; + newRoomDoc.Room.Name = roomName; + + foreach (var scene in newRoomDoc.Scenes) + { + scene.RoomId = newId; + scene.DataModifiedAt = DateTime.UtcNow; + } + + newRoomDoc.VisitCount = 0; + newRoomDoc.CheerCount = 0; + newRoomDoc.FavoriteCount = 0; + + await MongoDB.roomsCollection.InsertOneAsync(newRoomDoc); + + return new + { + Result = 0, + RoomDetails = newRoomDoc + }; + } + + [ServerAPI.POST("/api/rooms/v1/roomRolePermissions")] + [ServerAPI.UseAuthorization] + public dynamic ReturnRoomRolePermissions(MongoDB.User user) + { + return Results.Ok(); + } + } +} \ No newline at end of file diff --git a/routes/API/Settings.cs b/routes/API/Settings.cs new file mode 100644 index 0000000..f5dec6d --- /dev/null +++ b/routes/API/Settings.cs @@ -0,0 +1,37 @@ +using MongoDB.Driver; +using Stella.Models; + +namespace Stella.Routes.API +{ + public class Settings + { + [ServerAPI.GET("/api/settings/v2/")] + [ServerAPI.UseAuthorization] + public List ReturnGetSettings(MongoDB.User user) + { + return user.OtherData.Settings; + } + + [ServerAPI.POST("/api/settings/v2/set")] + [ServerAPI.UseAuthorization] + public async Task ReturnSetSettings(HttpContext ctx, MongoDB.User user) + { + SettingDTO? incoming = await ctx.Request.GetJson(); + + var updateResult = await MongoDB.usersCollection.UpdateOneAsync( + u => u.AccountId == user.AccountId && u.OtherData.Settings.Any(s => s.Key == incoming.Key), + Builders.Update.Set("OtherData.Settings.$.Value", incoming.Value) + ); + + if (updateResult.MatchedCount == 0) + { + await MongoDB.usersCollection.UpdateOneAsync( + u => u.AccountId == user.AccountId, + Builders.Update.Push("OtherData.Settings", incoming) + ); + } + + return Results.Ok(); + } + } +} \ No newline at end of file diff --git a/routes/API/VersionCheck.cs b/routes/API/VersionCheck.cs new file mode 100644 index 0000000..082831d --- /dev/null +++ b/routes/API/VersionCheck.cs @@ -0,0 +1,70 @@ +using Stella.Models; + +namespace Stella.Routes.API +{ + public class VersionCheck + { + [ServerAPI.GET("/api/versioncheck/v2")] + public VersionCheckV2ResponseDTO ReturnVersionCheckV2(HttpContext ctx) + { + string? v = ctx.Request.Query["v"]; + + VersionCheckV2ResponseDTO response = new() + { + ValidVersion = false + }; + + if (v != BuildConstants.Version && v != BuildConstants.PCVersion) + { + response = new VersionCheckV2ResponseDTO + { + ValidVersion = false + }; + } + + return response; + } + + [ServerAPI.GET("/api/versioncheck/v3")] + public VersionCheckV3ResponseDTO ReturnVersionCheckV3(HttpContext ctx) + { + string? v = ctx.Request.Query["v"]; + + VersionCheckV3ResponseDTO response = new() + { + ValidVersion = false + }; + + if (v != BuildConstants.Version && v != BuildConstants.PCVersion) + { + response = new VersionCheckV3ResponseDTO + { + ValidVersion = false + }; + } + + return response; + } + + [ServerAPI.GET("/api/versioncheck/v4")] + public VersionCheckV4ResponseDTO ReturnVersionCheckV4(HttpContext ctx) + { + string? v = ctx.Request.Query["v"]; + + VersionCheckV4ResponseDTO response = new() + { + VersionStatus = VersionStatus.ValidForPlay + }; + + if (v != BuildConstants.Version && v != BuildConstants.PCVersion) + { + response = new VersionCheckV4ResponseDTO + { + VersionStatus = VersionStatus.ValidForMenu + }; + } + + return response; + } + } +} \ No newline at end of file