Code Style
Fixed an indent.
This commit is contained in:
parent
39c5401cdb
commit
5e3dca5ce2
@ -65,28 +65,77 @@ public static class Luski
|
|||||||
|
|
||||||
public static AppConfig Config = null!;
|
public static AppConfig Config = null!;
|
||||||
|
|
||||||
public static bool HasAccessToChannel(long User, long Channel, params ServerPermissions[] RequiredPerms)
|
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)
|
|
||||||
{
|
{
|
||||||
more = more2;
|
long[] UserRoleIDList = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(User));
|
||||||
if (more2 && pp.Contains(ServerPermissions.ViewCategories)) pp.Add(ServerPermissions.ViewCategories);
|
List<ServerPermissions> pp = RequiredPerms.ToList();
|
||||||
long Parent = Tables.Categories.Read(Categories.Parent, Categories.ID.CreateParameter(Channel));
|
if (!pp.Contains(ServerPermissions.ViewChannels)) pp.Add(ServerPermissions.ViewChannels);
|
||||||
if (Parent != -1 && !CheckCatPerm(Parent, pp, true)) return false;
|
List<ServerPermissions> GoodPerms = new();
|
||||||
long[] CatUserOverides = Tables.Categories.Read(Categories.UserOverides, Categories.ID.CreateParameter(Cat));
|
bool more = false;
|
||||||
foreach (long CatUserOveride in CatUserOverides)
|
bool CheckCatPerm(long Cat, List<ServerPermissions> NeededPerms, bool more2 = false)
|
||||||
{
|
{
|
||||||
if (Tables.UserRoleOverides.Read(UserRoleOverides.UserID, UserRoleOverides.ID.CreateParameter(CatUserOveride)) != User) continue;
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
foreach (ServerPermissions p in NeededPerms)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
foreach (ServerPermissions p in NeededPerms)
|
||||||
|
{
|
||||||
|
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 (!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,
|
string[] overrids = Tables.UserRoleOverides.Read(UserRoleOverides.Overides,
|
||||||
UserRoleOverides.ID.CreateParameter(CatUserOveride));
|
UserRoleOverides.ID.CreateParameter(ChanUserOveride));
|
||||||
foreach (string o in overrids)
|
foreach (string o in overrids)
|
||||||
{
|
{
|
||||||
foreach (ServerPermissions p in NeededPerms)
|
foreach (ServerPermissions p in pp)
|
||||||
{
|
{
|
||||||
if (o.StartsWith($"{p.GetNumberString()}:"))
|
if (o.StartsWith($"{p.GetNumberString()}:"))
|
||||||
{
|
{
|
||||||
@ -96,15 +145,15 @@ public static bool HasAccessToChannel(long User, long Channel, params ServerPerm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
long[] CatRoleOverides = Tables.Categories.Read(Categories.RoleOverides, Categories.ID.CreateParameter(Cat));
|
long[] ChanRoleOverides = Tables.Channels.Read(Channels.RoleOverides, Channels.ID.CreateParameter(Channel));
|
||||||
foreach (long CatRoleOveride in CatRoleOverides)
|
foreach (long ChanRoleOveride in ChanRoleOverides)
|
||||||
{
|
{
|
||||||
if (!UserRoleIDList.Contains(Tables.ServerRoleOverides.Read(ServerRoleOverides.RoleID, ServerRoleOverides.ID.CreateParameter(CatRoleOveride)))) continue;
|
if (!UserRoleIDList.Contains(Tables.ServerRoleOverides.Read(ServerRoleOverides.RoleID, ServerRoleOverides.ID.CreateParameter(ChanRoleOveride)))) continue;
|
||||||
string[] overrids = Tables.UserRoleOverides.Read(ServerRoleOverides.Overides,
|
string[] overrids = Tables.UserRoleOverides.Read(ServerRoleOverides.Overides,
|
||||||
ServerRoleOverides.ID.CreateParameter(CatRoleOveride));
|
ServerRoleOverides.ID.CreateParameter(ChanRoleOveride));
|
||||||
foreach (string o in overrids)
|
foreach (string o in overrids)
|
||||||
{
|
{
|
||||||
foreach (ServerPermissions p in NeededPerms)
|
foreach (ServerPermissions p in pp)
|
||||||
{
|
{
|
||||||
if (o.StartsWith($"{p.GetNumberString()}:"))
|
if (o.StartsWith($"{p.GetNumberString()}:"))
|
||||||
{
|
{
|
||||||
@ -115,59 +164,10 @@ public static bool HasAccessToChannel(long User, long Channel, params ServerPerm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GoodPerms.Count == NeededPerms.Count) return true;
|
if (GoodPerms.Count == pp.Count) return true;
|
||||||
return false;
|
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
|
public static class Info
|
||||||
{
|
{
|
||||||
public static class Routes
|
public static class Routes
|
||||||
|
@ -23,33 +23,31 @@ public class SocketMessageController : ControllerBase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!this.CanTokenRequest(out long ID, out IActionResult? toc) && toc != null) return toc;
|
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)));
|
UserID = ID,
|
||||||
ChannelType type = Tables.Channels.Read(Channels.Type, Channels.ID.CreateParameter(data.ChannelID));
|
ChannelID = data.ChannelID,
|
||||||
MessageEvent MessageEvent = new()
|
Base64Context = data.Base64Context,
|
||||||
{
|
ID = Id.ID
|
||||||
UserID = ID,
|
};
|
||||||
ChannelID = data.ChannelID,
|
Tables.Messages.Insert(
|
||||||
Base64Context = data.Base64Context,
|
Messages.ChannelID.CreateParameter(data.ChannelID),
|
||||||
ID = Id.ID
|
Messages.ID.CreateParameter(Id.ID),
|
||||||
};
|
Messages.AuthorID.CreateParameter(ID),
|
||||||
Tables.Messages.Insert(
|
Messages.Context.CreateParameter(Convert.FromBase64String(data.Base64Context)),
|
||||||
Messages.ChannelID.CreateParameter(data.ChannelID),
|
Messages.TimeStamp.CreateParameter(Id.Timestamp),
|
||||||
Messages.ID.CreateParameter(Id.ID),
|
Messages.Files.CreateParameter(data.Files),
|
||||||
Messages.AuthorID.CreateParameter(ID),
|
Messages.EncoderType.CreateParameter(data.Encoding),
|
||||||
Messages.Context.CreateParameter(Convert.FromBase64String(data.Base64Context)),
|
Messages.EncryptionType.CreateParameter(data.Encryption));
|
||||||
Messages.TimeStamp.CreateParameter(Id.Timestamp),
|
//TODO Get all ID for members to send to
|
||||||
Messages.Files.CreateParameter(data.Files),
|
WSS.SendData(SendType.ID_Group, new ServerEvent()
|
||||||
Messages.EncoderType.CreateParameter(data.Encoding),
|
{
|
||||||
Messages.EncryptionType.CreateParameter(data.Encryption));
|
Type = DataType.MessageCreate,
|
||||||
//TODO Get all ID for members to send to
|
Data = MessageEvent
|
||||||
WSS.SendData(SendType.ID_Group, new ServerEvent()
|
}, Array.Empty<long>());
|
||||||
{
|
|
||||||
Type = DataType.MessageCreate,
|
|
||||||
Data = MessageEvent
|
|
||||||
}, Array.Empty<long>());
|
|
||||||
}
|
|
||||||
Response.StatusCode = 201;
|
Response.StatusCode = 201;
|
||||||
return null!;
|
return null!;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user