2019-01-04 18:45:11 +03:00
|
|
|
package ru.gravit.launcher;
|
|
|
|
|
|
|
|
import ru.gravit.launcher.serialize.HInput;
|
|
|
|
import ru.gravit.launcher.serialize.HOutput;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2019-04-03 12:21:53 +03:00
|
|
|
import java.util.StringJoiner;
|
2018-10-01 13:08:16 +03:00
|
|
|
|
|
|
|
public class ClientPermissions {
|
|
|
|
public static final ClientPermissions DEFAULT = new ClientPermissions();
|
2019-01-04 18:45:11 +03:00
|
|
|
@LauncherAPI
|
2019-04-03 11:51:41 +03:00
|
|
|
public boolean canAdmin;
|
2019-01-04 18:45:11 +03:00
|
|
|
@LauncherAPI
|
2019-04-03 11:51:41 +03:00
|
|
|
public boolean canServer;
|
2019-01-21 16:38:51 +03:00
|
|
|
@LauncherAPI
|
2019-04-03 11:51:41 +03:00
|
|
|
public boolean canUSR1;
|
2019-01-21 16:38:51 +03:00
|
|
|
@LauncherAPI
|
2019-04-03 11:51:41 +03:00
|
|
|
public boolean canUSR2;
|
2019-01-21 16:38:51 +03:00
|
|
|
@LauncherAPI
|
2019-04-03 11:51:41 +03:00
|
|
|
public boolean canUSR3;
|
2019-01-21 16:38:51 +03:00
|
|
|
@LauncherAPI
|
2019-04-03 11:51:41 +03:00
|
|
|
public boolean canBot;
|
2019-01-15 06:35:39 +03:00
|
|
|
|
2019-01-04 18:45:11 +03:00
|
|
|
public ClientPermissions(HInput input) throws IOException {
|
2019-04-03 11:51:41 +03:00
|
|
|
this(input.readLong());
|
2019-01-04 18:45:11 +03:00
|
|
|
}
|
2019-01-15 06:35:39 +03:00
|
|
|
|
2018-10-01 13:08:16 +03:00
|
|
|
public ClientPermissions() {
|
|
|
|
canAdmin = false;
|
|
|
|
canServer = false;
|
2019-01-21 16:38:51 +03:00
|
|
|
canUSR1 = false;
|
|
|
|
canUSR2 = false;
|
|
|
|
canUSR3 = false;
|
|
|
|
canBot = false;
|
2018-10-01 13:08:16 +03:00
|
|
|
}
|
2018-11-08 15:30:16 +03:00
|
|
|
|
2018-10-05 11:25:12 +03:00
|
|
|
public ClientPermissions(long data) {
|
2018-11-08 15:30:16 +03:00
|
|
|
canAdmin = (data & (1)) != 0;
|
2018-10-05 11:25:12 +03:00
|
|
|
canServer = (data & (1 << 1)) != 0;
|
2019-01-21 16:38:51 +03:00
|
|
|
canUSR1 = (data & (1 << 2)) != 0;
|
|
|
|
canUSR2 = (data & (1 << 3)) != 0;
|
|
|
|
canUSR3 = (data & (1 << 4)) != 0;
|
|
|
|
canBot = (data & (1 << 5)) != 0;
|
2018-10-05 11:25:12 +03:00
|
|
|
}
|
2019-04-03 16:27:40 +03:00
|
|
|
|
2019-01-22 08:29:57 +03:00
|
|
|
@LauncherAPI
|
2019-04-03 16:27:40 +03:00
|
|
|
public long toLong() {
|
2019-01-21 16:42:26 +03:00
|
|
|
long result = 0;
|
|
|
|
result |= canAdmin ? 0 : 1;
|
|
|
|
result |= canServer ? 0 : (1 << 1);
|
|
|
|
result |= canUSR1 ? 0 : (1 << 2);
|
|
|
|
result |= canUSR2 ? 0 : (1 << 3);
|
|
|
|
result |= canUSR3 ? 0 : (1 << 4);
|
|
|
|
result |= canBot ? 0 : (1 << 5);
|
|
|
|
return result;
|
|
|
|
}
|
2018-11-08 15:30:16 +03:00
|
|
|
|
|
|
|
public static ClientPermissions getSuperuserAccount() {
|
2018-10-05 11:36:50 +03:00
|
|
|
ClientPermissions perm = new ClientPermissions();
|
|
|
|
perm.canServer = true;
|
|
|
|
perm.canAdmin = true;
|
|
|
|
return perm;
|
|
|
|
}
|
2019-01-15 06:35:39 +03:00
|
|
|
|
2019-01-04 18:45:11 +03:00
|
|
|
public void write(HOutput output) throws IOException {
|
2019-04-03 11:51:41 +03:00
|
|
|
output.writeLong(toLong());
|
2019-01-04 18:45:11 +03:00
|
|
|
}
|
2019-04-03 12:21:53 +03:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return new StringJoiner(", ", ClientPermissions.class.getSimpleName() + "[", "]")
|
|
|
|
.add("canAdmin=" + canAdmin)
|
|
|
|
.add("canServer=" + canServer)
|
|
|
|
.add("canUSR1=" + canUSR1)
|
|
|
|
.add("canUSR2=" + canUSR2)
|
|
|
|
.add("canUSR3=" + canUSR3)
|
|
|
|
.add("canBot=" + canBot)
|
|
|
|
.toString();
|
|
|
|
}
|
2018-10-01 13:08:16 +03:00
|
|
|
}
|