scarpet run() runs with scriptACE permissions. Fixes #175
This commit is contained in:
1 parent
c0e72fe669
commit
893122fe1f
3 files changed
+31
-2
No files matched your search
@@ -2,6 +2,7 @@ package carpet;
|
||||
|
||||
import carpet.settings.ParsedRule;
|
||||
import carpet.settings.Rule;
|
||||
import carpet.settings.SettingsManager;
|
||||
import carpet.settings.Validator;
|
||||
import carpet.utils.Messenger;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -39,6 +40,7 @@ public class CarpetSettings
|
||||
public static boolean impendingFillSkipUpdates = false;
|
||||
public static Box currentTelepotingEntityBox = null;
|
||||
public static Vec3d fixedPosition = null;
|
||||
public static int runPermissionLevel = 2;
|
||||
|
||||
@Rule(
|
||||
desc = "Nether portals correctly place entities going through",
|
||||
@@ -311,13 +313,22 @@ public class CarpetSettings
|
||||
)
|
||||
public static String commandScript = "true";
|
||||
|
||||
private static class ModulePermissionLevel extends Validator<String> {
|
||||
@Override public String validate(ServerCommandSource source, ParsedRule<String> currentRule, String newValue, String string) {
|
||||
CarpetSettings.runPermissionLevel = SettingsManager.getCommandLevel(newValue);
|
||||
return newValue;
|
||||
}
|
||||
@Override
|
||||
public String description() { return "Also controls permission level of commands executed via `run()`";}
|
||||
}
|
||||
@Rule(
|
||||
desc = "Enables restrictions for arbitrary code execution with scarpet",
|
||||
extra = {
|
||||
"Users that don't have this permission level",
|
||||
"won't be able to load apps or /script run"
|
||||
},
|
||||
category = {COMMAND, SCARPET}
|
||||
category = {COMMAND, SCARPET},
|
||||
validate = ModulePermissionLevel.class
|
||||
)
|
||||
public static String commandScriptACE = "ops";
|
||||
|
||||
|
||||
@@ -3600,7 +3600,7 @@ public class CarpetExpression
|
||||
Vec3d posf = new Vec3d((double)target.getX()+0.5D,(double)target.getY(),(double)target.getZ()+0.5D);
|
||||
ServerCommandSource s = ((CarpetContext)c).s;
|
||||
Value retval = new NumericValue(s.getMinecraftServer().getCommandManager().execute(
|
||||
s.withPosition(posf).withSilent(), lv.get(0).evalValue(c).getString()));
|
||||
s.withPosition(posf).withSilent().withLevel(CarpetSettings.runPermissionLevel), lv.get(0).evalValue(c).getString()));
|
||||
return (c_, t_) -> retval;
|
||||
});
|
||||
|
||||
|
||||
@@ -206,6 +206,24 @@ public class SettingsManager
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getCommandLevel(String commandLevel)
|
||||
{
|
||||
switch (commandLevel)
|
||||
{
|
||||
case "true": return 2;
|
||||
case "false": return 0;
|
||||
case "ops": return 2; // typical for other cheaty commands
|
||||
case "0":
|
||||
case "1":
|
||||
case "2":
|
||||
case "3":
|
||||
case "4":
|
||||
return Integer.parseInt(commandLevel);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
private void loadConfigurationFromConf()
|
||||
{
|
||||
for (ParsedRule<?> rule : rules.values()) rule.resetToDefault(server.getCommandSource());
|
||||
|
||||
Reference in new issue
Block a user