diff --git a/src/main/java/emu/grasscutter/Configuration.java b/src/main/java/emu/grasscutter/Configuration.java index 4cbd0130c..486ca8739 100644 --- a/src/main/java/emu/grasscutter/Configuration.java +++ b/src/main/java/emu/grasscutter/Configuration.java @@ -4,9 +4,11 @@ import emu.grasscutter.utils.ConfigContainer; import emu.grasscutter.utils.ConfigContainer.*; import java.util.Locale; +import java.nio.file.Paths; import static emu.grasscutter.Grasscutter.config; + /** * A data container for the server's configuration. * @@ -24,12 +26,12 @@ public final class Configuration extends ConfigContainer { public static final Locale LANGUAGE = config.language.language; public static final Locale FALLBACK_LANGUAGE = config.language.fallback; - public static final String DATA_FOLDER = config.folderStructure.data; - public static final String RESOURCES_FOLDER = config.folderStructure.resources; - public static final String KEYS_FOLDER = config.folderStructure.keys; - public static final String PLUGINS_FOLDER = config.folderStructure.plugins; - public static final String SCRIPTS_FOLDER = config.folderStructure.scripts; - public static final String PACKETS_FOLDER = config.folderStructure.packets; + private static final String DATA_FOLDER = config.folderStructure.data; + private static final String RESOURCES_FOLDER = config.folderStructure.resources; + private static final String KEYS_FOLDER = config.folderStructure.keys; + private static final String PLUGINS_FOLDER = config.folderStructure.plugins; + private static final String SCRIPTS_FOLDER = config.folderStructure.scripts; + private static final String PACKETS_FOLDER = config.folderStructure.packets; public static final Server SERVER = config.server; public static final Database DATABASE = config.databaseInfo; @@ -49,17 +51,36 @@ public final class Configuration extends ConfigContainer { /* * Utilities */ - + public static String DATA() { + return DATA_FOLDER; + } + public static String DATA(String path) { - return DATA_FOLDER + "/" + path; + return Paths.get(DATA_FOLDER, path).toString(); } public static String RESOURCE(String path) { - return RESOURCES_FOLDER + "/" + path; + return Paths.get(RESOURCES_FOLDER, path).toString(); + } + + public static String KEY(String path) { + return Paths.get(KEYS_FOLDER, path).toString(); } + public static String PLUGIN() { + return PLUGINS_FOLDER; + } + + public static String PLUGIN(String path) { + return Paths.get(PLUGINS_FOLDER, path).toString(); + } + public static String SCRIPT(String path) { - return SCRIPTS_FOLDER + "/" + path; + return Paths.get(SCRIPTS_FOLDER, path).toString(); + } + + public static String PACKET(String path) { + return Paths.get(PACKETS_FOLDER, path).toString(); } /** @@ -91,4 +112,4 @@ public final class Configuration extends ConfigContainer { public static int lr(int left, int right) { return left == 0 ? right : left; } -} \ No newline at end of file +} diff --git a/src/main/java/emu/grasscutter/game/gacha/GachaManager.java b/src/main/java/emu/grasscutter/game/gacha/GachaManager.java index 4cbfde094..e4fafd814 100644 --- a/src/main/java/emu/grasscutter/game/gacha/GachaManager.java +++ b/src/main/java/emu/grasscutter/game/gacha/GachaManager.java @@ -358,7 +358,7 @@ public class GachaManager { if(this.watchService == null) { try { this.watchService = FileSystems.getDefault().newWatchService(); - Path path = new File(DATA_FOLDER).toPath(); + Path path = new File(DATA()).toPath(); path.register(watchService, new WatchEvent.Kind[]{StandardWatchEventKinds.ENTRY_MODIFY}, SensitivityWatchEventModifier.HIGH); } catch (Exception e) { Grasscutter.getLogger().error("Unable to load the Gacha Manager Watch Service. If ServerOptions.watchGacha is true it will not auto-reload"); diff --git a/src/main/java/emu/grasscutter/plugin/Plugin.java b/src/main/java/emu/grasscutter/plugin/Plugin.java index b45e642a5..f322adc93 100644 --- a/src/main/java/emu/grasscutter/plugin/Plugin.java +++ b/src/main/java/emu/grasscutter/plugin/Plugin.java @@ -37,7 +37,7 @@ public abstract class Plugin { this.identifier = identifier; this.classLoader = classLoader; - this.dataFolder = new File(PLUGINS_FOLDER, identifier.name); + this.dataFolder = new File(PLUGIN(), identifier.name); this.logger = LoggerFactory.getLogger(identifier.name); if(!this.dataFolder.exists() && !this.dataFolder.mkdirs()) { diff --git a/src/main/java/emu/grasscutter/plugin/PluginManager.java b/src/main/java/emu/grasscutter/plugin/PluginManager.java index 5d58744a4..f6f1cfbf7 100644 --- a/src/main/java/emu/grasscutter/plugin/PluginManager.java +++ b/src/main/java/emu/grasscutter/plugin/PluginManager.java @@ -34,7 +34,7 @@ public final class PluginManager { * Loads plugins from the config-specified directory. */ private void loadPlugins() { - File pluginsDir = new File(Utils.toFilePath(PLUGINS_FOLDER)); + File pluginsDir = new File(Utils.toFilePath(PLUGIN())); if(!pluginsDir.exists() && !pluginsDir.mkdirs()) { Grasscutter.getLogger().error("Failed to create plugins directory: " + pluginsDir.getAbsolutePath()); return; diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index aa2b9bc51..6ba0098a1 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -236,7 +236,7 @@ public class SceneScriptManager { group.setLoaded(true); CompiledScript cs = ScriptLoader.getScriptByPath( - SCRIPTS_FOLDER + "Scene/" + getScene().getId() + "/scene" + getScene().getId() + "_group" + group.id + "." + ScriptLoader.getScriptType()); + SCRIPT("Scene/" + getScene().getId() + "/scene" + getScene().getId() + "_group" + group.id + "." + ScriptLoader.getScriptType())); if (cs == null) { return; diff --git a/src/main/java/emu/grasscutter/server/game/GameSession.java b/src/main/java/emu/grasscutter/server/game/GameSession.java index cf6386770..fefc73d15 100644 --- a/src/main/java/emu/grasscutter/server/game/GameSession.java +++ b/src/main/java/emu/grasscutter/server/game/GameSession.java @@ -140,7 +140,7 @@ public class GameSession extends KcpChannel { } public void replayPacket(int opcode, String name) { - String filePath = PACKETS_FOLDER + name; + String filePath = PACKET(name); File p = new File(filePath); if (!p.exists()) return; diff --git a/src/main/java/emu/grasscutter/utils/Crypto.java b/src/main/java/emu/grasscutter/utils/Crypto.java index 41150ed13..1772e26de 100644 --- a/src/main/java/emu/grasscutter/utils/Crypto.java +++ b/src/main/java/emu/grasscutter/utils/Crypto.java @@ -20,11 +20,11 @@ public final class Crypto { public static byte[] ENCRYPT_SEED_BUFFER = new byte[0]; public static void loadKeys() { - DISPATCH_KEY = FileUtils.read(KEYS_FOLDER + "/dispatchKey.bin"); - DISPATCH_SEED = FileUtils.read(KEYS_FOLDER + "/dispatchSeed.bin"); + DISPATCH_KEY = FileUtils.read(KEY("dispatchKey.bin")); + DISPATCH_SEED = FileUtils.read(KEY("dispatchSeed.bin")); - ENCRYPT_KEY = FileUtils.read(KEYS_FOLDER + "/secretKey.bin"); - ENCRYPT_SEED_BUFFER = FileUtils.read(KEYS_FOLDER + "/secretKeyBuffer.bin"); + ENCRYPT_KEY = FileUtils.read(KEY("secretKey.bin")); + ENCRYPT_SEED_BUFFER = FileUtils.read(KEY("secretKeyBuffer.bin")); } public static void xor(byte[] packet, byte[] key) { @@ -40,7 +40,7 @@ public final class Crypto { public static void extractSecretKeyBuffer(byte[] data) { try { GetPlayerTokenRsp p = GetPlayerTokenRsp.parseFrom(data); - FileUtils.write(KEYS_FOLDER + "/secretKeyBuffer.bin", p.getSecretKeyBytes().toByteArray()); + FileUtils.write(KEY("/secretKeyBuffer.bin"), p.getSecretKeyBytes().toByteArray()); Grasscutter.getLogger().info("Secret Key: " + p.getSecretKey()); } catch (Exception e) { Grasscutter.getLogger().error("Crypto error.", e); @@ -50,7 +50,7 @@ public final class Crypto { public static void extractDispatchSeed(String data) { try { QueryCurrRegionHttpRsp p = QueryCurrRegionHttpRsp.parseFrom(Base64.getDecoder().decode(data)); - FileUtils.write(KEYS_FOLDER + "/dispatchSeed.bin", p.getRegionInfo().getSecretKey().toByteArray()); + FileUtils.write(KEY("/dispatchSeed.bin"), p.getRegionInfo().getSecretKey().toByteArray()); } catch (Exception e) { Grasscutter.getLogger().error("Crypto error.", e); }