Server Update
Lots of changes
This commit is contained in:
parent
346ef16530
commit
fae28490cd
@ -10,7 +10,7 @@ public class TokenFilterAttribute : Attribute, IActionFilter
|
|||||||
public void OnActionExecuting(ActionExecutingContext context)
|
public void OnActionExecuting(ActionExecutingContext context)
|
||||||
{
|
{
|
||||||
//token check here
|
//token check here
|
||||||
Console.WriteLine("Token Check");
|
//Console.WriteLine("Token Check");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnActionExecuted(ActionExecutedContext context)
|
public void OnActionExecuted(ActionExecutedContext context)
|
||||||
|
@ -94,79 +94,70 @@ public static class LuskiFunctions
|
|||||||
|
|
||||||
public static long[] GetChannelBroadcastMembers(long Channel)
|
public static long[] GetChannelBroadcastMembers(long Channel)
|
||||||
{
|
{
|
||||||
|
ServerPermission RequiredPerms = ServerPermission.ViewThis | ServerPermission.ReadMessageHistory;
|
||||||
List<long> Members = new();
|
List<long> Members = new();
|
||||||
long[] ChanUserOverides = Tables.Channels.Read(Channels.UserOverrides, Channels.ID.CreateParameter(Channel));
|
|
||||||
long[] ChanRoleOverides = Tables.Channels.Read(Channels.RoleOverrides, Channels.ID.CreateParameter(Channel));
|
|
||||||
Dictionary<long, long> ChanRoleIDOverides = new();
|
|
||||||
foreach (long cro in ChanRoleOverides)
|
|
||||||
{
|
|
||||||
ChanRoleIDOverides.Add(Tables.ServerRoleOverrides.Read(ServerRoleOverrides.RoleID, ServerRoleOverrides.ID.CreateParameter(cro)), cro);
|
|
||||||
}
|
|
||||||
Dictionary<long, long> ChanUserIDOverides = new();
|
|
||||||
foreach (long cro in ChanUserOverides)
|
|
||||||
{
|
|
||||||
ChanUserIDOverides.Add(Tables.UserRoleOverrides.Read(UserRoleOverrides.UserID, UserRoleOverrides.ID.CreateParameter(cro)), cro);
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerPermission req = ServerPermission.ViewThis | ServerPermission.ReadMessageHistory;
|
(long, ServerPermission, ServerPermission)[] ChanUserOverrides = Tables.ChannelUserOverrides.CreateCommand()
|
||||||
|
.WithFilter(ChannelUserOverrides.Channel, Channel)
|
||||||
|
.ReadColumns(ChannelUserOverrides.UserOverride, ChannelUserOverrides.GoodPermissions, ChannelUserOverrides.BadPermissions);
|
||||||
|
(long, ServerPermission, ServerPermission)[] ChanRoleOverrides = Tables.ChannelRoleOverrides.CreateCommand()
|
||||||
|
.WithFilter(ChannelRoleOverrides.Channel, Channel)
|
||||||
|
.ReadColumns(ChannelRoleOverrides.RoleOverride,
|
||||||
|
ChannelRoleOverrides.GoodPermissions, ChannelRoleOverrides.BadPermissions);
|
||||||
|
long owner = Tables.Server.Read(Server.Owner, Server.ID.CreateParameter(0));
|
||||||
|
|
||||||
using NpgsqlConnection dbConnection = LuskiFunctions.Database.CreateConnection();
|
foreach (var User in Tables.Users.ReadColumn(Users.ID))
|
||||||
dbConnection.Open();
|
|
||||||
using NpgsqlCommand cmd = new();
|
|
||||||
cmd.Connection = dbConnection;
|
|
||||||
cmd.CommandText = $"SELECT {Roles.ID.Name} FROM {Tables.Roles.Name};";
|
|
||||||
NpgsqlDataReader reader = cmd.ExecuteReader();
|
|
||||||
while (reader.Read())
|
|
||||||
{
|
{
|
||||||
long rol = reader.GetInt64(0);
|
if (User == owner)
|
||||||
|
{
|
||||||
|
Members.Add(User);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
ServerPermission GoodPerms = ServerPermission.None;
|
ServerPermission GoodPerms = ServerPermission.None;
|
||||||
if (ChanRoleIDOverides.ContainsKey(rol))
|
bool Break = false;
|
||||||
|
foreach ((long, ServerPermission, ServerPermission) ChanUserOverride in ChanUserOverrides)
|
||||||
{
|
{
|
||||||
GoodPerms |= Tables.ServerRoleOverrides.Read(ServerRoleOverrides.GoodPermissions,
|
if (ChanUserOverride.Item1 != User) continue;
|
||||||
ServerRoleOverrides.ID.CreateParameter(ChanRoleIDOverides[rol]));
|
if ((ChanUserOverride.Item3 & RequiredPerms) > ServerPermission.None)
|
||||||
|
|
||||||
|
|
||||||
if (GoodPerms.HasPermission(req))
|
|
||||||
{
|
{
|
||||||
foreach (long m in Tables.Roles.Read(Roles.MembersList, Roles.ID.CreateParameter(rol)))
|
Break = true;
|
||||||
{
|
break;
|
||||||
if (!Members.Contains(m)) Members.Add(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ServerPermission pppp = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(rol));
|
|
||||||
GoodPerms |= pppp;
|
|
||||||
if (GoodPerms.HasPermission(req))
|
|
||||||
{
|
|
||||||
foreach (long m in Tables.Roles.Read(Roles.MembersList, Roles.ID.CreateParameter(rol)))
|
|
||||||
{
|
|
||||||
if (!Members.Contains(m)) Members.Add(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (long o in ChanUserOverides)
|
GoodPerms |= ChanUserOverride.Item2;
|
||||||
{
|
}
|
||||||
ServerPermission GoodPerms = ServerPermission.None;
|
if (Break) continue;
|
||||||
long u = Tables.UserRoleOverrides.Read(UserRoleOverrides.UserID, UserRoleOverrides.ID.CreateParameter(o));
|
|
||||||
GoodPerms |= Tables.UserRoleOverrides.Read(UserRoleOverrides.GoodPermissions, UserRoleOverrides.ID.CreateParameter(o));
|
|
||||||
|
|
||||||
if (GoodPerms.HasPermission(req))
|
int bad_index = -1;
|
||||||
|
int good_index = -1;
|
||||||
|
long[] UserRoleIDList = Tables.RoleMembers.ReadColumn(RoleMembers.Role, RoleMembers.User.CreateParameter(User));
|
||||||
|
|
||||||
|
foreach ((long, ServerPermission, ServerPermission) ChanRoleOverride in ChanRoleOverrides)
|
||||||
{
|
{
|
||||||
if (!Members.Contains(u)) Members.Add(u);
|
if (!UserRoleIDList.Contains(ChanRoleOverride.Item1)) continue;
|
||||||
}
|
int i = Tables.Roles.Read(Roles.Index, Roles.ID.CreateParameter(ChanRoleOverride.Item1));
|
||||||
else
|
if (((ChanRoleOverride.Item3 & RequiredPerms) ^ GoodPerms) > ServerPermission.None)
|
||||||
{
|
{
|
||||||
if (Members.Contains(u)) Members.Remove(u);
|
if (bad_index < i)
|
||||||
|
bad_index = i;
|
||||||
}
|
}
|
||||||
|
else good_index = i;
|
||||||
|
|
||||||
|
GoodPerms |= ChanRoleOverride.Item2;
|
||||||
}
|
}
|
||||||
dbConnection.Close();
|
|
||||||
|
if (bad_index > good_index) continue;
|
||||||
|
foreach (long RoleID in UserRoleIDList)
|
||||||
|
{
|
||||||
|
ServerPermission pers = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID));
|
||||||
|
GoodPerms |= pers;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GoodPerms.HasPermission(RequiredPerms)) Members.Add(User);
|
||||||
|
}
|
||||||
|
|
||||||
return Members.ToArray();
|
return Members.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long[] GetCategoryChannels(long Category, long User)
|
public static long[] GetCategoryChannels(long Category, long User)
|
||||||
{
|
{
|
||||||
List<long> chans = new();
|
List<long> chans = new();
|
||||||
@ -178,11 +169,10 @@ public static class LuskiFunctions
|
|||||||
|
|
||||||
return chans.ToArray();
|
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;
|
||||||
long[] UserRoleIDList = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(User));
|
long[] UserRoleIDList = Tables.RoleMembers.ReadColumn(RoleMembers.Role, RoleMembers.User.CreateParameter(User));
|
||||||
ServerPermission op = ServerPermission.None;
|
ServerPermission op = ServerPermission.None;
|
||||||
foreach (long RoleID in UserRoleIDList)
|
foreach (long RoleID in UserRoleIDList)
|
||||||
{
|
{
|
||||||
@ -191,7 +181,6 @@ public static class LuskiFunctions
|
|||||||
|
|
||||||
return op.HasPermission(RequiredPerms);
|
return op.HasPermission(RequiredPerms);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HasAccessToCategory(long User, long Category, out ServerPermission missing, ServerPermission OptionalPerms)
|
public static bool HasAccessToCategory(long User, long Category, out ServerPermission missing, ServerPermission OptionalPerms)
|
||||||
{
|
{
|
||||||
if (User == Tables.Server.Read(Server.Owner, Server.ID.CreateParameter(0)))
|
if (User == Tables.Server.Read(Server.Owner, Server.ID.CreateParameter(0)))
|
||||||
@ -199,43 +188,43 @@ public static class LuskiFunctions
|
|||||||
missing = ServerPermission.None;
|
missing = ServerPermission.None;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
long[] UserRoleIDList = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(User));
|
long[] UserRoleIDList = Tables.RoleMembers.ReadColumn(RoleMembers.Role, RoleMembers.User.CreateParameter(User));
|
||||||
ServerPermission BadPermissions = ServerPermission.None;
|
ServerPermission BadPermissions = ServerPermission.None;
|
||||||
ServerPermission GoodPerms = ServerPermission.None;
|
ServerPermission GoodPerms = ServerPermission.None;
|
||||||
|
(long, ServerPermission, ServerPermission)[] CatUserOverrides = Tables.CategoryUserOverrides.CreateCommand()
|
||||||
|
.WithFilter(CategoryUserOverrides.Category, Category)
|
||||||
|
.ReadColumns(CategoryUserOverrides.UserOverride, CategoryUserOverrides.GoodPermissions, CategoryUserOverrides.BadPermissions);
|
||||||
|
(long, ServerPermission, ServerPermission)[] CatRoleOverrides = Tables.CategoryRoleOverrides.CreateCommand()
|
||||||
|
.WithFilter(CategoryRoleOverrides.Category, Category)
|
||||||
|
.ReadColumns(CategoryRoleOverrides.RoleOverride,
|
||||||
|
CategoryRoleOverrides.GoodPermissions, CategoryRoleOverrides.BadPermissions);
|
||||||
|
|
||||||
(long[], long[]) crow = Tables.Categories.CreateCommand().WithFilter(Categories.ID, Category)
|
foreach ((long, ServerPermission, ServerPermission) CatUserOverride in CatUserOverrides)
|
||||||
.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 (CatUserOverride.Item1 != User) continue;
|
||||||
if (!row.BadPermissions.HasPermission(ServerPermission.ViewThis))
|
if (!CatUserOverride.Item3.HasPermission(ServerPermission.ViewThis))
|
||||||
{
|
{
|
||||||
missing = ServerPermission.ViewThis;
|
missing = ServerPermission.ViewThis;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BadPermissions |= row.BadPermissions;
|
|
||||||
GoodPerms |= row.GoodPermissions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int bad_index = -1;
|
int bad_index = -1;
|
||||||
int good_index = -1;
|
int good_index = -1;
|
||||||
|
|
||||||
foreach (long CatRoleOveride in crow.Item2)
|
foreach (var CatRoleOverride in CatRoleOverrides)
|
||||||
{
|
{
|
||||||
ServerRoleOverrideRow row = Tables.ServerRoleOverrides.ReadRow(ServerRoleOverrides.ID.CreateParameter(CatRoleOveride));
|
if (!UserRoleIDList.Contains(CatRoleOverride.Item1)) continue;
|
||||||
if (!UserRoleIDList.Contains(row.RoleID)) continue;
|
int i = Tables.Roles.Read(Roles.Index, Roles.ID.CreateParameter(CatRoleOverride.Item1));
|
||||||
int i = Tables.Roles.Read(Roles.Index, Roles.ID.CreateParameter(row.RoleID));
|
if (!CatRoleOverride.Item3.HasPermission(ServerPermission.ViewThis) && !GoodPerms.HasPermission(ServerPermission.ViewThis))
|
||||||
if (!row.BadPermissions.HasPermission(ServerPermission.ViewThis) && !GoodPerms.HasPermission(ServerPermission.ViewThis))
|
|
||||||
{
|
{
|
||||||
if (bad_index < i)
|
if (bad_index < i)
|
||||||
bad_index = i;
|
bad_index = i;
|
||||||
}
|
}
|
||||||
else good_index = i;
|
else good_index = i;
|
||||||
|
|
||||||
BadPermissions |= row.BadPermissions;
|
BadPermissions |= CatRoleOverride.Item3;
|
||||||
GoodPerms |= row.GoodPermissions;
|
GoodPerms |= CatRoleOverride.Item2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bad_index > good_index)
|
if (bad_index > good_index)
|
||||||
@ -258,44 +247,46 @@ public static class LuskiFunctions
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HasAccessToCategory(long User, long Category, ServerPermission RequiredPerms = ServerPermission.ViewThis)
|
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.RoleMembers.ReadColumn(RoleMembers.Role, RoleMembers.User.CreateParameter(User));
|
||||||
|
(long, ServerPermission, ServerPermission)[] CatUserOverrides = Tables.CategoryUserOverrides.CreateCommand()
|
||||||
|
.WithFilter(CategoryUserOverrides.Category, Category)
|
||||||
|
.ReadColumns(CategoryUserOverrides.UserOverride, CategoryUserOverrides.GoodPermissions, CategoryUserOverrides.BadPermissions);
|
||||||
|
(long, ServerPermission, ServerPermission)[] CatRoleOverrides = Tables.CategoryRoleOverrides.CreateCommand()
|
||||||
|
.WithFilter(CategoryRoleOverrides.Category, Category)
|
||||||
|
.ReadColumns(CategoryRoleOverrides.RoleOverride,
|
||||||
|
CategoryRoleOverrides.GoodPermissions, CategoryRoleOverrides.BadPermissions);
|
||||||
|
|
||||||
RequiredPerms |= ServerPermission.ViewThis;
|
RequiredPerms |= ServerPermission.ViewThis;
|
||||||
|
|
||||||
ServerPermission GoodPerms = ServerPermission.None;
|
ServerPermission GoodPerms = ServerPermission.None;
|
||||||
|
|
||||||
(long[], long[]) crow = Tables.Categories.CreateCommand().WithFilter(Categories.ID, Category)
|
foreach ((long, ServerPermission, ServerPermission) CatUserOverride in CatUserOverrides)
|
||||||
.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 (CatUserOverride.Item1 != User) continue;
|
||||||
if ((row.BadPermissions & RequiredPerms) > ServerPermission.None) return false;
|
if ((CatUserOverride.Item3 & RequiredPerms) > ServerPermission.None) return false;
|
||||||
|
|
||||||
GoodPerms |= row.GoodPermissions;
|
GoodPerms |= CatUserOverride.Item2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bad_index = -1;
|
int bad_index = -1;
|
||||||
int good_index = -1;
|
int good_index = -1;
|
||||||
|
|
||||||
foreach (long CatRoleOveride in crow.Item2)
|
foreach ((long, ServerPermission, ServerPermission) CatRoleOverride in CatRoleOverrides)
|
||||||
{
|
{
|
||||||
ServerRoleOverrideRow row = Tables.ServerRoleOverrides.ReadRow(ServerRoleOverrides.ID.CreateParameter(CatRoleOveride));
|
if (!UserRoleIDList.Contains(CatRoleOverride.Item1)) continue;
|
||||||
if (!UserRoleIDList.Contains(row.RoleID)) continue;
|
int i = Tables.Roles.Read(Roles.Index, Roles.ID.CreateParameter(CatRoleOverride.Item1));
|
||||||
int i = Tables.Roles.Read(Roles.Index, Roles.ID.CreateParameter(row.RoleID));
|
if (((CatRoleOverride.Item3 & RequiredPerms) ^ GoodPerms) > ServerPermission.None)
|
||||||
if (((row.BadPermissions & RequiredPerms) ^ GoodPerms) > ServerPermission.None)
|
|
||||||
{
|
{
|
||||||
if (bad_index < i)
|
if (bad_index < i)
|
||||||
bad_index = i;
|
bad_index = i;
|
||||||
}
|
}
|
||||||
else good_index = i;
|
else good_index = i;
|
||||||
|
|
||||||
GoodPerms |= row.GoodPermissions;
|
GoodPerms |= CatRoleOverride.Item2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bad_index > good_index) return false;
|
if (bad_index > good_index) return false;
|
||||||
foreach (long RoleID in UserRoleIDList)
|
foreach (long RoleID in UserRoleIDList)
|
||||||
{
|
{
|
||||||
@ -305,42 +296,46 @@ public static class LuskiFunctions
|
|||||||
|
|
||||||
return GoodPerms.HasPermission(RequiredPerms);
|
return GoodPerms.HasPermission(RequiredPerms);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HasAccessToChannel(long User, long Channel, ServerPermission RequiredPerms = ServerPermission.ViewThis)
|
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;
|
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.RoleMembers.ReadColumn(RoleMembers.Role, RoleMembers.User.CreateParameter(User));
|
||||||
RequiredPerms |= ServerPermission.ViewThis;
|
RequiredPerms |= ServerPermission.ViewThis;
|
||||||
ServerPermission GoodPerms = ServerPermission.None;
|
ServerPermission GoodPerms = ServerPermission.None;
|
||||||
|
|
||||||
(long[], long[]) crow = Tables.Channels.CreateCommand().WithFilter(Channels.ID, Channel)
|
(long, ServerPermission, ServerPermission)[] ChanUserOverrides = Tables.ChannelUserOverrides.CreateCommand()
|
||||||
.Read(Channels.UserOverrides, Channels.RoleOverrides);
|
.WithFilter(ChannelUserOverrides.Channel, Channel)
|
||||||
|
.ReadColumns(ChannelUserOverrides.UserOverride, ChannelUserOverrides.GoodPermissions, ChannelUserOverrides.BadPermissions);
|
||||||
|
(long, ServerPermission, ServerPermission)[] ChanRoleOverrides = Tables.ChannelRoleOverrides.CreateCommand()
|
||||||
|
.WithFilter(ChannelRoleOverrides.Channel, Channel)
|
||||||
|
.ReadColumns(ChannelRoleOverrides.RoleOverride,
|
||||||
|
ChannelRoleOverrides.GoodPermissions, ChannelRoleOverrides.BadPermissions);
|
||||||
|
|
||||||
foreach (long CatUserOveride in crow.Item1)
|
foreach ((long, ServerPermission, ServerPermission) ChanUserOverride in ChanUserOverrides)
|
||||||
{
|
{
|
||||||
if (!Tables.UserRoleOverrides.TryReadRow(out UserRoleOverrideRow row, UserRoleOverrides.ID.CreateParameter(CatUserOveride), UserRoleOverrides.UserID.CreateParameter(User))) continue;
|
if (ChanUserOverride.Item1 != User) continue;
|
||||||
if ((row.BadPermissions & RequiredPerms) > ServerPermission.None) return false;
|
if ((ChanUserOverride.Item3 & RequiredPerms) > ServerPermission.None) return false;
|
||||||
|
|
||||||
GoodPerms |= row.GoodPermissions;
|
GoodPerms |= ChanUserOverride.Item2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bad_index = -1;
|
int bad_index = -1;
|
||||||
int good_index = -1;
|
int good_index = -1;
|
||||||
|
|
||||||
foreach (long CatRoleOveride in crow.Item2)
|
foreach ((long, ServerPermission, ServerPermission) ChanRoleOverride in ChanRoleOverrides)
|
||||||
{
|
{
|
||||||
ServerRoleOverrideRow row = Tables.ServerRoleOverrides.ReadRow(ServerRoleOverrides.ID.CreateParameter(CatRoleOveride));
|
if (!UserRoleIDList.Contains(ChanRoleOverride.Item1)) continue;
|
||||||
if (!UserRoleIDList.Contains(row.RoleID)) continue;
|
int i = Tables.Roles.Read(Roles.Index, Roles.ID.CreateParameter(ChanRoleOverride.Item1));
|
||||||
int i = Tables.Roles.Read(Roles.Index, Roles.ID.CreateParameter(row.RoleID));
|
if (((ChanRoleOverride.Item3 & RequiredPerms) ^ GoodPerms) > ServerPermission.None)
|
||||||
if (((row.BadPermissions & RequiredPerms) ^ GoodPerms) > ServerPermission.None)
|
|
||||||
{
|
{
|
||||||
if (bad_index < i)
|
if (bad_index < i)
|
||||||
bad_index = i;
|
bad_index = i;
|
||||||
}
|
}
|
||||||
else good_index = i;
|
else good_index = i;
|
||||||
|
|
||||||
GoodPerms |= row.GoodPermissions;
|
GoodPerms |= ChanRoleOverride.Item2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bad_index > good_index) return false;
|
if (bad_index > good_index) return false;
|
||||||
foreach (long RoleID in UserRoleIDList)
|
foreach (long RoleID in UserRoleIDList)
|
||||||
{
|
{
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
using System.Text.Json.Serialization;
|
|
||||||
using LuskiServer.Enums.ServerComs;
|
|
||||||
|
|
||||||
namespace LuskiServer.Classes.ServerComs;
|
|
||||||
|
|
||||||
public class CilentMessageSendEvent
|
|
||||||
{
|
|
||||||
[JsonPropertyName("type")]
|
|
||||||
[JsonInclude]
|
|
||||||
public DataType? Type { get; set; } = DataType.Token!;
|
|
||||||
[JsonPropertyName("error")]
|
|
||||||
[JsonInclude]
|
|
||||||
public string Error { get; set; } = default!;
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
using System.Text.Json.Serialization;
|
|
||||||
using JacobTechEncryption.Enums;
|
|
||||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
|
||||||
using LuskiServer.Interfaces.ServerComs;
|
|
||||||
|
|
||||||
namespace LuskiServer.Classes.ServerComs;
|
|
||||||
|
|
||||||
public class MessageEvent : IServerEvent
|
|
||||||
{
|
|
||||||
[JsonInclude]
|
|
||||||
[JsonPropertyName("author_id")]
|
|
||||||
public long UserID { get; set; }
|
|
||||||
[JsonInclude]
|
|
||||||
[JsonPropertyName("channel_id")]
|
|
||||||
public long ChannelID { get; set; }
|
|
||||||
[JsonInclude]
|
|
||||||
[JsonPropertyName("context")]
|
|
||||||
public string Base64Context { get; set; }
|
|
||||||
[JsonInclude]
|
|
||||||
[JsonPropertyName("id")]
|
|
||||||
public long ID { get; set; }
|
|
||||||
[JsonInclude]
|
|
||||||
[JsonPropertyName("files")]
|
|
||||||
public ServerFileInfoSTC[] Files { get; set; }
|
|
||||||
|
|
||||||
[JsonInclude]
|
|
||||||
[JsonPropertyName("encryption_key")]
|
|
||||||
public long EncryptionKey { get; set; } = default!;
|
|
||||||
[JsonInclude]
|
|
||||||
[JsonPropertyName("encoder_type")]
|
|
||||||
public EncoderType EncoderType { get; set; } = default!;
|
|
||||||
[JsonInclude]
|
|
||||||
[JsonPropertyName("is_channel_profile")]
|
|
||||||
public bool IsProfile { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonSerializable(typeof(MessageEvent))]
|
|
||||||
[JsonSourceGenerationOptions(
|
|
||||||
GenerationMode = JsonSourceGenerationMode.Default,
|
|
||||||
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
|
|
||||||
WriteIndented = false)]
|
|
||||||
internal partial class MessageEventContext : JsonSerializerContext
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
using System.Text.Json.Serialization;
|
|
||||||
using LuskiServer.Enums.ServerComs;
|
|
||||||
using LuskiServer.Interfaces.ServerComs;
|
|
||||||
|
|
||||||
namespace LuskiServer.Classes.ServerComs;
|
|
||||||
|
|
||||||
public class ServerEvent
|
|
||||||
{
|
|
||||||
[JsonInclude]
|
|
||||||
[JsonPropertyName("type")]
|
|
||||||
public DataType Type { get; set; }
|
|
||||||
|
|
||||||
[JsonInclude]
|
|
||||||
[JsonPropertyName("data")]
|
|
||||||
public object Data { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonSerializable(typeof(ServerEvent))]
|
|
||||||
[JsonSourceGenerationOptions(
|
|
||||||
GenerationMode = JsonSourceGenerationMode.Default,
|
|
||||||
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
|
|
||||||
WriteIndented = false)]
|
|
||||||
internal partial class ServerEventContext : JsonSerializerContext
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,4 +1,5 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using Luski.Shared.PublicServers.V1.Shared;
|
||||||
using LuskiServer.Enums.ServerComs;
|
using LuskiServer.Enums.ServerComs;
|
||||||
|
|
||||||
namespace LuskiServer.Classes.ServerComs;
|
namespace LuskiServer.Classes.ServerComs;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using Luski.Shared.PublicServers.V1.ServerToClient.WSS;
|
||||||
using LuskiServer.Interfaces.ServerComs;
|
using LuskiServer.Interfaces.ServerComs;
|
||||||
|
|
||||||
namespace LuskiServer.Classes.ServerComs;
|
namespace LuskiServer.Classes.ServerComs;
|
||||||
|
|
||||||
public class TokenEvent : CilentMessageSendEvent, IServerEvent
|
public class TokenEvent : WebsocketMessageSendEventSTC, IServerEvent
|
||||||
{
|
{
|
||||||
[JsonInclude]
|
[JsonInclude]
|
||||||
[JsonPropertyName("token")]
|
[JsonPropertyName("token")]
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.InteropServices.JavaScript;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using Luski.Shared.PublicServers.V1.Enums;
|
||||||
|
using Luski.Shared.PublicServers.V1.Shared;
|
||||||
using LuskiServer.Classes.TableDef;
|
using LuskiServer.Classes.TableDef;
|
||||||
using LuskiServer.Enums.ServerComs;
|
using LuskiServer.Enums.ServerComs;
|
||||||
using LuskiServer.Interfaces.ServerComs;
|
|
||||||
using WebSocketSharp;
|
using WebSocketSharp;
|
||||||
using WebSocketSharp.Server;
|
using WebSocketSharp.Server;
|
||||||
|
|
||||||
@ -26,6 +25,24 @@ public static class WSS
|
|||||||
{
|
{
|
||||||
Tables.Keys.DeleteRow(Keys.ID.CreateParameter(id.SessionKey));
|
Tables.Keys.DeleteRow(Keys.ID.CreateParameter(id.SessionKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Tables.Sessions.TryReadRow(out var r, TableDef.Sessions.ID.CreateParameter(id.ID)))
|
||||||
|
{
|
||||||
|
UserStatus before = Tables.Users.Read(Users.Status, Users.ID.CreateParameter(id.User));
|
||||||
|
Tables.Users.CreateCommand().WithFilter(Users.ID, id.User).WithValue(Users.Status, UserStatus.Offline).Update();
|
||||||
|
WSS.SendData(SendType.All, new ServerEvent()
|
||||||
|
{
|
||||||
|
Type = DataType.StatusUpdate,
|
||||||
|
Data = new StatusEvent()
|
||||||
|
{
|
||||||
|
User = id.User,
|
||||||
|
Before = (before == UserStatus.Invisible ? UserStatus.Offline : before),
|
||||||
|
After = UserStatus.Offline,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -77,6 +94,8 @@ public static class WSS
|
|||||||
TableDef.Sessions.LoginToken.CreateParameter(te.Token)))
|
TableDef.Sessions.LoginToken.CreateParameter(te.Token)))
|
||||||
{
|
{
|
||||||
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.CreateCommand()
|
Tables.Sessions.CreateCommand()
|
||||||
@ -112,6 +131,7 @@ public static class WSS
|
|||||||
{
|
{
|
||||||
ServerIPv4 = new WebSocketServer(IPAddress.Parse(IPv4), IPv4_Port, IPv4_Secure);
|
ServerIPv4 = new WebSocketServer(IPAddress.Parse(IPv4), IPv4_Port, IPv4_Secure);
|
||||||
ServerIPv4.AddWebSocketService<CoreV1>($"{IPv4_URL}v1");
|
ServerIPv4.AddWebSocketService<CoreV1>($"{IPv4_URL}v1");
|
||||||
|
ServerIPv4.WaitTime = TimeSpan.FromSeconds(5);
|
||||||
path = $"{IPv4_URL}v1";
|
path = $"{IPv4_URL}v1";
|
||||||
ServerIPv4.Start();
|
ServerIPv4.Start();
|
||||||
if (IPv6 is not null)
|
if (IPv6 is not null)
|
||||||
@ -150,6 +170,10 @@ public static class WSS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (SendType == SendType.All)
|
||||||
|
{
|
||||||
|
ServerIPv4.WebSocketServices[path].Sessions.Broadcast(JsonSerializer.Serialize(Event));
|
||||||
|
}
|
||||||
|
|
||||||
//TODO Start work on server send code
|
//TODO Start work on server send code
|
||||||
}
|
}
|
||||||
|
@ -11,5 +11,4 @@ public static class AltServers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TableRow(typeof(AltServers))]
|
[TableRow(typeof(AltServers))]
|
||||||
public partial class AltServerRow
|
public partial class AltServerRow;
|
||||||
{}
|
|
@ -1,5 +1,6 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using JacobTechEncryption.Enums;
|
using JacobTechEncryption.Enums;
|
||||||
|
using Luski.Shared.PublicServers.V1.Enums;
|
||||||
using ServerDatabase;
|
using ServerDatabase;
|
||||||
using ServerDatabase.SourceGenerator;
|
using ServerDatabase.SourceGenerator;
|
||||||
|
|
||||||
@ -9,16 +10,29 @@ public static class Categories
|
|||||||
{
|
{
|
||||||
public static TableColumn<CategoryRow, long> ID { get; } = new("id", true);
|
public static TableColumn<CategoryRow, long> ID { get; } = new("id", true);
|
||||||
public static TableColumn<CategoryRow, 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<CategoryRow, ColorType> ColorType { get; } = new("color_type") { DefaultValue = Luski.Shared.PublicServers.V1.Enums.ColorType.Full};
|
||||||
public static TableColumn<CategoryRow, 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<CategoryRow, 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<CategoryRow, long> Parent { get; } = new("parent") { DefaultValue = -1 };
|
public static TableColumn<CategoryRow, long> TitleEncryptionKey { get; } = new("title_encryption_key")
|
||||||
public static TableColumn<CategoryRow, long[]> RoleOverrides { get; } = new("role_overrides") { DefaultValue = Array.Empty<long>() };
|
{
|
||||||
public static TableColumn<CategoryRow, long[]> UserOverrides { get; } = new("member_overrides") { DefaultValue = Array.Empty<long>() };
|
DefaultValue = 0,
|
||||||
public static TableColumn<CategoryRow, long> TitleEncryptionKey { get; } = new("title_encryption_key") { DefaultValue = 0 };
|
ForeignKey = new ForeignKey()
|
||||||
public static TableColumn<CategoryRow, long> DescriptionEncryptionKey { get; } = new("description_encryption_key") { DefaultValue = 0 };
|
{
|
||||||
|
Table = Tables.Keys,
|
||||||
|
Column = Keys.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<CategoryRow, long> DescriptionEncryptionKey { get; } = new("description_encryption_key")
|
||||||
|
{
|
||||||
|
DefaultValue = 0,
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Keys,
|
||||||
|
Column = Keys.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
public static TableColumn<CategoryRow, EncoderType> TitleEncoderType { get; } = new("title_encoder_type") { DefaultValue = EncoderType.UTF8 };
|
public static TableColumn<CategoryRow, EncoderType> TitleEncoderType { get; } = new("title_encoder_type") { DefaultValue = EncoderType.UTF8 };
|
||||||
public static TableColumn<CategoryRow, EncoderType> DescriptionEncoderType { get; } = new("description_encoder_type") { DefaultValue = EncoderType.UTF8 };
|
public static TableColumn<CategoryRow, EncoderType> DescriptionEncoderType { get; } = new("description_encoder_type") { DefaultValue = EncoderType.UTF8 };
|
||||||
}
|
}
|
||||||
[TableRow(typeof(Categories))]
|
[TableRow(typeof(Categories))]
|
||||||
public partial class CategoryRow
|
public partial class CategoryRow;
|
||||||
{}
|
|
28
LuskiServer/Classes/TableDef/CategoryParents.cs
Normal file
28
LuskiServer/Classes/TableDef/CategoryParents.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public static class CategoryParents
|
||||||
|
{
|
||||||
|
public static TableColumn<CategoryParentRow, long> ID { get; } = new("id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Categories,
|
||||||
|
Column = Categories.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<CategoryParentRow, long> Parent { get; } = new("parent")
|
||||||
|
{
|
||||||
|
DefaultValue = 0 ,
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Categories,
|
||||||
|
Column = Categories.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(CategoryParents))]
|
||||||
|
public partial class CategoryParentRow;
|
28
LuskiServer/Classes/TableDef/CategoryProfiles.cs
Normal file
28
LuskiServer/Classes/TableDef/CategoryProfiles.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public static class CategoryProfiles
|
||||||
|
{
|
||||||
|
public static TableColumn<CategoryProfileRow, long> Profile { get; } = new("id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Profiles,
|
||||||
|
Column = Profiles.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static TableColumn<CategoryProfileRow, long> Category { get; } = new("category_id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Categories,
|
||||||
|
Column = Categories.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(CategoryProfiles))]
|
||||||
|
public partial class CategoryProfileRow;
|
30
LuskiServer/Classes/TableDef/CategoryRoleOverrides.cs
Normal file
30
LuskiServer/Classes/TableDef/CategoryRoleOverrides.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using Luski.Shared.PublicServers.V1.Enums;
|
||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public static class CategoryRoleOverrides
|
||||||
|
{
|
||||||
|
public static TableColumn<CategoryRoleOverrideRow, long> Category { get; } = new("category", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Categories,
|
||||||
|
Column = Categories.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<CategoryRoleOverrideRow, long> RoleOverride { get; } = new("override", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Roles,
|
||||||
|
Column = Roles.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<CategoryRoleOverrideRow, ServerPermission> BadPermissions { get; } = new("bad_permissions");
|
||||||
|
public static TableColumn<CategoryRoleOverrideRow, ServerPermission> GoodPermissions { get; } = new("good_permissions");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(CategoryRoleOverrides))]
|
||||||
|
public partial class CategoryRoleOverrideRow;
|
30
LuskiServer/Classes/TableDef/CategoryUserOverrides.cs
Normal file
30
LuskiServer/Classes/TableDef/CategoryUserOverrides.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using Luski.Shared.PublicServers.V1.Enums;
|
||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public static class CategoryUserOverrides
|
||||||
|
{
|
||||||
|
public static TableColumn<CategoryUserOverrideRow, long> Category { get; } = new("category", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Categories,
|
||||||
|
Column = Categories.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<CategoryUserOverrideRow, long> UserOverride { get; } = new("override", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Users,
|
||||||
|
Column = Users.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<CategoryUserOverrideRow, ServerPermission> BadPermissions { get; } = new("bad_permissions");
|
||||||
|
public static TableColumn<CategoryUserOverrideRow, ServerPermission> GoodPermissions { get; } = new("good_permissions");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(CategoryUserOverrides))]
|
||||||
|
public partial class CategoryUserOverrideRow;
|
28
LuskiServer/Classes/TableDef/ChannelKeys.cs
Normal file
28
LuskiServer/Classes/TableDef/ChannelKeys.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public static class ChannelKeys
|
||||||
|
{
|
||||||
|
public static TableColumn<ChannelKeyRow, long> Key { get; } = new("key_id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Keys,
|
||||||
|
Column = Keys.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static TableColumn<ChannelKeyRow, long> Channel { get; } = new("channel_id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Channels,
|
||||||
|
Column = Channels.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(ChannelKeys))]
|
||||||
|
public partial class ChannelKeyRow;
|
@ -1,20 +1,28 @@
|
|||||||
using Luski.Shared.PublicServers.V1.Enums;
|
|
||||||
using ServerDatabase;
|
using ServerDatabase;
|
||||||
using ServerDatabase.SourceGenerator;
|
using ServerDatabase.SourceGenerator;
|
||||||
using bob = Luski.Shared.PublicServers.V1.Enums.PictureType;
|
|
||||||
|
|
||||||
namespace LuskiServer.Classes.TableDef;
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
public class ChannelProfiles
|
public static class ChannelProfiles
|
||||||
{
|
{
|
||||||
public static TableColumn<ChannelProfileRow, long> ID { get; } = new("id", true);
|
public static TableColumn<ChannelProfileRow, long> Profile { get; } = new("id", true)
|
||||||
public static TableColumn<ChannelProfileRow, string> DisplayName { get; } = new("displayname");
|
{
|
||||||
public static TableColumn<ChannelProfileRow, long[]> Controllers { get; } = new("controllers") {DefaultValue = Array.Empty<long>()};
|
ForeignKey = new ForeignKey()
|
||||||
public static TableColumn<ChannelProfileRow, PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png };
|
{
|
||||||
public static TableColumn<ChannelProfileRow, byte[]> Picture { get; } = new("picture");
|
Table = Tables.Profiles,
|
||||||
public static TableColumn<ChannelProfileRow, byte[]> Color { get; } = new("color") { DefaultValue = new byte[]{255,255,255,255}};
|
Column = Profiles.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static TableColumn<ChannelProfileRow, long> Channel { get; } = new("channel_id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Channels,
|
||||||
|
Column = Channels.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[TableRow(typeof(ChannelProfiles))]
|
[TableRow(typeof(ChannelProfiles))]
|
||||||
public partial class ChannelProfileRow
|
public partial class ChannelProfileRow;
|
||||||
{}
|
|
30
LuskiServer/Classes/TableDef/ChannelRoleOverrides.cs
Normal file
30
LuskiServer/Classes/TableDef/ChannelRoleOverrides.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using Luski.Shared.PublicServers.V1.Enums;
|
||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public static class ChannelRoleOverrides
|
||||||
|
{
|
||||||
|
public static TableColumn<ChannelRoleOverrideRow, long> Channel { get; } = new("channel", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Channels,
|
||||||
|
Column = Channels.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<ChannelRoleOverrideRow, long> RoleOverride { get; } = new("override", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Roles,
|
||||||
|
Column = Roles.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<ChannelRoleOverrideRow, ServerPermission> BadPermissions { get; } = new("bad_permissions");
|
||||||
|
public static TableColumn<ChannelRoleOverrideRow, ServerPermission> GoodPermissions { get; } = new("good_permissions");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(ChannelRoleOverrides))]
|
||||||
|
public partial class ChannelRoleOverrideRow;
|
30
LuskiServer/Classes/TableDef/ChannelUserOverrides.cs
Normal file
30
LuskiServer/Classes/TableDef/ChannelUserOverrides.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using Luski.Shared.PublicServers.V1.Enums;
|
||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public static class ChannelUserOverrides
|
||||||
|
{
|
||||||
|
public static TableColumn<ChannelUserOverrideRow, long> Channel { get; } = new("channel", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Channels,
|
||||||
|
Column = Channels.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<ChannelUserOverrideRow, long> UserOverride { get; } = new("override", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Users,
|
||||||
|
Column = Users.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<ChannelUserOverrideRow, ServerPermission> BadPermissions { get; } = new("bad_permissions");
|
||||||
|
public static TableColumn<ChannelUserOverrideRow, ServerPermission> GoodPermissions { get; } = new("good_permissions");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(ChannelUserOverrides))]
|
||||||
|
public partial class ChannelUserOverrideRow;
|
@ -11,17 +11,39 @@ namespace LuskiServer.Classes.TableDef;
|
|||||||
public static class Channels
|
public static class Channels
|
||||||
{
|
{
|
||||||
public static TableColumn<ChannelRow, long> ID { get; } = new("id", true);
|
public static TableColumn<ChannelRow, long> ID { get; } = new("id", true);
|
||||||
public static TableColumn<ChannelRow, long> Parent { get; } = new("parent") { DefaultValue = -1 };
|
public static TableColumn<ChannelRow, long> Parent { get; } = new("parent")
|
||||||
|
{
|
||||||
|
DefaultValue = 0 ,
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Categories,
|
||||||
|
Column = Categories.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<ChannelRow, ColorType> ColorType { get; } = new("color_type") { DefaultValue = Luski.Shared.PublicServers.V1.Enums.ColorType.Full};
|
||||||
public static TableColumn<ChannelRow, 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<ChannelRow, ChannelType> Type { get; } = new("type");
|
public static TableColumn<ChannelRow, ChannelType> Type { get; } = new("type");
|
||||||
public static TableColumn<ChannelRow, DateTime> Epoch { get; } = new("epoch");
|
public static TableColumn<ChannelRow, DateTime> Epoch { get; } = new("epoch");
|
||||||
public static TableColumn<ChannelRow, 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<ChannelRow, 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<ChannelRow, long[]> RoleOverrides { get; } = new("role_overrides") { DefaultValue = Array.Empty<long>() };
|
public static TableColumn<ChannelRow, long> TitleEncryptionKey { get; } = new("title_encryption_key")
|
||||||
public static TableColumn<ChannelRow, long[]> UserOverrides { get; } = new("member_overrides") { DefaultValue = Array.Empty<long>() };
|
{
|
||||||
public static TableColumn<ChannelRow, long> TitleEncryptionKey { get; } = new("title_encryption_key") { DefaultValue = 0 };
|
DefaultValue = 0,
|
||||||
public static TableColumn<ChannelRow, long> DescriptionEncryptionKey { get; } = new("description_encryption_key") { DefaultValue = 0 };
|
ForeignKey = new ForeignKey()
|
||||||
public static TableColumn<ChannelRow, long[]> EncryptionKeys { get; } = new("encryption_keys") { DefaultValue = new long[]{0} };
|
{
|
||||||
|
Table = Tables.Keys,
|
||||||
|
Column = Keys.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<ChannelRow, long> DescriptionEncryptionKey { get; } = new("description_encryption_key")
|
||||||
|
{
|
||||||
|
DefaultValue = 0,
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Keys,
|
||||||
|
Column = Keys.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
public static TableColumn<ChannelRow, 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<ChannelRow, 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<ChannelRow, PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png };
|
public static TableColumn<ChannelRow, PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png };
|
||||||
@ -32,10 +54,7 @@ public static class Channels
|
|||||||
EncoderType.UTF32, EncoderType.ASCII,
|
EncoderType.UTF32, EncoderType.ASCII,
|
||||||
EncoderType.Latin1, EncoderType.BigEndianUnicode
|
EncoderType.Latin1, EncoderType.BigEndianUnicode
|
||||||
} };
|
} };
|
||||||
|
|
||||||
public static TableColumn<ChannelRow, long[]> Profiles { get; } = new("profiles") { DefaultValue = Array.Empty<long>() };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TableRow(typeof(Channels))]
|
[TableRow(typeof(Channels))]
|
||||||
public partial class ChannelRow
|
public partial class ChannelRow;
|
||||||
{}
|
|
27
LuskiServer/Classes/TableDef/FileChannels.cs
Normal file
27
LuskiServer/Classes/TableDef/FileChannels.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public static class FileChannels
|
||||||
|
{
|
||||||
|
public static TableColumn<FileChannelRow, long> FileID { get; } = new("file_id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Files,
|
||||||
|
Column = Files.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<FileChannelRow, long> ChannelID { get; } = new("channel_id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Channels,
|
||||||
|
Column = Channels.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(FileChannels))]
|
||||||
|
public partial class FileChannelRow;
|
@ -7,20 +7,38 @@ namespace LuskiServer.Classes.TableDef;
|
|||||||
public static class Files
|
public static class Files
|
||||||
{
|
{
|
||||||
public static TableColumn<FileRow, long> ID { get; } = new("id", true);
|
public static TableColumn<FileRow, long> ID { get; } = new("id", true);
|
||||||
public static TableColumn<FileRow, long> Owner { get; } = new("owner");
|
public static TableColumn<FileRow, long> Owner { get; } = new("owner")
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Users,
|
||||||
|
Column = Users.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
public static TableColumn<FileRow, bool> Public { get; } = new("public_download");
|
public static TableColumn<FileRow, bool> Public { get; } = new("public_download");
|
||||||
public static TableColumn<FileRow, long[]> AllowedChannels { get; } = new("channels");
|
|
||||||
public static TableColumn<FileRow, long> Size { get; } = new("size");
|
public static TableColumn<FileRow, long> Size { get; } = new("size");
|
||||||
public static TableColumn<FileRow, byte[]> Name { get; } = new("name");
|
public static TableColumn<FileRow, byte[]> Name { get; } = new("name");
|
||||||
public static TableColumn<FileRow, byte[]> Hash { get; } = new("hash");
|
public static TableColumn<FileRow, byte[]> Hash { get; } = new("hash");
|
||||||
public static TableColumn<FileRow, byte[]> Data { get; } = new("data");
|
public static TableColumn<FileRow, byte[]> Data { get; } = new("data");
|
||||||
public static TableColumn<FileRow, long> EncryptionKey { get; } = new("encryption_key");
|
public static TableColumn<FileRow, long> EncryptionKey { get; } = new("encryption_key")
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Keys,
|
||||||
|
Column = Keys.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
public static TableColumn<FileRow, EncoderType> EncoderType { get; } = new("encoder_type");
|
public static TableColumn<FileRow, EncoderType> EncoderType { get; } = new("encoder_type");
|
||||||
public static TableColumn<FileRow, long> NameEncryptionKey { get; } = new("name_encryption_key");
|
public static TableColumn<FileRow, long> NameEncryptionKey { get; } = new("name_encryption_key")
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Keys,
|
||||||
|
Column = Keys.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
public static TableColumn<FileRow, EncoderType> NameEncoderType { get; } = new("name_encoder_type");
|
public static TableColumn<FileRow, EncoderType> NameEncoderType { get; } = new("name_encoder_type");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TableRow(typeof(Files))]
|
[TableRow(typeof(Files))]
|
||||||
public partial class FileRow
|
public partial class FileRow;
|
||||||
{
|
|
||||||
}
|
|
@ -7,12 +7,9 @@ namespace LuskiServer.Classes.TableDef;
|
|||||||
public static class Keys
|
public static class Keys
|
||||||
{
|
{
|
||||||
public static TableColumn<KeyRow, long> ID { get; } = new("id", true);
|
public static TableColumn<KeyRow, long> ID { get; } = new("id", true);
|
||||||
public static TableColumn<KeyRow, long> Owner { get; } = new("owner");
|
|
||||||
public static TableColumn<KeyRow, EncryptionType> EncryptionType { get; } = new("encryption_type");
|
public static TableColumn<KeyRow, EncryptionType> EncryptionType { get; } = new("encryption_type");
|
||||||
public static TableColumn<KeyRow, byte[]> KeyData { get; } = new("key_data");
|
public static TableColumn<KeyRow, byte[]> KeyData { get; } = new("key_data");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TableRow(typeof(Keys))]
|
[TableRow(typeof(Keys))]
|
||||||
public partial class KeyRow
|
public partial class KeyRow;
|
||||||
{
|
|
||||||
}
|
|
@ -1,3 +1,4 @@
|
|||||||
|
using Luski.Shared.PublicServers.V1.Shared;
|
||||||
using LuskiServer.Enums;
|
using LuskiServer.Enums;
|
||||||
using ServerDatabase;
|
using ServerDatabase;
|
||||||
using ServerDatabase.SourceGenerator;
|
using ServerDatabase.SourceGenerator;
|
||||||
@ -12,5 +13,4 @@ public static class Logs
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TableRow(typeof(Logs))]
|
[TableRow(typeof(Logs))]
|
||||||
public partial class LogRow
|
public partial class LogRow;
|
||||||
{}
|
|
28
LuskiServer/Classes/TableDef/MessageFiles.cs
Normal file
28
LuskiServer/Classes/TableDef/MessageFiles.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using JacobTechEncryption.Enums;
|
||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public static class MessageFiles
|
||||||
|
{
|
||||||
|
public static TableColumn<MessageFileRow, long> MessageID { get; } = new("message_id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Messages,
|
||||||
|
Column = Messages.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<MessageFileRow, long> FileID { get; } = new("file_id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Files,
|
||||||
|
Column = Files.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(MessageFiles))]
|
||||||
|
public partial class MessageFileRow;
|
@ -7,16 +7,43 @@ namespace LuskiServer.Classes.TableDef;
|
|||||||
public static class Messages
|
public static class Messages
|
||||||
{
|
{
|
||||||
public static TableColumn<MessageRow, long> ID { get; } = new("id", true);
|
public static TableColumn<MessageRow, long> ID { get; } = new("id", true);
|
||||||
public static TableColumn<MessageRow, long> ChannelID { get; } = new("channel_id", true);
|
public static TableColumn<MessageRow, long> Timestamp { get; } = new("message_timestamp");
|
||||||
public static TableColumn<MessageRow, long> AuthorID { get; } = new("author_id");
|
public static TableColumn<MessageRow, long> ChannelID { get; } = new("channel_id")
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Channels,
|
||||||
|
Column = Channels.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<MessageRow, long> AuthorID { get; } = new("author_id")
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Users,
|
||||||
|
Column = Users.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<MessageRow, long> ProfileID { get; } = new("profile_id")
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Profiles,
|
||||||
|
Column = Profiles.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
public static TableColumn<MessageRow, byte[]> Context { get; } = new("context");
|
public static TableColumn<MessageRow, byte[]> Context { get; } = new("context");
|
||||||
public static TableColumn<MessageRow, long> EncryptionKey { get; } = new("encryption_key");
|
public static TableColumn<MessageRow, long> EncryptionKey { get; } = new("encryption_key")
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Keys,
|
||||||
|
Column = Keys.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
public static TableColumn<MessageRow, EncoderType> EncoderType { get; } = new("encoder_type");
|
public static TableColumn<MessageRow, EncoderType> EncoderType { get; } = new("encoder_type");
|
||||||
public static TableColumn<MessageRow, long[]> Files { get; } = new("files");
|
|
||||||
public static TableColumn<MessageRow, bool> IsChannelProfile { get; } = new("is_channel_profile") { DefaultValue = false };
|
|
||||||
public static TableColumn<MessageRow, long> ReplyTo { get; } = new("reply_to");
|
public static TableColumn<MessageRow, long> ReplyTo { get; } = new("reply_to");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TableRow(typeof(Messages))]
|
[TableRow(typeof(Messages))]
|
||||||
public partial class MessageRow
|
public partial class MessageRow;
|
||||||
{}
|
|
20
LuskiServer/Classes/TableDef/OfflineData.cs
Normal file
20
LuskiServer/Classes/TableDef/OfflineData.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public static class OfflineData
|
||||||
|
{
|
||||||
|
public static TableColumn<OfflineDataRow, long> StorageID { get; } = new("id")
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Storage,
|
||||||
|
Column = Storage.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<OfflineDataRow, byte[]> Data { get; } = new("data");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(OfflineData))]
|
||||||
|
public partial class OfflineDataRow;
|
22
LuskiServer/Classes/TableDef/ProfileColors.cs
Normal file
22
LuskiServer/Classes/TableDef/ProfileColors.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using Luski.Shared.PublicServers.V1.Enums;
|
||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public static class ProfileColors
|
||||||
|
{
|
||||||
|
public static TableColumn<ProfileColorRow, long> Profile { get; } = new("id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Profiles,
|
||||||
|
Column = Profiles.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<ProfileColorRow, ColorType> ColorType { get; } = new("color_type") { DefaultValue = Luski.Shared.PublicServers.V1.Enums.ColorType.Full};
|
||||||
|
public static TableColumn<ProfileColorRow, byte[]> Color { get; } = new("color") { DefaultValue = new byte[]{255,255,255,255}};
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(ProfileColors))]
|
||||||
|
public partial class ProfileColorRow;
|
28
LuskiServer/Classes/TableDef/ProfileControllers.cs
Normal file
28
LuskiServer/Classes/TableDef/ProfileControllers.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public static class ProfileControllers
|
||||||
|
{
|
||||||
|
public static TableColumn<ProfileControllerRow, long> Profile { get; } = new("id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Profiles,
|
||||||
|
Column = Profiles.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static TableColumn<ProfileControllerRow, long> User { get; } = new("user_id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Users,
|
||||||
|
Column = Users.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(ProfileControllers))]
|
||||||
|
public partial class ProfileControllerRow;
|
28
LuskiServer/Classes/TableDef/ProfileRoleControllers.cs
Normal file
28
LuskiServer/Classes/TableDef/ProfileRoleControllers.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public static class ProfileRoleControllers
|
||||||
|
{
|
||||||
|
public static TableColumn<ProfileRoleControllerRow, long> Profile { get; } = new("id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Profiles,
|
||||||
|
Column = Profiles.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static TableColumn<ProfileRoleControllerRow, long> Role { get; } = new("role_id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Roles,
|
||||||
|
Column = Roles.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(ProfileRoleControllers))]
|
||||||
|
public partial class ProfileRoleControllerRow;
|
18
LuskiServer/Classes/TableDef/Profiles.cs
Normal file
18
LuskiServer/Classes/TableDef/Profiles.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using Luski.Shared.PublicServers.V1.Enums;
|
||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
using bob = Luski.Shared.PublicServers.V1.Enums.PictureType;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public class Profiles
|
||||||
|
{
|
||||||
|
public static TableColumn<ProfileRow, long> ID { get; } = new("id", true);
|
||||||
|
public static TableColumn<ProfileRow, string> DisplayName { get; } = new("displayname");
|
||||||
|
public static TableColumn<ProfileRow, PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png };
|
||||||
|
public static TableColumn<ProfileRow, byte[]> Picture { get; } = new("picture");
|
||||||
|
public static TableColumn<ProfileRow, bool> CanUpdateName { get; } = new("update_name");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(Profiles))]
|
||||||
|
public partial class ProfileRow;
|
28
LuskiServer/Classes/TableDef/RoleMembers.cs
Normal file
28
LuskiServer/Classes/TableDef/RoleMembers.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using ServerDatabase;
|
||||||
|
using ServerDatabase.SourceGenerator;
|
||||||
|
using ServerDatabase.Utils.Enums;
|
||||||
|
|
||||||
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
|
public class RoleMembers
|
||||||
|
{
|
||||||
|
public static TableColumn<RoleMemberRow, long> Role { get; } = new("role", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Roles,
|
||||||
|
Column = Roles.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<RoleMemberRow, long> User { get; } = new("user_id", true)
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Users,
|
||||||
|
Column = Users.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[TableRow(typeof(RoleMembers))]
|
||||||
|
public partial class RoleMemberRow;
|
@ -2,21 +2,21 @@ 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 ServerDatabase.Utils.Enums;
|
||||||
|
|
||||||
namespace LuskiServer.Classes.TableDef;
|
namespace LuskiServer.Classes.TableDef;
|
||||||
|
|
||||||
public static class Roles
|
public static class Roles
|
||||||
{
|
{
|
||||||
public static TableColumn<RoleRow, long> ID { get; } = new("id", true);
|
public static TableColumn<RoleRow, long> ID { get; } = new("id", true);
|
||||||
public static TableColumn<RoleRow, string> Name { get; } = new("name");
|
|
||||||
public static TableColumn<RoleRow, 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<RoleRow, int> Index { get; } = new("index") {DefaultValue = 0 };
|
public static TableColumn<RoleRow, int> Index { get; } = new("index") {DefaultValue = 0 };
|
||||||
|
public static TableColumn<RoleRow, ColorType> ColorType { get; } = new("color_type") { DefaultValue = Luski.Shared.PublicServers.V1.Enums.ColorType.Full};
|
||||||
public static TableColumn<RoleRow, 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<RoleRow, string> Description { get; } = new("description");
|
public static TableColumn<RoleRow, string> Description { get; } = new("description") {DefaultValue = string.Empty};
|
||||||
public static TableColumn<RoleRow, ServerPermission> ServerPermissions { get; } = new("server_perms");
|
public static TableColumn<RoleRow, ServerPermission> ServerPermissions { get; } = new("server_perms");
|
||||||
public static TableColumn<RoleRow, long[]> MembersList { get; } = new("members_list") {DefaultValue = Array.Empty<long>()};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TableRow(typeof(Roles))]
|
[TableRow(typeof(Roles))]
|
||||||
public partial class RoleRow
|
public partial class RoleRow;
|
||||||
{}
|
|
@ -18,5 +18,4 @@ public static class Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
[TableRow(typeof(Server))]
|
[TableRow(typeof(Server))]
|
||||||
public partial class ServerRow
|
public partial class ServerRow;
|
||||||
{}
|
|
@ -1,16 +0,0 @@
|
|||||||
using Luski.Shared.PublicServers.V1.Enums;
|
|
||||||
using ServerDatabase;
|
|
||||||
using ServerDatabase.SourceGenerator;
|
|
||||||
|
|
||||||
namespace LuskiServer.Classes.TableDef;
|
|
||||||
|
|
||||||
public static class ServerRoleOverrides
|
|
||||||
{
|
|
||||||
public static TableColumn<ServerRoleOverrideRow, long> ID { get; } = new("id", true);
|
|
||||||
public static TableColumn<ServerRoleOverrideRow, long> RoleID { get; } = new("role_id");
|
|
||||||
public static TableColumn<ServerRoleOverrideRow, ServerPermission> BadPermissions { get; } = new("bad_permissions");
|
|
||||||
public static TableColumn<ServerRoleOverrideRow, ServerPermission> GoodPermissions { get; } = new("good_permissions");
|
|
||||||
}
|
|
||||||
|
|
||||||
[TableRow(typeof(ServerRoleOverrides))]
|
|
||||||
public partial class ServerRoleOverrideRow;
|
|
@ -6,12 +6,18 @@ namespace LuskiServer.Classes.TableDef;
|
|||||||
public static class SessionTokens
|
public static class SessionTokens
|
||||||
{
|
{
|
||||||
public static TableColumn<SessionTokenRow, long> ID { get; } = new("id", true);
|
public static TableColumn<SessionTokenRow, long> ID { get; } = new("id", true);
|
||||||
public static TableColumn<SessionTokenRow, long> AccountID { get; } = new("account_id");
|
public static TableColumn<SessionTokenRow, long> AccountID { get; } = new("account_id")
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Users,
|
||||||
|
Column = Users.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
public static TableColumn<SessionTokenRow, string> Token { get; } = new("token");
|
public static TableColumn<SessionTokenRow, string> Token { get; } = new("token");
|
||||||
public static TableColumn<SessionTokenRow, byte[]> AddressFilter { get; } = new("address_filter");
|
public static TableColumn<SessionTokenRow, byte[]> AddressFilter { get; } = new("address_filter");
|
||||||
public static TableColumn<SessionTokenRow, DateTime> TimeFilter { get; } = new("date_filter");
|
public static TableColumn<SessionTokenRow, DateTime> TimeFilter { get; } = new("date_filter");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TableRow(typeof(SessionTokens))]
|
[TableRow(typeof(SessionTokens))]
|
||||||
public partial class SessionTokenRow
|
public partial class SessionTokenRow;
|
||||||
{}
|
|
@ -8,14 +8,27 @@ namespace LuskiServer.Classes.TableDef;
|
|||||||
public static class Sessions
|
public static class Sessions
|
||||||
{
|
{
|
||||||
public static TableColumn<SessionsRow, long> ID { get; } = new("id", true);
|
public static TableColumn<SessionsRow, long> ID { get; } = new("id", true);
|
||||||
public static TableColumn<SessionsRow, long> User { get; } = new("userid");
|
public static TableColumn<SessionsRow, long> User { get; } = new("userid")
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Users,
|
||||||
|
Column = Users.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
public static TableColumn<SessionsRow, string> WSSTCP { get; } = new("wsstcp");
|
public static TableColumn<SessionsRow, string> WSSTCP { get; } = new("wsstcp");
|
||||||
public static TableColumn<SessionsRow, string> Token { get; } = new("token");
|
public static TableColumn<SessionsRow, string> Token { get; } = new("token");
|
||||||
public static TableColumn<SessionsRow, string> LoginToken { get; } = new("login_token");
|
public static TableColumn<SessionsRow, string> LoginToken { get; } = new("login_token");
|
||||||
public static TableColumn<SessionsRow, long> SessionKey { get; } = new("session_key");
|
public static TableColumn<SessionsRow, long> SessionKey { get; } = new("session_key")
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Keys,
|
||||||
|
Column = Keys.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
public static TableColumn<SessionsRow, long> StorageID { get; } = new("storage_id");
|
public static TableColumn<SessionsRow, long> StorageID { get; } = new("storage_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TableRow(typeof(Sessions))]
|
[TableRow(typeof(Sessions))]
|
||||||
public partial class SessionsRow
|
public partial class SessionsRow;
|
||||||
{}
|
|
||||||
|
@ -6,14 +6,24 @@ namespace LuskiServer.Classes.TableDef;
|
|||||||
public static class Storage
|
public static class Storage
|
||||||
{
|
{
|
||||||
public static TableColumn<StorageRow, long> ID { get; } = new("id", true);
|
public static TableColumn<StorageRow, long> ID { get; } = new("id", true);
|
||||||
public static TableColumn<StorageRow, long> AccountID { get; } = new("account_id");
|
public static TableColumn<StorageRow, long> AccountID { get; } = new("account_id")
|
||||||
public static TableColumn<StorageRow, byte[][]> Data { get; } = new("data");
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Users,
|
||||||
|
Column = Users.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
public static TableColumn<StorageRow, byte[]> Password { get; } = new("password");
|
public static TableColumn<StorageRow, byte[]> Password { get; } = new("password");
|
||||||
public static TableColumn<StorageRow, long> OffileKey { get; } = new("offline_key");
|
public static TableColumn<StorageRow, long> OfflineKey { get; } = new("offline_key")
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Keys,
|
||||||
|
Column = Keys.ID
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[TableRow(typeof(Storage))]
|
[TableRow(typeof(Storage))]
|
||||||
public partial class StorageRow
|
public partial class StorageRow;
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
using Luski.Shared.PublicServers.V1.Enums;
|
|
||||||
using LuskiServer.Enums;
|
|
||||||
using ServerDatabase;
|
|
||||||
using ServerDatabase.SourceGenerator;
|
|
||||||
|
|
||||||
namespace LuskiServer.Classes.TableDef;
|
|
||||||
|
|
||||||
public static class UserRoleOverrides
|
|
||||||
{
|
|
||||||
public static TableColumn<UserRoleOverrideRow, long> ID { get; } = new("id", true);
|
|
||||||
public static TableColumn<UserRoleOverrideRow, long> UserID { get; } = new("user_id");
|
|
||||||
public static TableColumn<UserRoleOverrideRow, ServerPermission> BadPermissions { get; } = new("bad_permissions");
|
|
||||||
public static TableColumn<UserRoleOverrideRow, ServerPermission> GoodPermissions { get; } = new("good_permissions");
|
|
||||||
}
|
|
||||||
|
|
||||||
[TableRow(typeof(UserRoleOverrides))]
|
|
||||||
public partial class UserRoleOverrideRow;
|
|
@ -1,8 +1,8 @@
|
|||||||
using Luski.Shared.PublicServers.V1.Enums;
|
using Luski.Shared.PublicServers.V1.Enums;
|
||||||
using LuskiServer.Enums;
|
|
||||||
using ServerDatabase;
|
using ServerDatabase;
|
||||||
using ServerDatabase.SourceGenerator;
|
using ServerDatabase.SourceGenerator;
|
||||||
using ServerDatabase.Utils;
|
using ServerDatabase.Utils;
|
||||||
|
using ServerDatabase.Utils.Enums;
|
||||||
using bob = Luski.Shared.PublicServers.V1.Enums.PictureType;
|
using bob = Luski.Shared.PublicServers.V1.Enums.PictureType;
|
||||||
|
|
||||||
|
|
||||||
@ -11,17 +11,29 @@ namespace LuskiServer.Classes.TableDef;
|
|||||||
public class Users
|
public class Users
|
||||||
{
|
{
|
||||||
public static TableColumn<UserRow, long> ID { get; } = new("id", true);
|
public static TableColumn<UserRow, long> ID { get; } = new("id", true);
|
||||||
public static TableColumn<UserRow, string> DisplayName { get; } = new("displayname");
|
public static TableColumn<UserRow, long> ServerProfile { get; } = new("server_profile")
|
||||||
public static TableColumn<UserRow, long> SelectedChannel { get; } = new("selected_channel");
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Profiles,
|
||||||
|
Column = Profiles.ID,
|
||||||
|
OnDelete = ConstraintAction.None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static TableColumn<UserRow, long> SelectedChannel { get; } = new("selected_channel")
|
||||||
|
{
|
||||||
|
ForeignKey = new ForeignKey()
|
||||||
|
{
|
||||||
|
Table = Tables.Channels,
|
||||||
|
Column = Channels.ID,
|
||||||
|
OnDelete = ConstraintAction.Restrict
|
||||||
|
}
|
||||||
|
};
|
||||||
public static TableColumn<UserRow, UserStatus> Status { get; } = new("status") { DefaultValue = UserStatus.Offline };
|
public static TableColumn<UserRow, UserStatus> Status { get; } = new("status") { DefaultValue = UserStatus.Offline };
|
||||||
public static TableColumn<UserRow, PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png };
|
|
||||||
public static TableColumn<UserRow, byte[]> Picture { get; } = new("picture");
|
|
||||||
public static TableColumn<UserRow, long[]> Roles { get; } = new("roles");
|
|
||||||
public static TableColumn<UserRow, byte[]> Username { get; } = new("username");
|
public static TableColumn<UserRow, byte[]> Username { get; } = new("username");
|
||||||
public static TableColumn<UserRow, byte[]> Password { get; } = new("password");
|
public static TableColumn<UserRow, byte[]> Password { get; } = new("password");
|
||||||
public static TableColumn<UserRow, byte[]> Salt { get; } = new("salt");
|
public static TableColumn<UserRow, byte[]> Salt { get; } = new("salt");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TableRow(typeof(Users))]
|
[TableRow(typeof(Users))]
|
||||||
public partial class UserRow
|
public partial class UserRow;
|
||||||
{}
|
|
@ -5,20 +5,33 @@ namespace LuskiServer.Classes;
|
|||||||
|
|
||||||
public static class Tables
|
public static class Tables
|
||||||
{
|
{
|
||||||
public static Table<UserRow> Users { get; } = new("users", null!);
|
|
||||||
public static Table<AltServerRow> AltServers { get; } = new("alt_servers", null!);
|
public static Table<AltServerRow> AltServers { get; } = new("alt_servers", null!);
|
||||||
public static Table<ServerRow> Server { get; } = new("server", null!);
|
|
||||||
public static Table<RoleRow> Roles { get; } = new("roles", null!);
|
|
||||||
public static Table<LogRow> Logs { get; } = new("logs", null!);
|
|
||||||
public static Table<FileRow> Files { get; } = new("files", null!);
|
|
||||||
public static Table<CategoryRow> Categories { get; } = new("categories", null!);
|
public static Table<CategoryRow> Categories { get; } = new("categories", null!);
|
||||||
|
public static Table<CategoryParentRow> CategoryParents { get; } = new("categories_parents", null!);
|
||||||
|
public static Table<CategoryProfileRow> CategoryProfiles { get; } = new("categories_profiles", null!);
|
||||||
|
public static Table<CategoryRoleOverrideRow> CategoryRoleOverrides { get; } = new("category_role_overrides", null!);
|
||||||
|
public static Table<CategoryUserOverrideRow> CategoryUserOverrides { get; } = new("category_user_overrides", null!);
|
||||||
|
public static Table<ChannelKeyRow> ChannelKeys { get; } = new("channel_keys", null!);
|
||||||
|
public static Table<ChannelProfileRow> ChannelProfiles { get; } = new("channel_profiles", null!);
|
||||||
|
public static Table<ChannelRoleOverrideRow> ChannelRoleOverrides { get; } = new("channel_role_overrides", null!);
|
||||||
public static Table<ChannelRow> Channels { get; } = new("channels", null!);
|
public static Table<ChannelRow> Channels { get; } = new("channels", null!);
|
||||||
|
public static Table<ChannelUserOverrideRow> ChannelUserOverrides { get; } = new("channel_user_overrides", null!);
|
||||||
|
public static Table<FileChannelRow> FileChannels { get; } = new("file_channels", null!);
|
||||||
|
public static Table<FileRow> Files { get; } = new("files", null!);
|
||||||
|
public static Table<KeyRow> Keys { get; } = new("keys", null!);
|
||||||
|
public static Table<LogRow> Logs { get; } = new("logs", null!);
|
||||||
|
public static Table<MessageFileRow> MessageFiles { get; } = new("message_files", null!);
|
||||||
public static Table<MessageRow> Messages { get; } = new("messages", null!);
|
public static Table<MessageRow> Messages { get; } = new("messages", null!);
|
||||||
public static Table<ServerRoleOverrideRow> ServerRoleOverrides { get; } = new("role_overrides", null!);
|
public static Table<OfflineDataRow> OfflineData { get; } = new("offline_data", null!);
|
||||||
public static Table<StorageRow> Storage { get; } = new("storage", null!);
|
public static Table<ProfileColorRow> ProfileColors { get; } = new("profile_colors", null!);
|
||||||
public static Table<UserRoleOverrideRow> UserRoleOverrides { get; } = new("user_overrides", null!);
|
public static Table<ProfileControllerRow> ProfileControllers { get; } = new("profile_controllers", null!);
|
||||||
|
public static Table<ProfileRoleControllerRow> ProfileRoleControllers { get; } = new("profiles_role_controllers", null!);
|
||||||
|
public static Table<ProfileRow> Profiles { get; } = new("profiles", null!);
|
||||||
|
public static Table<RoleMemberRow> RoleMembers { get; } = new("role_members", null!);
|
||||||
|
public static Table<RoleRow> Roles { get; } = new("roles", null!);
|
||||||
|
public static Table<ServerRow> Server { get; } = new("server", null!);
|
||||||
public static Table<SessionsRow> Sessions { get; } = new("sessions", null!);
|
public static Table<SessionsRow> Sessions { get; } = new("sessions", null!);
|
||||||
public static Table<SessionTokenRow> SessionTokens { get; } = new("session_tokens", null!);
|
public static Table<SessionTokenRow> SessionTokens { get; } = new("session_tokens", null!);
|
||||||
public static Table<KeyRow> Keys { get; } = new("keys", null!);
|
public static Table<StorageRow> Storage { get; } = new("storage", null!);
|
||||||
public static Table<ChannelProfileRow> ChannelProfiles { get; } = new("channel_profiles", null!);
|
public static Table<UserRow> Users { get; } = new("users", null!);
|
||||||
}
|
}
|
@ -46,7 +46,7 @@ public class KeysController : ControllerBase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
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.Keys.TryRead(Keys.Owner, out long Owner, Keys.ID.CreateParameter(keyid)) || (Owner != ID || !LuskiFunctions.HasPermissions(ID, ServerPermission.DeleteKeys)))
|
if (!LuskiFunctions.HasPermissions(ID, ServerPermission.DeleteKeys))
|
||||||
return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||||
|
|
||||||
Tables.Keys.DeleteRow(Keys.ID.CreateParameter(keyid));
|
Tables.Keys.DeleteRow(Keys.ID.CreateParameter(keyid));
|
||||||
@ -77,10 +77,9 @@ public class KeysController : 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;
|
||||||
|
|
||||||
LuskiFunctions.Snowflake sf = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch);
|
LuskiFunctions.Snowflake sf = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch);
|
||||||
Console.WriteLine("P");
|
|
||||||
Tables.Keys.Insert(
|
Tables.Keys.Insert(
|
||||||
Keys.ID.CreateParameter(sf.ID),
|
Keys.ID.CreateParameter(sf.ID),
|
||||||
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)));
|
||||||
return StatusCode(202);
|
return StatusCode(202);
|
||||||
@ -104,24 +103,9 @@ public class KeysController : ControllerBase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!Tables.Users.TryRead(Users.ID, out _, Users.ID.CreateParameter(userid))) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
if (!Tables.Users.TryRead(Users.ID, out _, Users.ID.CreateParameter(userid))) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||||
bool UserOnline = Tables.Sessions.TryReadRows(out SessionsRow[] usersessions, Sessions.User.CreateParameter(userid));
|
bool UserOnline = Tables.Sessions.TryReadRows(out SessionsRow[]? usersessions, Sessions.User.CreateParameter(userid));
|
||||||
List<KeyGetSTC> req = new();
|
List<KeyGetSTC> req = new();
|
||||||
if (!UserOnline)
|
if (UserOnline)
|
||||||
{
|
|
||||||
foreach (StorageRow StorageRow in Tables.Storage.ReadRows(uint.MaxValue, Storage.AccountID.CreateParameter(userid)))
|
|
||||||
{
|
|
||||||
KeyRow Row = Tables.Keys.ReadRow(Keys.ID.CreateParameter(StorageRow.OffileKey));
|
|
||||||
req.Add(new KeyGetSTC()
|
|
||||||
{
|
|
||||||
ID = Row.ID,
|
|
||||||
Owner = Row.Owner,
|
|
||||||
EncryptionType = Row.EncryptionType,
|
|
||||||
Data = Convert.ToBase64String(Row.KeyData)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
List<long> b = new();
|
List<long> b = new();
|
||||||
foreach (SessionsRow sess in usersessions)
|
foreach (SessionsRow sess in usersessions)
|
||||||
@ -131,7 +115,6 @@ public class KeysController : ControllerBase
|
|||||||
req.Add(new KeyGetSTC()
|
req.Add(new KeyGetSTC()
|
||||||
{
|
{
|
||||||
ID = Row.ID,
|
ID = Row.ID,
|
||||||
Owner = Row.Owner,
|
|
||||||
EncryptionType = Row.EncryptionType,
|
EncryptionType = Row.EncryptionType,
|
||||||
Data = Convert.ToBase64String(Row.KeyData)
|
Data = Convert.ToBase64String(Row.KeyData)
|
||||||
});
|
});
|
||||||
@ -140,11 +123,23 @@ public class KeysController : ControllerBase
|
|||||||
foreach (StorageRow StorageRow in Tables.Storage.ReadRows(uint.MaxValue, Storage.AccountID.CreateParameter(userid)))
|
foreach (StorageRow StorageRow in Tables.Storage.ReadRows(uint.MaxValue, Storage.AccountID.CreateParameter(userid)))
|
||||||
{
|
{
|
||||||
if (b.Contains(StorageRow.ID)) continue;
|
if (b.Contains(StorageRow.ID)) continue;
|
||||||
KeyRow Row = Tables.Keys.ReadRow(Keys.ID.CreateParameter(StorageRow.OffileKey));
|
KeyRow Row = Tables.Keys.ReadRow(Keys.ID.CreateParameter(StorageRow.OfflineKey));
|
||||||
|
req.Add(new KeyGetSTC()
|
||||||
|
{
|
||||||
|
ID = Row.ID,
|
||||||
|
EncryptionType = Row.EncryptionType,
|
||||||
|
Data = Convert.ToBase64String(Row.KeyData)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (StorageRow StorageRow in Tables.Storage.ReadRows(uint.MaxValue, Storage.AccountID.CreateParameter(userid)))
|
||||||
|
{
|
||||||
|
KeyRow Row = Tables.Keys.ReadRow(Keys.ID.CreateParameter(StorageRow.OfflineKey));
|
||||||
req.Add(new KeyGetSTC()
|
req.Add(new KeyGetSTC()
|
||||||
{
|
{
|
||||||
ID = Row.ID,
|
ID = Row.ID,
|
||||||
Owner = Row.Owner,
|
|
||||||
EncryptionType = Row.EncryptionType,
|
EncryptionType = Row.EncryptionType,
|
||||||
Data = Convert.ToBase64String(Row.KeyData)
|
Data = Convert.ToBase64String(Row.KeyData)
|
||||||
});
|
});
|
||||||
@ -177,7 +172,6 @@ public class KeysController : ControllerBase
|
|||||||
return this.ResponseToResult(new KeyGetSTC()
|
return this.ResponseToResult(new KeyGetSTC()
|
||||||
{
|
{
|
||||||
ID = Row.ID,
|
ID = Row.ID,
|
||||||
Owner = Row.Owner,
|
|
||||||
EncryptionType = Row.EncryptionType,
|
EncryptionType = Row.EncryptionType,
|
||||||
Data = Convert.ToBase64String(Row.KeyData)
|
Data = Convert.ToBase64String(Row.KeyData)
|
||||||
});
|
});
|
||||||
@ -206,21 +200,19 @@ public class KeysController : ControllerBase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
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;
|
||||||
bool f = Tables.Storage.TryRead(Storage.Data, out byte[][]? data, Storage.ID.CreateParameter(StorageID));
|
bool f = Tables.OfflineData.TryRead(OfflineData.Data, out byte[]? data, OfflineData.StorageID.CreateParameter(StorageID));
|
||||||
if (f && data!.Any()) return this.ShowError(ErrorCode.Forbidden, "you cant change your key until you download your data");
|
if (f && data!.Any()) return this.ShowError(ErrorCode.Forbidden, "you cant change your key until you download your data");
|
||||||
long k = 0;
|
long k = 0;
|
||||||
if (Tables.Storage.TryRead(Storage.OffileKey, out k, Storage.ID.CreateParameter(StorageID)) && k !=0)
|
if (Tables.Storage.TryRead(Storage.OfflineKey, out k, Storage.ID.CreateParameter(StorageID)) && k !=0)
|
||||||
{
|
{
|
||||||
Tables.Keys.DeleteRow(Keys.ID.CreateParameter(k));
|
Tables.Keys.DeleteRow(Keys.ID.CreateParameter(k));
|
||||||
}
|
}
|
||||||
LuskiFunctions.Snowflake sf = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch);
|
LuskiFunctions.Snowflake sf = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch);
|
||||||
Console.WriteLine("OO");
|
|
||||||
Tables.Keys.Insert(
|
Tables.Keys.Insert(
|
||||||
Keys.ID.CreateParameter(sf.ID),
|
Keys.ID.CreateParameter(sf.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.CreateCommand().WithFilter(Storage.ID, StorageID).WithValue(Storage.OffileKey, sf.ID);
|
Tables.Storage.CreateCommand().WithFilter(Storage.ID, StorageID).WithValue(Storage.OfflineKey, sf.ID);
|
||||||
return StatusCode(202);
|
return StatusCode(202);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -18,18 +18,21 @@ public class OfflineDataController : ControllerBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine("Storage GET 1: " +SID.ToString());
|
|
||||||
if (!this.CanTokenRequest(out long UID, out long SSID, out IActionResult? toc) && toc != null) return toc;
|
if (!this.CanTokenRequest(out long UID, out long SSID, out IActionResult? toc) && toc != null) return toc;
|
||||||
Console.WriteLine("Storage GET 1: " +SID.ToString());
|
|
||||||
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);
|
||||||
List<string> bbb = new();
|
List<string> bbb = new();
|
||||||
foreach (byte[]? blob in row.Data)
|
if (Tables.OfflineData.TryReadRows(out var rows, OfflineData.StorageID.CreateParameter(SID)))
|
||||||
{
|
{
|
||||||
bbb.Add(Convert.ToBase64String(blob));
|
foreach (var blob in rows)
|
||||||
|
{
|
||||||
|
bbb.Add(Convert.ToBase64String(blob.Data));
|
||||||
}
|
}
|
||||||
Tables.Storage.CreateCommand().WithFilter(Storage.ID, SID).WithValue(Storage.Data, Array.Empty<byte[]>()).Update();
|
}
|
||||||
|
|
||||||
|
Tables.OfflineData.DeleteRow(OfflineData.StorageID.CreateParameter(SID));
|
||||||
|
//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()
|
||||||
@ -47,16 +50,7 @@ public class OfflineDataController : ControllerBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var h in HttpContext.Request.Headers)
|
|
||||||
{
|
|
||||||
foreach (var v in h.Value)
|
|
||||||
{
|
|
||||||
Console.WriteLine(h.Key + ": " + v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Console.WriteLine("Storage GET: " +SID.ToString());
|
|
||||||
if (!this.CanTokenRequest(out long UID, out long SSID, out IActionResult? toc) && toc != null) return toc;
|
if (!this.CanTokenRequest(out long UID, out long SSID, out IActionResult? toc) && toc != null) return toc;
|
||||||
Console.WriteLine("Storage GET: " +SID.ToString());
|
|
||||||
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);
|
||||||
@ -96,9 +90,7 @@ public class OfflineDataController : ControllerBase
|
|||||||
Console.WriteLine(h.Key + ": " + v);
|
Console.WriteLine(h.Key + ": " + v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Console.WriteLine("Storage Patch: " +SID.ToString());
|
|
||||||
if (!this.CanTokenRequest(out long UID, out long SSID, out IActionResult? toc) && toc != null) return toc;
|
if (!this.CanTokenRequest(out long UID, out long SSID, out IActionResult? toc) && toc != null) return toc;
|
||||||
Console.WriteLine("Storage Patch: " +SID.ToString());
|
|
||||||
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);
|
||||||
@ -130,8 +122,7 @@ public class OfflineDataController : ControllerBase
|
|||||||
Storage.ID.CreateParameter(sf.ID),
|
Storage.ID.CreateParameter(sf.ID),
|
||||||
Storage.Password.CreateParameter(Convert.FromBase64String(si.Password)),
|
Storage.Password.CreateParameter(Convert.FromBase64String(si.Password)),
|
||||||
Storage.AccountID.CreateParameter(UID),
|
Storage.AccountID.CreateParameter(UID),
|
||||||
Storage.Data.CreateParameter(Array.Empty<byte[]>()),
|
Storage.OfflineKey.CreateParameter(0));
|
||||||
Storage.OffileKey.CreateParameter(0));
|
|
||||||
Tables.Sessions.CreateCommand().WithFilter(Sessions.ID, sf.ID).WithValue(Sessions.ID, SSID).Update();
|
Tables.Sessions.CreateCommand().WithFilter(Sessions.ID, sf.ID).WithValue(Sessions.ID, SSID).Update();
|
||||||
|
|
||||||
return this.ResponseToResult(new StorageInfoSTC()
|
return this.ResponseToResult(new StorageInfoSTC()
|
||||||
|
@ -79,7 +79,6 @@ public class SocketAccountController : Controller
|
|||||||
Tables.Keys.Insert(
|
Tables.Keys.Insert(
|
||||||
Keys.ID.CreateParameter(kid),
|
Keys.ID.CreateParameter(kid),
|
||||||
Keys.EncryptionType.CreateParameter(EncryptionType.RSA),
|
Keys.EncryptionType.CreateParameter(EncryptionType.RSA),
|
||||||
Keys.Owner.CreateParameter(ID),
|
|
||||||
Keys.KeyData.CreateParameter(Encoding.UTF8.GetBytes(KeyRaw)));
|
Keys.KeyData.CreateParameter(Encoding.UTF8.GetBytes(KeyRaw)));
|
||||||
Thread t = new(o => RegToken((string?)o, kid));
|
Thread t = new(o => RegToken((string?)o, kid));
|
||||||
t.Start(Token);
|
t.Start(Token);
|
||||||
@ -147,7 +146,6 @@ public class SocketAccountController : Controller
|
|||||||
Tables.Keys.Insert(
|
Tables.Keys.Insert(
|
||||||
Keys.ID.CreateParameter(kid),
|
Keys.ID.CreateParameter(kid),
|
||||||
Keys.EncryptionType.CreateParameter(EncryptionType.RSA),
|
Keys.EncryptionType.CreateParameter(EncryptionType.RSA),
|
||||||
Keys.Owner.CreateParameter(ID),
|
|
||||||
Keys.KeyData.CreateParameter(Encoding.UTF8.GetBytes(KeyRaw)));
|
Keys.KeyData.CreateParameter(Encoding.UTF8.GetBytes(KeyRaw)));
|
||||||
Thread t = new(o => RegToken((string?)o, kid));
|
Thread t = new(o => RegToken((string?)o, kid));
|
||||||
t.Start(Token);
|
t.Start(Token);
|
||||||
@ -227,10 +225,43 @@ public class SocketAccountController : Controller
|
|||||||
int num = new Random().Next(1000, 1000000000);
|
int num = new Random().Next(1000, 1000000000);
|
||||||
int num2 = new Random().Next(1000, 1000000000);
|
int num2 = new Random().Next(1000, 1000000000);
|
||||||
LuskiFunctions.Snowflake id = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch);
|
LuskiFunctions.Snowflake id = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch);
|
||||||
|
bool owner = false;
|
||||||
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.CreateCommand().WithValue(Server.Owner, id.ID).Update();
|
Tables.Server.CreateCommand().WithValue(Server.Owner, id.ID).Update();
|
||||||
|
if (!Tables.Keys.TryRead(Keys.ID, out _, Keys.ID.CreateParameter(0)))
|
||||||
|
{
|
||||||
|
Tables.Keys.Insert(
|
||||||
|
Keys.ID.CreateParameter(0),
|
||||||
|
Keys.EncryptionType.CreateParameter(EncryptionType.None),
|
||||||
|
Keys.KeyData.CreateParameter(Array.Empty<byte>()));
|
||||||
|
}
|
||||||
|
if (!Tables.Categories.TryRead(Categories.ID, out _, Categories.ID.CreateParameter(0)))
|
||||||
|
{
|
||||||
|
Tables.Categories.Insert(
|
||||||
|
Categories.ID.CreateParameter(0),
|
||||||
|
Categories.Name.CreateParameter(Encoding.UTF8.GetBytes("server")),
|
||||||
|
Categories.Description.CreateParameter(
|
||||||
|
Encoding.UTF8.GetBytes("The default category for the server. Everybody will see this category."))
|
||||||
|
);
|
||||||
|
Tables.Channels.Insert(
|
||||||
|
Channels.ID.CreateParameter(0),
|
||||||
|
Channels.Type.CreateParameter(ChannelType.TextAndVoice),
|
||||||
|
Channels.Description.CreateParameter(Encoding.UTF8.GetBytes("Default chat for you to use in your new server")),
|
||||||
|
Channels.Name.CreateParameter(Encoding.UTF8.GetBytes("Default Channel")),
|
||||||
|
Channels.Epoch.CreateParameter(DateTime.UtcNow.Date),
|
||||||
|
Channels.TitleEncryptionKey.CreateParameter(0),
|
||||||
|
Channels.Parent.CreateParameter(0),
|
||||||
|
Channels.DescriptionEncryptionKey.CreateParameter(0),
|
||||||
|
Channels.TitleEncoderType.CreateParameter(EncoderType.UTF8),
|
||||||
|
Channels.DescriptionEncoderType.CreateParameter(EncoderType.UTF8),
|
||||||
|
Channels.PictureType.CreateParameter(PictureType.none),
|
||||||
|
Channels.Picture.CreateParameter(Array.Empty<byte>()),
|
||||||
|
Channels.EncoderTypes.CreateParameter(new [] { EncoderType.UTF8 }));
|
||||||
|
Tables.ChannelKeys.Insert(ChannelKeys.Channel.CreateParameter(0), ChannelKeys.Key.CreateParameter(0));
|
||||||
|
}
|
||||||
|
owner = true;
|
||||||
}
|
}
|
||||||
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());
|
||||||
@ -241,25 +272,31 @@ public class SocketAccountController : Controller
|
|||||||
pfp = GetProfilePictureType(Encoding.UTF8.GetString(Body).ToUpper());
|
pfp = GetProfilePictureType(Encoding.UTF8.GetString(Body).ToUpper());
|
||||||
long uid = id.ID;
|
long uid = id.ID;
|
||||||
long kid = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch).ID;
|
long kid = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch).ID;
|
||||||
|
long pid = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch).ID;
|
||||||
|
Tables.Profiles.Insert(
|
||||||
|
Profiles.DisplayName.CreateParameter(DisplayName!.Replace("'", "\'")),
|
||||||
|
Profiles.ID.CreateParameter(pid),
|
||||||
|
Profiles.PictureType.CreateParameter(pfp),
|
||||||
|
Profiles.Picture.CreateParameter(Body),
|
||||||
|
Profiles.CanUpdateName.CreateParameter(true));
|
||||||
Tables.Users.Insert(
|
Tables.Users.Insert(
|
||||||
Users.ID.CreateParameter(uid),
|
Users.ID.CreateParameter(uid),
|
||||||
Users.DisplayName.CreateParameter(DisplayName!.Replace("'", "\'")),
|
Users.ServerProfile.CreateParameter(pid),
|
||||||
Users.SelectedChannel.CreateParameter(0), //TODO set to default channel
|
Users.SelectedChannel.CreateParameter(0), //TODO set to default channel
|
||||||
Users.Status.CreateParameter(UserStatus.Online),
|
Users.Status.CreateParameter(UserStatus.Online),
|
||||||
Users.PictureType.CreateParameter(pfp),
|
|
||||||
Users.Picture.CreateParameter(Body),
|
|
||||||
Users.Roles.CreateParameter(new long[] {0}),
|
|
||||||
Users.Username.CreateParameter(Username),
|
Users.Username.CreateParameter(Username),
|
||||||
Users.Password.CreateParameter(PasBytes),
|
Users.Password.CreateParameter(PasBytes),
|
||||||
Users.Salt.CreateParameter(salt));
|
Users.Salt.CreateParameter(salt));
|
||||||
List<long> old = Tables.Roles.Read(Roles.MembersList, Roles.ID.CreateParameter(0)).ToList();
|
Tables.RoleMembers.Insert(RoleMembers.Role.CreateParameter(0), RoleMembers.User.CreateParameter(uid));
|
||||||
old.Add(uid);
|
Tables.ProfileControllers.Insert(
|
||||||
Tables.Roles.CreateCommand().WithFilter(Roles.ID, 0).WithValue(Roles.MembersList,old.ToArray()).Update();
|
ProfileControllers.Profile.CreateParameter(pid),
|
||||||
Console.WriteLine("A");
|
ProfileControllers.User.CreateParameter(uid));
|
||||||
|
Tables.CategoryProfiles.Insert(
|
||||||
|
CategoryProfiles.Profile.CreateParameter(pid),
|
||||||
|
CategoryProfiles.Category.CreateParameter(0));
|
||||||
Tables.Keys.Insert(
|
Tables.Keys.Insert(
|
||||||
Keys.ID.CreateParameter(kid),
|
Keys.ID.CreateParameter(kid),
|
||||||
Keys.EncryptionType.CreateParameter(EncryptionType.RSA),
|
Keys.EncryptionType.CreateParameter(EncryptionType.RSA),
|
||||||
Keys.Owner.CreateParameter(uid),
|
|
||||||
Keys.KeyData.CreateParameter(Encoding.UTF8.GetBytes(KeyRaw)));
|
Keys.KeyData.CreateParameter(Encoding.UTF8.GetBytes(KeyRaw)));
|
||||||
Thread t = new(o => RegToken((string?)o, kid));
|
Thread t = new(o => RegToken((string?)o, kid));
|
||||||
t.Start(Token);
|
t.Start(Token);
|
||||||
|
@ -51,13 +51,12 @@ public class SocketBulkMessageController : ControllerBase
|
|||||||
}
|
}
|
||||||
SocketBulkMessageSTC all = new();
|
SocketBulkMessageSTC all = new();
|
||||||
List<MessageSTC> mmmm = new List<MessageSTC>();
|
List<MessageSTC> mmmm = new List<MessageSTC>();
|
||||||
if (MostRecentID != null)
|
if (MostRecentID != null && Tables.Messages.CreateCommand()
|
||||||
|
.WithFilter(Messages.ID, long.Parse(MostRecentID), sign)
|
||||||
|
.WithFilter(Messages.ChannelID, Channel_Id)
|
||||||
|
.DescendBy(Messages.Timestamp)
|
||||||
|
.TryReadRows(out MessageRow[]? rawmsgs))
|
||||||
{
|
{
|
||||||
MessageRow[] rawmsgs = Tables.Messages.ReadRows((uint)MessagesToDownload,
|
|
||||||
Messages.ID.GetDecendingOrder(),
|
|
||||||
Messages.ID.CreateParameter(long.Parse(MostRecentID), sign),
|
|
||||||
Messages.ChannelID.CreateParameter(Channel_Id));
|
|
||||||
|
|
||||||
foreach (MessageRow Row in rawmsgs)
|
foreach (MessageRow Row in rawmsgs)
|
||||||
{
|
{
|
||||||
MessageSTC temp = new()
|
MessageSTC temp = new()
|
||||||
@ -66,26 +65,28 @@ public class SocketBulkMessageController : ControllerBase
|
|||||||
EncoderType = Row.EncoderType,
|
EncoderType = Row.EncoderType,
|
||||||
EncryptionKey = Row.EncryptionKey,
|
EncryptionKey = Row.EncryptionKey,
|
||||||
ChannelID = Row.ChannelID,
|
ChannelID = Row.ChannelID,
|
||||||
|
ProfileID = Row.ProfileID,
|
||||||
AuthorID = Row.AuthorID,
|
AuthorID = Row.AuthorID,
|
||||||
ID = Row.ID,
|
ID = Row.ID,
|
||||||
Files = Array.Empty<ServerFileInfoSTC>(),
|
Files = Array.Empty<ServerFileInfoSTC>(),
|
||||||
IsProfile = Row.IsChannelProfile,
|
Timestamp = Row.Timestamp
|
||||||
};
|
};
|
||||||
if (Row.Files.Any())
|
|
||||||
|
if (Tables.MessageFiles.CreateCommand().WithFilter(MessageFiles.MessageID, Row.ID)
|
||||||
|
.WithCrossTableCheck(MessageFiles.FileID, Tables.Files, Files.ID).TryReadRows(out FileRow[]? rows))
|
||||||
{
|
{
|
||||||
List<ServerFileInfoSTC> list = new();
|
List<ServerFileInfoSTC> list = new();
|
||||||
foreach (long b in Row.Files)
|
foreach (FileRow b in rows)
|
||||||
{
|
{
|
||||||
FileRow fileraw = Tables.Files.ReadRow(Files.ID.CreateParameter(b));
|
|
||||||
ServerFileInfoSTC file = new()
|
ServerFileInfoSTC file = new()
|
||||||
{
|
{
|
||||||
ID = b,
|
ID = b.ID,
|
||||||
Name = Convert.ToBase64String(fileraw.Name),
|
Name = Convert.ToBase64String(b.Name),
|
||||||
Size = fileraw.Size,
|
Size = b.Size,
|
||||||
NameEncoder = fileraw.NameEncoderType,
|
NameEncoder = b.NameEncoderType,
|
||||||
NameKey = fileraw.NameEncryptionKey,
|
NameKey = b.NameEncryptionKey,
|
||||||
Encoder = fileraw.EncoderType,
|
Encoder = b.EncoderType,
|
||||||
Key = fileraw.EncryptionKey,
|
Key = b.EncryptionKey,
|
||||||
};
|
};
|
||||||
list.Add(file);
|
list.Add(file);
|
||||||
}
|
}
|
||||||
|
@ -22,58 +22,82 @@ 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, ChanReq.Parent, out ServerPermission opt, ServerPermission.CreateCategories)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
if (!LuskiFunctions.HasAccessToCategory(ID, ChanReq.Parent, out ServerPermission opt, ServerPermission.CreateCategories)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||||
DateTime epoch = LuskiFunctions.Config.ServerEpoch;
|
DateTime epoch = LuskiFunctions.Config.ServerEpoch;
|
||||||
List<long> RoleOverides = new(), UserOverides = new();
|
|
||||||
|
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)),
|
||||||
|
Categories.TitleEncryptionKey.CreateParameter(ChanReq.TitleEncryptionKey),
|
||||||
|
Categories.DescriptionEncryptionKey.CreateParameter(ChanReq.DescriptionEncryptionKey),
|
||||||
|
Categories.TitleEncoderType.CreateParameter(ChanReq.TitleEncoderType),
|
||||||
|
Categories.DescriptionEncoderType.CreateParameter(ChanReq.DescriptionEncoderType));
|
||||||
|
Tables.CategoryParents.Insert(CategoryParents.Parent.CreateParameter(ChanReq.Parent), CategoryParents.ID.CreateParameter(chanSnowflake.ID));
|
||||||
|
|
||||||
if (ChanReq.RoleOverrides.Length > 0)
|
if (ChanReq.RoleOverrides.Length > 0)
|
||||||
{
|
{
|
||||||
foreach (UserRoleOverrideCTS over in ChanReq.RoleOverrides)
|
foreach (RoleOverrideCTS over in ChanReq.RoleOverrides)
|
||||||
{
|
{
|
||||||
LuskiFunctions.Snowflake overSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch);
|
Tables.CategoryRoleOverrides.Insert(
|
||||||
Tables.ServerRoleOverrides.Insert(
|
CategoryRoleOverrides.Category.CreateParameter(chanSnowflake.ID),
|
||||||
ServerRoleOverrides.ID.CreateParameter(overSnowflake.ID),
|
CategoryRoleOverrides.RoleOverride.CreateParameter(over.RoleID),
|
||||||
ServerRoleOverrides.RoleID.CreateParameter(over.RoleID),
|
CategoryRoleOverrides.GoodPermissions.CreateParameter(over.GoodPermissions),
|
||||||
ServerRoleOverrides.GoodPermissions.CreateParameter(over.GoodPermissions),
|
CategoryRoleOverrides.BadPermissions.CreateParameter(over.BadPermissions));
|
||||||
ServerRoleOverrides.BadPermissions.CreateParameter(over.BadPermissions));
|
|
||||||
RoleOverides.Add(overSnowflake.ID);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ChanReq.UserOverrides.Length > 0)
|
if (ChanReq.UserOverrides.Length > 0)
|
||||||
{
|
{
|
||||||
foreach (UserOverrideCTS over in ChanReq.UserOverrides)
|
foreach (UserOverrideCTS over in ChanReq.UserOverrides)
|
||||||
{
|
{
|
||||||
LuskiFunctions.Snowflake overSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch);
|
Tables.CategoryUserOverrides.Insert(
|
||||||
Tables.UserRoleOverrides.Insert(
|
CategoryUserOverrides.Category.CreateParameter(chanSnowflake.ID),
|
||||||
UserRoleOverrides.ID.CreateParameter(overSnowflake.ID),
|
CategoryUserOverrides.UserOverride.CreateParameter(over.UserID),
|
||||||
UserRoleOverrides.UserID.CreateParameter(over.UserID),
|
CategoryUserOverrides.GoodPermissions.CreateParameter(over.GoodPermissions),
|
||||||
UserRoleOverrides.GoodPermissions.CreateParameter(over.GoodPermissions),
|
CategoryUserOverrides.BadPermissions.CreateParameter(over.BadPermissions));
|
||||||
UserRoleOverrides.BadPermissions.CreateParameter(over.BadPermissions));
|
|
||||||
UserOverides.Add(overSnowflake.ID);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
epoch = DateTime.UtcNow.Date;
|
|
||||||
LuskiFunctions.Snowflake chanSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch);
|
|
||||||
Tables.Categories.Insert(
|
|
||||||
Categories.ID.CreateParameter(chanSnowflake.ID),
|
|
||||||
Categories.Parent.CreateParameter(ChanReq.Parent),
|
|
||||||
Categories.Name.CreateParameter(Convert.FromBase64String(ChanReq.Name)),
|
|
||||||
Categories.Description.CreateParameter(Convert.FromBase64String(ChanReq.Description)),
|
|
||||||
Categories.RoleOverrides.CreateParameter(RoleOverides.ToArray()),
|
|
||||||
Categories.UserOverrides.CreateParameter(UserOverides.ToArray()),
|
|
||||||
Categories.TitleEncryptionKey.CreateParameter(ChanReq.TitleEncryptionKey),
|
|
||||||
Categories.DescriptionEncryptionKey.CreateParameter(ChanReq.DescriptionEncryptionKey),
|
|
||||||
Categories.TitleEncoderType.CreateParameter(ChanReq.TitleEncoderType),
|
|
||||||
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));
|
||||||
long[] ic = Array.Empty<long>();
|
long[] ic = Array.Empty<long>();
|
||||||
long[] c = Array.Empty<long>();
|
long[] c = Array.Empty<long>();
|
||||||
if (!opt.HasPermission(ServerPermission.ViewCategories))
|
if (!opt.HasPermission(ServerPermission.ViewCategories))
|
||||||
{
|
{
|
||||||
ic = Tables.Categories.ReadColumn(Categories.ID, Categories.Parent.CreateParameter(chanSnowflake.ID));
|
ic = Tables.CategoryParents.ReadColumn(CategoryParents.ID, CategoryParents.Parent.CreateParameter(chanSnowflake.ID));
|
||||||
}
|
}
|
||||||
if (!opt.HasPermission(ServerPermission.ViewChannels))
|
if (!opt.HasPermission(ServerPermission.ViewChannels))
|
||||||
{
|
{
|
||||||
c = LuskiFunctions.GetCategoryChannels(chanSnowflake.ID, ID);
|
c = LuskiFunctions.GetCategoryChannels(chanSnowflake.ID, ID);
|
||||||
}
|
}
|
||||||
|
List<RoleOverrideSTC> RO = new();
|
||||||
|
List<UserOverrideSTC> UO = new();
|
||||||
|
foreach (var over in Tables.CategoryRoleOverrides.ReadRows(CategoryRoleOverrides.Category.CreateParameter(chanSnowflake.ID)))
|
||||||
|
{
|
||||||
|
RO.Add(new()
|
||||||
|
{
|
||||||
|
RoleID = over.RoleOverride,
|
||||||
|
BadPermissions = over.BadPermissions,
|
||||||
|
GoodPermissions = over.GoodPermissions
|
||||||
|
});
|
||||||
|
}
|
||||||
|
foreach (var over in Tables.CategoryUserOverrides.ReadRows(CategoryUserOverrides.Category.CreateParameter(chanSnowflake.ID)))
|
||||||
|
{
|
||||||
|
UO.Add(new()
|
||||||
|
{
|
||||||
|
UserID = over.UserOverride,
|
||||||
|
BadPermissions = over.BadPermissions,
|
||||||
|
GoodPermissions = over.GoodPermissions
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
long Parent = -1;
|
||||||
|
if (Tables.CategoryParents.TryRead(CategoryParents.Parent, out long s,
|
||||||
|
CategoryParents.ID.CreateParameter(chan.ID)))
|
||||||
|
{
|
||||||
|
Parent = s;
|
||||||
|
}
|
||||||
|
|
||||||
return this.ResponseToResult(new CategorySTC()
|
return this.ResponseToResult(new CategorySTC()
|
||||||
{
|
{
|
||||||
Name = Convert.ToBase64String(chan.Name),
|
Name = Convert.ToBase64String(chan.Name),
|
||||||
@ -81,13 +105,122 @@ public class SocketCategoryController : ControllerBase
|
|||||||
ID = chanSnowflake.ID,
|
ID = chanSnowflake.ID,
|
||||||
Channels = c,
|
Channels = c,
|
||||||
InnerCategories = ic,
|
InnerCategories = ic,
|
||||||
Parent = chan.Parent,
|
Parent = Parent,
|
||||||
TitleEncryptionKey = chan.TitleEncryptionKey,
|
TitleEncryptionKey = chan.TitleEncryptionKey,
|
||||||
DescriptionEncryptionKey = chan.DescriptionEncryptionKey,
|
DescriptionEncryptionKey = chan.DescriptionEncryptionKey,
|
||||||
TitleEncoderType = chan.TitleEncoderType,
|
TitleEncoderType = chan.TitleEncoderType,
|
||||||
DescriptionEncoderType = chan.DescriptionEncoderType,
|
DescriptionEncoderType = chan.DescriptionEncoderType,
|
||||||
UserOverrides = chan.UserOverrides,
|
UserOverrides = UO.ToArray(),
|
||||||
RoleOverrides = chan.RoleOverrides,
|
RoleOverrides = RO.ToArray(),
|
||||||
|
ColorType = chan.ColorType,
|
||||||
|
Color = Convert.ToHexString(chan.Color)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return this.ShowError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Route(LuskiFunctions.Info.Routes.Default.Base + "/Upload/Matrix")]
|
||||||
|
public IActionResult PostMatrix([FromHeader(Name = "channel")]CategoryPostCTS ChanReq)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||||
|
if (!LuskiFunctions.HasAccessToCategory(ID, ChanReq.Parent, out ServerPermission opt, ServerPermission.CreateCategories)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||||
|
DateTime epoch = LuskiFunctions.Config.ServerEpoch;
|
||||||
|
|
||||||
|
epoch = DateTime.UtcNow.Date;
|
||||||
|
LuskiFunctions.Snowflake chanSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch);
|
||||||
|
Tables.Categories.Insert(
|
||||||
|
Categories.ID.CreateParameter(chanSnowflake.ID),
|
||||||
|
Categories.Name.CreateParameter(Convert.FromBase64String(ChanReq.Name)),
|
||||||
|
Categories.Description.CreateParameter(Convert.FromBase64String(ChanReq.Description)),
|
||||||
|
Categories.TitleEncryptionKey.CreateParameter(ChanReq.TitleEncryptionKey),
|
||||||
|
Categories.DescriptionEncryptionKey.CreateParameter(ChanReq.DescriptionEncryptionKey),
|
||||||
|
Categories.TitleEncoderType.CreateParameter(ChanReq.TitleEncoderType),
|
||||||
|
Categories.DescriptionEncoderType.CreateParameter(ChanReq.DescriptionEncoderType));
|
||||||
|
Tables.CategoryParents.Insert(CategoryParents.Parent.CreateParameter(ChanReq.Parent), CategoryParents.ID.CreateParameter(chanSnowflake.ID));
|
||||||
|
|
||||||
|
if (ChanReq.RoleOverrides.Length > 0)
|
||||||
|
{
|
||||||
|
foreach (RoleOverrideCTS over in ChanReq.RoleOverrides)
|
||||||
|
{
|
||||||
|
Tables.CategoryRoleOverrides.Insert(
|
||||||
|
CategoryRoleOverrides.Category.CreateParameter(chanSnowflake.ID),
|
||||||
|
CategoryRoleOverrides.RoleOverride.CreateParameter(over.RoleID),
|
||||||
|
CategoryRoleOverrides.GoodPermissions.CreateParameter(over.GoodPermissions),
|
||||||
|
CategoryRoleOverrides.BadPermissions.CreateParameter(over.BadPermissions));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ChanReq.UserOverrides.Length > 0)
|
||||||
|
{
|
||||||
|
foreach (UserOverrideCTS over in ChanReq.UserOverrides)
|
||||||
|
{
|
||||||
|
Tables.CategoryUserOverrides.Insert(
|
||||||
|
CategoryUserOverrides.Category.CreateParameter(chanSnowflake.ID),
|
||||||
|
CategoryUserOverrides.UserOverride.CreateParameter(over.UserID),
|
||||||
|
CategoryUserOverrides.GoodPermissions.CreateParameter(over.GoodPermissions),
|
||||||
|
CategoryUserOverrides.BadPermissions.CreateParameter(over.BadPermissions));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CategoryRow chan = Tables.Categories.ReadRow(Categories.ID.CreateParameter(chanSnowflake.ID));
|
||||||
|
long[] ic = Array.Empty<long>();
|
||||||
|
long[] c = Array.Empty<long>();
|
||||||
|
if (!opt.HasPermission(ServerPermission.ViewCategories))
|
||||||
|
{
|
||||||
|
ic = Tables.CategoryParents.ReadColumn(CategoryParents.ID, CategoryParents.Parent.CreateParameter(chanSnowflake.ID));
|
||||||
|
}
|
||||||
|
if (!opt.HasPermission(ServerPermission.ViewChannels))
|
||||||
|
{
|
||||||
|
c = LuskiFunctions.GetCategoryChannels(chanSnowflake.ID, ID);
|
||||||
|
}
|
||||||
|
List<RoleOverrideSTC> RO = new();
|
||||||
|
List<UserOverrideSTC> UO = new();
|
||||||
|
foreach (var over in Tables.CategoryRoleOverrides.ReadRows(CategoryRoleOverrides.Category.CreateParameter(chanSnowflake.ID)))
|
||||||
|
{
|
||||||
|
RO.Add(new()
|
||||||
|
{
|
||||||
|
RoleID = over.RoleOverride,
|
||||||
|
BadPermissions = over.BadPermissions,
|
||||||
|
GoodPermissions = over.GoodPermissions
|
||||||
|
});
|
||||||
|
}
|
||||||
|
foreach (var over in Tables.CategoryUserOverrides.ReadRows(CategoryUserOverrides.Category.CreateParameter(chanSnowflake.ID)))
|
||||||
|
{
|
||||||
|
UO.Add(new()
|
||||||
|
{
|
||||||
|
UserID = over.UserOverride,
|
||||||
|
BadPermissions = over.BadPermissions,
|
||||||
|
GoodPermissions = over.GoodPermissions
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
long Parent = -1;
|
||||||
|
if (Tables.CategoryParents.TryRead(CategoryParents.Parent, out long s,
|
||||||
|
CategoryParents.ID.CreateParameter(chan.ID)))
|
||||||
|
{
|
||||||
|
Parent = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.ResponseToResult(new CategorySTC()
|
||||||
|
{
|
||||||
|
Name = Convert.ToBase64String(chan.Name),
|
||||||
|
Description = Convert.ToBase64String(chan.Description),
|
||||||
|
ID = chanSnowflake.ID,
|
||||||
|
Channels = c,
|
||||||
|
InnerCategories = ic,
|
||||||
|
Parent = Parent,
|
||||||
|
TitleEncryptionKey = chan.TitleEncryptionKey,
|
||||||
|
DescriptionEncryptionKey = chan.DescriptionEncryptionKey,
|
||||||
|
TitleEncoderType = chan.TitleEncoderType,
|
||||||
|
DescriptionEncoderType = chan.DescriptionEncoderType,
|
||||||
|
UserOverrides = UO.ToArray(),
|
||||||
|
RoleOverrides = RO.ToArray(),
|
||||||
|
ColorType = chan.ColorType,
|
||||||
Color = Convert.ToHexString(chan.Color)
|
Color = Convert.ToHexString(chan.Color)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -135,7 +268,7 @@ public class SocketCategoryController : ControllerBase
|
|||||||
long[] c = Array.Empty<long>();
|
long[] c = Array.Empty<long>();
|
||||||
if (!opt.HasPermission(ServerPermission.ViewCategories))
|
if (!opt.HasPermission(ServerPermission.ViewCategories))
|
||||||
{
|
{
|
||||||
ic = Tables.Categories.ReadColumn(Categories.ID, Categories.Parent.CreateParameter(Channel)).ToList();
|
ic = Tables.CategoryParents.ReadColumn(CategoryParents.ID, CategoryParents.Parent.CreateParameter(Channel)).ToList();
|
||||||
}
|
}
|
||||||
if (!opt.HasPermission(ServerPermission.ViewChannels))
|
if (!opt.HasPermission(ServerPermission.ViewChannels))
|
||||||
{
|
{
|
||||||
@ -146,6 +279,32 @@ public class SocketCategoryController : ControllerBase
|
|||||||
{
|
{
|
||||||
if (!LuskiFunctions.HasAccessToChannel(ID, cc)) ic.Remove(cc);
|
if (!LuskiFunctions.HasAccessToChannel(ID, cc)) ic.Remove(cc);
|
||||||
}
|
}
|
||||||
|
List<RoleOverrideSTC> RO = new();
|
||||||
|
List<UserOverrideSTC> UO = new();
|
||||||
|
foreach (var over in Tables.CategoryRoleOverrides.ReadRows(CategoryRoleOverrides.Category.CreateParameter(chan.ID)))
|
||||||
|
{
|
||||||
|
RO.Add(new()
|
||||||
|
{
|
||||||
|
RoleID = over.RoleOverride,
|
||||||
|
BadPermissions = over.BadPermissions,
|
||||||
|
GoodPermissions = over.GoodPermissions
|
||||||
|
});
|
||||||
|
}
|
||||||
|
foreach (var over in Tables.CategoryUserOverrides.ReadRows(CategoryUserOverrides.Category.CreateParameter(chan.ID)))
|
||||||
|
{
|
||||||
|
UO.Add(new()
|
||||||
|
{
|
||||||
|
UserID = over.UserOverride,
|
||||||
|
BadPermissions = over.BadPermissions,
|
||||||
|
GoodPermissions = over.GoodPermissions
|
||||||
|
});
|
||||||
|
}
|
||||||
|
long Parent = -1;
|
||||||
|
if (Tables.CategoryParents.TryRead(CategoryParents.Parent, out long s,
|
||||||
|
CategoryParents.ID.CreateParameter(chan.ID)))
|
||||||
|
{
|
||||||
|
Parent = s;
|
||||||
|
}
|
||||||
return this.ResponseToResult(new CategorySTC()
|
return this.ResponseToResult(new CategorySTC()
|
||||||
{
|
{
|
||||||
Name = Convert.ToBase64String(chan.Name),
|
Name = Convert.ToBase64String(chan.Name),
|
||||||
@ -153,13 +312,14 @@ public class SocketCategoryController : ControllerBase
|
|||||||
ID = Channel,
|
ID = Channel,
|
||||||
Channels = c,
|
Channels = c,
|
||||||
InnerCategories = ic.ToArray(),
|
InnerCategories = ic.ToArray(),
|
||||||
Parent = chan.Parent,
|
Parent = Parent,
|
||||||
TitleEncryptionKey = chan.TitleEncryptionKey,
|
TitleEncryptionKey = chan.TitleEncryptionKey,
|
||||||
DescriptionEncryptionKey = chan.DescriptionEncryptionKey,
|
DescriptionEncryptionKey = chan.DescriptionEncryptionKey,
|
||||||
TitleEncoderType = chan.TitleEncoderType,
|
TitleEncoderType = chan.TitleEncoderType,
|
||||||
DescriptionEncoderType = chan.DescriptionEncoderType,
|
DescriptionEncoderType = chan.DescriptionEncoderType,
|
||||||
UserOverrides = chan.UserOverrides,
|
UserOverrides = UO.ToArray(),
|
||||||
RoleOverrides = chan.RoleOverrides,
|
RoleOverrides = RO.ToArray(),
|
||||||
|
ColorType = chan.ColorType,
|
||||||
Color = Convert.ToHexString(chan.Color)
|
Color = Convert.ToHexString(chan.Color)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -21,57 +21,80 @@ public class SocketChannelController : 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, ChanReq.Parent, ServerPermission.CreateChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
if (!LuskiFunctions.HasAccessToCategory(ID, ChanReq.Parent, ServerPermission.CreateChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||||
DateTime epoch = LuskiFunctions.Config.ServerEpoch;
|
DateTime epoch = LuskiFunctions.Config.ServerEpoch;
|
||||||
List<long> RoleOverides = new(), UserOverides = new();
|
//List<long> RoleOverides = new(), UserOverides = new();
|
||||||
if (ChanReq.RoleOverrides.Length > 0)
|
|
||||||
{
|
|
||||||
foreach (UserRoleOverrideCTS over in ChanReq.RoleOverrides)
|
|
||||||
{
|
|
||||||
LuskiFunctions.Snowflake overSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch);
|
|
||||||
Tables.ServerRoleOverrides.Insert(
|
|
||||||
ServerRoleOverrides.ID.CreateParameter(overSnowflake.ID),
|
|
||||||
ServerRoleOverrides.RoleID.CreateParameter(over.RoleID),
|
|
||||||
ServerRoleOverrides.GoodPermissions.CreateParameter(over.GoodPermissions),
|
|
||||||
ServerRoleOverrides.BadPermissions.CreateParameter(over.BadPermissions));
|
|
||||||
RoleOverides.Add(overSnowflake.ID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ChanReq.UserOverrides.Length > 0)
|
|
||||||
{
|
|
||||||
foreach (UserOverrideCTS over in ChanReq.UserOverrides)
|
|
||||||
{
|
|
||||||
LuskiFunctions.Snowflake overSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch);
|
|
||||||
Tables.UserRoleOverrides.Insert(
|
|
||||||
UserRoleOverrides.ID.CreateParameter(overSnowflake.ID),
|
|
||||||
UserRoleOverrides.UserID.CreateParameter(over.UserID),
|
|
||||||
UserRoleOverrides.GoodPermissions.CreateParameter(over.GoodPermissions),
|
|
||||||
UserRoleOverrides.BadPermissions.CreateParameter(over.BadPermissions));
|
|
||||||
UserOverides.Add(overSnowflake.ID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
epoch = DateTime.UtcNow.Date;
|
epoch = DateTime.UtcNow.Date;
|
||||||
LuskiFunctions.Snowflake chanSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch);
|
LuskiFunctions.Snowflake chanSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch);
|
||||||
Tables.Channels.Insert(
|
Tables.Channels.Insert(
|
||||||
Channels.ID.CreateParameter(chanSnowflake.ID),
|
Channels.ID.CreateParameter(chanSnowflake.ID),
|
||||||
Channels.Parent.CreateParameter(ChanReq.Parent),
|
Channels.Parent.CreateParameter(ChanReq.Parent),
|
||||||
|
Channels.ColorType.CreateParameter(ChanReq.ColorType),
|
||||||
Channels.Color.CreateParameter(Convert.FromHexString(ChanReq.Color)),
|
Channels.Color.CreateParameter(Convert.FromHexString(ChanReq.Color)),
|
||||||
Channels.Type.CreateParameter(ChanReq.Type),
|
Channels.Type.CreateParameter(ChanReq.Type),
|
||||||
Channels.Epoch.CreateParameter(epoch.Date),
|
Channels.Epoch.CreateParameter(epoch.Date),
|
||||||
Channels.Name.CreateParameter(Convert.FromBase64String(ChanReq.Name)),
|
Channels.Name.CreateParameter(Convert.FromBase64String(ChanReq.Name)),
|
||||||
Channels.Description.CreateParameter(Convert.FromBase64String(ChanReq.Description)),
|
Channels.Description.CreateParameter(Convert.FromBase64String(ChanReq.Description)),
|
||||||
Channels.RoleOverrides.CreateParameter(RoleOverides.ToArray()),
|
|
||||||
Channels.UserOverrides.CreateParameter(UserOverides.ToArray()),
|
|
||||||
Channels.TitleEncryptionKey.CreateParameter(ChanReq.TitleEncryptionKey),
|
Channels.TitleEncryptionKey.CreateParameter(ChanReq.TitleEncryptionKey),
|
||||||
Channels.DescriptionEncryptionKey.CreateParameter(ChanReq.DescriptionEncryptionKey),
|
Channels.DescriptionEncryptionKey.CreateParameter(ChanReq.DescriptionEncryptionKey),
|
||||||
Channels.EncryptionKeys.CreateParameter(ChanReq.EncryptionKeys),
|
|
||||||
Channels.TitleEncoderType.CreateParameter(ChanReq.TitleEncoderType),
|
Channels.TitleEncoderType.CreateParameter(ChanReq.TitleEncoderType),
|
||||||
Channels.DescriptionEncoderType.CreateParameter(ChanReq.DescriptionEncoderType),
|
Channels.DescriptionEncoderType.CreateParameter(ChanReq.DescriptionEncoderType),
|
||||||
Channels.PictureType.CreateParameter(PictureType.none),
|
Channels.PictureType.CreateParameter(PictureType.none),
|
||||||
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>()));
|
foreach (long ek in ChanReq.EncryptionKeys)
|
||||||
|
{
|
||||||
|
Tables.ChannelKeys.Insert(ChannelKeys.Channel.CreateParameter(chanSnowflake.ID), ChannelKeys.Key.CreateParameter(ek));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ChanReq.RoleOverrides.Length > 0)
|
||||||
|
{
|
||||||
|
foreach (RoleOverrideCTS over in ChanReq.RoleOverrides)
|
||||||
|
{
|
||||||
|
Tables.ChannelRoleOverrides.Insert(
|
||||||
|
ChannelRoleOverrides.Channel.CreateParameter(chanSnowflake.ID),
|
||||||
|
ChannelRoleOverrides.RoleOverride.CreateParameter(over.RoleID),
|
||||||
|
ChannelRoleOverrides.GoodPermissions.CreateParameter(over.GoodPermissions),
|
||||||
|
ChannelRoleOverrides.BadPermissions.CreateParameter(over.BadPermissions));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ChanReq.UserOverrides.Length > 0)
|
||||||
|
{
|
||||||
|
foreach (UserOverrideCTS over in ChanReq.UserOverrides)
|
||||||
|
{
|
||||||
|
Tables.ChannelUserOverrides.Insert(
|
||||||
|
ChannelUserOverrides.Channel.CreateParameter(chanSnowflake.ID),
|
||||||
|
ChannelUserOverrides.UserOverride.CreateParameter(over.UserID),
|
||||||
|
ChannelUserOverrides.GoodPermissions.CreateParameter(over.GoodPermissions),
|
||||||
|
ChannelUserOverrides.BadPermissions.CreateParameter(over.BadPermissions));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ChannelRow chan = Tables.Channels.ReadRow(Channels.ID.CreateParameter(chanSnowflake.ID));
|
ChannelRow chan = Tables.Channels.ReadRow(Channels.ID.CreateParameter(chanSnowflake.ID));
|
||||||
|
List<RoleOverrideSTC> RO = new();
|
||||||
|
List<UserOverrideSTC> UO = new();
|
||||||
|
foreach (var over in Tables.ChannelRoleOverrides.ReadRows(ChannelRoleOverrides.Channel.CreateParameter(chanSnowflake.ID)))
|
||||||
|
{
|
||||||
|
RO.Add(new()
|
||||||
|
{
|
||||||
|
RoleID = over.RoleOverride,
|
||||||
|
BadPermissions = over.BadPermissions,
|
||||||
|
GoodPermissions = over.GoodPermissions
|
||||||
|
});
|
||||||
|
}
|
||||||
|
foreach (var over in Tables.ChannelUserOverrides.ReadRows(ChannelUserOverrides.Channel.CreateParameter(chanSnowflake.ID)))
|
||||||
|
{
|
||||||
|
UO.Add(new()
|
||||||
|
{
|
||||||
|
UserID = over.UserOverride,
|
||||||
|
BadPermissions = over.BadPermissions,
|
||||||
|
GoodPermissions = over.GoodPermissions
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return this.ResponseToResult(new ChannelSTC()
|
return this.ResponseToResult(new ChannelSTC()
|
||||||
{
|
{
|
||||||
Name = Convert.ToBase64String(chan.Name),
|
Name = Convert.ToBase64String(chan.Name),
|
||||||
@ -82,13 +105,14 @@ public class SocketChannelController : ControllerBase
|
|||||||
Epoch = chan.Epoch,
|
Epoch = chan.Epoch,
|
||||||
TitleEncryptionKey = chan.TitleEncryptionKey,
|
TitleEncryptionKey = chan.TitleEncryptionKey,
|
||||||
DescriptionEncryptionKey = chan.DescriptionEncryptionKey,
|
DescriptionEncryptionKey = chan.DescriptionEncryptionKey,
|
||||||
EncryptionKeys = chan.EncryptionKeys,
|
EncryptionKeys = Tables.ChannelKeys.ReadColumn(ChannelKeys.Key, ChannelKeys.Channel.CreateParameter(chanSnowflake.ID)),
|
||||||
TitleEncoderType = chan.TitleEncoderType,
|
TitleEncoderType = chan.TitleEncoderType,
|
||||||
DescriptionEncoderType = chan.DescriptionEncoderType,
|
DescriptionEncoderType = chan.DescriptionEncoderType,
|
||||||
EncoderTypes = chan.EncoderTypes,
|
EncoderTypes = chan.EncoderTypes,
|
||||||
UserOverrides = chan.UserOverrides,
|
UserOverrides = UO.ToArray(),
|
||||||
RoleOverrides = chan.RoleOverrides,
|
RoleOverrides = RO.ToArray(),
|
||||||
PictureType = chan.PictureType,
|
PictureType = chan.PictureType,
|
||||||
|
ColorType = chan.ColorType,
|
||||||
Color = Convert.ToHexString(chan.Color)
|
Color = Convert.ToHexString(chan.Color)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -160,6 +184,26 @@ public class SocketChannelController : 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.HasAccessToChannel(ID, Channel, ServerPermission.ViewChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
if (!LuskiFunctions.HasAccessToChannel(ID, Channel, ServerPermission.ViewChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||||
ChannelRow chan = Tables.Channels.ReadRow(Channels.ID.CreateParameter(Channel));
|
ChannelRow chan = Tables.Channels.ReadRow(Channels.ID.CreateParameter(Channel));
|
||||||
|
List<RoleOverrideSTC> RO = new();
|
||||||
|
List<UserOverrideSTC> UO = new();
|
||||||
|
foreach (var over in Tables.ChannelRoleOverrides.ReadRows(ChannelRoleOverrides.Channel.CreateParameter(chan.ID)))
|
||||||
|
{
|
||||||
|
RO.Add(new()
|
||||||
|
{
|
||||||
|
RoleID = over.RoleOverride,
|
||||||
|
BadPermissions = over.BadPermissions,
|
||||||
|
GoodPermissions = over.GoodPermissions
|
||||||
|
});
|
||||||
|
}
|
||||||
|
foreach (var over in Tables.ChannelUserOverrides.ReadRows(ChannelUserOverrides.Channel.CreateParameter(chan.ID)))
|
||||||
|
{
|
||||||
|
UO.Add(new()
|
||||||
|
{
|
||||||
|
UserID = over.UserOverride,
|
||||||
|
BadPermissions = over.BadPermissions,
|
||||||
|
GoodPermissions = over.GoodPermissions
|
||||||
|
});
|
||||||
|
}
|
||||||
return this.ResponseToResult(new ChannelSTC()
|
return this.ResponseToResult(new ChannelSTC()
|
||||||
{
|
{
|
||||||
Name = Convert.ToBase64String(chan.Name),
|
Name = Convert.ToBase64String(chan.Name),
|
||||||
@ -170,13 +214,14 @@ public class SocketChannelController : ControllerBase
|
|||||||
Epoch = chan.Epoch,
|
Epoch = chan.Epoch,
|
||||||
TitleEncryptionKey = chan.TitleEncryptionKey,
|
TitleEncryptionKey = chan.TitleEncryptionKey,
|
||||||
DescriptionEncryptionKey = chan.DescriptionEncryptionKey,
|
DescriptionEncryptionKey = chan.DescriptionEncryptionKey,
|
||||||
EncryptionKeys = chan.EncryptionKeys,
|
EncryptionKeys = Tables.ChannelKeys.ReadColumn(ChannelKeys.Key, ChannelKeys.Channel.CreateParameter(Channel)),
|
||||||
TitleEncoderType = chan.TitleEncoderType,
|
TitleEncoderType = chan.TitleEncoderType,
|
||||||
DescriptionEncoderType = chan.DescriptionEncoderType,
|
DescriptionEncoderType = chan.DescriptionEncoderType,
|
||||||
EncoderTypes = chan.EncoderTypes,
|
EncoderTypes = chan.EncoderTypes,
|
||||||
UserOverrides = chan.UserOverrides,
|
UserOverrides = UO.ToArray(),
|
||||||
RoleOverrides = chan.RoleOverrides,
|
RoleOverrides = RO.ToArray(),
|
||||||
PictureType = chan.PictureType,
|
PictureType = chan.PictureType,
|
||||||
|
ColorType = chan.ColorType,
|
||||||
Color = Convert.ToHexString(chan.Color)
|
Color = Convert.ToHexString(chan.Color)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,75 +0,0 @@
|
|||||||
using System.Net.Mime;
|
|
||||||
using Asp.Versioning;
|
|
||||||
using Luski.Shared.PublicServers.V1.Enums;
|
|
||||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
|
||||||
using LuskiServer.Classes;
|
|
||||||
using LuskiServer.Classes.TableDef;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
namespace LuskiServer.Controllers.v1;
|
|
||||||
|
|
||||||
[ApiVersion(1)]
|
|
||||||
[ApiController]
|
|
||||||
public class SocketChannelProfileController : ControllerBase
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the Avatar for the channel profile.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">The ID of the requested profile</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet]
|
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
||||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
|
||||||
[Produces(MediaTypeNames.Image.Jpeg, MediaTypeNames.Image.Gif, MediaTypeNames.Image.Tiff, "image/png", MediaTypeNames.Application.Json)]
|
|
||||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/Avatar/{id:long}")]
|
|
||||||
public IActionResult? Avatar(long id)
|
|
||||||
{
|
|
||||||
if (Tables.ChannelProfiles.TryRead(ChannelProfiles.Picture, out byte[]? image, ChannelProfiles.ID.CreateParameter(id)))
|
|
||||||
{
|
|
||||||
return Tables.ChannelProfiles.Read(ChannelProfiles.PictureType, ChannelProfiles.ID.CreateParameter(id)) switch
|
|
||||||
{
|
|
||||||
PictureType.png => File(image, "image/png"),
|
|
||||||
PictureType.jpeg => File(image, "image/jpeg"),
|
|
||||||
PictureType.bmp => File(image, "image/bmp"),
|
|
||||||
PictureType.gif => File(image, "image/gif"),
|
|
||||||
PictureType.ico => File(image, "image/vnd.microsoft.icon"),
|
|
||||||
PictureType.svg => File(image, "image/svg+xml"),
|
|
||||||
PictureType.tif => File(image, "image/tiff"),
|
|
||||||
PictureType.webp => File(image, "image/webp"),
|
|
||||||
//should never happen
|
|
||||||
_ => File(image, "image/png"),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return StatusCode(403, new STC()
|
|
||||||
{
|
|
||||||
Error = ErrorCode.Forbidden,
|
|
||||||
ErrorMessage = "the user you have given does not exist"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet]
|
|
||||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
|
||||||
public IActionResult Get([FromHeader(Name = "id")]long Person)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
|
||||||
if (Person != ID && !Tables.ChannelProfiles.TryRead(ChannelProfiles.ID, out _, ChannelProfiles.ID.CreateParameter(Person))) return this.ShowError(ErrorCode.Forbidden, "Profile does not exist");
|
|
||||||
return this.ResponseToResult(new ChannelProfileSTC()
|
|
||||||
{
|
|
||||||
ID = Person,
|
|
||||||
DisplayName = Tables.ChannelProfiles.Read(ChannelProfiles.DisplayName, ChannelProfiles.ID.CreateParameter(Person)),
|
|
||||||
PictureType = Tables.ChannelProfiles.Read(ChannelProfiles.PictureType, ChannelProfiles.ID.CreateParameter(Person)),
|
|
||||||
Controllers = Tables.ChannelProfiles.Read(ChannelProfiles.Controllers, ChannelProfiles.ID.CreateParameter(Person)),
|
|
||||||
Color = Convert.ToHexString(Tables.ChannelProfiles.Read(ChannelProfiles.Color, ChannelProfiles.ID.CreateParameter(Person))),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
return this.ShowError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -70,12 +70,17 @@ public class SocketFileController : ControllerBase
|
|||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||||
public IActionResult Post([FromBody] byte[] data, [FromHeader(Name = "name_encoder")] EncoderType nameEncoderNum, [FromHeader(Name = "name_encryption")]long nameEncryptionRaw, [FromHeader(Name = "encoder")] EncoderType EncoderNum, [FromHeader(Name = "encryption")]long EncryptionRaw, [FromHeader(Name = "name")]string name)
|
public async Task<IActionResult> Post([FromHeader(Name = "name_encoder")] EncoderType nameEncoderNum, [FromHeader(Name = "name_encryption")]long nameEncryptionRaw, [FromHeader(Name = "encoder")] EncoderType EncoderNum, [FromHeader(Name = "encryption")]long EncryptionRaw, [FromHeader(Name = "name")]string name)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
byte[] data;
|
||||||
|
using (MemoryStream reader = new())
|
||||||
|
{
|
||||||
|
await Request.Body.CopyToAsync(reader);
|
||||||
|
data = reader.ToArray();
|
||||||
|
}
|
||||||
byte[] hash = Encryption.Hashing.SHA256(data);
|
byte[] hash = Encryption.Hashing.SHA256(data);
|
||||||
if (Tables.Files.TryReadRow(out FileRow ido, Files.Hash.CreateParameter(hash)))
|
if (Tables.Files.TryReadRow(out FileRow ido, Files.Hash.CreateParameter(hash)))
|
||||||
return this.ResponseToResult(new ServerFileInfoSTC()
|
return this.ResponseToResult(new ServerFileInfoSTC()
|
||||||
@ -88,9 +93,7 @@ public class SocketFileController : ControllerBase
|
|||||||
NameKey = ido.NameEncryptionKey,
|
NameKey = ido.NameEncryptionKey,
|
||||||
Size = ido.Size
|
Size = ido.Size
|
||||||
});
|
});
|
||||||
|
|
||||||
long ido2 = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch).ID;
|
long ido2 = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch).ID;
|
||||||
|
|
||||||
Tables.Files.Insert(
|
Tables.Files.Insert(
|
||||||
Files.ID.CreateParameter(ido2),
|
Files.ID.CreateParameter(ido2),
|
||||||
Files.Size.CreateParameter(data.Length),
|
Files.Size.CreateParameter(data.Length),
|
||||||
@ -102,17 +105,16 @@ public class SocketFileController : ControllerBase
|
|||||||
Files.EncryptionKey.CreateParameter(EncryptionRaw),
|
Files.EncryptionKey.CreateParameter(EncryptionRaw),
|
||||||
Files.Hash.CreateParameter(hash),
|
Files.Hash.CreateParameter(hash),
|
||||||
Files.Owner.CreateParameter(ID),
|
Files.Owner.CreateParameter(ID),
|
||||||
Files.Public.CreateParameter(false),
|
Files.Public.CreateParameter(false));
|
||||||
Files.AllowedChannels.CreateParameter(Array.Empty<long>()));
|
|
||||||
return this.ResponseToResult(new ServerFileInfoSTC()
|
return this.ResponseToResult(new ServerFileInfoSTC()
|
||||||
{
|
{
|
||||||
ID = ido2,
|
ID = ido2,
|
||||||
Name = name,
|
Name = name,
|
||||||
Encoder = ido.EncoderType,
|
Encoder = EncoderNum,
|
||||||
NameEncoder = ido.NameEncoderType,
|
NameEncoder = nameEncoderNum,
|
||||||
Key = ido.EncryptionKey,
|
Key = EncryptionRaw,
|
||||||
NameKey = ido.NameEncryptionKey,
|
NameKey = nameEncryptionRaw,
|
||||||
Size = ido.Size
|
Size = data.Length
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -3,12 +3,12 @@ using Asp.Versioning;
|
|||||||
using Luski.Shared.PublicServers.V1.ClientToServer.HTTP;
|
using Luski.Shared.PublicServers.V1.ClientToServer.HTTP;
|
||||||
using Luski.Shared.PublicServers.V1.Enums;
|
using Luski.Shared.PublicServers.V1.Enums;
|
||||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||||
|
using Luski.Shared.PublicServers.V1.Shared;
|
||||||
using LuskiServer.Classes;
|
using LuskiServer.Classes;
|
||||||
using LuskiServer.Classes.ServerComs;
|
using LuskiServer.Classes.ServerComs;
|
||||||
using LuskiServer.Classes.TableDef;
|
using LuskiServer.Classes.TableDef;
|
||||||
using LuskiServer.Enums.ServerComs;
|
using LuskiServer.Enums.ServerComs;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using DataType = LuskiServer.Enums.ServerComs.DataType;
|
|
||||||
|
|
||||||
namespace LuskiServer.Controllers.v1;
|
namespace LuskiServer.Controllers.v1;
|
||||||
|
|
||||||
@ -23,30 +23,28 @@ public class SocketMessageController : ControllerBase
|
|||||||
{
|
{
|
||||||
AuthorID = msgraw.AuthorID,
|
AuthorID = msgraw.AuthorID,
|
||||||
Context = Convert.ToBase64String(msgraw.Context),
|
Context = Convert.ToBase64String(msgraw.Context),
|
||||||
ID = MSG_id,
|
ID = msgraw.ID,
|
||||||
ChannelID = msgraw.ChannelID
|
ChannelID = msgraw.ChannelID,
|
||||||
|
ProfileID = msgraw.ProfileID
|
||||||
};
|
};
|
||||||
List<ServerFileInfoSTC> list = new();
|
List<ServerFileInfoSTC> list = new();
|
||||||
if (msgraw.Files.Any())
|
if (Tables.MessageFiles.CreateCommand().WithFilter(MessageFiles.MessageID, msgraw.ID)
|
||||||
|
.WithCrossTableCheck(MessageFiles.FileID, Tables.Files, Files.ID).TryReadRows(out FileRow[]? files))
|
||||||
{
|
{
|
||||||
|
foreach (FileRow b in files)
|
||||||
foreach (long b in msgraw.Files)
|
|
||||||
{
|
{
|
||||||
FileRow fileraw = Tables.Files.ReadRow(Files.ID.CreateParameter(b));
|
|
||||||
ServerFileInfoSTC file = new()
|
ServerFileInfoSTC file = new()
|
||||||
{
|
{
|
||||||
ID = b,
|
ID = b.ID,
|
||||||
Name = Convert.ToBase64String(fileraw.Name),
|
Name = Convert.ToBase64String(b.Name),
|
||||||
Size = fileraw.Size,
|
Size = b.Size,
|
||||||
NameEncoder = fileraw.NameEncoderType,
|
NameEncoder = b.NameEncoderType,
|
||||||
NameKey = fileraw.NameEncryptionKey,
|
NameKey = b.NameEncryptionKey,
|
||||||
Encoder = fileraw.EncoderType,
|
Encoder = b.EncoderType,
|
||||||
Key = fileraw.EncryptionKey
|
Key = b.EncryptionKey,
|
||||||
};
|
};
|
||||||
list.Add(file);
|
list.Add(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
msg.Files = list.ToArray();
|
msg.Files = list.ToArray();
|
||||||
|
|
||||||
@ -68,30 +66,29 @@ public class SocketMessageController : ControllerBase
|
|||||||
AuthorID = msgraw.AuthorID,
|
AuthorID = msgraw.AuthorID,
|
||||||
Context = Convert.ToBase64String(msgraw.Context),
|
Context = Convert.ToBase64String(msgraw.Context),
|
||||||
ID = MSG_id,
|
ID = MSG_id,
|
||||||
ChannelID = Channel_Id
|
ChannelID = Channel_Id,
|
||||||
|
ProfileID = msgraw.ProfileID
|
||||||
};
|
};
|
||||||
if (msgraw.Files.Any())
|
|
||||||
{
|
|
||||||
List<ServerFileInfoSTC> list = new();
|
List<ServerFileInfoSTC> list = new();
|
||||||
foreach (long b in msgraw.Files)
|
if (Tables.MessageFiles.CreateCommand().WithFilter(MessageFiles.MessageID, msgraw.ID)
|
||||||
|
.WithCrossTableCheck(MessageFiles.FileID, Tables.Files, Files.ID).TryReadRows(out FileRow[]? files))
|
||||||
|
{
|
||||||
|
foreach (FileRow b in files)
|
||||||
{
|
{
|
||||||
FileRow fileraw = Tables.Files.ReadRow(Files.ID.CreateParameter(b));
|
|
||||||
ServerFileInfoSTC file = new()
|
ServerFileInfoSTC file = new()
|
||||||
{
|
{
|
||||||
ID = b,
|
ID = b.ID,
|
||||||
Name = Convert.ToBase64String(fileraw.Name),
|
Name = Convert.ToBase64String(b.Name),
|
||||||
Size = fileraw.Size,
|
Size = b.Size,
|
||||||
NameEncoder = fileraw.NameEncoderType,
|
NameEncoder = b.NameEncoderType,
|
||||||
NameKey = fileraw.NameEncryptionKey,
|
NameKey = b.NameEncryptionKey,
|
||||||
Encoder = fileraw.EncoderType,
|
Encoder = b.EncoderType,
|
||||||
Key = fileraw.EncryptionKey
|
Key = b.EncryptionKey,
|
||||||
};
|
};
|
||||||
list.Add(file);
|
list.Add(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.Files = list.ToArray();
|
|
||||||
}
|
}
|
||||||
|
msg.Files = list.ToArray();
|
||||||
return this.ResponseToResult(msg);
|
return this.ResponseToResult(msg);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -110,34 +107,61 @@ public class SocketMessageController : 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.HasAccessToChannel(ID, data.ChannelID, ServerPermission.SendMessages)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
if (!LuskiFunctions.HasAccessToChannel(ID, data.ChannelID, ServerPermission.SendMessages)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||||
LuskiFunctions.Snowflake Id = LuskiFunctions.Snowflake.GenerateSnowflake(Tables.Channels.Read(Channels.Epoch, Channels.ID.CreateParameter(data.ChannelID)));
|
LuskiFunctions.Snowflake Id = LuskiFunctions.Snowflake.GenerateSnowflake();
|
||||||
ChannelType type = Tables.Channels.Read(Channels.Type, Channels.ID.CreateParameter(data.ChannelID));
|
ChannelType type = Tables.Channels.Read(Channels.Type, Channels.ID.CreateParameter(data.ChannelID));
|
||||||
bool Fake = data.Profile.HasValue;
|
bool Fake = data.Profile.HasValue;
|
||||||
if (Fake)
|
long profile = Tables.Users.Read(Users.ServerProfile, Users.ID.CreateParameter(ID));
|
||||||
|
if (Fake) //TODO check to make sure the profile can be used by them
|
||||||
{
|
{
|
||||||
ID = data.Profile!.Value;
|
profile = data.Profile!.Value;
|
||||||
}
|
}
|
||||||
MessageEvent MessageEvent = new()
|
MessageEvent MessageEvent = new()
|
||||||
{
|
{
|
||||||
UserID = ID,
|
AuthorID = ID,
|
||||||
|
ProfileID = profile,
|
||||||
ChannelID = data.ChannelID,
|
ChannelID = data.ChannelID,
|
||||||
Base64Context = data.Base64Context,
|
Base64Context = data.Base64Context,
|
||||||
ID = Id.ID,
|
ID = Id.ID,
|
||||||
EncoderType = data.Encoding,
|
EncoderType = data.Encoding,
|
||||||
EncryptionKey = data.EncryptionKey,
|
EncryptionKey = data.EncryptionKey,
|
||||||
Files = Array.Empty<ServerFileInfoSTC>(),
|
Files = Array.Empty<ServerFileInfoSTC>(),
|
||||||
IsProfile = Fake,
|
Timestamp = LuskiFunctions.Info.GetTimestampFromEpoch(Tables.Channels.Read(Channels.Epoch, Channels.ID.CreateParameter(data.ChannelID)))
|
||||||
};
|
};
|
||||||
|
|
||||||
Tables.Messages.Insert(
|
Tables.Messages.Insert(
|
||||||
Messages.ChannelID.CreateParameter(data.ChannelID),
|
Messages.ChannelID.CreateParameter(data.ChannelID),
|
||||||
Messages.ID.CreateParameter(Id.ID),
|
Messages.ID.CreateParameter(Id.ID),
|
||||||
|
Messages.Timestamp.CreateParameter(MessageEvent.Timestamp),
|
||||||
Messages.AuthorID.CreateParameter(ID),
|
Messages.AuthorID.CreateParameter(ID),
|
||||||
|
Messages.ProfileID.CreateParameter(profile),
|
||||||
Messages.Context.CreateParameter(Convert.FromBase64String(data.Base64Context)),
|
Messages.Context.CreateParameter(Convert.FromBase64String(data.Base64Context)),
|
||||||
Messages.Files.CreateParameter(data.Files),
|
|
||||||
Messages.EncoderType.CreateParameter(data.Encoding),
|
Messages.EncoderType.CreateParameter(data.Encoding),
|
||||||
Messages.EncryptionKey.CreateParameter(data.EncryptionKey),
|
Messages.EncryptionKey.CreateParameter(data.EncryptionKey),
|
||||||
Messages.ReplyTo.CreateParameter(Id.ID),
|
Messages.ReplyTo.CreateParameter(Id.ID));
|
||||||
Messages.IsChannelProfile.CreateParameter(Fake));
|
if (data.Files.Length > 0)
|
||||||
|
{
|
||||||
|
List<ServerFileInfoSTC> SFI = new();
|
||||||
|
foreach (long file in data.Files)
|
||||||
|
{
|
||||||
|
if (Tables.Files.TryReadRow(out FileRow ido, Files.ID.CreateParameter(file)))
|
||||||
|
{
|
||||||
|
Tables.MessageFiles.Insert(MessageFiles.MessageID.CreateParameter(Id.ID), MessageFiles.FileID.CreateParameter(file));
|
||||||
|
SFI.Add(new ServerFileInfoSTC()
|
||||||
|
{
|
||||||
|
ID = ido.ID,
|
||||||
|
Name = Convert.ToBase64String(ido.Name),
|
||||||
|
Encoder = ido.EncoderType,
|
||||||
|
NameEncoder = ido.NameEncoderType,
|
||||||
|
Key = ido.EncryptionKey,
|
||||||
|
NameKey = ido.NameEncryptionKey,
|
||||||
|
Size = ido.Size
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageEvent.Files = SFI.ToArray();
|
||||||
|
}
|
||||||
WSS.SendData(SendType.ID_Group, new ServerEvent()
|
WSS.SendData(SendType.ID_Group, new ServerEvent()
|
||||||
{
|
{
|
||||||
Type = DataType.MessageCreate,
|
Type = DataType.MessageCreate,
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
using Asp.Versioning;
|
|
||||||
using Luski.Shared.PublicServers.V1.Enums;
|
|
||||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
|
||||||
using Luski.Shared.PublicServers.V1.Shared;
|
|
||||||
using LuskiServer.Classes;
|
|
||||||
using LuskiServer.Classes.TableDef;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
namespace LuskiServer.Controllers.v1;
|
|
||||||
|
|
||||||
[ApiVersion(1)]
|
|
||||||
[ApiController]
|
|
||||||
public class SocketOverridesController : ControllerBase
|
|
||||||
{
|
|
||||||
[HttpGet]
|
|
||||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/UserOverride/{id:long}")]
|
|
||||||
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 (!Tables.UserRoleOverrides.TryReadRow(out UserRoleOverrideRow row, UserRoleOverrides.ID.CreateParameter(id))) return this.ShowError(ErrorCode.Forbidden, "Override does not exist");
|
|
||||||
return this.ResponseToResult(new UserOverrideSTC()
|
|
||||||
{
|
|
||||||
Id = row.ID,
|
|
||||||
UserID = row.UserID,
|
|
||||||
GoodPermissions = row.GoodPermissions,
|
|
||||||
BadPermissions = row.BadPermissions
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet]
|
|
||||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/RoleOverride/{id:long}")]
|
|
||||||
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 (!Tables.ServerRoleOverrides.TryReadRow(out ServerRoleOverrideRow? row, ServerRoleOverrides.ID.CreateParameter(id))) return this.ShowError(ErrorCode.Forbidden, "Override does not exist");
|
|
||||||
return this.ResponseToResult(new UserRoleOverrideSTC()
|
|
||||||
{
|
|
||||||
Id = row.ID,
|
|
||||||
RoleID = row.RoleID,
|
|
||||||
GoodPermissions = row.GoodPermissions,
|
|
||||||
BadPermissions = row.BadPermissions
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
169
LuskiServer/Controllers/v1/SocketProfileController.cs
Normal file
169
LuskiServer/Controllers/v1/SocketProfileController.cs
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
using System.Net.Mime;
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Luski.Shared.PublicServers.V1.Enums;
|
||||||
|
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||||
|
using LuskiServer.Classes;
|
||||||
|
using LuskiServer.Classes.TableDef;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace LuskiServer.Controllers.v1;
|
||||||
|
|
||||||
|
[ApiVersion(1)]
|
||||||
|
[ApiController]
|
||||||
|
public class SocketProfileController : ControllerBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the Avatar for the channel profile.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The ID of the requested profile</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
||||||
|
[Produces(MediaTypeNames.Image.Jpeg, MediaTypeNames.Image.Gif, MediaTypeNames.Image.Tiff, "image/png", MediaTypeNames.Application.Json)]
|
||||||
|
[Route(LuskiFunctions.Info.Routes.Default.Base + "/Avatar/{id:long}")]
|
||||||
|
public IActionResult? Avatar(long id)
|
||||||
|
{
|
||||||
|
if (Tables.Profiles.TryRead(Profiles.Picture, out byte[]? image, Profiles.ID.CreateParameter(id)))
|
||||||
|
{
|
||||||
|
return Tables.Profiles.Read(Profiles.PictureType, Profiles.ID.CreateParameter(id)) switch
|
||||||
|
{
|
||||||
|
PictureType.png => File(image, "image/png"),
|
||||||
|
PictureType.jpeg => File(image, "image/jpeg"),
|
||||||
|
PictureType.bmp => File(image, "image/bmp"),
|
||||||
|
PictureType.gif => File(image, "image/gif"),
|
||||||
|
PictureType.ico => File(image, "image/vnd.microsoft.icon"),
|
||||||
|
PictureType.svg => File(image, "image/svg+xml"),
|
||||||
|
PictureType.tif => File(image, "image/tiff"),
|
||||||
|
PictureType.webp => File(image, "image/webp"),
|
||||||
|
//should never happen
|
||||||
|
_ => File(image, "image/png"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return StatusCode(403, new STC()
|
||||||
|
{
|
||||||
|
Error = ErrorCode.Forbidden,
|
||||||
|
ErrorMessage = "the user you have given does not exist"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||||
|
public IActionResult Get([FromHeader(Name = "id")]long Person)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
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)),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return this.ShowError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route(LuskiFunctions.Info.Routes.Default.Base + "/myprofiles")]
|
||||||
|
public IActionResult GetMyProfiles()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||||
|
Dictionary<long, ProfileSTC> Vals = new();
|
||||||
|
if (Tables.ProfileControllers.CreateCommand()
|
||||||
|
.WithFilter(ProfileControllers.User, ID)
|
||||||
|
.WithCrossTableCheck(ProfileControllers.Profile, Tables.Profiles, Classes.TableDef.Profiles.ID)
|
||||||
|
.TryReadRows(out ProfileRow[]? PcRs))
|
||||||
|
{
|
||||||
|
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)),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Tables.RoleMembers.CreateCommand()
|
||||||
|
.WithFilter(RoleMembers.User, ID)
|
||||||
|
.WithCrossTableCheck(RoleMembers.Role, Tables.ProfileRoleControllers, ProfileRoleControllers.Role)
|
||||||
|
.WithCrossTableCheck(ProfileRoleControllers.Profile, Tables.Profiles, Classes.TableDef.Profiles.ID)
|
||||||
|
.TryReadRows(out ProfileRow[]? rows))
|
||||||
|
{
|
||||||
|
foreach (var PR in rows)
|
||||||
|
{
|
||||||
|
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)),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.ResponseToResult(new ProfileListSTC()
|
||||||
|
{
|
||||||
|
Profiles = Vals.Values.ToList()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return this.ShowError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,15 @@
|
|||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
|
using Luski.Shared.PublicServers.V1.ClientToServer.HTTP;
|
||||||
using Luski.Shared.PublicServers.V1.Enums;
|
using Luski.Shared.PublicServers.V1.Enums;
|
||||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
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;
|
||||||
|
using LuskiServer.Classes.ServerComs;
|
||||||
using LuskiServer.Classes.TableDef;
|
using LuskiServer.Classes.TableDef;
|
||||||
|
using LuskiServer.Enums.ServerComs;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using ServerDatabase;
|
||||||
|
|
||||||
namespace LuskiServer.Controllers.v1;
|
namespace LuskiServer.Controllers.v1;
|
||||||
|
|
||||||
@ -11,6 +17,156 @@ namespace LuskiServer.Controllers.v1;
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class SocketRoleController : ControllerBase
|
public class SocketRoleController : ControllerBase
|
||||||
{
|
{
|
||||||
|
[HttpPost]
|
||||||
|
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||||
|
public IActionResult Post([FromBody]RolePostCTS Role)
|
||||||
|
{
|
||||||
|
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||||
|
LuskiFunctions.Snowflake sf = LuskiFunctions.Snowflake.GenerateSnowflake();
|
||||||
|
Tables.Roles.Insert(
|
||||||
|
Roles.ID.CreateParameter(sf.ID),
|
||||||
|
Roles.Description.CreateParameter(Role.Description),
|
||||||
|
Roles.DisplayName.CreateParameter(Role.DisplayName),
|
||||||
|
Roles.ColorType.CreateParameter(Role.ColorType),
|
||||||
|
Roles.Color.CreateParameter(Convert.FromHexString(Role.Color)),
|
||||||
|
Roles.ServerPermissions.CreateParameter(Role.ServerPermissions),
|
||||||
|
Roles.Index.CreateParameter(Role.Index));
|
||||||
|
WSS.SendData(SendType.All, new ServerEvent()
|
||||||
|
{
|
||||||
|
Type = DataType.Role,
|
||||||
|
Data = new RoleEvent()
|
||||||
|
{
|
||||||
|
ID = sf.ID,
|
||||||
|
ServerPermissions = Role.ServerPermissions,
|
||||||
|
Description = Role.Description,
|
||||||
|
DisplayName = Role.DisplayName,
|
||||||
|
Index = Role.Index,
|
||||||
|
ColorType = Role.ColorType,
|
||||||
|
Color = Role.Color
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return this.ResponseToResult(new RoleSTC()
|
||||||
|
{
|
||||||
|
ID = sf.ID,
|
||||||
|
ServerPermissions = Role.ServerPermissions,
|
||||||
|
Description = Role.Description,
|
||||||
|
DisplayName = Role.DisplayName,
|
||||||
|
Index = Role.Index,
|
||||||
|
Members = Array.Empty<long>(),
|
||||||
|
ColorType = Role.ColorType,
|
||||||
|
Color = Role.Color
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPatch]
|
||||||
|
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||||
|
public IActionResult Patch([FromBody]RolePatchCTS Role)
|
||||||
|
{
|
||||||
|
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(Role.ID))) return this.ShowError(ErrorCode.Forbidden, "Role does not exist");
|
||||||
|
CommandHandler<RoleRow> command = Tables.Roles.CreateCommand().WithFilter(Roles.ID, Role.ID);
|
||||||
|
RoleEvent re = new()
|
||||||
|
{
|
||||||
|
ID = row.ID
|
||||||
|
};
|
||||||
|
if (Role.ServerPermissions is not null)
|
||||||
|
{
|
||||||
|
command = command.WithValue(Roles.ServerPermissions, Role.ServerPermissions.Value);
|
||||||
|
row.ServerPermissions = Role.ServerPermissions.Value;
|
||||||
|
re.ServerPermissions = Role.ServerPermissions.Value;
|
||||||
|
}
|
||||||
|
if (Role.Description is not null)
|
||||||
|
{
|
||||||
|
command = command.WithValue(Roles.Description, Role.Description);
|
||||||
|
row.Description = Role.Description;
|
||||||
|
re.Description = Role.Description;
|
||||||
|
}
|
||||||
|
if (Role.Index is not null)
|
||||||
|
{
|
||||||
|
command = command.WithValue(Roles.Index, Role.Index.Value);
|
||||||
|
row.Index = Role.Index.Value;
|
||||||
|
re.Index = Role.Index.Value;
|
||||||
|
}
|
||||||
|
if (Role.DisplayName is not null)
|
||||||
|
{
|
||||||
|
command = command.WithValue(Roles.DisplayName, Role.DisplayName);
|
||||||
|
row.DisplayName = Role.DisplayName;
|
||||||
|
re.DisplayName = Role.DisplayName;
|
||||||
|
}
|
||||||
|
if (Role.ColorType is not null)
|
||||||
|
{
|
||||||
|
command = command.WithValue(Roles.ColorType, Role.ColorType.Value);
|
||||||
|
row.ColorType = Role.ColorType.Value;
|
||||||
|
re.ColorType = Role.ColorType.Value;
|
||||||
|
}
|
||||||
|
if (Role.Color is not null)
|
||||||
|
{
|
||||||
|
command = command.WithValue(Roles.Color, Convert.FromHexString(Role.Color));
|
||||||
|
row.Color = Convert.FromHexString(Role.Color);
|
||||||
|
re.Color = Role.Color;
|
||||||
|
}
|
||||||
|
command.Update();
|
||||||
|
WSS.SendData(SendType.All, new ServerEvent()
|
||||||
|
{
|
||||||
|
Type = DataType.Role,
|
||||||
|
Data = re
|
||||||
|
});
|
||||||
|
return this.ResponseToResult(new RoleSTC()
|
||||||
|
{
|
||||||
|
ID = row.ID,
|
||||||
|
ServerPermissions = row.ServerPermissions,
|
||||||
|
Description = row.Description,
|
||||||
|
DisplayName = row.DisplayName,
|
||||||
|
Index = row.Index,
|
||||||
|
Members = Tables.RoleMembers.ReadColumn(RoleMembers.User, RoleMembers.Role.CreateParameter(row.ID)),
|
||||||
|
ColorType = row.ColorType,
|
||||||
|
Color = Convert.ToHexString(row.Color)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPatch]
|
||||||
|
[Route(LuskiFunctions.Info.Routes.Default.Base + "/Members")]
|
||||||
|
public IActionResult MemberPatch([FromBody]RoleMembersPatchCTS Role)
|
||||||
|
{
|
||||||
|
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(Role.ID))) return this.ShowError(ErrorCode.Forbidden, "Role does not exist");
|
||||||
|
LuskiFunctions.Database.ExecuteNonQuery($"DELETE FROM {Tables.RoleMembers.Name} WHERE {RoleMembers.Role.Name} = {Role.ID} AND {RoleMembers.User.Name} IN ({string.Join(", ", Role.RemovedMembers)})");
|
||||||
|
foreach (long am in Role.AddedMembers)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Tables.RoleMembers.Insert(RoleMembers.Role.CreateParameter(Role.ID), RoleMembers.User.CreateParameter(am));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
//ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WSS.SendData(SendType.All, new ServerEvent()
|
||||||
|
{
|
||||||
|
Type = DataType.RoleMember,
|
||||||
|
Data = new RoleEvent()
|
||||||
|
{
|
||||||
|
ID = row.ID,
|
||||||
|
ServerPermissions = row.ServerPermissions,
|
||||||
|
Description = row.Description,
|
||||||
|
DisplayName = row.DisplayName,
|
||||||
|
Index = row.Index,
|
||||||
|
Color = Convert.ToHexString(row.Color)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return this.ResponseToResult(new RoleSTC()
|
||||||
|
{
|
||||||
|
ID = row.ID,
|
||||||
|
ServerPermissions = row.ServerPermissions,
|
||||||
|
Description = row.Description,
|
||||||
|
DisplayName = row.DisplayName,
|
||||||
|
Index = row.Index,
|
||||||
|
Members = Tables.RoleMembers.ReadColumn(RoleMembers.User, RoleMembers.Role.CreateParameter(row.ID)),
|
||||||
|
Color = Convert.ToHexString(row.Color)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||||
public IActionResult Get([FromQuery(Name = "id")]long id)
|
public IActionResult Get([FromQuery(Name = "id")]long id)
|
||||||
@ -24,8 +180,8 @@ public class SocketRoleController : ControllerBase
|
|||||||
Description = row.Description,
|
Description = row.Description,
|
||||||
DisplayName = row.DisplayName,
|
DisplayName = row.DisplayName,
|
||||||
Index = row.Index,
|
Index = row.Index,
|
||||||
Name = row.Name,
|
Members = Tables.RoleMembers.ReadColumn(RoleMembers.User, RoleMembers.Role.CreateParameter(row.ID)),
|
||||||
Members = row.MembersList,
|
ColorType = row.ColorType,
|
||||||
Color = Convert.ToHexString(row.Color)
|
Color = Convert.ToHexString(row.Color)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -47,8 +203,8 @@ public class SocketRoleController : ControllerBase
|
|||||||
Description = rows[i].Description,
|
Description = rows[i].Description,
|
||||||
DisplayName = rows[i].DisplayName,
|
DisplayName = rows[i].DisplayName,
|
||||||
Index = rows[i].Index,
|
Index = rows[i].Index,
|
||||||
Name = rows[i].Name,
|
Members = Tables.RoleMembers.ReadColumn(RoleMembers.User, RoleMembers.Role.CreateParameter(rows[i].ID)),
|
||||||
Members = rows[i].MembersList,
|
ColorType = rows[i].ColorType,
|
||||||
Color = Convert.ToHexString(rows[i].Color)
|
Color = Convert.ToHexString(rows[i].Color)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ public class SocketServerController : ControllerBase
|
|||||||
? $"{(LuskiFunctions.Config.IPv4SecureWSS ? "wss" : "ws")}://{LuskiFunctions.Config.IPv4WSS}:{LuskiFunctions.Config.IPv4PortWSS}{LuskiFunctions.Config.IPv4_URL_WSS}v1"
|
? $"{(LuskiFunctions.Config.IPv4SecureWSS ? "wss" : "ws")}://{LuskiFunctions.Config.IPv4WSS}:{LuskiFunctions.Config.IPv4PortWSS}{LuskiFunctions.Config.IPv4_URL_WSS}v1"
|
||||||
: LuskiFunctions.Config.IPv4_Overode_WSS + "v1"),
|
: LuskiFunctions.Config.IPv4_Overode_WSS + "v1"),
|
||||||
Name = sr.Name,
|
Name = sr.Name,
|
||||||
|
PictureType = sr.PictureType,
|
||||||
Description = sr.Description,
|
Description = sr.Description,
|
||||||
Owner = sr.Owner
|
Owner = sr.Owner
|
||||||
};
|
};
|
||||||
|
@ -23,19 +23,17 @@ public class SocketUserController : ControllerBase
|
|||||||
if (Person == ID) return this.ResponseToResult(new SocketUserSTC()
|
if (Person == ID) return this.ResponseToResult(new SocketUserSTC()
|
||||||
{
|
{
|
||||||
ID = Person,
|
ID = Person,
|
||||||
DisplayName = UR.DisplayName,
|
RoleIds = Tables.RoleMembers.ReadColumn(RoleMembers.Role, RoleMembers.User.CreateParameter(Person)),
|
||||||
PictureType = UR.PictureType,
|
|
||||||
RoleIds = UR.Roles,
|
|
||||||
Status = UR.Status,
|
Status = UR.Status,
|
||||||
SelectedChannel = UR.SelectedChannel
|
SelectedChannel = UR.SelectedChannel,
|
||||||
|
ServerProfile = UR.ServerProfile
|
||||||
});
|
});
|
||||||
return this.ResponseToResult(new SocketUserSTC()
|
return this.ResponseToResult(new SocketUserSTC()
|
||||||
{
|
{
|
||||||
ID = Person,
|
ID = Person,
|
||||||
DisplayName = UR.DisplayName,
|
RoleIds = Tables.RoleMembers.ReadColumn(RoleMembers.Role, RoleMembers.User.CreateParameter(Person)),
|
||||||
PictureType = UR.PictureType,
|
Status = UR.Status,
|
||||||
RoleIds = UR.Roles,
|
ServerProfile = UR.ServerProfile
|
||||||
Status = UR.Status
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -3,9 +3,12 @@ using Asp.Versioning;
|
|||||||
using Luski.Shared.PublicServers.V1.ClientToServer.HTTP;
|
using Luski.Shared.PublicServers.V1.ClientToServer.HTTP;
|
||||||
using Luski.Shared.PublicServers.V1.Enums;
|
using Luski.Shared.PublicServers.V1.Enums;
|
||||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||||
|
using Luski.Shared.PublicServers.V1.Shared;
|
||||||
using LuskiServer.Classes;
|
using LuskiServer.Classes;
|
||||||
using LuskiServer.Classes.ActionFilters;
|
using LuskiServer.Classes.ActionFilters;
|
||||||
|
using LuskiServer.Classes.ServerComs;
|
||||||
using LuskiServer.Classes.TableDef;
|
using LuskiServer.Classes.TableDef;
|
||||||
|
using LuskiServer.Enums.ServerComs;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
|
|
||||||
@ -31,44 +34,6 @@ public class SocketUserProfileController : ControllerBase
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the Avatar for the user.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">The ID of the requested user</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet]
|
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
||||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
|
||||||
[Produces(MediaTypeNames.Image.Jpeg, MediaTypeNames.Image.Gif, MediaTypeNames.Image.Tiff, "image/png", MediaTypeNames.Application.Json)]
|
|
||||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/Avatar/{id:long}")]
|
|
||||||
public IActionResult? Avatar(long id)
|
|
||||||
{
|
|
||||||
if (Tables.Users.TryRead(Users.Picture, out byte[]? image, Users.ID.CreateParameter(id)))
|
|
||||||
{
|
|
||||||
return Tables.Users.Read(Users.PictureType, Users.ID.CreateParameter(id)) switch
|
|
||||||
{
|
|
||||||
PictureType.png => File(image, "image/png"),
|
|
||||||
PictureType.jpeg => File(image, "image/jpeg"),
|
|
||||||
PictureType.bmp => File(image, "image/bmp"),
|
|
||||||
PictureType.gif => File(image, "image/gif"),
|
|
||||||
PictureType.ico => File(image, "image/vnd.microsoft.icon"),
|
|
||||||
PictureType.svg => File(image, "image/svg+xml"),
|
|
||||||
PictureType.tif => File(image, "image/tiff"),
|
|
||||||
PictureType.webp => File(image, "image/webp"),
|
|
||||||
//should never happen
|
|
||||||
_ => File(image, "image/png"),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return StatusCode(403, new STC()
|
|
||||||
{
|
|
||||||
Error = ErrorCode.Forbidden,
|
|
||||||
ErrorMessage = "the user you have givven does not exist"
|
|
||||||
});
|
|
||||||
//return File(Encoding.UTF8.GetBytes(obj.ToString()), "application/json");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Make a post to this endpoint to change the status of you account.
|
/// Make a post to this endpoint to change the status of you account.
|
||||||
@ -94,15 +59,18 @@ public class SocketUserProfileController : ControllerBase
|
|||||||
UserStatus OldStatus = Tables.Users.Read(Users.Status, Users.ID.CreateParameter(ID));
|
UserStatus OldStatus = Tables.Users.Read(Users.Status, Users.ID.CreateParameter(ID));
|
||||||
if (OldStatus != NewStatus && (int)NewStatus < (int)UserStatus.MAX && (int)NewStatus >= 0)
|
if (OldStatus != NewStatus && (int)NewStatus < (int)UserStatus.MAX && (int)NewStatus >= 0)
|
||||||
{
|
{
|
||||||
// JObject @out = new()
|
|
||||||
// {
|
|
||||||
// { "id", ID },
|
|
||||||
// { "before", (int)OldStatus },
|
|
||||||
// { "after", (int)NewStatus },
|
|
||||||
// { "type", (int)DataType.Status_Update }
|
|
||||||
// };
|
|
||||||
Tables.Users.CreateCommand().WithFilter(Users.ID, ID).WithValue(Users.Status, NewStatus).Update();
|
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, new ServerEvent()
|
||||||
|
{
|
||||||
|
Type = DataType.StatusUpdate,
|
||||||
|
Data = new StatusEvent()
|
||||||
|
{
|
||||||
|
User = ID,
|
||||||
|
Before = (OldStatus == UserStatus.Invisible ? UserStatus.Offline : OldStatus),
|
||||||
|
After = NewStatus,
|
||||||
|
}
|
||||||
|
});
|
||||||
// WSS.SendData(SendType.All, @out);
|
// WSS.SendData(SendType.All, @out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ namespace LuskiServer.Converters.Matrix;
|
|||||||
|
|
||||||
public static class Matrix
|
public static class Matrix
|
||||||
{
|
{
|
||||||
public static void ZipJsonChatExport(Stream Zip, long Channel, Dictionary<string, long> UserMap,
|
public static void ZipJsonChatExport(Stream Zip, long Channel, long defaultuser, Dictionary<string, long> UserMap,
|
||||||
Dictionary<string, int> ChannelProfilesIdList,
|
Dictionary<string, int> ChannelProfilesIdList,
|
||||||
List<Tuple<string, byte[], PictureType, byte[]>> Profiles,
|
List<Tuple<string, byte[], PictureType, byte[]>> Profiles,
|
||||||
List<string> IgnoredUsers, EncoderType Encoder, long Encryption, bool remove = true)
|
List<string> IgnoredUsers, EncoderType Encoder, long Encryption, bool remove = true)
|
||||||
@ -34,14 +34,16 @@ public static class Matrix
|
|||||||
{
|
{
|
||||||
long id2 = LuskiFunctions.Snowflake.GenerateSnowflake().ID;
|
long id2 = LuskiFunctions.Snowflake.GenerateSnowflake().ID;
|
||||||
|
|
||||||
Tables.ChannelProfiles.Insert(
|
Tables.Profiles.Insert(
|
||||||
ChannelProfiles.ID.CreateParameter(id2),
|
Classes.TableDef.Profiles.ID.CreateParameter(id2),
|
||||||
ChannelProfiles.Controllers.CreateDefaultParameter(),
|
Classes.TableDef.Profiles.PictureType.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item3),
|
||||||
ChannelProfiles.PictureType.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item3),
|
Classes.TableDef.Profiles.Picture.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item2),
|
||||||
ChannelProfiles.Picture.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item2),
|
Classes.TableDef.Profiles.DisplayName.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item1));
|
||||||
ChannelProfiles.DisplayName.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item1),
|
Tables.ProfileColors.Insert(
|
||||||
ChannelProfiles.Color.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item4));
|
ProfileColors.Profile.CreateParameter(id2),
|
||||||
|
ProfileColors.Color.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item4));
|
||||||
IdConverter.Add(ChannelProfilesIdList[id], id2);
|
IdConverter.Add(ChannelProfilesIdList[id], id2);
|
||||||
|
Tables.ChannelProfiles.Insert(ChannelProfiles.Channel.CreateParameter(Channel), ChannelProfiles.Profile.CreateParameter(id2));
|
||||||
foreach (KeyValuePair<string, int> v in ChannelProfilesIdList.Where(s => s.Value == ChannelProfilesIdList[id]))
|
foreach (KeyValuePair<string, int> v in ChannelProfilesIdList.Where(s => s.Value == ChannelProfilesIdList[id]))
|
||||||
{
|
{
|
||||||
cps.Add(v.Key, id2);
|
cps.Add(v.Key, id2);
|
||||||
@ -53,32 +55,27 @@ public static class Matrix
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//TODO REMOVE FOR LAST VERSION
|
|
||||||
foreach (long i in Tables.Channels.Read(Channels.Profiles, Channels.ID.CreateParameter(Channel)))
|
|
||||||
{
|
|
||||||
Tables.ChannelProfiles.DeleteRow(ChannelProfiles.ID.CreateParameter(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
Tables.Channels.CreateCommand()
|
Tables.Channels.CreateCommand()
|
||||||
.WithFilter(Channels.ID, Channel)
|
.WithFilter(Channels.ID, Channel)
|
||||||
.WithValue(Channels.Parent, 0)
|
.WithValue(Channels.Parent, 0)
|
||||||
.WithValue(Channels.Type, ChannelType.TextAndVoice)
|
.WithValue(Channels.Type, ChannelType.TextAndVoice)
|
||||||
.WithValue(Channels.Description, export.RoomTopic.ToDB(Encoder, Encryption))
|
.WithValue(Channels.Description, export.RoomTopic.ToDB(Encoder, Encryption))
|
||||||
.WithValue(Channels.Name, export.RoomName.ToDB(Encoder, Encryption))
|
.WithValue(Channels.Name, export.RoomName.ToDB(Encoder, Encryption))
|
||||||
.WithValue(Channels.RoleOverrides, Array.Empty<long>())
|
|
||||||
.WithValue(Channels.UserOverrides, Array.Empty<long>())
|
|
||||||
.WithValue(Channels.Epoch, epoch)
|
.WithValue(Channels.Epoch, epoch)
|
||||||
.WithValue(Channels.TitleEncryptionKey, Encryption)
|
.WithValue(Channels.TitleEncryptionKey, Encryption)
|
||||||
.WithValue(Channels.DescriptionEncryptionKey, Encryption)
|
.WithValue(Channels.DescriptionEncryptionKey, Encryption)
|
||||||
.WithValue(Channels.EncryptionKeys, new long[] { Encryption })
|
|
||||||
.WithValue(Channels.TitleEncoderType, Encoder)
|
.WithValue(Channels.TitleEncoderType, Encoder)
|
||||||
.WithValue(Channels.DescriptionEncoderType, Encoder)
|
.WithValue(Channels.DescriptionEncoderType, Encoder)
|
||||||
.WithValue(Channels.EncoderTypes, new[] { Encoder }).Update();
|
.WithValue(Channels.EncoderTypes, new[] { Encoder }).Update();
|
||||||
|
|
||||||
|
|
||||||
Dictionary<string, long> Events = new();
|
Dictionary<string, long> Events = new();
|
||||||
|
int inow = 0;
|
||||||
|
int imax = export.Messages.Length;
|
||||||
foreach (Message msg in export.Messages)
|
foreach (Message msg in export.Messages)
|
||||||
{
|
{
|
||||||
|
inow++;
|
||||||
|
Console.WriteLine(inow + " of " + imax);
|
||||||
if (msg.Type != "m.room.message")
|
if (msg.Type != "m.room.message")
|
||||||
continue;
|
continue;
|
||||||
if (!UserMap.ContainsKey(msg.Sender) && !ChannelProfilesIdList.ContainsKey(msg.Sender))
|
if (!UserMap.ContainsKey(msg.Sender) && !ChannelProfilesIdList.ContainsKey(msg.Sender))
|
||||||
@ -103,18 +100,18 @@ public static class Matrix
|
|||||||
|
|
||||||
Events.Add(msg.Event, sf.ID);
|
Events.Add(msg.Event, sf.ID);
|
||||||
cur = cur.ToLocalTime();
|
cur = cur.ToLocalTime();
|
||||||
bool chanp;
|
|
||||||
long id;
|
long id;
|
||||||
|
long profile = 0;
|
||||||
if (ChannelProfilesIdList.ContainsKey(msg.Sender))
|
if (ChannelProfilesIdList.ContainsKey(msg.Sender))
|
||||||
{
|
{
|
||||||
chanp = true;
|
|
||||||
checkFakeUser(msg.Sender);
|
checkFakeUser(msg.Sender);
|
||||||
id = IdConverter[ChannelProfilesIdList[msg.Sender]];
|
profile = IdConverter[ChannelProfilesIdList[msg.Sender]];
|
||||||
|
id = defaultuser;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
chanp = false;
|
|
||||||
id = UserMap[msg.Sender];
|
id = UserMap[msg.Sender];
|
||||||
|
profile = Tables.Users.Read(Users.ServerProfile, Users.ID.CreateParameter(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.Context.Relations is not null)
|
if (msg.Context.Relations is not null)
|
||||||
@ -207,11 +204,10 @@ public static class Matrix
|
|||||||
Messages.Context.CreateParameter(body.ToDB(Encoder, Encryption)),
|
Messages.Context.CreateParameter(body.ToDB(Encoder, Encryption)),
|
||||||
Messages.ChannelID.CreateParameter(Channel),
|
Messages.ChannelID.CreateParameter(Channel),
|
||||||
Messages.EncoderType.CreateParameter(Encoder),
|
Messages.EncoderType.CreateParameter(Encoder),
|
||||||
Messages.Files.CreateParameter(Array.Empty<long>()),
|
|
||||||
Messages.EncryptionKey.CreateParameter(Encryption),
|
Messages.EncryptionKey.CreateParameter(Encryption),
|
||||||
Messages.AuthorID.CreateParameter(id),
|
Messages.AuthorID.CreateParameter(id),
|
||||||
Messages.IsChannelProfile.CreateParameter(chanp),
|
Messages.ReplyTo.CreateParameter(reply),
|
||||||
Messages.ReplyTo.CreateParameter(reply));
|
Messages.ProfileID.CreateParameter(profile));
|
||||||
break;
|
break;
|
||||||
case "m.image" or "m.video" or "m.audio" or "m.file":
|
case "m.image" or "m.video" or "m.audio" or "m.file":
|
||||||
int h = cur.Hour;
|
int h = cur.Hour;
|
||||||
@ -253,27 +249,24 @@ public static class Matrix
|
|||||||
Files.EncryptionKey.CreateParameter(Encryption),
|
Files.EncryptionKey.CreateParameter(Encryption),
|
||||||
Files.Hash.CreateParameter(JacobTechEncryption.Encryption.Hashing.SHA256(d)),
|
Files.Hash.CreateParameter(JacobTechEncryption.Encryption.Hashing.SHA256(d)),
|
||||||
Files.Owner.CreateParameter(id),
|
Files.Owner.CreateParameter(id),
|
||||||
Files.AllowedChannels.CreateParameter(new long[] { Channel }),
|
|
||||||
Files.Public.CreateParameter(true),
|
Files.Public.CreateParameter(true),
|
||||||
Files.Size.CreateParameter(d.LongLength),
|
Files.Size.CreateParameter(d.LongLength),
|
||||||
Files.NameEncoderType.CreateParameter(Encoder),
|
Files.NameEncoderType.CreateParameter(Encoder),
|
||||||
Files.NameEncryptionKey.CreateParameter(Encryption));
|
Files.NameEncryptionKey.CreateParameter(Encryption));
|
||||||
|
Tables.FileChannels.Insert(FileChannels.ChannelID.CreateParameter(Channel), FileChannels.FileID.CreateParameter(sf.ID));
|
||||||
Tables.Messages.Insert(
|
Tables.Messages.Insert(
|
||||||
Messages.ID.CreateParameter(sf.ID),
|
Messages.ID.CreateParameter(sf.ID),
|
||||||
Messages.Context.CreateParameter(Array.Empty<byte>()),
|
Messages.Context.CreateParameter(Array.Empty<byte>()),
|
||||||
Messages.ChannelID.CreateParameter(Encryption),
|
Messages.ChannelID.CreateParameter(Encryption),
|
||||||
Messages.EncoderType.CreateParameter(Encoder),
|
Messages.EncoderType.CreateParameter(Encoder),
|
||||||
Messages.Files.CreateParameter(new[] { sf.ID }),
|
|
||||||
Messages.EncryptionKey.CreateParameter(Encryption),
|
Messages.EncryptionKey.CreateParameter(Encryption),
|
||||||
Messages.AuthorID.CreateParameter(id),
|
Messages.AuthorID.CreateParameter(id),
|
||||||
Messages.IsChannelProfile.CreateParameter(chanp),
|
|
||||||
Messages.ReplyTo.CreateParameter(reply));
|
Messages.ReplyTo.CreateParameter(reply));
|
||||||
|
Tables.MessageFiles.Insert(MessageFiles.FileID.CreateParameter(sf.ID), MessageFiles.MessageID.CreateParameter(sf.ID));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Tables.Channels.CreateCommand().WithFilter(Channels.ID, Channel).WithValue(Channels.Profiles, IdConverter.Values.ToArray()).Update();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
namespace LuskiServer.Enums.ServerComs;
|
|
||||||
|
|
||||||
public enum DataType
|
|
||||||
{
|
|
||||||
Token,
|
|
||||||
MessageCreate
|
|
||||||
}
|
|
@ -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.1.6</FileVersion>
|
<FileVersion>1.0.0.0</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
@ -21,12 +21,12 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="7.0.0" />
|
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="7.0.0" />
|
||||||
<PackageReference Include="Flurl.Http" Version="2.3.2" />
|
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
|
||||||
<PackageReference Include="Luski.Shared" Version="1.1.0-alpha21" />
|
<PackageReference Include="Luski.Shared" Version="1.1.0-alpha43" />
|
||||||
<PackageReference Include="Markdig" Version="0.36.2" />
|
<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="3.0.8-alpha02" />
|
<PackageReference Include="ServerDatabase" Version="3.0.8-alpha10" />
|
||||||
<PackageReference Include="ServerDatabase.SourceGenerator" Version="1.0.2-alpha12" />
|
<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" />
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Asp.Versioning.ApiExplorer;
|
using Asp.Versioning.ApiExplorer;
|
||||||
|
using BenchmarkDotNet.Running;
|
||||||
|
using JacobTechEncryption;
|
||||||
using JacobTechEncryption.Enums;
|
using JacobTechEncryption.Enums;
|
||||||
using Luski.Shared.PublicServers.V1.Enums;
|
using Luski.Shared.PublicServers.V1.Enums;
|
||||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||||
@ -8,6 +10,7 @@ using LuskiServer;
|
|||||||
using LuskiServer.Classes;
|
using LuskiServer.Classes;
|
||||||
using LuskiServer.Classes.ServerComs;
|
using LuskiServer.Classes.ServerComs;
|
||||||
using LuskiServer.Classes.TableDef;
|
using LuskiServer.Classes.TableDef;
|
||||||
|
using LuskiServer.Converters.Matrix;
|
||||||
using LuskiServer.Converters.Matrix.Types;
|
using LuskiServer.Converters.Matrix.Types;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
@ -29,22 +32,6 @@ 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,
|
||||||
@ -59,15 +46,7 @@ LuskiFunctions.Database = new Database(LuskiFunctions.Config.Address,
|
|||||||
Dictionary<string, List<Message>> fff = new();
|
Dictionary<string, List<Message>> fff = new();
|
||||||
|
|
||||||
|
|
||||||
try
|
LuskiFunctions.Database.TestDatabase();
|
||||||
{
|
|
||||||
LuskiFunctions.Database.ExecuteNonQuery($"CREATE DATABASE {LuskiFunctions.Config.Database} WITH OWNER = {LuskiFunctions.Config.Username} ENCODING = 'UTF8' CONNECTION LIMIT = -1 IS_TEMPLATE = False;");
|
|
||||||
Console.WriteLine("Database Created");
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("Database Found");
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (PropertyInfo prop in typeof(Tables).GetProperties())
|
foreach (PropertyInfo prop in typeof(Tables).GetProperties())
|
||||||
{
|
{
|
||||||
@ -83,12 +62,40 @@ foreach (PropertyInfo prop in typeof(Tables).GetProperties())
|
|||||||
|
|
||||||
LuskiFunctions.Database.RegisterTables();
|
LuskiFunctions.Database.RegisterTables();
|
||||||
|
|
||||||
|
//Tables.ProfileColors.CreateCommand().WithFilter(ProfileColors.Profile, 0).WithValue(ProfileColors.ColorType, ColorType.LeftToRightGradient).WithValue(ProfileColors.Color, Convert.FromHexString("E54D24FFDDB249FF")).Update();
|
||||||
|
|
||||||
|
if (!Tables.Server.TryRead(Server.ID, out _, Server.ID.CreateParameter(0)))
|
||||||
|
{
|
||||||
|
Tables.Server.Insert();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Tables.Profiles.TryRead(Profiles.ID, out _, Profiles.ID.CreateParameter(0)))
|
||||||
|
{
|
||||||
|
Tables.Profiles.Insert(
|
||||||
|
Profiles.ID.CreateParameter(0),
|
||||||
|
Profiles.DisplayName.CreateParameter("Server"),
|
||||||
|
Profiles.PictureType.CreateParameter(PictureType.none),
|
||||||
|
Profiles.Picture.CreateParameter(Array.Empty<byte>()));
|
||||||
|
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 _,
|
||||||
|
LuskiFunctions.Database.VersionsTable.ID.CreateParameter(0)))
|
||||||
|
{
|
||||||
|
LuskiFunctions.Database.VersionsTable.Insert(LuskiFunctions.Database.VersionsTable.ID.CreateParameter(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//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()
|
||||||
{
|
{
|
||||||
{"@jacobtech:matrix.org", 0}
|
{"@jacobtech:matrix.org", 0},
|
||||||
|
//{"@c4tz:matrix.org", 2},
|
||||||
|
//{"@themagicalcats:matrix.org", 2},
|
||||||
|
//{"@captainleader:matrix.org", 1},
|
||||||
|
//{"@kaizenash:matrix.org", 1},
|
||||||
|
//{"@quadro:matrix.org", 4},
|
||||||
|
//{"@bubs_cooper:matrix.org", 3}
|
||||||
};
|
};
|
||||||
|
|
||||||
Dictionary<string, int> BMap = new()
|
Dictionary<string, int> BMap = new()
|
||||||
@ -128,191 +135,19 @@ List<Tuple<string, byte[], PictureType, byte[]>> BMapL = new()
|
|||||||
new("JacobTech Bot", Array.Empty<byte>(), PictureType.none, new byte[] { 114, 213, 174, 255 })
|
new("JacobTech Bot", Array.Empty<byte>(), PictureType.none, new byte[] { 114, 213, 174, 255 })
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
//Matrix.ZipJsonChatExport(File.OpenRead("/home/jacob/Downloads/matrix - Luski Project Discussion - Chat Export - 2024-04-13T18-14-08.180Z.zip"), 2, 0, AMap, BMap, BMapL, new(), EncoderType.UTF16, 0);
|
||||||
|
|
||||||
//
|
|
||||||
//Matrix.ZipJsonChatExport(File.OpenRead("/run/media/jacob/F69D-7CBA/Matrix Keys/l.zip"), 0, AMap, BMap, BMapL, new(), EncoderType.UTF16, 0);
|
|
||||||
//Matrix.ZipJsonChatExport(File.OpenRead("/home/jacob/Downloads/matrix - Luski Project Discussion - Chat Export - 2023-08-08T20-10-12.315Z.zip"), 0, AMap, BMap, BMapL, new(), EncoderType.UTF16, 0);
|
|
||||||
//
|
|
||||||
//Tables.Channels.Update(Channels.ID, 0, ">=", Channels.Color.CreateDefaultParameter());
|
|
||||||
//Tables.Categories.Update(Categories.ID, 0, ">=", Categories.Color.CreateDefaultParameter());
|
|
||||||
|
|
||||||
//Console.WriteLine(Convert.ToHexString(Tables.Channels.Read(Channels.Color, Channels.ID.CreateParameter(3))));
|
|
||||||
|
|
||||||
if (!Tables.Server.TryRead(Server.ID, out _, Server.ID.CreateParameter(0)))
|
|
||||||
{
|
|
||||||
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.Channels.Update(Channels.ID, 1, Channels.PictureType.CreateParameter(PictureType.png), Channels.Picture.CreateParameter(File.ReadAllBytes("/home/jacob/Downloads/zLqHooejmsmKzuMLneUSvjRH.png")));
|
|
||||||
/*
|
|
||||||
Tables.Channels.Insert(
|
|
||||||
Channels.ID.CreateParameter(1),
|
|
||||||
Channels.Parent.CreateParameter(0),
|
|
||||||
Channels.Type.CreateParameter(ChannelType.TextAndVoice),
|
|
||||||
Channels.Description.CreateParameter(Encoding.UTF8.GetBytes("A nother test Chat")),
|
|
||||||
Channels.Name.CreateParameter(Encoding.UTF8.GetBytes("Chat 1")),
|
|
||||||
Channels.RoleOverides.CreateParameter(Array.Empty<long>()),
|
|
||||||
Channels.UserOverides.CreateParameter(Array.Empty<long>()),
|
|
||||||
Channels.Epoch.CreateParameter(DateTime.UtcNow.Date),
|
|
||||||
Channels.TitleEncryptionKey.CreateParameter(0),
|
|
||||||
Channels.DescriptionEncryptionKey.CreateParameter(0),
|
|
||||||
Channels.EncryptionKeys.CreateParameter(new long[]{0}),
|
|
||||||
Channels.TitleEncoderType.CreateParameter(EncoderType.UTF8),
|
|
||||||
Channels.DescriptionEncoderType.CreateParameter(EncoderType.UTF8),
|
|
||||||
Channels.PictureType.CreateParameter(PictureType.png),
|
|
||||||
Channels.Picture.CreateParameter(File.ReadAllBytes("/home/jacob/Downloads/4ba.png")),
|
|
||||||
Channels.EncoderTypes.CreateParameter(new [] { EncoderType.UTF8 }));
|
|
||||||
Tables.Channels.Insert(
|
|
||||||
Channels.ID.CreateParameter(2),
|
|
||||||
Channels.Parent.CreateParameter(1),
|
|
||||||
Channels.Type.CreateParameter(ChannelType.TextAndVoice),
|
|
||||||
Channels.Description.CreateParameter(Encoding.UTF8.GetBytes("A nother test Chat")),
|
|
||||||
Channels.Name.CreateParameter(Encoding.UTF8.GetBytes("Chat 2")),
|
|
||||||
Channels.RoleOverides.CreateParameter(Array.Empty<long>()),
|
|
||||||
Channels.UserOverides.CreateParameter(Array.Empty<long>()),
|
|
||||||
Channels.Epoch.CreateParameter(DateTime.UtcNow.Date),
|
|
||||||
Channels.TitleEncryptionKey.CreateParameter(0),
|
|
||||||
Channels.DescriptionEncryptionKey.CreateParameter(0),
|
|
||||||
Channels.EncryptionKeys.CreateParameter(new long[]{0}),
|
|
||||||
Channels.TitleEncoderType.CreateParameter(EncoderType.UTF8),
|
|
||||||
Channels.DescriptionEncoderType.CreateParameter(EncoderType.UTF8),
|
|
||||||
Channels.PictureType.CreateParameter(PictureType.png),
|
|
||||||
Channels.Picture.CreateParameter(File.ReadAllBytes("/home/jacob/Downloads/4ba.png")),
|
|
||||||
Channels.EncoderTypes.CreateParameter(new [] { EncoderType.UTF8 }));
|
|
||||||
Tables.Channels.Insert(
|
|
||||||
Channels.ID.CreateParameter(3),
|
|
||||||
Channels.Parent.CreateParameter(2),
|
|
||||||
Channels.Type.CreateParameter(ChannelType.TextAndVoice),
|
|
||||||
Channels.Description.CreateParameter(Encoding.UTF8.GetBytes("A nother test Chat")),
|
|
||||||
Channels.Name.CreateParameter(Encoding.UTF8.GetBytes("Chat 3")),
|
|
||||||
Channels.RoleOverides.CreateParameter(Array.Empty<long>()),
|
|
||||||
Channels.UserOverides.CreateParameter(Array.Empty<long>()),
|
|
||||||
Channels.Epoch.CreateParameter(DateTime.UtcNow.Date),
|
|
||||||
Channels.TitleEncryptionKey.CreateParameter(0),
|
|
||||||
Channels.DescriptionEncryptionKey.CreateParameter(0),
|
|
||||||
Channels.EncryptionKeys.CreateParameter(new long[]{0}),
|
|
||||||
Channels.TitleEncoderType.CreateParameter(EncoderType.UTF8),
|
|
||||||
Channels.DescriptionEncoderType.CreateParameter(EncoderType.UTF8),
|
|
||||||
Channels.PictureType.CreateParameter(PictureType.png),
|
|
||||||
Channels.Picture.CreateParameter(File.ReadAllBytes("/home/jacob/Downloads/4ba.png")),
|
|
||||||
Channels.EncoderTypes.CreateParameter(new [] { EncoderType.UTF8 }));
|
|
||||||
Tables.Categories.Insert(
|
|
||||||
Categories.ID.CreateParameter(1),
|
|
||||||
Categories.Name.CreateParameter(Encoding.UTF8.GetBytes("Cat lol")),
|
|
||||||
Categories.Parent.CreateParameter(0),
|
|
||||||
Categories.Description.CreateParameter(
|
|
||||||
Encoding.UTF8.GetBytes("Test cat")),
|
|
||||||
Categories.RoleOverides.CreateParameter(Array.Empty<long>())
|
|
||||||
);
|
|
||||||
Tables.Categories.Insert(
|
|
||||||
Categories.ID.CreateParameter(2),
|
|
||||||
Categories.Name.CreateParameter(Encoding.UTF8.GetBytes("Cat lol")),
|
|
||||||
Categories.Parent.CreateParameter(1),
|
|
||||||
Categories.Description.CreateParameter(
|
|
||||||
Encoding.UTF8.GetBytes("Test cat")),
|
|
||||||
Categories.RoleOverides.CreateParameter(Array.Empty<long>())
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
if (!LuskiFunctions.Database.VersionsTable.TryRead(LuskiFunctions.Database.VersionsTable.ID, out _,
|
|
||||||
LuskiFunctions.Database.VersionsTable.ID.CreateParameter(0)))
|
|
||||||
{
|
|
||||||
LuskiFunctions.Database.VersionsTable.Insert(LuskiFunctions.Database.VersionsTable.ID.CreateParameter(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Tables.Roles.Update(Roles.ID, 1, Roles.Color.CreateParameter(new byte[]{1,143,243,255}));
|
|
||||||
|
|
||||||
/*
|
|
||||||
Tables.Roles.Insert(
|
|
||||||
Roles.ID.CreateParameter(1),
|
|
||||||
Roles.Name.CreateParameter("Mod"),
|
|
||||||
Roles.DisplayName.CreateParameter("Moderators"),
|
|
||||||
Roles.Color.CreateDefaultParameter(),
|
|
||||||
Roles.Description.CreateParameter("Mods for the server"),
|
|
||||||
Roles.ServerPermission.CreateParameter(new[]
|
|
||||||
{
|
|
||||||
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
|
|
||||||
})
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!Tables.Roles.TryRead(Roles.ID, out _, Roles.ID.CreateParameter(0)))
|
if (!Tables.Roles.TryRead(Roles.ID, out _, Roles.ID.CreateParameter(0)))
|
||||||
{
|
{
|
||||||
Tables.Roles.Insert(
|
Tables.Roles.Insert(
|
||||||
Roles.ID.CreateParameter(0),
|
Roles.ID.CreateParameter(0),
|
||||||
Roles.Name.CreateParameter("server"),
|
|
||||||
Roles.DisplayName.CreateParameter("Members"),
|
Roles.DisplayName.CreateParameter("Members"),
|
||||||
Roles.Color.CreateDefaultParameter(),
|
Roles.Color.CreateDefaultParameter(),
|
||||||
Roles.Description.CreateParameter("The default role for the server. Everybody will have this role."),
|
Roles.Description.CreateParameter("The default role for the server. Everybody will have this role."),
|
||||||
Roles.ServerPermissions.CreateParameter(
|
Roles.ServerPermissions.CreateParameter(
|
||||||
ServerPermission.ViewChannels |
|
ServerPermission.ViewChannels |
|
||||||
ServerPermission.ViewCategories |
|
ServerPermission.ViewCategories |
|
||||||
ServerPermission.Nickname |
|
|
||||||
ServerPermission.SendMessages |
|
ServerPermission.SendMessages |
|
||||||
ServerPermission.SendFiles |
|
ServerPermission.SendFiles |
|
||||||
ServerPermission.ChannelPings |
|
ServerPermission.ChannelPings |
|
||||||
@ -326,43 +161,6 @@ if (!Tables.Roles.TryRead(Roles.ID, out _, Roles.ID.CreateParameter(0)))
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Tables.Keys.TryRead(Keys.ID, out _, Keys.ID.CreateParameter(0)))
|
|
||||||
{
|
|
||||||
Tables.Keys.Insert(
|
|
||||||
Keys.ID.CreateParameter(0),
|
|
||||||
Keys.EncryptionType.CreateParameter(EncryptionType.None),
|
|
||||||
Keys.KeyData.CreateParameter(Array.Empty<byte>()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Tables.Categories.TryRead(Categories.ID, out _, Categories.ID.CreateParameter(0)))
|
|
||||||
{
|
|
||||||
Tables.Categories.Insert(
|
|
||||||
Categories.ID.CreateParameter(0),
|
|
||||||
Categories.Name.CreateParameter(Encoding.UTF8.GetBytes("server")),
|
|
||||||
Categories.Parent.CreateParameter(-1),
|
|
||||||
Categories.Description.CreateParameter(
|
|
||||||
Encoding.UTF8.GetBytes("The default category for the server. Everybody will see this category.")),
|
|
||||||
Categories.RoleOverrides.CreateParameter(Array.Empty<long>())
|
|
||||||
);
|
|
||||||
Tables.Channels.Insert(
|
|
||||||
Channels.ID.CreateParameter(0),
|
|
||||||
Channels.Type.CreateParameter(ChannelType.TextAndVoice),
|
|
||||||
Channels.Description.CreateParameter(Encoding.UTF8.GetBytes("Default chat for you to use in your new server")),
|
|
||||||
Channels.Name.CreateParameter(Encoding.UTF8.GetBytes("Default Channel")),
|
|
||||||
Channels.RoleOverrides.CreateParameter(Array.Empty<long>()),
|
|
||||||
Channels.UserOverrides.CreateParameter(Array.Empty<long>()),
|
|
||||||
Channels.Epoch.CreateParameter(DateTime.UtcNow.Date),
|
|
||||||
Channels.TitleEncryptionKey.CreateParameter(0),
|
|
||||||
Channels.Parent.CreateParameter(0),
|
|
||||||
Channels.DescriptionEncryptionKey.CreateParameter(0),
|
|
||||||
Channels.EncryptionKeys.CreateParameter(new long[]{0}),
|
|
||||||
Channels.TitleEncoderType.CreateParameter(EncoderType.UTF8),
|
|
||||||
Channels.DescriptionEncoderType.CreateParameter(EncoderType.UTF8),
|
|
||||||
Channels.PictureType.CreateParameter(PictureType.none),
|
|
||||||
Channels.Picture.CreateParameter(Array.Empty<byte>()),
|
|
||||||
Channels.EncoderTypes.CreateParameter(new [] { EncoderType.UTF8 }));
|
|
||||||
}
|
|
||||||
|
|
||||||
long[] keys = Tables.Sessions.ReadColumn(Sessions.SessionKey);
|
long[] keys = Tables.Sessions.ReadColumn(Sessions.SessionKey);
|
||||||
foreach (long key in keys)
|
foreach (long key in keys)
|
||||||
{
|
{
|
||||||
@ -372,6 +170,7 @@ foreach (long key in keys)
|
|||||||
|
|
||||||
|
|
||||||
Tables.Sessions.DeleteRows();
|
Tables.Sessions.DeleteRows();
|
||||||
|
Tables.Users.CreateCommand().WithValue(Users.Status, UserStatus.Offline).Update();
|
||||||
|
|
||||||
|
|
||||||
foreach (AltServerRow Server in Tables.AltServers.ReadRows())
|
foreach (AltServerRow Server in Tables.AltServers.ReadRows())
|
||||||
@ -379,6 +178,8 @@ foreach (AltServerRow Server in Tables.AltServers.ReadRows())
|
|||||||
//TODO add code to open a live WSS connection with all other servers on the network
|
//TODO add code to open a live WSS connection with all other servers on the network
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WSS.Init(LuskiFunctions.Config.IPv4WSS, LuskiFunctions.Config.IPv4PortWSS, LuskiFunctions.Config.IPv4_URL_WSS!, LuskiFunctions.Config.IPv4SecureWSS, LuskiFunctions.Config.IPv6WSS, LuskiFunctions.Config.IPv6_URL_WSS, LuskiFunctions.Config.IPv6PortWSS, LuskiFunctions.Config.IPv6SecureWSS);
|
WSS.Init(LuskiFunctions.Config.IPv4WSS, LuskiFunctions.Config.IPv4PortWSS, LuskiFunctions.Config.IPv4_URL_WSS!, LuskiFunctions.Config.IPv4SecureWSS, LuskiFunctions.Config.IPv6WSS, LuskiFunctions.Config.IPv6_URL_WSS, LuskiFunctions.Config.IPv6PortWSS, LuskiFunctions.Config.IPv6SecureWSS);
|
||||||
|
|
||||||
WebApplicationBuilder builder = WebApplication.CreateBuilder( args );
|
WebApplicationBuilder builder = WebApplication.CreateBuilder( args );
|
||||||
|
Loading…
Reference in New Issue
Block a user