Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
YAML stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 5, 2016
1 parent 617d999 commit 7f91987
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 41 deletions.
44 changes: 3 additions & 41 deletions src/main/java/com/denizenscript/denizen2sponge/Denizen2Sponge.java
Expand Up @@ -119,9 +119,10 @@ public void onServerStart(GamePreInitializationEvent event) {
loadConfig();
// Denizen2
Denizen2Core.init(new Denizen2SpongeImplementation());
// Ensure the scripts and addons folders exist
// Ensure the scripts, addons, and data folders exist
Denizen2Core.getImplementation().getScriptsFolder().mkdirs();
Denizen2Core.getImplementation().getAddonsFolder().mkdirs();
Denizen2Core.getImplementation().getScriptDataFolder().mkdirs();
// Commands: Entity
Denizen2Core.register(new EditEntityCommand());
Denizen2Core.register(new FlagEntityCommand());
Expand Down Expand Up @@ -185,45 +186,6 @@ public void onServerStart(GamePreInitializationEvent event) {
// TODO: Config option -> readyToSpamEvents = true;
}

/*
private static boolean readyToSpamEvents = false;
private static HashMap<Class, Integer> limiter = new HashMap<>();
// TODO: Move this block to a separate class so that we can easily unregister it!
@Listener
public void onAnyEvent(Event evt) {
if (readyToSpamEvents) {
if (evt instanceof AITaskEvent
|| evt instanceof SpawnEntityEvent
|| evt instanceof LoadChunkEvent
|| evt instanceof MoveEntityEvent) {
return;
}
if (limiter.containsKey(evt.getClass())) {
int current = limiter.get(evt.getClass());
limiter.put(evt.getClass(), current + 1);
if (current > 100) {
return;
}
}
else {
limiter.put(evt.getClass(), 1);
}
StringBuilder sb = new StringBuilder();
sb.append(evt.getClass().getCanonicalName()).append(":");
Class clz = evt.getClass().getSuperclass();
while (clz != null) {
sb.append(clz.getCanonicalName()).append(",");
clz = clz.getSuperclass();
}
if (sb.length() > 0 && sb.toString().contains("spongepowered")) {
Debug.info("EVENT OCCURRED: " + sb.toString());
}
}
}
*/

public File getMainDirectory() {
return new File("./assets/Denizen/");
}
Expand All @@ -234,7 +196,7 @@ public void onServerStop(GameStoppedEvent event) {
Denizen2Core.unload();
}

private File getConfigFile() {
public File getConfigFile() {
return new File(getMainDirectory(), "./config/config.yml");
}

Expand Down
Expand Up @@ -4,6 +4,7 @@
import com.denizenscript.denizen2core.commands.CommandEntry;
import com.denizenscript.denizen2core.commands.CommandQueue;
import com.denizenscript.denizen2core.utilities.ErrorInducedException;
import com.denizenscript.denizen2core.utilities.debugging.Debug;
import com.denizenscript.denizen2sponge.spongescripts.GameCommandScript;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.text.Text;
Expand Down Expand Up @@ -101,4 +102,51 @@ public String getImplementationVersion() {
public boolean enforceLocale() {
return Settings.enforceLocale();
}

public File getScriptDataFolder() {
return new File(Denizen2Sponge.instance.getMainDirectory(), "./data/");
}

private static File getBaseDirectory() {
// Genius!
return new File("./");
}

private static File getModsFolder() {
// TODO: Accuracy!
return new File(getBaseDirectory(), "./mods/");
}

public boolean isSafePath(String file) {
// TODO: Potentially prevent paths with bad symbolism, EG backslashes or colons, which could be misintrepretted based on environment?
try {
File f = new File(getScriptDataFolder(), file);
String canPath = f.getCanonicalPath();
if (Settings.noWeirdFiles()) {
if (canPath.contains(getAddonsFolder().getCanonicalPath())) {
return false;
}
if (canPath.contains(getScriptsFolder().getCanonicalPath())) {
return false;
}
if (canPath.contains(getModsFolder().getCanonicalPath())) {
return false;
}
if (canPath.contains(Denizen2Sponge.instance.getConfigFile().getCanonicalPath())) {
return false;
}
// TODO: Prevent fiddling with main jar / launcher scripts here?
}
if (Settings.noUnrelatedFiles()) {
if (!canPath.contains(getBaseDirectory().getCanonicalPath())) {
return false;
}
}
return true;
}
catch (Exception e) {
Debug.exception(e);
return false;
}
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/denizenscript/denizen2sponge/Settings.java
Expand Up @@ -17,4 +17,12 @@ public static boolean enforceLocale() {
public static boolean debugGeneral() {
return tryBool(Denizen2Sponge.instance.config.getString("Debug.General", "true"));
}

public static boolean noWeirdFiles() {
return tryBool(Denizen2Sponge.instance.config.getString("Files.Basic Protection", "true"));
}

public static boolean noUnrelatedFiles() {
return tryBool(Denizen2Sponge.instance.config.getString("Files.Advanced Protection", "true"));
}
}
6 changes: 6 additions & 0 deletions src/main/resources/default_config.yml
Expand Up @@ -3,3 +3,9 @@ Enforce Locale: true
Debug:
# Toggles general debug. If set to true, debug not attached to any queue will show.
General: true

Files:
# Just leave this one on for safety.
Basic Protection: true
# This one can be disabled if you have specific reason to modify files outside the directory of the server.
Advanced Protection: true

0 comments on commit 7f91987

Please sign in to comment.