mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 23:49:02 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,206 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RadicadeServer.DB;
|
||||
using RadicadeServer.RecNet;
|
||||
using RadicadeServer.RecNet.DB;
|
||||
using RadicadeServer.RecNet.Rooms;
|
||||
using RadicadeServer.Utils;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||
|
||||
namespace RadicadeServer.RoomServer
|
||||
{
|
||||
[Route("rooms")]
|
||||
public class RoomPlaylistAPI(RecDBContext db) : Controller
|
||||
{
|
||||
private async Task<PlaylistRoom?> GetBestOfPlaylist()
|
||||
{
|
||||
var topRooms = await db.Rooms
|
||||
.Select(r => new
|
||||
{
|
||||
r.RoomId,
|
||||
r.CreatorAccountId,
|
||||
Engagement = db.RoomInteractions
|
||||
.Where(i => i.RoomId == r.RoomId)
|
||||
.Sum(i => (i.Favorited ? 1 : 0) + (i.Cheered ? 1 : 0))
|
||||
})
|
||||
.OrderByDescending(x => x.Engagement)
|
||||
.ToListAsync();
|
||||
|
||||
var convertedRooms = new List<FullRoom>();
|
||||
var tags = new List<ItemTag>();
|
||||
foreach (var foundRoom in topRooms)
|
||||
{
|
||||
var room = await RoomUtils.GetRoom(foundRoom.RoomId);
|
||||
|
||||
if (room == null || room.Accessibility != RecNet.Enums.Accessibility.Public || room.IsDorm) continue;
|
||||
|
||||
convertedRooms.Add(room);
|
||||
foreach (var tag in room.Tags)
|
||||
tags.Add(tag);
|
||||
}
|
||||
|
||||
if (convertedRooms.Count <= 0)
|
||||
return null;
|
||||
|
||||
var mainRoom = new PlaylistRoom(convertedRooms[0]);
|
||||
|
||||
return mainRoom;
|
||||
}
|
||||
|
||||
[HttpGet("playlists/{playlistId}")]
|
||||
public async Task<object?> GetPlaylistRooms(long playlistId)
|
||||
{
|
||||
List<FullRoom> convertedRooms;
|
||||
var tags = new List<ItemTag>();
|
||||
|
||||
if (playlistId == 24226488)
|
||||
{
|
||||
var mainRoom = await GetBestOfPlaylist();
|
||||
if (mainRoom == null) return null;
|
||||
convertedRooms = mainRoom.Rooms;
|
||||
tags = mainRoom.Tags;
|
||||
}
|
||||
else
|
||||
{
|
||||
var playlist = await db.Playlists.FirstOrDefaultAsync(x => x.PlaylistId == playlistId);
|
||||
if (playlist == null) return null;
|
||||
|
||||
var keywords = playlist.GetKeywords();
|
||||
var foundRooms = await db.Rooms
|
||||
.Where(room => room.Accessibility == RecNet.Enums.Accessibility.Public
|
||||
&& keywords.Any(k => room.Name.Contains(k) || room.Tags.Contains(k)))
|
||||
.ToListAsync();
|
||||
|
||||
convertedRooms = new List<FullRoom>();
|
||||
foreach (var foundRoom in foundRooms)
|
||||
{
|
||||
var room = await RoomUtils.GetRoom(foundRoom.RoomId);
|
||||
if (room != null)
|
||||
{
|
||||
convertedRooms.Add(room);
|
||||
foreach (var tag in room.Tags)
|
||||
tags.Add(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var roomDtos = convertedRooms.Select(room => ToPlaylistRoomDict(room, playlistId)).ToArray();
|
||||
|
||||
var tagDtos = tags
|
||||
.Select(t => new Dictionary<string, object?> { ["Tag"] = t.Tag, ["Type"] = (int)t.Type })
|
||||
.ToArray();
|
||||
|
||||
var root = ToPlaylistRoomDict(convertedRooms.FirstOrDefault(), playlistId);
|
||||
|
||||
root["Rooms"] = roomDtos;
|
||||
root["Tags"] = tagDtos;
|
||||
root["community"] = Array.Empty<object>();
|
||||
root["junior"] = Array.Empty<object>();
|
||||
root["pickup"] = Array.Empty<object>();
|
||||
root["screen"] = Array.Empty<object>();
|
||||
root["teleportvr"] = Array.Empty<object>();
|
||||
root["walkvr"] = Array.Empty<object>();
|
||||
root["PinnedFilters"] = Array.Empty<object>();
|
||||
root["PopularFilters"] = Array.Empty<object>();
|
||||
root["TrendingFilters"] = Array.Empty<object>();
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private static Dictionary<string, object?> ToPlaylistRoomDict(FullRoom? room, long playlistId)
|
||||
{
|
||||
var dict = new Dictionary<string, object?>
|
||||
{
|
||||
["AnnouncementId"] = 0L,
|
||||
["AnnouncementType"] = 0,
|
||||
["Body"] = "",
|
||||
["LinkName"] = "",
|
||||
["LinkType"] = 0,
|
||||
["LinkUri"] = "",
|
||||
["Platform"] = 0,
|
||||
["Title"] = "",
|
||||
["PlaylistId"] = playlistId,
|
||||
["RoomId"] = 0L,
|
||||
["IsDorm"] = false,
|
||||
["MaxPlayers"] = 0,
|
||||
["MaxPlayerCalculationMode"] = 0,
|
||||
["CloningAllowed"] = false,
|
||||
["DisableMicAutoMute"] = false,
|
||||
["DisableRoomComments"] = false,
|
||||
["EncryptVoiceChat"] = false,
|
||||
["Name"] = "",
|
||||
["Description"] = "",
|
||||
["ImageName"] = "",
|
||||
["WarningMask"] = 0,
|
||||
["CustomWarning"] = "",
|
||||
["CreatorAccountId"] = 0L,
|
||||
["State"] = 0,
|
||||
["Accessibility"] = 1,
|
||||
["SupportsLevelVoting"] = false,
|
||||
["IsRRO"] = false,
|
||||
["SupportsScreens"] = false,
|
||||
["SupportsWalkVR"] = false,
|
||||
["SupportsTeleportVR"] = false,
|
||||
["SupportsVRLow"] = false,
|
||||
["SupportsQuest2"] = false,
|
||||
["SupportsMobile"] = false,
|
||||
["SupportsJuniors"] = false,
|
||||
["MinLevel"] = 0,
|
||||
["CreatedAt"] = DateTime.UnixEpoch,
|
||||
["Stats"] = new Dictionary<string, object?>
|
||||
{
|
||||
["RoomId"] = 0L,
|
||||
["CheerCount"] = 0,
|
||||
["FavoriteCount"] = 0,
|
||||
["VisitorCount"] = 0,
|
||||
["VisitCount"] = 0
|
||||
},
|
||||
["Version"] = 1,
|
||||
["SubRooms"] = Array.Empty<object>(),
|
||||
["Roles"] = Array.Empty<object>(),
|
||||
["LoadScreens"] = Array.Empty<object>(),
|
||||
["PromoImages"] = Array.Empty<object>(),
|
||||
["PromoExternalContent"] = Array.Empty<object>(),
|
||||
["DataBlob"] = "",
|
||||
["Tags"] = Array.Empty<object>()
|
||||
};
|
||||
|
||||
if (room != null)
|
||||
{
|
||||
var element = System.Text.Json.JsonSerializer.SerializeToElement(room, room.GetType());
|
||||
var roomDict = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, object?>>(element) ?? new Dictionary<string, object?>();
|
||||
foreach (var kv in roomDict)
|
||||
dict[kv.Key] = kv.Value;
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
[HttpGet("rooms/recommendations")]
|
||||
public async Task<List<FullRoom>?> GetRecommendedRooms()
|
||||
{
|
||||
var topRooms = await db.Rooms
|
||||
.Select(r => new
|
||||
{
|
||||
r.RoomId,
|
||||
r.CreatorAccountId,
|
||||
Engagement = db.RoomInteractions
|
||||
.Where(i => i.RoomId == r.RoomId)
|
||||
.Sum(i => (i.Favorited ? 1 : 0) + (i.Cheered ? 1 : 0))
|
||||
})
|
||||
.OrderByDescending(x => x.Engagement)
|
||||
.Take(10)
|
||||
.ToListAsync();
|
||||
|
||||
var convertedRooms = new List<FullRoom>();
|
||||
foreach (var room in topRooms)
|
||||
{
|
||||
var converted = await RoomUtils.GetRoom(room.RoomId);
|
||||
if (converted != null && converted.Accessibility == RecNet.Enums.Accessibility.Public && !converted.IsDorm)
|
||||
convertedRooms.Add(converted);
|
||||
}
|
||||
|
||||
return convertedRooms;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user