mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] GetPermissions/GivePermissions command
This commit is contained in:
parent
5c88b8eb14
commit
e9f36fa44f
9 changed files with 123 additions and 0 deletions
|
@ -19,6 +19,11 @@ public ClientPermissions getPermissions(String username) {
|
||||||
return permissions;
|
return permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPermissions(String username, ClientPermissions permissions) {
|
||||||
|
//Unsupported
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,11 @@ public ClientPermissions getPermissions(String username) {
|
||||||
return ClientPermissions.DEFAULT;
|
return ClientPermissions.DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPermissions(String username, ClientPermissions permissions) {
|
||||||
|
//Unsupported
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws Exception {
|
public void close() throws Exception {
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,11 @@ public ClientPermissions getPermissions(String username) {
|
||||||
return map.getOrDefault(username, ClientPermissions.DEFAULT);
|
return map.getOrDefault(username, ClientPermissions.DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPermissions(String username, ClientPermissions permissions) {
|
||||||
|
map.put(username, permissions);
|
||||||
|
}
|
||||||
|
|
||||||
public JsonFilePermissionsHandler() {
|
public JsonFilePermissionsHandler() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,11 @@ public ClientPermissions getPermissions(String username) {
|
||||||
return new ClientPermissions(map.getOrDefault(username, defaultPerms));
|
return new ClientPermissions(map.getOrDefault(username, defaultPerms));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPermissions(String username, ClientPermissions permissions) {
|
||||||
|
map.put(username, permissions.toLong());
|
||||||
|
}
|
||||||
|
|
||||||
public JsonLongFilePermissionsHandler() {
|
public JsonLongFilePermissionsHandler() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,4 +41,6 @@ public static void registerHandlers() {
|
||||||
public abstract void init();
|
public abstract void init();
|
||||||
|
|
||||||
public abstract ClientPermissions getPermissions(String username);
|
public abstract ClientPermissions getPermissions(String username);
|
||||||
|
|
||||||
|
public abstract void setPermissions(String username, ClientPermissions permissions);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,5 +66,7 @@ public static void registerCommands(ru.gravit.utils.command.CommandHandler handl
|
||||||
handler.registerCommand("multi", new MultiCommand(server));
|
handler.registerCommand("multi", new MultiCommand(server));
|
||||||
handler.registerCommand("getModulus", new GetModulusCommand(server));
|
handler.registerCommand("getModulus", new GetModulusCommand(server));
|
||||||
handler.registerCommand("component", new ComponentCommand(server));
|
handler.registerCommand("component", new ComponentCommand(server));
|
||||||
|
handler.registerCommand("givePermission", new GivePermissionsCommand(server));
|
||||||
|
handler.registerCommand("getPermissions", new GetPermissionsCommand(server));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package ru.gravit.launchserver.command.service;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
public class GetPermissionsCommand extends Command {
|
||||||
|
public GetPermissionsCommand(LaunchServer server) {
|
||||||
|
super(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getArgsDescription() {
|
||||||
|
return "[username]";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsageDescription() {
|
||||||
|
return "print username permissions";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(String... args) throws Exception {
|
||||||
|
verifyArgs(args,1);
|
||||||
|
String username = args[0];
|
||||||
|
ClientPermissions permissions = server.config.permissionsHandler.getPermissions(username);
|
||||||
|
LogHelper.info("Permissions %s: %s (long: %d)", username, permissions.toString(), permissions.toLong());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
package ru.gravit.launchserver.command.service;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.ClientPermissions;
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
public class GivePermissionsCommand extends Command {
|
||||||
|
public GivePermissionsCommand(LaunchServer server) {
|
||||||
|
super(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getArgsDescription() {
|
||||||
|
return "[username] [permission] [true/false]";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsageDescription() {
|
||||||
|
return "give permissions";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(String... args) throws Exception {
|
||||||
|
verifyArgs(args, 3);
|
||||||
|
String username = args[0];
|
||||||
|
ClientPermissions permissions = server.config.permissionsHandler.getPermissions(username);
|
||||||
|
String permission = args[1];
|
||||||
|
boolean isEnabled = Boolean.valueOf(args[2]);
|
||||||
|
switch (permission)
|
||||||
|
{
|
||||||
|
case "admin":
|
||||||
|
{
|
||||||
|
permissions.canAdmin = isEnabled;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "server":
|
||||||
|
{
|
||||||
|
permissions.canServer = isEnabled;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "bot":
|
||||||
|
{
|
||||||
|
permissions.canBot = isEnabled;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
LogHelper.error("Unknown permission: %s", permission);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LogHelper.info("Write new permissions for %s", username);
|
||||||
|
server.config.permissionsHandler.setPermissions(username, permissions);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
public class ClientPermissions {
|
public class ClientPermissions {
|
||||||
public static final ClientPermissions DEFAULT = new ClientPermissions();
|
public static final ClientPermissions DEFAULT = new ClientPermissions();
|
||||||
|
@ -64,4 +65,16 @@ public static ClientPermissions getSuperuserAccount() {
|
||||||
public void write(HOutput output) throws IOException {
|
public void write(HOutput output) throws IOException {
|
||||||
output.writeLong(toLong());
|
output.writeLong(toLong());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue