Code Style

Fixed an indent.
This commit is contained in:
JacobTech 2023-05-21 19:58:14 -04:00
parent 39c5401cdb
commit 5e3dca5ce2
2 changed files with 108 additions and 110 deletions

View File

@ -65,108 +65,108 @@ public static class Luski
public static AppConfig Config = null!;
public static bool HasAccessToChannel(long User, long Channel, params ServerPermissions[] RequiredPerms)
{
long[] UserRoleIDList = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(User));
List<ServerPermissions> pp = RequiredPerms.ToList();
if (!pp.Contains(ServerPermissions.ViewChannels)) pp.Add(ServerPermissions.ViewChannels);
List<ServerPermissions> GoodPerms = new();
bool more = false;
bool CheckCatPerm(long Cat, List<ServerPermissions> NeededPerms, bool more2 = false)
public static bool HasAccessToChannel(long User, long Channel, params ServerPermissions[] RequiredPerms)
{
more = more2;
if (more2 && pp.Contains(ServerPermissions.ViewCategories)) pp.Add(ServerPermissions.ViewCategories);
long Parent = Tables.Categories.Read(Categories.Parent, Categories.ID.CreateParameter(Channel));
if (Parent != -1 && !CheckCatPerm(Parent, pp, true)) return false;
long[] CatUserOverides = Tables.Categories.Read(Categories.UserOverides, Categories.ID.CreateParameter(Cat));
foreach (long CatUserOveride in CatUserOverides)
long[] UserRoleIDList = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(User));
List<ServerPermissions> pp = RequiredPerms.ToList();
if (!pp.Contains(ServerPermissions.ViewChannels)) pp.Add(ServerPermissions.ViewChannels);
List<ServerPermissions> GoodPerms = new();
bool more = false;
bool CheckCatPerm(long Cat, List<ServerPermissions> NeededPerms, bool more2 = false)
{
if (Tables.UserRoleOverides.Read(UserRoleOverides.UserID, UserRoleOverides.ID.CreateParameter(CatUserOveride)) != User) continue;
string[] overrids = Tables.UserRoleOverides.Read(UserRoleOverides.Overides,
UserRoleOverides.ID.CreateParameter(CatUserOveride));
foreach (string o in overrids)
more = more2;
if (more2 && pp.Contains(ServerPermissions.ViewCategories)) pp.Add(ServerPermissions.ViewCategories);
long Parent = Tables.Categories.Read(Categories.Parent, Categories.ID.CreateParameter(Channel));
if (Parent != -1 && !CheckCatPerm(Parent, pp, true)) return false;
long[] CatUserOverides = Tables.Categories.Read(Categories.UserOverides, Categories.ID.CreateParameter(Cat));
foreach (long CatUserOveride in CatUserOverides)
{
foreach (ServerPermissions p in NeededPerms)
if (Tables.UserRoleOverides.Read(UserRoleOverides.UserID, UserRoleOverides.ID.CreateParameter(CatUserOveride)) != User) continue;
string[] overrids = Tables.UserRoleOverides.Read(UserRoleOverides.Overides,
UserRoleOverides.ID.CreateParameter(CatUserOveride));
foreach (string o in overrids)
{
if (o.StartsWith($"{p.GetNumberString()}:"))
foreach (ServerPermissions p in NeededPerms)
{
if (o.EndsWith("0")) return false;
else GoodPerms.Add(p);
if (o.StartsWith($"{p.GetNumberString()}:"))
{
if (o.EndsWith("0")) return false;
else GoodPerms.Add(p);
}
}
}
}
}
long[] CatRoleOverides = Tables.Categories.Read(Categories.RoleOverides, Categories.ID.CreateParameter(Cat));
foreach (long CatRoleOveride in CatRoleOverides)
{
if (!UserRoleIDList.Contains(Tables.ServerRoleOverides.Read(ServerRoleOverides.RoleID, ServerRoleOverides.ID.CreateParameter(CatRoleOveride)))) continue;
string[] overrids = Tables.UserRoleOverides.Read(ServerRoleOverides.Overides,
ServerRoleOverides.ID.CreateParameter(CatRoleOveride));
foreach (string o in overrids)
long[] CatRoleOverides = Tables.Categories.Read(Categories.RoleOverides, Categories.ID.CreateParameter(Cat));
foreach (long CatRoleOveride in CatRoleOverides)
{
foreach (ServerPermissions p in NeededPerms)
if (!UserRoleIDList.Contains(Tables.ServerRoleOverides.Read(ServerRoleOverides.RoleID, ServerRoleOverides.ID.CreateParameter(CatRoleOveride)))) continue;
string[] overrids = Tables.UserRoleOverides.Read(ServerRoleOverides.Overides,
ServerRoleOverides.ID.CreateParameter(CatRoleOveride));
foreach (string o in overrids)
{
if (o.StartsWith($"{p.GetNumberString()}:"))
foreach (ServerPermissions p in NeededPerms)
{
if (o.EndsWith("0")) return false;
else GoodPerms.Add(p);
if (o.StartsWith($"{p.GetNumberString()}:"))
{
if (o.EndsWith("0")) return false;
else GoodPerms.Add(p);
}
}
}
}
if (GoodPerms.Count == NeededPerms.Count) return true;
return false;
}
if (GoodPerms.Count == NeededPerms.Count) return true;
if (!CheckCatPerm(Tables.Channels.Read(Channels.Parent, Channels.ID.CreateParameter(Channel)), pp)) return false;
if (more && !GoodPerms.Contains(ServerPermissions.ViewCategories)) return false;
foreach (ServerPermissions v in GoodPerms)
{
pp.Remove(v);
}
GoodPerms.Clear();
long[] ChanUserOverides = Tables.Channels.Read(Channels.UserOverides, Channels.ID.CreateParameter(Channel));
foreach (long ChanUserOveride in ChanUserOverides)
{
if (Tables.UserRoleOverides.Read(UserRoleOverides.UserID, UserRoleOverides.ID.CreateParameter(ChanUserOveride)) != User) continue;
string[] overrids = Tables.UserRoleOverides.Read(UserRoleOverides.Overides,
UserRoleOverides.ID.CreateParameter(ChanUserOveride));
foreach (string o in overrids)
{
foreach (ServerPermissions p in pp)
{
if (o.StartsWith($"{p.GetNumberString()}:"))
{
if (o.EndsWith("0")) return false;
else GoodPerms.Add(p);
}
}
}
}
long[] ChanRoleOverides = Tables.Channels.Read(Channels.RoleOverides, Channels.ID.CreateParameter(Channel));
foreach (long ChanRoleOveride in ChanRoleOverides)
{
if (!UserRoleIDList.Contains(Tables.ServerRoleOverides.Read(ServerRoleOverides.RoleID, ServerRoleOverides.ID.CreateParameter(ChanRoleOveride)))) continue;
string[] overrids = Tables.UserRoleOverides.Read(ServerRoleOverides.Overides,
ServerRoleOverides.ID.CreateParameter(ChanRoleOveride));
foreach (string o in overrids)
{
foreach (ServerPermissions p in pp)
{
if (o.StartsWith($"{p.GetNumberString()}:"))
{
if (o.EndsWith("0")) return false;
else GoodPerms.Add(p);
}
}
}
}
if (GoodPerms.Count == pp.Count) return true;
return false;
}
if (!CheckCatPerm(Tables.Channels.Read(Channels.Parent, Channels.ID.CreateParameter(Channel)), pp)) return false;
if (more && !GoodPerms.Contains(ServerPermissions.ViewCategories)) return false;
foreach (ServerPermissions v in GoodPerms)
{
pp.Remove(v);
}
GoodPerms.Clear();
long[] ChanUserOverides = Tables.Channels.Read(Channels.UserOverides, Channels.ID.CreateParameter(Channel));
foreach (long ChanUserOveride in ChanUserOverides)
{
if (Tables.UserRoleOverides.Read(UserRoleOverides.UserID, UserRoleOverides.ID.CreateParameter(ChanUserOveride)) != User) continue;
string[] overrids = Tables.UserRoleOverides.Read(UserRoleOverides.Overides,
UserRoleOverides.ID.CreateParameter(ChanUserOveride));
foreach (string o in overrids)
{
foreach (ServerPermissions p in pp)
{
if (o.StartsWith($"{p.GetNumberString()}:"))
{
if (o.EndsWith("0")) return false;
else GoodPerms.Add(p);
}
}
}
}
long[] ChanRoleOverides = Tables.Channels.Read(Channels.RoleOverides, Channels.ID.CreateParameter(Channel));
foreach (long ChanRoleOveride in ChanRoleOverides)
{
if (!UserRoleIDList.Contains(Tables.ServerRoleOverides.Read(ServerRoleOverides.RoleID, ServerRoleOverides.ID.CreateParameter(ChanRoleOveride)))) continue;
string[] overrids = Tables.UserRoleOverides.Read(ServerRoleOverides.Overides,
ServerRoleOverides.ID.CreateParameter(ChanRoleOveride));
foreach (string o in overrids)
{
foreach (ServerPermissions p in pp)
{
if (o.StartsWith($"{p.GetNumberString()}:"))
{
if (o.EndsWith("0")) return false;
else GoodPerms.Add(p);
}
}
}
}
if (GoodPerms.Count == pp.Count) return true;
return false;
}
public static class Info
{

View File

@ -23,33 +23,31 @@ public class SocketMessageController : ControllerBase
try
{
if (!this.CanTokenRequest(out long ID, out IActionResult? toc) && toc != null) return toc;
if (Luski.HasAccessToChannel(ID, data.ChannelID, ServerPermissions.SendMessages))
if (!Luski.HasAccessToChannel(ID, data.ChannelID, ServerPermissions.SendMessages)) return this.ResponseToResult(new HTTPResponse() { error = ErrorCode.Forbidden });
Luski.Snowflake Id = Luski.Snowflake.GenerateSnowflake(Tables.Channels.Read(Channels.Epoch, Channels.ID.CreateParameter(data.ChannelID)));
ChannelType type = Tables.Channels.Read(Channels.Type, Channels.ID.CreateParameter(data.ChannelID));
MessageEvent MessageEvent = new()
{
Luski.Snowflake Id = Luski.Snowflake.GenerateSnowflake(Tables.Channels.Read(Channels.Epoch, Channels.ID.CreateParameter(data.ChannelID)));
ChannelType type = Tables.Channels.Read(Channels.Type, Channels.ID.CreateParameter(data.ChannelID));
MessageEvent MessageEvent = new()
{
UserID = ID,
ChannelID = data.ChannelID,
Base64Context = data.Base64Context,
ID = Id.ID
};
Tables.Messages.Insert(
Messages.ChannelID.CreateParameter(data.ChannelID),
Messages.ID.CreateParameter(Id.ID),
Messages.AuthorID.CreateParameter(ID),
Messages.Context.CreateParameter(Convert.FromBase64String(data.Base64Context)),
Messages.TimeStamp.CreateParameter(Id.Timestamp),
Messages.Files.CreateParameter(data.Files),
Messages.EncoderType.CreateParameter(data.Encoding),
Messages.EncryptionType.CreateParameter(data.Encryption));
//TODO Get all ID for members to send to
WSS.SendData(SendType.ID_Group, new ServerEvent()
{
Type = DataType.MessageCreate,
Data = MessageEvent
}, Array.Empty<long>());
}
UserID = ID,
ChannelID = data.ChannelID,
Base64Context = data.Base64Context,
ID = Id.ID
};
Tables.Messages.Insert(
Messages.ChannelID.CreateParameter(data.ChannelID),
Messages.ID.CreateParameter(Id.ID),
Messages.AuthorID.CreateParameter(ID),
Messages.Context.CreateParameter(Convert.FromBase64String(data.Base64Context)),
Messages.TimeStamp.CreateParameter(Id.Timestamp),
Messages.Files.CreateParameter(data.Files),
Messages.EncoderType.CreateParameter(data.Encoding),
Messages.EncryptionType.CreateParameter(data.Encryption));
//TODO Get all ID for members to send to
WSS.SendData(SendType.ID_Group, new ServerEvent()
{
Type = DataType.MessageCreate,
Data = MessageEvent
}, Array.Empty<long>());
Response.StatusCode = 201;
return null!;
}