Add basic support for other regions

This commit is contained in:
Melledy
2025-11-26 21:31:09 -08:00
parent 7df1be99ef
commit 187d715866
5 changed files with 49 additions and 7 deletions

View File

@@ -24,6 +24,8 @@ public class Config {
public RemoteCommand remoteCommand = new RemoteCommand();
public int customDataVersion = 0;
public String region = "global";
public String resourceDir = "./resources";
public String webFilesDir = "./web";
public String patchListPath = "./patchlist.json";

View File

@@ -57,7 +57,7 @@ public class GameConstants {
// Helper functions
public static String getGameVersion() {
return VERSION + "." + getDataVersion();
return VERSION + "." + getDataVersion() + " (" + Nebula.getConfig().getRegion().toUpperCase() + ")";
}
public static int getDataVersion() {

View File

@@ -17,6 +17,7 @@ import emu.nebula.game.GameContext;
import emu.nebula.net.PacketHelper;
import emu.nebula.plugin.PluginManager;
import emu.nebula.server.HttpServer;
import emu.nebula.util.AeadHelper;
import emu.nebula.util.Handbook;
import emu.nebula.util.JsonUtils;
import lombok.Getter;
@@ -42,8 +43,9 @@ public class Nebula {
@Getter private static PluginManager pluginManager;
public static void main(String[] args) {
// Load config first
// Load config + keys first
Nebula.loadConfig();
AeadHelper.loadKeys();
// Start Server
Nebula.getLogger().info("Starting Nebula " + getJarVersion());

View File

@@ -18,6 +18,10 @@ import org.bouncycastle.crypto.generators.ECKeyPairGenerator;
import org.bouncycastle.crypto.generators.HKDFBytesGenerator;
import org.bouncycastle.crypto.params.*;
import emu.nebula.Nebula;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
// Official Name: AeadTool
public class AeadHelper {
private static final ThreadLocal<SecureRandom> random = new ThreadLocal<>() {
@@ -27,9 +31,34 @@ public class AeadHelper {
}
};
public static final byte[] serverGarbleKey = "xNdVF^XTa6T3HCUATMQ@sKMLzAw&%L!3".getBytes(StandardCharsets.US_ASCII); // Global
public static final byte[] serverMetaKey = "ma5Dn2FhC*Xhxy%c".getBytes(StandardCharsets.US_ASCII); // Global
public static byte[] serverGarbleKey = null;
public static byte[] serverMetaKey = null;
private static final Object2ObjectMap<String, String[]> keys = new Object2ObjectOpenHashMap<>();
public static void loadKeys() {
// Load keys
keys.put("global", new String[] {
"ma5Dn2FhC*Xhxy%c",
"xNdVF^XTa6T3HCUATMQ@sKMLzAw&%L!3"
});
keys.put("kr", new String[] {
"U9cjHuwGDDx&$drn",
"25hdume9H#*6hHn@d9hSF7tekTwN#JYj"
});
// Get key data
var keyData = keys.get(Nebula.getConfig().getRegion().toLowerCase());
if (keyData == null) {
keyData = keys.get("global"); // Default region
}
// Set keys
serverMetaKey = keyData[0].getBytes(StandardCharsets.US_ASCII);
serverGarbleKey = keyData[1].getBytes(StandardCharsets.US_ASCII);
}
public static byte[] generateBytes(int size) {
byte[] iv = new byte[size];
random.get().nextBytes(iv);