131 lines
5.6 KiB
C#
131 lines
5.6 KiB
C#
using DeluxeBackend.Models;
|
|
using DeluxeBackend.Services;
|
|
using static DeluxeBackend.Enums;
|
|
|
|
namespace DeluxeBackend.Extensions
|
|
{
|
|
public static class RoomExtensions
|
|
{
|
|
public static async Task<Dictionary<string, object>> ToDictionary(this Room room, DiscordBotService discord, ILiteDbService db, RoomDetailsMask include = RoomDetailsMask.None)
|
|
{
|
|
List<SubRoom> subRooms = db.SubRooms.Include(x => x.CurrentSave).Include(x => x.Room).Find(x => x.Room.Id == room.Id).ToList();
|
|
Dictionary<string, object> response = new()
|
|
{
|
|
["RoomId"] = room.Id,
|
|
["Accessibility"] = (int)room.Accessibility,
|
|
["CloningAllowed"] = room.CloningAllowed,
|
|
["CreatedAt"] = room.CreatedAt.ToString("O"),
|
|
["CreatorAccountId"] = room.Creator?.Id ?? -1,
|
|
["CustomWarning"] = room.CustomWarning ?? "",
|
|
["Description"] = room.Description ?? "",
|
|
["DisableMicAutoMute"] = room.DisableMicAutoMute,
|
|
["DisableRoomComments"] = room.DisableRoomComments,
|
|
["EncryptVoiceChat"] = room.EncryptVoiceChat,
|
|
["ImageName"] = room.ImageName ?? "DefaultRoomImage.jpg",
|
|
["IsDeveloperOwned"] = room.Creator != null && (room.Creator.Id == 1 || await room.Creator.HasRoleAsync(discord, "Developer")),
|
|
["IsDorm"] = room.IsDorm,
|
|
["IsRRO"] = room.IsRRO,
|
|
["MinLevel"] = room.MinLevel,
|
|
["Name"] = room.IsDorm ? "DormRoom" : (room.Name ?? "NO NAME PLS UPDATE"),
|
|
["MaxPlayerCalculationMode"] = 1,
|
|
["MaxPlayers"] = subRooms.Count != 0 ? subRooms.Max(x => x.MaxPlayers) : -1,
|
|
["State"] = 0,
|
|
["Stats"] = new Dictionary<string, object>()
|
|
{
|
|
["CheerCount"] = room.Stats.CheeredIds.Count,
|
|
["FavoriteCount"] = room.Stats.FavoritedIds.Count,
|
|
["VisitCount"] = room.Stats.VisitCount,
|
|
["VisitorCount"] = room.Stats.VisitorIds.Count
|
|
},
|
|
["SupportsJuniors"] = room.SupportedPlayerTypes.HasFlag(RoomSupports.Juniors),
|
|
["SupportsMobile"] = true,
|
|
["SupportsQuest2"] = true,
|
|
["SupportsVRLow"] = true,
|
|
["SupportsWalkVR"] = room.SupportedPlayerTypes.HasFlag(RoomSupports.WalkVR),
|
|
["SupportsTeleportVR"] = room.SupportedPlayerTypes.HasFlag(RoomSupports.TeleportVR),
|
|
["SupportsScreens"] = room.SupportedPlayerTypes.HasFlag(RoomSupports.Screens),
|
|
["SupportsLevelVoting"] = false,
|
|
["Version"] = 0,
|
|
["ToxmodEnabled"] = false,
|
|
["RankedEntityId"] = room.Id.ToString(),
|
|
["WarningMask"] = (int)room.WarningMask,
|
|
["AutoLocalizeRoom"] = false,
|
|
["LocalizationContext"] = new Dictionary<string, object>
|
|
{
|
|
["LocalizedFields"] = new List<string> { }
|
|
}
|
|
};
|
|
if (room.PersistenceVersion.HasValue)
|
|
{
|
|
response["PersistenceVersion"] = room.PersistenceVersion.Value;
|
|
}
|
|
|
|
if (include.HasFlag(RoomDetailsMask.PromoContent))
|
|
{
|
|
response["PromoExternalContent"] = new List<Dictionary<string, object>>();
|
|
response["PromoImages"] = new List<Dictionary<string, object>>();
|
|
}
|
|
|
|
if (include.HasFlag(RoomDetailsMask.AccountRoles))
|
|
{
|
|
List<Dictionary<string, object>> roles = [];
|
|
if (room.Creator != null)
|
|
{
|
|
roles.Add(new()
|
|
{
|
|
["AccountId"] = room.Creator.Id,
|
|
["InvitedRole"] = (int)RoomRoleType.None,
|
|
["Role"] = (int)RoomRoleType.Creator
|
|
});
|
|
|
|
}
|
|
foreach (RoomRole role in room.Roles)
|
|
{
|
|
roles.Add(new()
|
|
{
|
|
["AccountId"] = role.AccountId,
|
|
["InvitedRole"] = (int)role.InvitedRole,
|
|
["Role"] = (int)role.Role
|
|
});
|
|
}
|
|
response["Roles"] = roles;
|
|
}
|
|
|
|
if (include.HasFlag(RoomDetailsMask.SubRooms) || include.HasFlag(RoomDetailsMask.SubRoomsWithMatchmakingSettings))
|
|
{
|
|
response["SubRooms"] = subRooms.Select(x => x.ToDictionary(include.HasFlag(RoomDetailsMask.DataBlob), include.HasFlag(RoomDetailsMask.MatchmakingDetails))).ToList();
|
|
}
|
|
|
|
if (include.HasFlag(RoomDetailsMask.Tags))
|
|
{
|
|
response["Tags"] = new List<Dictionary<string, object>>()
|
|
{
|
|
new()
|
|
{
|
|
["Tag"] = "beta",
|
|
["Type"] = 1
|
|
},
|
|
new()
|
|
{
|
|
["Tag"] = "limitsv2",
|
|
["Type"] = 1
|
|
}
|
|
};
|
|
}
|
|
|
|
if (include.HasFlag(RoomDetailsMask.DataBlob))
|
|
{
|
|
response["DataBlob"] = room.DataBlob ?? "";
|
|
}
|
|
|
|
if (include.HasFlag(RoomDetailsMask.LoadScreens))
|
|
{
|
|
response["LoadScreens"] = new List<Dictionary<string, object>>();
|
|
response["LoadScreenLocked"] = false;
|
|
}
|
|
|
|
return response;
|
|
}
|
|
}
|
|
}
|