Launcher/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java

112 lines
2.6 KiB
Java
Raw Normal View History

package pro.gravit.launcher;
2019-06-03 10:58:10 +03:00
import pro.gravit.launcher.serialize.HInput;
import pro.gravit.launcher.serialize.HOutput;
2019-10-19 19:46:04 +03:00
import java.io.IOException;
2018-10-01 13:08:16 +03:00
public class ClientPermissions {
public static final ClientPermissions DEFAULT = new ClientPermissions();
2020-04-05 17:47:21 +03:00
@LauncherNetworkAPI
public long permissions;
2020-04-05 17:47:21 +03:00
@LauncherNetworkAPI
public long flags;
2019-01-15 06:35:39 +03:00
public ClientPermissions(HInput input) throws IOException {
this(input.readLong());
}
2019-01-15 06:35:39 +03:00
2018-10-01 13:08:16 +03:00
public ClientPermissions() {
2018-10-01 13:08:16 +03:00
}
2018-11-08 15:30:16 +03:00
public ClientPermissions(long permissions) {
this.permissions = permissions;
}
2019-04-03 16:27:40 +03:00
public ClientPermissions(long permissions, long flags) {
this.permissions = permissions;
this.flags = flags;
}
2018-11-08 15:30:16 +03:00
public static ClientPermissions getSuperuserAccount() {
ClientPermissions perm = new ClientPermissions();
return perm;
}
2020-04-05 10:27:04 +03:00
public long toLong() {
return permissions;
}
@Deprecated
public void write(HOutput output) throws IOException {
output.writeLong(toLong());
}
//Read methods
2020-04-05 10:27:04 +03:00
public final boolean isPermission(PermissionConsts con) {
return (permissions & con.mask) != 0;
}
2020-04-05 10:27:04 +03:00
public final boolean isPermission(long mask) {
return (permissions & mask) != 0;
}
2020-04-05 10:27:04 +03:00
public final boolean isFlag(FlagConsts con) {
return (flags & con.mask) != 0;
}
2020-04-05 10:27:04 +03:00
public final boolean isFlag(long mask) {
return (flags & mask) != 0;
}
2020-04-05 10:27:04 +03:00
//Write methods
2020-04-05 10:27:04 +03:00
public final void setPermission(PermissionConsts con, boolean value) {
if (value) this.permissions |= con.mask;
else this.permissions &= ~con.mask;
}
2020-04-05 10:27:04 +03:00
public final void setPermission(long mask, boolean value) {
if (value) this.permissions |= mask;
else this.permissions &= ~mask;
}
2020-04-05 10:27:04 +03:00
public final void setFlag(FlagConsts con, boolean value) {
if (value) this.flags |= con.mask;
else this.flags &= ~con.mask;
}
2020-04-05 10:27:04 +03:00
public final void setFlag(long mask, boolean value) {
if (value) this.flags |= mask;
else this.flags &= ~mask;
}
@Override
public String toString() {
return String.format("permissions %d | flags %d", permissions, flags);
}
2020-04-05 10:27:04 +03:00
public enum PermissionConsts {
ADMIN(0x01),
MANAGEMENT(0x02);
public final long mask;
PermissionConsts(long mask) {
this.mask = mask;
}
}
public enum FlagConsts {
SYSTEM(0x01),
BANNED(0x02),
UNTRUSTED(0x04),
HIDDEN(0x08);
public final long mask;
FlagConsts(long mask) {
this.mask = mask;
}
}
2018-10-01 13:08:16 +03:00
}