From 673e1bc4a8745cb475bbcb74af74467c3077ac6e Mon Sep 17 00:00:00 2001 From: JacobTech Date: Mon, 18 Nov 2024 23:23:48 -0500 Subject: [PATCH] Done --- LuskiServer/Classes/TableDef/Categories.cs | 2 - LuskiServer/Classes/TableDef/Channels.cs | 2 - LuskiServer/Classes/TableDef/ProfileColors.cs | 22 ----------- LuskiServer/Classes/TableDef/Roles.cs | 3 -- LuskiServer/Classes/Tables.cs | 1 - .../v1/SocketCategoryController.cs | 13 ++----- .../Controllers/v1/SocketChannelController.cs | 10 +---- .../Controllers/v1/SocketProfileController.cs | 30 -------------- .../Controllers/v1/SocketRoleController.cs | 1 - LuskiServer/Converters/Matrix/Matrix.cs | 39 ++++++++++++------- LuskiServer/LuskiServer.csproj | 4 +- LuskiServer/Program.cs | 2 - 12 files changed, 32 insertions(+), 97 deletions(-) delete mode 100644 LuskiServer/Classes/TableDef/ProfileColors.cs diff --git a/LuskiServer/Classes/TableDef/Categories.cs b/LuskiServer/Classes/TableDef/Categories.cs index 47d8b59..33f02d4 100644 --- a/LuskiServer/Classes/TableDef/Categories.cs +++ b/LuskiServer/Classes/TableDef/Categories.cs @@ -10,8 +10,6 @@ public static class Categories { public static TableColumn ID { get; } = new("id", true); public static TableColumn Name { get; } = new("name") { DefaultValue = Encoding.UTF8.GetBytes("New Category") }; - public static TableColumn ColorType { get; } = new("color_type") { DefaultValue = Luski.Shared.PublicServers.V1.Enums.ColorType.Full}; - public static TableColumn Color { get; } = new("color") { DefaultValue = new byte[]{255,255,255,255} }; public static TableColumn Description { get; } = new("description") { DefaultValue = Encoding.UTF8.GetBytes("Description") }; public static TableColumn TitleEncryptionKey { get; } = new("title_encryption_key") { diff --git a/LuskiServer/Classes/TableDef/Channels.cs b/LuskiServer/Classes/TableDef/Channels.cs index 5a59994..512a795 100644 --- a/LuskiServer/Classes/TableDef/Channels.cs +++ b/LuskiServer/Classes/TableDef/Channels.cs @@ -20,8 +20,6 @@ public static class Channels Column = Categories.ID } }; - public static TableColumn ColorType { get; } = new("color_type") { DefaultValue = Luski.Shared.PublicServers.V1.Enums.ColorType.Full}; - public static TableColumn Color { get; } = new("color") {DefaultValue = new byte[]{255,255,255,255} }; public static TableColumn Type { get; } = new("type"); public static TableColumn Epoch { get; } = new("epoch"); public static TableColumn Name { get; } = new("name") { DefaultValue = Encoding.UTF8.GetBytes("New Channel") }; diff --git a/LuskiServer/Classes/TableDef/ProfileColors.cs b/LuskiServer/Classes/TableDef/ProfileColors.cs deleted file mode 100644 index ec3fb7b..0000000 --- a/LuskiServer/Classes/TableDef/ProfileColors.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Luski.Shared.PublicServers.V1.Enums; -using ServerDatabase; -using ServerDatabase.SourceGenerator; - -namespace LuskiServer.Classes.TableDef; - -public static class ProfileColors -{ - public static TableColumn Profile { get; } = new("id", true) - { - ForeignKey = new ForeignKey() - { - Table = Tables.Profiles, - Column = Profiles.ID - } - }; - public static TableColumn ColorType { get; } = new("color_type") { DefaultValue = Luski.Shared.PublicServers.V1.Enums.ColorType.Full}; - public static TableColumn Color { get; } = new("color") { DefaultValue = new byte[]{255,255,255,255}}; -} - -[TableRow(typeof(ProfileColors))] -public partial class ProfileColorRow; \ No newline at end of file diff --git a/LuskiServer/Classes/TableDef/Roles.cs b/LuskiServer/Classes/TableDef/Roles.cs index d29e255..a09971b 100644 --- a/LuskiServer/Classes/TableDef/Roles.cs +++ b/LuskiServer/Classes/TableDef/Roles.cs @@ -1,9 +1,6 @@ using Luski.Shared.PublicServers.V1.Enums; -using LuskiServer.Enums; using ServerDatabase; using ServerDatabase.SourceGenerator; -using ServerDatabase.Utils; -using ServerDatabase.Utils.Enums; namespace LuskiServer.Classes.TableDef; diff --git a/LuskiServer/Classes/Tables.cs b/LuskiServer/Classes/Tables.cs index da129c5..21fcaac 100644 --- a/LuskiServer/Classes/Tables.cs +++ b/LuskiServer/Classes/Tables.cs @@ -23,7 +23,6 @@ public static class Tables public static Table MessageFiles { get; } = new("message_files", null!); public static Table Messages { get; } = new("messages", null!); public static Table OfflineData { get; } = new("offline_data", null!); - public static Table ProfileColors { get; } = new("profile_colors", null!); public static Table ProfileControllers { get; } = new("profile_controllers", null!); public static Table ProfileRoleControllers { get; } = new("profiles_role_controllers", null!); public static Table Profiles { get; } = new("profiles", null!); diff --git a/LuskiServer/Controllers/v1/SocketCategoryController.cs b/LuskiServer/Controllers/v1/SocketCategoryController.cs index 892f208..f662a90 100644 --- a/LuskiServer/Controllers/v1/SocketCategoryController.cs +++ b/LuskiServer/Controllers/v1/SocketCategoryController.cs @@ -26,7 +26,6 @@ public class SocketCategoryController : ControllerBase epoch = DateTime.UtcNow.Date; LuskiFunctions.Snowflake chanSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch); Tables.Categories.Insert( - Categories.ColorType.CreateParameter(ChanReq.ColorType), Categories.ID.CreateParameter(chanSnowflake.ID), Categories.Name.CreateParameter(Convert.FromBase64String(ChanReq.Name)), Categories.Description.CreateParameter(Convert.FromBase64String(ChanReq.Description)), @@ -111,9 +110,7 @@ public class SocketCategoryController : ControllerBase TitleEncoderType = chan.TitleEncoderType, DescriptionEncoderType = chan.DescriptionEncoderType, UserOverrides = UO.ToArray(), - RoleOverrides = RO.ToArray(), - ColorType = chan.ColorType, - Color = Convert.ToHexString(chan.Color) + RoleOverrides = RO.ToArray() }); } catch (Exception e) @@ -219,9 +216,7 @@ public class SocketCategoryController : ControllerBase TitleEncoderType = chan.TitleEncoderType, DescriptionEncoderType = chan.DescriptionEncoderType, UserOverrides = UO.ToArray(), - RoleOverrides = RO.ToArray(), - ColorType = chan.ColorType, - Color = Convert.ToHexString(chan.Color) + RoleOverrides = RO.ToArray() }); } catch (Exception e) @@ -318,9 +313,7 @@ public class SocketCategoryController : ControllerBase TitleEncoderType = chan.TitleEncoderType, DescriptionEncoderType = chan.DescriptionEncoderType, UserOverrides = UO.ToArray(), - RoleOverrides = RO.ToArray(), - ColorType = chan.ColorType, - Color = Convert.ToHexString(chan.Color) + RoleOverrides = RO.ToArray() }); } catch (Exception e) diff --git a/LuskiServer/Controllers/v1/SocketChannelController.cs b/LuskiServer/Controllers/v1/SocketChannelController.cs index 035f77a..4f4391e 100644 --- a/LuskiServer/Controllers/v1/SocketChannelController.cs +++ b/LuskiServer/Controllers/v1/SocketChannelController.cs @@ -29,8 +29,6 @@ public class SocketChannelController : ControllerBase Tables.Channels.Insert( Channels.ID.CreateParameter(chanSnowflake.ID), Channels.Parent.CreateParameter(ChanReq.Parent), - Channels.ColorType.CreateParameter(ChanReq.ColorType), - Channels.Color.CreateParameter(Convert.FromHexString(ChanReq.Color)), Channels.Type.CreateParameter(ChanReq.Type), Channels.Epoch.CreateParameter(epoch.Date), Channels.Name.CreateParameter(Convert.FromBase64String(ChanReq.Name)), @@ -111,9 +109,7 @@ public class SocketChannelController : ControllerBase EncoderTypes = chan.EncoderTypes, UserOverrides = UO.ToArray(), RoleOverrides = RO.ToArray(), - PictureType = chan.PictureType, - ColorType = chan.ColorType, - Color = Convert.ToHexString(chan.Color) + PictureType = chan.PictureType }); } catch (Exception e) @@ -220,9 +216,7 @@ public class SocketChannelController : ControllerBase EncoderTypes = chan.EncoderTypes, UserOverrides = UO.ToArray(), RoleOverrides = RO.ToArray(), - PictureType = chan.PictureType, - ColorType = chan.ColorType, - Color = Convert.ToHexString(chan.Color) + PictureType = chan.PictureType }); } catch (Exception e) diff --git a/LuskiServer/Controllers/v1/SocketProfileController.cs b/LuskiServer/Controllers/v1/SocketProfileController.cs index 801fcba..817bfef 100644 --- a/LuskiServer/Controllers/v1/SocketProfileController.cs +++ b/LuskiServer/Controllers/v1/SocketProfileController.cs @@ -58,22 +58,12 @@ public class SocketProfileController : ControllerBase { if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc; if (!Tables.Profiles.TryReadRow(out ProfileRow PR, Profiles.ID.CreateParameter(Person))) return this.ShowError(ErrorCode.Forbidden, "Profile does not exist"); - string? color = null; - ColorType? ct = null; - if (Tables.ProfileColors.TryReadRow(out var b, - ProfileColors.Profile.CreateParameter(PR.ID))) - { - color = Convert.ToHexString(b.Color); - ct = b.ColorType; - } return this.ResponseToResult(new ProfileSTC() { ID = PR.ID, DisplayName = PR.DisplayName, PictureType = PR.PictureType, Controllers = Tables.ProfileControllers.ReadColumn(ProfileControllers.User, ProfileControllers.Profile.CreateParameter(Person)), - ColorType = ct, - Color = color, RoleControllers = Tables.ProfileRoleControllers.ReadColumn(ProfileRoleControllers.Role, ProfileRoleControllers.Profile.CreateParameter(Person)), Channels = Tables.ChannelProfiles.ReadColumn(ChannelProfiles.Channel, ChannelProfiles.Profile.CreateParameter(Person)), Categories = Tables.CategoryProfiles.ReadColumn(CategoryProfiles.Category, CategoryProfiles.Profile.CreateParameter(Person)), @@ -100,22 +90,12 @@ public class SocketProfileController : ControllerBase { foreach (ProfileRow PR in PcRs) { - string? color = null; - ColorType? ct = null; - if (Tables.ProfileColors.TryReadRow(out ProfileColorRow b, - ProfileColors.Profile.CreateParameter(PR.ID))) - { - color = Convert.ToHexString(b.Color); - ct = b.ColorType; - } Vals.Add(PR.ID, new() { ID = PR.ID, DisplayName = PR.DisplayName, PictureType = PR.PictureType, Controllers = Tables.ProfileControllers.ReadColumn(ProfileControllers.User, ProfileControllers.Profile.CreateParameter(PR.ID)), - ColorType = ct, - Color = color, RoleControllers = Tables.ProfileRoleControllers.ReadColumn(ProfileRoleControllers.Role, ProfileRoleControllers.Profile.CreateParameter(PR.ID)), Channels = Tables.ChannelProfiles.ReadColumn(ChannelProfiles.Channel, ChannelProfiles.Profile.CreateParameter(PR.ID)), Categories = Tables.CategoryProfiles.ReadColumn(CategoryProfiles.Category, CategoryProfiles.Profile.CreateParameter(PR.ID)), @@ -132,22 +112,12 @@ public class SocketProfileController : ControllerBase { if (!Vals.ContainsKey(PR.ID)) { - string? color = null; - ColorType? ct = null; - if (Tables.ProfileColors.TryReadRow(out var b, - ProfileColors.Profile.CreateParameter(PR.ID))) - { - color = Convert.ToHexString(b.Color); - ct = b.ColorType; - } Vals.Add(PR.ID, new() { ID = PR.ID, DisplayName = PR.DisplayName, PictureType = PR.PictureType, Controllers = Tables.ProfileControllers.ReadColumn(ProfileControllers.User, ProfileControllers.Profile.CreateParameter(PR.ID)), - ColorType = ct, - Color = color, RoleControllers = Tables.ProfileRoleControllers.ReadColumn(ProfileRoleControllers.Role, ProfileRoleControllers.Profile.CreateParameter(PR.ID)), Channels = Tables.ChannelProfiles.ReadColumn(ChannelProfiles.Channel, ChannelProfiles.Profile.CreateParameter(PR.ID)), Categories = Tables.CategoryProfiles.ReadColumn(CategoryProfiles.Category, CategoryProfiles.Profile.CreateParameter(PR.ID)), diff --git a/LuskiServer/Controllers/v1/SocketRoleController.cs b/LuskiServer/Controllers/v1/SocketRoleController.cs index 42129eb..d911541 100644 --- a/LuskiServer/Controllers/v1/SocketRoleController.cs +++ b/LuskiServer/Controllers/v1/SocketRoleController.cs @@ -2,7 +2,6 @@ using Asp.Versioning; using Luski.Shared.PublicServers.V1.ClientToServer.HTTP; using Luski.Shared.PublicServers.V1.Enums; using Luski.Shared.PublicServers.V1.ServerToClient.HTTP; -using Luski.Shared.PublicServers.V1.ServerToClient.WSS; using Luski.Shared.PublicServers.V1.Shared; using LuskiServer.Classes; using LuskiServer.Classes.ServerComs; diff --git a/LuskiServer/Converters/Matrix/Matrix.cs b/LuskiServer/Converters/Matrix/Matrix.cs index c9339eb..600de51 100644 --- a/LuskiServer/Converters/Matrix/Matrix.cs +++ b/LuskiServer/Converters/Matrix/Matrix.cs @@ -10,9 +10,23 @@ namespace LuskiServer.Converters.Matrix; public static class Matrix { + /// + /// + /// + /// File Stream + /// Luski Channel ID + /// ID of user doing the conversion + /// Map of matrix name to luski account + /// Map of matrix name to Luski Profile + /// Map of matrix names to new Luski Profiles + /// List of ignored matrix names + /// The Encoding to use for Luski Messages + /// The Encryption key to use for Luski Messages + /// Removes channel if same id is already created + /// public static void ZipJsonChatExport(Stream Zip, long Channel, long defaultuser, Dictionary UserMap, - Dictionary ChannelProfilesIdList, - List> Profiles, + Dictionary ProfilesIdList, + List> Profiles, List IgnoredUsers, EncoderType Encoder, long Encryption, bool remove = true) { Dictionary IdConverter = new(); @@ -30,21 +44,18 @@ public static class Matrix void checkFakeUser(string id) { - if (!IdConverter.ContainsKey(ChannelProfilesIdList[id])) + if (!IdConverter.ContainsKey(ProfilesIdList[id])) { long id2 = LuskiFunctions.Snowflake.GenerateSnowflake().ID; Tables.Profiles.Insert( Classes.TableDef.Profiles.ID.CreateParameter(id2), - Classes.TableDef.Profiles.PictureType.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item3), - Classes.TableDef.Profiles.Picture.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item2), - Classes.TableDef.Profiles.DisplayName.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item1)); - Tables.ProfileColors.Insert( - ProfileColors.Profile.CreateParameter(id2), - ProfileColors.Color.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item4)); - IdConverter.Add(ChannelProfilesIdList[id], id2); + Classes.TableDef.Profiles.PictureType.CreateParameter(Profiles[ProfilesIdList[id]].Item3), + Classes.TableDef.Profiles.Picture.CreateParameter(Profiles[ProfilesIdList[id]].Item2), + Classes.TableDef.Profiles.DisplayName.CreateParameter(Profiles[ProfilesIdList[id]].Item1)); + IdConverter.Add(ProfilesIdList[id], id2); Tables.ChannelProfiles.Insert(ChannelProfiles.Channel.CreateParameter(Channel), ChannelProfiles.Profile.CreateParameter(id2)); - foreach (KeyValuePair v in ChannelProfilesIdList.Where(s => s.Value == ChannelProfilesIdList[id])) + foreach (KeyValuePair v in ProfilesIdList.Where(s => s.Value == ProfilesIdList[id])) { cps.Add(v.Key, id2); } @@ -78,7 +89,7 @@ public static class Matrix Console.WriteLine(inow + " of " + imax); if (msg.Type != "m.room.message") continue; - if (!UserMap.ContainsKey(msg.Sender) && !ChannelProfilesIdList.ContainsKey(msg.Sender)) + if (!UserMap.ContainsKey(msg.Sender) && !ProfilesIdList.ContainsKey(msg.Sender)) { if (IgnoredUsers.Contains(msg.Sender)) continue; @@ -102,10 +113,10 @@ public static class Matrix cur = cur.ToLocalTime(); long id; long profile = 0; - if (ChannelProfilesIdList.ContainsKey(msg.Sender)) + if (ProfilesIdList.ContainsKey(msg.Sender)) { checkFakeUser(msg.Sender); - profile = IdConverter[ChannelProfilesIdList[msg.Sender]]; + profile = IdConverter[ProfilesIdList[msg.Sender]]; id = defaultuser; } else diff --git a/LuskiServer/LuskiServer.csproj b/LuskiServer/LuskiServer.csproj index 2fc5382..e73280a 100644 --- a/LuskiServer/LuskiServer.csproj +++ b/LuskiServer/LuskiServer.csproj @@ -5,7 +5,7 @@ enable enable true - 1.0.0.0 + 1.0.0.1 @@ -22,7 +22,7 @@ - + diff --git a/LuskiServer/Program.cs b/LuskiServer/Program.cs index 902f6ad..9d3ce08 100644 --- a/LuskiServer/Program.cs +++ b/LuskiServer/Program.cs @@ -76,7 +76,6 @@ if (!Tables.Profiles.TryRead(Profiles.ID, out _, Profiles.ID.CreateParameter(0)) Profiles.DisplayName.CreateParameter("Server"), Profiles.PictureType.CreateParameter(PictureType.none), Profiles.Picture.CreateParameter(Array.Empty())); - Tables.ProfileColors.Insert(ProfileColors.Profile.CreateParameter(0), ProfileColors.Color.CreateParameter((new byte[] {255,255,255,255}))); } if (!LuskiFunctions.Database.VersionsTable.TryRead(LuskiFunctions.Database.VersionsTable.ID, out _, @@ -143,7 +142,6 @@ if (!Tables.Roles.TryRead(Roles.ID, out _, Roles.ID.CreateParameter(0))) Tables.Roles.Insert( Roles.ID.CreateParameter(0), Roles.DisplayName.CreateParameter("Members"), - Roles.Color.CreateDefaultParameter(), Roles.Description.CreateParameter("The default role for the server. Everybody will have this role."), Roles.ServerPermissions.CreateParameter( ServerPermission.ViewChannels |