Build region_list and cur_region dynamically

This commit is contained in:
Hotaru
2022-05-12 22:04:44 +02:00
committed by Melledy
parent f441d0665a
commit 2451d2c897
6 changed files with 46 additions and 70 deletions

View File

@@ -9,6 +9,7 @@ import emu.grasscutter.net.proto.PlayerLoginRspOuterClass.PlayerLoginRsp;
import emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass;
import emu.grasscutter.net.proto.RegionInfoOuterClass.RegionInfo;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.utils.Crypto;
import emu.grasscutter.utils.FileUtils;
import java.io.File;
@@ -30,24 +31,14 @@ public class PacketPlayerLoginRsp extends BasePacket {
if (SERVER.runMode == ServerRunMode.GAME_ONLY) {
if (regionCache == null) {
try {
File file = new File(DATA("query_cur_region.txt"));
String query_cur_region = "";
if (file.exists()) {
query_cur_region = new String(FileUtils.read(file));
} else {
Grasscutter.getLogger().warn("query_cur_region not found! Using default current region.");
}
byte[] decodedCurRegion = Base64.getDecoder().decode(query_cur_region);
QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp regionQuery = QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp.parseFrom(decodedCurRegion);
RegionInfo serverRegion = regionQuery.getRegionInfo().toBuilder()
// todo: we might want to push custom config to client
RegionInfo serverRegion = RegionInfo.newBuilder()
.setGateserverIp(lr(GAME_INFO.accessAddress, GAME_INFO.bindAddress))
.setGateserverPort(lr(GAME_INFO.accessPort, GAME_INFO.bindPort))
.setSecretKey(ByteString.copyFrom(FileUtils.read(KEYS_FOLDER + "/dispatchSeed.bin")))
.setSecretKey(ByteString.copyFrom(Crypto.DISPATCH_SEED))
.build();
regionCache = regionQuery.toBuilder().setRegionInfo(serverRegion).build();
regionCache = QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp.newBuilder().setRegionInfo(serverRegion).build();
} catch (Exception e) {
Grasscutter.getLogger().error("Error while initializing region cache!", e);
}