Lib Updates

This commit is contained in:
JacobTech 2024-03-31 23:55:46 -04:00
parent 298fdd2ef7
commit 346ef16530
30 changed files with 354 additions and 218 deletions

View File

@ -1,3 +1,4 @@
using System.Collections.Immutable;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
@ -166,6 +167,18 @@ public static class LuskiFunctions
return Members.ToArray(); return Members.ToArray();
} }
public static long[] GetCategoryChannels(long Category, long User)
{
List<long> chans = new();
long[] channels = Tables.Channels.ReadColumn(Channels.ID, Channels.Parent.CreateParameter(Category));
for (int i = 0; i < channels.Length; i++)
{
if (HasAccessToChannel(User, channels[i])) chans.Add(channels[i]);
}
return chans.ToArray();
}
public static bool HasPermissions(long User, ServerPermission RequiredPerms) public static bool HasPermissions(long User, ServerPermission RequiredPerms)
{ {
if (User == Tables.Server.Read(Server.Owner, Server.ID.CreateParameter(0))) return true; if (User == Tables.Server.Read(Server.Owner, Server.ID.CreateParameter(0))) return true;
@ -190,8 +203,10 @@ public static class LuskiFunctions
ServerPermission BadPermissions = ServerPermission.None; ServerPermission BadPermissions = ServerPermission.None;
ServerPermission GoodPerms = ServerPermission.None; ServerPermission GoodPerms = ServerPermission.None;
long[] CatUserOverides = Tables.Categories.Read(Categories.UserOverrides, Categories.ID.CreateParameter(Category)); (long[], long[]) crow = Tables.Categories.CreateCommand().WithFilter(Categories.ID, Category)
foreach (long CatUserOveride in CatUserOverides) .Read(Categories.UserOverrides, Categories.RoleOverrides);
foreach (long CatUserOveride in crow.Item1)
{ {
if (!Tables.UserRoleOverrides.TryReadRow(out UserRoleOverrideRow row, UserRoleOverrides.ID.CreateParameter(CatUserOveride), UserRoleOverrides.UserID.CreateParameter(User))) continue; if (!Tables.UserRoleOverrides.TryReadRow(out UserRoleOverrideRow row, UserRoleOverrides.ID.CreateParameter(CatUserOveride), UserRoleOverrides.UserID.CreateParameter(User))) continue;
if (!row.BadPermissions.HasPermission(ServerPermission.ViewThis)) if (!row.BadPermissions.HasPermission(ServerPermission.ViewThis))
@ -203,39 +218,48 @@ public static class LuskiFunctions
BadPermissions |= row.BadPermissions; BadPermissions |= row.BadPermissions;
GoodPerms |= row.GoodPermissions; GoodPerms |= row.GoodPermissions;
} }
long[] CatRoleOverides = Tables.Categories.Read(Categories.RoleOverrides, Categories.ID.CreateParameter(Category));
foreach (long CatRoleOveride in CatRoleOverides) int bad_index = -1;
int good_index = -1;
foreach (long CatRoleOveride in crow.Item2)
{ {
if (!UserRoleIDList.Contains(CatRoleOveride)) continue;
ServerRoleOverrideRow row = Tables.ServerRoleOverrides.ReadRow(ServerRoleOverrides.ID.CreateParameter(CatRoleOveride)); ServerRoleOverrideRow row = Tables.ServerRoleOverrides.ReadRow(ServerRoleOverrides.ID.CreateParameter(CatRoleOveride));
if (!UserRoleIDList.Contains(row.RoleID)) continue;
int i = Tables.Roles.Read(Roles.Index, Roles.ID.CreateParameter(row.RoleID));
if (!row.BadPermissions.HasPermission(ServerPermission.ViewThis) && !GoodPerms.HasPermission(ServerPermission.ViewThis)) if (!row.BadPermissions.HasPermission(ServerPermission.ViewThis) && !GoodPerms.HasPermission(ServerPermission.ViewThis))
{ {
missing = ServerPermission.ViewThis; if (bad_index < i)
return false; bad_index = i;
} }
else good_index = i;
BadPermissions |= (GoodPerms ^ row.BadPermissions); BadPermissions |= row.BadPermissions;
GoodPerms |= row.GoodPermissions; GoodPerms |= row.GoodPermissions;
} }
if (bad_index > good_index)
{
missing = ServerPermission.ViewThis;
return false;
}
foreach (long RoleID in UserRoleIDList) foreach (long RoleID in UserRoleIDList)
{ {
ServerPermission pers = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID)); ServerPermission pers = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID));
if (!pers.HasPermission(ServerPermission.ViewThis) && !GoodPerms.HasPermission(ServerPermission.ViewThis))
{
missing = ServerPermission.ViewThis;
return false;
}
GoodPerms |= pers; GoodPerms |= pers;
} }
ServerPermission combine = GoodPerms ^ BadPermissions; ServerPermission combine = GoodPerms ^ BadPermissions;
missing = (combine ^ OptionalPerms) & OptionalPerms; missing = (combine ^ OptionalPerms) & OptionalPerms;
if (!combine.HasPermission(ServerPermission.ViewThis))
{
missing |= ServerPermission.ViewThis;
return false;
}
return true; return true;
} }
public static bool HasAccessToCategory(long User, long Category, ServerPermission RequiredPerms) public static bool HasAccessToCategory(long User, long Category, ServerPermission RequiredPerms = ServerPermission.ViewThis)
{ {
if (User == Tables.Server.Read(Server.Owner, Server.ID.CreateParameter(0))) return true; if (User == Tables.Server.Read(Server.Owner, Server.ID.CreateParameter(0))) return true;
long[] UserRoleIDList = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(User)); long[] UserRoleIDList = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(User));
@ -244,62 +268,83 @@ public static class LuskiFunctions
ServerPermission GoodPerms = ServerPermission.None; ServerPermission GoodPerms = ServerPermission.None;
long[] CatUserOverides = Tables.Categories.Read(Categories.UserOverrides, Categories.ID.CreateParameter(Category)); (long[], long[]) crow = Tables.Categories.CreateCommand().WithFilter(Categories.ID, Category)
foreach (long CatUserOveride in CatUserOverides) .Read(Categories.UserOverrides, Categories.RoleOverrides);
foreach (long CatUserOveride in crow.Item1)
{ {
if (!Tables.UserRoleOverrides.TryReadRow(out UserRoleOverrideRow row, UserRoleOverrides.ID.CreateParameter(CatUserOveride), UserRoleOverrides.UserID.CreateParameter(User))) continue; if (!Tables.UserRoleOverrides.TryReadRow(out UserRoleOverrideRow row, UserRoleOverrides.ID.CreateParameter(CatUserOveride), UserRoleOverrides.UserID.CreateParameter(User))) continue;
if ((row.BadPermissions & RequiredPerms) > ServerPermission.None) return false; if ((row.BadPermissions & RequiredPerms) > ServerPermission.None) return false;
GoodPerms |= row.GoodPermissions; GoodPerms |= row.GoodPermissions;
} }
long[] CatRoleOverides = Tables.Categories.Read(Categories.RoleOverrides, Categories.ID.CreateParameter(Category));
foreach (long CatRoleOveride in CatRoleOverides) int bad_index = -1;
int good_index = -1;
foreach (long CatRoleOveride in crow.Item2)
{ {
if (!UserRoleIDList.Contains(CatRoleOveride)) continue;
ServerRoleOverrideRow row = Tables.ServerRoleOverrides.ReadRow(ServerRoleOverrides.ID.CreateParameter(CatRoleOveride)); ServerRoleOverrideRow row = Tables.ServerRoleOverrides.ReadRow(ServerRoleOverrides.ID.CreateParameter(CatRoleOveride));
if (((row.BadPermissions & RequiredPerms) ^ GoodPerms) > ServerPermission.None) return false; if (!UserRoleIDList.Contains(row.RoleID)) continue;
int i = Tables.Roles.Read(Roles.Index, Roles.ID.CreateParameter(row.RoleID));
if (((row.BadPermissions & RequiredPerms) ^ GoodPerms) > ServerPermission.None)
{
if (bad_index < i)
bad_index = i;
}
else good_index = i;
GoodPerms |= row.GoodPermissions; GoodPerms |= row.GoodPermissions;
} }
if (bad_index > good_index) return false;
foreach (long RoleID in UserRoleIDList) foreach (long RoleID in UserRoleIDList)
{ {
ServerPermission pers = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID)); ServerPermission pers = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID));
if (((pers & RequiredPerms) ^ GoodPerms) > ServerPermission.None) return false;
GoodPerms |= pers; GoodPerms |= pers;
} }
return GoodPerms.HasPermission(RequiredPerms); return GoodPerms.HasPermission(RequiredPerms);
} }
public static bool HasAccessToChannel(long User, long Channel, ServerPermission RequiredPerms) public static bool HasAccessToChannel(long User, long Channel, ServerPermission RequiredPerms = ServerPermission.ViewThis)
{ {
if (User == Tables.Server.Read(Server.Owner, Server.ID.CreateParameter(0))) return true;
long[] UserRoleIDList = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(User)); long[] UserRoleIDList = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(User));
RequiredPerms |= ServerPermission.ViewThis; RequiredPerms |= ServerPermission.ViewThis;
ServerPermission GoodPerms = ServerPermission.None; ServerPermission GoodPerms = ServerPermission.None;
long[] ChanUserOverides = Tables.Channels.Read(Channels.UserOverrides, Channels.ID.CreateParameter(Channel)); (long[], long[]) crow = Tables.Channels.CreateCommand().WithFilter(Channels.ID, Channel)
long[] ChanRoleOverides = Tables.Channels.Read(Channels.RoleOverrides, Channels.ID.CreateParameter(Channel)); .Read(Channels.UserOverrides, Channels.RoleOverrides);
foreach (long CatUserOveride in ChanUserOverides) foreach (long CatUserOveride in crow.Item1)
{ {
if (!Tables.UserRoleOverrides.TryReadRow(out UserRoleOverrideRow row, UserRoleOverrides.ID.CreateParameter(CatUserOveride), UserRoleOverrides.UserID.CreateParameter(User))) continue; if (!Tables.UserRoleOverrides.TryReadRow(out UserRoleOverrideRow row, UserRoleOverrides.ID.CreateParameter(CatUserOveride), UserRoleOverrides.UserID.CreateParameter(User))) continue;
if ((row.BadPermissions & RequiredPerms) > ServerPermission.None) return false; if ((row.BadPermissions & RequiredPerms) > ServerPermission.None) return false;
GoodPerms |= row.GoodPermissions; GoodPerms |= row.GoodPermissions;
} }
foreach (long CatRoleOveride in ChanRoleOverides)
int bad_index = -1;
int good_index = -1;
foreach (long CatRoleOveride in crow.Item2)
{ {
if (!UserRoleIDList.Contains(CatRoleOveride)) continue;
ServerRoleOverrideRow row = Tables.ServerRoleOverrides.ReadRow(ServerRoleOverrides.ID.CreateParameter(CatRoleOveride)); ServerRoleOverrideRow row = Tables.ServerRoleOverrides.ReadRow(ServerRoleOverrides.ID.CreateParameter(CatRoleOveride));
if (((row.BadPermissions & RequiredPerms) ^ GoodPerms) > ServerPermission.None) return false; if (!UserRoleIDList.Contains(row.RoleID)) continue;
int i = Tables.Roles.Read(Roles.Index, Roles.ID.CreateParameter(row.RoleID));
if (((row.BadPermissions & RequiredPerms) ^ GoodPerms) > ServerPermission.None)
{
if (bad_index < i)
bad_index = i;
}
else good_index = i;
GoodPerms |= row.GoodPermissions; GoodPerms |= row.GoodPermissions;
} }
if (bad_index > good_index) return false;
foreach (long RoleID in UserRoleIDList) foreach (long RoleID in UserRoleIDList)
{ {
ServerPermission pers = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID)); ServerPermission pers = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID));
if (((pers & RequiredPerms) ^ GoodPerms) > ServerPermission.None) return false;
GoodPerms |= pers; GoodPerms |= pers;
} }

View File

@ -79,7 +79,11 @@ public static class WSS
string Token = $"{Convert.ToBase64String(Encoding.UTF8.GetBytes(row.User.ToString()))}.{Convert.ToBase64String(Encoding.UTF8.GetBytes(row.ID.ToString()))}.{Convert.ToBase64String(Encoding.UTF8.GetBytes(DateTime.UtcNow.ToString()))}.{Convert.ToBase64String(Encoding.UTF8.GetBytes(new Random().Next(0, 1000000).ToString()))}.{Convert.ToBase64String(Encoding.UTF8.GetBytes(new Random().Next(0, 1000000).ToString()))}"; string Token = $"{Convert.ToBase64String(Encoding.UTF8.GetBytes(row.User.ToString()))}.{Convert.ToBase64String(Encoding.UTF8.GetBytes(row.ID.ToString()))}.{Convert.ToBase64String(Encoding.UTF8.GetBytes(DateTime.UtcNow.ToString()))}.{Convert.ToBase64String(Encoding.UTF8.GetBytes(new Random().Next(0, 1000000).ToString()))}.{Convert.ToBase64String(Encoding.UTF8.GetBytes(new Random().Next(0, 1000000).ToString()))}";
te.Token = Token; te.Token = Token;
te.Type = DataType.Token; te.Type = DataType.Token;
Tables.Sessions.Update(TableDef.Sessions.ID, row.ID, TableDef.Sessions.LoginToken.CreateParameter(string.Empty), TableDef.Sessions.Token.CreateParameter(Token), TableDef.Sessions.WSSTCP.CreateParameter(ID)); Tables.Sessions.CreateCommand()
.WithFilter(TableDef.Sessions.ID, row.ID)
.WithValue(TableDef.Sessions.LoginToken, string.Empty)
.WithValue(TableDef.Sessions.Token, Token)
.WithValue(TableDef.Sessions.WSSTCP, ID).Update();
Token = $"{Convert.ToBase64String(Encoding.UTF8.GetBytes(row.User.ToString()))}.{Convert.ToBase64String(Encoding.UTF8.GetBytes(DateTime.UtcNow.ToString()))}.{Convert.ToBase64String(Encoding.UTF8.GetBytes(new Random().Next(0, 1000000).ToString()))}.{Convert.ToBase64String(Encoding.UTF8.GetBytes(new Random().Next(0, 1000000).ToString()))}"; Token = $"{Convert.ToBase64String(Encoding.UTF8.GetBytes(row.User.ToString()))}.{Convert.ToBase64String(Encoding.UTF8.GetBytes(DateTime.UtcNow.ToString()))}.{Convert.ToBase64String(Encoding.UTF8.GetBytes(new Random().Next(0, 1000000).ToString()))}.{Convert.ToBase64String(Encoding.UTF8.GetBytes(new Random().Next(0, 1000000).ToString()))}";
te.SessionToken = Token; te.SessionToken = Token;
Tables.SessionTokens.Insert( Tables.SessionTokens.Insert(

View File

@ -5,9 +5,9 @@ namespace LuskiServer.Classes.TableDef;
public static class AltServers public static class AltServers
{ {
public static TableColumn<string> Address { get; } = new("address", true); public static TableColumn<AltServerRow, string> Address { get; } = new("address", true);
public static TableColumn<bool> Secure { get; }= new("secure"); public static TableColumn<AltServerRow, bool> Secure { get; }= new("secure");
public static TableColumn<byte[]> Key { get; } = new("key"); public static TableColumn<AltServerRow, byte[]> Key { get; } = new("key");
} }
[TableRow(typeof(AltServers))] [TableRow(typeof(AltServers))]

View File

@ -7,19 +7,17 @@ namespace LuskiServer.Classes.TableDef;
public static class Categories public static class Categories
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<CategoryRow, long> ID { get; } = new("id", true);
public static TableColumn<byte[]> Name { get; } = new("name") { DefaultValue = Encoding.UTF8.GetBytes("New Category") }; public static TableColumn<CategoryRow, byte[]> Name { get; } = new("name") { DefaultValue = Encoding.UTF8.GetBytes("New Category") };
public static TableColumn<byte[]> Color { get; } = new("color") { DefaultValue = new byte[]{255,255,255,255} }; public static TableColumn<CategoryRow, byte[]> Color { get; } = new("color") { DefaultValue = new byte[]{255,255,255,255} };
public static TableColumn<byte[]> Description { get; } = new("description") { DefaultValue = Encoding.UTF8.GetBytes("Description") }; public static TableColumn<CategoryRow, byte[]> Description { get; } = new("description") { DefaultValue = Encoding.UTF8.GetBytes("Description") };
public static TableColumn<long> Parent { get; } = new("parent") { DefaultValue = -1 }; public static TableColumn<CategoryRow, long> Parent { get; } = new("parent") { DefaultValue = -1 };
public static TableColumn<long[]> InnerCategories { get; } = new("inner_categories") { DefaultValue = Array.Empty<long>() }; public static TableColumn<CategoryRow, long[]> RoleOverrides { get; } = new("role_overrides") { DefaultValue = Array.Empty<long>() };
public static TableColumn<long[]> Channels { get; } = new("channels") { DefaultValue = Array.Empty<long>() }; public static TableColumn<CategoryRow, long[]> UserOverrides { get; } = new("member_overrides") { DefaultValue = Array.Empty<long>() };
public static TableColumn<long[]> RoleOverrides { get; } = new("role_overrides") { DefaultValue = Array.Empty<long>() }; public static TableColumn<CategoryRow, long> TitleEncryptionKey { get; } = new("title_encryption_key") { DefaultValue = 0 };
public static TableColumn<long[]> UserOverrides { get; } = new("member_overrides") { DefaultValue = Array.Empty<long>() }; public static TableColumn<CategoryRow, long> DescriptionEncryptionKey { get; } = new("description_encryption_key") { DefaultValue = 0 };
public static TableColumn<long> TitleEncryptionKey { get; } = new("title_encryption_key") { DefaultValue = 0 }; public static TableColumn<CategoryRow, EncoderType> TitleEncoderType { get; } = new("title_encoder_type") { DefaultValue = EncoderType.UTF8 };
public static TableColumn<long> DescriptionEncryptionKey { get; } = new("description_encryption_key") { DefaultValue = 0 }; public static TableColumn<CategoryRow, EncoderType> DescriptionEncoderType { get; } = new("description_encoder_type") { DefaultValue = EncoderType.UTF8 };
public static TableColumn<EncoderType> TitleEncoderType { get; } = new("title_encoder_type") { DefaultValue = EncoderType.UTF8 };
public static TableColumn<EncoderType> DescriptionEncoderType { get; } = new("description_encoder_type") { DefaultValue = EncoderType.UTF8 };
} }
[TableRow(typeof(Categories))] [TableRow(typeof(Categories))]
public partial class CategoryRow public partial class CategoryRow

View File

@ -7,12 +7,12 @@ namespace LuskiServer.Classes.TableDef;
public class ChannelProfiles public class ChannelProfiles
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<ChannelProfileRow, long> ID { get; } = new("id", true);
public static TableColumn<string> DisplayName { get; } = new("displayname"); public static TableColumn<ChannelProfileRow, string> DisplayName { get; } = new("displayname");
public static TableColumn<long[]> Controllers { get; } = new("controllers") {DefaultValue = Array.Empty<long>()}; public static TableColumn<ChannelProfileRow, long[]> Controllers { get; } = new("controllers") {DefaultValue = Array.Empty<long>()};
public static TableColumn<PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png }; public static TableColumn<ChannelProfileRow, PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png };
public static TableColumn<byte[]> Picture { get; } = new("picture"); public static TableColumn<ChannelProfileRow, byte[]> Picture { get; } = new("picture");
public static TableColumn<byte[]> Color { get; } = new("color") { DefaultValue = new byte[]{255,255,255,255}}; public static TableColumn<ChannelProfileRow, byte[]> Color { get; } = new("color") { DefaultValue = new byte[]{255,255,255,255}};
} }
[TableRow(typeof(ChannelProfiles))] [TableRow(typeof(ChannelProfiles))]

View File

@ -10,30 +10,30 @@ namespace LuskiServer.Classes.TableDef;
public static class Channels public static class Channels
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<ChannelRow, long> ID { get; } = new("id", true);
public static TableColumn<long> Parent { get; } = new("parent") { DefaultValue = -1 }; public static TableColumn<ChannelRow, long> Parent { get; } = new("parent") { DefaultValue = -1 };
public static TableColumn<byte[]> Color { get; } = new("color") {DefaultValue = new byte[]{255,255,255,255} }; public static TableColumn<ChannelRow, byte[]> Color { get; } = new("color") {DefaultValue = new byte[]{255,255,255,255} };
public static TableColumn<ChannelType> Type { get; } = new("type"); public static TableColumn<ChannelRow, ChannelType> Type { get; } = new("type");
public static TableColumn<DateTime> Epoch { get; } = new("epoch"); public static TableColumn<ChannelRow, DateTime> Epoch { get; } = new("epoch");
public static TableColumn<byte[]> Name { get; } = new("name") { DefaultValue = Encoding.UTF8.GetBytes("New Channel") }; public static TableColumn<ChannelRow, byte[]> Name { get; } = new("name") { DefaultValue = Encoding.UTF8.GetBytes("New Channel") };
public static TableColumn<byte[]> Description { get; } = new("description") { DefaultValue = Encoding.UTF8.GetBytes("New Channel") }; public static TableColumn<ChannelRow, byte[]> Description { get; } = new("description") { DefaultValue = Encoding.UTF8.GetBytes("New Channel") };
public static TableColumn<long[]> RoleOverrides { get; } = new("role_overrides") { DefaultValue = Array.Empty<long>() }; public static TableColumn<ChannelRow, long[]> RoleOverrides { get; } = new("role_overrides") { DefaultValue = Array.Empty<long>() };
public static TableColumn<long[]> UserOverrides { get; } = new("member_overrides") { DefaultValue = Array.Empty<long>() }; public static TableColumn<ChannelRow, long[]> UserOverrides { get; } = new("member_overrides") { DefaultValue = Array.Empty<long>() };
public static TableColumn<long> TitleEncryptionKey { get; } = new("title_encryption_key") { DefaultValue = 0 }; public static TableColumn<ChannelRow, long> TitleEncryptionKey { get; } = new("title_encryption_key") { DefaultValue = 0 };
public static TableColumn<long> DescriptionEncryptionKey { get; } = new("description_encryption_key") { DefaultValue = 0 }; public static TableColumn<ChannelRow, long> DescriptionEncryptionKey { get; } = new("description_encryption_key") { DefaultValue = 0 };
public static TableColumn<long[]> EncryptionKeys { get; } = new("encryption_keys") { DefaultValue = new long[]{0} }; public static TableColumn<ChannelRow, long[]> EncryptionKeys { get; } = new("encryption_keys") { DefaultValue = new long[]{0} };
public static TableColumn<EncoderType> TitleEncoderType { get; } = new("title_encoder_type") { DefaultValue = EncoderType.UTF8 }; public static TableColumn<ChannelRow, EncoderType> TitleEncoderType { get; } = new("title_encoder_type") { DefaultValue = EncoderType.UTF8 };
public static TableColumn<EncoderType> DescriptionEncoderType { get; } = new("description_encoder_type") { DefaultValue = EncoderType.UTF8 }; public static TableColumn<ChannelRow, EncoderType> DescriptionEncoderType { get; } = new("description_encoder_type") { DefaultValue = EncoderType.UTF8 };
public static TableColumn<PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png }; public static TableColumn<ChannelRow, PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png };
public static TableColumn<byte[]> Picture { get; } = new("picture"); public static TableColumn<ChannelRow, byte[]> Picture { get; } = new("picture");
public static TableColumn<EncoderType[]> EncoderTypes { get; } = new("encoder_types") { DefaultValue = new [] public static TableColumn<ChannelRow, EncoderType[]> EncoderTypes { get; } = new("encoder_types") { DefaultValue = new []
{ {
EncoderType.UTF8, EncoderType.UTF16, EncoderType.UTF8, EncoderType.UTF16,
EncoderType.UTF32, EncoderType.ASCII, EncoderType.UTF32, EncoderType.ASCII,
EncoderType.Latin1, EncoderType.BigEndianUnicode EncoderType.Latin1, EncoderType.BigEndianUnicode
} }; } };
public static TableColumn<long[]> Profiles { get; } = new("profiles") { DefaultValue = Array.Empty<long>() }; public static TableColumn<ChannelRow, long[]> Profiles { get; } = new("profiles") { DefaultValue = Array.Empty<long>() };
} }
[TableRow(typeof(Channels))] [TableRow(typeof(Channels))]

View File

@ -6,18 +6,18 @@ namespace LuskiServer.Classes.TableDef;
public static class Files public static class Files
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<FileRow, long> ID { get; } = new("id", true);
public static TableColumn<long> Owner { get; } = new("owner"); public static TableColumn<FileRow, long> Owner { get; } = new("owner");
public static TableColumn<bool> Public { get; } = new("public_download"); public static TableColumn<FileRow, bool> Public { get; } = new("public_download");
public static TableColumn<long[]> AllowedChannels { get; } = new("channels"); public static TableColumn<FileRow, long[]> AllowedChannels { get; } = new("channels");
public static TableColumn<long> Size { get; } = new("size"); public static TableColumn<FileRow, long> Size { get; } = new("size");
public static TableColumn<byte[]> Name { get; } = new("name"); public static TableColumn<FileRow, byte[]> Name { get; } = new("name");
public static TableColumn<byte[]> Hash { get; } = new("hash"); public static TableColumn<FileRow, byte[]> Hash { get; } = new("hash");
public static TableColumn<byte[]> Data { get; } = new("data"); public static TableColumn<FileRow, byte[]> Data { get; } = new("data");
public static TableColumn<long> EncryptionKey { get; } = new("encryption_key"); public static TableColumn<FileRow, long> EncryptionKey { get; } = new("encryption_key");
public static TableColumn<EncoderType> EncoderType { get; } = new("encoder_type"); public static TableColumn<FileRow, EncoderType> EncoderType { get; } = new("encoder_type");
public static TableColumn<long> NameEncryptionKey { get; } = new("name_encryption_key"); public static TableColumn<FileRow, long> NameEncryptionKey { get; } = new("name_encryption_key");
public static TableColumn<EncoderType> NameEncoderType { get; } = new("name_encoder_type"); public static TableColumn<FileRow, EncoderType> NameEncoderType { get; } = new("name_encoder_type");
} }
[TableRow(typeof(Files))] [TableRow(typeof(Files))]

View File

@ -6,10 +6,10 @@ namespace LuskiServer.Classes.TableDef;
public static class Keys public static class Keys
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<KeyRow, long> ID { get; } = new("id", true);
public static TableColumn<long> Owner { get; } = new("owner"); public static TableColumn<KeyRow, long> Owner { get; } = new("owner");
public static TableColumn<EncryptionType> EncryptionType { get; } = new("encryption_type"); public static TableColumn<KeyRow, EncryptionType> EncryptionType { get; } = new("encryption_type");
public static TableColumn<byte[]> KeyData { get; } = new("key_data"); public static TableColumn<KeyRow, byte[]> KeyData { get; } = new("key_data");
} }
[TableRow(typeof(Keys))] [TableRow(typeof(Keys))]

View File

@ -6,9 +6,9 @@ namespace LuskiServer.Classes.TableDef;
public static class Logs public static class Logs
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<LogRow, long> ID { get; } = new("id", true);
public static TableColumn<LogType> Type { get; } = new("type"); public static TableColumn<LogRow, LogType> Type { get; } = new("type");
public static TableColumn<string> Message { get; } = new("message"); public static TableColumn<LogRow, string> Message { get; } = new("message");
} }
[TableRow(typeof(Logs))] [TableRow(typeof(Logs))]

View File

@ -6,15 +6,15 @@ namespace LuskiServer.Classes.TableDef;
public static class Messages public static class Messages
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<MessageRow, long> ID { get; } = new("id", true);
public static TableColumn<long> ChannelID { get; } = new("channel_id", true); public static TableColumn<MessageRow, long> ChannelID { get; } = new("channel_id", true);
public static TableColumn<long> AuthorID { get; } = new("author_id"); public static TableColumn<MessageRow, long> AuthorID { get; } = new("author_id");
public static TableColumn<byte[]> Context { get; } = new("context"); public static TableColumn<MessageRow, byte[]> Context { get; } = new("context");
public static TableColumn<long> EncryptionKey { get; } = new("encryption_key"); public static TableColumn<MessageRow, long> EncryptionKey { get; } = new("encryption_key");
public static TableColumn<EncoderType> EncoderType { get; } = new("encoder_type"); public static TableColumn<MessageRow, EncoderType> EncoderType { get; } = new("encoder_type");
public static TableColumn<long[]> Files { get; } = new("files"); public static TableColumn<MessageRow, long[]> Files { get; } = new("files");
public static TableColumn<bool> IsChannelProfile { get; } = new("is_channel_profile") { DefaultValue = false }; public static TableColumn<MessageRow, bool> IsChannelProfile { get; } = new("is_channel_profile") { DefaultValue = false };
public static TableColumn<long> ReplyTo { get; } = new("reply_to"); public static TableColumn<MessageRow, long> ReplyTo { get; } = new("reply_to");
} }
[TableRow(typeof(Messages))] [TableRow(typeof(Messages))]

View File

@ -7,14 +7,14 @@ namespace LuskiServer.Classes.TableDef;
public static class Roles public static class Roles
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<RoleRow, long> ID { get; } = new("id", true);
public static TableColumn<string> Name { get; } = new("name"); public static TableColumn<RoleRow, string> Name { get; } = new("name");
public static TableColumn<string> DisplayName { get; } = new("display_name") {DefaultValue = string.Empty}; public static TableColumn<RoleRow, string> DisplayName { get; } = new("display_name") {DefaultValue = string.Empty};
public static TableColumn<int> Index { get; } = new("index") {DefaultValue = 0 }; public static TableColumn<RoleRow, int> Index { get; } = new("index") {DefaultValue = 0 };
public static TableColumn<byte[]> Color { get; } = new("color") {DefaultValue = new byte[]{255,255,255,255}}; public static TableColumn<RoleRow, byte[]> Color { get; } = new("color") {DefaultValue = new byte[]{255,255,255,255}};
public static TableColumn<string> Description { get; } = new("description"); public static TableColumn<RoleRow, string> Description { get; } = new("description");
public static TableColumn<ServerPermission> ServerPermissions { get; } = new("server_perms"); public static TableColumn<RoleRow, ServerPermission> ServerPermissions { get; } = new("server_perms");
public static TableColumn<long[]> MembersList { get; } = new("members_list") {DefaultValue = Array.Empty<long>()}; public static TableColumn<RoleRow, long[]> MembersList { get; } = new("members_list") {DefaultValue = Array.Empty<long>()};
} }
[TableRow(typeof(Roles))] [TableRow(typeof(Roles))]

View File

@ -9,12 +9,12 @@ namespace LuskiServer.Classes.TableDef;
public static class Server public static class Server
{ {
public static TableColumn<long> ID { get; } = new("id", true) { DefaultValue = 0 }; public static TableColumn<ServerRow, long> ID { get; } = new("id", true) { DefaultValue = 0 };
public static TableColumn<PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png }; public static TableColumn<ServerRow, PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png };
public static TableColumn<byte[]> Picture { get; } = new("picture") { DefaultValue = Array.Empty<byte>() }; public static TableColumn<ServerRow, byte[]> Picture { get; } = new("picture") { DefaultValue = Array.Empty<byte>() };
public static TableColumn<string> Name { get; } = new("name") { DefaultValue = "Luski Server" }; public static TableColumn<ServerRow, string> Name { get; } = new("name") { DefaultValue = "Luski Server" };
public static TableColumn<string> Description { get; } = new("description") { DefaultValue = "description" }; public static TableColumn<ServerRow, string> Description { get; } = new("description") { DefaultValue = "description" };
public static TableColumn<long> Owner { get; } = new("owner") { DefaultValue = -1 }; public static TableColumn<ServerRow, long> Owner { get; } = new("owner") { DefaultValue = -1 };
} }
[TableRow(typeof(Server))] [TableRow(typeof(Server))]

View File

@ -6,10 +6,10 @@ namespace LuskiServer.Classes.TableDef;
public static class ServerRoleOverrides public static class ServerRoleOverrides
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<ServerRoleOverrideRow, long> ID { get; } = new("id", true);
public static TableColumn<long> RoleID { get; } = new("role_id"); public static TableColumn<ServerRoleOverrideRow, long> RoleID { get; } = new("role_id");
public static TableColumn<ServerPermission> BadPermissions { get; } = new("bad_permissions"); public static TableColumn<ServerRoleOverrideRow, ServerPermission> BadPermissions { get; } = new("bad_permissions");
public static TableColumn<ServerPermission> GoodPermissions { get; } = new("good_permissions"); public static TableColumn<ServerRoleOverrideRow, ServerPermission> GoodPermissions { get; } = new("good_permissions");
} }
[TableRow(typeof(ServerRoleOverrides))] [TableRow(typeof(ServerRoleOverrides))]

View File

@ -5,11 +5,11 @@ namespace LuskiServer.Classes.TableDef;
public static class SessionTokens public static class SessionTokens
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<SessionTokenRow, long> ID { get; } = new("id", true);
public static TableColumn<long> AccountID { get; } = new("account_id"); public static TableColumn<SessionTokenRow, long> AccountID { get; } = new("account_id");
public static TableColumn<string> Token { get; } = new("token"); public static TableColumn<SessionTokenRow, string> Token { get; } = new("token");
public static TableColumn<byte[]> AddressFilter { get; } = new("address_filter"); public static TableColumn<SessionTokenRow, byte[]> AddressFilter { get; } = new("address_filter");
public static TableColumn<DateTime> TimeFilter { get; } = new("date_filter"); public static TableColumn<SessionTokenRow, DateTime> TimeFilter { get; } = new("date_filter");
} }
[TableRow(typeof(SessionTokens))] [TableRow(typeof(SessionTokens))]

View File

@ -7,16 +7,13 @@ namespace LuskiServer.Classes.TableDef;
public static class Sessions public static class Sessions
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<SessionsRow, long> ID { get; } = new("id", true);
public static TableColumn<long> User { get; } = new("userid") public static TableColumn<SessionsRow, long> User { get; } = new("userid");
{ForeignKeys = new IForeignKey[]{ new ForeignKey(){Table = Tables.Users, Column = Users.ID}}}; public static TableColumn<SessionsRow, string> WSSTCP { get; } = new("wsstcp");
public static TableColumn<string> WSSTCP { get; } = new("wsstcp"); public static TableColumn<SessionsRow, string> Token { get; } = new("token");
public static TableColumn<string> Token { get; } = new("token"); public static TableColumn<SessionsRow, string> LoginToken { get; } = new("login_token");
public static TableColumn<string> LoginToken { get; } = new("login_token"); public static TableColumn<SessionsRow, long> SessionKey { get; } = new("session_key");
public static TableColumn<long> SessionKey { get; } = new("session_key") public static TableColumn<SessionsRow, long> StorageID { get; } = new("storage_id");
{ForeignKeys = new IForeignKey[]{ new ForeignKey(){Table = Tables.Keys, Column = Keys.ID, OnDelete = ConstraintAction.Cascade}}};
public static TableColumn<long> StorageID { get; } = new("storage_id");
} }
[TableRow(typeof(Sessions))] [TableRow(typeof(Sessions))]

View File

@ -5,11 +5,11 @@ namespace LuskiServer.Classes.TableDef;
public static class Storage public static class Storage
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<StorageRow, long> ID { get; } = new("id", true);
public static TableColumn<long> AccountID { get; } = new("account_id"); public static TableColumn<StorageRow, long> AccountID { get; } = new("account_id");
public static TableColumn<byte[][]> Data { get; } = new("data"); public static TableColumn<StorageRow, byte[][]> Data { get; } = new("data");
public static TableColumn<byte[]> Password { get; } = new("password"); public static TableColumn<StorageRow, byte[]> Password { get; } = new("password");
public static TableColumn<long> OffileKey { get; } = new("offline_key"); public static TableColumn<StorageRow, long> OffileKey { get; } = new("offline_key");
} }
[TableRow(typeof(Storage))] [TableRow(typeof(Storage))]

View File

@ -7,10 +7,10 @@ namespace LuskiServer.Classes.TableDef;
public static class UserRoleOverrides public static class UserRoleOverrides
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<UserRoleOverrideRow, long> ID { get; } = new("id", true);
public static TableColumn<long> UserID { get; } = new("user_id"); public static TableColumn<UserRoleOverrideRow, long> UserID { get; } = new("user_id");
public static TableColumn<ServerPermission> BadPermissions { get; } = new("bad_permissions"); public static TableColumn<UserRoleOverrideRow, ServerPermission> BadPermissions { get; } = new("bad_permissions");
public static TableColumn<ServerPermission> GoodPermissions { get; } = new("good_permissions"); public static TableColumn<UserRoleOverrideRow, ServerPermission> GoodPermissions { get; } = new("good_permissions");
} }
[TableRow(typeof(UserRoleOverrides))] [TableRow(typeof(UserRoleOverrides))]

View File

@ -2,6 +2,7 @@ using Luski.Shared.PublicServers.V1.Enums;
using LuskiServer.Enums; using LuskiServer.Enums;
using ServerDatabase; using ServerDatabase;
using ServerDatabase.SourceGenerator; using ServerDatabase.SourceGenerator;
using ServerDatabase.Utils;
using bob = Luski.Shared.PublicServers.V1.Enums.PictureType; using bob = Luski.Shared.PublicServers.V1.Enums.PictureType;
@ -9,16 +10,16 @@ namespace LuskiServer.Classes.TableDef;
public class Users public class Users
{ {
public static TableColumn<long> ID { get; } = new("id", true); public static TableColumn<UserRow, long> ID { get; } = new("id", true);
public static TableColumn<string> DisplayName { get; } = new("displayname"); public static TableColumn<UserRow, string> DisplayName { get; } = new("displayname");
public static TableColumn<long> SelectedChannel { get; } = new("selected_channel"); public static TableColumn<UserRow, long> SelectedChannel { get; } = new("selected_channel");
public static TableColumn<UserStatus> Status { get; } = new("status") { DefaultValue = UserStatus.Offline }; public static TableColumn<UserRow, UserStatus> Status { get; } = new("status") { DefaultValue = UserStatus.Offline };
public static TableColumn<PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png }; public static TableColumn<UserRow, PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png };
public static TableColumn<byte[]> Picture { get; } = new("picture"); public static TableColumn<UserRow, byte[]> Picture { get; } = new("picture");
public static TableColumn<long[]> Roles { get; } = new("roles"); public static TableColumn<UserRow, long[]> Roles { get; } = new("roles");
public static TableColumn<byte[]> Username { get; } = new("username"); public static TableColumn<UserRow, byte[]> Username { get; } = new("username");
public static TableColumn<byte[]> Password { get; } = new("password"); public static TableColumn<UserRow, byte[]> Password { get; } = new("password");
public static TableColumn<byte[]> Salt { get; } = new("salt"); public static TableColumn<UserRow, byte[]> Salt { get; } = new("salt");
} }
[TableRow(typeof(Users))] [TableRow(typeof(Users))]

View File

@ -220,8 +220,7 @@ public class KeysController : ControllerBase
Keys.Owner.CreateParameter(ID), Keys.Owner.CreateParameter(ID),
Keys.EncryptionType.CreateParameter(keyreq.EncryptionType), Keys.EncryptionType.CreateParameter(keyreq.EncryptionType),
Keys.KeyData.CreateParameter(Convert.FromBase64String(keyreq.Data))); Keys.KeyData.CreateParameter(Convert.FromBase64String(keyreq.Data)));
Tables.Storage.Update(Storage.ID, StorageID, Tables.Storage.CreateCommand().WithFilter(Storage.ID, StorageID).WithValue(Storage.OffileKey, sf.ID);
Storage.OffileKey.CreateParameter(sf.ID));
return StatusCode(202); return StatusCode(202);
} }
catch (Exception ex) catch (Exception ex)

View File

@ -29,7 +29,7 @@ public class OfflineDataController : ControllerBase
{ {
bbb.Add(Convert.ToBase64String(blob)); bbb.Add(Convert.ToBase64String(blob));
} }
Tables.Storage.Update(Storage.ID, SID, Storage.Data.CreateParameter(Array.Empty<byte[]>())); Tables.Storage.CreateCommand().WithFilter(Storage.ID, SID).WithValue(Storage.Data, Array.Empty<byte[]>()).Update();
return this.ResponseToResult(new OfflineDataBlobSTC() return this.ResponseToResult(new OfflineDataBlobSTC()
{ {
Data = bbb.ToArray() Data = bbb.ToArray()
@ -68,7 +68,7 @@ public class OfflineDataController : ControllerBase
{ {
update = true; update = true;
} }
Tables.Sessions.Update(Sessions.ID, SSID, Sessions.StorageID.CreateParameter(SID)); Tables.Sessions.CreateCommand().WithFilter(Sessions.ID, SID).WithValue(Sessions.StorageID, SID).Update();
} }
return this.ResponseToResult(new StorageInfoSTC() return this.ResponseToResult(new StorageInfoSTC()
{ {
@ -102,7 +102,7 @@ public class OfflineDataController : ControllerBase
if (!Tables.Storage.TryReadRow(out StorageRow row, Storage.ID.CreateParameter(SID))) if (!Tables.Storage.TryReadRow(out StorageRow row, Storage.ID.CreateParameter(SID)))
return this.ResponseCodeToResult(ErrorCode.InvalidHeader); return this.ResponseCodeToResult(ErrorCode.InvalidHeader);
if (row.AccountID != UID) return this.ResponseCodeToResult(ErrorCode.Forbidden); if (row.AccountID != UID) return this.ResponseCodeToResult(ErrorCode.Forbidden);
Tables.Storage.Update(Storage.ID, SID, Storage.Password.CreateParameter(Convert.FromBase64String(si.Password))); Tables.Storage.CreateCommand().WithFilter(Storage.ID, SID).WithValue(Storage.Password, Convert.FromBase64String(si.Password)).Update();
return this.ResponseToResult(new StorageInfoSTC() return this.ResponseToResult(new StorageInfoSTC()
{ {
@ -132,7 +132,7 @@ public class OfflineDataController : ControllerBase
Storage.AccountID.CreateParameter(UID), Storage.AccountID.CreateParameter(UID),
Storage.Data.CreateParameter(Array.Empty<byte[]>()), Storage.Data.CreateParameter(Array.Empty<byte[]>()),
Storage.OffileKey.CreateParameter(0)); Storage.OffileKey.CreateParameter(0));
Tables.Sessions.Update(Sessions.StorageID, sf.ID, Sessions.ID.CreateParameter(SSID)); Tables.Sessions.CreateCommand().WithFilter(Sessions.ID, sf.ID).WithValue(Sessions.ID, SSID).Update();
return this.ResponseToResult(new StorageInfoSTC() return this.ResponseToResult(new StorageInfoSTC()
{ {

View File

@ -75,7 +75,7 @@ public class SocketAccountController : Controller
LuskiFunctions.Snowflake id = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch); LuskiFunctions.Snowflake id = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch);
long kid = id.ID; long kid = id.ID;
Tables.Users.Update(Users.ID, ID, Users.Status.CreateParameter(UserStatus.Invisible)); Tables.Users.CreateCommand().WithFilter(Users.ID, ID).WithValue(Users.Status, UserStatus.Invisible).Update();
Tables.Keys.Insert( Tables.Keys.Insert(
Keys.ID.CreateParameter(kid), Keys.ID.CreateParameter(kid),
Keys.EncryptionType.CreateParameter(EncryptionType.RSA), Keys.EncryptionType.CreateParameter(EncryptionType.RSA),
@ -142,7 +142,7 @@ public class SocketAccountController : Controller
Tables.SessionTokens.DeleteRow(SessionTokens.Token.CreateParameter(tok)); Tables.SessionTokens.DeleteRow(SessionTokens.Token.CreateParameter(tok));
LuskiFunctions.Snowflake id = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch); LuskiFunctions.Snowflake id = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch);
long kid = id.ID; long kid = id.ID;
Tables.Users.Update(Users.ID, ID, Users.Status.CreateParameter(UserStatus.Invisible)); Tables.Users.CreateCommand().WithFilter(Users.ID, ID).WithValue(Users.Status, UserStatus.Invisible).Update();
Console.WriteLine("C"); Console.WriteLine("C");
Tables.Keys.Insert( Tables.Keys.Insert(
Keys.ID.CreateParameter(kid), Keys.ID.CreateParameter(kid),
@ -230,7 +230,7 @@ public class SocketAccountController : Controller
if (Tables.Server.Read(Server.Owner, Server.ID.CreateParameter(0)) == -1) if (Tables.Server.Read(Server.Owner, Server.ID.CreateParameter(0)) == -1)
{ {
id = new(0); id = new(0);
Tables.Server.Update(Server.ID, 0, Server.Owner.CreateParameter(id.ID)); Tables.Server.CreateCommand().WithValue(Server.Owner, id.ID).Update();
} }
byte[] ID = Encoding.UTF8.GetBytes(id.ID.ToString()); byte[] ID = Encoding.UTF8.GetBytes(id.ID.ToString());
byte[] Timestamp = Encoding.UTF8.GetBytes(DateTime.UtcNow.ToString()); byte[] Timestamp = Encoding.UTF8.GetBytes(DateTime.UtcNow.ToString());
@ -254,7 +254,7 @@ public class SocketAccountController : Controller
Users.Salt.CreateParameter(salt)); Users.Salt.CreateParameter(salt));
List<long> old = Tables.Roles.Read(Roles.MembersList, Roles.ID.CreateParameter(0)).ToList(); List<long> old = Tables.Roles.Read(Roles.MembersList, Roles.ID.CreateParameter(0)).ToList();
old.Add(uid); old.Add(uid);
Tables.Roles.Update(Roles.ID, 0, Roles.MembersList.CreateParameter(old.ToArray())); Tables.Roles.CreateCommand().WithFilter(Roles.ID, 0).WithValue(Roles.MembersList,old.ToArray()).Update();
Console.WriteLine("A"); Console.WriteLine("A");
Tables.Keys.Insert( Tables.Keys.Insert(
Keys.ID.CreateParameter(kid), Keys.ID.CreateParameter(kid),

View File

@ -64,21 +64,23 @@ public class SocketCategoryController : ControllerBase
Categories.TitleEncoderType.CreateParameter(ChanReq.TitleEncoderType), Categories.TitleEncoderType.CreateParameter(ChanReq.TitleEncoderType),
Categories.DescriptionEncoderType.CreateParameter(ChanReq.DescriptionEncoderType)); Categories.DescriptionEncoderType.CreateParameter(ChanReq.DescriptionEncoderType));
CategoryRow chan = Tables.Categories.ReadRow(Categories.ID.CreateParameter(chanSnowflake.ID)); CategoryRow chan = Tables.Categories.ReadRow(Categories.ID.CreateParameter(chanSnowflake.ID));
if (opt.HasPermission(ServerPermission.ViewCategories)) long[] ic = Array.Empty<long>();
long[] c = Array.Empty<long>();
if (!opt.HasPermission(ServerPermission.ViewCategories))
{ {
chan.InnerCategories = Array.Empty<long>(); ic = Tables.Categories.ReadColumn(Categories.ID, Categories.Parent.CreateParameter(chanSnowflake.ID));
} }
if (opt.HasPermission(ServerPermission.ViewChannels)) if (!opt.HasPermission(ServerPermission.ViewChannels))
{ {
chan.Channels = Array.Empty<long>(); c = LuskiFunctions.GetCategoryChannels(chanSnowflake.ID, ID);
} }
return this.ResponseToResult(new CategorySTC() return this.ResponseToResult(new CategorySTC()
{ {
Name = Convert.ToBase64String(chan.Name), Name = Convert.ToBase64String(chan.Name),
Description = Convert.ToBase64String(chan.Description), Description = Convert.ToBase64String(chan.Description),
ID = chanSnowflake.ID, ID = chanSnowflake.ID,
Channels = chan.Channels, Channels = c,
InnerCategories = chan.InnerCategories, InnerCategories = ic,
Parent = chan.Parent, Parent = chan.Parent,
TitleEncryptionKey = chan.TitleEncryptionKey, TitleEncryptionKey = chan.TitleEncryptionKey,
DescriptionEncryptionKey = chan.DescriptionEncryptionKey, DescriptionEncryptionKey = chan.DescriptionEncryptionKey,
@ -129,21 +131,28 @@ public class SocketCategoryController : ControllerBase
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc; if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
if (!LuskiFunctions.HasAccessToCategory(ID, Channel, out ServerPermission opt, ServerPermission.ViewCategories | ServerPermission.ViewChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden); if (!LuskiFunctions.HasAccessToCategory(ID, Channel, out ServerPermission opt, ServerPermission.ViewCategories | ServerPermission.ViewChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
CategoryRow chan = Tables.Categories.ReadRow(Categories.ID.CreateParameter(Channel)); CategoryRow chan = Tables.Categories.ReadRow(Categories.ID.CreateParameter(Channel));
if (opt.HasPermission(ServerPermission.ViewCategories)) List<long> ic = new();
long[] c = Array.Empty<long>();
if (!opt.HasPermission(ServerPermission.ViewCategories))
{ {
chan.InnerCategories = Array.Empty<long>(); ic = Tables.Categories.ReadColumn(Categories.ID, Categories.Parent.CreateParameter(Channel)).ToList();
} }
if (opt.HasPermission(ServerPermission.ViewChannels)) if (!opt.HasPermission(ServerPermission.ViewChannels))
{ {
chan.Channels = Array.Empty<long>(); c = LuskiFunctions.GetCategoryChannels(Channel, ID);
}
foreach (long cc in ic)
{
if (!LuskiFunctions.HasAccessToChannel(ID, cc)) ic.Remove(cc);
} }
return this.ResponseToResult(new CategorySTC() return this.ResponseToResult(new CategorySTC()
{ {
Name = Convert.ToBase64String(chan.Name), Name = Convert.ToBase64String(chan.Name),
Description = Convert.ToBase64String(chan.Description), Description = Convert.ToBase64String(chan.Description),
ID = Channel, ID = Channel,
Channels = chan.Channels, Channels = c,
InnerCategories = chan.InnerCategories, InnerCategories = ic.ToArray(),
Parent = chan.Parent, Parent = chan.Parent,
TitleEncryptionKey = chan.TitleEncryptionKey, TitleEncryptionKey = chan.TitleEncryptionKey,
DescriptionEncryptionKey = chan.DescriptionEncryptionKey, DescriptionEncryptionKey = chan.DescriptionEncryptionKey,

View File

@ -70,10 +70,6 @@ public class SocketChannelController : ControllerBase
Channels.Picture.CreateParameter(Array.Empty<byte>()), Channels.Picture.CreateParameter(Array.Empty<byte>()),
Channels.EncoderTypes.CreateParameter(ChanReq.EncoderTypes), Channels.EncoderTypes.CreateParameter(ChanReq.EncoderTypes),
Channels.Profiles.CreateParameter(Array.Empty<long>())); Channels.Profiles.CreateParameter(Array.Empty<long>()));
List<long> lll = Tables.Categories.Read(Categories.Channels, Categories.ID.CreateParameter(ChanReq.Parent))
.ToList();
lll.Add(chanSnowflake.ID);
Tables.Categories.Update(Categories.ID, ChanReq.Parent, Categories.Channels.CreateParameter(lll.ToArray()));
ChannelRow chan = Tables.Channels.ReadRow(Channels.ID.CreateParameter(chanSnowflake.ID)); ChannelRow chan = Tables.Channels.ReadRow(Channels.ID.CreateParameter(chanSnowflake.ID));
return this.ResponseToResult(new ChannelSTC() return this.ResponseToResult(new ChannelSTC()

View File

@ -51,13 +51,15 @@ public class SocketFileController : ControllerBase
{ {
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc; if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
if (!Tables.Files.TryRead(Files.Owner, out long raw, Files.ID.CreateParameter(File_id)) || raw != ID) return this.ResponseCodeToResult(ErrorCode.Forbidden); if (!Tables.Files.TryRead(Files.Owner, out long raw, Files.ID.CreateParameter(File_id)) || raw != ID) return this.ResponseCodeToResult(ErrorCode.Forbidden);
Tables.Files.Update(Files.ID, File_id, Tables.Files.CreateCommand()
Files.Data.CreateParameter(Array.Empty<byte>()), .WithFilter(Files.ID, File_id)
Files.NameEncoderType.CreateParameter(EncoderType.UTF8), .WithValue(Files.Data, Array.Empty<byte>())
Files.NameEncryptionKey.CreateParameter(0), .WithValue(Files.NameEncoderType, EncoderType.UTF8)
Files.Name.CreateParameter(Encoding.UTF8.GetBytes("Deleted File")), .WithValue(Files.NameEncryptionKey, 0)
Files.Size.CreateParameter(0), .WithValue(Files.Name, Encoding.UTF8.GetBytes("Deleted File"))
Files.EncryptionKey.CreateParameter(0)); .WithValue(Files.Size, 0)
.WithValue(Files.EncryptionKey, 0).Update();
return StatusCode(StatusCodes.Status202Accepted); return StatusCode(StatusCodes.Status202Accepted);
} }
catch (Exception e) catch (Exception e)

View File

@ -14,7 +14,7 @@ public class SocketOverridesController : ControllerBase
{ {
[HttpGet] [HttpGet]
[Route(LuskiFunctions.Info.Routes.Default.Base + "/UserOverride/{id:long}")] [Route(LuskiFunctions.Info.Routes.Default.Base + "/UserOverride/{id:long}")]
public IActionResult GetUserOverride([FromQuery(Name = "id")]long id) public IActionResult GetUserOverride([FromRoute(Name = "id")]long id)
{ {
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc; if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
if (!Tables.UserRoleOverrides.TryReadRow(out UserRoleOverrideRow row, UserRoleOverrides.ID.CreateParameter(id))) return this.ShowError(ErrorCode.Forbidden, "Override does not exist"); if (!Tables.UserRoleOverrides.TryReadRow(out UserRoleOverrideRow row, UserRoleOverrides.ID.CreateParameter(id))) return this.ShowError(ErrorCode.Forbidden, "Override does not exist");
@ -29,7 +29,7 @@ public class SocketOverridesController : ControllerBase
[HttpGet] [HttpGet]
[Route(LuskiFunctions.Info.Routes.Default.Base + "/RoleOverride/{id:long}")] [Route(LuskiFunctions.Info.Routes.Default.Base + "/RoleOverride/{id:long}")]
public IActionResult GetRoleOverride([FromQuery(Name = "id")]long id) public IActionResult GetRoleOverride([FromRoute(Name = "id")]long id)
{ {
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc; if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
if (!Tables.ServerRoleOverrides.TryReadRow(out ServerRoleOverrideRow? row, ServerRoleOverrides.ID.CreateParameter(id))) return this.ShowError(ErrorCode.Forbidden, "Override does not exist"); if (!Tables.ServerRoleOverrides.TryReadRow(out ServerRoleOverrideRow? row, ServerRoleOverrides.ID.CreateParameter(id))) return this.ShowError(ErrorCode.Forbidden, "Override does not exist");

View File

@ -16,7 +16,7 @@ public class SocketRoleController : ControllerBase
public IActionResult Get([FromQuery(Name = "id")]long id) public IActionResult Get([FromQuery(Name = "id")]long id)
{ {
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc; if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
if (!Tables.Roles.TryReadRow(out RoleRow row, Roles.ID.CreateParameter(id))) return this.ShowError(ErrorCode.Forbidden, "User does not exist"); if (!Tables.Roles.TryReadRow(out RoleRow row, Roles.ID.CreateParameter(id))) return this.ShowError(ErrorCode.Forbidden, "Role does not exist");
return this.ResponseToResult(new RoleSTC() return this.ResponseToResult(new RoleSTC()
{ {
ID = row.ID, ID = row.ID,
@ -29,4 +29,32 @@ public class SocketRoleController : ControllerBase
Color = Convert.ToHexString(row.Color) Color = Convert.ToHexString(row.Color)
}); });
} }
[HttpGet]
[Route(LuskiFunctions.Info.Routes.Default.Base + "/GetAll")]
public IActionResult GetAll()
{
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
RoleRow[] rows = Tables.Roles.ReadRows();
List<RoleSTC> r = new();
for (int i = 0; i < rows.Length; i++)
{
r.Add(new()
{
ID = rows[i].ID,
ServerPermissions = rows[i].ServerPermissions,
Description = rows[i].Description,
DisplayName = rows[i].DisplayName,
Index = rows[i].Index,
Name = rows[i].Name,
Members = rows[i].MembersList,
Color = Convert.ToHexString(rows[i].Color)
});
}
return this.ResponseToResult(new RolesSTC()
{
Roles = r.ToArray()
});
}
} }

View File

@ -101,7 +101,7 @@ public class SocketUserProfileController : ControllerBase
// { "after", (int)NewStatus }, // { "after", (int)NewStatus },
// { "type", (int)DataType.Status_Update } // { "type", (int)DataType.Status_Update }
// }; // };
Tables.Users.Update(Users.ID, ID, Users.Status.CreateParameter(NewStatus)); Tables.Users.CreateCommand().WithFilter(Users.ID, ID).WithValue(Users.Status, NewStatus).Update();
if (NewStatus == UserStatus.Invisible) NewStatus = UserStatus.Offline; if (NewStatus == UserStatus.Invisible) NewStatus = UserStatus.Offline;
// WSS.SendData(SendType.All, @out); // WSS.SendData(SendType.All, @out);
} }

View File

@ -59,24 +59,22 @@ public static class Matrix
Tables.ChannelProfiles.DeleteRow(ChannelProfiles.ID.CreateParameter(i)); Tables.ChannelProfiles.DeleteRow(ChannelProfiles.ID.CreateParameter(i));
} }
Tables.Channels.Update(Channels.ID, Channel, Tables.Channels.CreateCommand()
//Tables.Channels.Insert( .WithFilter(Channels.ID, Channel)
Channels.ID.CreateParameter(Channel), .WithValue(Channels.Parent, 0)
Channels.Parent.CreateParameter(0), .WithValue(Channels.Type, ChannelType.TextAndVoice)
Channels.Type.CreateParameter(ChannelType.TextAndVoice), .WithValue(Channels.Description, export.RoomTopic.ToDB(Encoder, Encryption))
Channels.Description.CreateParameter(export.RoomTopic.ToDB(Encoder, Encryption)), .WithValue(Channels.Name, export.RoomName.ToDB(Encoder, Encryption))
Channels.Name.CreateParameter(export.RoomName.ToDB(Encoder, Encryption)), .WithValue(Channels.RoleOverrides, Array.Empty<long>())
Channels.RoleOverrides.CreateParameter(Array.Empty<long>()), .WithValue(Channels.UserOverrides, Array.Empty<long>())
Channels.UserOverrides.CreateParameter(Array.Empty<long>()), .WithValue(Channels.Epoch, epoch)
Channels.Epoch.CreateParameter(epoch), .WithValue(Channels.TitleEncryptionKey, Encryption)
Channels.TitleEncryptionKey.CreateParameter(Encryption), .WithValue(Channels.DescriptionEncryptionKey, Encryption)
Channels.DescriptionEncryptionKey.CreateParameter(Encryption), .WithValue(Channels.EncryptionKeys, new long[] { Encryption })
Channels.EncryptionKeys.CreateParameter(new long[] { Encryption }), .WithValue(Channels.TitleEncoderType, Encoder)
Channels.TitleEncoderType.CreateParameter(Encoder), .WithValue(Channels.DescriptionEncoderType, Encoder)
Channels.DescriptionEncoderType.CreateParameter(Encoder), .WithValue(Channels.EncoderTypes, new[] { Encoder }).Update();
//Channels.PictureType.CreateParameter(PictureType.none),
//Channels.Picture.CreateParameter(Array.Empty<byte>()),
Channels.EncoderTypes.CreateParameter(new[] { Encoder }));
Dictionary<string, long> Events = new(); Dictionary<string, long> Events = new();
foreach (Message msg in export.Messages) foreach (Message msg in export.Messages)
@ -275,7 +273,7 @@ public static class Matrix
} }
} }
Tables.Channels.Update(Channels.ID, Channel, Channels.Profiles.CreateParameter(IdConverter.Values.ToArray())); Tables.Channels.CreateCommand().WithFilter(Channels.ID, Channel).WithValue(Channels.Profiles, IdConverter.Values.ToArray()).Update();
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -5,7 +5,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<IncludeBuildOutput>true</IncludeBuildOutput> <IncludeBuildOutput>true</IncludeBuildOutput>
<FileVersion>1.0.08</FileVersion> <FileVersion>1.0.1.6</FileVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
@ -21,11 +21,13 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="7.0.0" /> <PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="7.0.0" />
<PackageReference Include="Luski.Shared" Version="1.1.0-alpha19" /> <PackageReference Include="Flurl.Http" Version="2.3.2" />
<PackageReference Include="Luski.Shared" Version="1.1.0-alpha21" />
<PackageReference Include="Markdig" Version="0.36.2" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.3" /> <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="ServerDatabase" Version="2.9.9" /> <PackageReference Include="ServerDatabase" Version="3.0.8-alpha02" />
<PackageReference Include="ServerDatabase.SourceGenerator" Version="1.0.2-alpha10" /> <PackageReference Include="ServerDatabase.SourceGenerator" Version="1.0.2-alpha12" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" /> <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageReference Include="websocketsharp.core" Version="1.0.0" /> <PackageReference Include="websocketsharp.core" Version="1.0.0" />

View File

@ -29,6 +29,22 @@ else
tttt.Add(string.Join(";", LuskiFunctions.Config.Addresses)); tttt.Add(string.Join(";", LuskiFunctions.Config.Addresses));
} }
//MatrixChatroomWatcher mcw = new("https://matrix.org", "!EqhzONquTblIjhgyHG:matrix.org", "Luski-Server",
// "syt_amFjb2J0ZWNoLWJvdA_mGvmyCvUOGKZXmMOyvTr_1QRrzv");
//mcw.NewMessageReceived += McwOnNewMessageReceived;
void McwOnNewMessageReceived(dynamic message)
{
Console.WriteLine(message);
}
//await mcw.Start();
//await mcw.SendMessage("Test Message from Luski Server");
args = tttt.ToArray(); args = tttt.ToArray();
Console.WriteLine($"Server starting with starting epoch of {LuskiFunctions.Config.ServerEpoch.ToLocalTime()} and current time of {DateTime.UtcNow.ToLocalTime()}"); Console.WriteLine($"Server starting with starting epoch of {LuskiFunctions.Config.ServerEpoch.ToLocalTime()} and current time of {DateTime.UtcNow.ToLocalTime()}");
LuskiFunctions.Database = new Database(LuskiFunctions.Config.Address, LuskiFunctions.Database = new Database(LuskiFunctions.Config.Address,
@ -38,6 +54,8 @@ LuskiFunctions.Database = new Database(LuskiFunctions.Config.Address,
LuskiFunctions.Config.CustomeName); LuskiFunctions.Config.CustomeName);
Dictionary<string, List<Message>> fff = new(); Dictionary<string, List<Message>> fff = new();
@ -65,8 +83,7 @@ foreach (PropertyInfo prop in typeof(Tables).GetProperties())
LuskiFunctions.Database.RegisterTables(); LuskiFunctions.Database.RegisterTables();
bool d = Tables.Storage.TryReadRow(out StorageRow row, Storage.ID.CreateParameter(534144618594309));
Console.WriteLine(d);
//Tables.Channels.Update(Channels.ID, 0, Channels.PictureType.CreateParameter(PictureType.png), Channels.Picture.CreateParameter(File.ReadAllBytes("/home/jacob/Pictures/Logo.png"))); //Tables.Channels.Update(Channels.ID, 0, Channels.PictureType.CreateParameter(PictureType.png), Channels.Picture.CreateParameter(File.ReadAllBytes("/home/jacob/Pictures/Logo.png")));
/* /*
Dictionary<string, long> AMap = new() Dictionary<string, long> AMap = new()
@ -125,6 +142,47 @@ if (!Tables.Server.TryRead(Server.ID, out _, Server.ID.CreateParameter(0)))
{ {
Tables.Server.Insert(); Tables.Server.Insert();
} }
/*
Tables.Roles.Insert(
Roles.ID.CreateParameter(2),
Roles.Name.CreateParameter("Admins"),
Roles.DisplayName.CreateParameter("Admins"),
Roles.Index.CreateParameter(2),
Roles.Color.CreateParameter(Convert.FromHexString("FF1B1BFF")),
Roles.Description.CreateParameter("Admins for the server"),
Roles.MembersList.CreateParameter(new long[]{0}),
Roles.ServerPermissions.CreateParameter(
ServerPermission.ViewChannels |
ServerPermission.ViewCategories |
ServerPermission.Nickname |
ServerPermission.SendMessages |
ServerPermission.SendFiles |
ServerPermission.ChannelPings |
ServerPermission.ServerPings |
ServerPermission.PingSomeone |
ServerPermission.ReadMessageHistory |
ServerPermission.UseServerCommands |
ServerPermission.JoinVoice |
ServerPermission.SpeakInVoice |
ServerPermission.ViewThis |
ServerPermission.Kick |
ServerPermission.CreateCategories |
ServerPermission.CreateChannels |
ServerPermission.DeleteCategories |
ServerPermission.DeleteChannels |
ServerPermission.EditCategories |
ServerPermission.EditChannels |
ServerPermission.EditCategoryPermissions |
ServerPermission.EditChannelPermissions |
ServerPermission.Invite |
ServerPermission.ManageMessages |
ServerPermission.ManageRoles |
ServerPermission.ViewLogs |
ServerPermission.Ban |
ServerPermission.AddServers)
);*/
//Tables.Server.Update(Server.ID, 0, Server.Picture.CreateParameter(File.ReadAllBytes("/home/jacob/Downloads/XBsECOXDZIXMVIxxMNxRfGRo.png"))); //Tables.Server.Update(Server.ID, 0, Server.Picture.CreateParameter(File.ReadAllBytes("/home/jacob/Downloads/XBsECOXDZIXMVIxxMNxRfGRo.png")));
//Tables.Channels.Update(Channels.ID, 1, Channels.PictureType.CreateParameter(PictureType.png), Channels.Picture.CreateParameter(File.ReadAllBytes("/home/jacob/Downloads/zLqHooejmsmKzuMLneUSvjRH.png"))); //Tables.Channels.Update(Channels.ID, 1, Channels.PictureType.CreateParameter(PictureType.png), Channels.Picture.CreateParameter(File.ReadAllBytes("/home/jacob/Downloads/zLqHooejmsmKzuMLneUSvjRH.png")));
/* /*
@ -282,7 +340,6 @@ if (!Tables.Categories.TryRead(Categories.ID, out _, Categories.ID.CreateParamet
Categories.ID.CreateParameter(0), Categories.ID.CreateParameter(0),
Categories.Name.CreateParameter(Encoding.UTF8.GetBytes("server")), Categories.Name.CreateParameter(Encoding.UTF8.GetBytes("server")),
Categories.Parent.CreateParameter(-1), Categories.Parent.CreateParameter(-1),
Categories.Channels.CreateParameter(new long[]{0}),
Categories.Description.CreateParameter( Categories.Description.CreateParameter(
Encoding.UTF8.GetBytes("The default category for the server. Everybody will see this category.")), Encoding.UTF8.GetBytes("The default category for the server. Everybody will see this category.")),
Categories.RoleOverrides.CreateParameter(Array.Empty<long>()) Categories.RoleOverrides.CreateParameter(Array.Empty<long>())